]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig2/stgconfig.h
Rename BASE_AUTH and BASE_STORE to AUTH and STORE
[stg.git] / projects / stargazer / plugins / configuration / sgconfig2 / stgconfig.h
1 #include <pthread.h>
2
3 #include <string>
4 #include <list>
5
6 #include "plugin.h"
7 #include "store.h"
8 #include "configproto.h"
9
10 using namespace std;
11
12 extern "C" PLUGIN * GetPlugin();
13
14 class STG_CONFIG;
15
16 //-----------------------------------------------------------------------------
17 class STG_CONFIG_SETTINGS {
18 public:
19                     STG_CONFIG_SETTINGS();
20     virtual         ~STG_CONFIG_SETTINGS() {}
21     const string &  GetStrError() const;
22     int             ParseSettings(const MODULE_SETTINGS & s);
23     uint16_t        GetPort();
24 private:
25     int     ParseIntInRange(const string & str, int min, int max, int * val);
26     string  errorStr;
27     int     port;
28 };
29 //-----------------------------------------------------------------------------
30 class STG_CONFIG: public PLUGIN {
31 public:
32     STG_CONFIG();
33     virtual ~STG_CONFIG() {}
34
35     void                SetUsers(USERS * u) { users = u; }
36     void                SetTariffs(TARIFFS * t) { tariffs = t; }
37     void                SetAdmins(ADMINS * a) { admins = a; }
38     void                SetStore(STORE * s) { store = s; }
39     void                SetTraffcounter(TRAFFCOUNTER *) {}
40     void                SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; }
41     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
42     int                 ParseSettings();
43
44     int                 Start();
45     int                 Stop();
46     int                 Reload() { return 0; }
47     bool                IsRunning() { return running; }
48
49     const string      & GetStrError() const { return errorStr; }
50     string              GetVersion() const;
51     uint16_t            GetStartPosition() const;
52     uint16_t            GetStopPosition() const;
53
54 private:
55     static void *       Run(void *);
56     void                RealRun();
57     bool                PrepareNetwork();
58     bool                FinalizeNetwork();
59     void                AcceptConnection();
60
61     mutable string      errorStr;
62     STG_CONFIG_SETTINGS stgConfigSettings;
63     pthread_t           thread;
64     bool                running;
65     bool                stopped;
66     CONFIGPROTO         config;
67     USERS *             users;
68     ADMINS *            admins;
69     TARIFFS *           tariffs;
70     STORE *             store;
71     MODULE_SETTINGS     settings;
72     const SETTINGS *    stgSettings;
73
74     std::list<ConnectionThread *> connections;
75
76     int                 sd;
77 };
78 //-----------------------------------------------------------------------------