Changeset 245864
- Timestamp:
- 11/04/11 14:32:22 (19 months ago)
- 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
- Location:
- telldus-core
- Files:
-
- 12 edited
-
client/CallbackDispatcher.cpp (modified) (2 diffs)
-
client/Client.cpp (modified) (6 diffs)
-
common/Message.cpp (modified) (2 diffs)
-
common/Message.h (modified) (1 diff)
-
common/Socket_win.cpp (modified) (6 diffs)
-
common/Strings.cpp (modified) (1 diff)
-
common/Strings.h (modified) (1 diff)
-
service/ClientCommunicationHandler.cpp (modified) (1 diff)
-
service/EventHandler_win.cpp (modified) (1 diff)
-
service/EventUpdateManager.cpp (modified) (3 diffs)
-
service/ProtocolNexa.cpp (modified) (1 diff)
-
service/SettingsWinRegistry.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telldus-core/client/CallbackDispatcher.cpp
r9535ec r245864 9 9 10 10 #include "CallbackDispatcher.h" 11 #include "common.h" 11 12 12 13 using namespace TelldusCore; … … 29 30 30 31 void TDDeviceEventDispatcher::run() { 32 char *str = wrapStdString(strData); 31 33 d->event(deviceId, method, strData.c_str(), d->id, d->context); 34 32 35 doneRunning = true; 33 36 } -
telldus-core/client/Client.cpp
r9535ec r245864 131 131 callback->context = context; 132 132 d->deviceEventList.push_back(callback); 133 //debuglog(id, "deviceeventadded"); 133 134 return id; 134 135 } … … 142 143 callback->context = context; 143 144 d->deviceChangeEventList.push_back(callback); 145 //debuglog(id, "devicechangeeventadded"); 144 146 return id; 145 147 } … … 177 179 if(!d->eventSocket.isConnected()){ 178 180 //reconnect didn't succeed, wait a while and try again 181 //debuglog(0, "Reconnecting"); 179 182 msleep(2000); 180 183 continue; … … 183 186 184 187 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 }*/ 185 193 while(clientMessage != L""){ 194 //debuglog(99, TelldusCore::wideToString(clientMessage)); 195 //test++; 196 /*if(test > 5){ 197 debuglog(test, "Test is getting big"); 198 }*/ 186 199 //a message arrived 187 200 std::wstring type = Message::takeString(&clientMessage); … … 283 296 284 297 std::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; 295 345 } 296 346 … … 301 351 302 352 bool Client::unregisterCallback( int callbackId ) { 353 //debuglog(callbackId, "unregistering"); 303 354 DeviceEventList newDEList; 304 355 { -
telldus-core/common/Message.cpp
rfe7f8f r245864 24 24 25 25 void 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()); 29 29 this->append(L":"); 30 30 this->append(value); … … 32 32 33 33 void Message::addArgument(int value) { 34 std::wstringstream st;35 st << (int)value;34 //std::wstringstream st; 35 //st << (int)value; 36 36 this->append(L"i"); 37 this->append( st.str());37 this->append(TelldusCore::intToWstring(value)); // st.str()); 38 38 this->append(L"s"); 39 39 } 40 41 /* 42 void 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 70 void 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 /* 85 void Message::addSpecialArgument(const char *value){ 86 this->addSpecialArgument(TelldusCore::charToWstring(value)); 87 } 88 */ 40 89 41 90 void Message::addArgument(const char *value) { -
telldus-core/common/Message.h
rfe7f8f r245864 12 12 13 13 void addArgument(const std::wstring &); 14 //void addSpecialArgument(const std::wstring &); 15 //void addSpecialArgument(int); 16 //void addSpecialArgument(const char *); 14 17 void addArgument(int); 15 18 void addArgument(const char *); -
telldus-core/common/Socket_win.cpp
rffeb0b7 r245864 1 1 #include "Socket.h" 2 #include "common.h" 2 3 3 4 #include <windows.h> … … 103 104 CancelIo(d->hPipe); 104 105 CloseHandle(d->readEvent); 106 //debuglog(1, "Not running"); 105 107 return L""; 106 108 } … … 109 111 CancelIo(d->hPipe); 110 112 CloseHandle(d->readEvent); 113 //debuglog(1, "Wait timeout"); 111 114 return L""; 112 115 } … … 114 117 if (!fSuccess) { 115 118 DWORD err = GetLastError(); 119 //debuglog(result, "This then?"); 120 //debuglog(1, "Unsuccessful"); 121 116 122 if (err == ERROR_BROKEN_PIPE) { 123 //debuglog(1, "Broken pipe"); 117 124 d->connected = false; 118 125 } … … 144 151 CloseHandle(writeEvent); 145 152 d->connected = false; 153 //debuglog(2, "Wait timeout"); 146 154 return; 147 155 } … … 151 159 CancelIo(d->hPipe); 152 160 d->connected = false; 161 //debuglog(2, "Unsuccessful"); 153 162 return; 154 163 } -
telldus-core/common/Strings.cpp
r11dd17 r245864 92 92 93 93 std::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 94 107 std::wstringstream st; 95 108 st << value; 96 109 return st.str(); 110 #endif 97 111 } 98 112 99 113 std::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 100 121 std::stringstream st; 101 122 st << value; 102 123 return st.str(); 103 } 124 #endif 125 } 126 127 /* 128 std::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 */ 104 145 105 146 int TelldusCore::wideToInteger(const std::wstring &input){ -
telldus-core/common/Strings.h
r11dd17 r245864 11 11 bool comparei(std::wstring stringA, std::wstring stringB); 12 12 std::wstring intToWstring(int value); 13 //std::wstring intToWStringSafe(int value); 13 14 std::string intToString(int value); 14 15 std::string wideToString(const std::wstring &input); -
telldus-core/service/ClientCommunicationHandler.cpp
rad1b18 r245864 82 82 83 83 } else if (function == L"tdBell") { 84 //TelldusCore::Message msg2; 85 //msg2.addSpecialArgument(18); 86 //msg2.addSpecialArgument("testgrej"); 87 84 88 int deviceId = TelldusCore::Message::takeInt(&msg); 85 89 (*intReturn) = d->deviceManager->doAction(deviceId, TELLSTICK_BELL, 0); -
telldus-core/service/EventHandler_win.cpp
r485b1e r245864 52 52 53 53 bool 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; 59 68 } 60 int eventIndex = result - WAIT_OBJECT_0;61 if (eventIndex >= d->eventCount) {62 return false;63 }64 return true;65 69 } -
telldus-core/service/EventUpdateManager.cpp
rf25ca4 r245864 5 5 #include "Message.h" 6 6 #include "Socket.h" 7 //#include "common.h" //debug 7 8 8 9 #include <list> … … 74 75 void EventUpdateManager::sendMessageToClients(EventUpdateData *data){ 75 76 77 int connected = 0; 76 78 for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();){ 77 78 79 if((*it)->isConnected()){ 79 80 connected++; 80 81 TelldusCore::Message msg; 81 82 … … 117 118 } 118 119 } 120 //debuglog(connected, " - number of clients"); 121 //debuglog(temp2, " - number of clients total"); 119 122 } -
telldus-core/service/ProtocolNexa.cpp
ree627e r245864 4 4 #include "TellStick.h" 5 5 #include "Strings.h" 6 #include "common.h"7 6 8 7 int ProtocolNexa::lastArctecCodeSwitchWasTurnOff=0; //TODO, always removing first turnon now, make more flexible (waveman too) -
telldus-core/service/SettingsWinRegistry.cpp
rc36430 r245864 1 1 #include "Settings.h" 2 #include "Strings.h" 2 3 #include <Windows.h> 3 4 #include <sstream> … … 6 7 #include <iostream> 7 8 #include <fstream> 9 #include "common.h" 8 10 9 11 #include "../client/telldus-core.h" … … 94 96 intDeviceId = getNextDeviceId(); 95 97 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)); 99 103 100 104 if (RegCreateKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hk, &dwDisp)) { … … 144 148 TelldusCore::MutexLocker locker(&mutex); 145 149 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)); 149 155 150 156 long lngSuccess = RegDeleteKey(d->rootKey, strCompleteRegPath.c_str()); … … 162 168 HKEY hk; 163 169 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)); 167 175 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_QUERY_VALUE, &hk); 168 176 … … 192 200 int ret = TELLSTICK_SUCCESS; 193 201 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)); 197 212 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 198 213 … … 224 239 HKEY hk; 225 240 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)); 229 246 long lnExists = RegOpenKeyEx(d->rootKey, strCompleteRegPath.c_str(), 0, KEY_WRITE, &hk); 230 247 if (lnExists == ERROR_SUCCESS) {
Note: See TracChangeset
for help on using the changeset viewer.
