Add function to query controllers in the service
This commit is contained in:
parent
799c25f98e
commit
00eeea1283
6 changed files with 39 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "Mutex.h"
|
||||
#include "TellStick.h"
|
||||
#include "Log.h"
|
||||
#include "Message.h"
|
||||
#include "../client/telldus-core.h"
|
||||
|
||||
#include <map>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
void queryControllerStatus();
|
||||
int resetController(Controller *controller);
|
||||
|
||||
std::wstring getControllers() const;
|
||||
|
||||
private:
|
||||
class PrivateData;
|
||||
PrivateData *d;
|
||||
|
|
|
@ -91,7 +91,7 @@ void TelldusMain::start(void) {
|
|||
TelldusCore::EventDataRef eventDataRef = clientEvent->takeSignal();
|
||||
ConnectionListenerEventData *data = reinterpret_cast<ConnectionListenerEventData*>(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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue