Add public function tdRemoveController() to telldus-core, see #108
This commit is contained in:
parent
3de0a98f89
commit
a766fe32de
5 changed files with 47 additions and 0 deletions
|
@ -758,4 +758,22 @@ int WINAPI tdSetControllerValue(int controllerId, const char *name, const char *
|
||||||
return Client::getIntegerFromService(msg);
|
return Client::getIntegerFromService(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function removes a controller from the list
|
||||||
|
* of controllers. The controller must not be
|
||||||
|
* available (disconnected) for this to work.
|
||||||
|
*
|
||||||
|
* Added in version 2.1.2.
|
||||||
|
* @param controllerId The controller to remove
|
||||||
|
* @returns TELLSTICK_SUCCESS if the controller was
|
||||||
|
* removed, TELLSTICK_ERROR_NOT_FOUND if the controller was
|
||||||
|
* not found, and TELLSTICK_ERROR_PERMISSION_DENIED if the
|
||||||
|
* controller is still connected.
|
||||||
|
**/
|
||||||
|
int WINAPI tdRemoveController(int controllerId) {
|
||||||
|
Message msg(L"tdRemoveController");
|
||||||
|
msg.addArgument(controllerId);
|
||||||
|
return Client::getIntegerFromService(msg);
|
||||||
|
}
|
||||||
|
|
||||||
/* @} */
|
/* @} */
|
||||||
|
|
|
@ -89,6 +89,7 @@ extern "C" {
|
||||||
TELLSTICK_API int WINAPI tdController(int *controllerId, int *controllerType, char *name, int nameLen, int *available);
|
TELLSTICK_API int WINAPI tdController(int *controllerId, int *controllerType, char *name, int nameLen, int *available);
|
||||||
TELLSTICK_API int WINAPI tdControllerValue(int controllerId, const char *name, char *value, int valueLen);
|
TELLSTICK_API int WINAPI tdControllerValue(int controllerId, const char *name, char *value, int valueLen);
|
||||||
TELLSTICK_API int WINAPI tdSetControllerValue(int controllerId, const char *name, const char *value);
|
TELLSTICK_API int WINAPI tdSetControllerValue(int controllerId, const char *name, const char *value);
|
||||||
|
TELLSTICK_API int WINAPI tdRemoveController(int controllerId);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,10 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
|
||||||
std::wstring value = TelldusCore::Message::takeString(&msg);
|
std::wstring value = TelldusCore::Message::takeString(&msg);
|
||||||
(*intReturn) = d->controllerManager->setControllerValue(id, name, value);
|
(*intReturn) = d->controllerManager->setControllerValue(id, name, value);
|
||||||
|
|
||||||
|
} else if (function == L"tdRemoveController") {
|
||||||
|
int controllerId = TelldusCore::Message::takeInt(&msg);
|
||||||
|
(*intReturn) = d->controllerManager->removeController(controllerId);
|
||||||
|
|
||||||
} else{
|
} else{
|
||||||
(*intReturn) = TELLSTICK_ERROR_UNKNOWN;
|
(*intReturn) = TELLSTICK_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,6 +276,29 @@ std::wstring ControllerManager::getControllerValue(int id, const std::wstring &n
|
||||||
return L"";
|
return L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ControllerManager::removeController(int id) {
|
||||||
|
TelldusCore::MutexLocker locker(&d->mutex);
|
||||||
|
|
||||||
|
ControllerMap::iterator it = d->controllers.find(id);
|
||||||
|
if (it == d->controllers.end()) {
|
||||||
|
return TELLSTICK_ERROR_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (it->second.controller) {
|
||||||
|
//Still connected
|
||||||
|
return TELLSTICK_ERROR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = d->settings.removeNode(Settings::Controller, id);
|
||||||
|
if (ret != TELLSTICK_SUCCESS) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->controllers.erase(it);
|
||||||
|
|
||||||
|
//TODO: signal
|
||||||
|
return TELLSTICK_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int ControllerManager::setControllerValue(int id, const std::wstring &name, const std::wstring &value) {
|
int ControllerManager::setControllerValue(int id, const std::wstring &name, const std::wstring &value) {
|
||||||
TelldusCore::MutexLocker locker(&d->mutex);
|
TelldusCore::MutexLocker locker(&d->mutex);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
|
|
||||||
std::wstring getControllers() const;
|
std::wstring getControllers() const;
|
||||||
std::wstring getControllerValue(int id, const std::wstring &name);
|
std::wstring getControllerValue(int id, const std::wstring &name);
|
||||||
|
int removeController(int id);
|
||||||
int setControllerValue(int id, const std::wstring &name, const std::wstring &value);
|
int setControllerValue(int id, const std::wstring &name, const std::wstring &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue