Changeset 2b7f02


Ignore:
Timestamp:
02/23/12 10:07:16 (9 years ago)
Author:
Micke Prag <micke.prag@…>
Branches:
('master', 'cc326285c5d9e5d35ef50c97ddab57539e602594')
Children:
f8226be943f5d023e4c74835c7e4aa506069d022
Parents:
00eeea1283b5dc8168ff7b48b95fcdd92fe5b792
git-author:
Micke Prag <micke.prag@telldus.se>2012-02-13 18:10:20+01:00
git-committer:
Micke Prag <micke.prag@telldus.se>2012-02-23 10:07:16+01:00
Message:

Add public function tdController() to telldus-core. See #108

Location:
telldus-core/client
Files:
4 edited

Legend:

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

    rf34e1a r2b7f02  
    3333        RawDeviceEventList rawDeviceEventList; 
    3434        SensorEventList sensorEventList; 
    35         bool running, sensorCached; 
    36         std::wstring sensorCache; 
     35        bool running, sensorCached, controllerCached; 
     36        std::wstring sensorCache, controllerCache; 
    3737        TelldusCore::Mutex mutex; 
    3838 
     
    288288 
    289289std::wstring Client::sendToService(const Message &msg) { 
    290          
     290 
    291291        int tries = 0; 
    292292        std::wstring readData; 
     
    315315                        //TODO perhaps break here instead? 
    316316                } 
    317                  
     317 
    318318                if (!s.isConnected()) { //Connection failed sometime during operation... 
    319319                        msleep(500); 
     
    450450        return TELLSTICK_SUCCESS; 
    451451} 
     452 
     453int Client::getController(int *controllerId, int *controllerType, char *name, int nameLen, int *available) { 
     454        if (!d->controllerCached) { 
     455                Message msg(L"tdController"); 
     456                std::wstring response = Client::getWStringFromService(msg); 
     457                int count = Message::takeInt(&response); 
     458                d->controllerCached = true; 
     459                d->controllerCache = L""; 
     460                if (count > 0) { 
     461                        d->controllerCache = response; 
     462                } 
     463        } 
     464 
     465        if (d->controllerCache == L"") { 
     466                d->controllerCached = false; 
     467                return TELLSTICK_ERROR_DEVICE_NOT_FOUND; 
     468        } 
     469 
     470        int id = Message::takeInt(&d->controllerCache); 
     471        int type = Message::takeInt(&d->controllerCache); 
     472        std::wstring n = Message::takeString(&d->controllerCache); 
     473        int a = Message::takeInt(&d->controllerCache); 
     474 
     475        if (controllerId) { 
     476                (*controllerId) = id; 
     477        } 
     478        if (controllerType) { 
     479                (*controllerType) = type; 
     480        } 
     481        if (name && nameLen) { 
     482                strncpy(name, TelldusCore::wideToString(n).c_str(), nameLen); 
     483        } 
     484        if (available) { 
     485                (*available) = a; 
     486        } 
     487 
     488        return TELLSTICK_SUCCESS; 
     489} 
  • telldus-core/client/Client.h

    r9535ec r2b7f02  
    2727 
    2828                int getSensor(char *protocol, int protocolLen, char *model, int modelLen, int *id, int *dataTypes); 
     29                int getController(int *controllerId, int *controllerType, char *name, int nameLen, int *available); 
    2930 
    3031                static bool getBoolFromService(const Message &msg); 
  • telldus-core/client/telldus-core.cpp

    r795123 r2b7f02  
    698698} 
    699699 
     700/** 
     701 * Use this function to iterate over all controllers. Iterate until 
     702 * TELLSTICK_SUCCESS is not returned 
     703 * 
     704 * Added in version 2.1.2. 
     705 * @param controllerId A byref int where the id of the controller will be placed 
     706 * @param controllerType A byref int where the type of the controller will be placed 
     707 * @param name A byref string where the name of the controller will be placed 
     708 * @param nameLen The length of the \c name parameter 
     709 * @param available A byref int if the controller is currently available or maybe disconnected 
     710 * @returns TELLSTICK_SUCCESS if there is more sensors to be fetched 
     711 * @sa TELLSTICK_CONTROLLER_TELLSTICK 
     712 * @sa TELLSTICK_CONTROLLER_TELLSTICK_DUO 
     713 * @sa TELLSTICK_CONTROLLER_TELLSTICK_NET 
     714 **/ 
     715int WINAPI tdController(int *controllerId, int *controllerType, char *name, int nameLen, int *available) { 
     716        Client *client = Client::getInstance(); 
     717        return client->getController(controllerId, controllerType, name, nameLen, available); 
     718} 
    700719 
    701720/* @} */ 
  • telldus-core/client/telldus-core.h

    r00eeea r2b7f02  
    8787        TELLSTICK_API int WINAPI tdSensorValue(const char *protocol, const char *model, int id, int dataType, char *value, int len, int *timestamp); 
    8888 
     89        TELLSTICK_API int WINAPI tdController(int *controllerId, int *controllerType, char *name, int nameLen, int *available); 
     90 
    8991#ifdef __cplusplus 
    9092} 
Note: See TracChangeset for help on using the changeset viewer.