]> git.stg.codes - stg.git/blob - include/user_stat.h
Добавление исходников
[stg.git] / include / 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
32 #include "os_int.h"
33 #include "resetable.h"
34 #include "user_traff.h"
35 //-----------------------------------------------------------------------------
36 struct IP_DIR_PAIR
37 {
38     #ifdef TRAFF_STAT_WITH_PORTS
39     IP_DIR_PAIR(uint32_t _ip,
40                 int _dir,
41                 uint16_t _port)
42         : ip(_ip),
43           dir(_dir),
44           port(_port)
45     {}
46     #else
47     IP_DIR_PAIR(uint32_t _ip,
48                 int _dir)
49         : ip(_ip),
50           dir(_dir)
51     {}
52     #endif
53     //------------------------
54     bool operator<(const IP_DIR_PAIR & idp) const
55         {
56         if (ip < idp.ip)
57             return true;
58
59         if (ip > idp.ip)
60             return false;
61
62         #ifdef TRAFF_STAT_WITH_PORTS
63         if (port < idp.port)
64             return true;
65
66         if (port > idp.port)
67             return false;
68         #endif
69
70         if (dir < idp.dir)
71             return true;
72
73         return false;
74         }
75     //------------------------
76     uint32_t        ip;
77     int             dir;
78     #ifdef TRAFF_STAT_WITH_PORTS
79     uint16_t        port;
80     #endif
81 };
82 //-----------------------------------------------------------------------------
83 struct STAT_NODE
84 {
85     STAT_NODE(uint64_t _up,
86               uint64_t _down,
87               double   _cash)
88         : up(_up),
89           down(_down),
90           cash(_cash)
91     {}
92     uint64_t        up;
93     uint64_t        down;
94     double          cash;
95 };
96 //-----------------------------------------------------------------------------
97 struct USER_STAT
98 {
99     //USER_STAT & operator= (const USER_STAT_RES & usr);
100     USER_STAT()
101         : up(),
102           down(),
103           cash(0),
104           freeMb(0),
105           lastCashAdd(0),
106           lastCashAddTime(0),
107           passiveTime(0),
108           lastActivityTime(0)
109     {};
110
111     DIR_TRAFF   up;
112     DIR_TRAFF   down;
113     double      cash;
114     double      freeMb;
115     double      lastCashAdd;
116     time_t      lastCashAddTime;
117     time_t      passiveTime;
118     time_t      lastActivityTime;
119 };
120 //-----------------------------------------------------------------------------
121 struct USER_STAT_RES
122 {
123     USER_STAT_RES()
124         : cash(),
125           freeMb(),
126           lastCashAdd(),
127           lastCashAddTime(),
128           passiveTime(),
129           lastActivityTime(),
130           up(),
131           down()
132     {}
133
134     USER_STAT_RES & operator= (const USER_STAT & us)
135     {
136         cash             = us.cash;
137         freeMb           = us.freeMb;
138         lastCashAdd      = us.lastCashAdd;
139         lastCashAddTime  = us.lastCashAddTime;
140         passiveTime      = us.passiveTime;
141         lastActivityTime = us.lastActivityTime;
142         up = us.up;
143         down = us.down;
144         return * this;
145     };
146     operator USER_STAT()
147     {
148         USER_STAT us;
149         us.cash             = cash;
150         us.freeMb           = freeMb;
151         us.lastCashAdd      = lastCashAdd;
152         us.lastCashAddTime  = lastCashAddTime;
153         us.passiveTime      = passiveTime;
154         us.lastActivityTime = lastActivityTime;
155         us.up               = up;
156         us.down             = down;
157         return us;
158     };
159
160     RESETABLE<double>      cash;
161     RESETABLE<double>      freeMb;
162     RESETABLE<double>      lastCashAdd;
163     RESETABLE<time_t>      lastCashAddTime;
164     RESETABLE<time_t>      passiveTime;
165     RESETABLE<time_t>      lastActivityTime;
166     RESETABLE<DIR_TRAFF>   up;
167     RESETABLE<DIR_TRAFF>   down;
168 };
169 //-----------------------------------------------------------------------------
170 #endif
171
172
173