7 #include "stg/tariffs.h"
8 #include "stg/admins.h"
9 #include "stg/services.h"
10 #include "stg/corporations.h"
11 #include "stg/user_property.h"
13 #include "stg/ObjectSyntax.h"
20 virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
22 virtual std::string ToString() const = 0;
26 typedef std::map<OID, Sensor *> Sensors;
28 class TotalUsersSensor : public Sensor {
30 TotalUsersSensor(const USERS & u) : users(u) {}
31 virtual ~TotalUsersSensor() {}
33 bool GetValue(ObjectSyntax_t * objectSyntax) const
35 ValueToOS(users.Count(), objectSyntax);
40 std::string ToString() const
41 { std::string res; x2str(users.Count(), res); return res; }
48 class UsersSensor : public Sensor {
50 UsersSensor(USERS & u) : users(u) {}
51 virtual ~UsersSensor() {}
53 bool GetValue(ObjectSyntax_t * objectSyntax) const;
55 std::string ToString() const;
61 virtual bool UserPredicate(USER_PTR userPtr) const = 0;
64 class ConnectedUsersSensor : public UsersSensor {
66 ConnectedUsersSensor(USERS & u) : UsersSensor(u) {}
67 virtual ~ConnectedUsersSensor() {}
70 bool UserPredicate(USER_PTR userPtr) const
71 { return userPtr->GetConnected(); }
74 class AuthorizedUsersSensor : public UsersSensor {
76 AuthorizedUsersSensor(USERS & u) : UsersSensor(u) {}
77 virtual ~AuthorizedUsersSensor() {}
80 bool UserPredicate(USER_PTR userPtr) const
81 { return userPtr->GetAuthorized(); }
84 class AlwaysOnlineUsersSensor : public UsersSensor {
86 AlwaysOnlineUsersSensor(USERS & u) : UsersSensor(u) {}
87 virtual ~AlwaysOnlineUsersSensor() {}
90 bool UserPredicate(USER_PTR userPtr) const
91 { return userPtr->GetProperty().alwaysOnline; }
94 class NoCashUsersSensor : public UsersSensor {
96 NoCashUsersSensor(USERS & u) : UsersSensor(u) {}
97 virtual ~NoCashUsersSensor() {}
100 bool UserPredicate(USER_PTR userPtr) const
101 { return userPtr->GetProperty().cash < 0; }
104 class DisabledDetailStatsUsersSensor : public UsersSensor {
106 DisabledDetailStatsUsersSensor(USERS & u) : UsersSensor(u) {}
107 virtual ~DisabledDetailStatsUsersSensor() {}
110 bool UserPredicate(USER_PTR userPtr) const
111 { return userPtr->GetProperty().disabledDetailStat; }
114 class DisabledUsersSensor : public UsersSensor {
116 DisabledUsersSensor(USERS & u) : UsersSensor(u) {}
117 virtual ~DisabledUsersSensor() {}
120 bool UserPredicate(USER_PTR userPtr) const
121 { return userPtr->GetProperty().disabled; }
124 class PassiveUsersSensor : public UsersSensor {
126 PassiveUsersSensor(USERS & u) : UsersSensor(u) {}
127 virtual ~PassiveUsersSensor() {}
130 bool UserPredicate(USER_PTR userPtr) const
131 { return userPtr->GetProperty().passive; }
134 class CreditUsersSensor : public UsersSensor {
136 CreditUsersSensor(USERS & u) : UsersSensor(u) {}
137 virtual ~CreditUsersSensor() {}
140 bool UserPredicate(USER_PTR userPtr) const
141 { return userPtr->GetProperty().credit > 0; }
144 class FreeMbUsersSensor : public UsersSensor {
146 FreeMbUsersSensor(USERS & u) : UsersSensor(u) {}
147 virtual ~FreeMbUsersSensor() {}
150 bool UserPredicate(USER_PTR userPtr) const
151 { return userPtr->GetProperty().freeMb > 0; }
154 class TariffChangeUsersSensor : public UsersSensor {
156 TariffChangeUsersSensor(USERS & u) : UsersSensor(u) {}
157 virtual ~TariffChangeUsersSensor() {}
160 bool UserPredicate(USER_PTR userPtr) const
161 { return userPtr->GetProperty().nextTariff.ConstData().empty(); }
164 class TotalTariffsSensor : public Sensor {
166 TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
167 virtual ~TotalTariffsSensor() {}
169 bool GetValue(ObjectSyntax_t * objectSyntax) const
171 ValueToOS(tariffs.Count(), objectSyntax);
176 std::string ToString() const
177 { std::string res; x2str(tariffs.Count(), res); return res; }
181 const TARIFFS & tariffs;
184 class TotalAdminsSensor : public Sensor {
186 TotalAdminsSensor(const ADMINS & a) : admins(a) {}
187 virtual ~TotalAdminsSensor() {}
189 bool GetValue(ObjectSyntax_t * objectSyntax) const
191 ValueToOS(admins.Count(), objectSyntax);
196 std::string ToString() const
197 { std::string res; x2str(admins.Count(), res); return res; }
201 const ADMINS & admins;
204 class TotalServicesSensor : public Sensor {
206 TotalServicesSensor(const SERVICES & s) : services(s) {}
207 virtual ~TotalServicesSensor() {}
209 bool GetValue(ObjectSyntax_t * objectSyntax) const
211 ValueToOS(services.Count(), objectSyntax);
216 std::string ToString() const
217 { std::string res; x2str(services.Count(), res); return res; }
221 const SERVICES & services;
224 class TotalCorporationsSensor : public Sensor {
226 TotalCorporationsSensor(const CORPORATIONS & c) : corporations(c) {}
227 virtual ~TotalCorporationsSensor() {}
229 bool GetValue(ObjectSyntax_t * objectSyntax) const
231 ValueToOS(corporations.Count(), objectSyntax);
236 std::string ToString() const
237 { std::string res; x2str(corporations.Count(), res); return res; }
241 const CORPORATIONS & corporations;
244 template <typename T>
245 class ConstSensor : public Sensor {
247 ConstSensor(const T & v) : value(v) {}
248 virtual ~ConstSensor() {}
250 bool GetValue(ObjectSyntax * objectSyntax) const
251 { return ValueToOS(value, objectSyntax); }
254 std::string ToString() const
255 { std::string res; x2str(value, res); return res; }
264 std::string ConstSensor<std::string>::ToString() const