]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig2/stgconfig.h
52d7801851c056400fb0866d15183314854374bc
[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     string  errorStr;
26     int     port;
27 };
28 //-----------------------------------------------------------------------------
29 class STG_CONFIG: public PLUGIN {
30 public:
31     STG_CONFIG();
32     virtual ~STG_CONFIG() {}
33
34     void                SetUsers(USERS * u) { users = u; }
35     void                SetTariffs(TARIFFS * t) { tariffs = t; }
36     void                SetAdmins(ADMINS * a) { admins = a; }
37     void                SetStore(STORE * s) { store = s; }
38     void                SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; }
39     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
40     int                 ParseSettings();
41
42     int                 Start();
43     int                 Stop();
44     int                 Reload() { return 0; }
45     bool                IsRunning() { return running; }
46
47     const string      & GetStrError() const { return errorStr; }
48     string              GetVersion() const;
49     uint16_t            GetStartPosition() const;
50     uint16_t            GetStopPosition() const;
51
52 private:
53     static void *       Run(void *);
54     void                RealRun();
55     bool                PrepareNetwork();
56     bool                FinalizeNetwork();
57     void                AcceptConnection();
58
59     mutable string      errorStr;
60     STG_CONFIG_SETTINGS stgConfigSettings;
61     pthread_t           thread;
62     bool                running;
63     bool                stopped;
64     CONFIGPROTO         config;
65     USERS *             users;
66     ADMINS *            admins;
67     TARIFFS *           tariffs;
68     STORE *             store;
69     MODULE_SETTINGS     settings;
70     const SETTINGS *    stgSettings;
71
72     std::list<ConnectionThread *> connections;
73
74     int                 sd;
75 };
76 //-----------------------------------------------------------------------------