]> 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 <string>
11 #include <pthread.h>
12
13 #include "os_int.h"
14 #include "base_plugin.h"
15 #include "notifer.h"
16 #include "user_ips.h"
17 #include "pinger.h"
18 #include "../../../users.h"
19
20 using namespace std;
21
22 extern "C" BASE_PLUGIN * GetPlugin();
23
24 class PING;
25 //-----------------------------------------------------------------------------*/
26 class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t>
27 {
28 public:
29     void        Notify(const uint32_t & oldIP, const uint32_t & newIP);
30     void        SetUser(user_iter u) { user = u; }
31     user_iter   GetUser() {return user; }
32     void        SetPinger(const PING * p) { ping = p; }
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     void        Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
43     void        SetUser(user_iter u) { user = u; }
44     user_iter   GetUser() {return user; }
45     void        SetPinger(const PING * p) { ping = p; }
46
47 private:
48     user_iter   user;
49     const PING * ping;
50 };
51 //-----------------------------------------------------------------------------
52 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
53 {
54 public:
55     ADD_USER_NONIFIER_PING(){};
56     virtual ~ADD_USER_NONIFIER_PING(){};
57
58     void SetPinger(PING * p) { ping = p; }
59     void Notify(const user_iter & user);
60
61 private:
62     PING * ping;
63 };
64 //-----------------------------------------------------------------------------
65 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<user_iter>
66 {
67 public:
68     DEL_USER_NONIFIER_PING(){};
69     virtual ~DEL_USER_NONIFIER_PING(){};
70
71     void SetPinger(PING * p) { ping = p; }
72     void Notify(const user_iter & user);
73
74 private:
75     PING * ping;
76 };
77 //-----------------------------------------------------------------------------
78 class PING_SETTINGS
79 {
80 public:
81                     PING_SETTINGS();
82     virtual         ~PING_SETTINGS(){};
83     const string&   GetStrError() const { return errorStr; }
84     int             ParseSettings(const MODULE_SETTINGS & s);
85     int             GetPingDelay(){ return pingDelay; };
86 private:
87     int             ParseIntInRange(const string & str, int min, int max, int * val);
88     int             pingDelay;
89     mutable string  errorStr;
90 };
91 //-----------------------------------------------------------------------------
92 class PING: public BASE_PLUGIN
93 {
94 friend class CHG_CURRIP_NOTIFIER_PING;
95 friend class CHG_IPS_NOTIFIER_PING;
96 public:
97     PING();
98     virtual ~PING();
99
100     void                SetUsers(USERS * u);
101     void                SetTariffs(TARIFFS *){};
102     void                SetAdmins(ADMINS *){};
103     void                SetTraffcounter(TRAFFCOUNTER *){};
104     void                SetStore(BASE_STORE *){};
105     void                SetStgSettings(const SETTINGS *){};
106     void                SetSettings(const MODULE_SETTINGS & s);
107     int                 ParseSettings();
108
109     int                 Start();
110     int                 Stop();
111     int                 Reload() { return 0; };
112     bool                IsRunning();
113
114     const string      & GetStrError() const;
115     const string        GetVersion() const;
116     uint16_t            GetStartPosition() const;
117     uint16_t            GetStopPosition() const;
118
119     void                AddUser(user_iter u);
120     void                DelUser(user_iter u);
121
122 private:
123     void                GetUsers();
124     void                SetUserNotifiers(user_iter u);
125     void                UnSetUserNotifiers(user_iter u);
126     static void *       Run(void * d);
127     mutable string      errorStr;
128     PING_SETTINGS       pingSettings;
129     MODULE_SETTINGS     settings;
130     USERS             * users;
131     list<user_iter>     usersList;
132
133     /*
134     ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ ÐÉÎÇÏ×ÁÎÉÑ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
135     ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
136     - currIP
137     - ips
138     */
139     pthread_t           thread;
140     pthread_mutex_t     mutex;
141     bool                nonstop;
142     bool                isRunning;
143     mutable STG_PINGER  pinger;
144
145     list<CHG_CURRIP_NOTIFIER_PING>   ChgCurrIPNotifierList;
146     list<CHG_IPS_NOTIFIER_PING>      ChgIPNotifierList;
147
148     ADD_USER_NONIFIER_PING      onAddUserNotifier;
149     DEL_USER_NONIFIER_PING      onDelUserNotifier;
150 };
151 //-----------------------------------------------------------------------------
152
153 #endif
154
155