Create one generic callback dispatcher that can handle all our
callbacks. This minimize code duplication and allows us much easier to add and maintain callbacks.
This commit is contained in:
parent
5d4ee9a4be
commit
148fd52c76
7 changed files with 187 additions and 454 deletions
|
@ -11,83 +11,54 @@
|
||||||
|
|
||||||
using namespace TelldusCore;
|
using namespace TelldusCore;
|
||||||
|
|
||||||
TDDeviceEventDispatcher::TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int id, int m, const std::string &strD, TelldusCore::EventRef cbDone)
|
TDEventDispatcher::TDEventDispatcher(EventDataRef cbd, CallbackStruct *cb, EventRef cbDone)
|
||||||
:Thread(), d(data), deviceId(id), method(m), strData(strD), doneRunning(false), callbackExecuted(cbDone)
|
:Thread(), doneRunning(false), callbackData(cbd), callback(cb), callbackExecuted(cbDone)
|
||||||
{
|
{
|
||||||
this->startAndLock(&d->mutex);
|
this->startAndLock(&callback->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
TDDeviceEventDispatcher::~TDDeviceEventDispatcher() {
|
TDEventDispatcher::~TDEventDispatcher() {
|
||||||
this->wait();
|
this->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TDDeviceEventDispatcher::done() const {
|
bool TDEventDispatcher::done() const {
|
||||||
return doneRunning;
|
return doneRunning;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TDDeviceEventDispatcher::run() {
|
void TDEventDispatcher::run() {
|
||||||
char *str = wrapStdString(strData);
|
this->fireEvent();
|
||||||
d->event(deviceId, method, strData.c_str(), d->id, d->context);
|
|
||||||
doneRunning = true;
|
doneRunning = true;
|
||||||
callbackExecuted->signal();
|
callbackExecuted->signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
TDDeviceChangeEventDispatcher::TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int id, int event, int type, TelldusCore::EventRef cbDone)
|
void TDEventDispatcher::fireEvent() {
|
||||||
:Thread(), d(data), deviceId(id), changeEvent(event), changeType(type), doneRunning(false), callbackExecuted(cbDone)
|
if (callback->type == CallbackStruct::DeviceEvent) {
|
||||||
{
|
DeviceEventCallbackData *data = dynamic_cast<DeviceEventCallbackData *>(callbackData.get());
|
||||||
this->startAndLock(&d->mutex);
|
if (!data) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
((TDDeviceEvent)callback->event)(data->deviceId, data->deviceState, data->deviceStateValue.c_str(), callback->id, callback->context);
|
||||||
|
|
||||||
TDDeviceChangeEventDispatcher::~TDDeviceChangeEventDispatcher() {
|
} else if (callback->type == CallbackStruct::DeviceChangeEvent) {
|
||||||
this->wait();
|
DeviceChangeEventCallbackData *data = dynamic_cast<DeviceChangeEventCallbackData *>(callbackData.get());
|
||||||
}
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
((TDDeviceChangeEvent)callback->event)(data->deviceId, data->changeEvent, data->changeType, callback->id, callback->context);
|
||||||
|
|
||||||
bool TDDeviceChangeEventDispatcher::done() const {
|
} else if (callback->type == CallbackStruct::RawDeviceEvent) {
|
||||||
return doneRunning;
|
RawDeviceEventCallbackData *data = dynamic_cast<RawDeviceEventCallbackData *>(callbackData.get());
|
||||||
}
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
((TDRawDeviceEvent)callback->event)(data->data.c_str(), data->controllerId, callback->id, callback->context);
|
||||||
|
|
||||||
void TDDeviceChangeEventDispatcher::run() {
|
} else if (callback->type == CallbackStruct::SensorEvent) {
|
||||||
d->event(deviceId, changeEvent, changeType, d->id, d->context);
|
SensorEventCallbackData *data = dynamic_cast<SensorEventCallbackData *>(callbackData.get());
|
||||||
doneRunning = true;
|
if (!data) {
|
||||||
callbackExecuted->signal();
|
return;
|
||||||
}
|
}
|
||||||
|
((TDSensorEvent)callback->event)(data->protocol.c_str(), data->model.c_str(), data->id, data->dataType, data->value.c_str(), data->timestamp, callback->id, callback->context);
|
||||||
|
|
||||||
TDRawDeviceEventDispatcher::TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strD, int id, TelldusCore::EventRef cbDone)
|
}
|
||||||
:Thread(), d(data), controllerId(id), strData(strD), doneRunning(false), callbackExecuted(cbDone)
|
|
||||||
{
|
|
||||||
this->startAndLock(&d->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
TDRawDeviceEventDispatcher::~TDRawDeviceEventDispatcher() {
|
|
||||||
this->wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TDRawDeviceEventDispatcher::done() const {
|
|
||||||
return doneRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TDRawDeviceEventDispatcher::run() {
|
|
||||||
d->event(strData.c_str(), controllerId, d->id, d->context);
|
|
||||||
doneRunning = true;
|
|
||||||
callbackExecuted->signal();
|
|
||||||
}
|
|
||||||
|
|
||||||
TDSensorEventDispatcher::TDSensorEventDispatcher( CallbackStruct<TDSensorEvent> *data, const std::string &p, const std::string &m, int id, int type, const std::string &v, int t, TelldusCore::EventRef cbDone)
|
|
||||||
:Thread(), d(data), protocol(p), model(m), sensorId(id), dataType(type), value(v), timestamp(t), doneRunning(false), callbackExecuted(cbDone)
|
|
||||||
{
|
|
||||||
this->startAndLock(&d->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
TDSensorEventDispatcher::~TDSensorEventDispatcher() {
|
|
||||||
this->wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TDSensorEventDispatcher::done() const {
|
|
||||||
return doneRunning;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TDSensorEventDispatcher::run() {
|
|
||||||
d->event(protocol.c_str(), model.c_str(), sensorId, dataType, value.c_str(), timestamp, d->id, d->context);
|
|
||||||
doneRunning = true;
|
|
||||||
callbackExecuted->signal();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,71 +17,77 @@
|
||||||
#include "telldus-core.h"
|
#include "telldus-core.h"
|
||||||
|
|
||||||
namespace TelldusCore {
|
namespace TelldusCore {
|
||||||
template <typename T> struct CallbackStruct {
|
|
||||||
|
/*template <typename T> struct CallbackStruct {
|
||||||
T event;
|
T event;
|
||||||
int id;
|
int id;
|
||||||
void *context;
|
void *context;
|
||||||
TelldusCore::Mutex mutex;
|
TelldusCore::Mutex mutex;
|
||||||
|
};*/
|
||||||
|
struct CallbackStruct {
|
||||||
|
enum CallbackType { DeviceEvent, DeviceChangeEvent, RawDeviceEvent, SensorEvent };
|
||||||
|
CallbackType type;
|
||||||
|
void *event;
|
||||||
|
int id;
|
||||||
|
void *context;
|
||||||
|
TelldusCore::Mutex mutex;
|
||||||
|
};
|
||||||
|
/*typedef CallbackStruct<TDDeviceChangeEvent> DeviceChangeEvent;
|
||||||
|
typedef CallbackStruct<TDRawDeviceEvent> RawDeviceEvent;
|
||||||
|
typedef CallbackStruct<TDSensorEvent> SensorEvent;*/
|
||||||
|
|
||||||
|
class CallbackData: public EventDataBase {
|
||||||
|
public:
|
||||||
|
explicit CallbackData(CallbackStruct::CallbackType t) : EventDataBase(), type(t) {}
|
||||||
|
CallbackStruct::CallbackType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TDDeviceEventDispatcher : public Thread {
|
class DeviceEventCallbackData : public CallbackData {
|
||||||
public:
|
public:
|
||||||
TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int deviceId, int method, const std::string &strData, TelldusCore::EventRef cbDone);
|
DeviceEventCallbackData() : CallbackData(CallbackStruct::DeviceEvent) {}
|
||||||
virtual ~TDDeviceEventDispatcher();
|
int deviceId;
|
||||||
bool done() const;
|
int deviceState;
|
||||||
protected:
|
std::string deviceStateValue;
|
||||||
virtual void run();
|
|
||||||
bool doneRunning;
|
|
||||||
private:
|
|
||||||
CallbackStruct<TDDeviceEvent> *d;
|
|
||||||
int deviceId, method;
|
|
||||||
std::string strData;
|
|
||||||
TelldusCore::EventRef callbackExecuted;
|
|
||||||
};
|
};
|
||||||
class TDDeviceChangeEventDispatcher : public Thread {
|
class DeviceChangeEventCallbackData : public CallbackData {
|
||||||
public:
|
public:
|
||||||
TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int deviceId, int changeEvent, int changeType, TelldusCore::EventRef cbDone);
|
DeviceChangeEventCallbackData() : CallbackData(CallbackStruct::DeviceChangeEvent) {}
|
||||||
virtual ~TDDeviceChangeEventDispatcher();
|
int deviceId;
|
||||||
bool done() const;
|
int changeEvent;
|
||||||
protected:
|
int changeType;
|
||||||
virtual void run();
|
|
||||||
bool doneRunning;
|
|
||||||
private:
|
|
||||||
CallbackStruct<TDDeviceChangeEvent> *d;
|
|
||||||
int deviceId, changeEvent, changeType;
|
|
||||||
TelldusCore::EventRef callbackExecuted;
|
|
||||||
};
|
};
|
||||||
class TDRawDeviceEventDispatcher : public Thread {
|
|
||||||
|
class RawDeviceEventCallbackData : public CallbackData {
|
||||||
public:
|
public:
|
||||||
TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strData, int controllerId, TelldusCore::EventRef cbDone);
|
RawDeviceEventCallbackData() : CallbackData(CallbackStruct::RawDeviceEvent) {}
|
||||||
virtual ~TDRawDeviceEventDispatcher();
|
std::string data;
|
||||||
bool done() const;
|
|
||||||
protected:
|
|
||||||
virtual void run();
|
|
||||||
bool doneRunning;
|
|
||||||
private:
|
|
||||||
CallbackStruct<TDRawDeviceEvent> *d;
|
|
||||||
int controllerId;
|
int controllerId;
|
||||||
std::string strData;
|
|
||||||
TelldusCore::EventRef callbackExecuted;
|
|
||||||
};
|
};
|
||||||
class TDSensorEventDispatcher : public Thread {
|
|
||||||
|
class SensorEventCallbackData : public CallbackData {
|
||||||
public:
|
public:
|
||||||
TDSensorEventDispatcher( CallbackStruct<TDSensorEvent> *data, const std::string &protocol, const std::string &model, int id, int dataType, const std::string &value, int timestamp, TelldusCore::EventRef cbDone);
|
SensorEventCallbackData() : CallbackData(CallbackStruct::SensorEvent) {}
|
||||||
virtual ~TDSensorEventDispatcher();
|
|
||||||
bool done() const;
|
|
||||||
protected:
|
|
||||||
virtual void run();
|
|
||||||
bool doneRunning;
|
|
||||||
private:
|
|
||||||
CallbackStruct<TDSensorEvent> *d;
|
|
||||||
std::string protocol;
|
std::string protocol;
|
||||||
std::string model;
|
std::string model;
|
||||||
int sensorId;
|
int id;
|
||||||
int dataType;
|
int dataType;
|
||||||
std::string value;
|
std::string value;
|
||||||
int timestamp;
|
int timestamp;
|
||||||
TelldusCore::EventRef callbackExecuted;
|
};
|
||||||
|
|
||||||
|
class TDEventDispatcher : public Thread {
|
||||||
|
public:
|
||||||
|
TDEventDispatcher(EventDataRef callbackData, CallbackStruct *callback, TelldusCore::EventRef cbDone);
|
||||||
|
virtual ~TDEventDispatcher();
|
||||||
|
bool done() const;
|
||||||
|
protected:
|
||||||
|
virtual void run();
|
||||||
|
bool doneRunning;
|
||||||
|
private:
|
||||||
|
void fireEvent();
|
||||||
|
EventDataRef callbackData;
|
||||||
|
CallbackStruct *callback;
|
||||||
|
EventRef callbackExecuted;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,19 @@
|
||||||
|
|
||||||
using namespace TelldusCore;
|
using namespace TelldusCore;
|
||||||
|
|
||||||
|
typedef std::list<CallbackStruct *> CallbackList;
|
||||||
|
|
||||||
class CallbackMainDispatcher::PrivateData {
|
class CallbackMainDispatcher::PrivateData {
|
||||||
public:
|
public:
|
||||||
EventHandler eventHandler;
|
EventHandler eventHandler;
|
||||||
EventRef stopEvent, generalCallbackEvent, janitor;
|
EventRef stopEvent, generalCallbackEvent, janitor;
|
||||||
|
|
||||||
std::list<std::tr1::shared_ptr<TDDeviceEventDispatcher> > deviceEventThreadList;
|
|
||||||
std::list<std::tr1::shared_ptr<TDDeviceChangeEventDispatcher> > deviceChangeEventThreadList;
|
|
||||||
std::list<std::tr1::shared_ptr<TDRawDeviceEventDispatcher> > rawDeviceEventThreadList;
|
|
||||||
std::list<std::tr1::shared_ptr<TDSensorEventDispatcher> > sensorEventThreadList;
|
|
||||||
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
std::list<std::tr1::shared_ptr<TelldusCore::TDEventDispatcher> > eventThreadList;
|
||||||
|
|
||||||
|
CallbackList callbackList;
|
||||||
|
|
||||||
|
int lastCallbackId;
|
||||||
};
|
};
|
||||||
|
|
||||||
CallbackMainDispatcher::CallbackMainDispatcher()
|
CallbackMainDispatcher::CallbackMainDispatcher()
|
||||||
|
@ -33,6 +35,8 @@ CallbackMainDispatcher::CallbackMainDispatcher()
|
||||||
d->stopEvent = d->eventHandler.addEvent();
|
d->stopEvent = d->eventHandler.addEvent();
|
||||||
d->generalCallbackEvent = d->eventHandler.addEvent();
|
d->generalCallbackEvent = d->eventHandler.addEvent();
|
||||||
d->janitor = d->eventHandler.addEvent(); //Used for cleanups
|
d->janitor = d->eventHandler.addEvent(); //Used for cleanups
|
||||||
|
|
||||||
|
d->lastCallbackId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackMainDispatcher::~CallbackMainDispatcher(void){
|
CallbackMainDispatcher::~CallbackMainDispatcher(void){
|
||||||
|
@ -48,6 +52,42 @@ EventRef CallbackMainDispatcher::retrieveCallbackEvent(){
|
||||||
return d->generalCallbackEvent;
|
return d->generalCallbackEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CallbackMainDispatcher::registerCallback(CallbackStruct::CallbackType type, void *eventFunction, void *context) {
|
||||||
|
TelldusCore::MutexLocker locker(&d->mutex);
|
||||||
|
int id = ++d->lastCallbackId;
|
||||||
|
CallbackStruct *callback = new CallbackStruct;
|
||||||
|
callback->type = type;
|
||||||
|
callback->event = eventFunction;
|
||||||
|
callback->id = id;
|
||||||
|
callback->context = context;
|
||||||
|
d->callbackList.push_back(callback);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CallbackMainDispatcher::unregisterCallback(int callbackId) {
|
||||||
|
CallbackList newEventList;
|
||||||
|
{
|
||||||
|
TelldusCore::MutexLocker locker(&d->mutex);
|
||||||
|
for(CallbackList::iterator callback_it = d->callbackList.begin(); callback_it != d->callbackList.end(); ++callback_it) {
|
||||||
|
if ( (*callback_it)->id != callbackId ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newEventList.splice(newEventList.begin(), d->callbackList, callback_it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newEventList.size()) {
|
||||||
|
CallbackList::iterator it = newEventList.begin();
|
||||||
|
{ //Lock and unlock to make sure no one else uses the object
|
||||||
|
TelldusCore::MutexLocker locker( &(*it)->mutex );
|
||||||
|
}
|
||||||
|
delete (*it);
|
||||||
|
newEventList.erase(it);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void CallbackMainDispatcher::run(){
|
void CallbackMainDispatcher::run(){
|
||||||
|
|
||||||
while(!d->stopEvent->isSignaled()){
|
while(!d->stopEvent->isSignaled()){
|
||||||
|
@ -57,37 +97,17 @@ void CallbackMainDispatcher::run(){
|
||||||
|
|
||||||
if(d->generalCallbackEvent->isSignaled()){
|
if(d->generalCallbackEvent->isSignaled()){
|
||||||
EventDataRef eventData = d->generalCallbackEvent->takeSignal();
|
EventDataRef eventData = d->generalCallbackEvent->takeSignal();
|
||||||
|
|
||||||
DeviceEventCallbackData *decd = dynamic_cast<DeviceEventCallbackData*>(eventData.get());
|
|
||||||
if(decd){
|
|
||||||
std::tr1::shared_ptr<TDDeviceEventDispatcher> ptr(new TDDeviceEventDispatcher(decd->data, decd->deviceId, decd->deviceState, decd->deviceStateValue, d->janitor));
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
d->deviceEventThreadList.push_back(ptr);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceChangeEventCallbackData *dcecd = dynamic_cast<DeviceChangeEventCallbackData*>(eventData.get());
|
CallbackData *cbd = dynamic_cast<CallbackData *>(eventData.get());
|
||||||
if(dcecd){
|
if (!cbd) {
|
||||||
std::tr1::shared_ptr<TDDeviceChangeEventDispatcher> ptr(new TDDeviceChangeEventDispatcher(dcecd->data, dcecd->deviceId, dcecd->eventDeviceChanges, dcecd->eventChangeType, d->janitor));
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
d->deviceChangeEventThreadList.push_back(ptr);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
TelldusCore::MutexLocker locker(&d->mutex);
|
||||||
RawDeviceEventCallbackData *rdecd = dynamic_cast<RawDeviceEventCallbackData*>(eventData.get());
|
for(CallbackList::iterator callback_it = d->callbackList.begin(); callback_it != d->callbackList.end(); ++callback_it) {
|
||||||
if(rdecd){
|
if ( (*callback_it)->type == cbd->type ) {
|
||||||
std::tr1::shared_ptr<TDRawDeviceEventDispatcher> ptr(new TDRawDeviceEventDispatcher(rdecd->data, rdecd->command, rdecd->controllerId, d->janitor));
|
std::tr1::shared_ptr<TelldusCore::TDEventDispatcher> ptr(new TelldusCore::TDEventDispatcher(eventData, *callback_it, d->janitor));
|
||||||
MutexLocker locker(&d->mutex);
|
d->eventThreadList.push_back(ptr);
|
||||||
d->rawDeviceEventThreadList.push_back(ptr);
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SensorEventCallbackData *secd = dynamic_cast<SensorEventCallbackData*>(eventData.get());
|
|
||||||
if(secd){
|
|
||||||
std::tr1::shared_ptr<TDSensorEventDispatcher> ptr(new TDSensorEventDispatcher(secd->data, secd->protocol, secd->model, secd->id, secd->dataType, secd->value, secd->timestamp, d->janitor));
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
d->sensorEventThreadList.push_back(ptr);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d->janitor->isSignaled()) {
|
if (d->janitor->isSignaled()) {
|
||||||
|
@ -107,55 +127,13 @@ void CallbackMainDispatcher::cleanupCallbacks() {
|
||||||
do {
|
do {
|
||||||
again = false;
|
again = false;
|
||||||
MutexLocker locker(&d->mutex);
|
MutexLocker locker(&d->mutex);
|
||||||
std::list<std::tr1::shared_ptr<TDDeviceEventDispatcher> >::iterator it = d->deviceEventThreadList.begin();
|
std::list<std::tr1::shared_ptr<TDEventDispatcher> >::iterator it = d->eventThreadList.begin();
|
||||||
for (;it != d->deviceEventThreadList.end(); ++it) {
|
for (;it != d->eventThreadList.end(); ++it) {
|
||||||
if ((*it)->done()) {
|
if ((*it)->done()) {
|
||||||
d->deviceEventThreadList.erase(it);
|
d->eventThreadList.erase(it);
|
||||||
again = true;
|
again = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (again);
|
} while (again);
|
||||||
|
}
|
||||||
//Device Change Event
|
|
||||||
do {
|
|
||||||
again = false;
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
std::list<std::tr1::shared_ptr<TDDeviceChangeEventDispatcher> >::iterator it = d->deviceChangeEventThreadList.begin();
|
|
||||||
for (;it != d->deviceChangeEventThreadList.end(); ++it) {
|
|
||||||
if ((*it)->done()) {
|
|
||||||
d->deviceChangeEventThreadList.erase(it);
|
|
||||||
again = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (again);
|
|
||||||
|
|
||||||
//Raw Device Event
|
|
||||||
do {
|
|
||||||
again = false;
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
std::list<std::tr1::shared_ptr<TDRawDeviceEventDispatcher> >::iterator it = d->rawDeviceEventThreadList.begin();
|
|
||||||
for (;it != d->rawDeviceEventThreadList.end(); ++it) {
|
|
||||||
if ((*it)->done()) {
|
|
||||||
d->rawDeviceEventThreadList.erase(it);
|
|
||||||
again = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (again);
|
|
||||||
|
|
||||||
//Sensor Event
|
|
||||||
do {
|
|
||||||
again = false;
|
|
||||||
MutexLocker locker(&d->mutex);
|
|
||||||
std::list<std::tr1::shared_ptr<TDSensorEventDispatcher> >::iterator it = d->sensorEventThreadList.begin();
|
|
||||||
for (;it != d->sensorEventThreadList.end(); ++it) {
|
|
||||||
if ((*it)->done()) {
|
|
||||||
d->sensorEventThreadList.erase(it);
|
|
||||||
again = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (again);
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,39 +16,6 @@
|
||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
|
|
||||||
namespace TelldusCore {
|
namespace TelldusCore {
|
||||||
class DeviceChangeEventCallbackData : public EventDataBase {
|
|
||||||
public:
|
|
||||||
CallbackStruct<TDDeviceChangeEvent> *data;
|
|
||||||
int deviceId;
|
|
||||||
int eventDeviceChanges;
|
|
||||||
int eventChangeType;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DeviceEventCallbackData : public EventDataBase {
|
|
||||||
public:
|
|
||||||
CallbackStruct<TDDeviceEvent> *data;
|
|
||||||
int deviceId;
|
|
||||||
int deviceState;
|
|
||||||
std::string deviceStateValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RawDeviceEventCallbackData : public EventDataBase {
|
|
||||||
public:
|
|
||||||
CallbackStruct<TDRawDeviceEvent> *data;
|
|
||||||
int controllerId;
|
|
||||||
std::string command;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SensorEventCallbackData : public EventDataBase {
|
|
||||||
public:
|
|
||||||
CallbackStruct<TDSensorEvent> *data;
|
|
||||||
std::string protocol;
|
|
||||||
std::string model;
|
|
||||||
int id;
|
|
||||||
int dataType;
|
|
||||||
std::string value;
|
|
||||||
int timestamp;
|
|
||||||
};
|
|
||||||
|
|
||||||
class CallbackMainDispatcher : public Thread
|
class CallbackMainDispatcher : public Thread
|
||||||
{
|
{
|
||||||
|
@ -57,7 +24,10 @@ namespace TelldusCore {
|
||||||
~CallbackMainDispatcher(void);
|
~CallbackMainDispatcher(void);
|
||||||
|
|
||||||
EventRef retrieveCallbackEvent();
|
EventRef retrieveCallbackEvent();
|
||||||
|
|
||||||
|
int registerCallback( TelldusCore::CallbackStruct::CallbackType type, void *eventFunction, void *context );
|
||||||
|
bool unregisterCallback( int callbackId );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|
|
@ -9,23 +9,9 @@
|
||||||
|
|
||||||
using namespace TelldusCore;
|
using namespace TelldusCore;
|
||||||
|
|
||||||
typedef CallbackStruct<TDDeviceEvent> DeviceEvent;
|
|
||||||
typedef CallbackStruct<TDDeviceChangeEvent> DeviceChangeEvent;
|
|
||||||
typedef CallbackStruct<TDRawDeviceEvent> RawDeviceEvent;
|
|
||||||
typedef CallbackStruct<TDSensorEvent> SensorEvent;
|
|
||||||
typedef std::list<DeviceEvent *> DeviceEventList;
|
|
||||||
typedef std::list<DeviceChangeEvent *> DeviceChangeList;
|
|
||||||
typedef std::list<RawDeviceEvent *> RawDeviceEventList;
|
|
||||||
typedef std::list<SensorEvent *> SensorEventList;
|
|
||||||
|
|
||||||
class Client::PrivateData {
|
class Client::PrivateData {
|
||||||
public:
|
public:
|
||||||
int lastCallbackId;
|
|
||||||
DeviceEventList deviceEventList;
|
|
||||||
DeviceChangeList deviceChangeEventList;
|
|
||||||
Socket eventSocket;
|
Socket eventSocket;
|
||||||
RawDeviceEventList rawDeviceEventList;
|
|
||||||
SensorEventList sensorEventList;
|
|
||||||
bool running, sensorCached, controllerCached;
|
bool running, sensorCached, controllerCached;
|
||||||
std::wstring sensorCache, controllerCache;
|
std::wstring sensorCache, controllerCache;
|
||||||
TelldusCore::Mutex mutex;
|
TelldusCore::Mutex mutex;
|
||||||
|
@ -39,7 +25,6 @@ Client::Client()
|
||||||
: Thread()
|
: Thread()
|
||||||
{
|
{
|
||||||
d = new PrivateData;
|
d = new PrivateData;
|
||||||
d->lastCallbackId = 0;
|
|
||||||
d->running = true;
|
d->running = true;
|
||||||
d->sensorCached = false;
|
d->sensorCached = false;
|
||||||
d->controllerCached = false;
|
d->controllerCached = false;
|
||||||
|
@ -70,63 +55,6 @@ Client *Client::getInstance() {
|
||||||
return Client::instance;
|
return Client::instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::callbackDeviceEvent(int deviceId, int deviceState, const std::wstring &deviceStateValue){
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(DeviceEventList::iterator callback_it = d->deviceEventList.begin(); callback_it != d->deviceEventList.end(); ++callback_it) {
|
|
||||||
DeviceEventCallbackData *deviceEventCallbackData = new DeviceEventCallbackData();
|
|
||||||
deviceEventCallbackData->data = *callback_it;
|
|
||||||
deviceEventCallbackData->deviceId = deviceId;
|
|
||||||
deviceEventCallbackData->deviceState = deviceState;
|
|
||||||
deviceEventCallbackData->deviceStateValue = TelldusCore::wideToString(deviceStateValue);
|
|
||||||
|
|
||||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(deviceEventCallbackData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::callbackDeviceChangeEvent(int deviceId, int eventDeviceChanges, int eventChangeType){
|
|
||||||
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(DeviceChangeList::iterator callback_it = d->deviceChangeEventList.begin(); callback_it != d->deviceChangeEventList.end(); ++callback_it) {
|
|
||||||
DeviceChangeEventCallbackData *deviceChangeEventCallbackData = new DeviceChangeEventCallbackData();
|
|
||||||
deviceChangeEventCallbackData->data = *callback_it;
|
|
||||||
deviceChangeEventCallbackData->deviceId = deviceId;
|
|
||||||
deviceChangeEventCallbackData->eventDeviceChanges = eventDeviceChanges;
|
|
||||||
deviceChangeEventCallbackData->eventChangeType = eventChangeType;
|
|
||||||
|
|
||||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(deviceChangeEventCallbackData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::callbackRawEvent(std::wstring command, int controllerId) {
|
|
||||||
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(RawDeviceEventList::iterator callback_it = d->rawDeviceEventList.begin(); callback_it != d->rawDeviceEventList.end(); ++callback_it) {
|
|
||||||
RawDeviceEventCallbackData *rawDeviceEventCallbackData = new RawDeviceEventCallbackData();
|
|
||||||
rawDeviceEventCallbackData->data = *callback_it;
|
|
||||||
rawDeviceEventCallbackData->controllerId = controllerId;
|
|
||||||
rawDeviceEventCallbackData->command = TelldusCore::wideToString(command);
|
|
||||||
|
|
||||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(rawDeviceEventCallbackData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::callbackSensorEvent(const std::wstring &protocol, const std::wstring &model, int id, int dataType, const std::wstring &value, int timestamp) {
|
|
||||||
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(SensorEventList::iterator callback_it = d->sensorEventList.begin(); callback_it != d->sensorEventList.end(); ++callback_it) {
|
|
||||||
SensorEventCallbackData *sensorEventCallbackData = new SensorEventCallbackData();
|
|
||||||
sensorEventCallbackData->data = *callback_it;
|
|
||||||
sensorEventCallbackData->protocol = TelldusCore::wideToString(protocol);
|
|
||||||
sensorEventCallbackData->model = TelldusCore::wideToString(model);
|
|
||||||
sensorEventCallbackData->id = id;
|
|
||||||
sensorEventCallbackData->dataType = dataType;
|
|
||||||
sensorEventCallbackData->value = TelldusCore::wideToString(value);
|
|
||||||
sensorEventCallbackData->timestamp = timestamp;
|
|
||||||
|
|
||||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(sensorEventCallbackData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Client::getBoolFromService(const Message &msg) {
|
bool Client::getBoolFromService(const Message &msg) {
|
||||||
return getIntegerFromService(msg) == TELLSTICK_SUCCESS;
|
return getIntegerFromService(msg) == TELLSTICK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -144,48 +72,8 @@ std::wstring Client::getWStringFromService(const Message &msg) {
|
||||||
return Message::takeString(&response);
|
return Message::takeString(&response);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::registerDeviceEvent( TDDeviceEvent eventFunction, void *context ) {
|
int Client::registerEvent( CallbackStruct::CallbackType type, void *eventFunction, void *context ) {
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
return d->callbackMainDispatcher.registerCallback(type, eventFunction, context );
|
||||||
int id = ++d->lastCallbackId;
|
|
||||||
DeviceEvent *callback = new DeviceEvent;
|
|
||||||
callback->event = eventFunction;
|
|
||||||
callback->id = id;
|
|
||||||
callback->context = context;
|
|
||||||
d->deviceEventList.push_back(callback);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Client::registerDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context ) {
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
int id = ++d->lastCallbackId;
|
|
||||||
DeviceChangeEvent *callback = new DeviceChangeEvent;
|
|
||||||
callback->event = eventFunction;
|
|
||||||
callback->id = id;
|
|
||||||
callback->context = context;
|
|
||||||
d->deviceChangeEventList.push_back(callback);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Client::registerRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context ) {
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
int id = ++d->lastCallbackId;
|
|
||||||
RawDeviceEvent *callback = new RawDeviceEvent;
|
|
||||||
callback->event = eventFunction;
|
|
||||||
callback->id = id;
|
|
||||||
callback->context = context;
|
|
||||||
d->rawDeviceEventList.push_back(callback);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Client::registerSensorEvent( TDSensorEvent eventFunction, void *context ) {
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
int id = ++d->lastCallbackId;
|
|
||||||
SensorEvent *callback = new SensorEvent;
|
|
||||||
callback->event = eventFunction;
|
|
||||||
callback->id = id;
|
|
||||||
callback->context = context;
|
|
||||||
d->sensorEventList.push_back(callback);
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::run(){
|
void Client::run(){
|
||||||
|
@ -209,32 +97,36 @@ void Client::run(){
|
||||||
//a message arrived
|
//a message arrived
|
||||||
std::wstring type = Message::takeString(&clientMessage);
|
std::wstring type = Message::takeString(&clientMessage);
|
||||||
if(type == L"TDDeviceChangeEvent"){
|
if(type == L"TDDeviceChangeEvent"){
|
||||||
int deviceId = Message::takeInt(&clientMessage);
|
DeviceChangeEventCallbackData *data = new DeviceChangeEventCallbackData();
|
||||||
int eventDeviceChanges = Message::takeInt(&clientMessage);
|
data->deviceId = Message::takeInt(&clientMessage);
|
||||||
int eventChangeType = Message::takeInt(&clientMessage);
|
data->changeEvent = Message::takeInt(&clientMessage);
|
||||||
callbackDeviceChangeEvent(deviceId, eventDeviceChanges, eventChangeType);
|
data->changeType = Message::takeInt(&clientMessage);
|
||||||
}
|
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||||
else if(type == L"TDDeviceEvent"){
|
|
||||||
int deviceId = Message::takeInt(&clientMessage);
|
} else if(type == L"TDDeviceEvent"){
|
||||||
int eventState = Message::takeInt(&clientMessage);
|
DeviceEventCallbackData *data = new DeviceEventCallbackData();
|
||||||
std::wstring eventValue = Message::takeString(&clientMessage);
|
data->deviceId = Message::takeInt(&clientMessage);
|
||||||
callbackDeviceEvent(deviceId, eventState, eventValue);
|
data->deviceState = Message::takeInt(&clientMessage);
|
||||||
}
|
data->deviceStateValue = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||||
else if(type == L"TDRawDeviceEvent"){
|
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||||
std::wstring command = Message::takeString(&clientMessage);
|
|
||||||
int controllerId = Message::takeInt(&clientMessage);
|
} else if(type == L"TDRawDeviceEvent"){
|
||||||
callbackRawEvent(command, controllerId);
|
RawDeviceEventCallbackData *data = new RawDeviceEventCallbackData();
|
||||||
}
|
data->data = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||||
else if(type == L"TDSensorEvent"){
|
data->controllerId = Message::takeInt(&clientMessage);
|
||||||
std::wstring protocol = Message::takeString(&clientMessage);
|
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||||
std::wstring model = Message::takeString(&clientMessage);
|
|
||||||
int sensorId = Message::takeInt(&clientMessage);
|
} else if(type == L"TDSensorEvent"){
|
||||||
int dataType = Message::takeInt(&clientMessage);
|
SensorEventCallbackData *data = new SensorEventCallbackData();
|
||||||
std::wstring value = Message::takeString(&clientMessage);
|
data->protocol = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||||
int timestamp = Message::takeInt(&clientMessage);
|
data->model = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||||
callbackSensorEvent(protocol, model, sensorId, dataType, value, timestamp);
|
data->id = Message::takeInt(&clientMessage);
|
||||||
}
|
data->dataType = Message::takeInt(&clientMessage);
|
||||||
else{
|
data->value = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||||
|
data->timestamp = Message::takeInt(&clientMessage);
|
||||||
|
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||||
|
|
||||||
|
} else {
|
||||||
clientMessage = L""; //cleanup, if message contained garbage/unhandled data
|
clientMessage = L""; //cleanup, if message contained garbage/unhandled data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,85 +178,7 @@ void Client::stopThread(){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::unregisterCallback( int callbackId ) {
|
bool Client::unregisterCallback( int callbackId ) {
|
||||||
DeviceEventList newDEList;
|
return d->callbackMainDispatcher.unregisterCallback(callbackId);
|
||||||
{
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(DeviceEventList::iterator callback_it = d->deviceEventList.begin(); callback_it != d->deviceEventList.end(); ++callback_it) {
|
|
||||||
if ( (*callback_it)->id != callbackId ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newDEList.splice(newDEList.begin(), d->deviceEventList, callback_it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newDEList.size()) {
|
|
||||||
DeviceEventList::iterator it = newDEList.begin();
|
|
||||||
{ //Lock and unlock to make sure no one else uses the object
|
|
||||||
TelldusCore::MutexLocker locker( &(*it)->mutex );
|
|
||||||
}
|
|
||||||
delete (*it);
|
|
||||||
newDEList.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceChangeList newDCList;
|
|
||||||
{
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(DeviceChangeList::iterator callback_it = d->deviceChangeEventList.begin(); callback_it != d->deviceChangeEventList.end(); ++callback_it) {
|
|
||||||
if ( (*callback_it)->id != callbackId ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newDCList.splice(newDCList.begin(), d->deviceChangeEventList, callback_it);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newDCList.size()) {
|
|
||||||
DeviceChangeList::iterator it = newDCList.begin();
|
|
||||||
{TelldusCore::MutexLocker locker( &(*it)->mutex );}
|
|
||||||
delete (*it);
|
|
||||||
newDCList.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
RawDeviceEventList newRDEList;
|
|
||||||
{
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(RawDeviceEventList::iterator callback_it = d->rawDeviceEventList.begin(); callback_it != d->rawDeviceEventList.end(); ++callback_it) {
|
|
||||||
if ( (*callback_it)->id != callbackId ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newRDEList.splice(newRDEList.begin(), d->rawDeviceEventList, callback_it );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newRDEList.size()) {
|
|
||||||
RawDeviceEventList::iterator it = newRDEList.begin();
|
|
||||||
{TelldusCore::MutexLocker locker( &(*it)->mutex );}
|
|
||||||
delete (*it);
|
|
||||||
newRDEList.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SensorEventList newSEList;
|
|
||||||
{
|
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
|
||||||
for(SensorEventList::iterator callback_it = d->sensorEventList.begin(); callback_it != d->sensorEventList.end(); ++callback_it) {
|
|
||||||
if ( (*callback_it)->id != callbackId ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
newSEList.splice(newSEList.begin(), d->sensorEventList, callback_it );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newSEList.size()) {
|
|
||||||
SensorEventList::iterator it = newSEList.begin();
|
|
||||||
{TelldusCore::MutexLocker locker( &(*it)->mutex );}
|
|
||||||
delete (*it);
|
|
||||||
newSEList.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Client::getSensor(char *protocol, int protocolLen, char *model, int modelLen, int *sensorId, int *dataTypes) {
|
int Client::getSensor(char *protocol, int protocolLen, char *model, int modelLen, int *sensorId, int *dataTypes) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "Message.h"
|
#include "Message.h"
|
||||||
#include "telldus-core.h"
|
#include "telldus-core.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
|
#include "CallbackDispatcher.h"
|
||||||
|
|
||||||
namespace TelldusCore {
|
namespace TelldusCore {
|
||||||
class Client : public Thread
|
class Client : public Thread
|
||||||
|
@ -14,14 +15,7 @@ namespace TelldusCore {
|
||||||
static Client *getInstance();
|
static Client *getInstance();
|
||||||
static void close();
|
static void close();
|
||||||
|
|
||||||
void callbackDeviceEvent(int deviceId, int deviceState, const std::wstring &deviceStateValue);
|
int registerEvent(CallbackStruct::CallbackType type, void *eventFunction, void *context );
|
||||||
void callbackDeviceChangeEvent(int deviceId, int eventDeviceChanges, int eventChangeType);
|
|
||||||
void callbackRawEvent(std::wstring command, int controllerId);
|
|
||||||
void callbackSensorEvent(const std::wstring &protocol, const std::wstring &model, int id, int dataType, const std::wstring &value, int timestamp);
|
|
||||||
int registerDeviceEvent( TDDeviceEvent eventFunction, void *context );
|
|
||||||
int registerDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context );
|
|
||||||
int registerRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
|
|
||||||
int registerSensorEvent( TDSensorEvent eventFunction, void *context );
|
|
||||||
void stopThread(void);
|
void stopThread(void);
|
||||||
bool unregisterCallback( int callbackId );
|
bool unregisterCallback( int callbackId );
|
||||||
|
|
||||||
|
@ -38,7 +32,7 @@ namespace TelldusCore {
|
||||||
private:
|
private:
|
||||||
Client();
|
Client();
|
||||||
static std::wstring sendToService(const Message &msg);
|
static std::wstring sendToService(const Message &msg);
|
||||||
|
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
PrivateData *d;
|
PrivateData *d;
|
||||||
static Client *instance;
|
static Client *instance;
|
||||||
|
|
|
@ -110,8 +110,8 @@ void WINAPI tdInit(void) {
|
||||||
* Added in version 2.0.0.
|
* Added in version 2.0.0.
|
||||||
**/
|
**/
|
||||||
int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context ) {
|
int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context ) {
|
||||||
Client *client = Client::getInstance();
|
eventFunction; Client *client = Client::getInstance();
|
||||||
return client->registerDeviceEvent( eventFunction, context );
|
return client->registerEvent( CallbackStruct::DeviceEvent, (void *)eventFunction, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +119,7 @@ int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context ) {
|
||||||
**/
|
**/
|
||||||
int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context ) {
|
int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context ) {
|
||||||
Client *client = Client::getInstance();
|
Client *client = Client::getInstance();
|
||||||
return client->registerRawDeviceEvent( eventFunction, context );
|
return client->registerEvent( CallbackStruct::RawDeviceEvent, (void *)eventFunction, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +127,7 @@ int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *conte
|
||||||
**/
|
**/
|
||||||
int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context) {
|
int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context) {
|
||||||
Client *client = Client::getInstance();
|
Client *client = Client::getInstance();
|
||||||
return client->registerDeviceChangeEvent( eventFunction, context );
|
return client->registerEvent( CallbackStruct::DeviceChangeEvent, (void *)eventFunction, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,7 +135,7 @@ int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void
|
||||||
**/
|
**/
|
||||||
int WINAPI tdRegisterSensorEvent( TDSensorEvent eventFunction, void *context) {
|
int WINAPI tdRegisterSensorEvent( TDSensorEvent eventFunction, void *context) {
|
||||||
Client *client = Client::getInstance();
|
Client *client = Client::getInstance();
|
||||||
return client->registerSensorEvent( eventFunction, context );
|
return client->registerEvent( CallbackStruct::SensorEvent, (void *)eventFunction, context );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue