2013-12-06 10:45:53 +01:00
|
|
|
#include "IServer.h"
|
2013-12-08 23:56:17 +01:00
|
|
|
#include "../NetworkDependencies/Listener.h"
|
|
|
|
#include "IClient.h"
|
|
|
|
#include "../NetworkDependencies/PostBox.h"
|
|
|
|
#include "../../Misc/Utilities.h"
|
2013-12-06 10:45:53 +01:00
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
using namespace Oyster::Network;
|
|
|
|
using namespace ::Server;
|
|
|
|
using namespace Utility::DynamicMemory;
|
|
|
|
|
|
|
|
/*************************************
|
|
|
|
PrivateData
|
|
|
|
*************************************/
|
|
|
|
|
|
|
|
struct IServer::PrivateData
|
2013-12-06 10:45:53 +01:00
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
PrivateData();
|
|
|
|
~PrivateData();
|
|
|
|
|
|
|
|
bool Init(INIT_DESC& initDesc);
|
|
|
|
bool Start();
|
|
|
|
bool Stop();
|
|
|
|
bool Shutdown();
|
|
|
|
|
|
|
|
//
|
|
|
|
IListener* listener;
|
|
|
|
INIT_DESC initDesc;
|
|
|
|
bool started;
|
|
|
|
|
|
|
|
IPostBox<SmartPointer<int>> *postBox;
|
|
|
|
};
|
|
|
|
|
|
|
|
IServer::PrivateData::PrivateData()
|
|
|
|
{
|
|
|
|
listener = 0;
|
|
|
|
started = false;
|
|
|
|
postBox = new PostBox<SmartPointer<int>>();
|
|
|
|
}
|
2013-12-06 10:45:53 +01:00
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
IServer::PrivateData::~PrivateData()
|
|
|
|
{
|
|
|
|
Shutdown();
|
2013-12-06 10:45:53 +01:00
|
|
|
}
|
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
bool IServer::PrivateData::Init(INIT_DESC& initDesc)
|
|
|
|
{
|
|
|
|
//Check if it's a valid port
|
|
|
|
if(initDesc.port == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->initDesc = initDesc;
|
|
|
|
|
|
|
|
//Initiate listener
|
|
|
|
listener = new Listener();
|
|
|
|
((Listener*)listener)->Init(this->initDesc.port, false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::PrivateData::Start()
|
2013-12-06 10:45:53 +01:00
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
//Start listener
|
|
|
|
((Listener*)listener)->Start();
|
|
|
|
started = true;
|
2013-12-06 10:45:53 +01:00
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::PrivateData::Stop()
|
|
|
|
{
|
|
|
|
if(listener)
|
|
|
|
{
|
|
|
|
((Listener*)listener)->Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
started = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::PrivateData::Shutdown()
|
|
|
|
{
|
|
|
|
if(listener)
|
|
|
|
{
|
|
|
|
delete listener;
|
|
|
|
listener = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
started = false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************
|
|
|
|
IServer
|
|
|
|
*************************************/
|
|
|
|
|
|
|
|
IServer::IServer()
|
|
|
|
{
|
|
|
|
privateData = new PrivateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
IServer::~IServer()
|
|
|
|
{
|
|
|
|
if(privateData)
|
|
|
|
{
|
|
|
|
delete privateData;
|
|
|
|
}
|
2013-12-06 10:45:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::Init(INIT_DESC& initDesc)
|
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
privateData->Init(initDesc);
|
2013-12-06 10:45:53 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::Start()
|
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
privateData->Start();
|
2013-12-06 10:45:53 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::Stop()
|
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
privateData->Stop();
|
2013-12-06 10:45:53 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::Shutdown()
|
|
|
|
{
|
2013-12-08 23:56:17 +01:00
|
|
|
privateData->Shutdown();
|
2013-12-06 10:45:53 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IServer::AddSession(ISession* session)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IServer::RemoveSession(ISession* session)
|
|
|
|
{
|
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IServer::IsStarted() const
|
|
|
|
{
|
|
|
|
return privateData->started;
|
2013-12-06 10:45:53 +01:00
|
|
|
}
|