]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/sensors.h
Link against smux library instead of plain object files
[stg.git] / projects / stargazer / plugins / other / smux / sensors.h
1 #ifndef __SENSORS_H__
2 #define __SENSORS_H__
3
4 #include <map>
5
6 #include "stg/users.h"
7 #include "stg/tariffs.h"
8 #include "stg/user_property.h"
9
10 #include "stg/ObjectSyntax.h"
11
12 #include "value2os.h"
13 #include "types.h"
14
15 class Sensor {
16     public:
17         virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
18 };
19
20 typedef std::map<OID, Sensor *> Sensors;
21
22 class TableSensor {
23     public:
24         virtual bool appendTable(Sensors & sensors);
25 };
26
27 class TotalUsersSensor : public Sensor {
28     public:
29         TotalUsersSensor(const USERS & u) : users(u) {}
30         virtual ~TotalUsersSensor() {}
31
32         bool GetValue(ObjectSyntax_t * objectSyntax) const
33         {
34         ValueToOS(users.GetUserNum(), objectSyntax);
35         return true;
36         }
37
38     private:
39         const USERS & users;
40 };
41
42 class UsersSensor : public Sensor {
43     public:
44         UsersSensor(USERS & u) : users(u) {}
45         virtual ~UsersSensor() {};
46
47         bool GetValue(ObjectSyntax_t * objectSyntax) const;
48
49     private:
50         USERS & users;
51
52         virtual bool UserPredicate(USER_PTR userPtr) const = 0;
53 };
54
55 class ConnectedUsersSensor : public UsersSensor {
56     public:
57         ConnectedUsersSensor(USERS & u) : UsersSensor(u) {}
58         virtual ~ConnectedUsersSensor() {}
59
60     private:
61         bool UserPredicate(USER_PTR userPtr) const
62         { return userPtr->GetConnected(); }
63 };
64
65 class AuthorizedUsersSensor : public UsersSensor {
66     public:
67         AuthorizedUsersSensor(USERS & u) : UsersSensor(u) {}
68         virtual ~AuthorizedUsersSensor() {}
69
70     private:
71         bool UserPredicate(USER_PTR userPtr) const
72         { return userPtr->GetAuthorized(); }
73 };
74
75 class AlwaysOnlineUsersSensor : public UsersSensor {
76     public:
77         AlwaysOnlineUsersSensor(USERS & u) : UsersSensor(u) {}
78         virtual ~AlwaysOnlineUsersSensor() {}
79
80     private:
81         bool UserPredicate(USER_PTR userPtr) const
82         { return userPtr->GetProperty().alwaysOnline; }
83 };
84
85 class NoCashUsersSensor : public UsersSensor {
86     public:
87         NoCashUsersSensor(USERS & u) : UsersSensor(u) {}
88         virtual ~NoCashUsersSensor() {}
89
90     private:
91         bool UserPredicate(USER_PTR userPtr) const
92         { return userPtr->GetProperty().cash < 0; }
93 };
94
95 class DisabledDetailStatsUsersSensor : public UsersSensor {
96     public:
97         DisabledDetailStatsUsersSensor(USERS & u) : UsersSensor(u) {}
98         virtual ~DisabledDetailStatsUsersSensor() {}
99
100     private:
101         bool UserPredicate(USER_PTR userPtr) const
102         { return userPtr->GetProperty().disabledDetailStat; }
103 };
104
105 class DisabledUsersSensor : public UsersSensor {
106     public:
107         DisabledUsersSensor(USERS & u) : UsersSensor(u) {}
108         virtual ~DisabledUsersSensor() {}
109
110     private:
111         bool UserPredicate(USER_PTR userPtr) const
112         { return userPtr->GetProperty().disabled; }
113 };
114
115 class PassiveUsersSensor : public UsersSensor {
116     public:
117         PassiveUsersSensor(USERS & u) : UsersSensor(u) {}
118         virtual ~PassiveUsersSensor() {}
119
120     private:
121         bool UserPredicate(USER_PTR userPtr) const
122         { return userPtr->GetProperty().passive; }
123 };
124
125 class CreditUsersSensor : public UsersSensor {
126     public:
127         CreditUsersSensor(USERS & u) : UsersSensor(u) {}
128         virtual ~CreditUsersSensor() {}
129
130     private:
131         bool UserPredicate(USER_PTR userPtr) const
132         { return userPtr->GetProperty().credit > 0; }
133 };
134
135 class FreeMbUsersSensor : public UsersSensor {
136     public:
137         FreeMbUsersSensor(USERS & u) : UsersSensor(u) {}
138         virtual ~FreeMbUsersSensor() {}
139
140     private:
141         bool UserPredicate(USER_PTR userPtr) const
142         { return userPtr->GetProperty().freeMb > 0; }
143 };
144
145 class TariffChangeUsersSensor : public UsersSensor {
146     public:
147         TariffChangeUsersSensor(USERS & u) : UsersSensor(u) {}
148         virtual ~TariffChangeUsersSensor() {}
149
150     private:
151         bool UserPredicate(USER_PTR userPtr) const
152         { return userPtr->GetProperty().nextTariff.ConstData().empty(); }
153 };
154
155 class TotalTariffsSensor : public Sensor {
156     public:
157         TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
158         virtual ~TotalTariffsSensor() {}
159
160         bool GetValue(ObjectSyntax_t * objectSyntax) const
161         {
162         ValueToOS(tariffs.GetTariffsNum(), objectSyntax);
163         return true;
164         }
165
166     private:
167         const TARIFFS & tariffs;
168 };
169
170 template <typename T>
171 class ConstSensor : public Sensor {
172     public:
173         ConstSensor(const T & v) : value(v) {}
174         virtual ~ConstSensor() {}
175
176         bool GetValue(ObjectSyntax * objectSyntax) const
177         { return ValueToOS(value, objectSyntax); }
178
179     private:
180         T value;
181 };
182
183 #endif