]> git.stg.codes - stg.git/blob - include/stg/user.h
Complete replacement notifiers with subscriptions.
[stg.git] / include / stg / user.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 #pragma once
22
23 #include "message.h"
24 #include "user_property.h"
25
26 #include <vector>
27 #include <string>
28
29 #include <ctime>
30 #include <cstdint>
31
32 namespace STG
33 {
34
35 struct Tariff;
36 class UserProperties;
37 class DirTraff;
38 struct Auth;
39
40 class User
41 {
42     public:
43         User() noexcept
44             : m_connectedBase(false),
45               m_currIPBase(0),
46               m_connected(m_connectedBase),
47               m_currIP(m_currIPBase)
48         {
49         }
50
51         virtual ~User() = default;
52
53         virtual int                 WriteConf() = 0;
54         virtual int                 WriteStat() = 0;
55
56         virtual const std::string&  GetLogin() const = 0;
57
58         uint32_t                    GetCurrIP() const { return m_currIP; }
59         time_t                      GetCurrIPModificationTime() const { return m_currIP.ModificationTime(); }
60
61         template <typename F>
62         auto                        beforeCurrIPChange(F&& f) { return m_currIP.beforeChange(std::forward<F>(f)); }
63         template <typename F>
64         auto                        afterCurrIPChange(F&& f) { return m_currIP.afterChange(std::forward<F>(f)); }
65
66         template <typename F>
67         auto                        beforeConnectedChange(F&& f) { return m_connected.beforeChange(std::forward<F>(f)); }
68         template <typename F>
69         auto                        afterConnectedChange(F&& f) { return m_connected.afterChange(std::forward<F>(f)); }
70
71         virtual int                 GetID() const = 0;
72
73         virtual double              GetPassiveTimePart() const = 0;
74
75         virtual const Tariff*       GetTariff() const = 0;
76         virtual void                ResetNextTariff() = 0;
77
78         virtual const DirTraff&     GetSessionUpload() const = 0;
79         virtual const DirTraff&     GetSessionDownload() const = 0;
80         virtual time_t              GetSessionUploadModificationTime() const = 0;
81         virtual time_t              GetSessionDownloadModificationTime() const = 0;
82
83         bool                        GetConnected() const { return m_connected; }
84         time_t                      GetConnectedModificationTime() const { return m_connected.ModificationTime(); }
85
86         virtual const std::string&  GetLastDisconnectReason() const = 0;
87         virtual int                 GetAuthorized() const = 0;
88         virtual time_t              GetAuthorizedModificationTime() const = 0;
89
90         virtual bool                IsAuthorizedBy(const Auth * auth) const = 0;
91         virtual std::vector<std::string> GetAuthorizers() const = 0;
92
93         virtual int                 AddMessage(Message* msg) = 0;
94
95         virtual void                UpdatePingTime(time_t t = 0) = 0;
96         virtual time_t              GetPingTime() const = 0;
97
98         virtual void                Run() = 0;
99
100         virtual const std::string&  GetStrError() const = 0;
101
102         virtual UserProperties&     GetProperties() = 0;
103         virtual const UserProperties& GetProperties() const = 0;
104
105         virtual bool                GetDeleted() const = 0;
106         virtual void                SetDeleted() = 0;
107
108         virtual time_t              GetLastWriteStatTime() const = 0;
109
110         virtual bool                IsInetable() = 0;
111         virtual std::string         GetEnabledDirs() const = 0;
112
113         virtual void                OnAdd() = 0;
114         virtual void                OnDelete() = 0;
115
116         virtual std::string GetParamValue(const std::string& name) const = 0;
117
118     private:
119         bool m_connectedBase;
120         uint32_t m_currIPBase;
121
122     protected:
123         UserProperty<bool> m_connected;
124         UserProperty<uint32_t> m_currIP;
125 };
126
127 }