]> git.stg.codes - stg.git/blobdiff - projects/stargazer/traffcounter_impl.h
Default constructor added in resetable structures
[stg.git] / projects / stargazer / traffcounter_impl.h
index eb4762392332c21740b799f0fa39d5544605532e..225a636e19594d65e5afe6d9fc5e5ea97378ad50 100644 (file)
 #include <map>
 #include <string>
 
 #include <map>
 #include <string>
 
-#include "traffcounter.h"
-#include "os_int.h"
-#include "stg_logger.h"
-#include "raw_ip_packet.h"
-#include "users.h"
+#include "stg/traffcounter.h"
+#include "stg/os_int.h"
+#include "stg/logger.h"
+#include "stg/raw_ip_packet.h"
+#include "stg/noncopyable.h"
+#include "stg/notifer.h"
 #include "actions.h"
 #include "actions.h"
-#include "noncopyable.h"
 #include "eventloop.h"
 #include "eventloop.h"
+#include "user_impl.h"
 
 #define PROTOMAX    (5)
 
 
 #define PROTOMAX    (5)
 
-class TARIFFS;
+class USERS_IMPL;
 
 //-----------------------------------------------------------------------------
 struct RULE {
 
 //-----------------------------------------------------------------------------
 struct RULE {
@@ -62,9 +63,9 @@ struct PACKET_EXTRA_DATA {
 PACKET_EXTRA_DATA()
     : flushTime(0),
       updateTime(0),
 PACKET_EXTRA_DATA()
     : flushTime(0),
       updateTime(0),
-      userU(),
+      userU(NULL),
       userUPresent(false),
       userUPresent(false),
-      userD(),
+      userD(NULL),
       userDPresent(false),
       dirU(DIR_NUM),
       dirD(DIR_NUM),
       userDPresent(false),
       dirU(DIR_NUM),
       dirD(DIR_NUM),
@@ -87,9 +88,9 @@ PACKET_EXTRA_DATA(const PACKET_EXTRA_DATA & pp)
 
 time_t      flushTime;          // Last flush time
 time_t      updateTime;         // Last update time
 
 time_t      flushTime;          // Last flush time
 time_t      updateTime;         // Last update time
-USER_PTR    userU;              // Uploader
+USER_IMPL * userU;              // Uploader
 bool        userUPresent;       // Uploader is registered user
 bool        userUPresent;       // Uploader is registered user
-USER_PTR    userD;              // Downloader
+USER_IMPL * userD;              // Downloader
 bool        userDPresent;       // Downloader is registered user
 int         dirU;               // Upload direction
 int         dirD;               // Download direction
 bool        userDPresent;       // Downloader is registered user
 int         dirU;               // Upload direction
 int         dirD;               // Download direction
@@ -101,66 +102,66 @@ class TRAFFCOUNTER_IMPL;
 //-----------------------------------------------------------------------------
 class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
 //-----------------------------------------------------------------------------
 class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
-                    TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_PTR u)
+                    TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_IMPL * u)
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
-    void            SetUser(USER_PTR u) { user = u; }
-    USER_PTR        GetUser() const { return user; }
+    void            SetUser(USER_IMPL * u) { user = u; }
+    USER_IMPL *     GetUser() const { return user; }
 
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
-    USER_PTR            user;
+    USER_IMPL *         user;
 };
 //-----------------------------------------------------------------------------
 class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
 };
 //-----------------------------------------------------------------------------
 class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
-                    TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_PTR u)
+                    TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_IMPL * u)
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
-    void            SetUser(USER_PTR u) { user = u; }
-    USER_PTR        GetUser() const { return user; }
+    void            SetUser(USER_IMPL * u) { user = u; }
+    USER_IMPL *     GetUser() const { return user; }
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
-    USER_PTR            user;
+    USER_IMPL *         user;
 };
 //-----------------------------------------------------------------------------
 };
 //-----------------------------------------------------------------------------
