Changeset 345ff6


Ignore:
Timestamp:
02/23/12 12:14:33 (9 years ago)
Author:
Micke Prag <micke.prag@…>
Branches:
('master', 'cc326285c5d9e5d35ef50c97ddab57539e602594')
Children:
3de0a98f89a6481ab9ffe89bb3d0a056599b8bda
Parents:
fae493f4979a96e9c481fe141792546b11138d8b
git-author:
Micke Prag <micke.prag@telldus.se>2012-02-17 15:32:39+01:00
git-committer:
Micke Prag <micke.prag@telldus.se>2012-02-23 12:14:33+01:00
Message:

Add new function tdControllerValue(), see #108

Location:
telldus-core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • telldus-core/client/telldus-core.cpp

    rcd044d r345ff6  
    719719 
    720720/** 
     721 * This function gets a parameter on a controller. 
     722 * Valid parameters are: \c serial \c and firmware 
     723 * 
     724 * Added in version 2.1.2. 
     725 * @param controllerId The controller to change 
     726 * @param name The parameter to get. 
     727 * @param value A byref string where the value of the parameter will be placed 
     728 **/ 
     729int WINAPI tdControllerValue(int controllerId, const char *name, char *value, int valueLen) { 
     730        Message msg(L"tdControllerValue"); 
     731        msg.addArgument(controllerId); 
     732        msg.addArgument(name); 
     733        std::wstring retval = Client::getWStringFromService(msg); 
     734        if (retval.length() == 0) { 
     735                return TELLSTICK_ERROR_METHOD_NOT_SUPPORTED; 
     736        } 
     737 
     738        if (value && valueLen) { 
     739                strncpy(value, TelldusCore::wideToString(retval).c_str(), valueLen); 
     740        } 
     741        return TELLSTICK_SUCCESS; 
     742} 
     743 
     744/** 
    721745 * This function sets a parameter on a controller. 
    722746 * Valid parameters are: \c name 
  • telldus-core/client/telldus-core.h

    rcd044d r345ff6  
    8888 
    8989        TELLSTICK_API int WINAPI tdController(int *controllerId, int *controllerType, char *name, int nameLen, int *available); 
     90        TELLSTICK_API int WINAPI tdControllerValue(int controllerId, const char *name, char *value, int valueLen); 
    9091        TELLSTICK_API int WINAPI tdSetControllerValue(int controllerId, const char *name, const char *value); 
    9192 
  • telldus-core/service/ClientCommunicationHandler.cpp

    r979e60 r345ff6  
    235235                (*wstringReturn) = d->controllerManager->getControllers(); 
    236236 
     237        } else if (function == L"tdControllerValue") { 
     238                int id = TelldusCore::Message::takeInt(&msg); 
     239                std::wstring name = TelldusCore::Message::takeString(&msg); 
     240                (*wstringReturn) = d->controllerManager->getControllerValue(id, name); 
     241 
    237242        } else if (function == L"tdSetControllerValue") { 
    238243                int id = TelldusCore::Message::takeInt(&msg); 
  • telldus-core/service/ControllerManager.cpp

    rfae493 r345ff6  
    259259} 
    260260 
     261std::wstring ControllerManager::getControllerValue(int id, const std::wstring &name) { 
     262        TelldusCore::MutexLocker locker(&d->mutex); 
     263 
     264        ControllerMap::iterator it = d->controllers.find(id); 
     265        if (it == d->controllers.end()) { 
     266                return L""; 
     267        } 
     268        if (name == L"serial") { 
     269                return it->second.serial; 
     270        } else if (name == L"firmware") { 
     271                if (!it->second.controller) { 
     272                        return L"-1"; 
     273                } 
     274                return TelldusCore::intToWstring(it->second.controller->firmwareVersion()); 
     275        } 
     276        return L""; 
     277} 
     278 
    261279int ControllerManager::setControllerValue(int id, const std::wstring &name, const std::wstring &value) { 
    262280        TelldusCore::MutexLocker locker(&d->mutex); 
  • telldus-core/service/ControllerManager.h

    r94ca41 r345ff6  
    2323 
    2424        std::wstring getControllers() const; 
     25        std::wstring getControllerValue(int id, const std::wstring &name); 
    2526        int setControllerValue(int id, const std::wstring &name, const std::wstring &value); 
    2627 
Note: See TracChangeset for help on using the changeset viewer.