]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/ping/ping.h
Code deduplication
[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 "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"
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 pingDelay;
80     mutable std::string errorStr;
81 };
82 //-----------------------------------------------------------------------------
83 class PING : public PLUGIN {
84 friend class CHG_CURRIP_NOTIFIER_PING;
85 friend class CHG_IPS_NOTIFIER_PING;
86 public:
87     PING();
88     virtual ~PING();
89
90     void SetUsers(USERS * u);
91     void SetTariffs(TARIFFS *) {}
92     void SetAdmins(ADMINS *) {}
93     void SetTraffcounter(TRAFFCOUNTER *) {}
94     void SetStore(STORE *) {}
95     void SetStgSettings(const SETTINGS *) {}
96     void SetSettings(const MODULE_SETTINGS & s);
97     int ParseSettings();
98
99     int Start();
100     int Stop();
101     int Reload() { return 0; }
102     bool IsRunning();
103
104     const std::string & GetStrError() const;
105     const std::string GetVersion() const;
106     uint16_t GetStartPosition() const;
107     uint16_t GetStopPosition() const;
108
109     void AddUser(USER_PTR u);
110     void DelUser(USER_PTR u);
111
112 private:
113     void GetUsers();
114     void SetUserNotifiers(USER_PTR u);
115     void UnSetUserNotifiers(USER_PTR u);
116     static void * Run(void * d);
117
118     mutable std::string errorStr;
119     PING_SETTINGS pingSettings;
120     MODULE_SETTINGS settings;
121     USERS * users;
122     std::list<USER_PTR> usersList;
123
124     /*
125     ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ ÐÉÎÇÏ×ÁÎÉÑ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
126     ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
127     - currIP
128     - ips
129     */
130     pthread_t thread;
131     pthread_mutex_t mutex;
132     bool nonstop;
133     bool isRunning;
134     mutable STG_PINGER pinger;
135
136     std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
137     std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
138
139     ADD_USER_NONIFIER_PING onAddUserNotifier;
140     DEL_USER_NONIFIER_PING onDelUserNotifier;
141 };
142 //-----------------------------------------------------------------------------
143
144 #endif