]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/ping/ping.h
Проведен легкий рефакторинг плагина пингера. Инициализация нотификаторов
[stg.git] / projects / stargazer / plugins / other / ping / ping.h
1  /*
2  $Revision: 1.16 $
3  $Date: 2009/06/23 11:32:28 $
4  $Author: faust $
5  */
6
7 #ifndef PING_H
8 #define PING_H
9
10 #include <pthread.h>
11
12 #include <string>
13
14 #include "os_int.h"
15 #include "base_plugin.h"
16 #include "notifer.h"
17 #include "user_ips.h"
18 #include "pinger.h"
19 #include "../../../users.h"
20
21 using namespace std;
22
23 extern "C" BASE_PLUGIN * GetPlugin();
24
25 class PING;
26 //-----------------------------------------------------------------------------*/
27 class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t>
28 {
29 public:
30     CHG_CURRIP_NOTIFIER_PING(const PING & p, user_iter u) : user(u), ping(p) {}
31     void Notify(const uint32_t & oldIP, const uint32_t & newIP);
32     user_iter GetUser() { return user; }
33
34 private:
35     user_iter user;
36     const PING & ping;
37 };
38 //-----------------------------------------------------------------------------
39 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS>
40 {
41 public:
42     CHG_IPS_NOTIFIER_PING(const PING & p, user_iter u) : user(u), ping(p) {}
43     void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
44     user_iter GetUser() { return user; }
45
46 private:
47     user_iter user;
48     const PING & ping;
49 };
50 //-----------------------------------------------------------------------------
51 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
52 {
53 public:
54     ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
55     virtual ~ADD_USER_NONIFIER_PING() {}
56     void Notify(const user_iter & user);
57
58 private:
59     PING & ping;
60 };
61 //-----------------------------------------------------------------------------
62 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
63 {
64 public:
65     DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
66     virtual ~DEL_USER_NONIFIER_PING() {}
67     void Notify(const user_iter & user);
68
69 private:
70     PING & ping;
71 };
72 //-----------------------------------------------------------------------------
73 class PING_SETTINGS
74 {
75 public:
76     PING_SETTINGS();
77     virtual ~PING_SETTINGS() {}
78     const string& GetStrError() const { return errorStr; }
79     int ParseSettings(const MODULE_SETTINGS & s);
80     int GetPingDelay() { return pingDelay; }
81 private:
82     int ParseIntInRange(const string & str, int min, int max, int * val);
83
84     int pingDelay;
85     mutable string errorStr;
86 };
87 //-----------------------------------------------------------------------------
88 class PING: public BASE_PLUGIN
89 {
90 friend class CHG_CURRIP_NOTIFIER_PING;
91 friend class CHG_IPS_NOTIFIER_PING;
92 public:
93     PING();
94     virtual ~PING();
95
96     void SetUsers(USERS * u);
97     void SetTariffs(TARIFFS *) {}
98     void SetAdmins(ADMINS *) {}
99     void SetTraffcounter(TRAFFCOUNTER *) {}
100     void SetStore(BASE_STORE *) {}
101     void SetStgSettings(const SETTINGS *) {}
102     void SetSettings(const MODULE_SETTINGS & s);
103     int ParseSettings();
104
105     int Start();
106     int Stop();
107     int Reload() { return 0; }
108     bool IsRunning();
109
110     const string & GetStrError() const;
111     const string GetVersion() const;
112     uint16_t GetStartPosition() const;
113     uint16_t GetStopPosition() const;
114
115     void AddUser(user_iter u);
116     void DelUser(user_iter u);
117
118 private:
119     void GetUsers();
120     void SetUserNotifiers(user_iter u);
121     void UnSetUserNotifiers(user_iter u);
122     static void * Run(void * d);
123
124     mutable string errorStr;
125     PING_SETTINGS pingSettings;
126     MODULE_SETTINGS settings;
127     USERS * users;
128     list<user_iter> usersList;
129
130     /*
131     ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ ÐÉÎÇÏ×ÁÎÉÑ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
132     ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
133     - currIP
134     - ips
135     */
136     pthread_t thread;
137     pthread_mutex_t mutex;
138     bool nonstop;
139     bool isRunning;
140     mutable STG_PINGER pinger;
141
142     list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
143     list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
144
145     ADD_USER_NONIFIER_PING onAddUserNotifier;
146     DEL_USER_NONIFIER_PING onDelUserNotifier;
147 };
148 //-----------------------------------------------------------------------------
149
150 #endif