Dispatching of events in own thread, to somewhat counter problems with long running events.

This commit is contained in:
Stefan Persson 2012-02-23 15:44:36 +01:00
parent f34e1ad53f
commit c049b97a64
8 changed files with 293 additions and 104 deletions

View file

@ -7,12 +7,14 @@ FIND_PACKAGE( SignTool REQUIRED )
######## Non configurable options ######## ######## Non configurable options ########
SET( telldus-core_SRCS SET( telldus-core_SRCS
CallbackDispatcher.cpp CallbackDispatcher.cpp
CallbackMainDispatcher.cpp
Client.cpp Client.cpp
telldus-core.cpp telldus-core.cpp
) )
SET( telldus-core_HDRS SET( telldus-core_HDRS
CallbackDispatcher.h CallbackDispatcher.h
CallbackMainDispatcher.cpp
Client.h Client.h
) )
SET( telldus-core_PUB_HDRS SET( telldus-core_PUB_HDRS

View file

@ -8,12 +8,11 @@
*/ */
#include "CallbackDispatcher.h" #include "CallbackDispatcher.h"
#include "common.h"
using namespace TelldusCore; using namespace TelldusCore;
TDDeviceEventDispatcher::TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int id, int m, const std::string &strD) 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) :Thread(), d(data), deviceId(id), method(m), strData(strD), doneRunning(false), callbackExecuted(cbDone)
{ {
this->startAndLock(&d->mutex); this->startAndLock(&d->mutex);
} }
@ -29,13 +28,12 @@ bool TDDeviceEventDispatcher::done() const {
void TDDeviceEventDispatcher::run() { void TDDeviceEventDispatcher::run() {
char *str = wrapStdString(strData); char *str = wrapStdString(strData);
d->event(deviceId, method, strData.c_str(), d->id, d->context); d->event(deviceId, method, strData.c_str(), d->id, d->context);
doneRunning = true; doneRunning = true;
callbackExecuted->signal();
} }
TDDeviceChangeEventDispatcher::TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int id, int event, int type, TelldusCore::EventRef cbDone)
TDDeviceChangeEventDispatcher::TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int id, int event, int type) :Thread(), d(data), deviceId(id), changeEvent(event), changeType(type), doneRunning(false), callbackExecuted(cbDone)
:Thread(), d(data), deviceId(id), changeEvent(event), changeType(type), doneRunning(false)
{ {
this->startAndLock(&d->mutex); this->startAndLock(&d->mutex);
} }
@ -51,10 +49,11 @@ bool TDDeviceChangeEventDispatcher::done() const {
void TDDeviceChangeEventDispatcher::run() { void TDDeviceChangeEventDispatcher::run() {
d->event(deviceId, changeEvent, changeType, d->id, d->context); d->event(deviceId, changeEvent, changeType, d->id, d->context);
doneRunning = true; doneRunning = true;
callbackExecuted->signal();
} }
TDRawDeviceEventDispatcher::TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strD, int id) TDRawDeviceEventDispatcher::TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strD, int id, TelldusCore::EventRef cbDone)
:Thread(), d(data), controllerId(id), strData(strD), doneRunning(false) :Thread(), d(data), controllerId(id), strData(strD), doneRunning(false), callbackExecuted(cbDone)
{ {
this->startAndLock(&d->mutex); this->startAndLock(&d->mutex);
} }
@ -70,10 +69,11 @@ bool TDRawDeviceEventDispatcher::done() const {
void TDRawDeviceEventDispatcher::run() { void TDRawDeviceEventDispatcher::run() {
d->event(strData.c_str(), controllerId, d->id, d->context); d->event(strData.c_str(), controllerId, d->id, d->context);
doneRunning = true; 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) 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) :Thread(), d(data), protocol(p), model(m), sensorId(id), dataType(type), value(v), timestamp(t), doneRunning(false), callbackExecuted(cbDone)
{ {
this->startAndLock(&d->mutex); this->startAndLock(&d->mutex);
} }
@ -89,4 +89,5 @@ bool TDSensorEventDispatcher::done() const {
void TDSensorEventDispatcher::run() { void TDSensorEventDispatcher::run() {
d->event(protocol.c_str(), model.c_str(), sensorId, dataType, value.c_str(), timestamp, d->id, d->context); d->event(protocol.c_str(), model.c_str(), sensorId, dataType, value.c_str(), timestamp, d->id, d->context);
doneRunning = true; doneRunning = true;
callbackExecuted->signal();
} }

View file

@ -7,10 +7,11 @@
* *
*/ */
#ifndef CALLBACKDISPATCHER_H #ifndef CALLBACKDISPATCHER_H
#define CALLBACKDISPATCHER_H #define CALLBACKDISPATCHER_H
#include "common.h"
#include "Event.h"
#include "Thread.h" #include "Thread.h"
#include "Mutex.h" #include "Mutex.h"
#include "telldus-core.h" #include "telldus-core.h"
@ -25,7 +26,7 @@ namespace TelldusCore {
class TDDeviceEventDispatcher : public Thread { class TDDeviceEventDispatcher : public Thread {
public: public:
TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int deviceId, int method, const std::string &strData); TDDeviceEventDispatcher(CallbackStruct<TDDeviceEvent> *data, int deviceId, int method, const std::string &strData, TelldusCore::EventRef cbDone);
virtual ~TDDeviceEventDispatcher(); virtual ~TDDeviceEventDispatcher();
bool done() const; bool done() const;
protected: protected:
@ -35,22 +36,24 @@ namespace TelldusCore {
CallbackStruct<TDDeviceEvent> *d; CallbackStruct<TDDeviceEvent> *d;
int deviceId, method; int deviceId, method;
std::string strData; std::string strData;
TelldusCore::EventRef callbackExecuted;
}; };
class TDDeviceChangeEventDispatcher : public Thread { class TDDeviceChangeEventDispatcher : public Thread {
public: public:
TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int deviceId, int changeEvent, int changeType); TDDeviceChangeEventDispatcher(CallbackStruct<TDDeviceChangeEvent> *data, int deviceId, int changeEvent, int changeType, TelldusCore::EventRef cbDone);
virtual ~TDDeviceChangeEventDispatcher(); virtual ~TDDeviceChangeEventDispatcher();
bool done() const; bool done() const;
protected: protected:
virtual void run(); virtual void run();
bool doneRunning; bool doneRunning;
public: private:
CallbackStruct<TDDeviceChangeEvent> *d; CallbackStruct<TDDeviceChangeEvent> *d;
int deviceId, changeEvent, changeType; int deviceId, changeEvent, changeType;
TelldusCore::EventRef callbackExecuted;
}; };
class TDRawDeviceEventDispatcher : public Thread { class TDRawDeviceEventDispatcher : public Thread {
public: public:
TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strData, int controllerId); TDRawDeviceEventDispatcher( CallbackStruct<TDRawDeviceEvent> *data, const std::string &strData, int controllerId, TelldusCore::EventRef cbDone);
virtual ~TDRawDeviceEventDispatcher(); virtual ~TDRawDeviceEventDispatcher();
bool done() const; bool done() const;
protected: protected:
@ -60,10 +63,11 @@ namespace TelldusCore {
CallbackStruct<TDRawDeviceEvent> *d; CallbackStruct<TDRawDeviceEvent> *d;
int controllerId; int controllerId;
std::string strData; std::string strData;
TelldusCore::EventRef callbackExecuted;
}; };
class TDSensorEventDispatcher : public Thread { class TDSensorEventDispatcher : public Thread {
public: public:
TDSensorEventDispatcher( CallbackStruct<TDSensorEvent> *data, const std::string &protocol, const std::string &model, int id, int dataType, const std::string &value, int timestamp); 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);
virtual ~TDSensorEventDispatcher(); virtual ~TDSensorEventDispatcher();
bool done() const; bool done() const;
protected: protected:
@ -77,6 +81,7 @@ namespace TelldusCore {
int dataType; int dataType;
std::string value; std::string value;
int timestamp; int timestamp;
TelldusCore::EventRef callbackExecuted;
}; };
} }

