* Use Deskflow Name * Remove business-oriented options from issue templates * Remove business-oriented workflow * Bump version to 3.0.0 (to avoid confusion with previously used version numbers 1.x & 2.x) * Update readme to reflect new project name and goals * Found some more "synergy" to rename * Rename `synlib` to `app` * Rename `syntool` to `deskflow-legacy` * Rename `synwinhk` to `dfwhook` * Rename dirs from synergy to deskflow * Rename more "Synergy" files * Rename app bundle ID * Fixed copyright typo * Rename only title in serial key dialog (to be moved downstream later) * Preserve original serial key window for moving downstream * Restore dialogs ready for moving downstream * Rename `QDeskflowApplication` to `DeskflowApplication` (the Q is confusing) * Restore Volker's original project name * Fixed mimetype * Fixed weird grammar * Fixed (more) weird grammar * Broken link, restoring (but we should move all links out of source) * Broken link, restoring (but we should move all links out of source) * Add write permission to valgrind-analysis.yml * Restore AUR conflicts * Apply Clang format * Update ChangeLog * Back out version change --------- Co-authored-by: Nick Bolton <nick@symless.com>
112 lines
3.2 KiB
C++
112 lines
3.2 KiB
C++
/*
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
|
* 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 LICENSE 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/IpcServerProxy.h"
|
|
|
|
#include "base/Log.h"
|
|
#include "base/TMethodEventJob.h"
|
|
#include "common/ipc.h"
|
|
#include "deskflow/ProtocolUtil.h"
|
|
#include "io/IStream.h"
|
|
#include "ipc/IpcMessage.h"
|
|
|
|
//
|
|
// IpcServerProxy
|
|
//
|
|
|
|
IpcServerProxy::IpcServerProxy(deskflow::IStream &stream, IEventQueue *events)
|
|
: m_stream(stream),
|
|
m_events(events) {
|
|
m_events->adoptHandler(
|
|
m_events->forIStream().inputReady(), stream.getEventTarget(),
|
|
new TMethodEventJob<IpcServerProxy>(this, &IpcServerProxy::handleData));
|
|
}
|
|
|
|
IpcServerProxy::~IpcServerProxy() {
|
|
m_events->removeHandler(
|
|
m_events->forIStream().inputReady(), m_stream.getEventTarget());
|
|
}
|
|
|
|
void IpcServerProxy::handleData(const Event &, void *) {
|
|
LOG((CLOG_DEBUG "start ipc handle data"));
|
|
|
|
UInt8 code[4];
|
|
UInt32 n = m_stream.read(code, 4);
|
|
while (n != 0) {
|
|
|
|
LOG((CLOG_DEBUG "ipc read: %c%c%c%c", code[0], code[1], code[2], code[3]));
|
|
|
|
IpcMessage *m = nullptr;
|
|
if (memcmp(code, kIpcMsgLogLine, 4) == 0) {
|
|
m = parseLogLine();
|
|
} else if (memcmp(code, kIpcMsgShutdown, 4) == 0) {
|
|
m = new IpcShutdownMessage();
|
|
} else {
|
|
LOG((CLOG_ERR "invalid ipc message"));
|
|
disconnect();
|
|
}
|
|
|
|
// don't delete with this event; the data is passed to a new event.
|
|
Event e(
|
|
m_events->forIpcServerProxy().messageReceived(), this, NULL,
|
|
Event::kDontFreeData);
|
|
e.setDataObject(m);
|
|
m_events->addEvent(e);
|
|
|
|
n = m_stream.read(code, 4);
|
|
}
|
|
|
|
LOG((CLOG_DEBUG "finished ipc handle data"));
|
|
}
|
|
|
|
void IpcServerProxy::send(const IpcMessage &message) {
|
|
LOG((CLOG_DEBUG4 "ipc write: %d", message.type()));
|
|
|
|
switch (message.type()) {
|
|
case IpcMessageType::Hello: {
|
|
const IpcHelloMessage &hm = static_cast<const IpcHelloMessage &>(message);
|
|
ProtocolUtil::writef(&m_stream, kIpcMsgHello, hm.clientType());
|
|
break;
|
|
}
|
|
|
|
case IpcMessageType::Command: {
|
|
const IpcCommandMessage &cm =
|
|
static_cast<const IpcCommandMessage &>(message);
|
|
const String command = cm.command();
|
|
ProtocolUtil::writef(&m_stream, kIpcMsgCommand, &command);
|
|
break;
|
|
}
|
|
|
|
default:
|
|
LOG((CLOG_ERR "ipc message not supported: %d", message.type()));
|
|
break;
|
|
}
|
|
}
|
|
|
|
IpcLogLineMessage *IpcServerProxy::parseLogLine() {
|
|
String logLine;
|
|
ProtocolUtil::readf(&m_stream, kIpcMsgLogLine + 4, &logLine);
|
|
|
|
// must be deleted by event handler.
|
|
return new IpcLogLineMessage(logLine);
|
|
}
|
|
|
|
void IpcServerProxy::disconnect() {
|
|
LOG((CLOG_DEBUG "ipc disconnect, closing stream"));
|
|
m_stream.close();
|
|
}
|