Dispatching of events in own thread, to somewhat counter problems with long running events.
This commit is contained in:
parent
f34e1ad53f
commit
c049b97a64
8 changed files with 293 additions and 104 deletions
|
@ -8,12 +8,11 @@
|
|||
*/
|
||||
|
||||
#include "CallbackDispatcher.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace TelldusCore;
|
||||
|
||||
TDDeviceEventDispatcher::TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int id, int m, const std::string &strD)
|
||||
:Thread(), d(data), deviceId(id), method(m), strData(strD), doneRunning(false)
|
||||
TDDeviceEventDispatcher::TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int id, int m, const std::string &strD, TelldusCore::EventRef cbDone)
|
||||
:Thread(), d(data), deviceId(id), method(m), strData(strD), doneRunning(false), callbackExecuted(cbDone)
|
||||
{
|
||||
this->startAndLock(&d->mutex);
|
||||
}
|
||||
|
@ -29,13 +28,12 @@ bool TDDeviceEventDispatcher::done() const {
|
|||
void TDDeviceEventDispatcher::run() {
|
||||
char *str = wrapStdString(strData);
|
||||
d->event(deviceId, method, strData.c_str(), d->id, d->context);
|
||||
|
||||
doneRunning = true;
|
||||
callbackExecuted->signal();
|
||||
}
|
||||
|
||||
|
||||
TDDeviceChangeEventDispatcher::TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int id, int event, int type)
|
||||
:Thread(), d(data), deviceId(id), changeEvent(event), changeType(type), doneRunning(false)
|
||||
TDDeviceChangeEventDispatcher::TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int id, int event, int type, TelldusCore::EventRef cbDone)
|
||||
:Thread(), d(data), deviceId(id), changeEvent(event), changeType(type), doneRunning(false), callbackExecuted(cbDone)
|
||||
{
|
||||
this->startAndLock(&d->mutex);
|
||||
}
|
||||
|
@ -51,10 +49,11 @@ bool TDDeviceChangeEventDispatcher::done() const {
|
|||
void TDDeviceChangeEventDispatcher::run() {
|
||||
d->event(deviceId, changeEvent, changeType, d->id, d->context);
|
||||
doneRunning = true;
|
||||
callbackExecuted->signal();
|
||||
}
|
||||
|
||||
TDRawDeviceEventDispatcher::TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strD, int id)
|
||||
:Thread(), d(data), controllerId(id), strData(strD), doneRunning(false)
|
||||
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);
|
||||
}
|
||||
|
@ -70,10 +69,11 @@ bool TDRawDeviceEventDispatcher::done() const {
|
|||
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)
|
||||
:Thread(), d(data), protocol(p), model(m), sensorId(id), dataType(type), value(v), timestamp(t), doneRunning(false)
|
||||
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);
|
||||
}
|
||||
|
@ -89,4 +89,5 @@ bool TDSensorEventDispatcher::done() const {
|
|||
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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue