Add callback TDControllerEvent
This commit is contained in:
parent
42beb57169
commit
246b4273ce
6 changed files with 35 additions and 1 deletions
|
@ -60,5 +60,12 @@ void TDEventDispatcher::fireEvent() {
|
|||
}
|
||||
((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);
|
||||
|
||||
} else if (callback->type == CallbackStruct::ControllerEvent) {
|
||||
ControllerEventCallbackData *data = dynamic_cast<ControllerEventCallbackData *>(callbackData.get());
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
((TDControllerEvent)callback->event)(data->controllerId, data->changeEvent, data->changeType, data->newValue.c_str(), callback->id, callback->context);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace TelldusCore {
|
|||
TelldusCore::Mutex mutex;
|
||||
};*/
|
||||
struct CallbackStruct {
|
||||
enum CallbackType { DeviceEvent, DeviceChangeEvent, RawDeviceEvent, SensorEvent };
|
||||
enum CallbackType { DeviceEvent, DeviceChangeEvent, RawDeviceEvent, SensorEvent, ControllerEvent };
|
||||
CallbackType type;
|
||||
void *event;
|
||||
int id;
|
||||
|
@ -74,6 +74,14 @@ namespace TelldusCore {
|
|||
std::string value;
|
||||
int timestamp;
|
||||
};
|
||||
class ControllerEventCallbackData : public CallbackData {
|
||||
public:
|
||||
ControllerEventCallbackData() : CallbackData(CallbackStruct::ControllerEvent) {}
|
||||
int controllerId;
|
||||
int changeEvent;
|
||||
int changeType;
|
||||
std::string newValue;
|
||||
};
|
||||
|
||||
class TDEventDispatcher : public Thread {
|
||||
public:
|
||||
|
|
|
@ -126,6 +126,14 @@ void Client::run(){
|
|||
data->timestamp = Message::takeInt(&clientMessage);
|
||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||
|
||||
} else if(type == L"TDControllerEvent") {
|
||||
ControllerEventCallbackData *data = new ControllerEventCallbackData();
|
||||
data->controllerId = Message::takeInt(&clientMessage);
|
||||
data->changeEvent = Message::takeInt(&clientMessage);
|
||||
data->changeType = Message::takeInt(&clientMessage);
|
||||
data->newValue = TelldusCore::wideToString(Message::takeString(&clientMessage));
|
||||
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
|
||||
|
||||
} else {
|
||||
clientMessage = L""; //cleanup, if message contained garbage/unhandled data
|
||||
}
|
||||
|
|
|
@ -57,3 +57,4 @@ EXPORTS
|
|||
tdControllerValue @41
|
||||
tdSetControllerValue @42
|
||||
tdRemoveController @43
|
||||
tdRegisterControllerEvent @44
|
||||
|
|
|
@ -138,6 +138,14 @@ int WINAPI tdRegisterSensorEvent( TDSensorEvent eventFunction, void *context) {
|
|||
return client->registerEvent( CallbackStruct::SensorEvent, (void *)eventFunction, context );
|
||||
}
|
||||
|
||||
/**
|
||||
* Added in version 2.1.2.
|
||||
**/
|
||||
int WINAPI tdRegisterControllerEvent( TDControllerEvent eventFunction, void *context) {
|
||||
Client *client = Client::getInstance();
|
||||
return client->registerEvent( CallbackStruct::ControllerEvent, (void *)eventFunction, context );
|
||||
}
|
||||
|
||||
/**
|
||||
* Added in version 2.1.0.
|
||||
**/
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef void (WINAPI *TDDeviceEvent)(int deviceId, int method, const char *data,
|
|||
typedef void (WINAPI *TDDeviceChangeEvent)(int deviceId, int changeEvent, int changeType, int callbackId, void *context);
|
||||
typedef void (WINAPI *TDRawDeviceEvent)(const char *data, int controllerId, int callbackId, void *context);
|
||||
typedef void (WINAPI *TDSensorEvent)(const char *protocol, const char *model, int id, int dataType, const char *value, int timestamp, int callbackId, void *context);
|
||||
typedef void (WINAPI *TDControllerEvent)(int controllerId, int changeEvent, int changeType, const char *newValue, int callbackId, void *context);
|
||||
|
||||
#ifndef __cplusplus
|
||||
#define bool char
|
||||
|
@ -42,6 +43,7 @@ extern "C" {
|
|||
TELLSTICK_API int WINAPI tdRegisterDeviceChangeEvent( TDDeviceChangeEvent eventFunction, void *context);
|
||||
TELLSTICK_API int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context );
|
||||
TELLSTICK_API int WINAPI tdRegisterSensorEvent( TDSensorEvent eventFunction, void *context );
|
||||
TELLSTICK_API int WINAPI tdRegisterControllerEvent( TDControllerEvent eventFunction, void *context);
|
||||
TELLSTICK_API int WINAPI tdUnregisterCallback( int callbackId );
|
||||
TELLSTICK_API void WINAPI tdClose(void);
|
||||
TELLSTICK_API void WINAPI tdReleaseString(char *string);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue