RoboidControl-cpp/SiteServer.h
2025-02-19 17:54:55 +01:00

40 lines
1.1 KiB
C++

#pragma once
#include "Participant.h"
#include <functional>
#include <memory>
#include <unordered_map>
namespace Passer {
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(Participant *sender, ClientMsg *msg) override;
virtual void Process(Participant *sender, NetworkIdMsg *msg) override;
virtual void Process(ThingMsg *msg) override;
using ThingConstructor =
std::function<Thing *(unsigned char networkId, unsigned char thingId)>;
std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors;
};
} // namespace Control
} // namespace Passer
using namespace Passer::RoboidControl;