ipc client connect test with working unit tests.
This commit is contained in:
parent
7d8fd5927d
commit
218e98398f
|
@ -54,6 +54,18 @@ CEventQueue::~CEventQueue()
|
||||||
setInstance(NULL);
|
setInstance(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CEventQueue::loop()
|
||||||
|
{
|
||||||
|
CEvent event;
|
||||||
|
getEvent(event);
|
||||||
|
while (event.getType() != CEvent::kQuit) {
|
||||||
|
dispatchEvent(event);
|
||||||
|
CEvent::deleteData(event);
|
||||||
|
getEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CEvent::Type
|
CEvent::Type
|
||||||
CEventQueue::registerType(const char* name)
|
CEventQueue::registerType(const char* name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
virtual ~CEventQueue();
|
virtual ~CEventQueue();
|
||||||
|
|
||||||
// IEventQueue overrides
|
// IEventQueue overrides
|
||||||
|
virtual void loop();
|
||||||
virtual void adoptBuffer(IEventQueueBuffer*);
|
virtual void adoptBuffer(IEventQueueBuffer*);
|
||||||
virtual bool getEvent(CEvent& event, double timeout = -1.0);
|
virtual bool getEvent(CEvent& event, double timeout = -1.0);
|
||||||
virtual bool dispatchEvent(const CEvent& event);
|
virtual bool dispatchEvent(const CEvent& event);
|
||||||
|
|
|
@ -49,6 +49,12 @@ public:
|
||||||
//! @name manipulators
|
//! @name manipulators
|
||||||
//@{
|
//@{
|
||||||
|
|
||||||
|
//! Loop the event queue until quit
|
||||||
|
/*!
|
||||||
|
Dequeues and dispatches events until the kQuit event is found.
|
||||||
|
*/
|
||||||
|
virtual void loop() = 0;
|
||||||
|
|
||||||
//! Set the buffer
|
//! Set the buffer
|
||||||
/*!
|
/*!
|
||||||
Replace the current event queue buffer. Any queued events are
|
Replace the current event queue buffer. Any queued events are
|
||||||
|
|
|
@ -16,9 +16,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CIpcClient.h"
|
#include "CIpcClient.h"
|
||||||
|
#include "Ipc.h"
|
||||||
|
|
||||||
CIpcClient::CIpcClient()
|
CIpcClient::CIpcClient() :
|
||||||
|
m_serverAddress(CNetworkAddress(IPC_HOST, IPC_PORT))
|
||||||
{
|
{
|
||||||
|
m_serverAddress.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcClient::~CIpcClient()
|
CIpcClient::~CIpcClient()
|
||||||
|
@ -28,4 +31,5 @@ CIpcClient::~CIpcClient()
|
||||||
void
|
void
|
||||||
CIpcClient::connect()
|
CIpcClient::connect()
|
||||||
{
|
{
|
||||||
|
m_socket.connect(m_serverAddress);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "CNetworkAddress.h"
|
||||||
|
#include "CTCPSocket.h"
|
||||||
|
|
||||||
//! IPC client for communication between daemon and GUI.
|
//! IPC client for communication between daemon and GUI.
|
||||||
/*!
|
/*!
|
||||||
* See \ref CIpcServer description.
|
* See \ref CIpcServer description.
|
||||||
|
@ -28,4 +31,8 @@ public:
|
||||||
|
|
||||||
//! Connects to the IPC server at localhost.
|
//! Connects to the IPC server at localhost.
|
||||||
void connect();
|
void connect();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CNetworkAddress m_serverAddress;
|
||||||
|
CTCPSocket m_socket;
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,9 +16,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CIpcServer.h"
|
#include "CIpcServer.h"
|
||||||
|
#include "Ipc.h"
|
||||||
|
|
||||||
CIpcServer::CIpcServer()
|
CIpcServer::CIpcServer() :
|
||||||
|
m_address(CNetworkAddress(IPC_HOST, IPC_PORT))
|
||||||
{
|
{
|
||||||
|
m_address.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
CIpcServer::~CIpcServer()
|
CIpcServer::~CIpcServer()
|
||||||
|
@ -28,4 +31,5 @@ CIpcServer::~CIpcServer()
|
||||||
void
|
void
|
||||||
CIpcServer::listen()
|
CIpcServer::listen()
|
||||||
{
|
{
|
||||||
|
m_socket.bind(m_address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "CTCPListenSocket.h"
|
||||||
|
#include "CNetworkAddress.h"
|
||||||
|
|
||||||
//! IPC server for communication between daemon and GUI.
|
//! IPC server for communication between daemon and GUI.
|
||||||
/*!
|
/*!
|
||||||
* The IPC server listens on localhost. The IPC client runs on both the
|
* The IPC server listens on localhost. The IPC client runs on both the
|
||||||
|
@ -31,4 +34,8 @@ public:
|
||||||
|
|
||||||
//! Opens a TCP socket only allowing local connections
|
//! Opens a TCP socket only allowing local connections
|
||||||
void listen();
|
void listen();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CTCPListenSocket m_socket;
|
||||||
|
CNetworkAddress m_address;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
set(inc
|
set(inc
|
||||||
|
Ipc.h
|
||||||
CIpcServer.h
|
CIpcServer.h
|
||||||
CIpcClient.h
|
CIpcClient.h
|
||||||
CIpcServerProxy.h
|
CIpcServerProxy.h
|
||||||
|
@ -32,6 +33,11 @@ if (WIN32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(inc
|
set(inc
|
||||||
|
../arch
|
||||||
|
../base
|
||||||
|
../common
|
||||||
|
../io
|
||||||
|
../mt
|
||||||
../net
|
../net
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,5 +51,5 @@ include_directories(${inc})
|
||||||
add_library(ipc STATIC ${src})
|
add_library(ipc STATIC ${src})
|
||||||
|
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
target_link_libraries(net)
|
target_link_libraries(arch base common mt io net)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define IPC_HOST "127.0.0.1"
|
||||||
|
#define IPC_PORT 24801
|
|
@ -82,6 +82,7 @@ CSocketMultiplexer::~CSocketMultiplexer()
|
||||||
CSocketMultiplexer*
|
CSocketMultiplexer*
|
||||||
CSocketMultiplexer::getInstance()
|
CSocketMultiplexer::getInstance()
|
||||||
{
|
{
|
||||||
|
assert(s_instance != NULL);
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -538,14 +538,8 @@ CClientApp::mainLoop()
|
||||||
// run event loop. if startClient() failed we're supposed to retry
|
// run event loop. if startClient() failed we're supposed to retry
|
||||||
// later. the timer installed by startClient() will take care of
|
// later. the timer installed by startClient() will take care of
|
||||||
// that.
|
// that.
|
||||||
CEvent event;
|
|
||||||
DAEMON_RUNNING(true);
|
DAEMON_RUNNING(true);
|
||||||
EVENTQUEUE->getEvent(event);
|
EVENTQUEUE->loop();
|
||||||
while (event.getType() != CEvent::kQuit) {
|
|
||||||
EVENTQUEUE->dispatchEvent(event);
|
|
||||||
CEvent::deleteData(event);
|
|
||||||
EVENTQUEUE->getEvent(event);
|
|
||||||
}
|
|
||||||
DAEMON_RUNNING(false);
|
DAEMON_RUNNING(false);
|
||||||
|
|
||||||
// close down
|
// close down
|
||||||
|
|
|
@ -190,13 +190,7 @@ CDaemonApp::mainLoop(bool logToFile)
|
||||||
m_relauncher.startAsync();
|
m_relauncher.startAsync();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CEvent event;
|
EVENTQUEUE->loop();
|
||||||
EVENTQUEUE->getEvent(event);
|
|
||||||
while (event.getType() != CEvent::kQuit) {
|
|
||||||
EVENTQUEUE->dispatchEvent(event);
|
|
||||||
CEvent::deleteData(event);
|
|
||||||
EVENTQUEUE->getEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
m_relauncher.stop();
|
m_relauncher.stop();
|
||||||
|
|
|
@ -356,13 +356,9 @@ CServerApp::closeServer(CServer* server)
|
||||||
new TMethodEventJob<CServerApp>(this, &CServerApp::handleClientsDisconnected));
|
new TMethodEventJob<CServerApp>(this, &CServerApp::handleClientsDisconnected));
|
||||||
EVENTQUEUE->adoptHandler(CServer::getDisconnectedEvent(), server,
|
EVENTQUEUE->adoptHandler(CServer::getDisconnectedEvent(), server,
|
||||||
new TMethodEventJob<CServerApp>(this, &CServerApp::handleClientsDisconnected));
|
new TMethodEventJob<CServerApp>(this, &CServerApp::handleClientsDisconnected));
|
||||||
CEvent event;
|
|
||||||
EVENTQUEUE->getEvent(event);
|
EVENTQUEUE->loop();
|
||||||
while (event.getType() != CEvent::kQuit) {
|
|
||||||
EVENTQUEUE->dispatchEvent(event);
|
|
||||||
CEvent::deleteData(event);
|
|
||||||
EVENTQUEUE->getEvent(event);
|
|
||||||
}
|
|
||||||
EVENTQUEUE->removeHandler(CEvent::kTimer, timer);
|
EVENTQUEUE->removeHandler(CEvent::kTimer, timer);
|
||||||
EVENTQUEUE->deleteTimer(timer);
|
EVENTQUEUE->deleteTimer(timer);
|
||||||
EVENTQUEUE->removeHandler(CServer::getDisconnectedEvent(), server);
|
EVENTQUEUE->removeHandler(CServer::getDisconnectedEvent(), server);
|
||||||
|
@ -815,14 +811,8 @@ CServerApp::mainLoop()
|
||||||
// run event loop. if startServer() failed we're supposed to retry
|
// run event loop. if startServer() failed we're supposed to retry
|
||||||
// later. the timer installed by startServer() will take care of
|
// later. the timer installed by startServer() will take care of
|
||||||
// that.
|
// that.
|
||||||
CEvent event;
|
|
||||||
DAEMON_RUNNING(true);
|
DAEMON_RUNNING(true);
|
||||||
EVENTQUEUE->getEvent(event);
|
EVENTQUEUE->loop();
|
||||||
while (event.getType() != CEvent::kQuit) {
|
|
||||||
EVENTQUEUE->dispatchEvent(event);
|
|
||||||
CEvent::deleteData(event);
|
|
||||||
EVENTQUEUE->getEvent(event);
|
|
||||||
}
|
|
||||||
DAEMON_RUNNING(false);
|
DAEMON_RUNNING(false);
|
||||||
|
|
||||||
// close down
|
// close down
|
||||||
|
|
|
@ -18,21 +18,19 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "CIpcServer.h"
|
#include "CIpcServer.h"
|
||||||
#include "CIpcClient.h"
|
#include "CIpcClient.h"
|
||||||
|
#include "CSocketMultiplexer.h"
|
||||||
|
#include "CEventQueue.h"
|
||||||
|
|
||||||
TEST(CIpcTests, serverSend)
|
TEST(CIpcTests, connectToServer)
|
||||||
{
|
{
|
||||||
|
CSocketMultiplexer multiplexer;
|
||||||
|
CEventQueue eventQueue;
|
||||||
|
|
||||||
CIpcServer server;
|
CIpcServer server;
|
||||||
server.listen();
|
server.listen();
|
||||||
|
|
||||||
CIpcClient client;
|
CIpcClient client;
|
||||||
client.connect();
|
client.connect();
|
||||||
}
|
|
||||||
|
|
||||||
TEST(CIpcTests, clientSend)
|
eventQueue.loop();
|
||||||
{
|
|
||||||
CIpcServer server;
|
|
||||||
server.listen();
|
|
||||||
|
|
||||||
CIpcClient client;
|
|
||||||
client.connect();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
class CMockEventQueue : public IEventQueue
|
class CMockEventQueue : public IEventQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
MOCK_METHOD0(loop, void());
|
||||||
MOCK_METHOD2(newOneShotTimer, CEventQueueTimer*(double, void*));
|
MOCK_METHOD2(newOneShotTimer, CEventQueueTimer*(double, void*));
|
||||||
MOCK_METHOD2(newTimer, CEventQueueTimer*(double, void*));
|
MOCK_METHOD2(newTimer, CEventQueueTimer*(double, void*));
|
||||||
MOCK_METHOD2(getEvent, bool(CEvent&, double));
|
MOCK_METHOD2(getEvent, bool(CEvent&, double));
|
||||||
|
|
Loading…
Reference in New Issue