finished ipc connect with unit test.

This commit is contained in:
Nick Bolton 2012-07-01 21:18:21 +00:00
parent d829e854a4
commit 05775bc73d
5 changed files with 171 additions and 14 deletions

View file

@ -17,15 +17,30 @@
#include "CIpcServer.h"
#include "Ipc.h"
#include "IEventQueue.h"
#include "TMethodEventJob.h"
#include "CEvent.h"
#include "CLog.h"
#include "CIpcClientProxy.h"
#include "IStream.h"
#include "IDataSocket.h"
CEvent::Type CIpcServer::s_clientConnectedEvent = CEvent::kUnknown;
CIpcServer::CIpcServer() :
m_address(CNetworkAddress(IPC_HOST, IPC_PORT))
{
m_address.resolve();
EVENTQUEUE->adoptHandler(
IListenSocket::getConnectingEvent(), &m_socket,
new TMethodEventJob<CIpcServer>(
this, &CIpcServer::handleClientConnecting));
}
CIpcServer::~CIpcServer()
{
EVENTQUEUE->removeHandler(IListenSocket::getConnectingEvent(), &m_socket);
}
void
@ -33,3 +48,26 @@ CIpcServer::listen()
{
m_socket.bind(m_address);
}
void
CIpcServer::handleClientConnecting(const CEvent&, void*)
{
IStream* stream = m_socket.accept();
if (stream == NULL) {
return;
}
LOG((CLOG_NOTE "accepted ipc client connection"));
// TODO: delete on disconnect
CIpcClientProxy* proxy = new CIpcClientProxy(*stream);
m_clients.insert(proxy);
EVENTQUEUE->addEvent(CEvent(getClientConnectedEvent(), this, proxy));
}
CEvent::Type
CIpcServer::getClientConnectedEvent()
{
return EVENTQUEUE->registerTypeOnce(
s_clientConnectedEvent, "CIpcServer::clientConnected");
}