RoboidControl-cpp/SiteServer.cpp
2025-02-24 12:54:06 +01:00

52 lines
1.4 KiB
C++

#include "SiteServer.h"
#include "Sensors/TemperatureSensor.h"
#include <functional>
#include <memory>
namespace RoboidControl {
SiteServer::SiteServer(int port) {
this->name = "Site Server";
this->publishInterval = 0;
this->ipAddress = "0.0.0.0";
this->port = port;
this->senders.push_back(this);
SetupUDP(port, ipAddress, 0);
Register<TemperatureSensor>((unsigned char)Thing::Type::TemperatureSensor);
}
void SiteServer::Process(RemoteParticipant *sender, ParticipantMsg *msg) {
if (msg->networkId == 0) {
std::cout << this->name << " received New Client -> " << sender->ipAddress
<< " " << (int)sender->networkId << "\n";
SiteMsg *msg = new SiteMsg(sender->networkId);
//sender->Send(msg);
this->Send(sender, msg);
delete msg;
}
}
void SiteServer::Process(RemoteParticipant *sender, SiteMsg *msg) {}
void SiteServer::Process(RemoteParticipant *sender, ThingMsg *msg) {
Thing *thing = sender->Get(msg->networkId, msg->thingId);
if (thing == nullptr) {
auto thingMsgProcessor = thingMsgProcessors.find(msg->thingType);
Thing *newThing;
if (thingMsgProcessor != thingMsgProcessors.end()) // found item
newThing = thingMsgProcessor->second(sender, msg->networkId, msg->thingId);
else
newThing = new Thing(sender, msg->networkId, msg->thingId,
(Thing::Type)msg->thingType);
//sender->Add(newThing);
}
}
} // namespace Control