]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/smux/sensors.cpp
Merge remote-tracking branch 'github/master'
[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 STG::User* 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 STG::User* 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 return std::to_string(count);
45 }
46 #endif
47
48 bool ActiveUsersSensor::UserPredicate(STG::User* userPtr) const
49 {
50 if (!userPtr->GetConnected())
51     return false;
52 for (size_t i = 0; i < DIR_NUM; ++i)
53     {
54     if (userPtr->GetSessionUpload()[i] > 0 ||
55         userPtr->GetSessionDownload()[i] > 0)
56         return true;
57     }
58 return false;
59 }