]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/ping/ping.h
Remove redundand ctors.
[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 "stg/os_int.h"
11 #include "stg/plugin.h"
12 #include "stg/module_settings.h"
13 #include "stg/notifer.h"
14 #include "stg/user_ips.h"
15 #include "stg/pinger.h"
16 #include "stg/users.h"
17 #include "stg/logger.h"
18
19 #include <string>
20 #include <list>
21
22 #include <pthread.h>
23
24 extern "C" PLUGIN * GetPlugin();
25
26 class PING;
27 class USER;
28 class SETTINGS;
29 //-----------------------------------------------------------------------------*/
30 class CHG_CURRIP_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<uint32_t> {
31 public:
32     CHG_CURRIP_NOTIFIER_PING(const PING & p, USER_PTR u)
33         : user(u), ping(p) {}
34     void Notify(const uint32_t & oldIP, const uint32_t & newIP);
35     USER_PTR GetUser() const { return user; }
36
37 private:
38     CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING &);
39
40     USER_PTR user;
41     const PING & ping;
42 };
43 //-----------------------------------------------------------------------------
44 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
45 public:
46     CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u)
47         : user(u), ping(p) {}
48     void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
49     USER_PTR GetUser() const { return user; }
50
51 private:
52     CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING &);
53
54     USER_PTR user;
55     const PING & ping;
56 };
57 //-----------------------------------------------------------------------------
58 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
59 public:
60     explicit ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
61     void Notify(const USER_PTR & user);
62
63 private:
64     ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING &);
65     ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING &);
66
67     PING & ping;
68 };
69 //-----------------------------------------------------------------------------
70 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
71 public:
72     explicit DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
73     void Notify(const USER_PTR & user);
74
75 private:
76     DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING &);
77     DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING &);
78
79     PING & ping;
80 };
81 //-----------------------------------------------------------------------------
82 class PING_SETTINGS {
83 public:
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; }
88 private:
89     int pingDelay;
90     mutable std::string errorStr;
91 };
92 //-----------------------------------------------------------------------------
93 class PING : public PLUGIN {
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) { users = u; }
101     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
102     int ParseSettings();
103
104     int Start();
105     int Stop();
106     int Reload(const MODULE_SETTINGS & /*ms*/) { return 0; }
107     bool IsRunning();
108
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; }
113
114     void AddUser(USER_PTR u);
115     void DelUser(USER_PTR u);
116
117 private:
118     explicit PING(const PING & rvalue);
119     PING & operator=(const PING & rvalue);
120
121     void GetUsers();
122     void SetUserNotifiers(USER_PTR u);
123     void UnSetUserNotifiers(USER_PTR u);
124     static void * Run(void * d);
125
126     mutable std::string errorStr;
127     PING_SETTINGS pingSettings;
128     MODULE_SETTINGS settings;
129     USERS * users;
130     std::list<USER_PTR> usersList;
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     PLUGIN_LOGGER logger;
145 };
146 //-----------------------------------------------------------------------------
147
148 #endif