Changeset 245864


Ignore:
Timestamp:
11/04/11 14:32:22 (19 months ago)
Author:
Stefan Persson <stefan.persson@…>
Branches:
('master', 'a231b56d57a69513303d0061f5fa3e3cd51c85c1')('controller-upgrade', '72b31cc86eeeef18f1371a3067b6e8a5ca21abfc')('windows_service_fixes', 'df6bd2788365991d36d5af2a75833b8de2a5860f')
Children:
81671d160764c227b981ade81be7b91b2a70bc10
Parents:
4b37109f279b3517d8d152423aa0b8d6245954b7
git-author:
Stefan Persson <stefan.persson@telldus.se>2011-11-04 14:32:22+01:00
git-committer:
Stefan Persson <stefan.persson@telldus.se>2011-11-04 14:32:22+01:00
Message:

Windows service, 2.1.0a and new changes for possible new version.

Location:
telldus-core
Files:
12 edited

Legend:

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

    r9535ec r245864  
    99 
    1010#include "CallbackDispatcher.h" 
     11#include "common.h" 
    1112 
    1213using namespace TelldusCore; 
     
    2930 
    3031void TDDeviceEventDispatcher::run() { 
     32        char *str = wrapStdString(strData); 
    3133        d->event(deviceId, method, strData.c_str(), d->id, d->context); 
     34 
    3235        doneRunning = true; 
    3336} 
  • telldus-core/client/Client.cpp

    r9535ec r245864  
    131131        callback->context = context; 
    132132        d->deviceEventList.push_back(callback); 
     133        //debuglog(id, "deviceeventadded"); 
    133134        return id; 
    134135} 
     
    142143        callback->context = context; 
    143144        d->deviceChangeEventList.push_back(callback); 
     145        //debuglog(id, "devicechangeeventadded"); 
    144146        return id; 
    145147} 
     
    177179                        if(!d->eventSocket.isConnected()){ 
    178180                                //reconnect didn't succeed, wait a while and try again 
     181                                //debuglog(0, "Reconnecting"); 
    179182                                msleep(2000); 
    180183                                continue; 
     
    183186 
    184187                std::wstring clientMessage = d->eventSocket.read(5000); //testing 5 second timeout 
     188 
     189                //int test = 0; 
     190                /*if(clientMessage != L""){ 
     191                        debuglog(88, "Clientmessage nothing after read"); 
     192                }*/ 
    185193                while(clientMessage != L""){ 
     194                        //debuglog(99, TelldusCore::wideToString(clientMessage)); 
     195                        //test++; 
     196                        /*if(test > 5){ 
     197                                debuglog(test, "Test is getting big"); 
     198                        }*/ 
    186199                        //a message arrived 
    187200                        std::wstring type = Message::takeString(&clientMessage); 
     
    283296 
    284297std::wstring Client::sendToService(const Message &msg) { 
    285         Socket s; 
    286         s.connect(L"TelldusClient"); 
    287         if (!s.isConnected()) { //Connection failed 
    288                 TelldusCore::Message msg; 
    289                 msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE); 
    290                 return msg; 
    291         } 
    292         s.write(msg.data()); 
    293  
    294         return s.read(5000); 
     298         
     299        int tries = 0; 
     300        std::wstring readData; 
     301        //debuglog(3, "PRETEST"); 
     302        while(tries < 20){ 
     303                //debuglog(3, "PRETESTINNE"); 
     304                tries++; 
     305                if(tries == 20){ 
     306                        TelldusCore::Message msg; 
     307                        msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE); 
     308                        return msg; 
     309                } 
     310                Socket s; 
     311                s.connect(L"TelldusClient"); 
     312                if (!s.isConnected()) { //Connection failed 
     313                        //debuglog(3, "Ett)");  //deviceeventscallbacks verkar sluta fungera vid/med ett sådant här!? njä, bara ngn ggn... 
     314                        msleep(500); 
     315                        continue; //retry 
     316                } 
     317                s.write(msg.data()); 
     318                if (!s.isConnected()) { //Connection failed sometime during operation... (better check here, instead of 5 seconds timeout later) 
     319                        //debuglog(3, "Två"); 
     320                        msleep(500); 
     321                        continue; //retry 
     322                } 
     323                readData = s.read(5000); //500 
     324                if(readData == L""){ 
     325                        //debuglog(3, "Empty result (may be ok?)"); 
     326                        /* 
     327                        if this is  enabled, all "send"  will run 20 times... - NO! That was due to too short timeout in s.read, turnOn didn't  havee titme otecxeu 
     328                        if it's  NOT enabled, tdGetName  will often return empty... 
     329                        */ 
     330                        msleep(500); 
     331                        continue; //TODO cannot be sure it SHOULD be anything... right? 
     332                         
     333                } 
     334                 
     335                if (!s.isConnected()) { //Connection failed sometime during operation... 
     336                        //debuglog(3, "Not connected"); 
     337                        msleep(500); 
     338                        continue; //retry 
     339                } 
     340                break; 
     341        } 
     342 
     343        //debuglog(3, "POSTTEST"); 
     344        return readData; 
    295345} 
    296346 
     
    301351 
    302352bool Client::unregisterCallback( int callbackId ) { 
     353        //debuglog(callbackId, "unregistering"); 
    303354        DeviceEventList newDEList; 
    304355        { 
  • telldus-core/common/Message.cpp

    rfe7f8f r245864  
    2424 
    2525void Message::addArgument(const std::wstring &value) { 
    26         std::wstringstream st; 
    27         st << (int)value.size(); 
    28         this->append(st.str()); 
     26        //std::wstringstream st; 
     27        //st << (int)value.size(); 
     28        this->append(TelldusCore::intToWstring(value.size())); //st.str()); 
    2929        this->append(L":"); 
    3030        this->append(value); 
     
    3232 
    3333void Message::addArgument(int value) { 
    34         std::wstringstream st; 
    35         st << (int)value; 
     34        //std::wstringstream st; 
     35        //st << (int)value; 
    3636        this->append(L"i"); 
    37         this->append(st.str()); 
     37        this->append(TelldusCore::intToWstring(value)); // st.str()); 
    3838        this->append(L"s"); 
    3939} 
     40 
     41/* 
     42void Message::addSpecialArgument(const std::wstring &value){ 
     43        int i = 0; 
     44        while(i<1000000){ 
     45                i++; 
     46 
     47                char numstr[21]; // enough to hold all numbers up to 64-bits 
     48                //sprintf(numstr, "%d", value.size()); 
     49                //this->append(TelldusCore::charToWstring(numstr)); //.str()); 
     50 
     51                itoa(value.size(), numstr, 10); 
     52                std::string test(numstr); 
     53                std::wstring temp(test.length(), L' '); 
     54                std::copy(test.begin(), test.end(), temp.begin()); 
     55 
     56                this->append(temp); 
     57                this->append(L":"); 
     58                this->append(value); 
     59 
     60                /* 
     61                std::wstringstream st; 
     62                st << (int)value.size(); 
     63                this->append(st.str()); 
     64                this->append(L":"); 
     65                this->append(value); 
     66                 
     67        } 
     68} 
     69 
     70void Message::addSpecialArgument(int value){ 
     71        int i = 0; 
     72        while(i<1000000){ 
     73                i++; 
     74                /* 
     75                //std::wstringstream st; 
     76                //st << (int)value; 
     77                this->append(L"i"); 
     78                //this->append(st.str()); 
     79                this->append(L"s"); 
     80                 
     81        } 
     82} 
     83*/ 
     84/* 
     85void Message::addSpecialArgument(const char *value){ 
     86        this->addSpecialArgument(TelldusCore::charToWstring(value)); 
     87} 
     88*/ 
    4089 
    4190void Message::addArgument(const char *value) { 
  • telldus-core/common/Message.h

    rfe7f8f r245864  
    1212 
    1313                void addArgument(const std::wstring &); 
     14                //void addSpecialArgument(const std::wstring &); 
     15                //void addSpecialArgument(int); 
     16                //void addSpecialArgument(const char *); 
    1417                void addArgument(int); 
    1518                void addArgument(const char *); 
  • telldus-core/common/Socket_win.cpp

    rffeb0b7 r245864  
    11#include "Socket.h" 
     2#include "common.h" 
    23 
    34#include <windows.h> 
     
    103104                CancelIo(d->hPipe); 
    104105                CloseHandle(d->readEvent); 
     106                //debuglog(1, "Not running"); 
    105107                return L""; 
    106108        } 
     
    109111                CancelIo(d->hPipe); 
    110112                CloseHandle(d->readEvent); 
     113                //debuglog(1, "Wait timeout"); 
    111114                return L""; 
    112115        } 
     
    114117        if (!fSuccess) { 
    115118                DWORD err = GetLastError(); 
     119                //debuglog(result, "This then?"); 
     120                //debuglog(1, "Unsuccessful"); 
     121                 
    116122                if (err == ERROR_BROKEN_PIPE) { 
     123                        //debuglog(1, "Broken pipe"); 
    117124                        d->connected = false; 
    118125                } 
     
    144151                CloseHandle(writeEvent); 
    145152                d->connected = false; 
     153                //debuglog(2, "Wait timeout"); 
    146154                return; 
    147155        } 
     
    151159                CancelIo(d->hPipe); 
    152160                d->connected = false; 
     161                //debuglog(2, "Unsuccessful"); 
    153162                return;  
    154163        } 
  • telldus-core/common/Strings.cpp

    r11dd17 r245864  
    9292 
    9393std::wstring TelldusCore::intToWstring(int value) { 
     94#ifdef _WINDOWS 
     95        //no stream used 
     96//TODO! Make effective and safe... 
     97        wchar_t numstr[21]; // enough to hold all numbers up to 64-bits 
     98        _itow_s(value, numstr, sizeof(numstr), 10); 
     99        std::wstring newstring(numstr); 
     100        return newstring; 
     101        //return TelldusCore::charToWstring(stdstring.c_str()); 
     102        //std::wstring temp = TelldusCore::charToWstring(stdstring.c_str()); 
     103        //std::wstring temp(stdstring.length(), L' '); 
     104        //std::copy(stdstring.begin(), stdstring.end(), temp.begin()); 
     105        //return temp; 
     106#else 
    94107        std::wstringstream st; 
    95108        st << value; 
    96109        return st.str(); 
     110#endif 
    97111} 
    98112 
    99113std::string TelldusCore::intToString(int value) { 
     114//Not sure if this is neecssary (for ordinary stringstream that is) 
     115#ifdef _WINDOWS 
     116        char numstr[21]; // enough to hold all numbers up to 64-bits 
     117        _itoa_s(value, numstr, sizeof(numstr), 10); 
     118        std::string stdstring(numstr); 
     119        return stdstring; 
     120#else 
    100121        std::stringstream st; 
    101122        st << value; 
    102123        return st.str(); 
    103 } 
     124#endif 
     125} 
     126 
     127/* 
     128std::wstring TelldusCore::intToWStringSafe(int value){ 
     129        #ifdef _WINDOWS 
     130                //no stream used 
     131        //TODO! Make effective and safe... 
     132                char numstr[21]; // enough to hold all numbers up to 64-bits 
     133                itoa(value, numstr, 10); 
     134                std::string stdstring(numstr); 
     135                return TelldusCore::charToWstring(stdstring.c_str()); 
     136                //std::wstring temp = TelldusCore::charToWstring(stdstring.c_str()); 
     137                //std::wstring temp(stdstring.length(), L' '); 
     138                //std::copy(stdstring.begin(), stdstring.end(), temp.begin()); 
     139                //return temp; 
     140        #else 
     141                return TelldusCore::intToWString(value); 
     142        #endif 
     143} 
     144*/ 
    104145 
    105146int TelldusCore::wideToInteger(const std::wstring &input){ 
  • telldus-core/common/Strings.h

    r11dd17 r245864  
    1111        bool comparei(std::wstring stringA, std::wstring stringB); 
    1212        std::wstring intToWstring(int value); 
     13        //std::wstring intToWStringSafe(int value); 
    1314        std::string intToString(int value); 
    1415        std::string wideToString(const std::wstring &input); 
  • telldus-core/service/ClientCommunicationHandler.cpp

    rad1b18 r245864  
    8282 
    8383        } else if (function == L"tdBell") { 
     84                //TelldusCore::Message msg2; 
     85                //msg2.addSpecialArgument(18); 
     86                //msg2.addSpecialArgument("testgrej"); 
     87 
    8488                int deviceId = TelldusCore::Message::takeInt(&msg); 
    8589                (*intReturn) = d->deviceManager->doAction(deviceId, TELLSTICK_BELL, 0); 
  • telldus-core/service/EventHandler_win.cpp

    r485b1e r245864  
    5252 
    5353bool EventHandler::waitForAny() { 
    54         int result = WaitForMultipleObjects(d->eventCount, d->eventArray, FALSE, INFINITE); 
    55  
    56         TelldusCore::MutexLocker locker(&d->mutex); 
    57         if (result == WAIT_TIMEOUT) { 
    58                 return false; 
     54         
     55        while(1){ 
     56                int result = WaitForMultipleObjects(d->eventCount, d->eventArray, FALSE, 1000); //FALSE, INFINITE); 
     57        //TODO KANSE ÄNDRA HÄR... Svårt att se effekten säkert, men lite nytta verkade det göra... 
     58                if (result == WAIT_TIMEOUT) { 
     59                        //return false; 
     60                        continue; 
     61                } 
     62                TelldusCore::MutexLocker locker(&d->mutex); 
     63                int eventIndex = result - WAIT_OBJECT_0; 
     64                if (eventIndex >= d->eventCount) { 
     65                        return false; 
     66                } 
     67                return true; 
    5968        } 
    60         int eventIndex = result - WAIT_OBJECT_0; 
    61         if (eventIndex >= d->eventCount) { 
    62                 return false; 
    63         } 
    64         return true; 
    6569} 
  • telldus-core/service/EventUpdateManager.cpp

    rf25ca4 r245864  
    55#include "Message.h" 
    66#include "Socket.h" 
     7//#include "common.h" //debug 
    78 
    89#include <list> 
     
    7475void EventUpdateManager::sendMessageToClients(EventUpdateData *data){ 
    7576 
     77        int connected = 0; 
    7678        for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();){ 
    77  
    7879                if((*it)->isConnected()){ 
    79  
     80                        connected++; 
    8081                        TelldusCore::Message msg; 
    8182 
     
    117118                } 
    118119        } 
     120        //debuglog(connected, " - number of clients"); 
     121        //debuglog(temp2, " - number of clients total"); 
    119122} 
  • telldus-core/service/ProtocolNexa.cpp

    ree627e r245864  
    44#include "TellStick.h" 
    55#include "Strings.h" 
    6 #include "common.h" 
    76 
    87int ProtocolNexa::lastArctecCodeSwitchWasTurnOff=0;  //TODO, always removing first turnon now, make more flexible (waveman too) 
  • telldus-core/service/SettingsWinRegistry.cpp

    rc36430 r245864  
    11#include "Settings.h" 
     2#include "Strings.h" 
    23#include <Windows.h> 
    34#include <sstream>  
     
    67#include <iostream> 
    78#include <fstream> 
     9#include "common.h" 
    810 
    911#include "../client/telldus-core.h" 
     
    9496        intDeviceId = getNextDeviceId(); 
    9597 
    96         std::wostringstream ssRegPath;  
    97         ssRegPath << d->strRegPathDevice << intDeviceId; 
    98         std::wstring strCompleteRegPath = ssRegPath.str(); 
     98        //std::wostringstream ssRegPath;  
     99        //ssRegPath << d->strRegPathDevice << intDeviceId; 
     100        //std::wstring strCompleteRegPath = ssRegPath.str(); 
     101        std::wstring strCompleteRegPath = d->strRegPathDevice; 
     102        strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 
    99103                 
    100104        if (RegCreateKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)) { 
     
    144148        TelldusCore::MutexLocker locker(&mutex); 
    145149         
    146         std::wostringstream ssRegPath;  
    147         ssRegPath << d->strRegPathDevice << intDeviceId; 
    148         std::wstring strCompleteRegPath = ssRegPath.str(); 
     150        //std::wostringstream ssRegPath;  
     151        //ssRegPath << d->strRegPathDevice << intDeviceId; 
     152        //std::wstring strCompleteRegPath = ssRegPath.str(); 
     153        std::wstring strCompleteRegPath = d->strRegPathDevice; 
     154        strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 
    149155 
    150156        long lngSuccess = RegDeleteKey(d->rootKey, strCompleteRegPath.c_str()); 
     
    162168        HKEY hk; 
    163169 
    164         std::wostringstream ssRegPath;  
    165         ssRegPath << d->strRegPathDevice << intDeviceId; 
    166         std::wstring strCompleteRegPath = ssRegPath.str(); 
     170        //std::wostringstream ssRegPath;  
     171        //ssRegPath << d->strRegPathDevice << intDeviceId; 
     172        //std::wstring strCompleteRegPath = ssRegPath.str(); 
     173        std::wstring strCompleteRegPath = d->strRegPathDevice; 
     174        strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 
    167175        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 
    168176                         
     
    192200        int ret = TELLSTICK_SUCCESS; 
    193201                 
    194         std::wostringstream ssRegPath;  
    195         ssRegPath << d->strRegPathDevice << intDeviceId; 
    196         std::wstring strCompleteRegPath = ssRegPath.str(); 
     202        //std::wostringstream ssRegPath;  
     203        //ssRegPath << d->strRegPathDevice << intDeviceId; 
     204        //std::wstring strCompleteRegPath = ssRegPath.str(); 
     205        //debuglog(intDeviceId, "Device id"); 
     206        std::wstring bla = TelldusCore::intToWstring(intDeviceId); 
     207        //debuglog(888, TelldusCore::wideToString(bla)); 
     208        //debuglog(555, TelldusCore::wideToString(d->strRegPathDevice)); 
     209        std::wstring strCompleteRegPath = d->strRegPathDevice; 
     210        strCompleteRegPath.append(bla); 
     211        //debuglog(999, TelldusCore::wideToString(strCompleteRegPath)); 
    197212        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 
    198213                                 
     
    224239        HKEY hk; 
    225240 
    226         std::wostringstream ssRegPath;  
    227         ssRegPath << d->strRegPathDevice << intDeviceId; 
    228         std::wstring strCompleteRegPath = ssRegPath.str(); 
     241        //std::wostringstream ssRegPath;  
     242        //ssRegPath << d->strRegPathDevice << intDeviceId; 
     243        //std::wstring strCompleteRegPath = ssRegPath.str(); 
     244        std::wstring strCompleteRegPath =  d->strRegPathDevice; 
     245        strCompleteRegPath.append(TelldusCore::intToWstring(intDeviceId)); 
    229246        long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 
    230247        if (lnExists == ERROR_SUCCESS) { 
Note: See TracChangeset for help on using the changeset viewer.