]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/sensors.cpp
snma agent -> smux
[stg.git] / projects / stargazer / plugins / other / smux / sensors.cpp
1 #include "asn1/INTEGER.h"
2
3 #include "stg/user.h"
4 #include "stg/user_property.h"
5
6 #include "sensors.h"
7
8 bool ConnectedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
9 {
10 int handle = users.OpenSearch();
11 if (!handle)
12     return false;
13
14 USER_PTR user;
15 size_t count = 0;
16 while (!users.SearchNext(handle, &user))
17     {
18     if (user->GetConnected())
19         ++count;
20     }
21
22 users.CloseSearch(handle);
23
24 ValueToOS(count, objectSyntax);
25 return true;
26 }
27
28 bool AuthorizedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
29 {
30 int handle = users.OpenSearch();
31 if (!handle)
32     return false;
33
34 USER_PTR user;
35 size_t count = 0;
36 while (!users.SearchNext(handle, &user))
37     {
38     if (user->GetAuthorized())
39         ++count;
40     }
41
42 users.CloseSearch(handle);
43
44 ValueToOS(count, objectSyntax);
45 return true;
46 }
47
48 bool AlwaysOnlineUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
49 {
50 int handle = users.OpenSearch();
51 if (!handle)
52     return false;
53
54 USER_PTR user;
55 size_t count = 0;
56 while (!users.SearchNext(handle, &user))
57     {
58     if (user->GetProperty().alwaysOnline)
59         ++count;
60     }
61
62 users.CloseSearch(handle);
63
64 ValueToOS(count, objectSyntax);
65 return true;
66 }
67
68 bool NoCashUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
69 {
70 int handle = users.OpenSearch();
71 if (!handle)
72     return false;
73
74 USER_PTR user;
75 size_t count = 0;
76 while (!users.SearchNext(handle, &user))
77     {
78     if (user->GetProperty().cash < 0)
79         ++count;
80     }
81
82 users.CloseSearch(handle);
83
84 ValueToOS(count, objectSyntax);
85 return true;
86 }
87
88 bool DisabledDetailStatsUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
89 {
90 int handle = users.OpenSearch();
91 if (!handle)
92     return false;
93
94 USER_PTR user;
95 size_t count = 0;
96 while (!users.SearchNext(handle, &user))
97     {
98     if (user->GetProperty().disabledDetailStat)
99         ++count;
100     }
101
102 users.CloseSearch(handle);
103
104 ValueToOS(count, objectSyntax);
105 return true;
106 }
107
108 bool DisabledUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
109 {
110 int handle = users.OpenSearch();
111 if (!handle)
112     return false;
113
114 USER_PTR user;
115 size_t count = 0;
116 while (!users.SearchNext(handle, &user))
117     {
118     if (user->GetProperty().disabled)
119         ++count;
120     }
121
122 users.CloseSearch(handle);
123
124 ValueToOS(count, objectSyntax);
125 return true;
126 }
127
128 bool PassiveUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
129 {
130 int handle = users.OpenSearch();
131 if (!handle)
132     return false;
133
134 USER_PTR user;
135 size_t count = 0;
136 while (!users.SearchNext(handle, &user))
137     {
138     if (user->GetProperty().passive)
139         ++count;
140     }
141
142 users.CloseSearch(handle);
143
144 ValueToOS(count, objectSyntax);
145 return true;
146 }
147
148 bool CreditUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
149 {
150 int handle = users.OpenSearch();
151 if (!handle)
152     return false;
153
154 USER_PTR user;
155 size_t count = 0;
156 while (!users.SearchNext(handle, &user))
157     {
158     if (user->GetProperty().credit > 0)
159         ++count;
160     }
161
162 users.CloseSearch(handle);
163
164 ValueToOS(count, objectSyntax);
165 return true;
166 }
167
168 bool FreeMbUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
169 {
170 int handle = users.OpenSearch();
171 if (!handle)
172     return false;
173
174 USER_PTR user;
175 size_t count = 0;
176 while (!users.SearchNext(handle, &user))
177     {
178     if (user->GetProperty().freeMb > 0)
179         ++count;
180     }
181
182 users.CloseSearch(handle);
183
184 ValueToOS(count, objectSyntax);
185 return true;
186 }
187
188 bool TariffChangeUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
189 {
190 int handle = users.OpenSearch();
191 if (!handle)
192     return false;
193
194 USER_PTR user;
195 size_t count = 0;
196 while (!users.SearchNext(handle, &user))
197     {
198     if (!user->GetProperty().nextTariff.ConstData().empty())
199         ++count;
200     }
201
202 users.CloseSearch(handle);
203
204 ValueToOS(count, objectSyntax);
205 return true;
206 }