File: OniDriverHandler.h

package info (click to toggle)
openni2 2.2.0.33%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 22,216 kB
  • sloc: cpp: 111,197; ansic: 35,511; sh: 10,542; python: 1,313; java: 952; makefile: 575; xml: 12
file content (261 lines) | stat: -rw-r--r-- 11,563 bytes parent folder | download | duplicates (4)
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
250
251
252
253
254
255
256
257
258
259
260
261
/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
#ifndef _LIBRARY_HANDLER_H_
#define _LIBRARY_HANDLER_H_

#include "OniCAPI.h"
#include "OniCTypes.h"
#include "XnErrorLogger.h"
#include "XnPlatform.h"
#include "XnErrorLogger.h"
#include "OniCommon.h"
#include "Driver/OniDriverTypes.h"

ONI_NAMESPACE_IMPLEMENTATION_BEGIN

typedef void (ONI_CALLBACK_TYPE* OniDriverDeviceConnected)(const OniDeviceInfo*, void* pCookie);
typedef void (ONI_CALLBACK_TYPE* OniDriverDeviceDisconnected)(const OniDeviceInfo*, void* pCookie);
typedef void (ONI_CALLBACK_TYPE* OniDriverDeviceStateChanged)(const OniDeviceInfo*, OniDeviceState, void* pCookie);

typedef void (ONI_CALLBACK_TYPE* OniDriverNewFrame)(void* streamHandle, OniFrame*, void* pCookie);
typedef void (ONI_CALLBACK_TYPE* OniDriverPropertyChanged)(void* sender, int propertyId, const void* data, int dataSize, void* pCookie);

struct Funcs
{
	// As Driver
	void (ONI_C_DECL* oniDriverCreate)(OniDriverServices* driverServices);
	void (ONI_C_DECL* oniDriverDestroy)();
	OniStatus (ONI_C_DECL* oniDriverInitialize)(OniDriverDeviceConnected connectedCallback, OniDriverDeviceDisconnected disconnectedCallback, 
                                                OniDriverDeviceStateChanged deviceStateChangedCallback, void* pCookie);
	void (ONI_C_DECL* oniDriverRun)();

	OniStatus (ONI_C_DECL* oniDriverTryDevice)(const char* uri);

	// As Device
	void* (ONI_C_DECL* oniDriverDeviceOpen)(const char* uri, const char* mode);
	void (ONI_C_DECL* oniDriverDeviceClose)(void* deviceHandle);

	OniStatus (ONI_C_DECL* oniDriverDeviceGetSensorInfoList)(void* deviceHandle, OniSensorInfo** pSensors, int* numSensors);

	void* (ONI_C_DECL* oniDriverDeviceCreateStream)(void* deviceHandle, OniSensorType sensorType);
	void (ONI_C_DECL* oniDriverDeviceDestroyStream)(void* deviceHandle, void* streamHandle);

	OniStatus (ONI_C_DECL* oniDriverDeviceSetProperty)(void* deviceHandle, int propertyId, const void* data, int dataSize);
	OniStatus (ONI_C_DECL* oniDriverDeviceGetProperty)(void* deviceHandle, int propertyId, void* data, int* pDataSize);
	OniBool (ONI_C_DECL* oniDriverDeviceIsPropertySupported)(void* deviceHandle, int propertyId);
	void (ONI_C_DECL* oniDriverDeviceSetPropertyChangedCallback)(void* deviceHandle, OniDriverPropertyChanged handler, void* pCookie);
	void (ONI_C_DECL* oniDriverDeviceNotifyAllProperties)(void* deviceHandle);
	OniStatus (ONI_C_DECL* oniDriverDeviceInvoke)(void* deviceHandle, int commandId, const void* data, int dataSize);
	OniBool (ONI_C_DECL* oniDriverDeviceIsCommandSupported)(void* deviceHandle, int commandId);
	OniStatus (ONI_C_DECL* oniDriverDeviceTryManualTrigger)(void* deviceHandle);
	OniBool (ONI_C_DECL* oniDriverDeviceIsImageRegistrationModeSupported)(void* deviceHandle, OniImageRegistrationMode mode);

