3 $Date: 2009/06/23 11:32:28 $
10 #include "stg/plugin.h"
11 #include "stg/module_settings.h"
12 #include "stg/notifer.h"
13 #include "stg/user_ips.h"
14 #include "stg/pinger.h"
15 #include "stg/users.h"
16 #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)
34 void Notify(const uint32_t & oldIP, const uint32_t & newIP);
35 USER_PTR GetUser() const { return user; }
38 CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING &);
43 //-----------------------------------------------------------------------------
44 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
46 CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u)
48 void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
49 USER_PTR GetUser() const { return user; }
52 CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING &);
57 //-----------------------------------------------------------------------------
58 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
60 explicit ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
61 void Notify(const USER_PTR & 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 NOTIFIER_BASE<USER_PTR> {
72 explicit DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
73 void Notify(const USER_PTR & 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 MODULE_SETTINGS & s);
87 int GetPingDelay() const { return pingDelay; }
90 mutable std::string errorStr;
92 //-----------------------------------------------------------------------------
93 class PING : public PLUGIN {
94 friend class CHG_CURRIP_NOTIFIER_PING;
95 friend class CHG_IPS_NOTIFIER_PING;
100 void SetUsers(USERS * u) { users = u; }
101 void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
106 int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
109 const std::string & GetStrError() const { return errorStr; }
110 std::string GetVersion() const { return "Pinger v.1.01"; }
111 uint16_t GetStartPosition() const { return 10; }
112 uint16_t GetStopPosition() const { return 10; }
114 void AddUser(USER_PTR u);
115 void DelUser(USER_PTR u);
118 explicit PING(const PING & rvalue);
119 PING & operator=(const PING & rvalue);
122 void SetUserNotifiers(USER_PTR u);
123 void UnSetUserNotifiers(USER_PTR u);
124 static void * Run(void * d);
126 mutable std::string errorStr;
127 PING_SETTINGS pingSettings;
128 MODULE_SETTINGS settings;
130 std::list<USER_PTR> usersList;
133 pthread_mutex_t mutex;
136 mutable STG_PINGER pinger;
138 std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
139 std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
141 ADD_USER_NONIFIER_PING onAddUserNotifier;
142 DEL_USER_NONIFIER_PING onDelUserNotifier;
144 PLUGIN_LOGGER logger;
146 //-----------------------------------------------------------------------------