7 #include "stg/tariffs.h"
8 #include "stg/user_property.h"
10 #include "stg/ObjectSyntax.h"
17 virtual bool GetValue(ObjectSyntax_t * objectSyntax) const = 0;
19 virtual std::string ToString() const = 0;
23 typedef std::map<OID, Sensor *> Sensors;
25 class TotalUsersSensor : public Sensor {
27 TotalUsersSensor(const USERS & u) : users(u) {}
28 virtual ~TotalUsersSensor() {}
30 bool GetValue(ObjectSyntax_t * objectSyntax) const
32 ValueToOS(users.GetUserNum(), objectSyntax);
37 std::string ToString() const
38 { std::string res; x2str(users.GetUserNum(), res); return res; }
45 class UsersSensor : public Sensor {
47 UsersSensor(USERS & u) : users(u) {}
48 virtual ~UsersSensor() {}
50 bool GetValue(ObjectSyntax_t * objectSyntax) const;
52 std::string ToString() const;
58 virtual bool UserPredicate(USER_PTR userPtr) const = 0;
61 class ConnectedUsersSensor : public UsersSensor {
63 ConnectedUsersSensor(USERS & u) : UsersSensor(u) {}
64 virtual ~ConnectedUsersSensor() {}
67 bool UserPredicate(USER_PTR userPtr) const
68 { return userPtr->GetConnected(); }
71 class AuthorizedUsersSensor : public UsersSensor {
73 AuthorizedUsersSensor(USERS & u) : UsersSensor(u) {}
74 virtual ~AuthorizedUsersSensor() {}
77 bool UserPredicate(USER_PTR userPtr) const
78 { return userPtr->GetAuthorized(); }
81 class AlwaysOnlineUsersSensor : public UsersSensor {
83 AlwaysOnlineUsersSensor(USERS & u) : UsersSensor(u) {}
84 virtual ~AlwaysOnlineUsersSensor() {}
87 bool UserPredicate(USER_PTR userPtr) const
88 { return userPtr->GetProperty().alwaysOnline; }
91 class NoCashUsersSensor : public UsersSensor {
93 NoCashUsersSensor(USERS & u) : UsersSensor(u) {}
94 virtual ~NoCashUsersSensor() {}
97 bool UserPredicate(USER_PTR userPtr) const
98 { return userPtr->GetProperty().cash < 0; }
101 class DisabledDetailStatsUsersSensor : public UsersSensor {
103 DisabledDetailStatsUsersSensor(USERS & u) : UsersSensor(u) {}
104 virtual ~DisabledDetailStatsUsersSensor() {}
107 bool UserPredicate(USER_PTR userPtr) const
108 { return userPtr->GetProperty().disabledDetailStat; }
111 class DisabledUsersSensor : public UsersSensor {
113 DisabledUsersSensor(USERS & u) : UsersSensor(u) {}
114 virtual ~DisabledUsersSensor() {}
117 bool UserPredicate(USER_PTR userPtr) const
118 { return userPtr->GetProperty().disabled; }
121 class PassiveUsersSensor : public UsersSensor {
123 PassiveUsersSensor(USERS & u) : UsersSensor(u) {}
124 virtual ~PassiveUsersSensor() {}
127 bool UserPredicate(USER_PTR userPtr) const
128 { return userPtr->GetProperty().passive; }
131 class CreditUsersSensor : public UsersSensor {
133 CreditUsersSensor(USERS & u) : UsersSensor(u) {}
134 virtual ~CreditUsersSensor() {}
137 bool UserPredicate(USER_PTR userPtr) const
138 { return userPtr->GetProperty().credit > 0; }
141 class FreeMbUsersSensor : public UsersSensor {
143 FreeMbUsersSensor(USERS & u) : UsersSensor(u) {}
144 virtual ~FreeMbUsersSensor() {}
147 bool UserPredicate(USER_PTR userPtr) const
148 { return userPtr->GetProperty().freeMb > 0; }
151 class TariffChangeUsersSensor : public UsersSensor {
153 TariffChangeUsersSensor(USERS & u) : UsersSensor(u) {}
154 virtual ~TariffChangeUsersSensor() {}
157 bool UserPredicate(USER_PTR userPtr) const
158 { return userPtr->GetProperty().nextTariff.ConstData().empty(); }
161 class TotalTariffsSensor : public Sensor {
163 TotalTariffsSensor(const TARIFFS & t) : tariffs(t) {}
164 virtual ~TotalTariffsSensor() {}
166 bool GetValue(ObjectSyntax_t * objectSyntax) const
168 ValueToOS(tariffs.GetTariffsNum(), objectSyntax);
173 std::string ToString() const
174 { std::string res; x2str(tariffs.GetTariffsNum(), res); return res; }
178 const TARIFFS & tariffs;
181 template <typename T>
182 class ConstSensor : public Sensor {
184 ConstSensor(const T & v) : value(v) {}
185 virtual ~ConstSensor() {}
187 bool GetValue(ObjectSyntax * objectSyntax) const
188 { return ValueToOS(value, objectSyntax); }
191 std::string ToString() const
192 { std::string res; x2str(value, res); return res; }
201 std::string ConstSensor<std::string>::ToString() const