]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/sensors.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / projects / stargazer / plugins / other / smux / sensors.cpp
1 #include <cassert>
2
3 #include "stg/INTEGER.h"
4
5 #include "stg/user.h"
6
7 #include "sensors.h"
8
9 bool UsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
10 {
11 int handle = users.OpenSearch();
12 assert(handle && "USERS::OpenSearch is always correct");
13
14 USER_PTR user;
15 size_t count = 0;
16 while (!users.SearchNext(handle, &user))
17     {
18     if (UserPredicate(user))
19         ++count;
20     }
21
22 users.CloseSearch(handle);
23
24 ValueToOS(count, objectSyntax);
25 return true;
26 }
27
28 #ifdef DEBUG
29 std::string UsersSensor::ToString() const
30 {
31 int handle = users.OpenSearch();
32 assert(handle && "USERS::OpenSearch is always correct");
33
34 USER_PTR user;
35 size_t count = 0;
36 while (!users.SearchNext(handle, &user))
37     {
38     if (UserPredicate(user))
39         ++count;
40     }
41
42 users.CloseSearch(handle);
43
44 std::string res;
45 x2str(count, res);
46 return res;
47 }
48 #endif
49
50 bool ActiveUsersSensor::UserPredicate(USER_PTR userPtr) const
51 {
52 if (!userPtr->GetConnected())
53     return false;
54 for (size_t i = 0; i < DIR_NUM; ++i)
55     {
56     if (userPtr->GetSessionUpload()[i] > 0 ||
57         userPtr->GetSessionDownload()[i] > 0)
58         return true;
59     }
60 return false;
61 }