From 00eeea1283b5dc8168ff7b48b95fcdd92fe5b792 Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Mon, 13 Feb 2012 18:08:21 +0100 Subject: [PATCH] Add function to query controllers in the service --- telldus-core/client/telldus-core.h | 5 +++++ .../service/ClientCommunicationHandler.cpp | 11 +++++++---- .../service/ClientCommunicationHandler.h | 8 +++++++- telldus-core/service/ControllerManager.cpp | 17 +++++++++++++++++ telldus-core/service/ControllerManager.h | 2 ++ telldus-core/service/TelldusMain.cpp | 2 +- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/telldus-core/client/telldus-core.h b/telldus-core/client/telldus-core.h index 87eb6132..f78d6bcc 100644 --- a/telldus-core/client/telldus-core.h +++ b/telldus-core/client/telldus-core.h @@ -125,6 +125,11 @@ extern "C" { #define TELLSTICK_TYPE_GROUP 2 #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 #define TELLSTICK_DEVICE_ADDED 1 #define TELLSTICK_DEVICE_CHANGED 2 diff --git a/telldus-core/service/ClientCommunicationHandler.cpp b/telldus-core/service/ClientCommunicationHandler.cpp index 96342382..f0278bd6 100644 --- a/telldus-core/service/ClientCommunicationHandler.cpp +++ b/telldus-core/service/ClientCommunicationHandler.cpp @@ -10,13 +10,14 @@ public: TelldusCore::EventRef event, deviceUpdateEvent; bool done; DeviceManager *deviceManager; + ControllerManager *controllerManager; }; 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() { d = new PrivateData; @@ -25,7 +26,7 @@ ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clie d->done = false; d->deviceManager = deviceManager; d->deviceUpdateEvent = deviceUpdateEvent; - + d->controllerManager = controllerManager; } ClientCommunicationHandler::~ClientCommunicationHandler(void) @@ -230,8 +231,10 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage, int dataType = TelldusCore::Message::takeInt(&msg); (*wstringReturn) = d->deviceManager->getSensorValue(protocol, model, id, dataType); - } - else{ + } else if (function == L"tdController") { + (*wstringReturn) = d->controllerManager->getControllers(); + + } else{ (*intReturn) = TELLSTICK_ERROR_UNKNOWN; } } diff --git a/telldus-core/service/ClientCommunicationHandler.h b/telldus-core/service/ClientCommunicationHandler.h index 7333775a..08c9d421 100644 --- a/telldus-core/service/ClientCommunicationHandler.h +++ b/telldus-core/service/ClientCommunicationHandler.h @@ -12,7 +12,13 @@ class ClientCommunicationHandler : public TelldusCore::Thread { public: 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); bool isDone(); diff --git a/telldus-core/service/ControllerManager.cpp b/telldus-core/service/ControllerManager.cpp index c5421612..ef5a73b7 100644 --- a/telldus-core/service/ControllerManager.cpp +++ b/telldus-core/service/ControllerManager.cpp @@ -3,6 +3,7 @@ #include "Mutex.h" #include "TellStick.h" #include "Log.h" +#include "Message.h" #include "../client/telldus-core.h" #include @@ -202,3 +203,19 @@ int ControllerManager::resetController(Controller *controller) { deviceInsertedOrRemoved(tellstick->vid(), tellstick->pid(), tellstick->serial(), false); //remove from list and delete 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; +} diff --git a/telldus-core/service/ControllerManager.h b/telldus-core/service/ControllerManager.h index a3d0c6bb..2c0a16aa 100644 --- a/telldus-core/service/ControllerManager.h +++ b/telldus-core/service/ControllerManager.h @@ -20,6 +20,8 @@ public: void queryControllerStatus(); int resetController(Controller *controller); + std::wstring getControllers() const; + private: class PrivateData; PrivateData *d; diff --git a/telldus-core/service/TelldusMain.cpp b/telldus-core/service/TelldusMain.cpp index 9cac2660..edf4c9de 100644 --- a/telldus-core/service/TelldusMain.cpp +++ b/telldus-core/service/TelldusMain.cpp @@ -91,7 +91,7 @@ void TelldusMain::start(void) { TelldusCore::EventDataRef eventDataRef = clientEvent->takeSignal(); ConnectionListenerEventData *data = reinterpret_cast(eventDataRef.get()); if (data) { - ClientCommunicationHandler *clientCommunication = new ClientCommunicationHandler(data->socket, handlerEvent, &deviceManager, deviceUpdateEvent); + ClientCommunicationHandler *clientCommunication = new ClientCommunicationHandler(data->socket, handlerEvent, &deviceManager, deviceUpdateEvent, &controllerManager); clientCommunication->start(); clientCommunicationHandlerList.push_back(clientCommunication); }