forked from avin2/SensorKinect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXnSensorProductionNode.cpp
249 lines (206 loc) · 8.97 KB
/
XnSensorProductionNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*****************************************************************************
* *
* PrimeSense Sensor 5.0 Alpha *
* Copyright (C) 2010 PrimeSense Ltd. *
* *
* This file is part of PrimeSense Common. *
* *
* PrimeSense Sensor is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* PrimeSense Sensor is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with PrimeSense Sensor. If not, see <http://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnSensorProductionNode.h"
#include "XnMultiPropChangedHandler.h"
//---------------------------------------------------------------------------
// XnSensorProductionNode class
//---------------------------------------------------------------------------
XnSensorProductionNode::XnSensorProductionNode(xn::Context& context, const XnChar* strInstanceName, XnDeviceBase* pSensor, const XnChar* strModuleName) :
m_Context(context),
m_pSensor(pSensor),
m_pNotifications(NULL)
{
strcpy(m_strInstanceName, strInstanceName);
strcpy(m_strModule, strModuleName);
}
XnSensorProductionNode::~XnSensorProductionNode()
{
// free all memory allocated for registration, even if client did not unregister from it
for (XnMultiPropChangedHandlerHash::Iterator it = m_AllHandlers.begin(); it != m_AllHandlers.end(); ++it)
{
XN_DELETE(it.Key());
}
}
XnBool XnSensorProductionNode::IsCapabilitySupported(const XnChar* strCapabilityName)
{
return ((strcmp(strCapabilityName, XN_CAPABILITY_EXTENDED_SERIALIZATION) == 0) ||
(strcmp(strCapabilityName, XN_CAPABILITY_LOCK_AWARE) == 0));
}
XnStatus XnSensorProductionNode::SetIntProperty(const XnChar* strName, XnUInt64 nValue)
{
return m_pSensor->SetProperty(m_strModule, strName, nValue);
}
XnStatus XnSensorProductionNode::SetRealProperty(const XnChar* strName, XnDouble dValue)
{
return m_pSensor->SetProperty(m_strModule, strName, dValue);
}
XnStatus XnSensorProductionNode::SetStringProperty(const XnChar* strName, const XnChar* strValue)
{
return m_pSensor->SetProperty(m_strModule, strName, strValue);
}
XnStatus XnSensorProductionNode::SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
{
return m_pSensor->SetProperty(m_strModule, strName, XnGeneralBufferPack((void*)pBuffer, nBufferSize));
}
XnStatus XnSensorProductionNode::GetIntProperty(const XnChar* strName, XnUInt64& nValue) const
{
return m_pSensor->GetProperty(m_strModule, strName, &nValue);
}
XnStatus XnSensorProductionNode::GetRealProperty(const XnChar* strName, XnDouble& dValue) const
{
return m_pSensor->GetProperty(m_strModule, strName, &dValue);
}
XnStatus XnSensorProductionNode::GetStringProperty(const XnChar* strName, XnChar* csValue, XnUInt32 nBufSize) const
{
XnChar strValue[XN_DEVICE_MAX_STRING_LENGTH];
XnStatus nRetVal = m_pSensor->GetProperty(m_strModule, strName, strValue);
XN_IS_STATUS_OK(nRetVal);
nRetVal = xnOSStrCopy(csValue, strValue, nBufSize);
XN_IS_STATUS_OK(nRetVal);
return XN_STATUS_OK;
}
XnStatus XnSensorProductionNode::GetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, void* pBuffer) const
{
return m_pSensor->GetProperty(m_strModule, strName, XnGeneralBufferPack(pBuffer, nBufferSize));
}
XnStatus XnSensorProductionNode::SetLockState(XnBool bLocked)
{
return m_pSensor->SetProperty(m_strModule, XN_MODULE_PROPERTY_LOCK, (XnUInt64)bLocked);
}
XnBool XnSensorProductionNode::GetLockState()
{
XnUInt64 nValue = FALSE;
XnStatus nRetVal = m_pSensor->GetProperty(m_strModule, XN_MODULE_PROPERTY_LOCK, &nValue);
return (nValue == TRUE);
}
XnStatus XnSensorProductionNode::RegisterToLockChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
const XnChar* aProps[] =
{
XN_MODULE_PROPERTY_LOCK,
NULL
};
return RegisterToProps(handler, pCookie, hCallback, aProps);
}
void XnSensorProductionNode::UnregisterFromLockChange(XnCallbackHandle hCallback)
{
UnregisterFromProps(hCallback);
}
void XnSensorProductionNode::FilterProperties(XnActualPropertiesHash* pHash)
{
pHash->Remove(XN_MODULE_PROPERTY_LOCK);
}
XnStatus XnSensorProductionNode::NotifyExState(XnNodeNotifications* pNotifications, void* pCookie)
{
XnStatus nRetVal = XN_STATUS_OK;
// get all properties
XN_PROPERTY_SET_CREATE_ON_STACK(props);
nRetVal = m_pSensor->GetAllProperties(&props, FALSE, GetModuleName());
XN_IS_STATUS_OK(nRetVal);
XnActualPropertiesHash* pPropsHash = props.pData->begin().Value();
// filter properties (remove the ones already exposed as OpenNI interfaces)
FilterProperties(pPropsHash);
const XnChar* astrIntProps[200] = {0};
const XnChar* astrRealProps[200] = {0};
const XnChar* astrStringProps[200] = {0};
const XnChar* astrGeneralProps[200] = {0};
XnUInt32 nIntProps = 0;
XnUInt32 nRealProps = 0;
XnUInt32 nStringProps = 0;
XnUInt32 nGeneralProps = 0;
// enumerate over properties
for (XnActualPropertiesHash::Iterator it = pPropsHash->begin(); it != pPropsHash->end(); ++it)
{
XnProperty* pProp = it.Value();
switch (pProp->GetType())
{
case XN_PROPERTY_TYPE_INTEGER:
{
XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
pNotifications->OnNodeIntPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pIntProp->GetValue());
astrIntProps[nIntProps++] = pProp->GetName();
}
break;
case XN_PROPERTY_TYPE_REAL:
{
XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
pNotifications->OnNodeRealPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pRealProp->GetValue());
astrRealProps[nRealProps++] = pProp->GetName();
}
break;
case XN_PROPERTY_TYPE_STRING:
{
XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
pNotifications->OnNodeStringPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pStrProp->GetValue());
astrStringProps[nStringProps++] = pProp->GetName();
}
break;
case XN_PROPERTY_TYPE_GENERAL:
{
XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
pNotifications->OnNodeGeneralPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pGenProp->GetValue().nDataSize, pGenProp->GetValue().pData);
astrGeneralProps[nGeneralProps++] = pProp->GetName();
}
break;
default:
XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DEVICE_SENSOR, "Unknown property type: %d", pProp->GetType());
}
}
// TODO: also register to these properties, and if changed, notify.
// store notifications object
m_pNotifications = pNotifications;
m_pCookie = pCookie;
return (XN_STATUS_OK);
}
void XnSensorProductionNode::UnregisterExNotifications()
{
// TODO: unregister from props
// reset notifications object
m_pNotifications = NULL;
m_pCookie = NULL;
}
XnStatus XnSensorProductionNode::RegisterToProps(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback, const XnChar** strNames, const XnChar* strModule /* = NULL */)
{
XnStatus nRetVal = XN_STATUS_OK;
XnMultiPropStateChangedHandler* pHandler;
XN_VALIDATE_NEW(pHandler, XnMultiPropStateChangedHandler, this, handler, pCookie, strModule);
nRetVal = pHandler->AddProperties(strNames);
if (nRetVal != XN_STATUS_OK)
{
XN_DELETE(pHandler);
return (nRetVal);
}
// register it for later deletion
m_AllHandlers.Set(pHandler, pHandler);
hCallback = (XnCallbackHandle)pHandler;
return (XN_STATUS_OK);
}
void XnSensorProductionNode::UnregisterFromProps(XnCallbackHandle hCallback)
{
XnMultiPropStateChangedHandler* pHandler = (XnMultiPropStateChangedHandler*)hCallback;
m_AllHandlers.Remove(pHandler);
pHandler->Unregister();
XN_DELETE(pHandler);
}