]> git.stg.codes - stg.git/blob - projects/stargazer/tariff_impl.h
Ticket 37. The time_t currentTime parameter added in
[stg.git] / projects / stargazer / tariff_impl.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  *    Date: 07.11.2007
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 /*
26  $Revision: 1.9 $
27  $Date: 2010/10/07 17:53:39 $
28  $Author: faust $
29  */
30
31 #ifndef TARIFF_IMPL_H
32 #define TARIFF_IMPL_H
33
34 #include <ctime>
35
36 #include <string>
37 #include <list>
38
39 #include "stg/tariff.h"
40 #include "stg/os_int.h"
41 #include "stg/tariff_conf.h"
42
43 #define TARIFF_DAY     0
44 #define TARIFF_NIGHT   1
45
46 class TARIFF_IMPL : public TARIFF {
47 public:
48     TARIFF_IMPL()
49         : TARIFF(),
50           tariffData()
51     {}
52     TARIFF_IMPL(const std::string & name)
53         : TARIFF(),
54           tariffData(name)
55     {}
56     TARIFF_IMPL(const TARIFF_DATA & td)
57         : TARIFF(),
58           tariffData(td)
59     {}
60     TARIFF_IMPL(const TARIFF_IMPL & t)
61         : TARIFF(),
62           tariffData(t.tariffData)
63     {}
64     virtual ~TARIFF_IMPL() {}
65
66     double  GetPriceWithTraffType(uint64_t up,
67                                   uint64_t down,
68                                   int dir,
69                                   time_t t) const;
70     double  GetFreeMb() const { return tariffData.tariffConf.free; }
71     double  GetPassiveCost() const { return tariffData.tariffConf.passiveCost; }
72     double  GetFee() const { return tariffData.tariffConf.fee; }
73     double  GetFree() const { return tariffData.tariffConf.free; }
74     PERIOD  GetPeriod() const { return tariffData.tariffConf.period; }
75     CHANGE_POLICY GetChangePolicy() const { return tariffData.tariffConf.changePolicy; }
76     time_t GetChangePolicyTimeout() const { return tariffData.tariffConf.changePolicyTimeout; }
77
78     void    Print() const;
79
80     const   std::string & GetName() const { return tariffData.tariffConf.name; }
81     void    SetName(const std::string & name) { tariffData.tariffConf.name = name; }
82
83     int     GetTraffType() const { return tariffData.tariffConf.traffType; }
84     int64_t GetTraffByType(uint64_t up, uint64_t down) const;
85     int     GetThreshold(int dir) const;
86     const TARIFF_DATA & GetTariffData() const { return tariffData; }
87
88     TARIFF_IMPL & operator=(const TARIFF_DATA & td);
89     TARIFF_IMPL & operator=(const TARIFF_IMPL & t);
90     bool     operator==(const TARIFF_IMPL & rhs) const { return GetName() == rhs.GetName(); }
91     bool     operator!=(const TARIFF_IMPL & rhs) const { return GetName() != rhs.GetName(); }
92     std::string TariffChangeIsAllowed(const TARIFF & to, time_t currentTime) const;
93
94 private:
95     TARIFF_DATA     tariffData;
96
97     double  GetPriceWithoutFreeMb(int dir, int64_t mb, time_t t) const;
98     int     Interval(int dir, time_t t) const;
99 };
100
101 #endif