From 407cf1584a079c65d91b658858fd64fdd94daa7d Mon Sep 17 00:00:00 2001 From: Stefan Persson Date: Mon, 11 Oct 2010 08:08:08 +0000 Subject: [PATCH] tdGetNumberOfDevices now communicates as expected. --- telldus-core/client/telldus-core.cpp | 6 ++-- telldus-core/common/Socket.h | 3 +- telldus-core/common/Socket_win.cpp | 33 ++++++++++--------- .../service/ClientCommunicationHandler.cpp | 11 ++++--- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/telldus-core/client/telldus-core.cpp b/telldus-core/client/telldus-core.cpp index 3f8c5d93..ab2b1df4 100644 --- a/telldus-core/client/telldus-core.cpp +++ b/telldus-core/client/telldus-core.cpp @@ -6,6 +6,7 @@ #include "telldus-core.h" #include "common.h" +#include "Message.h" #include "Socket.h" #include @@ -186,12 +187,13 @@ char * WINAPI tdLastSentValue( int intDeviceId ) { * @returns an integer of the total number of devices configured */ int WINAPI tdGetNumberOfDevices(void){ - TelldusCore::Socket s(L"TelldusClient"); + TelldusCore::Socket s; + s.connect(L"TelldusClient"); std::wstring msg = L"20:tdGetNumberOfDevices"; s.write(msg); std::wstring response = s.read(); - return 1; + return TelldusCore::Message::takeInt(&response); } /** diff --git a/telldus-core/common/Socket.h b/telldus-core/common/Socket.h index 02f0961c..5c95a64a 100644 --- a/telldus-core/common/Socket.h +++ b/telldus-core/common/Socket.h @@ -14,10 +14,11 @@ namespace TelldusCore { class Socket { public: - Socket(const std::wstring &server); + Socket(); Socket(SOCKET_T hPipe); virtual ~Socket(void); + void connect(const std::wstring &server); std::wstring read(); void write(const std::wstring &msg); diff --git a/telldus-core/common/Socket_win.cpp b/telldus-core/common/Socket_win.cpp index 1cc48376..b4051cb2 100644 --- a/telldus-core/common/Socket_win.cpp +++ b/telldus-core/common/Socket_win.cpp @@ -14,10 +14,27 @@ public: bool connected; }; -Socket::Socket(const std::wstring &server) { +Socket::Socket() { d = new PrivateData; d->connected = false; +} +Socket::Socket(SOCKET_T hPipe) +{ + d = new PrivateData; + d->hPipe = hPipe; + +} + + +Socket::~Socket(void){ + if (d->hPipe != INVALID_HANDLE_VALUE) { + CloseHandle(d->hPipe); + } + delete d; +} + +void Socket::connect(const std::wstring &server){ bool fSuccess = false; std::wstring name(L"\\\\.\\pipe\\" + server); @@ -48,20 +65,6 @@ Socket::Socket(const std::wstring &server) { d->connected = true; } -Socket::Socket(SOCKET_T hPipe) -{ - d = new PrivateData; - d->hPipe = hPipe; - -} - -Socket::~Socket(void){ - if (d->hPipe != INVALID_HANDLE_VALUE) { - CloseHandle(d->hPipe); - } - delete d; -} - std::wstring Socket::read() { wchar_t buf[BUFSIZE]; int result; diff --git a/telldus-core/service/ClientCommunicationHandler.cpp b/telldus-core/service/ClientCommunicationHandler.cpp index 173e8a8d..cf0585a5 100644 --- a/telldus-core/service/ClientCommunicationHandler.cpp +++ b/telldus-core/service/ClientCommunicationHandler.cpp @@ -51,8 +51,9 @@ void ClientCommunicationHandler::run(){ if(strReturn == L""){ msg.addArgument(intTemp); } - // msg.addArgument(temp); //temp.toString().toStdString()); - //} + else{ + msg.addArgument(strReturn); //temp.toString().toStdString()); + } msg.append(L"\n"); d->clientSocket->write(msg); @@ -76,8 +77,8 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage, //return L"12"; intReturn = 12; } - - intReturn = 5; - + else{ + intReturn = 5; + } //return L"5"; }