#include "ehs/io/socket/ehc/NetSys.h" #include "ehs/io/socket/EHC.h" #include "ehs/io/socket/ehc/NetEnd.h" #include "ehs/io/socket/ehc/NetOp.h" #include "ehs/io/socket/ehc/NetChannel.h" namespace ehs { NetSys::~NetSys() { for (UInt_64 i = 0; i < ops.Size(); ++i) delete ops[i]; ops.Clear(); } NetSys::NetSys() : id(0) { } NetSys::NetSys(Str_8 name) : id(name.Hash_64()), name((Str_8&&)name) { } NetSys::NetSys(NetSys&& sys) noexcept : id(sys.id), name((Str_8&&)sys.name), ops((Array&&)sys.ops) { sys.id = 0; } NetSys::NetSys(const NetSys& sys) : id(sys.id), name(sys.name) { } NetSys& NetSys::operator=(NetSys&& sys) noexcept { if (this == &sys) return *this; id = sys.id; name = (Str_8&&)sys.name; ops = (Array&&)sys.ops; sys.id = 0; return *this; } NetSys& NetSys::operator=(const NetSys& sys) { if (this == &sys) return *this; id = sys.id; name = sys.name; ops = Array(); return *this; } UInt_64 NetSys::GetId() const { return id; } Str_8 NetSys::GetName() const { return name; } bool NetSys::HasOperation(const UInt_64 id) const { for (UInt_64 i = 0; i < ops.Size(); ++i) if (ops[i]->GetId() == id) return true; return false; } bool NetSys::AddOperation(NetOp* op) { if (HasOperation(op->GetId())) return false; ops.Push(op); return true; } void NetSys::Execute(NetChannel *channel, NetEnd *endpoint, const UInt_64 hashId, Serializer &payload) { for (UInt_64 i = 0; i < ops.Size(); ++i) { if (ops[i]->GetId() == hashId) { ops[i]->Execute(channel, endpoint, this, payload); return; } } EHS_LOG_INT(LogType::INFO, 0, "System not found."); } }