View file

@ -0,0 +1,159 @@
/*
* CallbackMainDispatcher.cpp
* telldus-core
*
* Created by Stefan Persson on 2012-02-23.
* Copyright 2012 Telldus Technologies AB. All rights reserved.
*
*/
#include "CallbackMainDispatcher.h"
#include <list>
class CallbackMainDispatcher::PrivateData {
public:
TelldusCore::EventHandler eventHandler;
TelldusCore::EventRef stopEvent, generalCallbackEvent, janitor;
std::list<std::tr1::shared_ptr<TelldusCore::TDDeviceEventDispatcher> > deviceEventThreadList;
std::list<std::tr1::shared_ptr<TelldusCore::TDDeviceChangeEventDispatcher> > deviceChangeEventThreadList;
std::list<std::tr1::shared_ptr<TelldusCore::TDRawDeviceEventDispatcher> > rawDeviceEventThreadList;
std::list<std::tr1::shared_ptr<TelldusCore::TDSensorEventDispatcher> > sensorEventThreadList;
TelldusCore::Mutex mutex;
};
CallbackMainDispatcher::CallbackMainDispatcher()
:Thread()
{
d = new PrivateData;
d->stopEvent = d->eventHandler.addEvent();
d->generalCallbackEvent = d->eventHandler.addEvent();
d->janitor = d->eventHandler.addEvent(); //Used for cleanups
}
CallbackMainDispatcher::~CallbackMainDispatcher(void){
d->stopEvent->signal();
wait();
{
TelldusCore::MutexLocker locker(&d->mutex);
}
delete d;
}
TelldusCore::EventRef CallbackMainDispatcher::retrieveCallbackEvent(){
return d->generalCallbackEvent;
}
void CallbackMainDispatcher::run(){
while(!d->stopEvent->isSignaled()){
if (!d->eventHandler.waitForAny()) {
continue;
}
if(d->generalCallbackEvent->isSignaled()){
TelldusCore::EventDataRef eventData = d->generalCallbackEvent->takeSignal();
DeviceEventCallbackData *decd = dynamic_cast<DeviceEventCallbackData*>(eventData.get());
if(decd){
std::tr1::shared_ptr<TelldusCore::TDDeviceEventDispatcher> ptr(new TelldusCore::TDDeviceEventDispatcher(decd->data, decd->deviceId, decd->deviceState, decd->deviceStateValue, d->janitor));
TelldusCore::MutexLocker locker(&d->mutex);
d->deviceEventThreadList.push_back(ptr);
continue;
}
DeviceChangeEventCallbackData *dcecd = dynamic_cast<DeviceChangeEventCallbackData*>(eventData.get());
if(dcecd){
std::tr1::shared_ptr<TelldusCore::TDDeviceChangeEventDispatcher> ptr(new TelldusCore::TDDeviceChangeEventDispatcher(dcecd->data, dcecd->deviceId, dcecd->eventDeviceChanges, dcecd->eventChangeType, d->janitor));
TelldusCore::MutexLocker locker(&d->mutex);
d->deviceChangeEventThreadList.push_back(ptr);
continue;
}
RawDeviceEventCallbackData *rdecd = dynamic_cast<RawDeviceEventCallbackData*>(eventData.get());
if(rdecd){
std::tr1::shared_ptr<TelldusCore::TDRawDeviceEventDispatcher> ptr(new TelldusCore::TDRawDeviceEventDispatcher(rdecd->data, rdecd->command, rdecd->controllerId, d->janitor));
TelldusCore::MutexLocker locker(&d->mutex);
d->rawDeviceEventThreadList.push_back(ptr);
continue;
}
SensorEventCallbackData *secd = dynamic_cast<SensorEventCallbackData*>(eventData.get());
if(secd){
std::tr1::shared_ptr<TelldusCore::TDSensorEventDispatcher> ptr(new TelldusCore::TDSensorEventDispatcher(secd->data, secd->protocol, secd->model, secd->id, secd->dataType, secd->value, secd->timestamp, d->janitor));
TelldusCore::MutexLocker locker(&d->mutex);
d->sensorEventThreadList.push_back(ptr);
continue;
}
}
if (d->janitor->isSignaled()) {
//Clear all of them if there is more than one
while(d->janitor->isSignaled()) {
d->janitor->popSignal();
}
this->cleanupCallbacks();
}
}
}
void CallbackMainDispatcher::cleanupCallbacks() {
bool again = false;
//Device Event
do {
again = false;
TelldusCore::MutexLocker locker(&d->mutex);
std::list<std::tr1::shared_ptr<TelldusCore::TDDeviceEventDispatcher> >::iterator it = d->deviceEventThreadList.begin();
for (;it != d->deviceEventThreadList.end(); ++it) {
if ((*it)->done()) {
d->deviceEventThreadList.erase(it);
again = true;
break;
}
}
} while (again);
//Device Change Event
do {
again = false;
TelldusCore::MutexLocker locker(&d->mutex);
std::list<std::tr1::shared_ptr<TelldusCore::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;
TelldusCore::MutexLocker locker(&d->mutex);
std::list<std::tr1::shared_ptr<TelldusCore::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;
TelldusCore::MutexLocker locker(&d->mutex);
std::list<std::tr1::shared_ptr<TelldusCore::TDSensorEventDispatcher> >::iterator it = d->sensorEventThreadList.begin();
for (;it != d->sensorEventThreadList.end(); ++it) {
if ((*it)->done()) {
d->sensorEventThreadList.erase(it);
again = true;
break;
}
}
} while (again);
}

