X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/e9ae1f101b5418c0ba2e6c9d86b23c12f0140982..b2b89723a2427bba8290bd6967a1ab39cbb630be:/include/stg/user.h diff --git a/include/stg/user.h b/include/stg/user.h index b08f3cd0..78b602ba 100644 --- a/include/stg/user.h +++ b/include/stg/user.h @@ -20,8 +20,8 @@ #pragma once -#include "notifer.h" #include "message.h" +#include "user_property.h" #include #include @@ -37,77 +37,91 @@ class UserProperties; class DirTraff; struct Auth; -using CURR_IP_NOTIFIER = PropertyNotifierBase; -using CONNECTED_NOTIFIER = PropertyNotifierBase; +class User +{ + public: + User() noexcept + : m_connectedBase(false), + m_currIPBase(0), + m_connected(m_connectedBase), + m_currIP(m_currIPBase) + { + } + + virtual ~User() = default; -struct User { - virtual ~User() = default; + virtual int WriteConf() = 0; + virtual int WriteStat() = 0; - virtual int WriteConf() = 0; - virtual int WriteStat() = 0; + virtual const std::string& GetLogin() const = 0; - virtual const std::string& GetLogin() const = 0; + uint32_t GetCurrIP() const { return m_currIP; } + time_t GetCurrIPModificationTime() const { return m_currIP.ModificationTime(); } - virtual uint32_t GetCurrIP() const = 0; - virtual time_t GetCurrIPModificationTime() const = 0; + template + auto beforeCurrIPChange(F&& f) { return m_currIP.beforeChange(std::forward(f)); } + template + auto afterCurrIPChange(F&& f) { return m_currIP.afterChange(std::forward(f)); } - virtual void AddCurrIPBeforeNotifier(CURR_IP_NOTIFIER* notifier) = 0; - virtual void DelCurrIPBeforeNotifier(const CURR_IP_NOTIFIER* notifier) = 0; + template + auto beforeConnectedChange(F&& f) { return m_connected.beforeChange(std::forward(f)); } + template + auto afterConnectedChange(F&& f) { return m_connected.afterChange(std::forward(f)); } - virtual void AddCurrIPAfterNotifier(CURR_IP_NOTIFIER* notifier) = 0; - virtual void DelCurrIPAfterNotifier(const CURR_IP_NOTIFIER* notifier) = 0; + virtual int GetID() const = 0; - virtual void AddConnectedBeforeNotifier(CONNECTED_NOTIFIER* notifier) = 0; - virtual void DelConnectedBeforeNotifier(const CONNECTED_NOTIFIER* notifier) = 0; + virtual double GetPassiveTimePart() const = 0; - virtual void AddConnectedAfterNotifier(CONNECTED_NOTIFIER* notifier) = 0; - virtual void DelConnectedAfterNotifier(const CONNECTED_NOTIFIER* notifier) = 0; + virtual const Tariff* GetTariff() const = 0; + virtual void ResetNextTariff() = 0; - virtual int GetID() const = 0; + virtual const DirTraff& GetSessionUpload() const = 0; + virtual const DirTraff& GetSessionDownload() const = 0; + virtual time_t GetSessionUploadModificationTime() const = 0; + virtual time_t GetSessionDownloadModificationTime() const = 0; - virtual double GetPassiveTimePart() const = 0; + bool GetConnected() const { return m_connected; } + time_t GetConnectedModificationTime() const { return m_connected.ModificationTime(); } - virtual const Tariff* GetTariff() const = 0; - virtual void ResetNextTariff() = 0; + virtual const std::string& GetLastDisconnectReason() const = 0; + virtual int GetAuthorized() const = 0; + virtual time_t GetAuthorizedModificationTime() const = 0; - virtual const DirTraff& GetSessionUpload() const = 0; - virtual const DirTraff& GetSessionDownload() const = 0; - virtual time_t GetSessionUploadModificationTime() const = 0; - virtual time_t GetSessionDownloadModificationTime() const = 0; + virtual bool IsAuthorizedBy(const Auth * auth) const = 0; + virtual std::vector GetAuthorizers() const = 0; - virtual bool GetConnected() const = 0; - virtual time_t GetConnectedModificationTime() const = 0; - virtual const std::string& GetLastDisconnectReason() const = 0; - virtual int GetAuthorized() const = 0; - virtual time_t GetAuthorizedModificationTime() const = 0; + virtual int AddMessage(Message* msg) = 0; - virtual bool IsAuthorizedBy(const Auth * auth) const = 0; - virtual std::vector GetAuthorizers() const = 0; + virtual void UpdatePingTime(time_t t = 0) = 0; + virtual time_t GetPingTime() const = 0; - virtual int AddMessage(Message* msg) = 0; + virtual void Run() = 0; - virtual void UpdatePingTime(time_t t = 0) = 0; - virtual time_t GetPingTime() const = 0; + virtual const std::string& GetStrError() const = 0; - virtual void Run() = 0; + virtual UserProperties& GetProperties() = 0; + virtual const UserProperties& GetProperties() const = 0; - virtual const std::string& GetStrError() const = 0; + virtual bool GetDeleted() const = 0; + virtual void SetDeleted() = 0; - virtual UserProperties& GetProperties() = 0; - virtual const UserProperties& GetProperties() const = 0; + virtual time_t GetLastWriteStatTime() const = 0; - virtual bool GetDeleted() const = 0; - virtual void SetDeleted() = 0; + virtual bool IsInetable() = 0; + virtual std::string GetEnabledDirs() const = 0; - virtual time_t GetLastWriteStatTime() const = 0; + virtual void OnAdd() = 0; + virtual void OnDelete() = 0; - virtual bool IsInetable() = 0; - virtual std::string GetEnabledDirs() const = 0; + virtual std::string GetParamValue(const std::string& name) const = 0; - virtual void OnAdd() = 0; - virtual void OnDelete() = 0; + private: + bool m_connectedBase; + uint32_t m_currIPBase; - virtual std::string GetParamValue(const std::string& name) const = 0; + protected: + UserProperty m_connected; + UserProperty m_currIP; }; }