7 #include "stg/tariffs.h"
8 #include "stg/admins.h"
9 #include "stg/services.h"
10 #include "stg/corporations.h"
11 #include "stg/traffcounter.h"
12 #include "stg/user_property.h"
14 #include "stg/ObjectSyntax.h"
22 virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
24 virtual std::string ToString() const = 0;
28 typedef std::map<OID, Sensor *> Sensors;
30 class TotalUsersSensor : public Sensor {
32 TotalUsersSensor(const USERS & u) : users(u) {}
33 virtual ~TotalUsersSensor() {}
35 bool GetValue(ObjectSyntax_t * objectSyntax) const
37 ValueToOS(users.Count(), objectSyntax);
42 std::string ToString() const
43 { std::string res; x2str(users.Count(), res); return res; }
50 class UsersSensor : public Sensor {
52 UsersSensor(USERS & u) : users(u) {}
53 virtual ~UsersSensor() {}
55 bool GetValue(ObjectSyntax_t * objectSyntax) const;
57 std::string ToString() const;
63 virtual bool UserPredicate(USER_PTR userPtr) const = 0;
66 class ConnectedUsersSensor : public UsersSensor {
68 ConnectedUsersSensor(USERS & u) : UsersSensor(u) {}
69 virtual ~ConnectedUsersSensor() {}
72 bool UserPredicate(USER_PTR userPtr) const
73 { return userPtr->GetConnected(); }
76 class AuthorizedUsersSensor : public UsersSensor {
78 AuthorizedUsersSensor(USERS & u) : UsersSensor(u) {}
79 virtual ~AuthorizedUsersSensor() {}
82 bool UserPredicate(USER_PTR userPtr) const
83 { return userPtr->GetAuthorized(); }
86 class AlwaysOnlineUsersSensor : public UsersSensor {
88 AlwaysOnlineUsersSensor(USERS & u) : UsersSensor(u) {}
89 virtual ~AlwaysOnlineUsersSensor() {}
92 bool UserPredicate(USER_PTR userPtr) const
93 { return userPtr->GetProperty().alwaysOnline; }
96 class NoCashUsersSensor : public UsersSensor {
98 NoCashUsersSensor(USERS & u) : UsersSensor(u) {}
99 virtual ~NoCashUsersSensor() {}
102 bool UserPredicate(USER_PTR userPtr) const
103 { return userPtr->GetProperty().cash < 0; }
106 class DisabledDetailStatsUsersSensor : public UsersSensor {
108 DisabledDetailStatsUsersSensor(USERS & u) : UsersSensor(u) {}
109 virtual ~DisabledDetailStatsUsersSensor() {}
112 bool UserPredicate(USER_PTR userPtr) const
113 { return userPtr->GetProperty().disabledDetailStat; }
116 class DisabledUsersSensor : public UsersSensor {
118 DisabledUsersSensor(USERS & u) : UsersSensor(u) {}
119 virtual ~DisabledUsersSensor() {}
122 bool UserPredicate(USER_PTR userPtr) const
123 { return userPtr->GetProperty().disabled; }
126 class PassiveUsersSensor : public UsersSensor {
128 PassiveUsersSensor(USERS & u) : UsersSensor(u) {}
129 virtual ~PassiveUsersSensor() {}
132 bool UserPredicate(USER_PTR userPtr) const
133 { return userPtr->GetProperty().passive; }
136 class CreditUsersSensor : public UsersSensor {
138 CreditUsersSensor(USERS & u) : UsersSensor(u) {}
139 virtual ~CreditUsersSensor() {}
142 bool UserPredicate(USER_PTR userPtr) const
143 { return userPtr->GetProperty().credit > 0; }
146 class FreeMbUsersSensor : public UsersSensor {
148 FreeMbUsersSensor(USERS & u) : UsersSensor(u) {}
149 virtual ~FreeMbUsersSensor() {}
152 bool UserPredicate(USER_PTR userPtr) const
153 { return userPtr->GetProperty().freeMb > 0; }
156 class TariffChangeUsersSensor : public UsersSensor {
158 TariffChangeUsersSensor(USERS & u) : UsersSensor(u) {}
159 virtual ~TariffChangeUsersSensor() {}
162 bool UserPredicate(USER_PTR userPtr) const
163 { return !userPtr->GetProperty().nextTariff.ConstData().empty(); }
166 class ActiveUsersSensor : public UsersSensor {
168 ActiveUsersSensor(USERS & u) : UsersSensor(u) {}
169 virtual ~ActiveUsersSensor() {}
172 bool UserPredicate(USER_PTR userPtr) const;
175 class TotalTariffsSensor : public Sensor {
177 TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
178 virtual ~TotalTariffsSensor() {}
180 bool GetValue(ObjectSyntax_t * objectSyntax) const
182 ValueToOS(tariffs.Count(), objectSyntax);
187 std::string ToString() const
188 { std::string res; x2str(tariffs.Count(), res); return res; }
192 const TARIFFS & tariffs;
195 class TotalAdminsSensor : public Sensor {
197 TotalAdminsSensor(const ADMINS & a) : admins(a) {}
198 virtual ~TotalAdminsSensor() {}
200 bool GetValue(ObjectSyntax_t * objectSyntax) const
202 ValueToOS(admins.Count(), objectSyntax);
207 std::string ToString() const
208 { std::string res; x2str(admins.Count(), res); return res; }
212 const ADMINS & admins;
215 class TotalServicesSensor : public Sensor {
217 TotalServicesSensor(const SERVICES & s) : services(s) {}
218 virtual ~TotalServicesSensor() {}
220 bool GetValue(ObjectSyntax_t * objectSyntax) const
222 ValueToOS(services.Count(), objectSyntax);
227 std::string ToString() const
228 { std::string res; x2str(services.Count(), res); return res; }
232 const SERVICES & services;
235 class TotalCorporationsSensor : public Sensor {
237 TotalCorporationsSensor(const CORPORATIONS & c) : corporations(c) {}
238 virtual ~TotalCorporationsSensor() {}
240 bool GetValue(ObjectSyntax_t * objectSyntax) const
242 ValueToOS(corporations.Count(), objectSyntax);
247 std::string ToString() const
248 { std::string res; x2str(corporations.Count(), res); return res; }
252 const CORPORATIONS & corporations;
255 class TotalRulesSensor : public Sensor {
257 TotalRulesSensor(const TRAFFCOUNTER & t) : traffcounter(t) {}
258 virtual ~TotalRulesSensor() {}
260 bool GetValue(ObjectSyntax_t * objectSyntax) const
262 ValueToOS(traffcounter.RulesCount(), objectSyntax);
267 std::string ToString() const
268 { std::string res; x2str(traffcounter.RulesCount(), res); return res; }
272 const TRAFFCOUNTER & traffcounter;
275 template <typename T>
276 class ConstSensor : public Sensor {
278 ConstSensor(const T & v) : value(v) {}
279 virtual ~ConstSensor() {}
281 bool GetValue(ObjectSyntax * objectSyntax) const
282 { return ValueToOS(value, objectSyntax); }
285 std::string ToString() const
286 { std::string res; x2str(value, res); return res; }
296 std::string ConstSensor<std::string>::ToString() const