OpenNI 1.5.7
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
Include
XnOSCpp.h
Go to the documentation of this file.
1
/*****************************************************************************
2
* *
3
* OpenNI 1.x Alpha *
4
* Copyright (C) 2012 PrimeSense Ltd. *
5
* *
6
* This file is part of OpenNI. *
7
* *
8
* Licensed under the Apache License, Version 2.0 (the "License"); *
9
* you may not use this file except in compliance with the License. *
10
* You may obtain a copy of the License at *
11
* *
12
* http://www.apache.org/licenses/LICENSE-2.0 *
13
* *
14
* Unless required by applicable law or agreed to in writing, software *
15
* distributed under the License is distributed on an "AS IS" BASIS, *
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17
* See the License for the specific language governing permissions and *
18
* limitations under the License. *
19
* *
20
*****************************************************************************/
21
#ifndef __XN_OS_CPP_H__
22
#define __XN_OS_CPP_H__
23
24
//---------------------------------------------------------------------------
25
// Includes
26
//---------------------------------------------------------------------------
27
#include <
XnOS.h
>
28
29
//---------------------------------------------------------------------------
30
// Types
31
//---------------------------------------------------------------------------
32
class
XnAutoCSLocker
33
{
34
public
:
35
inline
XnAutoCSLocker
(
const
XnAutoCSLocker
& other) : m_hCS(other.m_hCS), m_bLocked(
FALSE
)
36
{
37
Lock
();
38
}
39
40
inline
XnAutoCSLocker
&
operator=
(
const
XnAutoCSLocker
& other)
41
{
42
Unlock
();
43
m_hCS = other.m_hCS;
44
Lock
();
45
return
*
this
;
46
}
47
48
inline
XnAutoCSLocker
(XN_CRITICAL_SECTION_HANDLE hCS) : m_hCS(hCS), m_bLocked(
FALSE
)
49
{
50
Lock
();
51
}
52
53
inline
~XnAutoCSLocker
()
54
{
55
Unlock
();
56
}
57
58
inline
void
Lock
()
59
{
60
if
(!m_bLocked)
61
{
62
xnOSEnterCriticalSection
(&m_hCS);
63
m_bLocked =
TRUE
;
64
}
65
}
66
67
inline
void
Unlock
()
68
{
69
if
(m_bLocked)
70
{
71
xnOSLeaveCriticalSection
(&m_hCS);
72
m_bLocked =
FALSE
;
73
}
74
}
75
76
private
:
77
XN_CRITICAL_SECTION_HANDLE m_hCS;
78
XnBool m_bLocked;
79
};
80
81
class
XnAutoMutexLocker
82
{
83
public
:
84
inline
XnAutoMutexLocker
(XN_MUTEX_HANDLE hMutex, XnUInt32 nMilliseconds) : m_hMutex(hMutex)
85
{
86
m_nStatus =
xnOSLockMutex
(m_hMutex, nMilliseconds);
87
}
88
89
XnStatus
GetStatus
()
const
90
{
91
return
m_nStatus;
92
}
93
94
inline
~XnAutoMutexLocker
()
95
{
96
if
(m_nStatus ==
XN_STATUS_OK
)
97
{
98
//Only unlock if we managed to lock in the first place
99
xnOSUnLockMutex
(m_hMutex);
100
}
101
}
102
103
private
:
104
XN_MUTEX_HANDLE m_hMutex;
105
XnStatus
m_nStatus;
106
};
107
108
class
XnOSEvent
109
{
110
public
:
111
XnOSEvent
() : m_hEvent(NULL) {}
112
113
~XnOSEvent
()
114
{
115
Close
();
116
}
117
118
operator
XN_EVENT_HANDLE()
const
119
{
120
return
m_hEvent;
121
}
122
123
XnStatus
Create
(XnBool bManualReset)
124
{
125
return
xnOSCreateEvent
(&m_hEvent, bManualReset);
126
}
127
128
XnStatus
Create
(
const
XnChar* strName, XnBool bManualReset, XnBool bAllowOtherUsers =
FALSE
)
129
{
130
return
xnOSCreateNamedEventEx
(&m_hEvent, strName, bManualReset, bAllowOtherUsers);
131
}
132
133
XnStatus
Open
(
const
XnChar* strName, XnBool bEnableOtherUsers =
FALSE
)
134
{
135
return
xnOSOpenNamedEventEx
(&m_hEvent, strName, bEnableOtherUsers);
136
}
137
138
XnStatus
Close
()
139
{
140
return
(m_hEvent != NULL) ?
xnOSCloseEvent
(&m_hEvent) :
XN_STATUS_OK
;
141
}
142
143
XnStatus
Set
()
144
{
145
return
xnOSSetEvent
(m_hEvent);
146
}
147
148
XnStatus
Reset
()
149
{
150
return
xnOSResetEvent
(m_hEvent);
151
}
152
153
XnStatus
Wait
(XnUInt32 nMilliseconds)
154
{
155
return
xnOSWaitEvent
(m_hEvent, nMilliseconds);
156
}
157
158
private
:
159
XN_EVENT_HANDLE m_hEvent;
160
};
161
162
#endif // __XN_OS_CPP_H__
Generated on Tue Nov 12 2013 13:40:20 for OpenNI 1.5.7 by
1.8.3.1