Reorganized project again.
This commit is contained in:
84
src/io/socket/CommsSystem.cpp
Normal file
84
src/io/socket/CommsSystem.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "io/socket/CommsSystem.h"
|
||||
#include "io/socket/Comms.h"
|
||||
#include "io/socket/Endpoint.h"
|
||||
#include "io/socket/Operation.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
CommsSystem::~CommsSystem()
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
delete ops[i];
|
||||
ops.Clear();
|
||||
}
|
||||
|
||||
CommsSystem::CommsSystem()
|
||||
: hashId(0)
|
||||
{
|
||||
}
|
||||
|
||||
CommsSystem::CommsSystem(const Str_8& id)
|
||||
: id(id), hashId(id.Hash_64())
|
||||
{
|
||||
}
|
||||
|
||||
CommsSystem::CommsSystem(const CommsSystem& sys)
|
||||
: id(sys.id), hashId(sys.hashId)
|
||||
{
|
||||
}
|
||||
|
||||
CommsSystem& CommsSystem::operator=(const CommsSystem& sys)
|
||||
{
|
||||
if (this == &sys)
|
||||
return *this;
|
||||
|
||||
id = sys.id;
|
||||
hashId = sys.hashId;
|
||||
ops = Array<Operation*>();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Str_8 CommsSystem::GetId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
UInt_64 CommsSystem::GetHashId() const
|
||||
{
|
||||
return hashId;
|
||||
}
|
||||
|
||||
bool CommsSystem::HasOperation(const UInt_64 hashId)
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
if (ops[i]->GetHashId() == hashId)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CommsSystem::AddOperation(Operation* op)
|
||||
{
|
||||
if (HasOperation(op->GetHashId()))
|
||||
return false;
|
||||
|
||||
ops.Push(op);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CommsSystem::Execute(Comms* comms, Endpoint* endpoint, const UInt_64 hashId, Serializer<>& payload)
|
||||
{
|
||||
for (UInt_64 i = 0; i < ops.Size(); ++i)
|
||||
{
|
||||
if (ops[i]->GetHashId() == hashId)
|
||||
{
|
||||
ops[i]->Process(comms, endpoint, this, payload);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EHS_LOG_INT("Info", 0, "System not found.");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user