Add function to query controllers in the service

This commit is contained in:
Micke Prag 2012-02-13 18:08:21 +01:00
parent 799c25f98e
commit 00eeea1283
6 changed files with 39 additions and 6 deletions

View file

@ -125,6 +125,11 @@ extern "C" {
#define TELLSTICK_TYPE_GROUP 2 #define TELLSTICK_TYPE_GROUP 2
#define TELLSTICK_TYPE_SCENE 3 #define TELLSTICK_TYPE_SCENE 3
//Controller typedef
#define TELLSTICK_CONTROLLER_TELLSTICK 1
#define TELLSTICK_CONTROLLER_TELLSTICK_DUO 2
#define TELLSTICK_CONTROLLER_TELLSTICK_NET 3
//Device changes //Device changes
#define TELLSTICK_DEVICE_ADDED 1 #define TELLSTICK_DEVICE_ADDED 1
#define TELLSTICK_DEVICE_CHANGED 2 #define TELLSTICK_DEVICE_CHANGED 2

View file

@ -10,13 +10,14 @@ public:
TelldusCore::EventRef event, deviceUpdateEvent; TelldusCore::EventRef event, deviceUpdateEvent;
bool done; bool done;
DeviceManager *deviceManager; DeviceManager *deviceManager;
ControllerManager *controllerManager;
}; };
ClientCommunicationHandler::ClientCommunicationHandler(){ ClientCommunicationHandler::ClientCommunicationHandler(){
} }
ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clientSocket, TelldusCore::EventRef event, DeviceManager *deviceManager, TelldusCore::EventRef deviceUpdateEvent) ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clientSocket, TelldusCore::EventRef event, DeviceManager *deviceManager, TelldusCore::EventRef deviceUpdateEvent, ControllerManager *controllerManager)
:Thread() :Thread()
{ {
d = new PrivateData; d = new PrivateData;
@ -25,7 +26,7 @@ ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clie
d->done = false; d->done = false;
d->deviceManager = deviceManager; d->deviceManager = deviceManager;
d->deviceUpdateEvent = deviceUpdateEvent; d->deviceUpdateEvent = deviceUpdateEvent;
d->controllerManager = controllerManager;
} }
ClientCommunicationHandler::~ClientCommunicationHandler(void) ClientCommunicationHandler::~ClientCommunicationHandler(void)
@ -230,8 +231,10 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
int dataType = TelldusCore::Message::takeInt(&msg); int dataType = TelldusCore::Message::takeInt(&msg);
(*wstringReturn) = d->deviceManager->getSensorValue(protocol, model, id, dataType); (*wstringReturn) = d->deviceManager->getSensorValue(protocol, model, id, dataType);
} } else if (function == L"tdController") {
else{ (*wstringReturn) = d->controllerManager->getControllers();
} else{
(*intReturn) = TELLSTICK_ERROR_UNKNOWN; (*intReturn) = TELLSTICK_ERROR_UNKNOWN;
} }
} }

View file

@ -12,7 +12,13 @@ class ClientCommunicationHandler : public TelldusCore::Thread
{ {
public: public:
ClientCommunicationHandler(); ClientCommunicationHandler();
ClientCommunicationHandler(TelldusCore::Socket *clientSocket, TelldusCore::EventRef event, DeviceManager *deviceManager, TelldusCore::EventRef deviceUpdateEvent); ClientCommunicationHandler(
TelldusCore::Socket *clientSocket,
TelldusCore::EventRef event,
DeviceManager *deviceManager,
TelldusCore::EventRef deviceUpdateEvent,
ControllerManager *controllerManager
);
~ClientCommunicationHandler(void); ~ClientCommunicationHandler(void);
bool isDone(); bool isDone();

View file

@ -3,6 +3,7 @@
#include "Mutex.h" #include "Mutex.h"
#include "TellStick.h" #include "TellStick.h"
#include "Log.h" #include "Log.h"
#include "Message.h"
#include "../client/telldus-core.h" #include "../client/telldus-core.h"
#include <map> #include <map>
@ -202,3 +203,19 @@ int ControllerManager::resetController(Controller *controller) {
deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete
return success; return success;
} }
std::wstring ControllerManager::getControllers() const {
TelldusCore::MutexLocker locker(&d->mutex);
TelldusCore::Message msg;
msg.addArgument((int)d->controllers.size());
for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) {
msg.addArgument(it->first);
msg.addArgument(it->second.type);
msg.addArgument(it->second.name.c_str());
msg.addArgument(it->second.controller ? 1 : 0);
}
return msg;
}

View file

@ -20,6 +20,8 @@ public:
void queryControllerStatus(); void queryControllerStatus();
int resetController(Controller *controller); int resetController(Controller *controller);
std::wstring getControllers() const;
private: private:
class PrivateData; class PrivateData;
PrivateData *d; PrivateData *d;

View file

@ -91,7 +91,7 @@ void TelldusMain::start(void) {
TelldusCore::EventDataRef eventDataRef = clientEvent->takeSignal(); TelldusCore::EventDataRef eventDataRef = clientEvent->takeSignal();
ConnectionListenerEventData *data = reinterpret_cast<ConnectionListenerEventData*>(eventDataRef.get()); ConnectionListenerEventData *data = reinterpret_cast<ConnectionListenerEventData*>(eventDataRef.get());
if (data) { if (data) {
ClientCommunicationHandler *clientCommunication = new ClientCommunicationHandler(data->socket, handlerEvent, &deviceManager, deviceUpdateEvent); ClientCommunicationHandler *clientCommunication = new ClientCommunicationHandler(data->socket, handlerEvent, &deviceManager, deviceUpdateEvent, &controllerManager);
clientCommunication->start(); clientCommunication->start();
clientCommunicationHandlerList.push_back(clientCommunication); clientCommunicationHandlerList.push_back(clientCommunication);
} }