fixed: ipc client running on synergyc wasn't sending hello message, and so wasn't getting shutdown message. edits to CIpcClient or CIpcTests weren't really needed, but looks slightly better this way maybe.

This commit is contained in:
Nick Bolton 2012-07-10 11:23:08 +00:00
parent 5be1fd0cfa
commit f9f04034c9
3 changed files with 28 additions and 17 deletions

View File

@ -29,23 +29,21 @@ 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.getEventTarget(),
new TMethodEventJob<CIpcClient>(
this, &CIpcClient::handleConnected));
} }
CIpcClient::~CIpcClient() CIpcClient::~CIpcClient()
{ {
EVENTQUEUE->removeHandler(m_socket.getConnectedEvent(), m_socket.getEventTarget()); disconnect();
EVENTQUEUE->removeHandler(CIpcServerProxy::getMessageReceivedEvent(), m_server);
delete m_server;
} }
void void
CIpcClient::connect() CIpcClient::connect()
{ {
EVENTQUEUE->adoptHandler(
IDataSocket::getConnectedEvent(), m_socket.getEventTarget(),
new TMethodEventJob<CIpcClient>(
this, &CIpcClient::handleConnected));
m_socket.connect(m_serverAddress); m_socket.connect(m_serverAddress);
m_server = new CIpcServerProxy(m_socket); m_server = new CIpcServerProxy(m_socket);
@ -58,6 +56,9 @@ CIpcClient::connect()
void void
CIpcClient::disconnect() CIpcClient::disconnect()
{ {
EVENTQUEUE->removeHandler(IDataSocket::getConnectedEvent(), m_socket.getEventTarget());
EVENTQUEUE->removeHandler(CIpcServerProxy::getMessageReceivedEvent(), m_server);
m_server->disconnect(); m_server->disconnect();
delete m_server; delete m_server;
m_server = nullptr; m_server = nullptr;

View File

@ -529,13 +529,15 @@ CClientApp::mainLoop()
// create the event queue // create the event queue
CEventQueue eventQueue; CEventQueue eventQueue;
// start client, etc
appUtil().startNode();
// init ipc client after node start, since create a new screen wipes out
// the event queue (the screen ctors call adoptBuffer).
if (argsBase().m_enableIpc) { if (argsBase().m_enableIpc) {
initIpcClient(); initIpcClient();
} }
// start client, etc
appUtil().startNode();
// load all available plugins. // load all available plugins.
ARCH->plugin().init(s_clientScreen->getEventTarget()); ARCH->plugin().init(s_clientScreen->getEventTarget());

View File

@ -59,7 +59,9 @@ public:
CSocketMultiplexer m_multiplexer; CSocketMultiplexer m_multiplexer;
CEventQueue m_events; CEventQueue m_events;
CEventQueueTimer* m_quitTimeoutTimer; CEventQueueTimer* m_quitTimeoutTimer;
bool m_connectToServer_clientConnected; bool m_connectToServer_helloMessageReceived;
bool m_connectToServer_hasClientNode;
CIpcServer* m_connectToServer_server;
CString m_sendMessageToServer_receivedString; CString m_sendMessageToServer_receivedString;
CString m_sendMessageToClient_receivedString; CString m_sendMessageToClient_receivedString;
CIpcClient* m_sendMessageToServer_client; CIpcClient* m_sendMessageToServer_client;
@ -71,6 +73,7 @@ TEST_F(CIpcTests, connectToServer)
{ {
CIpcServer server; CIpcServer server;
server.listen(); server.listen();
m_connectToServer_server = &server;
m_events.adoptHandler( m_events.adoptHandler(
CIpcServer::getMessageReceivedEvent(), &server, CIpcServer::getMessageReceivedEvent(), &server,
@ -85,7 +88,8 @@ TEST_F(CIpcTests, connectToServer)
m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server); m_events.removeHandler(CIpcServer::getMessageReceivedEvent(), &server);
cleanupQuitTimeout(); cleanupQuitTimeout();
EXPECT_EQ(true, m_connectToServer_clientConnected); EXPECT_EQ(true, m_connectToServer_helloMessageReceived);
EXPECT_EQ(true, m_connectToServer_hasClientNode);
} }
TEST_F(CIpcTests, sendMessageToServer) TEST_F(CIpcTests, sendMessageToServer)
@ -148,7 +152,9 @@ TEST_F(CIpcTests, sendMessageToClient)
CIpcTests::CIpcTests() : CIpcTests::CIpcTests() :
m_quitTimeoutTimer(nullptr), m_quitTimeoutTimer(nullptr),
m_connectToServer_clientConnected(false), m_connectToServer_helloMessageReceived(false),
m_connectToServer_hasClientNode(false),
m_connectToServer_server(nullptr),
m_sendMessageToClient_server(nullptr), m_sendMessageToClient_server(nullptr),
m_sendMessageToServer_client(nullptr) m_sendMessageToServer_client(nullptr)
{ {
@ -163,7 +169,9 @@ CIpcTests::connectToServer_handleMessageReceived(const CEvent& e, void*)
{ {
CIpcMessage* m = static_cast<CIpcMessage*>(e.getDataObject()); CIpcMessage* m = static_cast<CIpcMessage*>(e.getDataObject());
if (m->m_type == kIpcHello) { if (m->m_type == kIpcHello) {
m_connectToServer_clientConnected = true; m_connectToServer_hasClientNode =
m_connectToServer_server->hasClients(kIpcClientNode);
m_connectToServer_helloMessageReceived = true;
raiseQuitEvent(); raiseQuitEvent();
} }
} }