View file

@ -0,0 +1,69 @@
/*
* CallbackMainDispatcher.h
* telldus-core
*
* Created by Stefan Persson on 2012-02-23.
* Copyright 2012 Telldus Technologies AB. All rights reserved.
*
*/
#ifndef CALLBACKMAINDISPATCHER_H
#define CALLBACKMAINDISPATCHER_H
#include "CallbackDispatcher.h"
#include "Thread.h"
#include "Event.h"
#include "EventHandler.h"
class DeviceChangeEventCallbackData : public TelldusCore::EventDataBase {
public:
TelldusCore::CallbackStruct<TDDeviceChangeEvent> *data;
int deviceId;
int eventDeviceChanges;
int eventChangeType;
};
class DeviceEventCallbackData : public TelldusCore::EventDataBase {
public:
TelldusCore::CallbackStruct<TDDeviceEvent> *data;
int deviceId;
int deviceState;
std::string deviceStateValue;
};
class RawDeviceEventCallbackData : public TelldusCore::EventDataBase {
public:
TelldusCore::CallbackStruct<TDRawDeviceEvent> *data;
int controllerId;
std::string command;
};
class SensorEventCallbackData : public TelldusCore::EventDataBase {
public:
TelldusCore::CallbackStruct<TDSensorEvent> *data;
std::string protocol;
std::string model;
int id;
int dataType;
std::string value;
int timestamp;
};
class CallbackMainDispatcher : public TelldusCore::Thread
{
public:
CallbackMainDispatcher(void);
~CallbackMainDispatcher(void);
TelldusCore::EventRef retrieveCallbackEvent();
protected:
void run();
private:
class PrivateData;
PrivateData *d;
void cleanupCallbacks(void);
};
#endif //CALLBACKMAINDISPATCHER_H

