-#include "asn1/INTEGER.h"
-
-#include "stg/user.h"
-#include "stg/user_property.h"
-
#include "sensors.h"
-bool ConnectedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetConnected())
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool AuthorizedUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetAuthorized())
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool AlwaysOnlineUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetProperty().alwaysOnline)
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool NoCashUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetProperty().cash < 0)
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool DisabledDetailStatsUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetProperty().disabledDetailStat)
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool DisabledUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetProperty().disabled)
- ++count;
- }
-
-users.CloseSearch(handle);
+#include "stg/user.h"
-ValueToOS(count, objectSyntax);
-return true;
-}
+#include <cassert>
-bool PassiveUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
-{
-int handle = users.OpenSearch();
-if (!handle)
- return false;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#include "stg/INTEGER.h"
+#pragma GCC diagnostic pop
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
- {
- if (user->GetProperty().passive)
- ++count;
- }
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
-}
-
-bool CreditUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
+void UsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
{
int handle = users.OpenSearch();
-if (!handle)
- return false;
+assert(handle && "USERS::OpenSearch is always correct");
-USER_PTR user;
+STG::User* user;
size_t count = 0;
while (!users.SearchNext(handle, &user))
{
- if (user->GetProperty().credit > 0)
+ if (UserPredicate(user))
++count;
}
users.CloseSearch(handle);
ValueToOS(count, objectSyntax);
-return true;
}
-bool FreeMbUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
+#ifdef DEBUG
+std::string UsersSensor::ToString() const
{
int handle = users.OpenSearch();
-if (!handle)
- return false;
+assert(handle && "USERS::OpenSearch is always correct");
-USER_PTR user;
+STG::User* user;
size_t count = 0;
while (!users.SearchNext(handle, &user))
{
- if (user->GetProperty().freeMb > 0)
+ if (UserPredicate(user))
++count;
}
users.CloseSearch(handle);
-ValueToOS(count, objectSyntax);
-return true;
+return std::to_string(count);
}
+#endif
-bool TariffChangeUsersSensor::GetValue(ObjectSyntax_t * objectSyntax) const
+bool ActiveUsersSensor::UserPredicate(STG::User* userPtr) const
{
-int handle = users.OpenSearch();
-if (!handle)
+if (!userPtr->GetConnected())
return false;
-
-USER_PTR user;
-size_t count = 0;
-while (!users.SearchNext(handle, &user))
+for (size_t i = 0; i < DIR_NUM; ++i)
{
- if (!user->GetProperty().nextTariff.ConstData().empty())
- ++count;
+ if (userPtr->GetSessionUpload()[i] > 0 ||
+ userPtr->GetSessionDownload()[i] > 0)
+ return true;
}
-
-users.CloseSearch(handle);
-
-ValueToOS(count, objectSyntax);
-return true;
+return false;
}