#include "stg/common.h"
#include "stg/plugin_creator.h"
-#include "stg/users.h"
+/*#include "stg/users.h"
#include "stg/tariffs.h"
#include "stg/admins.h"
#include "stg/services.h"
#include "stg/corporations.h"
+#include "stg/traffcounter.h"*/
#include "smux.h"
#include "utils.h"
admins(NULL),
services(NULL),
corporations(NULL),
+ traffcounter(NULL),
running(false),
stopped(true),
- sock(-1)
+ sock(-1),
+ smuxHandlers(),
+ pdusHandlers(),
+ sensors(),
+ tables(),
+ notifiers(),
+ addUserNotifier(*this),
+ delUserNotifier(*this),
+ addDelTariffNotifier(*this)
{
pthread_mutex_init(&mutex, NULL);
int SMUX::Start()
{
-assert(users != NULL && "users not NULL");
-assert(tariffs != NULL && "tariffs not NULL");
-assert(admins != NULL && "admins not NULL");
-assert(services != NULL && "services not NULL");
-assert(corporations != NULL && "corporations not NULL");
+assert(users != NULL && "users must not be NULL");
+assert(tariffs != NULL && "tariffs must not be NULL");
+assert(admins != NULL && "admins must not be NULL");
+assert(services != NULL && "services must not be NULL");
+assert(corporations != NULL && "corporations must not be NULL");
+assert(traffcounter != NULL && "traffcounter must not be NULL");
if (PrepareNet())
return -1;
sensors[OID(".1.3.6.1.4.1.38313.1.4.1")] = new TotalServicesSensor(*services);
// Corporations
sensors[OID(".1.3.6.1.4.1.38313.1.5.1")] = new TotalCorporationsSensor(*corporations);
+// Traffcounter
+sensors[OID(".1.3.6.1.4.1.38313.1.6.1")] = new TotalRulesSensor(*traffcounter);
// Table data
-tables[".1.3.6.1.4.1.38313.1.1.6"] = new TariffUsersTable(".1.3.6.1.4.1.38313.1.1.6", *users);
+tables[".1.3.6.1.4.1.38313.1.1.6"] = new TariffUsersTable(".1.3.6.1.4.1.38313.1.1.6", *tariffs, *users);
UpdateTables();
+SetNotifiers();
#ifdef DEBUG
Sensors::const_iterator it(sensors.begin());
printfd(__FILE__, "SMUX::Stop() - Before\n");
running = false;
+ResetNotifiers();
+
if (!stopped)
{
//5 seconds to thread stops itself
SendRReqPDU(sock);
running = true;
stopped = false;
+
while(running)
{
if (WaitPackets(sock))
{
SMUX_PDUs_t * pdus = RecvSMUXPDUs(sock);
if (pdus)
+ {
DispatchPDUs(pdus);
+ ASN_STRUCT_FREE(asn_DEF_SMUX_PDUs, pdus);
+ }
}
if (!running)
break;
return true;
}
+
+void SMUX::SetNotifier(USER_PTR userPtr)
+{
+notifiers.push_back(CHG_AFTER_NOTIFIER(*this, userPtr));
+userPtr->GetProperty().tariffName.AddAfterNotifier(¬ifiers.back());
+}
+
+void SMUX::UnsetNotifier(USER_PTR userPtr)
+{
+std::list<CHG_AFTER_NOTIFIER>::iterator it = notifiers.begin();
+while (it != notifiers.end())
+ {
+ if (it->GetUserPtr() == userPtr)
+ {
+ userPtr->GetProperty().tariffName.DelAfterNotifier(&(*it));
+ notifiers.erase(it);
+ break;
+ }
+ ++it;
+ }
+}
+
+void SMUX::SetNotifiers()
+{
+int h = users->OpenSearch();
+assert(h && "USERS::OpenSearch is always correct");
+
+USER_PTR u;
+while (!users->SearchNext(h, &u))
+ SetNotifier(u);
+
+users->CloseSearch(h);
+
+users->AddNotifierUserAdd(&addUserNotifier);
+users->AddNotifierUserDel(&delUserNotifier);
+
+tariffs->AddNotifierAdd(&addDelTariffNotifier);
+tariffs->AddNotifierDel(&addDelTariffNotifier);
+}
+
+void SMUX::ResetNotifiers()
+{
+tariffs->DelNotifierDel(&addDelTariffNotifier);
+tariffs->DelNotifierAdd(&addDelTariffNotifier);
+
+users->DelNotifierUserDel(&delUserNotifier);
+users->DelNotifierUserAdd(&addUserNotifier);
+
+std::list<CHG_AFTER_NOTIFIER>::iterator it = notifiers.begin();
+while (it != notifiers.end())
+ {
+ it->GetUserPtr()->GetProperty().tariffName.DelAfterNotifier(&(*it));
+ ++it;
+ }
+}
+
+void CHG_AFTER_NOTIFIER::Notify(const std::string &, const std::string &)
+{
+smux.UpdateTables();
+}