View file

@ -1,17 +1,11 @@
#include "Client.h" #include "Client.h"
#include "CallbackDispatcher.h" #include "CallbackDispatcher.h"
#include "CallbackMainDispatcher.h"
#include "Socket.h" #include "Socket.h"
#include "Strings.h" #include "Strings.h"
#include "Mutex.h" #include "Mutex.h"
#include "common.h"
#include <list> #include <list>
#ifdef _WINDOWS
#include <memory>
#else
#include <tr1/memory>
#endif
using namespace TelldusCore; using namespace TelldusCore;
@ -35,11 +29,8 @@ public:
bool running, sensorCached; bool running, sensorCached;
std::wstring sensorCache; std::wstring sensorCache;
TelldusCore::Mutex mutex; TelldusCore::Mutex mutex;
CallbackMainDispatcher callbackMainDispatcher;
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;
}; };
Client *Client::instance = 0; Client *Client::instance = 0;
@ -51,6 +42,7 @@ Client::Client()
d->lastCallbackId = 0; d->lastCallbackId = 0;
d->running = true; d->running = true;
d->sensorCached = false; d->sensorCached = false;
d->callbackMainDispatcher.start();
start(); start();
} }
@ -80,32 +72,57 @@ Client *Client::getInstance() {
void Client::callbackDeviceEvent(int deviceId, int deviceState, const std::wstring &deviceStateValue){ void Client::callbackDeviceEvent(int deviceId, int deviceState, const std::wstring &deviceStateValue){
TelldusCore::MutexLocker locker(&d->mutex); TelldusCore::MutexLocker locker(&d->mutex);
for(DeviceEventList::iterator callback_it = d->deviceEventList.begin(); callback_it != d->deviceEventList.end(); ++callback_it) { for(DeviceEventList::iterator callback_it = d->deviceEventList.begin(); callback_it != d->deviceEventList.end(); ++callback_it) {
std::tr1::shared_ptr<TDDeviceEventDispatcher> ptr(new TDDeviceEventDispatcher(*callback_it, deviceId, deviceState, TelldusCore::wideToString(deviceStateValue))); DeviceEventCallbackData *deviceEventCallbackData = new DeviceEventCallbackData();
d->deviceEventThreadList.push_back(ptr); 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){ void Client::callbackDeviceChangeEvent(int deviceId, int eventDeviceChanges, int eventChangeType){
TelldusCore::MutexLocker locker(&d->mutex); TelldusCore::MutexLocker locker(&d->mutex);
for(DeviceChangeList::iterator callback_it = d->deviceChangeEventList.begin(); callback_it != d->deviceChangeEventList.end(); ++callback_it) { for(DeviceChangeList::iterator callback_it = d->deviceChangeEventList.begin(); callback_it != d->deviceChangeEventList.end(); ++callback_it) {
std::tr1::shared_ptr<TDDeviceChangeEventDispatcher> ptr(new TDDeviceChangeEventDispatcher(*callback_it, deviceId, eventDeviceChanges, eventChangeType)); DeviceChangeEventCallbackData *deviceChangeEventCallbackData = new DeviceChangeEventCallbackData();
d->deviceChangeEventThreadList.push_back(ptr); 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) { void Client::callbackRawEvent(std::wstring command, int controllerId) {
TelldusCore::MutexLocker locker(&d->mutex); TelldusCore::MutexLocker locker(&d->mutex);
for(RawDeviceEventList::iterator callback_it = d->rawDeviceEventList.begin(); callback_it != d->rawDeviceEventList.end(); ++callback_it) { for(RawDeviceEventList::iterator callback_it = d->rawDeviceEventList.begin(); callback_it != d->rawDeviceEventList.end(); ++callback_it) {
std::tr1::shared_ptr<TDRawDeviceEventDispatcher> ptr(new TDRawDeviceEventDispatcher(*callback_it, TelldusCore::wideToString(command), controllerId)); RawDeviceEventCallbackData *rawDeviceEventCallbackData = new RawDeviceEventCallbackData();
d->rawDeviceEventThreadList.push_back(ptr); 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) { 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); TelldusCore::MutexLocker locker(&d->mutex);
for(SensorEventList::iterator callback_it = d->sensorEventList.begin(); callback_it != d->sensorEventList.end(); ++callback_it) { for(SensorEventList::iterator callback_it = d->sensorEventList.begin(); callback_it != d->sensorEventList.end(); ++callback_it) {
std::tr1::shared_ptr<TDSensorEventDispatcher> ptr(new TDSensorEventDispatcher(*callback_it, TelldusCore::wideToString(protocol), TelldusCore::wideToString(model), id, dataType, TelldusCore::wideToString(value), timestamp)); SensorEventCallbackData *sensorEventCallbackData = new SensorEventCallbackData();
d->sensorEventThreadList.push_back(ptr); 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);
} }
} }
@ -220,72 +237,9 @@ void Client::run(){
clientMessage = L""; //cleanup, if message contained garbage/unhandled data clientMessage = L""; //cleanup, if message contained garbage/unhandled data
} }
} }
//Clean up finished callbacks
this->cleanupCallbacks();
} }
} }
void Client::cleanupCallbacks() {
bool again = false;
//Device Event
do {
again = false;
TelldusCore::MutexLocker locker(&d->mutex);
std::list<std::tr1::shared_ptr<TDDeviceEventDispatcher> >::iterator it = d->deviceEventThreadList.begin();
for (;it != d->deviceEventThreadList.end(); ++it) {
if ((*it)->done()) {
d->deviceEventThreadList.erase(it);
again = true;
break;
}
}
} while (again);
//Device Change Event
do {
again = false;
TelldusCore::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;
TelldusCore::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;
TelldusCore::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);
}
std::wstring Client::sendToService(const Message &msg) { std::wstring Client::sendToService(const Message &msg) {
int tries = 0; int tries = 0;

View file

@ -37,7 +37,6 @@ namespace TelldusCore {
private: private:
Client(); Client();
static std::wstring sendToService(const Message &msg); static std::wstring sendToService(const Message &msg);
void cleanupCallbacks();
class PrivateData; class PrivateData;
PrivateData *d; PrivateData *d;