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