]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/ping/ping.h
Hide or add proper copy ctor and assignement operator, initialize
[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     CHG_CURRIP_NOTIFIER_PING(const CHG_CURRIP_NOTIFIER_PING & rvalue)
33         : user(rvalue.user), ping(rvalue.ping)
34     {}
35     void Notify(const uint32_t & oldIP, const uint32_t & newIP);
36     USER_PTR GetUser() const { return user; }
37
38 private:
39     CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING & rvalue);
40
41     USER_PTR user;
42     const PING & ping;
43 };
44 //-----------------------------------------------------------------------------
45 class CHG_IPS_NOTIFIER_PING: public PROPERTY_NOTIFIER_BASE<USER_IPS> {
46 public:
47     CHG_IPS_NOTIFIER_PING(const PING & p, USER_PTR u) : user(u), ping(p) {}
48     CHG_IPS_NOTIFIER_PING(const CHG_IPS_NOTIFIER_PING & rvalue)
49         : user(rvalue.user), ping(rvalue.ping)
50     {}
51     void Notify(const USER_IPS & oldIPS, const USER_IPS & newIPS);
52     USER_PTR GetUser() const { return user; }
53
54 private:
55     CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING & rvalue);
56
57     USER_PTR user;
58     const PING & ping;
59 };
60 //-----------------------------------------------------------------------------
61 class ADD_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
62 public:
63     ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
64     virtual ~ADD_USER_NONIFIER_PING() {}
65     void Notify(const USER_PTR & user);
66
67 private:
68     ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING & rvalue);
69     ADD_USER_NONIFIER_PING & operator=(const ADD_USER_NONIFIER_PING & rvalue);
70
71     PING & ping;
72 };
73 //-----------------------------------------------------------------------------
74 class DEL_USER_NONIFIER_PING: public NOTIFIER_BASE<USER_PTR> {
75 public:
76     DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
77     virtual ~DEL_USER_NONIFIER_PING() {}
78     void Notify(const USER_PTR & user);
79
80 private:
81     DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING & rvalue);
82     DEL_USER_NONIFIER_PING & operator=(const DEL_USER_NONIFIER_PING & rvalue);
83
84     PING & ping;
85 };
86 //-----------------------------------------------------------------------------
87 class PING_SETTINGS {
88 public:
89     PING_SETTINGS() : pingDelay(0), errorStr() {}
90     virtual ~PING_SETTINGS() {}
91     const std::string & GetStrError() const { return errorStr; }
92     int ParseSettings(const MODULE_SETTINGS & s);
93     int GetPingDelay() const { return pingDelay; }
94 private:
95     int pingDelay;
96     mutable std::string errorStr;
97 };
98 //-----------------------------------------------------------------------------
99 class PING : public PLUGIN {
100 friend class CHG_CURRIP_NOTIFIER_PING;
101 friend class CHG_IPS_NOTIFIER_PING;
102 public:
103     PING();
104     virtual ~PING();
105
106     void SetUsers(USERS * u) { users = u; }
107     void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
108     int ParseSettings();
109
110     int Start();
111     int Stop();
112     int Reload() { return 0; }
113     bool IsRunning();
114
115     const std::string & GetStrError() const { return errorStr; }
116     const std::string GetVersion() const { return "Pinger v.1.01"; }
117     uint16_t GetStartPosition() const { return 100; }
118     uint16_t GetStopPosition() const { return 100; }
119
120     void AddUser(USER_PTR u);
121     void DelUser(USER_PTR u);
122
123 private:
124     PING(const PING & rvalue);
125     PING & operator=(const PING & rvalue);
126
127     void GetUsers();
128     void SetUserNotifiers(USER_PTR u);
129     void UnSetUserNotifiers(USER_PTR u);
130     static void * Run(void * d);
131
132     mutable std::string errorStr;
133     PING_SETTINGS pingSettings;
134     MODULE_SETTINGS settings;
135     USERS * users;
136     std::list<USER_PTR> usersList;
137
138     pthread_t thread;
139     pthread_mutex_t mutex;
140     bool nonstop;
141     bool isRunning;
142     mutable STG_PINGER pinger;
143
144     std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
145     std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
146
147     ADD_USER_NONIFIER_PING onAddUserNotifier;
148     DEL_USER_NONIFIER_PING onDelUserNotifier;
149 };
150 //-----------------------------------------------------------------------------
151
152 #endif