	// As Stream
	void (ONI_C_DECL* oniDriverStreamSetServices)(void* streamHandle, OniStreamServices* pServices);
	OniStatus (ONI_C_DECL* oniDriverStreamSetProperty)(void* streamHandle, int propertyId, const void* data, int dataSize);
	OniStatus (ONI_C_DECL* oniDriverStreamGetProperty)(void* streamHandle, int propertyId, void* data, int* pDataSize);
	OniBool (ONI_C_DECL* oniDriverStreamIsPropertySupported)(void* streamHandle, int propertyId);
	void (ONI_C_DECL* oniDriverStreamSetPropertyChangedCallback)(void* streamHandle, OniDriverPropertyChanged handler, void* pCookie);
	void (ONI_C_DECL* oniDriverStreamNotifyAllProperties)(void* streamHandle);
	OniStatus (ONI_C_DECL* oniDriverStreamInvoke)(void* streamHandle, int commandId, const void* data, int dataSize);
	OniBool (ONI_C_DECL* oniDriverStreamIsCommandSupported)(void* streamHandle, int commandId);

	OniStatus (ONI_C_DECL* oniDriverStreamStart)(void* streamHandle);
	void (ONI_C_DECL* oniDriverStreamStop)(void* streamHandle);

	int (ONI_C_DECL* oniDriverStreamGetRequiredFrameSize)(void* streamHandle);

	void (ONI_C_DECL* oniDriverStreamSetNewFrameCallback)(void* streamHandle, OniDriverNewFrame handler, void* pCookie);
	OniStatus (ONI_C_DECL* oniDriverStreamConvertDepthToColorCoordinates)(void* depthStreamHandle, void* colorStreamHandle, int depthX, int depthY, OniDepthPixel depthZ, int* pColorX, int* pColorY);

	void* (ONI_C_DECL* oniDriverEnableFrameSync)(void** pStreamHandles, int streamCount);
	void (ONI_C_DECL* oniDriverDisableFrameSync)(void* frameSyncGroup);
};


class DriverHandler
{
public:
	DriverHandler(const char* library, xnl::ErrorLogger& errorLogger);
	~DriverHandler();

	bool isValid() const {return m_valid;}

	void create(OniDriverServices* driverServices) const 
	{
		(*funcs.oniDriverCreate)(driverServices);
	}
	void destroy() const 
	{
		(*funcs.oniDriverDestroy)();
	}
	OniStatus initialize(OniDriverDeviceConnected connectedCallback, OniDriverDeviceDisconnected disconnectedCallback, 
					OniDriverDeviceStateChanged deviceStateChangedCallback, void* pCookie) const 
	{
		return (*funcs.oniDriverInitialize)(connectedCallback, disconnectedCallback, deviceStateChangedCallback, pCookie);
	}

	OniStatus tryDevice(const char* uri) const 
	{
		return (*funcs.oniDriverTryDevice)(uri);
	}

	void* deviceOpen(const char* uri, const char* mode) const 
	{
		return (*funcs.oniDriverDeviceOpen)(uri, mode);
	}
	void deviceClose(void* deviceHandle) const 
	{
		(*funcs.oniDriverDeviceClose)(deviceHandle);
	}

	OniStatus deviceGetSensorInfoList(void* deviceHandle, OniSensorInfo** pSensors, int* numSensors) const 
	{
		return (*funcs.oniDriverDeviceGetSensorInfoList)(deviceHandle, pSensors, numSensors);
	}

	void* deviceCreateStream(void* deviceHandle, OniSensorType sensorType) const 
	{
		return (*funcs.oniDriverDeviceCreateStream)(deviceHandle, sensorType); // return stream
	}

	void deviceDestroyStream(void* deviceHandle, void* streamHandle) const
	{
		(*funcs.oniDriverDeviceDestroyStream)(deviceHandle, streamHandle);
	}

