3 #include "stg/plugin.h"
4 #include "stg/module_settings.h"
5 #include "stg/subscriptions.h"
6 #include "stg/user_ips.h"
7 #include "stg/pinger.h"
9 #include "stg/logger.h"
16 #pragma GCC diagnostic push
17 #pragma GCC diagnostic ignored "-Wshadow"
18 #include <jthread.hpp>
19 #pragma GCC diagnostic pop
27 using UserPtr = User*;
28 //-----------------------------------------------------------------------------
32 PING_SETTINGS() : pingDelay(0) {}
33 const std::string & GetStrError() const { return errorStr; }
34 int ParseSettings(const ModuleSettings & s);
35 int GetPingDelay() const { return pingDelay; }
40 //-----------------------------------------------------------------------------
41 class PING : public Plugin
46 void SetUsers(Users * u) override { users = u; }
47 void SetSettings(const ModuleSettings & s) override { settings = s; }
48 int ParseSettings() override;
52 int Reload(const ModuleSettings & /*ms*/) override { return 0; }
53 bool IsRunning() override;
55 const std::string & GetStrError() const override { return errorStr; }
56 std::string GetVersion() const override { return "Pinger v.1.01"; }
57 uint16_t GetStartPosition() const override { return 10; }
58 uint16_t GetStopPosition() const override { return 10; }
60 void AddUser(UserPtr u);
61 void DelUser(UserPtr u);
64 explicit PING(const PING & rvalue);
65 PING & operator=(const PING & rvalue);
68 void SetUserNotifiers(UserPtr u);
69 void UnSetUserNotifiers(UserPtr u);
70 void Run(std::stop_token token);
73 PING_SETTINGS pingSettings;
74 ModuleSettings settings;
76 std::list<UserPtr> usersList;
78 std::jthread m_thread;
83 void updateCurrIP(uint32_t oldVal, uint32_t newVal);
84 void updateIPs(const UserIPs& oldVal, const UserIPs& newVal);
86 ScopedConnection m_onAddUserConn;
87 ScopedConnection m_onDelUserConn;
89 using ConnHolder = std::tuple<int, ScopedConnection, ScopedConnection>;
90 std::vector<ConnHolder> m_conns;