]> git.stg.codes - stg.git/blob - projects/stargazer/tariffs_impl.h
Move projects back into subfolder.
[stg.git] / projects / stargazer / tariffs_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 #pragma once
26
27 #include "stg/tariff.h"
28 #include "stg/tariffs.h"
29 #include "stg/tariff_conf.h"
30 #include "tariff_impl.h"
31
32 #include <string>
33 #include <vector>
34 #include <set>
35 #include <mutex>
36
37 namespace STG
38 {
39
40 struct Store;
41 class Logger;
42 struct Admin;
43
44 class TariffsImpl : public Tariffs {
45     public:
46         using Data = std::vector<TariffImpl>;
47
48         explicit TariffsImpl(Store * store);
49
50         int ReadTariffs () override;
51         const Tariff * FindByName(const std::string & name) const override;
52         const Tariff * GetNoTariff() const override { return &noTariff; }
53         size_t Count() const override;
54         int Del(const std::string & name, const Admin * admin) override;
55         int Add(const std::string & name, const Admin * admin) override;
56         int Chg(const TariffData & td, const Admin * admin) override;
57
58         void AddNotifierAdd(NotifierBase<TariffData> * notifier) override;
59         void DelNotifierAdd(NotifierBase<TariffData> * notifier) override;
60
61         void AddNotifierDel(NotifierBase<TariffData> * notifier) override;
62         void DelNotifierDel(NotifierBase<TariffData> * notifier) override;
63
64         void GetTariffsData(std::vector<TariffData> * tdl) const override;
65
66         const std::string & GetStrError() const override { return strError; }
67
68     private:
69         Data               tariffs;
70         Store*             store;
71         Logger&            WriteServLog;
72         mutable std::mutex m_mutex;
73         std::string        strError;
74         TariffImpl         noTariff;
75
76         std::set<NotifierBase<TariffData>*> onAddNotifiers;
77         std::set<NotifierBase<TariffData>*> onDelNotifiers;
78 };
79
80 }