OpenNI 1.5.4
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) 2011 PrimeSense Ltd. *
5
* *
6
* This file is part of OpenNI. *
7
* *
8
* OpenNI is free software: you can redistribute it and/or modify *
9
* it under the terms of the GNU Lesser General Public License as published *
10
* by the Free Software Foundation, either version 3 of the License, or *
11
* (at your option) any later version. *
12
* *
13
* OpenNI is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU Lesser General Public License for more details. *
17
* *
18
* You should have received a copy of the GNU Lesser General Public License *
19
* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20
* *
21
****************************************************************************/
22
#ifndef __XN_OS_CPP_H__
23
#define __XN_OS_CPP_H__
24
25
//---------------------------------------------------------------------------
26
// Includes
27
//---------------------------------------------------------------------------
28
#include <
XnOS.h
>
29
30
//---------------------------------------------------------------------------
31
// Types
32
//---------------------------------------------------------------------------
33
class
XnAutoCSLocker
34
{
35
public
:
36
inline
XnAutoCSLocker
(
const
XnAutoCSLocker
& other) : m_hCS(other.m_hCS), m_bLocked(
FALSE
)
37
{
38
Lock
();
39
}
40
41
inline
XnAutoCSLocker
&
operator=
(
const
XnAutoCSLocker
& other)
42
{
43
Unlock
();
44
m_hCS = other.m_hCS;
45
Lock
();
46
return
*
this
;
47
}
48
49
inline
XnAutoCSLocker
(XN_CRITICAL_SECTION_HANDLE hCS) : m_hCS(hCS), m_bLocked(
FALSE
)
50
{
51
Lock
();
52
}
53
54
inline
~XnAutoCSLocker
()
55
{
56
Unlock
();
57
}
58
59
inline
void
Lock
()
60
{
61
if
(!m_bLocked)
62
{
63
xnOSEnterCriticalSection
(&m_hCS);
64
m_bLocked =
TRUE
;
65
}
66
}
67
68
inline
void
Unlock
()
69
{
70
if
(m_bLocked)
71
{
72
xnOSLeaveCriticalSection
(&m_hCS);
73
m_bLocked =
FALSE
;
74
}
75
}
76
77
private
:
78
XN_CRITICAL_SECTION_HANDLE m_hCS;
79
XnBool m_bLocked;
80
};
81
82
class
XnAutoMutexLocker
83
{
84
public
:
85
inline
XnAutoMutexLocker
(XN_MUTEX_HANDLE hMutex, XnUInt32 nMilliseconds) : m_hMutex(hMutex)
86
{
87
m_nStatus =
xnOSLockMutex
(m_hMutex, nMilliseconds);
88
}
89
90
XnStatus
GetStatus
()
const
91
{
92
return
m_nStatus;
93
}
94
95
inline
~XnAutoMutexLocker
()
96
{
97
if
(m_nStatus ==
XN_STATUS_OK
)
98
{
99
//Only unlock if we managed to lock in the first place
100
xnOSUnLockMutex
(m_hMutex);
101
}
102
}
103
104
private
:
105
XN_MUTEX_HANDLE m_hMutex;
106
XnStatus
m_nStatus;
107
};
108
109
class
XnOSEvent
110
{
111
public
:
112
XnOSEvent
() : m_hEvent(NULL) {}
113
114
~XnOSEvent
()
115
{
116
Close
();
117
}
118
119
operator
XN_EVENT_HANDLE()
const
120
{
121
return
m_hEvent;
122
}
123
124
XnStatus
Create
(XnBool bManualReset)
125
{
126
return
xnOSCreateEvent
(&m_hEvent, bManualReset);
127
}
128
129
XnStatus
Create
(
const
XnChar* strName, XnBool bManualReset, XnBool bAllowOtherUsers =
FALSE
)
130
{
131
return
xnOSCreateNamedEventEx
(&m_hEvent, strName, bManualReset, bAllowOtherUsers);
132
}
133
134
XnStatus
Open
(
const
XnChar* strName, XnBool bEnableOtherUsers =
FALSE
)
135
{
136
return
xnOSOpenNamedEventEx
(&m_hEvent, strName, bEnableOtherUsers);
137
}
138
139
XnStatus
Close
()
140
{
141
return
(m_hEvent != NULL) ?
xnOSCloseEvent
(&m_hEvent) :
XN_STATUS_OK
;
142
}
143
144
XnStatus
Set
()
145
{
146
return
xnOSSetEvent
(m_hEvent);
147
}
148
149
XnStatus
Reset
()
150
{
151
return
xnOSResetEvent
(m_hEvent);
152
}
153
154
XnStatus
Wait
(XnUInt32 nMilliseconds)
155
{
156
return
xnOSWaitEvent
(m_hEvent, nMilliseconds);
157
}
158
159
private
:
160
XN_EVENT_HANDLE m_hEvent;
161
};
162
163
#endif // __XN_OS_CPP_H__
Generated on Fri Dec 28 2012 12:04:02 for OpenNI 1.5.4 by
1.8.1.2