8 #include "stg/tariffs.h"
9 #include "stg/admins.h"
10 #include "stg/services.h"
11 #include "stg/corporations.h"
12 #include "stg/traffcounter.h"
13 #include "stg/user_property.h"
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wold-style-cast"
17 #include "stg/ObjectSyntax.h"
18 #pragma GCC diagnostic pop
24 virtual ~Sensor() = default;
25 virtual void GetValue(ObjectSyntax_t * objectSyntax) const = 0;
27 virtual std::string ToString() const = 0;
31 typedef std::map<OID, Sensor *> Sensors;
33 class TotalUsersSensor : public Sensor {
35 explicit TotalUsersSensor(const STG::Users & u) : users(u) {}
37 void GetValue(ObjectSyntax_t * objectSyntax) const override
39 ValueToOS(users.Count(), objectSyntax);
43 std::string ToString() const override
44 { std::string res; std::to_string(users.Count(), res); return res; }
48 const STG::Users & users;
51 class UsersSensor : public Sensor {
53 explicit UsersSensor(STG::Users & u) : users(u) {}
55 void GetValue(ObjectSyntax_t * objectSyntax) const override;
57 std::string ToString() const override;
63 virtual bool UserPredicate(STG::User* userPtr) const = 0;
66 class ConnectedUsersSensor : public UsersSensor {
68 explicit ConnectedUsersSensor(STG::Users & u) : UsersSensor(u) {}
71 bool UserPredicate(STG::User* userPtr) const override
72 { return userPtr->GetConnected(); }
75 class AuthorizedUsersSensor : public UsersSensor {
77 explicit AuthorizedUsersSensor(STG::Users & u) : UsersSensor(u) {}
80 bool UserPredicate(STG::User* userPtr) const override
81 { return userPtr->GetAuthorized(); }
84 class AlwaysOnlineUsersSensor : public UsersSensor {
86 explicit AlwaysOnlineUsersSensor(STG::Users & u) : UsersSensor(u) {}
89 bool UserPredicate(STG::User* userPtr) const override
90 { return userPtr->GetProperties().alwaysOnline; }
93 class NoCashUsersSensor : public UsersSensor {
95 explicit NoCashUsersSensor(STG::Users & u) : UsersSensor(u) {}
98 bool UserPredicate(STG::User* userPtr) const override
99 { return userPtr->GetProperties().cash < 0; }
102 class DisabledDetailStatsUsersSensor : public UsersSensor {
104 explicit DisabledDetailStatsUsersSensor(STG::Users & u) : UsersSensor(u) {}
107 bool UserPredicate(STG::User* userPtr) const override
108 { return userPtr->GetProperties().disabledDetailStat; }
111 class DisabledUsersSensor : public UsersSensor {
113 explicit DisabledUsersSensor(STG::Users & u) : UsersSensor(u) {}
116 bool UserPredicate(STG::User* userPtr) const override
117 { return userPtr->GetProperties().disabled; }
120 class PassiveUsersSensor : public UsersSensor {
122 explicit PassiveUsersSensor(STG::Users & u) : UsersSensor(u) {}
125 bool UserPredicate(STG::User* userPtr) const override
126 { return userPtr->GetProperties().passive; }
129 class CreditUsersSensor : public UsersSensor {
131 explicit CreditUsersSensor(STG::Users & u) : UsersSensor(u) {}
134 bool UserPredicate(STG::User* userPtr) const override
135 { return userPtr->GetProperties().credit > 0; }
138 class FreeMbUsersSensor : public UsersSensor {
140 explicit FreeMbUsersSensor(STG::Users & u) : UsersSensor(u) {}
143 bool UserPredicate(STG::User* userPtr) const override
144 { return userPtr->GetProperties().freeMb > 0; }
147 class TariffChangeUsersSensor : public UsersSensor {
149 explicit TariffChangeUsersSensor(STG::Users & u) : UsersSensor(u) {}
152 bool UserPredicate(STG::User* userPtr) const override
153 { return !userPtr->GetProperties().nextTariff.ConstData().empty(); }
156 class ActiveUsersSensor : public UsersSensor {
158 explicit ActiveUsersSensor(STG::Users & u) : UsersSensor(u) {}
161 bool UserPredicate(STG::User* userPtr) const override;
164 class TotalTariffsSensor : public Sensor {
166 explicit TotalTariffsSensor(const STG::Tariffs & t) : tariffs(t) {}
168 void GetValue(ObjectSyntax_t * objectSyntax) const override
170 ValueToOS(tariffs.Count(), objectSyntax);
174 std::string ToString() const override
175 { std::string res; std::to_string(tariffs.Count(), res); return res; }
179 const STG::Tariffs & tariffs;
182 class TotalAdminsSensor : public Sensor {
184 explicit TotalAdminsSensor(const STG::Admins & a) : admins(a) {}
186 void GetValue(ObjectSyntax_t * objectSyntax) const override
188 ValueToOS(admins.count(), objectSyntax);
192 std::string ToString() const override
193 { std::string res; std::to_string(admins.Count(), res); return res; }
197 const STG::Admins & admins;
200 class TotalServicesSensor : public Sensor {
202 explicit TotalServicesSensor(const STG::Services & s) : services(s) {}
204 void GetValue(ObjectSyntax_t * objectSyntax) const override
206 ValueToOS(services.Count(), objectSyntax);
210 std::string ToString() const override
211 { std::string res; std::to_string(services.Count(), res); return res; }
215 const STG::Services & services;
218 class TotalCorporationsSensor : public Sensor {
220 explicit TotalCorporationsSensor(const STG::Corporations & c) : corporations(c) {}
222 void GetValue(ObjectSyntax_t * objectSyntax) const override
224 ValueToOS(corporations.Count(), objectSyntax);
228 std::string ToString() const override
229 { std::string res; std::to_string(corporations.Count(), res); return res; }
233 const STG::Corporations & corporations;
236 class TotalRulesSensor : public Sensor {
238 explicit TotalRulesSensor(const STG::TraffCounter & t) : traffcounter(t) {}
240 void GetValue(ObjectSyntax_t * objectSyntax) const override
242 ValueToOS(traffcounter.rulesCount(), objectSyntax);
246 std::string ToString() const override
247 { std::string res; std::to_string(traffcounter.rulesCount(), res); return res; }
251 const STG::TraffCounter & traffcounter;
254 template <typename T>
255 class ConstSensor : public Sensor {
257 explicit ConstSensor(const T & v) : value(v) {}
259 void GetValue(ObjectSyntax * objectSyntax) const override
261 ValueToOS(value, objectSyntax);
265 std::string ToString() const override
266 { std::string res; std::to_string(value, res); return res; }
276 std::string ConstSensor<std::string>::ToString() const