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"
25 using UserPtr = STG::User*;
26 //-----------------------------------------------------------------------------*/
27 class CHG_CURRIP_NOTIFIER_PING: public STG::PropertyNotifierBase<uint32_t> {
29 CHG_CURRIP_NOTIFIER_PING(const PING & p, UserPtr u)
31 void Notify(const uint32_t & oldIP, const uint32_t & newIP);
32 UserPtr GetUser() const { return user; }
35 CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING &);
40 //-----------------------------------------------------------------------------
41 class CHG_IPS_NOTIFIER_PING: public STG::PropertyNotifierBase<STG::UserIPs> {
43 CHG_IPS_NOTIFIER_PING(const PING & p, UserPtr u)
45 void Notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS);
46 UserPtr GetUser() const { return user; }
49 CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING &);
54 //-----------------------------------------------------------------------------
55 class ADD_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
57 explicit ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
58 void Notify(const UserPtr & user);
61 ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING &);
62 ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING &);
66 //-----------------------------------------------------------------------------
67 class DEL_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
69 explicit DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
70 void Notify(const UserPtr & user);
73 DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING &);
74 DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING &);
78 //-----------------------------------------------------------------------------
81 PING_SETTINGS() : pingDelay(0) {}
82 const std::string & GetStrError() const { return errorStr; }
83 int ParseSettings(const STG::ModuleSettings & s);
84 int GetPingDelay() const { return pingDelay; }
87 mutable std::string errorStr;
89 //-----------------------------------------------------------------------------
90 class PING : public STG::Plugin {
91 friend class CHG_CURRIP_NOTIFIER_PING;
92 friend class CHG_IPS_NOTIFIER_PING;
97 void SetUsers(STG::Users * u) override { users = u; }
98 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
99 int ParseSettings() override;
101 int Start() override;
103 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
104 bool IsRunning() override;
106 const std::string & GetStrError() const override { return errorStr; }
107 std::string GetVersion() const override { return "Pinger v.1.01"; }
108 uint16_t GetStartPosition() const override { return 10; }
109 uint16_t GetStopPosition() const override { return 10; }
111 void AddUser(UserPtr u);
112 void DelUser(UserPtr u);
115 explicit PING(const PING & rvalue);
116 PING & operator=(const PING & rvalue);
119 void SetUserNotifiers(UserPtr u);
120 void UnSetUserNotifiers(UserPtr u);
121 static void * Run(void * d);
123 mutable std::string errorStr;
124 PING_SETTINGS pingSettings;
125 STG::ModuleSettings settings;
127 std::list<UserPtr> usersList;
130 pthread_mutex_t mutex;
133 mutable STG_PINGER pinger;
135 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
136 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
138 ADD_USER_NONIFIER_PING onAddUserNotifier;
139 DEL_USER_NONIFIER_PING onDelUserNotifier;
141 STG::PluginLogger logger;