#include "SiteServer.h" #include "Things/TemperatureSensor.h" #if !defined(NO_STD) #include #include #endif namespace RoboidControl { #pragma region Init SiteServer::SiteServer(int port) : ParticipantUDP(port) { this->name = "Site Server"; this->publishInterval = 0; SetupUDP(port, ipAddress, 0); } #pragma endregion Init #pragma region Update void SiteServer::UpdateMyThings() { for (Thing* thing : this->things) { if (thing == nullptr) continue; thing->Update(true); if (this->isIsolated == false) { // Send to all other participants #if defined(NO_STD) Participant** participants = Participant::registry.GetAll(); for (int ix = 0; ix < Participant::registry.count; ix++) { Participant* participant = participants[ix]; #else for (Participant* participant : Participant::registry.GetAll()) { #endif if (participant == nullptr || participant == this) continue; PoseMsg* poseMsg = new PoseMsg(this->networkId, thing); this->Send(participant, poseMsg); delete poseMsg; BinaryMsg* binaryMsg = new BinaryMsg(this->networkId, thing); this->Send(participant, binaryMsg); delete binaryMsg; } } } } #pragma endregion Update #pragma region Receive void SiteServer::Process(Participant* sender, ParticipantMsg* msg) { if (msg->networkId != sender->networkId) { // std::cout << this->name << " received New Client -> " << // sender->ipAddress // << ":" << (int)sender->port << "\n"; NetworkIdMsg* msg = new NetworkIdMsg(sender->networkId); this->Send(sender, msg); delete msg; } } void SiteServer::Process(Participant* sender, NetworkIdMsg* msg) {} void SiteServer::Process(Participant* sender, ThingMsg* msg) { Thing* thing = sender->Get(msg->thingId); if (thing == nullptr) // new Thing(sender, (Thing::Type)msg->thingType, msg->thingId); Thing::Reconstruct(sender, msg->thingType, msg->thingId); if (msg->parentId != 0) { thing->SetParent(*Get(msg->parentId)); if (thing->IsRoot()) // if (thing->GetParent() != nullptr) #if defined(NO_STD) ; #else std::cout << "Could not find parent [" << (int)msg->networkId << "/" << (int)msg->parentId << "]\n"; #endif } else thing->SetParent(Thing::LocalRoot()); } #pragma endregion Receive } // namespace RoboidControl