]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/ping/ping.h
More clear plugin API
[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 SetSettings(const MODULE_SETTINGS & s);
92     int ParseSettings();
93
94     int Start();
95     int Stop();
96     int Reload() { return 0; }
97     bool IsRunning();
98
99     const std::string & GetStrError() const;
100     const std::string GetVersion() const;
101     uint16_t GetStartPosition() const;
102     uint16_t GetStopPosition() const;
103
104     void AddUser(USER_PTR u);
105     void DelUser(USER_PTR u);
106
107 private:
108     void GetUsers();
109     void SetUserNotifiers(USER_PTR u);
110     void UnSetUserNotifiers(USER_PTR u);
111     static void * Run(void * d);
112
113     mutable std::string errorStr;
114     PING_SETTINGS pingSettings;
115     MODULE_SETTINGS settings;
116     USERS * users;
117     std::list<USER_PTR> usersList;
118
119     /*
120     ÍÙ ÄÏÌÖÎÙ ÐÅÒÅÐÒÏ×ÅÒÉÔØ ×ÏÚÍÏÖÎÏÓÔØ ÐÉÎÇÏ×ÁÎÉÑ ÀÚÅÒÁ ÐÒÉ ÉÚÍÅÎÅÎÉÉ
121     ÓÌÅÄÕÀÝÉÈ ÅÇÏ ÐÁÒÁÍÅÔÒÏ×:
122     - currIP
123     - ips
124     */
125     pthread_t thread;
126     pthread_mutex_t mutex;
127     bool nonstop;
128     bool isRunning;
129     mutable STG_PINGER pinger;
130
131     std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
132     std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
133
134     ADD_USER_NONIFIER_PING onAddUserNotifier;
135     DEL_USER_NONIFIER_PING onDelUserNotifier;
136 };
137 //-----------------------------------------------------------------------------
138
139 #endif