123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #pragma once
- #include <sstream>
-
- #include <asio.hpp>
- #include "net_server_client.h"
-
- namespace net {
- enum class MessageTypes : uint32_t
- {
- ServerAccept,
- ServerDeny,
- ServerData,
- ServerLog,
- ServerCondition,
- ServerAlert,
- ServerCloseConnection,
- };
- }
-
- class NetServer : public net::ServerInterface<net::MessageTypes>
- {
- public:
- NetServer(uint16_t nPort) : net::ServerInterface<net::MessageTypes>(nPort) {}
- NetServer() = delete;
- NetServer(NetServer&) = delete;
-
- void Stop() override;
- bool Start() override;
-
- bool isRunning(){return serverRunning;}
-
- void notifyAllConnections(net::Message<net::MessageTypes>& message);
-
- bool serverRunning = false;
- protected:
- virtual bool OnClientConnect(std::shared_ptr<net::Connection<net::MessageTypes>> client) override;
-
- // Called when a client appears to have disconnected
- virtual void OnClientDisconnect(std::shared_ptr<net::Connection<net::MessageTypes>> client) override;
-
- // Called when a message arrives
- virtual void OnMessage(std::shared_ptr<net::Connection<net::MessageTypes>> client, net::Message<net::MessageTypes>& msg) override;
-
- private:
- //Functions to collect the data for response message body
-
- //Collects Data message body
- std::stringstream& getBodyData(std::stringstream& buffer);
- //Collects Lof files message body
- std::stringstream& getBodyLog(std::stringstream& buffer, net::Message<net::MessageTypes> msgRcv);
- //Collects Electrical Condition values message body
- std::stringstream& getBodyCondition(std::stringstream& buffer);
-
- };
|