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