]> git.stg.codes - stg.git/blob - stargazer/plugins/configuration/sgconfig/configproto.h
Public interfaces: part 1
[stg.git] / stargazer / plugins / configuration / sgconfig / configproto.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  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
20  */
21
22 #pragma once
23
24 #include "parser.h"
25
26 #include "stg/module_settings.h"
27
28 #include <string>
29 #include <deque>
30 #include <cstdint>
31
32 #include <sys/select.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35
36 namespace STG
37 {
38
39 struct Settings;
40 struct Admins;
41 struct Tariffs;
42 struct Users;
43 struct Services;
44 struct Corporations;
45 struct Store;
46 class PluginLogger;
47
48 class Conn;
49
50 }
51
52 class CONFIGPROTO {
53 public:
54     explicit CONFIGPROTO(STG::PluginLogger & l);
55     ~CONFIGPROTO();
56
57     void SetPort(uint16_t port) { m_port = port; }
58     void SetBindAddress(const std::string & address) { m_bindAddress = address; }
59     void SetSettings(const STG::Settings * settings) { m_settings = settings; }
60     void SetAdmins(STG::Admins * admins) { m_admins = admins; }
61     void SetTariffs(STG::Tariffs * tariffs) { m_tariffs = tariffs; }
62     void SetUsers(STG::Users * users) { m_users = users; }
63     void SetStore(STG::Store * store) { m_store = store; }
64     void SetServices(STG::Services * services) { m_services = services; }
65     void SetCorporations(STG::Corporations * corporations) { m_corporations = corporations; }
66
67     int Prepare();
68     int Stop();
69     const std::string & GetStrError() const { return m_errorStr; }
70     void Run();
71
72 private:
73     CONFIGPROTO(const CONFIGPROTO & rvalue);
74     CONFIGPROTO & operator=(const CONFIGPROTO & rvalue);
75
76     const STG::Settings * m_settings;
77     STG::Admins *         m_admins;
78     STG::Tariffs *        m_tariffs;
79     STG::Users *          m_users;
80     STG::Services *       m_services;
81     STG::Corporations *   m_corporations;
82     STG::Store *          m_store;
83
84     uint16_t         m_port;
85     std::string      m_bindAddress;
86     bool             m_running;
87     bool             m_stopped;
88     STG::PluginLogger &   m_logger;
89     int              m_listenSocket;
90
91     std::string      m_errorStr;
92
93     BASE_PARSER::REGISTRY m_registry;
94     std::deque<STG::Conn *> m_conns;
95
96     bool Bind();
97
98     void RegisterParsers();
99
100     int MaxFD() const;
101     void BuildFDSet(fd_set & fds) const;
102     void CleanupConns();
103     void HandleEvents(const fd_set & fds);
104     void AcceptConnection();
105 };