3 $Date: 2009/06/23 11:32:28 $
10 #include "stg/os_int.h"
11 #include "stg/plugin.h"
12 #include "stg/module_settings.h"
13 #include "stg/notifer.h"
14 #include "stg/user_ips.h"
15 #include "stg/pinger.h"
16 #include "stg/users.h"
17 #include "stg/logger.h"
24 extern "C" PLUGIN * GetPlugin();
29 //-----------------------------------------------------------------------------*/
30 class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t> {
32 CHG_CURRIP_NOTIFIER_PING(const PING & p, USER_PTR u)
33 : PROPERTY_NOTIFIER_BASE<uint32_t>(), user(u), ping(p) {}
34 CHG_CURRIP_NOTIFIER_PING(const CHG_CURRIP_NOTIFIER_PING & rvalue)
35 : PROPERTY_NOTIFIER_BASE<uint32_t>(),
36 user(rvalue.user), ping(rvalue.ping) {}
37 void Notify(const uint32_t & oldIP, const uint32_t & newIP);
38 USER_PTR GetUser() const { return user; }
41 CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING & rvalue);
46 //-----------------------------------------------------------------------------
47 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
49 CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u)
50 : PROPERTY_NOTIFIER_BASE<USER_IPS>(), user(u), ping(p) {}
51 CHG_IPS_NOTIFIER_PING(const CHG_IPS_NOTIFIER_PING & rvalue)
52 : PROPERTY_NOTIFIER_BASE<USER_IPS>(),
53 user(rvalue.user), ping(rvalue.ping) {}
54 void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
55 USER_PTR GetUser() const { return user; }
58 CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING & rvalue);
63 //-----------------------------------------------------------------------------
64 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
66 explicit ADD_USER_NONIFIER_PING(PING & p) : NOTIFIER_BASE<USER_PTR>(), ping(p) {}
67 virtual ~ADD_USER_NONIFIER_PING() {}
68 void Notify(const USER_PTR & user);
71 ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING & rvalue);
72 ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING & rvalue);
76 //-----------------------------------------------------------------------------
77 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
79 explicit DEL_USER_NONIFIER_PING(PING & p) : NOTIFIER_BASE<USER_PTR>(), ping(p) {}
80 virtual ~DEL_USER_NONIFIER_PING() {}
81 void Notify(const USER_PTR & user);
84 DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING & rvalue);
85 DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING & rvalue);
89 //-----------------------------------------------------------------------------
92 PING_SETTINGS() : pingDelay(0), errorStr() {}
93 virtual ~PING_SETTINGS() {}
94 const std::string & GetStrError() const { return errorStr; }
95 int ParseSettings(const MODULE_SETTINGS & s);
96 int GetPingDelay() const { return pingDelay; }
99 mutable std::string errorStr;
101 //-----------------------------------------------------------------------------
102 class PING : public PLUGIN {
103 friend class CHG_CURRIP_NOTIFIER_PING;
104 friend class CHG_IPS_NOTIFIER_PING;
109 void SetUsers(USERS * u) { users = u; }
110 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
115 int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
118 const std::string & GetStrError() const { return errorStr; }
119 std::string GetVersion() const { return "Pinger v.1.01"; }
120 uint16_t GetStartPosition() const { return 10; }
121 uint16_t GetStopPosition() const { return 10; }
123 void AddUser(USER_PTR u);
124 void DelUser(USER_PTR u);
127 explicit PING(const PING & rvalue);
128 PING & operator=(const PING & rvalue);
131 void SetUserNotifiers(USER_PTR u);
132 void UnSetUserNotifiers(USER_PTR u);
133 static void * Run(void * d);
135 mutable std::string errorStr;
136 PING_SETTINGS pingSettings;
137 MODULE_SETTINGS settings;
139 std::list<USER_PTR> usersList;
142 pthread_mutex_t mutex;
145 mutable STG_PINGER pinger;
147 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
148 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
150 ADD_USER_NONIFIER_PING onAddUserNotifier;
151 DEL_USER_NONIFIER_PING onDelUserNotifier;
153 PLUGIN_LOGGER logger;
155 //-----------------------------------------------------------------------------