made gui compatible with new version of ipc protocol.

This commit is contained in:
Nick Bolton 2012-07-11 18:28:28 +00:00
parent 82d91605fa
commit 19ccba8126
5 changed files with 64 additions and 29 deletions

View File

@ -37,7 +37,8 @@ SOURCES += src/main.cpp \
src/VersionChecker.cpp \ src/VersionChecker.cpp \
src/SetupWizard.cpp \ src/SetupWizard.cpp \
src/IpcClient.cpp \ src/IpcClient.cpp \
src/IpcReader.cpp src/IpcReader.cpp \
src/Ipc.cpp
HEADERS += src/MainWindow.h \ HEADERS += src/MainWindow.h \
src/AboutDialog.h \ src/AboutDialog.h \
src/ServerConfig.h \ src/ServerConfig.h \

23
src/gui/src/Ipc.cpp Normal file
View File

@ -0,0 +1,23 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2012 Nick Bolton
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file COPYING that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Ipc.h"
const char* kIpcMsgHello = "IHEL%1i";
const char* kIpcMsgLogLine = "ILOG%s";
const char* kIpcMsgCommand = "ICMD%s";
const char* kIpcMsgShutdown = "ISDN";

View File

@ -32,3 +32,8 @@ enum qIpcClientType {
kIpcClientGui, kIpcClientGui,
kIpcClientNode, kIpcClientNode,
}; };
extern const char* kIpcMsgHello;
extern const char* kIpcMsgLogLine;
extern const char* kIpcMsgCommand;
extern const char* kIpcMsgShutdown;

View File

@ -71,19 +71,18 @@ void IpcClient::write(int code, int length, const char* data)
{ {
QDataStream stream(m_Socket); QDataStream stream(m_Socket);
char codeBuf[1];
codeBuf[0] = code;
stream.writeRawData(codeBuf, 1);
switch (code) { switch (code) {
case kIpcHello: case kIpcHello:
stream.writeRawData(kIpcMsgHello, 4);
stream.writeRawData(data, 1); stream.writeRawData(data, 1);
break; break;
case kIpcCommand: { case kIpcCommand: {
char lenBuf[2]; char lenBuf[4];
intToBytes(length, lenBuf, 2); intToBytes(length, lenBuf, 4);
stream.writeRawData(lenBuf, 2);
stream.writeRawData(kIpcMsgCommand, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(data, length); stream.writeRawData(data, length);
break; break;
} }
@ -102,10 +101,19 @@ void IpcClient::handleReadLogLine(const QString& text)
// TODO: qt must have a built in way of converting int to bytes. // TODO: qt must have a built in way of converting int to bytes.
void IpcClient::intToBytes(int value, char *buffer, int size) void IpcClient::intToBytes(int value, char *buffer, int size)
{ {
if (size == 2) { if (size == 1) {
buffer[0] = value & 0xff;
}
else if (size == 2) {
buffer[0] = (value >> 8) & 0xff; buffer[0] = (value >> 8) & 0xff;
buffer[1] = value & 0xff; buffer[1] = value & 0xff;
} }
else if (size == 4) {
buffer[0] = (value >> 24) & 0xff;
buffer[1] = (value >> 16) & 0xff;
buffer[2] = (value >> 8) & 0xff;
buffer[3] = value & 0xff;
}
else { else {
// TODO: other sizes, if needed. // TODO: other sizes, if needed.
} }

View File

@ -44,30 +44,28 @@ void IpcReader::read()
while (m_Socket->bytesAvailable()) { while (m_Socket->bytesAvailable()) {
std::cout << "bytes available" << std::endl; std::cout << "bytes available" << std::endl;
char codeBuf[1]; char codeBuf[5];
readStream(codeBuf, 1); readStream(codeBuf, 4);
int code = bytesToInt(codeBuf, 1); codeBuf[4] = 0;
std::cout << "ipc read: " << codeBuf << std::endl;
switch (code) { if (memcmp(codeBuf, kIpcMsgLogLine, 4) == 0) {
case kIpcLogLine: { std::cout << "reading log line" << std::endl;
std::cout << "reading log line" << std::endl;
char lenBuf[4]; char lenBuf[4];
readStream(lenBuf, 4); readStream(lenBuf, 4);
int len = bytesToInt(lenBuf, 4); int len = bytesToInt(lenBuf, 4);
char* data = new char[len]; char* data = new char[len];
readStream(data, len); readStream(data, len);
QString line = QString::fromUtf8(data, len); QString line = QString::fromUtf8(data, len);
delete data; delete data;
readLogLine(line); readLogLine(line);
break; }
} else {
std::cerr << "aborting, message invalid" << std::endl;
default: return;
std::cerr << "aborting, message invalid: " << code << std::endl;
return;
} }
} }