Implement tdSetControllerValue in TelldusService

This commit is contained in:
Micke Prag 2012-02-15 10:24:04 +01:00
parent f8226be943
commit 979e6082c2
3 changed files with 23 additions and 0 deletions

View file

@ -234,6 +234,12 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
} else if (function == L"tdController") {
(*wstringReturn) = d->controllerManager->getControllers();
} else if (function == L"tdSetControllerValue") {
int id = TelldusCore::Message::takeInt(&msg);
std::wstring name = TelldusCore::Message::takeString(&msg);
std::wstring value = TelldusCore::Message::takeString(&msg);
(*intReturn) = d->controllerManager->setControllerValue(id, name, value);
} else{
(*intReturn) = TELLSTICK_ERROR_UNKNOWN;
}

View file

@ -4,6 +4,7 @@
#include "TellStick.h"
#include "Log.h"
#include "Message.h"
#include "Strings.h"
#include "../client/telldus-core.h"
#include <map>
@ -219,3 +220,18 @@ std::wstring ControllerManager::getControllers() const {
}
return msg;
}
int ControllerManager::setControllerValue(int id, const std::wstring &name, const std::wstring &value) {
TelldusCore::MutexLocker locker(&d->mutex);
ControllerMap::iterator it = d->controllers.find(id);
if (it == d->controllers.end()) {
return TELLSTICK_ERROR_NOT_FOUND;
}
if (name == L"name") {
it->second.name = TelldusCore::wideToString(value);
} else {
return TELLSTICK_ERROR_SYNTAX; //TODO: Is this the best error?
}
return TELLSTICK_SUCCESS;
}

View file

@ -21,6 +21,7 @@ public:
int resetController(Controller *controller);
std::wstring getControllers() const;
int setControllerValue(int id, const std::wstring &name, const std::wstring &value);
private:
class PrivateData;