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