#include "ehs/io/socket/CommsSystem.h" #include "ehs/io/socket/Comms.h" #include "ehs/io/socket/Endpoint.h" #include "ehs/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(); 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."); } }