RoboidControl-cpp/SiteServer.h
2025-02-24 09:30:17 +01:00

37 lines
1.1 KiB
C++

#pragma once
#include "Participant.h"
#include <functional>
#include <memory>
#include <unordered_map>
namespace RoboidControl {
/// @brief A participant is device which can communicate with other participants
class SiteServer : public Participant {
public:
SiteServer(int port = 7681);
// virtual void Update(unsigned long currentTimeMs = 0) override;
template <typename ThingClass>
void Register(unsigned char thingType) {
thingMsgProcessors[thingType] = [](unsigned char networkId, unsigned char thingId) {
return new ThingClass(networkId, thingId);
};
};
protected:
unsigned long nextPublishMe = 0;
virtual void Process(RemoteParticipant* sender, ParticipantMsg* msg) override;
virtual void Process(RemoteParticipant* sender, NetworkIdMsg* msg) override;
virtual void Process(RemoteParticipant* sender, ThingMsg* msg) override;
using ThingConstructor = std::function<Thing*(unsigned char networkId, unsigned char thingId)>;
std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors;
};
} // namespace RoboidControl