-class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
+class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_IMPL_PTR> {
 public:
             ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
 public:
             ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
-                NOTIFIER_BASE<USER_PTR>(),
+                NOTIFIER_BASE<USER_IMPL_PTR>(),
                 traffCnt(t)
             {}
     virtual ~ADD_USER_NONIFIER() {}
                 traffCnt(t)
             {}
     virtual ~ADD_USER_NONIFIER() {}
-    void    Notify(const USER_PTR & user);
+    void    Notify(const USER_IMPL_PTR & user);
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
-class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
+class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_IMPL_PTR> {
 public:
             DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
 public:
             DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
-                NOTIFIER_BASE<USER_PTR>(),
+                NOTIFIER_BASE<USER_IMPL_PTR>(),
                 traffCnt(t)
             {}
     virtual ~DEL_USER_NONIFIER() {}
                 traffCnt(t)
             {}
     virtual ~DEL_USER_NONIFIER() {}
-    void    Notify(const USER_PTR & user);
+    void    Notify(const USER_IMPL_PTR & user);
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
-class TRAFFCOUNTER : public TRAFFCOUNTER, private NONCOPYABLE {
+class TRAFFCOUNTER_IMPL : public TRAFFCOUNTER, private NONCOPYABLE {
 friend class ADD_USER_NONIFIER;
 friend class DEL_USER_NONIFIER;
 friend class TRF_IP_BEFORE;
 friend class TRF_IP_AFTER;
 public:
 friend class ADD_USER_NONIFIER;
 friend class DEL_USER_NONIFIER;
 friend class TRF_IP_BEFORE;
 friend class TRF_IP_AFTER;
 public:
-    TRAFFCOUNTER_IMPL(USERS * users, const TARIFFS * tariffs, const std::string & rulesFileName);
+    TRAFFCOUNTER_IMPL(USERS_IMPL * users, const std::string & rulesFileName);
     ~TRAFFCOUNTER_IMPL();
 
     void        SetRulesFile(const std::string & rulesFileName);
     ~TRAFFCOUNTER_IMPL();
 
     void        SetRulesFile(const std::string & rulesFileName);
@@ -172,6 +173,8 @@ public:
     void        Process(const RAW_PACKET & rawPacket);
     void        SetMonitorDir(const std::string & monitorDir);
 
     void        Process(const RAW_PACKET & rawPacket);
     void        SetMonitorDir(const std::string & monitorDir);
 
+    size_t      RulesCount() const { return rules.size(); }
+
 private:
     bool        ParseAddress(const char * ta, RULE * rule) const;
     uint32_t    CalcMask(uint32_t msk) const;
 private:
     bool        ParseAddress(const char * ta, RULE * rule) const;
     uint32_t    CalcMask(uint32_t msk) const;
@@ -187,10 +190,10 @@ private:
 
     void        FlushAndRemove();
 
 
     void        FlushAndRemove();
 
-    void        AddUser(USER_PTR user);
+    void        AddUser(USER_IMPL * user);
     void        DelUser(uint32_t uip);
     void        DelUser(uint32_t uip);
-    void        SetUserNotifiers(USER_PTR user);
-    void        UnSetUserNotifiers(USER_PTR user);
+    void        SetUserNotifiers(USER_IMPL * user);
+    void        UnSetUserNotifiers(USER_IMPL * user);
 
     typedef std::list<RULE>::iterator rule_iter;
     typedef std::map<RAW_PACKET, PACKET_EXTRA_DATA>::iterator pp_iter;
 
     typedef std::list<RULE>::iterator rule_iter;
     typedef std::map<RAW_PACKET, PACKET_EXTRA_DATA>::iterator pp_iter;
@@ -211,7 +214,7 @@ private:
     std::string              monitorDir;
     bool                     monitoring;
 
     std::string              monitorDir;
     bool                     monitoring;
 
-    USERS *                  users;
+    USERS_IMPL *             users;
 
     bool                     running;
     bool                     stopped;
 
     bool                     running;
     bool                     stopped;
@@ -232,7 +235,7 @@ void TRF_IP_BEFORE::Notify(const uint32_t & oldValue, const uint32_t &)
 if (!oldValue)
     return;
 
 if (!oldValue)
     return;
 
-EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::DelUser, oldValue);
+EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, oldValue);
 }
 //-----------------------------------------------------------------------------
 inline
 }
 //-----------------------------------------------------------------------------
 inline
@@ -242,20 +245,20 @@ void TRF_IP_AFTER::Notify(const uint32_t &, const uint32_t & newValue)
 if (!newValue)
     return;
 
 if (!newValue)
     return;
 
-EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::AddUser, user);
+EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::AddUser, user);
 }
 //-----------------------------------------------------------------------------
 inline
 }
 //-----------------------------------------------------------------------------
 inline
-void ADD_USER_NONIFIER::Notify(const USER_PTR & user)
+void ADD_USER_NONIFIER::Notify(const USER_IMPL_PTR & user)
 {
 {
-EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::SetUserNotifiers, user);
+EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::SetUserNotifiers, user);
 }
 //-----------------------------------------------------------------------------
 inline
 }
 //-----------------------------------------------------------------------------
 inline
-void DEL_USER_NONIFIER::Notify(const USER_PTR & user)
+void DEL_USER_NONIFIER::Notify(const USER_IMPL_PTR & user)
 {
 {
-EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::UnSetUserNotifiers, user);
-EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER::DelUser, user->GetCurrIP());
+EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::UnSetUserNotifiers, user);
+EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, user->GetCurrIP());
 }
 //-----------------------------------------------------------------------------
 #endif //TRAFFCOUNTER_H
 }
 //-----------------------------------------------------------------------------
 #endif //TRAFFCOUNTER_H