	OniStatus deviceSetProperty(void* deviceHandle, int propertyId, const void* data, int dataSize) const 
	{
		return (*funcs.oniDriverDeviceSetProperty)(deviceHandle, propertyId, data, dataSize);
	}
	OniStatus deviceGetProperty(void* deviceHandle, int propertyId, void* data, int* pDataSize) const 
	{
		return (*funcs.oniDriverDeviceGetProperty)(deviceHandle, propertyId, data, pDataSize);
	}
	OniBool deviceIsPropertySupported(void* deviceHandle, int propertyId) const 
	{
		return (*funcs.oniDriverDeviceIsPropertySupported)(deviceHandle, propertyId);
	}
	void deviceSetPropertyChangedCallback(void* deviceHandle, OniDriverPropertyChanged handler, void* pCookie) const
	{
		(*funcs.oniDriverDeviceSetPropertyChangedCallback)(deviceHandle, handler, pCookie);
	}
	void deviceNotifyAllProperties(void* deviceHandle) const
	{
		(*funcs.oniDriverDeviceNotifyAllProperties)(deviceHandle);
	}
	OniStatus deviceInvoke(void* deviceHandle, int commandId, const void* data, int dataSize) const
	{
		return (*funcs.oniDriverDeviceInvoke)(deviceHandle, commandId, data, dataSize);
	}
	OniBool deviceIsCommandSupported(void* deviceHandle, int commandId) const 
	{
		return (*funcs.oniDriverDeviceIsCommandSupported)(deviceHandle, commandId);
	}
	OniBool deviceIsImageRegistrationModeSupported(void* deviceHandle, OniImageRegistrationMode mode) const 
	{
		return (*funcs.oniDriverDeviceIsImageRegistrationModeSupported)(deviceHandle, mode);
	}
	OniStatus tryManualTrigger(void* deviceHandle) const
	{
		return (*funcs.oniDriverDeviceTryManualTrigger)(deviceHandle);
	}
	////////////////////////////

	void streamSetServices(void* streamHandle, OniStreamServices* pServices) const
	{
		(*funcs.oniDriverStreamSetServices)(streamHandle, pServices);
	}
	OniStatus streamSetProperty(void* streamHandle, int propertyId, const void* data, int dataSize) const
	{
		return (*funcs.oniDriverStreamSetProperty)(streamHandle, propertyId, data, dataSize);
	}
	OniStatus streamGetProperty(void* streamHandle, int propertyId, void* data, int* pDataSize) const
	{
		return (*funcs.oniDriverStreamGetProperty)(streamHandle, propertyId, data, pDataSize);
	}
	OniBool streamIsPropertySupported(void* streamHandle, int propertyId) const
	{
		return (*funcs.oniDriverStreamIsPropertySupported)(streamHandle, propertyId);
	}
	void streamSetPropertyChangedCallback(void* streamHandle, OniDriverPropertyChanged handler, void* pCookie) const
	{
		(*funcs.oniDriverStreamSetPropertyChangedCallback)(streamHandle, handler, pCookie);
	}
	void streamNotifyAllProperties(void* streamHandle) const
	{
		(*funcs.oniDriverStreamNotifyAllProperties)(streamHandle);
	}
	OniStatus streamInvoke(void* streamHandle, int commandId, const void* data, int dataSize) const
	{
		return (*funcs.oniDriverStreamInvoke)(streamHandle, commandId, data, dataSize);
	}
	OniBool streamIsCommandSupported(void* streamHandle, int commandId) const
	{
		return (*funcs.oniDriverStreamIsCommandSupported)(streamHandle, commandId);
	}

	OniStatus streamStart(void* streamHandle) const
	{
		return (*funcs.oniDriverStreamStart)(streamHandle);
	}
	void streamStop(void* streamHandle) const 
	{
		(*funcs.oniDriverStreamStop)(streamHandle);
	}

	int streamGetRequiredFrameSize(void* streamHandle) const
	{
		return (*funcs.oniDriverStreamGetRequiredFrameSize)(streamHandle);
	}

	void streamSetNewFrameCallback(void* streamHandle, OniDriverNewFrame handler, void* pCookie) const 
	{
		(*funcs.oniDriverStreamSetNewFrameCallback)(streamHandle, handler, pCookie);
	}

	OniStatus convertDepthPointToColor(void* depthStreamHandle, void* colorStreamHandle, int depthX, int depthY, OniDepthPixel DepthZ, int* pColorX, int* pColorY) const
	{
		return (*funcs.oniDriverStreamConvertDepthToColorCoordinates)(depthStreamHandle, colorStreamHandle, depthX, depthY, DepthZ, pColorX, pColorY);
	}

	void* enableFrameSync(void** streamHandles, int streamCount) const
	{
		return (*funcs.oniDriverEnableFrameSync)(streamHandles, streamCount);
	}
	void disableFrameSync(void* frameSyncGroup) const
	{
		return (*funcs.oniDriverDisableFrameSync)(frameSyncGroup);
	}

private:
	Funcs funcs;

	XN_LIB_HANDLE m_libHandle;
	bool m_valid;
};



ONI_NAMESPACE_IMPLEMENTATION_END


#endif // _LIBRARY_HANDLER_H_