Ferenc Szontágh
2024-06-27 920507bff803647c79dfce27c4c265b2caee7f8d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef TCPSERVERPLUGIN_H
#define TCPSERVERPLUGIN_H
 
#include "PluginInterface.h"
#include "IPC.h"
#include <nlohmann/json.hpp>
#include <memory>
#include <TcpServer.h>
#include <glog/logging.h>
 
class TcpServerPlugin : public IPlugin {
public:
    TcpServerPlugin(IPC *ipc);
    ~TcpServerPlugin();
 
    void handleMessage(const Command& cmd) override;
    void updateConfig(const nlohmann::json& config) override;
    const std::string getPluginName() override;
 
    void onClientConnect(sockets::ClientHandle client);
    void onClientDisconnect(sockets::ClientHandle client, const sockets::SocketRet& ret);
    void onReceiveClientData(sockets::ClientHandle client, const char* data, size_t size);
 
    const std::string plugin_name = "TcpServer";
 
private:
    void startServer();
    void stopServer();
 
    IPC *ipc;
    nlohmann::json config;
    bool running;
    std::unique_ptr<sockets::TcpServer<TcpServerPlugin>> server;
};
 
extern "C" IPlugin* create(IPC * ipc);
 
#endif // TCPSERVERPLUGIN_H