Digitalisierte Elektroverteilung zur permanenten Verbraucherüberwachung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NetServer.h 1.6KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <sstream>
  3. #include <asio.hpp>
  4. #include "net_server_client.h"
  5. namespace net {
  6. enum class MessageTypes : uint32_t
  7. {
  8. ServerAccept,
  9. ServerDeny,
  10. ServerData,
  11. ServerLog,
  12. ServerCondition,
  13. ServerAlert,
  14. ServerCloseConnection,
  15. };
  16. }
  17. class NetServer : public net::ServerInterface<net::MessageTypes>
  18. {
  19. public:
  20. NetServer(uint16_t nPort) : net::ServerInterface<net::MessageTypes>(nPort) {}
  21. NetServer() = delete;
  22. NetServer(NetServer&) = delete;
  23. void Stop() override;
  24. bool Start() override;
  25. bool isRunning(){return serverRunning;}
  26. void notifyAllConnections(net::Message<net::MessageTypes>& message);
  27. bool serverRunning = false;
  28. protected:
  29. virtual bool OnClientConnect(std::shared_ptr<net::Connection<net::MessageTypes>> client) override;
  30. // Called when a client appears to have disconnected
  31. virtual void OnClientDisconnect(std::shared_ptr<net::Connection<net::MessageTypes>> client) override;
  32. // Called when a message arrives
  33. virtual void OnMessage(std::shared_ptr<net::Connection<net::MessageTypes>> client, net::Message<net::MessageTypes>& msg) override;
  34. private:
  35. //Functions to collect the data for response message body
  36. //Collects Data message body
  37. std::stringstream& getBodyData(std::stringstream& buffer);
  38. //Collects Lof files message body
  39. std::stringstream& getBodyLog(std::stringstream& buffer, net::Message<net::MessageTypes> msgRcv);
  40. //Collects Electrical Condition values message body
  41. std::stringstream& getBodyCondition(std::stringstream& buffer);
  42. };