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/SetupWizard.cpp \
src/IpcClient.cpp \
src/IpcReader.cpp
src/IpcReader.cpp \
src/Ipc.cpp
HEADERS += src/MainWindow.h \
src/AboutDialog.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,
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);
char codeBuf[1];
codeBuf[0] = code;
stream.writeRawData(codeBuf, 1);
switch (code) {
case kIpcHello:
stream.writeRawData(kIpcMsgHello, 4);
stream.writeRawData(data, 1);
break;
case kIpcCommand: {
char lenBuf[2];
intToBytes(length, lenBuf, 2);
stream.writeRawData(lenBuf, 2);
char lenBuf[4];
intToBytes(length, lenBuf, 4);
stream.writeRawData(kIpcMsgCommand, 4);
stream.writeRawData(lenBuf, 4);
stream.writeRawData(data, length);
break;
}
@ -102,10 +101,19 @@ void IpcClient::handleReadLogLine(const QString& text)
// TODO: qt must have a built in way of converting int to bytes.
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[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 {
// TODO: other sizes, if needed.
}

View File

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