]> git.stg.codes - stg.git/blob - include/stg/user_stat.h
Fixed compilation issue.
[stg.git] / include / stg / user_stat.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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.15 $
23  $Date: 2010/03/11 14:42:05 $
24  $Author: faust $
25  */
26
27 #ifndef USER_STAT_H
28 #define USER_STAT_H
29
30 #include <ctime>
31 #include <map>
32
33 #include "os_int.h"
34 #include "resetable.h"
35 #include "user_traff.h"
36 //-----------------------------------------------------------------------------
37 struct IP_DIR_PAIR
38 {
39     #ifdef TRAFF_STAT_WITH_PORTS
40     IP_DIR_PAIR(uint32_t _ip,
41                 int _dir,
42                 uint16_t _port)
43         : ip(_ip),
44           dir(_dir),
45           port(_port)
46     {}
47     #else
48     IP_DIR_PAIR(uint32_t _ip,
49                 int _dir)
50         : ip(_ip),
51           dir(_dir)
52     {}
53     #endif
54     //------------------------
55     bool operator<(const IP_DIR_PAIR & idp) const
56         {
57         if (ip < idp.ip)
58             return true;
59
60         if (ip > idp.ip)
61             return false;
62
63         #ifdef TRAFF_STAT_WITH_PORTS
64         if (port < idp.port)
65             return true;
66
67         if (port > idp.port)
68             return false;
69         #endif
70
71         if (dir < idp.dir)
72             return true;
73
74         return false;
75         }
76     //------------------------
77     bool operator!=(const IP_DIR_PAIR & rvalue) const
78         {
79         if (ip != rvalue.ip)
80             return true;
81
82         #ifdef TRAFF_STAT_WITH_PORTS
83         if (port != rvalue.port)
84             return true;
85         #endif
86
87         if (dir != rvalue.dir)
88             return true;
89
90         return false;
91         }
92     //------------------------
93     uint32_t        ip;
94     int             dir;
95     #ifdef TRAFF_STAT_WITH_PORTS
96     uint16_t        port;
97     #endif
98 };
99 //-----------------------------------------------------------------------------
100 struct STAT_NODE
101 {
102     STAT_NODE(uint64_t _up,
103               uint64_t _down,
104               double   _cash)
105         : up(_up),
106           down(_down),
107           cash(_cash)
108     {}
109     uint64_t        up;
110     uint64_t        down;
111     double          cash;
112 };
113 //-----------------------------------------------------------------------------
114 struct USER_STAT
115 {
116     USER_STAT()
117         : sessionUp(),
118           sessionDown(),
119           monthUp(),
120           monthDown(),
121           cash(0),
122           freeMb(0),
123           lastCashAdd(0),
124           lastCashAddTime(0),
125           passiveTime(0),
126           lastActivityTime(0)
127     {}
128
129     DIR_TRAFF   sessionUp;
130     DIR_TRAFF   sessionDown;
131     DIR_TRAFF   monthUp;
132     DIR_TRAFF   monthDown;
133     double      cash;
134     double      freeMb;
135     double      lastCashAdd;
136     time_t      lastCashAddTime;
137     time_t      passiveTime;
138     time_t      lastActivityTime;
139 };
140 //-----------------------------------------------------------------------------
141 typedef std::map<IP_DIR_PAIR, STAT_NODE> TRAFF_STAT;
142 //-----------------------------------------------------------------------------
143 struct USER_STAT_RES
144 {
145     USER_STAT_RES()
146         : cash(),
147           freeMb(),
148           lastCashAdd(),
149           lastCashAddTime(),
150           passiveTime(),
151           lastActivityTime(),
152           sessionUp(),
153           sessionDown(),
154           monthUp(),
155           monthDown()
156     {}
157
158     USER_STAT_RES & operator= (const USER_STAT & us)
159     {
160         cash             = us.cash;
161         freeMb           = us.freeMb;
162         lastCashAdd      = us.lastCashAdd;
163         lastCashAddTime  = us.lastCashAddTime;
164         passiveTime      = us.passiveTime;
165         lastActivityTime = us.lastActivityTime;
166         sessionUp        = us.sessionUp;
167         sessionDown      = us.sessionDown;
168         monthUp          = us.monthUp;
169         monthDown        = us.monthDown;
170         return *this;
171     }
172     USER_STAT GetData() const
173     {
174         USER_STAT us;
175         us.cash             = cash.data();
176         us.freeMb           = freeMb.data();
177         us.lastCashAdd      = lastCashAdd.data();
178         us.lastCashAddTime  = lastCashAddTime.data();
179         us.passiveTime      = passiveTime.data();
180         us.lastActivityTime = lastActivityTime.data();
181         us.sessionUp        = sessionUp.GetData();
182         us.sessionDown      = sessionDown.GetData();
183         us.monthUp          = monthUp.GetData();
184         us.monthDown        = monthDown.GetData();
185         return us;
186     }
187
188     RESETABLE<double>      cash;
189     RESETABLE<double>      freeMb;
190     RESETABLE<double>      lastCashAdd;
191     RESETABLE<time_t>      lastCashAddTime;
192     RESETABLE<time_t>      passiveTime;
193     RESETABLE<time_t>      lastActivityTime;
194     DIR_TRAFF_RES          sessionUp;
195     DIR_TRAFF_RES          sessionDown;
196     DIR_TRAFF_RES          monthUp;
197     DIR_TRAFF_RES          monthDown;
198 };
199 //-----------------------------------------------------------------------------
200 #endif