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);
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);
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);
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);
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;
100 void SetUsers(STG::Users * u) override { users = u; }
101 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
102 int ParseSettings() override;
104 int Start() override;
106 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
107 bool IsRunning() override;
109 const std::string & GetStrError() const override { return errorStr; }
110 std::string GetVersion() const override { return "Pinger v.1.01"; }
111 uint16_t GetStartPosition() const override { return 10; }
112 uint16_t GetStopPosition() const override { return 10; }
114 void AddUser(UserPtr u);
115 void DelUser(UserPtr u);
118 explicit PING(const PING & rvalue);
119 PING & operator=(const PING & rvalue);
122 void SetUserNotifiers(UserPtr u);
123 void UnSetUserNotifiers(UserPtr u);
124 void Run(std::stop_token token);
126 mutable std::string errorStr;
127 PING_SETTINGS pingSettings;
128 STG::ModuleSettings settings;
130 std::list<UserPtr> usersList;
132 std::jthread m_thread;
135 mutable STG_PINGER pinger;
137 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
138 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
140 ADD_USER_NONIFIER_PING onAddUserNotifier;
141 DEL_USER_NONIFIER_PING onDelUserNotifier;
143 STG::PluginLogger logger;