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 TotalTariffsSensor : public Sensor {
168 TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
169 virtual ~TotalTariffsSensor() {}
171 bool GetValue(ObjectSyntax_t * objectSyntax) const
173 ValueToOS(tariffs.Count(), objectSyntax);
178 std::string ToString() const
179 { std::string res; x2str(tariffs.Count(), res); return res; }
183 const TARIFFS & tariffs;
186 class TotalAdminsSensor : public Sensor {
188 TotalAdminsSensor(const ADMINS & a) : admins(a) {}
189 virtual ~TotalAdminsSensor() {}
191 bool GetValue(ObjectSyntax_t * objectSyntax) const
193 ValueToOS(admins.Count(), objectSyntax);
198 std::string ToString() const
199 { std::string res; x2str(admins.Count(), res); return res; }
203 const ADMINS & admins;
206 class TotalServicesSensor : public Sensor {
208 TotalServicesSensor(const SERVICES & s) : services(s) {}
209 virtual ~TotalServicesSensor() {}
211 bool GetValue(ObjectSyntax_t * objectSyntax) const
213 ValueToOS(services.Count(), objectSyntax);
218 std::string ToString() const
219 { std::string res; x2str(services.Count(), res); return res; }
223 const SERVICES & services;
226 class TotalCorporationsSensor : public Sensor {
228 TotalCorporationsSensor(const CORPORATIONS & c) : corporations(c) {}
229 virtual ~TotalCorporationsSensor() {}
231 bool GetValue(ObjectSyntax_t * objectSyntax) const
233 ValueToOS(corporations.Count(), objectSyntax);
238 std::string ToString() const
239 { std::string res; x2str(corporations.Count(), res); return res; }
243 const CORPORATIONS & corporations;
246 class TotalRulesSensor : public Sensor {
248 TotalRulesSensor(const TRAFFCOUNTER & t) : traffcounter(t) {}
249 virtual ~TotalRulesSensor() {}
251 bool GetValue(ObjectSyntax_t * objectSyntax) const
253 ValueToOS(traffcounter.RulesCount(), objectSyntax);
258 std::string ToString() const
259 { std::string res; x2str(traffcounter.RulesCount(), res); return res; }
263 const TRAFFCOUNTER & traffcounter;
266 template <typename T>
267 class ConstSensor : public Sensor {
269 ConstSensor(const T & v) : value(v) {}
270 virtual ~ConstSensor() {}
272 bool GetValue(ObjectSyntax * objectSyntax) const
273 { return ValueToOS(value, objectSyntax); }
276 std::string ToString() const
277 { std::string res; x2str(value, res); return res; }
287 std::string ConstSensor<std::string>::ToString() const