OniDriverAPI.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * *
3 * OpenNI 2.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 _ONI_DRIVER_API_H_
22 #define _ONI_DRIVER_API_H_
23 
24 #include "OniPlatform.h"
25 #include "OniCTypes.h"
26 #include "OniCProperties.h"
27 #include "OniDriverTypes.h"
28 #include <stdarg.h>
29 
30 namespace oni { namespace driver {
31 
32 class DeviceBase;
33 class StreamBase;
34 
35 typedef void (ONI_CALLBACK_TYPE* DeviceConnectedCallback)(const OniDeviceInfo*, void* pCookie);
36 typedef void (ONI_CALLBACK_TYPE* DeviceDisconnectedCallback)(const OniDeviceInfo*, void* pCookie);
37 typedef void (ONI_CALLBACK_TYPE* DeviceStateChangedCallback)(const OniDeviceInfo* deviceId, int errorState, void* pCookie);
39 typedef void (ONI_CALLBACK_TYPE* PropertyChangedCallback)(void* sender, int propertyId, const void* data, int dataSize, void* pCookie);
40 
42 {
43 public:
45  {
46  return OniStreamServices::getDefaultRequiredFrameSize(streamServices);
47  }
48 
49  OniFrame* acquireFrame()
50  {
52  }
53 
54  void addFrameRef(OniFrame* pFrame)
55  {
56  OniStreamServices::addFrameRef(streamServices, pFrame);
57  }
58 
59  void releaseFrame(OniFrame* pFrame)
60  {
61  OniStreamServices::releaseFrame(streamServices, pFrame);
62  }
63 };
64 
66 {
67 public:
68  StreamBase() : m_newFrameCallback(NULL), m_propertyChangedCallback(NULL) {}
69  virtual ~StreamBase() {}
70 
71  virtual void setServices(StreamServices* pStreamServices) { m_pServices = pStreamServices; }
72 
73  virtual OniStatus setProperty(int /*propertyId*/, const void* /*data*/, int /*dataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
74  virtual OniStatus getProperty(int /*propertyId*/, void* /*data*/, int* /*pDataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
75  virtual OniBool isPropertySupported(int /*propertyId*/) {return FALSE;}
76  virtual OniStatus invoke(int /*commandId*/, void* /*data*/, int /*dataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
77  virtual OniBool isCommandSupported(int /*commandId*/) {return FALSE;}
78 
79  virtual int getRequiredFrameSize() { return getServices().getDefaultRequiredFrameSize(); }
80 
81  virtual OniStatus start() = 0;
82  virtual void stop() = 0;
83 
84  virtual void setNewFrameCallback(NewFrameCallback handler, void* pCookie) { m_newFrameCallback = handler; m_newFrameCallbackCookie = pCookie; }
85  virtual void setPropertyChangedCallback(PropertyChangedCallback handler, void* pCookie) { m_propertyChangedCallback = handler; m_propertyChangedCookie = pCookie; }
86 
87  virtual void notifyAllProperties() { return; }
88 
89  virtual OniStatus convertDepthToColorCoordinates(StreamBase* /*colorStream*/, int /*depthX*/, int /*depthY*/, OniDepthPixel /*depthZ*/, int* /*pColorX*/, int* /*pColorY*/) { return ONI_STATUS_NOT_SUPPORTED; }
90 
91 protected:
92  void raiseNewFrame(OniFrame* pFrame) { (*m_newFrameCallback)(this, pFrame, m_newFrameCallbackCookie); }
93  void raisePropertyChanged(int propertyId, const void* data, int dataSize) { (*m_propertyChangedCallback)(this, propertyId, data, dataSize, m_propertyChangedCookie); }
94 
95  StreamServices& getServices() { return *m_pServices; }
96 
97 private:
103 };
104 
106 {
107 public:
109  virtual ~DeviceBase() {}
110 
111  virtual OniStatus getSensorInfoList(OniSensorInfo** pSensorInfos, int* numSensors) = 0;
112 
113  virtual StreamBase* createStream(OniSensorType) = 0;
114  virtual void destroyStream(StreamBase* pStream) = 0;
115 
116  virtual OniStatus setProperty(int /*propertyId*/, const void* /*data*/, int /*dataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
117  virtual OniStatus getProperty(int /*propertyId*/, void* /*data*/, int* /*pDataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
118  virtual OniBool isPropertySupported(int /*propertyId*/) {return FALSE;}
119  virtual OniStatus invoke(int /*commandId*/, void* /*data*/, int /*dataSize*/) {return ONI_STATUS_NOT_IMPLEMENTED;}
120  virtual OniBool isCommandSupported(int /*commandId*/) {return FALSE;}
122 
123  virtual void setPropertyChangedCallback(PropertyChangedCallback handler, void* pCookie) { m_propertyChangedCallback = handler; m_propertyChangedCookie = pCookie; }
124  virtual void notifyAllProperties() { return; }
125 
127 
128 protected:
129  void raisePropertyChanged(int propertyId, const void* data, int dataSize) { (*m_propertyChangedCallback)(this, propertyId, data, dataSize, m_propertyChangedCookie); }
130 
131 private:
134 };
135 
137 {
138 public:
139  DriverServices(OniDriverServices* pDriverServices) : m_pDriverServices(pDriverServices) {}
140 
141  void errorLoggerAppend(const char* format, ...)
142  {
143  va_list args;
144  va_start(args, format);
145  m_pDriverServices->errorLoggerAppend(m_pDriverServices->driverServices, format, args);
146  va_end(args);
147  }
148 
150  {
151  m_pDriverServices->errorLoggerClear(m_pDriverServices->driverServices);
152  }
153 
154  void log(int severity, const char* file, int line, const char* mask, const char* message)
155  {
156  m_pDriverServices->log(m_pDriverServices->driverServices, severity, file, line, mask, message);
157  }
158 
159 private:
161 };
162 
164 {
165 public:
166  DriverBase(OniDriverServices* pDriverServices) : m_services(pDriverServices)
167  {}
168 
169  virtual ~DriverBase() {}
170 
171  virtual OniStatus initialize(DeviceConnectedCallback connectedCallback, DeviceDisconnectedCallback disconnectedCallback, DeviceStateChangedCallback deviceStateChangedCallback, void* pCookie)
172  {
173  m_deviceConnectedEvent = connectedCallback;
174  m_deviceDisconnectedEvent = disconnectedCallback;
175  m_deviceStateChangedEvent = deviceStateChangedCallback;
176  m_pCookie = pCookie;
177  return ONI_STATUS_OK;
178  }
179 
180  virtual DeviceBase* deviceOpen(const char* uri, const char* mode) = 0;
181  virtual void deviceClose(DeviceBase* pDevice) = 0;
182 
183  virtual void shutdown() = 0;
184 
185  virtual OniStatus tryDevice(const char* /*uri*/) { return ONI_STATUS_ERROR;}
186 
187  virtual void* enableFrameSync(StreamBase** /*pStreams*/, int /*streamCount*/) { return NULL; }
188  virtual void disableFrameSync(void* /*frameSyncGroup*/) {}
189 
190 protected:
191  void deviceConnected(const OniDeviceInfo* pInfo) { (m_deviceConnectedEvent)(pInfo, m_pCookie); }
192  void deviceDisconnected(const OniDeviceInfo* pInfo) { (m_deviceDisconnectedEvent)(pInfo, m_pCookie); }
193  void deviceStateChanged(const OniDeviceInfo* pInfo, int errorState) { (m_deviceStateChangedEvent)(pInfo, errorState, m_pCookie); }
194 
195  DriverServices& getServices() { return m_services; }
196 
197 private:
198  DeviceConnectedCallback m_deviceConnectedEvent;
201  void* m_pCookie;
202 
204 };
205 
206 }} // oni::driver
207 
208 #define ONI_EXPORT_DRIVER(DriverClass) \
209  \
210 oni::driver::DriverBase* g_pDriver = NULL; \
211  \
212 /* As Driver */ \
213 ONI_C_API_EXPORT void oniDriverCreate(OniDriverServices* driverServices) { \
214  g_pDriver = XN_NEW(DriverClass, driverServices); \
215 } \
216 ONI_C_API_EXPORT void oniDriverDestroy() \
217 { \
218  g_pDriver->shutdown(); \
219  XN_DELETE(g_pDriver); g_pDriver = NULL; \
220 } \
221 ONI_C_API_EXPORT OniStatus oniDriverInitialize(oni::driver::DeviceConnectedCallback deviceConnectedCallback, \
222  oni::driver::DeviceDisconnectedCallback deviceDisconnectedCallback, \
223  oni::driver::DeviceStateChangedCallback deviceStateChangedCallback, \
224  void* pCookie) \
225 { \
226  return g_pDriver->initialize(deviceConnectedCallback, deviceDisconnectedCallback, deviceStateChangedCallback, pCookie); \
227 } \
228  \
229 ONI_C_API_EXPORT OniStatus oniDriverTryDevice(const char* uri) \
230 { \
231  return g_pDriver->tryDevice(uri); \
232 } \
233  \
234 /* As Device */ \
235 ONI_C_API_EXPORT oni::driver::DeviceBase* oniDriverDeviceOpen(const char* uri, const char* mode) \
236 { \
237  return g_pDriver->deviceOpen(uri, mode); \
238 } \
239 ONI_C_API_EXPORT void oniDriverDeviceClose(oni::driver::DeviceBase* pDevice) \
240 { \
241  g_pDriver->deviceClose(pDevice); \
242 } \
243  \
244 ONI_C_API_EXPORT OniStatus oniDriverDeviceGetSensorInfoList(oni::driver::DeviceBase* pDevice, OniSensorInfo** pSensorInfos, \
245  int* numSensors) \
246 { \
247  return pDevice->getSensorInfoList(pSensorInfos, numSensors); \
248 } \
249  \
250 ONI_C_API_EXPORT oni::driver::StreamBase* oniDriverDeviceCreateStream(oni::driver::DeviceBase* pDevice, \
251  OniSensorType sensorType) \
252 { \
253  return pDevice->createStream(sensorType); \
254 } \
255  \
256 ONI_C_API_EXPORT void oniDriverDeviceDestroyStream(oni::driver::DeviceBase* pDevice, oni::driver::StreamBase* pStream) \
257 { \
258  return pDevice->destroyStream(pStream); \
259 } \
260  \
261 ONI_C_API_EXPORT OniStatus oniDriverDeviceSetProperty(oni::driver::DeviceBase* pDevice, int propertyId, \
262  const void* data, int dataSize) \
263 { \
264  return pDevice->setProperty(propertyId, data, dataSize); \
265 } \
266 ONI_C_API_EXPORT OniStatus oniDriverDeviceGetProperty(oni::driver::DeviceBase* pDevice, int propertyId, \
267  void* data, int* pDataSize) \
268 { \
269  return pDevice->getProperty(propertyId, data, pDataSize); \
270 } \
271 ONI_C_API_EXPORT OniBool oniDriverDeviceIsPropertySupported(oni::driver::DeviceBase* pDevice, int propertyId) \
272 { \
273  return pDevice->isPropertySupported(propertyId); \
274 } \
275 ONI_C_API_EXPORT void oniDriverDeviceSetPropertyChangedCallback(oni::driver::DeviceBase* pDevice, \
276  oni::driver::PropertyChangedCallback handler, void* pCookie) \
277 { \
278  pDevice->setPropertyChangedCallback(handler, pCookie); \
279 } \
280 ONI_C_API_EXPORT void oniDriverDeviceNotifyAllProperties(oni::driver::DeviceBase* pDevice) \
281 { \
282  pDevice->notifyAllProperties(); \
283 } \
284 ONI_C_API_EXPORT OniStatus oniDriverDeviceInvoke(oni::driver::DeviceBase* pDevice, int commandId, \
285  void* data, int dataSize) \
286 { \
287  return pDevice->invoke(commandId, data, dataSize); \
288 } \
289 ONI_C_API_EXPORT OniBool oniDriverDeviceIsCommandSupported(oni::driver::DeviceBase* pDevice, int commandId) \
290 { \
291  return pDevice->isCommandSupported(commandId); \
292 } \
293 ONI_C_API_EXPORT OniStatus oniDriverDeviceTryManualTrigger(oni::driver::DeviceBase* pDevice) \
294 { \
295  return pDevice->tryManualTrigger(); \
296 } \
297 ONI_C_API_EXPORT OniBool oniDriverDeviceIsImageRegistrationModeSupported(oni::driver::DeviceBase* pDevice, \
298  OniImageRegistrationMode mode) \
299 { \
300  return pDevice->isImageRegistrationModeSupported(mode); \
301 } \
302  \
303 /* As Stream */ \
304 ONI_C_API_EXPORT void oniDriverStreamSetServices(oni::driver::StreamBase* pStream, OniStreamServices* pServices) \
305 { \
306  pStream->setServices((oni::driver::StreamServices*)pServices); \
307 } \
308  \
309 ONI_C_API_EXPORT OniStatus oniDriverStreamSetProperty(oni::driver::StreamBase* pStream, int propertyId, \
310  const void* data, int dataSize) \
311 { \
312  return pStream->setProperty(propertyId, data, dataSize); \
313 } \
314 ONI_C_API_EXPORT OniStatus oniDriverStreamGetProperty(oni::driver::StreamBase* pStream, int propertyId, void* data, \
315  int* pDataSize) \
316 { \
317  return pStream->getProperty(propertyId, data, pDataSize); \
318 } \
319 ONI_C_API_EXPORT OniBool oniDriverStreamIsPropertySupported(oni::driver::StreamBase* pStream, int propertyId) \
320 { \
321  return pStream->isPropertySupported(propertyId); \
322 } \
323 ONI_C_API_EXPORT void oniDriverStreamSetPropertyChangedCallback(oni::driver::StreamBase* pStream, \
324  oni::driver::PropertyChangedCallback handler, void* pCookie) \
325 { \
326  pStream->setPropertyChangedCallback(handler, pCookie); \
327 } \
328 ONI_C_API_EXPORT void oniDriverStreamNotifyAllProperties(oni::driver::StreamBase* pStream) \
329 { \
330  pStream->notifyAllProperties(); \
331 } \
332 ONI_C_API_EXPORT OniStatus oniDriverStreamInvoke(oni::driver::StreamBase* pStream, int commandId, \
333  void* data, int dataSize) \
334 { \
335  return pStream->invoke(commandId, data, dataSize); \
336 } \
337 ONI_C_API_EXPORT OniBool oniDriverStreamIsCommandSupported(oni::driver::StreamBase* pStream, int commandId) \
338 { \
339  return pStream->isCommandSupported(commandId); \
340 } \
341  \
342 ONI_C_API_EXPORT OniStatus oniDriverStreamStart(oni::driver::StreamBase* pStream) \
343 { \
344  return pStream->start(); \
345 } \
346 ONI_C_API_EXPORT void oniDriverStreamStop(oni::driver::StreamBase* pStream) \
347 { \
348  pStream->stop(); \
349 } \
350  \
351 ONI_C_API_EXPORT int oniDriverStreamGetRequiredFrameSize(oni::driver::StreamBase* pStream) \
352 { \
353  return pStream->getRequiredFrameSize(); \
354 } \
355  \
356 ONI_C_API_EXPORT void oniDriverStreamSetNewFrameCallback(oni::driver::StreamBase* pStream, \
357  oni::driver::NewFrameCallback handler, void* pCookie) \
358 { \
359  pStream->setNewFrameCallback(handler, pCookie); \
360 } \
361  \
362 ONI_C_API_EXPORT OniStatus oniDriverStreamConvertDepthToColorCoordinates(oni::driver::StreamBase* pDepthStream, \
363  oni::driver::StreamBase* pColorStream, int depthX, int depthY, OniDepthPixel depthZ, int* pColorX, int* pColorY) \
364 { \
365  return pDepthStream->convertDepthToColorCoordinates(pColorStream, depthX, depthY, depthZ, pColorX, pColorY); \
366 } \
367  \
368 ONI_C_API_EXPORT void* oniDriverEnableFrameSync(oni::driver::StreamBase** pStreams, int streamCount) \
369 { \
370  return g_pDriver->enableFrameSync(pStreams, streamCount); \
371 } \
372  \
373 ONI_C_API_EXPORT void oniDriverDisableFrameSync(void* frameSyncGroup) \
374 { \
375  return g_pDriver->disableFrameSync(frameSyncGroup); \
376 } \
377 
378 #endif // _ONI_DRIVER_API_H_
NewFrameCallback m_newFrameCallback
Definition: OniDriverAPI.h:99
virtual OniBool isCommandSupported(int)
Definition: OniDriverAPI.h:77
OniImageRegistrationMode
Definition: OniCEnums.h:72
#define FALSE
Definition: OniCTypes.h:34
virtual OniStatus getProperty(int, void *, int *)
Definition: OniDriverAPI.h:117
PropertyChangedCallback m_propertyChangedCallback
Definition: OniDriverAPI.h:101
void errorLoggerAppend(const char *format,...)
Definition: OniDriverAPI.h:141
void log(int severity, const char *file, int line, const char *mask, const char *message)
Definition: OniDriverAPI.h:154
DriverServices(OniDriverServices *pDriverServices)
Definition: OniDriverAPI.h:139
void raiseNewFrame(OniFrame *pFrame)
Definition: OniDriverAPI.h:92
void deviceStateChanged(const OniDeviceInfo *pInfo, int errorState)
Definition: OniDriverAPI.h:193
int OniBool
Definition: OniCTypes.h:28
DeviceStateChangedCallback m_deviceStateChangedEvent
Definition: OniDriverAPI.h:200
virtual void * enableFrameSync(StreamBase **, int)
Definition: OniDriverAPI.h:187
void addFrameRef(OniFrame *pFrame)
Definition: OniDriverAPI.h:54
StreamServices * m_pServices
Definition: OniDriverAPI.h:98
virtual void setPropertyChangedCallback(PropertyChangedCallback handler, void *pCookie)
Definition: OniDriverAPI.h:85
virtual OniStatus invoke(int, void *, int)
Definition: OniDriverAPI.h:76
virtual OniBool isPropertySupported(int)
Definition: OniDriverAPI.h:75
OniDriverServices * m_pDriverServices
Definition: OniDriverAPI.h:160
virtual OniStatus tryDevice(const char *)
Definition: OniDriverAPI.h:185
DriverServices & getServices()
Definition: OniDriverAPI.h:195
StreamServices & getServices()
Definition: OniDriverAPI.h:95
virtual OniStatus setProperty(int, const void *, int)
Definition: OniDriverAPI.h:116
virtual int getRequiredFrameSize()
Definition: OniDriverAPI.h:79
virtual OniStatus convertDepthToColorCoordinates(StreamBase *, int, int, OniDepthPixel, int *, int *)
Definition: OniDriverAPI.h:89
DeviceConnectedCallback m_deviceConnectedEvent
Definition: OniDriverAPI.h:198
virtual void setServices(StreamServices *pStreamServices)
Definition: OniDriverAPI.h:71
virtual OniBool isImageRegistrationModeSupported(OniImageRegistrationMode mode)
Definition: OniDriverAPI.h:126
virtual OniBool isCommandSupported(int)
Definition: OniDriverAPI.h:120
DriverBase(OniDriverServices *pDriverServices)
Definition: OniDriverAPI.h:166
virtual OniStatus getProperty(int, void *, int *)
Definition: OniDriverAPI.h:74
OniSensorType
Definition: OniCEnums.h:38
void(ONI_CALLBACK_TYPE * PropertyChangedCallback)(void *sender, int propertyId, const void *data, int dataSize, void *pCookie)
Definition: OniDriverAPI.h:39
virtual void notifyAllProperties()
Definition: OniDriverAPI.h:87
void raisePropertyChanged(int propertyId, const void *data, int dataSize)
Definition: OniDriverAPI.h:93
PropertyChangedCallback m_propertyChangedCallback
Definition: OniDriverAPI.h:132
void(ONI_CALLBACK_TYPE * NewFrameCallback)(StreamBase *streamId, OniFrame *, void *pCookie)
Definition: OniDriverAPI.h:38
void deviceDisconnected(const OniDeviceInfo *pInfo)
Definition: OniDriverAPI.h:192
void deviceConnected(const OniDeviceInfo *pInfo)
Definition: OniDriverAPI.h:191
virtual OniStatus initialize(DeviceConnectedCallback connectedCallback, DeviceDisconnectedCallback disconnectedCallback, DeviceStateChangedCallback deviceStateChangedCallback, void *pCookie)
Definition: OniDriverAPI.h:171
virtual void disableFrameSync(void *)
Definition: OniDriverAPI.h:188
DriverServices m_services
Definition: OniDriverAPI.h:203
virtual OniStatus tryManualTrigger()
Definition: OniDriverAPI.h:121
virtual void setNewFrameCallback(NewFrameCallback handler, void *pCookie)
Definition: OniDriverAPI.h:84
typedef void(ONI_CALLBACK_TYPE *DeviceConnectedCallback)(const OniDeviceInfo *
virtual void setPropertyChangedCallback(PropertyChangedCallback handler, void *pCookie)
Definition: OniDriverAPI.h:123
#define ONI_CALLBACK_TYPE
virtual OniStatus invoke(int, void *, int)
Definition: OniDriverAPI.h:119
uint16_t OniDepthPixel
Definition: OniCTypes.h:143
DeviceDisconnectedCallback m_deviceDisconnectedEvent
Definition: OniDriverAPI.h:199
virtual void notifyAllProperties()
Definition: OniDriverAPI.h:124
virtual OniStatus setProperty(int, const void *, int)
Definition: OniDriverAPI.h:73
void raisePropertyChanged(int propertyId, const void *data, int dataSize)
Definition: OniDriverAPI.h:129
OniFrame *ONI_CALLBACK_TYPE * acquireFrame(void *streamServices)
void(ONI_CALLBACK_TYPE * DeviceStateChangedCallback)(const OniDeviceInfo *deviceId, int errorState, void *pCookie)
Definition: OniDriverAPI.h:37
OniStatus
Definition: OniCEnums.h:25
void releaseFrame(OniFrame *pFrame)
Definition: OniDriverAPI.h:59
def handler(signum, frame)
void * pCookie
Definition: OniDriverAPI.h:35
virtual OniBool isPropertySupported(int)
Definition: OniDriverAPI.h:118
void(ONI_CALLBACK_TYPE * DeviceDisconnectedCallback)(const OniDeviceInfo *, void *pCookie)
Definition: OniDriverAPI.h:36


libfreenect
Author(s): Hector Martin, Josh Blake, Kyle Machulis, OpenKinect community
autogenerated on Thu Jun 6 2019 19:25:38