3 #include "stg/plugin.h"
4 #include "stg/module_settings.h"
5 #include "stg/notifer.h"
6 #include "stg/user_ips.h"
7 #include "stg/pinger.h"
9 #include "stg/logger.h"
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wshadow"
16 #include <jthread.hpp>
17 #pragma GCC diagnostic pop
28 using UserPtr = STG::User*;
29 //-----------------------------------------------------------------------------*/
30 class CHG_CURRIP_NOTIFIER_PING: public STG::PropertyNotifierBase<uint32_t> {
32 CHG_CURRIP_NOTIFIER_PING(const PING & p, UserPtr u)
34 void notify(const uint32_t & oldIP, const uint32_t & newIP) override;
35 UserPtr GetUser() const { return user; }
38 CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING &);
43 //-----------------------------------------------------------------------------
44 class CHG_IPS_NOTIFIER_PING: public STG::PropertyNotifierBase<STG::UserIPs> {
46 CHG_IPS_NOTIFIER_PING(const PING & p, UserPtr u)
48 void notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS) override;
49 UserPtr GetUser() const { return user; }
52 CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING &);
57 //-----------------------------------------------------------------------------
58 class ADD_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
60 explicit ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
61 void notify(const UserPtr & user) override;
64 ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING &);
65 ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING &);
69 //-----------------------------------------------------------------------------
70 class DEL_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
72 explicit DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
73 void notify(const UserPtr & user) override;
76 DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING &);
77 DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING &);
81 //-----------------------------------------------------------------------------
84 PING_SETTINGS() : pingDelay(0) {}
85 const std::string & GetStrError() const { return errorStr; }
86 int ParseSettings(const STG::ModuleSettings & s);
87 int GetPingDelay() const { return pingDelay; }
90 mutable std::string errorStr;
92 //-----------------------------------------------------------------------------
93 class PING : public STG::Plugin {
94 friend class CHG_CURRIP_NOTIFIER_PING;
95 friend class CHG_IPS_NOTIFIER_PING;
99 void SetUsers(STG::Users * u) override { users = u; }
100 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
101 int ParseSettings() override;
103 int Start() override;
105 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
106 bool IsRunning() override;
108 const std::string & GetStrError() const override { return errorStr; }
109 std::string GetVersion() const override { return "Pinger v.1.01"; }
110 uint16_t GetStartPosition() const override { return 10; }
111 uint16_t GetStopPosition() const override { return 10; }
113 void AddUser(UserPtr u);
114 void DelUser(UserPtr u);
117 explicit PING(const PING & rvalue);
118 PING & operator=(const PING & rvalue);
121 void SetUserNotifiers(UserPtr u);
122 void UnSetUserNotifiers(UserPtr u);
123 void Run(std::stop_token token);
125 mutable std::string errorStr;
126 PING_SETTINGS pingSettings;
127 STG::ModuleSettings settings;
129 std::list<UserPtr> usersList;
131 std::jthread m_thread;
134 mutable STG_PINGER pinger;
136 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
137 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
139 ADD_USER_NONIFIER_PING onAddUserNotifier;
140 DEL_USER_NONIFIER_PING onDelUserNotifier;
142 STG::PluginLogger logger;