moved stream into synergy namespace (to prevent naming collision in win libs)
implemented ipc "hello" message (to identify client type) integ tests working for hello message, but use of ipc in main program has problem with events.
This commit is contained in:
parent
4e268760b3
commit
3d6551f708
|
@ -41,6 +41,7 @@ set(inc
|
||||||
../../lib/client
|
../../lib/client
|
||||||
../../lib/common
|
../../lib/common
|
||||||
../../lib/io
|
../../lib/io
|
||||||
|
../../lib/ipc
|
||||||
../../lib/mt
|
../../lib/mt
|
||||||
../../lib/net
|
../../lib/net
|
||||||
../../lib/platform
|
../../lib/platform
|
||||||
|
@ -60,7 +61,7 @@ endif()
|
||||||
include_directories(${inc})
|
include_directories(${inc})
|
||||||
add_executable(synergyc ${src})
|
add_executable(synergyc ${src})
|
||||||
target_link_libraries(synergyc
|
target_link_libraries(synergyc
|
||||||
arch base client common io mt net platform server synergy ${libs})
|
arch base client common io mt net ipc platform server synergy ${libs})
|
||||||
|
|
||||||
if (CONF_CPACK)
|
if (CONF_CPACK)
|
||||||
install(TARGETS
|
install(TARGETS
|
||||||
|
|
|
@ -40,6 +40,7 @@ set(inc
|
||||||
../../lib/base
|
../../lib/base
|
||||||
../../lib/common
|
../../lib/common
|
||||||
../../lib/io
|
../../lib/io
|
||||||
|
../../lib/ipc
|
||||||
../../lib/mt
|
../../lib/mt
|
||||||
../../lib/net
|
../../lib/net
|
||||||
../../lib/platform
|
../../lib/platform
|
||||||
|
@ -60,7 +61,7 @@ endif()
|
||||||
include_directories(${inc})
|
include_directories(${inc})
|
||||||
add_executable(synergys ${src})
|
add_executable(synergys ${src})
|
||||||
target_link_libraries(synergys
|
target_link_libraries(synergys
|
||||||
arch base client common io mt net platform server synergy ${libs})
|
arch base client common io mt net ipc platform server synergy ${libs})
|
||||||
|
|
||||||
if (CONF_CPACK)
|
if (CONF_CPACK)
|
||||||
install(TARGETS
|
install(TARGETS
|
||||||
|
|
|
@ -25,6 +25,7 @@ IpcClient::IpcClient()
|
||||||
{
|
{
|
||||||
m_Socket = new QTcpSocket(this);
|
m_Socket = new QTcpSocket(this);
|
||||||
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
|
connect(m_Socket, SIGNAL(readyRead()), this, SLOT(read()));
|
||||||
|
connect(m_Socket, SIGNAL(connected()), this, SLOT(connected()));
|
||||||
connect(m_Socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
|
connect(m_Socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(error(QAbstractSocket::SocketError)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +33,15 @@ IpcClient::~IpcClient()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IpcClient::connected()
|
||||||
|
{
|
||||||
|
infoMessage("connected to background service");
|
||||||
|
|
||||||
|
char typeBuf[1];
|
||||||
|
typeBuf[0] = kIpcClientGui;
|
||||||
|
write(kIpcHello, 1, typeBuf);
|
||||||
|
}
|
||||||
|
|
||||||
void IpcClient::connectToHost()
|
void IpcClient::connectToHost()
|
||||||
{
|
{
|
||||||
infoMessage("connecting to background service...");
|
infoMessage("connecting to background service...");
|
||||||
|
@ -52,6 +62,7 @@ void IpcClient::read()
|
||||||
char lenBuf[2];
|
char lenBuf[2];
|
||||||
stream.readRawData(lenBuf, 2);
|
stream.readRawData(lenBuf, 2);
|
||||||
int len = bytesToInt(lenBuf, 2);
|
int len = bytesToInt(lenBuf, 2);
|
||||||
|
std::cout << "len: " << len << std::endl;
|
||||||
|
|
||||||
char* data = new char[len];
|
char* data = new char[len];
|
||||||
stream.readRawData(data, len);
|
stream.readRawData(data, len);
|
||||||
|
|
|
@ -42,6 +42,7 @@ private:
|
||||||
void intToBytes(int value, char* buffer, int size);
|
void intToBytes(int value, char* buffer, int size);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void connected();
|
||||||
void read();
|
void read();
|
||||||
void error(QAbstractSocket::SocketError error);
|
void error(QAbstractSocket::SocketError error);
|
||||||
|
|
||||||
|
@ -54,7 +55,15 @@ private:
|
||||||
QTcpSocket* m_Socket;
|
QTcpSocket* m_Socket;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EIpcMessage {
|
enum IpcMessageType {
|
||||||
|
kIpcHello,
|
||||||
kIpcLogLine,
|
kIpcLogLine,
|
||||||
kIpcCommand
|
kIpcCommand,
|
||||||
|
kIpcShutdown,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum IpcClientType {
|
||||||
|
kIpcClientUnknown,
|
||||||
|
kIpcClientGui,
|
||||||
|
kIpcClientNode,
|
||||||
};
|
};
|
||||||
|
|
|
@ -369,6 +369,11 @@ void MainWindow::startSynergy()
|
||||||
{
|
{
|
||||||
setSynergyProcess(new QProcess(this));
|
setSynergyProcess(new QProcess(this));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// tell client/server to talk to daemon through ipc.
|
||||||
|
args << "--ipc";
|
||||||
|
}
|
||||||
|
|
||||||
if ((synergyType() == synergyClient && !clientArgs(args, app))
|
if ((synergyType() == synergyClient && !clientArgs(args, app))
|
||||||
|| (synergyType() == synergyServer && !serverArgs(args, app)))
|
|| (synergyType() == synergyServer && !serverArgs(args, app)))
|
||||||
|
|
|
@ -28,7 +28,7 @@ class CScreen;
|
||||||
class CServerProxy;
|
class CServerProxy;
|
||||||
class IDataSocket;
|
class IDataSocket;
|
||||||
class ISocketFactory;
|
class ISocketFactory;
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
class IStreamFilterFactory;
|
class IStreamFilterFactory;
|
||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ private:
|
||||||
ISocketFactory* m_socketFactory;
|
ISocketFactory* m_socketFactory;
|
||||||
IStreamFilterFactory* m_streamFilterFactory;
|
IStreamFilterFactory* m_streamFilterFactory;
|
||||||
CScreen* m_screen;
|
CScreen* m_screen;
|
||||||
IStream* m_stream;
|
synergy::IStream* m_stream;
|
||||||
CEventQueueTimer* m_timer;
|
CEventQueueTimer* m_timer;
|
||||||
CServerProxy* m_server;
|
CServerProxy* m_server;
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
// CServerProxy
|
// CServerProxy
|
||||||
//
|
//
|
||||||
|
|
||||||
CServerProxy::CServerProxy(CClient* client, IStream* stream, IEventQueue& eventQueue) :
|
CServerProxy::CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue& eventQueue) :
|
||||||
m_client(client),
|
m_client(client),
|
||||||
m_stream(stream),
|
m_stream(stream),
|
||||||
m_seqNum(0),
|
m_seqNum(0),
|
||||||
|
|
|
@ -27,7 +27,7 @@ class CClient;
|
||||||
class CClientInfo;
|
class CClientInfo;
|
||||||
class CEventQueueTimer;
|
class CEventQueueTimer;
|
||||||
class IClipboard;
|
class IClipboard;
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
//! Proxy for server
|
//! Proxy for server
|
||||||
|
@ -41,7 +41,7 @@ public:
|
||||||
Process messages from the server on \p stream and forward to
|
Process messages from the server on \p stream and forward to
|
||||||
\p client.
|
\p client.
|
||||||
*/
|
*/
|
||||||
CServerProxy(CClient* client, IStream* stream, IEventQueue& eventQueue);
|
CServerProxy(CClient* client, synergy::IStream* stream, IEventQueue& eventQueue);
|
||||||
~CServerProxy();
|
~CServerProxy();
|
||||||
|
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
|
@ -104,7 +104,7 @@ private:
|
||||||
typedef EResult (CServerProxy::*MessageParser)(const UInt8*);
|
typedef EResult (CServerProxy::*MessageParser)(const UInt8*);
|
||||||
|
|
||||||
CClient* m_client;
|
CClient* m_client;
|
||||||
IStream* m_stream;
|
synergy::IStream* m_stream;
|
||||||
|
|
||||||
UInt32 m_seqNum;
|
UInt32 m_seqNum;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
// CStreamFilter
|
// CStreamFilter
|
||||||
//
|
//
|
||||||
|
|
||||||
CStreamFilter::CStreamFilter(IStream* stream, bool adoptStream) :
|
CStreamFilter::CStreamFilter(synergy::IStream* stream, bool adoptStream) :
|
||||||
m_stream(stream),
|
m_stream(stream),
|
||||||
m_adopted(adoptStream)
|
m_adopted(adoptStream)
|
||||||
{
|
{
|
||||||
|
@ -96,7 +96,7 @@ CStreamFilter::getSize() const
|
||||||
return getStream()->getSize();
|
return getStream()->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
IStream*
|
synergy::IStream*
|
||||||
CStreamFilter::getStream() const
|
CStreamFilter::getStream() const
|
||||||
{
|
{
|
||||||
return m_stream;
|
return m_stream;
|
||||||
|
|
|
@ -25,14 +25,14 @@
|
||||||
This class wraps a stream. Subclasses provide indirect access
|
This class wraps a stream. Subclasses provide indirect access
|
||||||
to the wrapped stream, typically performing some filtering.
|
to the wrapped stream, typically performing some filtering.
|
||||||
*/
|
*/
|
||||||
class CStreamFilter : public IStream {
|
class CStreamFilter : public synergy::IStream {
|
||||||
public:
|
public:
|
||||||
/*!
|
/*!
|
||||||
Create a wrapper around \c stream. Iff \c adoptStream is true then
|
Create a wrapper around \c stream. Iff \c adoptStream is true then
|
||||||
this object takes ownership of the stream and will delete it in the
|
this object takes ownership of the stream and will delete it in the
|
||||||
d'tor.
|
d'tor.
|
||||||
*/
|
*/
|
||||||
CStreamFilter(IStream* stream, bool adoptStream = true);
|
CStreamFilter(synergy::IStream* stream, bool adoptStream = true);
|
||||||
~CStreamFilter();
|
~CStreamFilter();
|
||||||
|
|
||||||
// IStream overrides
|
// IStream overrides
|
||||||
|
@ -53,7 +53,7 @@ protected:
|
||||||
/*!
|
/*!
|
||||||
Returns the stream passed to the c'tor.
|
Returns the stream passed to the c'tor.
|
||||||
*/
|
*/
|
||||||
IStream* getStream() const;
|
synergy::IStream* getStream() const;
|
||||||
|
|
||||||
//! Handle events from source stream
|
//! Handle events from source stream
|
||||||
/*!
|
/*!
|
||||||
|
@ -66,7 +66,7 @@ private:
|
||||||
void handleUpstreamEvent(const CEvent&, void*);
|
void handleUpstreamEvent(const CEvent&, void*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IStream* m_stream;
|
synergy::IStream* m_stream;
|
||||||
bool m_adopted;
|
bool m_adopted;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#include "IStream.h"
|
#include "IStream.h"
|
||||||
#include "CEventQueue.h"
|
#include "CEventQueue.h"
|
||||||
|
|
||||||
|
using namespace synergy;
|
||||||
|
|
||||||
//
|
//
|
||||||
// IStream
|
// IStream
|
||||||
//
|
//
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
|
namespace synergy {
|
||||||
|
|
||||||
//! Bidirectional stream interface
|
//! Bidirectional stream interface
|
||||||
/*!
|
/*!
|
||||||
Defines the interface for all streams.
|
Defines the interface for all streams.
|
||||||
|
@ -165,4 +167,6 @@ private:
|
||||||
static CEvent::Type s_outputShutdownEvent;
|
static CEvent::Type s_outputShutdownEvent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
|
|
||||||
#include "IInterface.h"
|
#include "IInterface.h"
|
||||||
|
|
||||||
class IStream;
|
using namespace synergy;
|
||||||
|
namespace synergy { class IStream; }
|
||||||
|
|
||||||
//! Stream filter factory interface
|
//! Stream filter factory interface
|
||||||
/*!
|
/*!
|
||||||
|
@ -33,7 +34,7 @@ public:
|
||||||
Create and return a stream filter on \p stream. The caller must
|
Create and return a stream filter on \p stream. The caller must
|
||||||
delete the returned object.
|
delete the returned object.
|
||||||
*/
|
*/
|
||||||
virtual IStream* create(IStream* stream, bool adoptStream) = 0;
|
virtual synergy::IStream* create(IStream* stream, bool adoptStream) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,16 +18,26 @@
|
||||||
#include "CIpcClient.h"
|
#include "CIpcClient.h"
|
||||||
#include "Ipc.h"
|
#include "Ipc.h"
|
||||||
#include "CIpcServerProxy.h"
|
#include "CIpcServerProxy.h"
|
||||||
|
#include "TMethodEventJob.h"
|
||||||
|
#include "CIpcMessage.h"
|
||||||
|
|
||||||
|
CEvent::Type CIpcClient::s_connectedEvent = CEvent::kUnknown;
|
||||||
|
|
||||||
CIpcClient::CIpcClient() :
|
CIpcClient::CIpcClient() :
|
||||||
m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT)),
|
m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT)),
|
||||||
m_server(nullptr)
|
m_server(nullptr)
|
||||||
{
|
{
|
||||||
m_serverAddress.resolve();
|
m_serverAddress.resolve();
|
||||||
|
|
||||||
|
EVENTQUEUE->adoptHandler(
|
||||||
|
m_socket.getConnectedEvent(), &m_socket,
|
||||||
|
new TMethodEventJob<CIpcClient>(
|
||||||
|
this, &CIpcClient::handleConnected));
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcClient::~CIpcClient()
|
CIpcClient::~CIpcClient()
|
||||||
{
|
{
|
||||||
|
delete m_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -43,3 +53,21 @@ CIpcClient::send(const CIpcMessage& message)
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
m_server->send(message);
|
m_server->send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CEvent::Type
|
||||||
|
CIpcClient::getConnectedEvent()
|
||||||
|
{
|
||||||
|
return EVENTQUEUE->registerTypeOnce(
|
||||||
|
s_connectedEvent, "CIpcClient::connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CIpcClient::handleConnected(const CEvent&, void*)
|
||||||
|
{
|
||||||
|
EVENTQUEUE->addEvent(CEvent(getConnectedEvent(), this, m_server, CEvent::kDontFreeData));
|
||||||
|
|
||||||
|
CIpcMessage message;
|
||||||
|
message.m_type = kIpcHello;
|
||||||
|
message.m_data = new UInt8(kIpcClientNode);
|
||||||
|
send(message);
|
||||||
|
}
|
||||||
|
|
|
@ -32,14 +32,31 @@ public:
|
||||||
CIpcClient();
|
CIpcClient();
|
||||||
virtual ~CIpcClient();
|
virtual ~CIpcClient();
|
||||||
|
|
||||||
|
//! @name manipulators
|
||||||
|
//@{
|
||||||
|
|
||||||
//! Connects to the IPC server at localhost.
|
//! Connects to the IPC server at localhost.
|
||||||
void connect();
|
void connect();
|
||||||
|
|
||||||
//! Sends a message to the server.
|
//! Sends a message to the server.
|
||||||
void send(const CIpcMessage& message);
|
void send(const CIpcMessage& message);
|
||||||
|
|
||||||
|
//@}
|
||||||
|
//! @name accessors
|
||||||
|
//@{
|
||||||
|
|
||||||
|
//! Raised when the socket is connected.
|
||||||
|
static CEvent::Type getConnectedEvent();
|
||||||
|
|
||||||
|
//@}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void handleConnected(const CEvent&, void*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CNetworkAddress m_serverAddress;
|
CNetworkAddress m_serverAddress;
|
||||||
CTCPSocket m_socket;
|
CTCPSocket m_socket;
|
||||||
CIpcServerProxy* m_server;
|
CIpcServerProxy* m_server;
|
||||||
|
|
||||||
|
static CEvent::Type s_connectedEvent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,20 +25,23 @@
|
||||||
|
|
||||||
CEvent::Type CIpcClientProxy::s_messageReceivedEvent = CEvent::kUnknown;
|
CEvent::Type CIpcClientProxy::s_messageReceivedEvent = CEvent::kUnknown;
|
||||||
|
|
||||||
CIpcClientProxy::CIpcClientProxy(IStream& stream) :
|
CIpcClientProxy::CIpcClientProxy(synergy::IStream& stream) :
|
||||||
m_stream(stream),
|
m_stream(stream),
|
||||||
m_enableLog(false)
|
m_enableLog(false),
|
||||||
|
m_clientType(kIpcClientUnknown)
|
||||||
{
|
{
|
||||||
EVENTQUEUE->adoptHandler(m_stream.getInputReadyEvent(),
|
EVENTQUEUE->adoptHandler(
|
||||||
stream.getEventTarget(),
|
m_stream.getInputReadyEvent(), stream.getEventTarget(),
|
||||||
new TMethodEventJob<CIpcClientProxy>(
|
new TMethodEventJob<CIpcClientProxy>(
|
||||||
this, &CIpcClientProxy::handleData, nullptr));
|
this, &CIpcClientProxy::handleData, nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcClientProxy::~CIpcClientProxy()
|
CIpcClientProxy::~CIpcClientProxy()
|
||||||
{
|
{
|
||||||
EVENTQUEUE->removeHandler(m_stream.getInputReadyEvent(),
|
EVENTQUEUE->removeHandler(
|
||||||
m_stream.getEventTarget());
|
m_stream.getInputReadyEvent(), m_stream.getEventTarget());
|
||||||
|
|
||||||
|
m_stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -57,6 +60,10 @@ CIpcClientProxy::handleData(const CEvent&, void*)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case kIpcHello:
|
||||||
|
parseHello();
|
||||||
|
break;
|
||||||
|
|
||||||
case kIpcCommand:
|
case kIpcCommand:
|
||||||
m->m_data = parseCommand();
|
m->m_data = parseCommand();
|
||||||
break;
|
break;
|
||||||
|
@ -94,7 +101,11 @@ CIpcClientProxy::send(const CIpcMessage& message)
|
||||||
CProtocolUtil::writef(&m_stream, "%2i", len);
|
CProtocolUtil::writef(&m_stream, "%2i", len);
|
||||||
|
|
||||||
m_stream.write(data, len);
|
m_stream.write(data, len);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kIpcShutdown:
|
||||||
|
// no data.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -105,6 +116,14 @@ CIpcClientProxy::send(const CIpcMessage& message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CIpcClientProxy::parseHello()
|
||||||
|
{
|
||||||
|
UInt8 buffer[1];
|
||||||
|
m_stream.read(buffer, 1);
|
||||||
|
m_clientType = static_cast<EIpcClientType>(buffer[0]);
|
||||||
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
CIpcClientProxy::parseCommand()
|
CIpcClientProxy::parseCommand()
|
||||||
{
|
{
|
||||||
|
@ -114,6 +133,7 @@ CIpcClientProxy::parseCommand()
|
||||||
UInt8* buffer = new UInt8[len];
|
UInt8* buffer = new UInt8[len];
|
||||||
m_stream.read(buffer, len);
|
m_stream.read(buffer, len);
|
||||||
|
|
||||||
|
// delete by event cleanup.
|
||||||
return new CString((const char*)buffer, len);
|
return new CString((const char*)buffer, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CEvent.h"
|
#include "CEvent.h"
|
||||||
|
#include "Ipc.h"
|
||||||
|
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
class CIpcMessage;
|
class CIpcMessage;
|
||||||
|
|
||||||
class CIpcClientProxy {
|
class CIpcClientProxy {
|
||||||
public:
|
public:
|
||||||
CIpcClientProxy(IStream& stream);
|
CIpcClientProxy(synergy::IStream& stream);
|
||||||
virtual ~CIpcClientProxy();
|
virtual ~CIpcClientProxy();
|
||||||
|
|
||||||
//! Send a message to the client.
|
//! Send a message to the client.
|
||||||
|
@ -35,12 +36,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleData(const CEvent&, void*);
|
void handleData(const CEvent&, void*);
|
||||||
|
void parseHello();
|
||||||
void* parseCommand();
|
void* parseCommand();
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IStream& m_stream;
|
synergy::IStream& m_stream;
|
||||||
bool m_enableLog;
|
bool m_enableLog;
|
||||||
|
EIpcClientType m_clientType;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CEvent::Type s_messageReceivedEvent;
|
static CEvent::Type s_messageReceivedEvent;
|
||||||
|
|
|
@ -50,6 +50,6 @@ CIpcLogOutputter::write(ELevel level, const char* msg)
|
||||||
CIpcMessage message;
|
CIpcMessage message;
|
||||||
message.m_type = kIpcLogLine;
|
message.m_type = kIpcLogLine;
|
||||||
message.m_data = new CString(msg);
|
message.m_data = new CString(msg);
|
||||||
m_ipcServer.send(message);
|
m_ipcServer.send(message, kIpcClientGui);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,19 @@ m_address(CNetworkAddress(IPC_HOST, IPC_PORT))
|
||||||
m_address.resolve();
|
m_address.resolve();
|
||||||
|
|
||||||
EVENTQUEUE->adoptHandler(
|
EVENTQUEUE->adoptHandler(
|
||||||
IListenSocket::getConnectingEvent(), &m_socket,
|
m_socket.getConnectingEvent(), &m_socket,
|
||||||
new TMethodEventJob<CIpcServer>(
|
new TMethodEventJob<CIpcServer>(
|
||||||
this, &CIpcServer::handleClientConnecting));
|
this, &CIpcServer::handleClientConnecting));
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcServer::~CIpcServer()
|
CIpcServer::~CIpcServer()
|
||||||
{
|
{
|
||||||
EVENTQUEUE->removeHandler(IListenSocket::getConnectingEvent(), &m_socket);
|
CClientSet::iterator it;
|
||||||
|
for (it = m_clients.begin(); it != m_clients.end(); it++) {
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENTQUEUE->removeHandler(m_socket.getConnectingEvent(), &m_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -53,12 +58,11 @@ CIpcServer::listen()
|
||||||
void
|
void
|
||||||
CIpcServer::handleClientConnecting(const CEvent&, void*)
|
CIpcServer::handleClientConnecting(const CEvent&, void*)
|
||||||
{
|
{
|
||||||
IStream* stream = m_socket.accept();
|
synergy::IStream* stream = m_socket.accept();
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// when there is already a client connected, this causes stack overflow,
|
|
||||||
//
|
|
||||||
LOG((CLOG_NOTE "accepted ipc client connection"));
|
LOG((CLOG_NOTE "accepted ipc client connection"));
|
||||||
|
|
||||||
// TODO: delete on disconnect
|
// TODO: delete on disconnect
|
||||||
|
@ -76,10 +80,13 @@ CIpcServer::getClientConnectedEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CIpcServer::send(const CIpcMessage& message)
|
CIpcServer::send(const CIpcMessage& message, EIpcClientType filterType)
|
||||||
{
|
{
|
||||||
CClientSet::iterator it;
|
CClientSet::iterator it;
|
||||||
for (it = m_clients.begin(); it != m_clients.end(); it++) {
|
for (it = m_clients.begin(); it != m_clients.end(); it++) {
|
||||||
(*it)->send(message);
|
CIpcClientProxy* proxy = *it;
|
||||||
|
if (proxy->m_clientType == filterType) {
|
||||||
|
proxy->send(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "CTCPListenSocket.h"
|
#include "CTCPListenSocket.h"
|
||||||
#include "CNetworkAddress.h"
|
#include "CNetworkAddress.h"
|
||||||
|
#include "Ipc.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
class CEvent;
|
class CEvent;
|
||||||
|
@ -43,8 +44,8 @@ public:
|
||||||
//! Opens a TCP socket only allowing local connections.
|
//! Opens a TCP socket only allowing local connections.
|
||||||
void listen();
|
void listen();
|
||||||
|
|
||||||
//! Send a message to all clients.
|
//! Send a message to all clients matching the filter type.
|
||||||
void send(const CIpcMessage& message);
|
void send(const CIpcMessage& message, EIpcClientType filterType);
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
//! @name accessors
|
//! @name accessors
|
||||||
|
|
|
@ -25,19 +25,21 @@
|
||||||
|
|
||||||
CEvent::Type CIpcServerProxy::s_messageReceivedEvent = CEvent::kUnknown;
|
CEvent::Type CIpcServerProxy::s_messageReceivedEvent = CEvent::kUnknown;
|
||||||
|
|
||||||
CIpcServerProxy::CIpcServerProxy(IStream& stream) :
|
CIpcServerProxy::CIpcServerProxy(synergy::IStream& stream) :
|
||||||
m_stream(stream)
|
m_stream(stream)
|
||||||
{
|
{
|
||||||
EVENTQUEUE->adoptHandler(m_stream.getInputReadyEvent(),
|
EVENTQUEUE->adoptHandler(m_stream.getInputReadyEvent(),
|
||||||
stream.getEventTarget(),
|
stream.getEventTarget(),
|
||||||
new TMethodEventJob<CIpcServerProxy>(
|
new TMethodEventJob<CIpcServerProxy>(
|
||||||
this, &CIpcServerProxy::handleData, nullptr));
|
this, &CIpcServerProxy::handleData));
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcServerProxy::~CIpcServerProxy()
|
CIpcServerProxy::~CIpcServerProxy()
|
||||||
{
|
{
|
||||||
EVENTQUEUE->removeHandler(m_stream.getInputReadyEvent(),
|
EVENTQUEUE->removeHandler(m_stream.getInputReadyEvent(),
|
||||||
m_stream.getEventTarget());
|
m_stream.getEventTarget());
|
||||||
|
|
||||||
|
m_stream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -48,14 +50,18 @@ CIpcServerProxy::handleData(const CEvent&, void*)
|
||||||
while (n != 0) {
|
while (n != 0) {
|
||||||
|
|
||||||
CIpcMessage* m = new CIpcMessage();
|
CIpcMessage* m = new CIpcMessage();
|
||||||
m->m_type = code[1];
|
m->m_type = code[0];
|
||||||
|
|
||||||
LOG((CLOG_DEBUG "ipc server proxy read: %d", code[0]));
|
LOG((CLOG_DEBUG "ipc server proxy read: %d", m->m_type));
|
||||||
switch (code[0]) {
|
switch (m->m_type) {
|
||||||
case kIpcLogLine:
|
case kIpcLogLine:
|
||||||
m->m_data = parseLogLine();
|
m->m_data = parseLogLine();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kIpcShutdown:
|
||||||
|
// no data.
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
delete m;
|
delete m;
|
||||||
disconnect();
|
disconnect();
|
||||||
|
@ -79,6 +85,10 @@ CIpcServerProxy::send(const CIpcMessage& message)
|
||||||
m_stream.write(code, 1);
|
m_stream.write(code, 1);
|
||||||
|
|
||||||
switch (message.m_type) {
|
switch (message.m_type) {
|
||||||
|
case kIpcHello:
|
||||||
|
m_stream.write(message.m_data, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
case kIpcCommand: {
|
case kIpcCommand: {
|
||||||
CString* s = (CString*)message.m_data;
|
CString* s = (CString*)message.m_data;
|
||||||
const char* data = s->c_str();
|
const char* data = s->c_str();
|
||||||
|
@ -87,8 +97,8 @@ CIpcServerProxy::send(const CIpcMessage& message)
|
||||||
CProtocolUtil::writef(&m_stream, "%2i", len);
|
CProtocolUtil::writef(&m_stream, "%2i", len);
|
||||||
|
|
||||||
m_stream.write(data, len);
|
m_stream.write(data, len);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
LOG((CLOG_ERR "message not supported: %d", message.m_type));
|
LOG((CLOG_ERR "message not supported: %d", message.m_type));
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
|
|
||||||
#include "CEvent.h"
|
#include "CEvent.h"
|
||||||
|
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
class CIpcMessage;
|
class CIpcMessage;
|
||||||
|
|
||||||
class CIpcServerProxy {
|
class CIpcServerProxy {
|
||||||
public:
|
public:
|
||||||
CIpcServerProxy(IStream& stream);
|
CIpcServerProxy(synergy::IStream& stream);
|
||||||
virtual ~CIpcServerProxy();
|
virtual ~CIpcServerProxy();
|
||||||
|
|
||||||
void send(const CIpcMessage& message);
|
void send(const CIpcMessage& message);
|
||||||
|
@ -38,7 +38,7 @@ private:
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IStream& m_stream;
|
synergy::IStream& m_stream;
|
||||||
|
|
||||||
static CEvent::Type s_messageReceivedEvent;
|
static CEvent::Type s_messageReceivedEvent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,14 @@
|
||||||
#define IPC_PORT 24801
|
#define IPC_PORT 24801
|
||||||
|
|
||||||
enum EIpcMessage {
|
enum EIpcMessage {
|
||||||
|
kIpcHello,
|
||||||
kIpcLogLine,
|
kIpcLogLine,
|
||||||
kIpcCommand
|
kIpcCommand,
|
||||||
|
kIpcShutdown,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EIpcClientType {
|
||||||
|
kIpcClientUnknown,
|
||||||
|
kIpcClientGui,
|
||||||
|
kIpcClientNode,
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
This interface defines the methods common to all network sockets that
|
This interface defines the methods common to all network sockets that
|
||||||
represent a full-duplex data stream.
|
represent a full-duplex data stream.
|
||||||
*/
|
*/
|
||||||
class IDataSocket : public ISocket, public IStream {
|
class IDataSocket : public ISocket, public synergy::IStream {
|
||||||
public:
|
public:
|
||||||
class CConnectionFailedInfo {
|
class CConnectionFailedInfo {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
#include "CApp.h"
|
#include "CApp.h"
|
||||||
#include "CArgsBase.h"
|
#include "CArgsBase.h"
|
||||||
#include "CIpcLogOutputter.h"
|
#include "CIpcLogOutputter.h"
|
||||||
|
#include "CIpcServer.h"
|
||||||
|
#include "CIpcMessage.h"
|
||||||
|
#include "Ipc.h"
|
||||||
|
|
||||||
#include <Tlhelp32.h>
|
#include <Tlhelp32.h>
|
||||||
#include <UserEnv.h>
|
#include <UserEnv.h>
|
||||||
|
@ -37,14 +40,18 @@ enum {
|
||||||
|
|
||||||
typedef VOID (WINAPI *SendSas)(BOOL asUser);
|
typedef VOID (WINAPI *SendSas)(BOOL asUser);
|
||||||
|
|
||||||
CMSWindowsRelauncher::CMSWindowsRelauncher(bool autoDetectCommand) :
|
CMSWindowsRelauncher::CMSWindowsRelauncher(
|
||||||
|
bool autoDetectCommand,
|
||||||
|
CIpcServer& ipcServer,
|
||||||
|
CIpcLogOutputter& ipcLogOutputter) :
|
||||||
m_thread(NULL),
|
m_thread(NULL),
|
||||||
m_autoDetectCommand(autoDetectCommand),
|
m_autoDetectCommand(autoDetectCommand),
|
||||||
m_running(true),
|
m_running(true),
|
||||||
m_commandChanged(false),
|
m_commandChanged(false),
|
||||||
m_stdOutWrite(NULL),
|
m_stdOutWrite(NULL),
|
||||||
m_stdOutRead(NULL),
|
m_stdOutRead(NULL),
|
||||||
m_ipcLogOutputter(nullptr)
|
m_ipcServer(ipcServer),
|
||||||
|
m_ipcLogOutputter(ipcLogOutputter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +381,7 @@ CMSWindowsRelauncher::command() const
|
||||||
|
|
||||||
// build up a full command line
|
// build up a full command line
|
||||||
std::stringstream cmdTemp;
|
std::stringstream cmdTemp;
|
||||||
cmdTemp << launchName << /*" --debug-data session-" << sessionId <<*/ args;
|
cmdTemp << launchName << args;
|
||||||
|
|
||||||
std::string cmd = cmdTemp.str();
|
std::string cmd = cmdTemp.str();
|
||||||
|
|
||||||
|
@ -390,7 +397,8 @@ CMSWindowsRelauncher::command() const
|
||||||
void
|
void
|
||||||
CMSWindowsRelauncher::outputLoop(void*)
|
CMSWindowsRelauncher::outputLoop(void*)
|
||||||
{
|
{
|
||||||
CHAR buffer[kOutputBufferSize];
|
// +1 char for \0
|
||||||
|
CHAR buffer[kOutputBufferSize + 1];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
@ -405,7 +413,7 @@ CMSWindowsRelauncher::outputLoop(void*)
|
||||||
else {
|
else {
|
||||||
// send process output over IPC to GUI.
|
// send process output over IPC to GUI.
|
||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
m_ipcLogOutputter->write(kINFO, buffer);
|
m_ipcLogOutputter.write(kINFO, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -419,6 +427,10 @@ CMSWindowsRelauncher::shutdownProcess(const PROCESS_INFORMATION& pi, int timeout
|
||||||
if (exitCode != STILL_ACTIVE)
|
if (exitCode != STILL_ACTIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CIpcMessage shutdown;
|
||||||
|
shutdown.m_type = kIpcShutdown;
|
||||||
|
m_ipcServer.send(shutdown, kIpcClientNode);
|
||||||
|
|
||||||
// wait for process to exit gracefully.
|
// wait for process to exit gracefully.
|
||||||
double start = ARCH->time();
|
double start = ARCH->time();
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -430,12 +442,13 @@ CMSWindowsRelauncher::shutdownProcess(const PROCESS_INFORMATION& pi, int timeout
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if ((ARCH->time() - start) > timeout) {
|
double elapsed = (ARCH->time() - start);
|
||||||
|
if (elapsed > timeout) {
|
||||||
// if timeout reached, kill forcefully.
|
// if timeout reached, kill forcefully.
|
||||||
// calling TerminateProcess on synergy is very bad!
|
// calling TerminateProcess on synergy is very bad!
|
||||||
// it causes the hook DLL to stay loaded in some apps,
|
// it causes the hook DLL to stay loaded in some apps,
|
||||||
// making it impossible to start synergy again.
|
// making it impossible to start synergy again.
|
||||||
LOG((CLOG_WARN "shutdown timed out after %d secs, forcefully terminating", pi.dwProcessId));
|
LOG((CLOG_WARN "shutdown timed out after %d secs, forcefully terminating", (int)elapsed));
|
||||||
TerminateProcess(pi.hProcess, kExitSuccess);
|
TerminateProcess(pi.hProcess, kExitSuccess);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,14 @@
|
||||||
|
|
||||||
class CThread;
|
class CThread;
|
||||||
class CIpcLogOutputter;
|
class CIpcLogOutputter;
|
||||||
|
class CIpcServer;
|
||||||
|
|
||||||
class CMSWindowsRelauncher {
|
class CMSWindowsRelauncher {
|
||||||
public:
|
public:
|
||||||
CMSWindowsRelauncher(bool autoDetectCommand);
|
CMSWindowsRelauncher(
|
||||||
|
bool autoDetectCommand,
|
||||||
|
CIpcServer& ipcServer,
|
||||||
|
CIpcLogOutputter& ipcLogOutputter);
|
||||||
virtual ~CMSWindowsRelauncher();
|
virtual ~CMSWindowsRelauncher();
|
||||||
void startAsync();
|
void startAsync();
|
||||||
std::string command() const;
|
std::string command() const;
|
||||||
|
@ -42,9 +46,6 @@ private:
|
||||||
void outputLoop(void*);
|
void outputLoop(void*);
|
||||||
void shutdownProcess(const PROCESS_INFORMATION& pi, int timeout);
|
void shutdownProcess(const PROCESS_INFORMATION& pi, int timeout);
|
||||||
|
|
||||||
public:
|
|
||||||
CIpcLogOutputter* m_ipcLogOutputter;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CThread* m_thread;
|
CThread* m_thread;
|
||||||
bool m_autoDetectCommand;
|
bool m_autoDetectCommand;
|
||||||
|
@ -54,4 +55,6 @@ private:
|
||||||
HANDLE m_stdOutWrite;
|
HANDLE m_stdOutWrite;
|
||||||
HANDLE m_stdOutRead;
|
HANDLE m_stdOutRead;
|
||||||
CThread* m_outputThread;
|
CThread* m_outputThread;
|
||||||
|
CIpcServer& m_ipcServer;
|
||||||
|
CIpcLogOutputter& m_ipcLogOutputter;
|
||||||
};
|
};
|
||||||
|
|
|
@ -138,6 +138,8 @@ set(inc
|
||||||
../mt
|
../mt
|
||||||
../synergy
|
../synergy
|
||||||
../ipc
|
../ipc
|
||||||
|
../net
|
||||||
|
../io
|
||||||
)
|
)
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
|
@ -192,5 +194,5 @@ if (WIN32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
target_link_libraries(platform ipc synergy ${libs})
|
target_link_libraries(platform io net ipc synergy ${libs})
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -66,7 +66,7 @@ CClientListener::CClientListener(const CNetworkAddress& address,
|
||||||
LOG((CLOG_DEBUG1 "listening for clients"));
|
LOG((CLOG_DEBUG1 "listening for clients"));
|
||||||
|
|
||||||
// setup event handler
|
// setup event handler
|
||||||
EVENTQUEUE->adoptHandler(IListenSocket::getConnectingEvent(), m_listen,
|
EVENTQUEUE->adoptHandler(m_listen->getConnectingEvent(), m_listen,
|
||||||
new TMethodEventJob<CClientListener>(this,
|
new TMethodEventJob<CClientListener>(this,
|
||||||
&CClientListener::handleClientConnecting));
|
&CClientListener::handleClientConnecting));
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ CClientListener::~CClientListener()
|
||||||
client = getNextClient();
|
client = getNextClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
EVENTQUEUE->removeHandler(IListenSocket::getConnectingEvent(), m_listen);
|
EVENTQUEUE->removeHandler(m_listen->getConnectingEvent(), m_listen);
|
||||||
delete m_listen;
|
delete m_listen;
|
||||||
delete m_socketFactory;
|
delete m_socketFactory;
|
||||||
delete m_streamFilterFactory;
|
delete m_streamFilterFactory;
|
||||||
|
@ -131,7 +131,7 @@ void
|
||||||
CClientListener::handleClientConnecting(const CEvent&, void*)
|
CClientListener::handleClientConnecting(const CEvent&, void*)
|
||||||
{
|
{
|
||||||
// accept client connection
|
// accept client connection
|
||||||
IStream* stream = m_listen->accept();
|
synergy::IStream* stream = m_listen->accept();
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ CEvent::Type CClientProxy::s_disconnectedEvent = CEvent::kUnknown;
|
||||||
CEvent::Type CClientProxy::s_clipboardChangedEvent= CEvent::kUnknown;
|
CEvent::Type CClientProxy::s_clipboardChangedEvent= CEvent::kUnknown;
|
||||||
CEvent::Type CClientProxy::s_gameDeviceTimingRecvEvent= CEvent::kUnknown;
|
CEvent::Type CClientProxy::s_gameDeviceTimingRecvEvent= CEvent::kUnknown;
|
||||||
|
|
||||||
CClientProxy::CClientProxy(const CString& name, IStream* stream) :
|
CClientProxy::CClientProxy(const CString& name, synergy::IStream* stream) :
|
||||||
CBaseClientProxy(name),
|
CBaseClientProxy(name),
|
||||||
m_stream(stream)
|
m_stream(stream)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,7 @@ CClientProxy::close(const char* msg)
|
||||||
getStream()->flush();
|
getStream()->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
IStream*
|
synergy::IStream*
|
||||||
CClientProxy::getStream() const
|
CClientProxy::getStream() const
|
||||||
{
|
{
|
||||||
return m_stream;
|
return m_stream;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "CEvent.h"
|
#include "CEvent.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
|
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
|
|
||||||
//! Generic proxy for client
|
//! Generic proxy for client
|
||||||
class CClientProxy : public CBaseClientProxy {
|
class CClientProxy : public CBaseClientProxy {
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
\c name is the name of the client.
|
\c name is the name of the client.
|
||||||
*/
|
*/
|
||||||
CClientProxy(const CString& name, IStream* adoptedStream);
|
CClientProxy(const CString& name, synergy::IStream* adoptedStream);
|
||||||
~CClientProxy();
|
~CClientProxy();
|
||||||
|
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
|
@ -50,7 +50,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
Returns the stream passed to the c'tor.
|
Returns the stream passed to the c'tor.
|
||||||
*/
|
*/
|
||||||
IStream* getStream() const;
|
synergy::IStream* getStream() const;
|
||||||
|
|
||||||
//! Get ready event type
|
//! Get ready event type
|
||||||
/*!
|
/*!
|
||||||
|
@ -117,7 +117,7 @@ public:
|
||||||
virtual void gameDeviceTimingReq() = 0;
|
virtual void gameDeviceTimingReq() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IStream* m_stream;
|
synergy::IStream* m_stream;
|
||||||
|
|
||||||
static CEvent::Type s_readyEvent;
|
static CEvent::Type s_readyEvent;
|
||||||
static CEvent::Type s_disconnectedEvent;
|
static CEvent::Type s_disconnectedEvent;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
// CClientProxy1_0
|
// CClientProxy1_0
|
||||||
//
|
//
|
||||||
|
|
||||||
CClientProxy1_0::CClientProxy1_0(const CString& name, IStream* stream) :
|
CClientProxy1_0::CClientProxy1_0(const CString& name, synergy::IStream* stream) :
|
||||||
CClientProxy(name, stream),
|
CClientProxy(name, stream),
|
||||||
m_heartbeatTimer(NULL),
|
m_heartbeatTimer(NULL),
|
||||||
m_parser(&CClientProxy1_0::parseHandshakeMessage)
|
m_parser(&CClientProxy1_0::parseHandshakeMessage)
|
||||||
|
|
|
@ -28,7 +28,7 @@ class CEventQueueTimer;
|
||||||
//! Proxy for client implementing protocol version 1.0
|
//! Proxy for client implementing protocol version 1.0
|
||||||
class CClientProxy1_0 : public CClientProxy {
|
class CClientProxy1_0 : public CClientProxy {
|
||||||
public:
|
public:
|
||||||
CClientProxy1_0(const CString& name, IStream* adoptedStream);
|
CClientProxy1_0(const CString& name, synergy::IStream* adoptedStream);
|
||||||
~CClientProxy1_0();
|
~CClientProxy1_0();
|
||||||
|
|
||||||
// IScreen
|
// IScreen
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
// CClientProxy1_1
|
// CClientProxy1_1
|
||||||
//
|
//
|
||||||
|
|
||||||
CClientProxy1_1::CClientProxy1_1(const CString& name, IStream* stream) :
|
CClientProxy1_1::CClientProxy1_1(const CString& name, synergy::IStream* stream) :
|
||||||
CClientProxy1_0(name, stream)
|
CClientProxy1_0(name, stream)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//! Proxy for client implementing protocol version 1.1
|
//! Proxy for client implementing protocol version 1.1
|
||||||
class CClientProxy1_1 : public CClientProxy1_0 {
|
class CClientProxy1_1 : public CClientProxy1_0 {
|
||||||
public:
|
public:
|
||||||
CClientProxy1_1(const CString& name, IStream* adoptedStream);
|
CClientProxy1_1(const CString& name, synergy::IStream* adoptedStream);
|
||||||
~CClientProxy1_1();
|
~CClientProxy1_1();
|
||||||
|
|
||||||
// IClient overrides
|
// IClient overrides
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
// CClientProxy1_1
|
// CClientProxy1_1
|
||||||
//
|
//
|
||||||
|
|
||||||
CClientProxy1_2::CClientProxy1_2(const CString& name, IStream* stream) :
|
CClientProxy1_2::CClientProxy1_2(const CString& name, synergy::IStream* stream) :
|
||||||
CClientProxy1_1(name, stream)
|
CClientProxy1_1(name, stream)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//! Proxy for client implementing protocol version 1.2
|
//! Proxy for client implementing protocol version 1.2
|
||||||
class CClientProxy1_2 : public CClientProxy1_1 {
|
class CClientProxy1_2 : public CClientProxy1_1 {
|
||||||
public:
|
public:
|
||||||
CClientProxy1_2(const CString& name, IStream* adoptedStream);
|
CClientProxy1_2(const CString& name, synergy::IStream* adoptedStream);
|
||||||
~CClientProxy1_2();
|
~CClientProxy1_2();
|
||||||
|
|
||||||
// IClient overrides
|
// IClient overrides
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
// CClientProxy1_3
|
// CClientProxy1_3
|
||||||
//
|
//
|
||||||
|
|
||||||
CClientProxy1_3::CClientProxy1_3(const CString& name, IStream* stream) :
|
CClientProxy1_3::CClientProxy1_3(const CString& name, synergy::IStream* stream) :
|
||||||
CClientProxy1_2(name, stream),
|
CClientProxy1_2(name, stream),
|
||||||
m_keepAliveRate(kKeepAliveRate),
|
m_keepAliveRate(kKeepAliveRate),
|
||||||
m_keepAliveTimer(NULL)
|
m_keepAliveTimer(NULL)
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
//! Proxy for client implementing protocol version 1.3
|
//! Proxy for client implementing protocol version 1.3
|
||||||
class CClientProxy1_3 : public CClientProxy1_2 {
|
class CClientProxy1_3 : public CClientProxy1_2 {
|
||||||
public:
|
public:
|
||||||
CClientProxy1_3(const CString& name, IStream* adoptedStream);
|
CClientProxy1_3(const CString& name, synergy::IStream* adoptedStream);
|
||||||
~CClientProxy1_3();
|
~CClientProxy1_3();
|
||||||
|
|
||||||
// IClient overrides
|
// IClient overrides
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
// CClientProxy1_4
|
// CClientProxy1_4
|
||||||
//
|
//
|
||||||
|
|
||||||
CClientProxy1_4::CClientProxy1_4(const CString& name, IStream* stream, CServer* server) :
|
CClientProxy1_4::CClientProxy1_4(const CString& name, synergy::IStream* stream, CServer* server) :
|
||||||
CClientProxy1_3(name, stream), m_server(server)
|
CClientProxy1_3(name, stream), m_server(server)
|
||||||
{
|
{
|
||||||
assert(m_server != NULL);
|
assert(m_server != NULL);
|
||||||
|
|
|
@ -25,7 +25,7 @@ class CServer;
|
||||||
//! Proxy for client implementing protocol version 1.4
|
//! Proxy for client implementing protocol version 1.4
|
||||||
class CClientProxy1_4 : public CClientProxy1_3 {
|
class CClientProxy1_4 : public CClientProxy1_3 {
|
||||||
public:
|
public:
|
||||||
CClientProxy1_4(const CString& name, IStream* adoptedStream, CServer* server);
|
CClientProxy1_4(const CString& name, synergy::IStream* adoptedStream, CServer* server);
|
||||||
~CClientProxy1_4();
|
~CClientProxy1_4();
|
||||||
|
|
||||||
// IClient overrides
|
// IClient overrides
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
CEvent::Type CClientProxyUnknown::s_successEvent = CEvent::kUnknown;
|
CEvent::Type CClientProxyUnknown::s_successEvent = CEvent::kUnknown;
|
||||||
CEvent::Type CClientProxyUnknown::s_failureEvent = CEvent::kUnknown;
|
CEvent::Type CClientProxyUnknown::s_failureEvent = CEvent::kUnknown;
|
||||||
|
|
||||||
CClientProxyUnknown::CClientProxyUnknown(IStream* stream, double timeout, CServer* server) :
|
CClientProxyUnknown::CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server) :
|
||||||
m_stream(stream),
|
m_stream(stream),
|
||||||
m_proxy(NULL),
|
m_proxy(NULL),
|
||||||
m_ready(false),
|
m_ready(false),
|
||||||
|
|
|
@ -22,12 +22,12 @@
|
||||||
|
|
||||||
class CClientProxy;
|
class CClientProxy;
|
||||||
class CEventQueueTimer;
|
class CEventQueueTimer;
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
class CServer;
|
class CServer;
|
||||||
|
|
||||||
class CClientProxyUnknown {
|
class CClientProxyUnknown {
|
||||||
public:
|
public:
|
||||||
CClientProxyUnknown(IStream* stream, double timeout, CServer* server);
|
CClientProxyUnknown(synergy::IStream* stream, double timeout, CServer* server);
|
||||||
~CClientProxyUnknown();
|
~CClientProxyUnknown();
|
||||||
|
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
|
@ -75,7 +75,7 @@ private:
|
||||||
void handleReady(const CEvent&, void*);
|
void handleReady(const CEvent&, void*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IStream* m_stream;
|
synergy::IStream* m_stream;
|
||||||
CEventQueueTimer* m_timer;
|
CEventQueueTimer* m_timer;
|
||||||
CClientProxy* m_proxy;
|
CClientProxy* m_proxy;
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
|
|
|
@ -25,6 +25,10 @@
|
||||||
#include "LogOutputters.h"
|
#include "LogOutputters.h"
|
||||||
#include "XSynergy.h"
|
#include "XSynergy.h"
|
||||||
#include "CArgsBase.h"
|
#include "CArgsBase.h"
|
||||||
|
#include "CIpcServerProxy.h"
|
||||||
|
#include "TMethodEventJob.h"
|
||||||
|
#include "CIpcMessage.h"
|
||||||
|
#include "Ipc.h"
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
#include "CArchMiscWindows.h"
|
#include "CArchMiscWindows.h"
|
||||||
|
@ -46,7 +50,8 @@ m_createTaskBarReceiver(createTaskBarReceiver),
|
||||||
m_args(args),
|
m_args(args),
|
||||||
m_bye(&exit),
|
m_bye(&exit),
|
||||||
m_taskBarReceiver(NULL),
|
m_taskBarReceiver(NULL),
|
||||||
m_suspended(false)
|
m_suspended(false),
|
||||||
|
m_ipcClient(nullptr)
|
||||||
{
|
{
|
||||||
assert(s_instance == nullptr);
|
assert(s_instance == nullptr);
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
@ -142,6 +147,10 @@ CApp::parseArg(const int& argc, const char* const* argv, int& i)
|
||||||
argsBase().m_disableTray = true;
|
argsBase().m_disableTray = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (isArg(i, argc, argv, NULL, "--ipc")) {
|
||||||
|
argsBase().m_enableIpc = true;
|
||||||
|
}
|
||||||
|
|
||||||
#if VNC_SUPPORT
|
#if VNC_SUPPORT
|
||||||
else if (isArg(i, argc, argv, NULL, "--vnc")) {
|
else if (isArg(i, argc, argv, NULL, "--vnc")) {
|
||||||
argsBase().m_enableVnc = true;
|
argsBase().m_enableVnc = true;
|
||||||
|
@ -335,3 +344,33 @@ CApp::initApp(int argc, const char** argv)
|
||||||
m_taskBarReceiver = m_createTaskBarReceiver(logBuffer);
|
m_taskBarReceiver = m_createTaskBarReceiver(logBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CApp::initIpcClient()
|
||||||
|
{
|
||||||
|
// TODO: delete ipc client on shutdown and the 2 event handlers.
|
||||||
|
m_ipcClient = new CIpcClient();
|
||||||
|
m_ipcClient->connect();
|
||||||
|
|
||||||
|
EVENTQUEUE->adoptHandler(
|
||||||
|
CIpcClient::getConnectedEvent(), m_ipcClient,
|
||||||
|
new TMethodEventJob<CApp>(this, &CApp::handleIpcConnected));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CApp::handleIpcConnected(const CEvent& e, void*)
|
||||||
|
{
|
||||||
|
EVENTQUEUE->adoptHandler(
|
||||||
|
CIpcServerProxy::getMessageReceivedEvent(), e.getData(),
|
||||||
|
new TMethodEventJob<CApp>(this, &CApp::handleIpcMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CApp::handleIpcMessage(const CEvent& e, void*)
|
||||||
|
{
|
||||||
|
CIpcMessage* m = static_cast<CIpcMessage*>(e.getData());
|
||||||
|
if (m->m_type == kIpcShutdown) {
|
||||||
|
LOG((CLOG_INFO "got ipc shutdown message"));
|
||||||
|
EVENTQUEUE->addEvent(CEvent(CEvent::kQuit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "CString.h"
|
#include "CString.h"
|
||||||
#include "IApp.h"
|
#include "IApp.h"
|
||||||
|
#include "CIpcClient.h"
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
#include "CAppUtilWindows.h"
|
#include "CAppUtilWindows.h"
|
||||||
|
@ -92,9 +93,14 @@ public:
|
||||||
virtual void setByeFunc(void(*bye)(int)) { m_bye = bye; }
|
virtual void setByeFunc(void(*bye)(int)) { m_bye = bye; }
|
||||||
virtual void bye(int error) { m_bye(error); }
|
virtual void bye(int error) { m_bye(error); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void handleIpcConnected(const CEvent&, void*);
|
||||||
|
void handleIpcMessage(const CEvent&, void*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
virtual void parseArgs(int argc, const char* const* argv, int &i);
|
||||||
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||||
|
void initIpcClient();
|
||||||
|
|
||||||
IArchTaskBarReceiver* m_taskBarReceiver;
|
IArchTaskBarReceiver* m_taskBarReceiver;
|
||||||
bool m_suspended;
|
bool m_suspended;
|
||||||
|
@ -105,6 +111,7 @@ private:
|
||||||
CFileLogOutputter* m_fileLog;
|
CFileLogOutputter* m_fileLog;
|
||||||
CreateTaskBarReceiverFunc m_createTaskBarReceiver;
|
CreateTaskBarReceiverFunc m_createTaskBarReceiver;
|
||||||
ARCH_APP_UTIL m_appUtil;
|
ARCH_APP_UTIL m_appUtil;
|
||||||
|
CIpcClient* m_ipcClient;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BYE "\nTry `%s --help' for more information."
|
#define BYE "\nTry `%s --help' for more information."
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "CMSWindowsScreen.h"
|
#include "CMSWindowsScreen.h"
|
||||||
#include "XSynergy.h"
|
#include "XSynergy.h"
|
||||||
#include "IArchTaskBarReceiver.h"
|
#include "IArchTaskBarReceiver.h"
|
||||||
#include "CMSWindowsRelauncher.h"
|
|
||||||
#include "CScreen.h"
|
#include "CScreen.h"
|
||||||
#include "CArgsBase.h"
|
#include "CArgsBase.h"
|
||||||
#include "IEventQueue.h"
|
#include "IEventQueue.h"
|
||||||
|
@ -214,17 +213,5 @@ CAppUtilWindows::debugServiceWait()
|
||||||
void
|
void
|
||||||
CAppUtilWindows::startNode()
|
CAppUtilWindows::startNode()
|
||||||
{
|
{
|
||||||
if (app().argsBase().m_relaunchMode) {
|
|
||||||
|
|
||||||
LOG((CLOG_DEBUG1 "entering relaunch mode"));
|
|
||||||
CMSWindowsRelauncher relauncher(true);
|
|
||||||
relauncher.startAsync();
|
|
||||||
|
|
||||||
// HACK: create a dummy screen, which can handle system events
|
|
||||||
// (such as a stop request from the service controller).
|
|
||||||
CScreen* dummyScreen = app().createScreen();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
app().startNode();
|
app().startNode();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ CArgsBase::CArgsBase() :
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
m_daemon(false), // daemon mode not supported on windows (use --service)
|
m_daemon(false), // daemon mode not supported on windows (use --service)
|
||||||
m_debugServiceWait(false),
|
m_debugServiceWait(false),
|
||||||
m_relaunchMode(false),
|
|
||||||
m_pauseOnExit(false),
|
m_pauseOnExit(false),
|
||||||
#else
|
#else
|
||||||
m_daemon(true), // backward compatibility for unix (daemon by default)
|
m_daemon(true), // backward compatibility for unix (daemon by default)
|
||||||
|
|
|
@ -35,8 +35,8 @@ public:
|
||||||
CString m_name;
|
CString m_name;
|
||||||
bool m_disableTray;
|
bool m_disableTray;
|
||||||
bool m_enableVnc;
|
bool m_enableVnc;
|
||||||
|
bool m_enableIpc;
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
bool m_relaunchMode;
|
|
||||||
bool m_debugServiceWait;
|
bool m_debugServiceWait;
|
||||||
bool m_pauseOnExit;
|
bool m_pauseOnExit;
|
||||||
CGameDeviceInfo m_gameDevice;
|
CGameDeviceInfo m_gameDevice;
|
||||||
|
|
|
@ -529,6 +529,10 @@ CClientApp::mainLoop()
|
||||||
// create the event queue
|
// create the event queue
|
||||||
CEventQueue eventQueue;
|
CEventQueue eventQueue;
|
||||||
|
|
||||||
|
if (argsBase().m_enableIpc) {
|
||||||
|
initIpcClient();
|
||||||
|
}
|
||||||
|
|
||||||
// start client, etc
|
// start client, etc
|
||||||
appUtil().startNode();
|
appUtil().startNode();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ CDaemonApp::CDaemonApp() :
|
||||||
m_ipcServer(nullptr),
|
m_ipcServer(nullptr),
|
||||||
m_ipcLogOutputter(nullptr)
|
m_ipcLogOutputter(nullptr)
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
,m_relauncher(false)
|
,m_relauncher(nullptr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
@ -182,16 +182,20 @@ CDaemonApp::mainLoop(bool logToFile)
|
||||||
// uses event queue, must be created here.
|
// uses event queue, must be created here.
|
||||||
m_ipcServer = new CIpcServer();
|
m_ipcServer = new CIpcServer();
|
||||||
|
|
||||||
|
// send logging to gui via ipc, log system adopts outputter.
|
||||||
|
m_ipcLogOutputter = new CIpcLogOutputter(*m_ipcServer);
|
||||||
|
CLOG->insert(m_ipcLogOutputter);
|
||||||
|
|
||||||
|
#if SYSAPI_WIN32
|
||||||
|
m_relauncher = new CMSWindowsRelauncher(false, *m_ipcServer, *m_ipcLogOutputter);
|
||||||
|
#endif
|
||||||
|
|
||||||
eventQueue.adoptHandler(
|
eventQueue.adoptHandler(
|
||||||
CIpcServer::getClientConnectedEvent(), m_ipcServer,
|
CIpcServer::getClientConnectedEvent(), m_ipcServer,
|
||||||
new TMethodEventJob<CDaemonApp>(this, &CDaemonApp::handleIpcConnected));
|
new TMethodEventJob<CDaemonApp>(this, &CDaemonApp::handleIpcConnected));
|
||||||
|
|
||||||
m_ipcServer->listen();
|
m_ipcServer->listen();
|
||||||
|
|
||||||
// send logging to gui via ipc, log system adopts outputter.
|
|
||||||
m_ipcLogOutputter = new CIpcLogOutputter(*m_ipcServer);
|
|
||||||
CLOG->insert(m_ipcLogOutputter);
|
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
// HACK: create a dummy screen, which can handle system events
|
// HACK: create a dummy screen, which can handle system events
|
||||||
// (such as a stop request from the service controller).
|
// (such as a stop request from the service controller).
|
||||||
|
@ -199,21 +203,19 @@ CDaemonApp::mainLoop(bool logToFile)
|
||||||
CGameDeviceInfo gameDevice;
|
CGameDeviceInfo gameDevice;
|
||||||
CScreen dummyScreen(new CMSWindowsScreen(false, true, gameDevice));
|
CScreen dummyScreen(new CMSWindowsScreen(false, true, gameDevice));
|
||||||
|
|
||||||
m_relauncher.m_ipcLogOutputter = m_ipcLogOutputter;
|
|
||||||
|
|
||||||
string command = ARCH->setting("Command");
|
string command = ARCH->setting("Command");
|
||||||
if (command != "") {
|
if (command != "") {
|
||||||
LOG((CLOG_INFO "using last known command: %s", command.c_str()));
|
LOG((CLOG_INFO "using last known command: %s", command.c_str()));
|
||||||
m_relauncher.command(command);
|
m_relauncher->command(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_relauncher.startAsync();
|
m_relauncher->startAsync();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eventQueue.loop();
|
eventQueue.loop();
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
m_relauncher.stop();
|
m_relauncher->stop();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eventQueue.removeHandler(
|
eventQueue.removeHandler(
|
||||||
|
@ -275,13 +277,12 @@ CDaemonApp::handleIpcConnected(const CEvent& e, void*)
|
||||||
void
|
void
|
||||||
CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
||||||
{
|
{
|
||||||
CIpcMessage& m = *reinterpret_cast<CIpcMessage*>(e.getData());
|
CIpcMessage& m = *static_cast<CIpcMessage*>(e.getData());
|
||||||
|
|
||||||
LOG((CLOG_DEBUG "ipc message, type=%d", m.m_type));
|
LOG((CLOG_DEBUG "ipc message, type=%d", m.m_type));
|
||||||
|
|
||||||
switch (m.m_type) {
|
switch (m.m_type) {
|
||||||
case kIpcCommand: {
|
case kIpcCommand: {
|
||||||
CString& command = *reinterpret_cast<CString*>(m.m_data);
|
CString& command = *static_cast<CString*>(m.m_data);
|
||||||
LOG((CLOG_DEBUG "got new command: %s", command.c_str()));
|
LOG((CLOG_DEBUG "got new command: %s", command.c_str()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -296,7 +297,7 @@ CDaemonApp::handleIpcMessage(const CEvent& e, void*)
|
||||||
// tell the relauncher about the new command. this causes the
|
// tell the relauncher about the new command. this causes the
|
||||||
// relauncher to stop the existing command and start the new
|
// relauncher to stop the existing command and start the new
|
||||||
// command.
|
// command.
|
||||||
m_relauncher.command(command);
|
m_relauncher->command(command);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ public:
|
||||||
static CDaemonApp* s_instance;
|
static CDaemonApp* s_instance;
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
CMSWindowsRelauncher m_relauncher;
|
CMSWindowsRelauncher*
|
||||||
|
m_relauncher;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -57,7 +58,3 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LOG_FILENAME "synergyd.log"
|
#define LOG_FILENAME "synergyd.log"
|
||||||
|
|
||||||
enum {
|
|
||||||
kIpcCommand = 1
|
|
||||||
};
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
// CPacketStreamFilter
|
// CPacketStreamFilter
|
||||||
//
|
//
|
||||||
|
|
||||||
CPacketStreamFilter::CPacketStreamFilter(IStream* stream, bool adoptStream) :
|
CPacketStreamFilter::CPacketStreamFilter(synergy::IStream* stream, bool adoptStream) :
|
||||||
CStreamFilter(stream, adoptStream),
|
CStreamFilter(stream, adoptStream),
|
||||||
m_size(0),
|
m_size(0),
|
||||||
m_inputShutdown(false)
|
m_inputShutdown(false)
|
||||||
|
|
|
@ -28,7 +28,7 @@ Filters a stream to read and write packets.
|
||||||
*/
|
*/
|
||||||
class CPacketStreamFilter : public CStreamFilter {
|
class CPacketStreamFilter : public CStreamFilter {
|
||||||
public:
|
public:
|
||||||
CPacketStreamFilter(IStream* stream, bool adoptStream = true);
|
CPacketStreamFilter(synergy::IStream* stream, bool adoptStream = true);
|
||||||
~CPacketStreamFilter();
|
~CPacketStreamFilter();
|
||||||
|
|
||||||
// IStream overrides
|
// IStream overrides
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void
|
||||||
CProtocolUtil::writef(IStream* stream, const char* fmt, ...)
|
CProtocolUtil::writef(synergy::IStream* stream, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
@ -43,7 +43,7 @@ CProtocolUtil::writef(IStream* stream, const char* fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CProtocolUtil::readf(IStream* stream, const char* fmt, ...)
|
CProtocolUtil::readf(synergy::IStream* stream, const char* fmt, ...)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
@ -64,7 +64,7 @@ CProtocolUtil::readf(IStream* stream, const char* fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CProtocolUtil::vwritef(IStream* stream,
|
CProtocolUtil::vwritef(synergy::IStream* stream,
|
||||||
const char* fmt, UInt32 size, va_list args)
|
const char* fmt, UInt32 size, va_list args)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
|
@ -93,7 +93,7 @@ CProtocolUtil::vwritef(IStream* stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CProtocolUtil::vreadf(IStream* stream, const char* fmt, va_list args)
|
CProtocolUtil::vreadf(synergy::IStream* stream, const char* fmt, va_list args)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
@ -507,7 +507,7 @@ CProtocolUtil::eatLength(const char** pfmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CProtocolUtil::read(IStream* stream, void* vbuffer, UInt32 count)
|
CProtocolUtil::read(synergy::IStream* stream, void* vbuffer, UInt32 count)
|
||||||
{
|
{
|
||||||
assert(stream != NULL);
|
assert(stream != NULL);
|
||||||
assert(vbuffer != NULL);
|
assert(vbuffer != NULL);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "XIO.h"
|
#include "XIO.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
class IStream;
|
namespace synergy { class IStream; }
|
||||||
|
|
||||||
//! Synergy protocol utilities
|
//! Synergy protocol utilities
|
||||||
/*!
|
/*!
|
||||||
|
@ -49,7 +49,7 @@ public:
|
||||||
- \%s -- converts CString* to stream of bytes
|
- \%s -- converts CString* to stream of bytes
|
||||||
- \%S -- converts integer N and const UInt8* to stream of N bytes
|
- \%S -- converts integer N and const UInt8* to stream of N bytes
|
||||||
*/
|
*/
|
||||||
static void writef(IStream*,
|
static void writef(synergy::IStream*,
|
||||||
const char* fmt, ...);
|
const char* fmt, ...);
|
||||||
|
|
||||||
//! Read formatted data
|
//! Read formatted data
|
||||||
|
@ -68,19 +68,19 @@ public:
|
||||||
- \%4I -- reads NBO 4 byte integers; arg is std::vector<UInt32>*
|
- \%4I -- reads NBO 4 byte integers; arg is std::vector<UInt32>*
|
||||||
- \%s -- reads bytes; argument must be a CString*, \b not a char*
|
- \%s -- reads bytes; argument must be a CString*, \b not a char*
|
||||||
*/
|
*/
|
||||||
static bool readf(IStream*,
|
static bool readf(synergy::IStream*,
|
||||||
const char* fmt, ...);
|
const char* fmt, ...);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void vwritef(IStream*,
|
static void vwritef(synergy::IStream*,
|
||||||
const char* fmt, UInt32 size, va_list);
|
const char* fmt, UInt32 size, va_list);
|
||||||
static void vreadf(IStream*,
|
static void vreadf(synergy::IStream*,
|
||||||
const char* fmt, va_list);
|
const char* fmt, va_list);
|
||||||
|
|
||||||
static UInt32 getLength(const char* fmt, va_list);
|
static UInt32 getLength(const char* fmt, va_list);
|
||||||
static void writef(void*, const char* fmt, va_list);
|
static void writef(void*, const char* fmt, va_list);
|
||||||
static UInt32 eatLength(const char** fmt);
|
static UInt32 eatLength(const char** fmt);
|
||||||
static void read(IStream*, void*, UInt32);
|
static void read(synergy::IStream*, void*, UInt32);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Mismatched read exception
|
//! Mismatched read exception
|
||||||
|
|
|
@ -760,6 +760,15 @@ CServerApp::mainLoop()
|
||||||
|
|
||||||
// create the event queue
|
// create the event queue
|
||||||
CEventQueue eventQueue;
|
CEventQueue eventQueue;
|
||||||
|
/*
|
||||||
|
bool a = true;
|
||||||
|
while (a) {
|
||||||
|
ARCH->sleep(1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (argsBase().m_enableIpc) {
|
||||||
|
initIpcClient();
|
||||||
|
}
|
||||||
|
|
||||||
// if configuration has no screens then add this system
|
// if configuration has no screens then add this system
|
||||||
// as the default
|
// as the default
|
||||||
|
|
|
@ -59,8 +59,8 @@ public:
|
||||||
bool m_connectToServer_clientConnected;
|
bool m_connectToServer_clientConnected;
|
||||||
CString m_sendMessageToServer_receivedString;
|
CString m_sendMessageToServer_receivedString;
|
||||||
CString m_sendMessageToClient_receivedString;
|
CString m_sendMessageToClient_receivedString;
|
||||||
|
CIpcClient* m_sendMessageToServer_client;
|
||||||
CIpcServer* m_sendMessageToClient_server;
|
CIpcServer* m_sendMessageToClient_server;
|
||||||
CIpcServerProxy* m_sendMessageToClient_serverProxy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CIpcTests, connectToServer)
|
TEST_F(CIpcTests, connectToServer)
|
||||||
|
@ -89,17 +89,14 @@ TEST_F(CIpcTests, sendMessageToServer)
|
||||||
|
|
||||||
CIpcClient client;
|
CIpcClient client;
|
||||||
client.connect();
|
client.connect();
|
||||||
|
m_sendMessageToServer_client = &client;
|
||||||
|
|
||||||
|
// event handler sends "test" log line to client.
|
||||||
m_events.adoptHandler(
|
m_events.adoptHandler(
|
||||||
CIpcServer::getClientConnectedEvent(), &server,
|
CIpcServer::getClientConnectedEvent(), &server,
|
||||||
new TMethodEventJob<CIpcTests>(
|
new TMethodEventJob<CIpcTests>(
|
||||||
this, &CIpcTests::sendMessageToServer_handleClientConnected));
|
this, &CIpcTests::sendMessageToServer_handleClientConnected));
|
||||||
|
|
||||||
CIpcMessage m;
|
|
||||||
m.m_type = kIpcCommand;
|
|
||||||
m.m_data = (void*)(new CString("test"));
|
|
||||||
client.send(m);
|
|
||||||
|
|
||||||
quitTimeout(2);
|
quitTimeout(2);
|
||||||
m_events.loop();
|
m_events.loop();
|
||||||
|
|
||||||
|
@ -114,11 +111,10 @@ TEST_F(CIpcTests, sendMessageToClient)
|
||||||
|
|
||||||
CIpcClient client;
|
CIpcClient client;
|
||||||
client.connect();
|
client.connect();
|
||||||
m_sendMessageToClient_serverProxy = client.m_server;
|
|
||||||
|
|
||||||
// event handler sends "test" log line to client.
|
// event handler sends "test" log line to server.
|
||||||
m_events.adoptHandler(
|
m_events.adoptHandler(
|
||||||
CIpcServer::getClientConnectedEvent(), &server,
|
CIpcClient::getConnectedEvent(), &client,
|
||||||
new TMethodEventJob<CIpcTests>(
|
new TMethodEventJob<CIpcTests>(
|
||||||
this, &CIpcTests::sendMessageToClient_handleConnected));
|
this, &CIpcTests::sendMessageToClient_handleConnected));
|
||||||
|
|
||||||
|
@ -131,7 +127,7 @@ TEST_F(CIpcTests, sendMessageToClient)
|
||||||
CIpcTests::CIpcTests() :
|
CIpcTests::CIpcTests() :
|
||||||
m_connectToServer_clientConnected(false),
|
m_connectToServer_clientConnected(false),
|
||||||
m_sendMessageToClient_server(nullptr),
|
m_sendMessageToClient_server(nullptr),
|
||||||
m_sendMessageToClient_serverProxy(nullptr)
|
m_sendMessageToServer_client(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,36 +149,45 @@ CIpcTests::sendMessageToServer_handleClientConnected(const CEvent& e, void*)
|
||||||
CIpcClientProxy::getMessageReceivedEvent(), e.getData(),
|
CIpcClientProxy::getMessageReceivedEvent(), e.getData(),
|
||||||
new TMethodEventJob<CIpcTests>(
|
new TMethodEventJob<CIpcTests>(
|
||||||
this, &CIpcTests::sendMessageToServer_handleMessageReceived));
|
this, &CIpcTests::sendMessageToServer_handleMessageReceived));
|
||||||
|
|
||||||
|
CIpcMessage m;
|
||||||
|
m.m_type = kIpcCommand;
|
||||||
|
m.m_data = new CString("test");
|
||||||
|
m_sendMessageToServer_client->send(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CIpcTests::sendMessageToServer_handleMessageReceived(const CEvent& e, void*)
|
CIpcTests::sendMessageToServer_handleMessageReceived(const CEvent& e, void*)
|
||||||
{
|
{
|
||||||
CIpcMessage* m = (CIpcMessage*)e.getData();
|
CIpcMessage* m = static_cast<CIpcMessage*>(e.getData());
|
||||||
m_sendMessageToServer_receivedString = *((CString*)m->m_data);
|
if (m->m_type == kIpcCommand) {
|
||||||
|
m_sendMessageToServer_receivedString = *static_cast<CString*>(m->m_data);
|
||||||
raiseQuitEvent();
|
raiseQuitEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CIpcTests::sendMessageToClient_handleConnected(const CEvent& e, void*)
|
CIpcTests::sendMessageToClient_handleConnected(const CEvent& e, void*)
|
||||||
{
|
{
|
||||||
m_events.adoptHandler(
|
m_events.adoptHandler(
|
||||||
CIpcServerProxy::getMessageReceivedEvent(), m_sendMessageToClient_serverProxy,
|
CIpcServerProxy::getMessageReceivedEvent(), e.getData(),
|
||||||
new TMethodEventJob<CIpcTests>(
|
new TMethodEventJob<CIpcTests>(
|
||||||
this, &CIpcTests::sendMessageToClient_handleMessageReceived));
|
this, &CIpcTests::sendMessageToClient_handleMessageReceived));
|
||||||
|
|
||||||
CIpcMessage m;
|
CIpcMessage m;
|
||||||
m.m_type = kIpcLogLine;
|
m.m_type = kIpcLogLine;
|
||||||
m.m_data = (void*)(new CString("test"));
|
m.m_data = new CString("test");
|
||||||
m_sendMessageToClient_server->send(m);
|
m_sendMessageToClient_server->send(m, kIpcClientUnknown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CIpcTests::sendMessageToClient_handleMessageReceived(const CEvent& e, void*)
|
CIpcTests::sendMessageToClient_handleMessageReceived(const CEvent& e, void*)
|
||||||
{
|
{
|
||||||
CIpcMessage* m = reinterpret_cast<CIpcMessage*>(e.getData());
|
CIpcMessage* m = static_cast<CIpcMessage*>(e.getData());
|
||||||
m_sendMessageToClient_receivedString = *((CString*)m->m_data);
|
if (m->m_type == kIpcLogLine) {
|
||||||
|
m_sendMessageToClient_receivedString = *static_cast<CString*>(m->m_data);
|
||||||
raiseQuitEvent();
|
raiseQuitEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
class IEventQueue;
|
class IEventQueue;
|
||||||
|
|
||||||
class CMockStream : public IStream
|
class CMockStream : public synergy::IStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CMockStream(IEventQueue& eventQueue) : IStream(eventQueue) { }
|
CMockStream(IEventQueue& eventQueue) : IStream(eventQueue) { }
|
||||||
|
|
Loading…
Reference in New Issue