3 $Date: 2009/06/23 11:32:28 $
15 #include "stg/os_int.h"
16 #include "stg/plugin.h"
17 #include "stg/module_settings.h"
18 #include "stg/notifer.h"
19 #include "stg/user_ips.h"
20 #include "stg/pinger.h"
21 #include "stg/users.h"
23 extern "C" PLUGIN * GetPlugin();
28 //-----------------------------------------------------------------------------*/
29 class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t> {
31 CHG_CURRIP_NOTIFIER_PING(const PING & p, USER_PTR u)
32 : PROPERTY_NOTIFIER_BASE<uint32_t>(), user(u), ping(p) {}
33 CHG_CURRIP_NOTIFIER_PING(const CHG_CURRIP_NOTIFIER_PING & rvalue)
34 : PROPERTY_NOTIFIER_BASE<uint32_t>(),
35 user(rvalue.user), ping(rvalue.ping) {}
36 void Notify(const uint32_t & oldIP, const uint32_t & newIP);
37 USER_PTR GetUser() const { return user; }
40 CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING & rvalue);
45 //-----------------------------------------------------------------------------
46 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
48 CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u)
49 : PROPERTY_NOTIFIER_BASE<USER_IPS>(), user(u), ping(p) {}
50 CHG_IPS_NOTIFIER_PING(const CHG_IPS_NOTIFIER_PING & rvalue)
51 : PROPERTY_NOTIFIER_BASE<USER_IPS>(),
52 user(rvalue.user), ping(rvalue.ping) {}
53 void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
54 USER_PTR GetUser() const { return user; }
57 CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING & rvalue);
62 //-----------------------------------------------------------------------------
63 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
65 ADD_USER_NONIFIER_PING(PING & p) : NOTIFIER_BASE<USER_PTR>(), ping(p) {}
66 virtual ~ADD_USER_NONIFIER_PING() {}
67 void Notify(const USER_PTR & user);
70 ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING & rvalue);
71 ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING & rvalue);
75 //-----------------------------------------------------------------------------
76 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
78 DEL_USER_NONIFIER_PING(PING & p) : NOTIFIER_BASE<USER_PTR>(), ping(p) {}
79 virtual ~DEL_USER_NONIFIER_PING() {}
80 void Notify(const USER_PTR & user);
83 DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING & rvalue);
84 DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING & rvalue);
88 //-----------------------------------------------------------------------------
91 PING_SETTINGS() : pingDelay(0), errorStr() {}
92 virtual ~PING_SETTINGS() {}
93 const std::string & GetStrError() const { return errorStr; }
94 int ParseSettings(const MODULE_SETTINGS & s);
95 int GetPingDelay() const { return pingDelay; }
98 mutable std::string errorStr;
100 //-----------------------------------------------------------------------------
101 class PING : public PLUGIN {
102 friend class CHG_CURRIP_NOTIFIER_PING;
103 friend class CHG_IPS_NOTIFIER_PING;
108 void SetUsers(USERS * u) { users = u; }
109 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
114 int Reload() { return 0; }
117 const std::string & GetStrError() const { return errorStr; }
118 const std::string GetVersion() const { return "Pinger v.1.01"; }
119 uint16_t GetStartPosition() const { return 10; }
120 uint16_t GetStopPosition() const { return 10; }
122 void AddUser(USER_PTR u);
123 void DelUser(USER_PTR u);
126 PING(const PING & rvalue);
127 PING & operator=(const PING & rvalue);
130 void SetUserNotifiers(USER_PTR u);
131 void UnSetUserNotifiers(USER_PTR u);
132 static void * Run(void * d);
134 mutable std::string errorStr;
135 PING_SETTINGS pingSettings;
136 MODULE_SETTINGS settings;
138 std::list<USER_PTR> usersList;
141 pthread_mutex_t mutex;
144 mutable STG_PINGER pinger;
146 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
147 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
149 ADD_USER_NONIFIER_PING onAddUserNotifier;
150 DEL_USER_NONIFIER_PING onDelUserNotifier;
152 //-----------------------------------------------------------------------------