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"
21 virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
23 virtual std::string ToString() const = 0;
27 typedef std::map<OID, Sensor *> Sensors;
29 class TotalUsersSensor : public Sensor {
31 TotalUsersSensor(const USERS & u) : users(u) {}
32 virtual ~TotalUsersSensor() {}
34 bool GetValue(ObjectSyntax_t * objectSyntax) const
36 ValueToOS(users.Count(), objectSyntax);
41 std::string ToString() const
42 { std::string res; x2str(users.Count(), res); return res; }
49 class UsersSensor : public Sensor {
51 UsersSensor(USERS & u) : users(u) {}
52 virtual ~UsersSensor() {}
54 bool GetValue(ObjectSyntax_t * objectSyntax) const;
56 std::string ToString() const;
62 virtual bool UserPredicate(USER_PTR userPtr) const = 0;
65 class ConnectedUsersSensor : public UsersSensor {
67 ConnectedUsersSensor(USERS & u) : UsersSensor(u) {}
68 virtual ~ConnectedUsersSensor() {}
71 bool UserPredicate(USER_PTR userPtr) const
72 { return userPtr->GetConnected(); }
75 class AuthorizedUsersSensor : public UsersSensor {
77 AuthorizedUsersSensor(USERS & u) : UsersSensor(u) {}
78 virtual ~AuthorizedUsersSensor() {}
81 bool UserPredicate(USER_PTR userPtr) const
82 { return userPtr->GetAuthorized(); }
85 class AlwaysOnlineUsersSensor : public UsersSensor {
87 AlwaysOnlineUsersSensor(USERS & u) : UsersSensor(u) {}
88 virtual ~AlwaysOnlineUsersSensor() {}
91 bool UserPredicate(USER_PTR userPtr) const
92 { return userPtr->GetProperty().alwaysOnline; }
95 class NoCashUsersSensor : public UsersSensor {
97 NoCashUsersSensor(USERS & u) : UsersSensor(u) {}
98 virtual ~NoCashUsersSensor() {}
101 bool UserPredicate(USER_PTR userPtr) const
102 { return userPtr->GetProperty().cash < 0; }
105 class DisabledDetailStatsUsersSensor : public UsersSensor {
107 DisabledDetailStatsUsersSensor(USERS & u) : UsersSensor(u) {}
108 virtual ~DisabledDetailStatsUsersSensor() {}
111 bool UserPredicate(USER_PTR userPtr) const
112 { return userPtr->GetProperty().disabledDetailStat; }
115 class DisabledUsersSensor : public UsersSensor {
117 DisabledUsersSensor(USERS & u) : UsersSensor(u) {}
118 virtual ~DisabledUsersSensor() {}
121 bool UserPredicate(USER_PTR userPtr) const
122 { return userPtr->GetProperty().disabled; }
125 class PassiveUsersSensor : public UsersSensor {
127 PassiveUsersSensor(USERS & u) : UsersSensor(u) {}
128 virtual ~PassiveUsersSensor() {}
131 bool UserPredicate(USER_PTR userPtr) const
132 { return userPtr->GetProperty().passive; }
135 class CreditUsersSensor : public UsersSensor {
137 CreditUsersSensor(USERS & u) : UsersSensor(u) {}
138 virtual ~CreditUsersSensor() {}
141 bool UserPredicate(USER_PTR userPtr) const
142 { return userPtr->GetProperty().credit > 0; }
145 class FreeMbUsersSensor : public UsersSensor {
147 FreeMbUsersSensor(USERS & u) : UsersSensor(u) {}
148 virtual ~FreeMbUsersSensor() {}
151 bool UserPredicate(USER_PTR userPtr) const
152 { return userPtr->GetProperty().freeMb > 0; }
155 class TariffChangeUsersSensor : public UsersSensor {
157 TariffChangeUsersSensor(USERS & u) : UsersSensor(u) {}
158 virtual ~TariffChangeUsersSensor() {}
161 bool UserPredicate(USER_PTR userPtr) const
162 { return userPtr->GetProperty().nextTariff.ConstData().empty(); }
165 class TotalTariffsSensor : public Sensor {
167 TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
168 virtual ~TotalTariffsSensor() {}
170 bool GetValue(ObjectSyntax_t * objectSyntax) const
172 ValueToOS(tariffs.Count(), objectSyntax);
177 std::string ToString() const
178 { std::string res; x2str(tariffs.Count(), res); return res; }
182 const TARIFFS & tariffs;
185 class TotalAdminsSensor : public Sensor {
187 TotalAdminsSensor(const ADMINS & a) : admins(a) {}
188 virtual ~TotalAdminsSensor() {}
190 bool GetValue(ObjectSyntax_t * objectSyntax) const
192 ValueToOS(admins.Count(), objectSyntax);
197 std::string ToString() const
198 { std::string res; x2str(admins.Count(), res); return res; }
202 const ADMINS & admins;
205 class TotalServicesSensor : public Sensor {
207 TotalServicesSensor(const SERVICES & s) : services(s) {}
208 virtual ~TotalServicesSensor() {}
210 bool GetValue(ObjectSyntax_t * objectSyntax) const
212 ValueToOS(services.Count(), objectSyntax);
217 std::string ToString() const
218 { std::string res; x2str(services.Count(), res); return res; }
222 const SERVICES & services;
225 class TotalCorporationsSensor : public Sensor {
227 TotalCorporationsSensor(const CORPORATIONS & c) : corporations(c) {}
228 virtual ~TotalCorporationsSensor() {}
230 bool GetValue(ObjectSyntax_t * objectSyntax) const
232 ValueToOS(corporations.Count(), objectSyntax);
237 std::string ToString() const
238 { std::string res; x2str(corporations.Count(), res); return res; }
242 const CORPORATIONS & corporations;
245 class TotalRulesSensor : public Sensor {
247 TotalRulesSensor(const TRAFFCOUNTER & t) : traffcounter(t) {}
248 virtual ~TotalRulesSensor() {}
250 bool GetValue(ObjectSyntax_t * objectSyntax) const
252 ValueToOS(traffcounter.RulesCount(), objectSyntax);
257 std::string ToString() const
258 { std::string res; x2str(traffcounter.RulesCount(), res); return res; }
262 const TRAFFCOUNTER & traffcounter;
265 template <typename T>
266 class ConstSensor : public Sensor {
268 ConstSensor(const T & v) : value(v) {}
269 virtual ~ConstSensor() {}
271 bool GetValue(ObjectSyntax * objectSyntax) const
272 { return ValueToOS(value, objectSyntax); }
275 std::string ToString() const
276 { std::string res; x2str(value, res); return res; }
285 std::string ConstSensor<std::string>::ToString() const