]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig2/stgconfig.h
Code deduplication
[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                SetTraffcounter(TRAFFCOUNTER *) {}
39     void                SetStgSettings(const SETTINGS * s) { stgConfigSettings = s; }
40     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
41     int                 ParseSettings();
42
43     int                 Start();
44     int                 Stop();
45     int                 Reload() { return 0; }
46     bool                IsRunning() { return running; }
47
48     const string      & GetStrError() const { return errorStr; }
49     string              GetVersion() const;
50     uint16_t            GetStartPosition() const;
51     uint16_t            GetStopPosition() const;
52
53 private:
54     static void *       Run(void *);
55     void                RealRun();
56     bool                PrepareNetwork();
57     bool                FinalizeNetwork();
58     void                AcceptConnection();
59
60     mutable string      errorStr;
61     STG_CONFIG_SETTINGS stgConfigSettings;
62     pthread_t           thread;
63     bool                running;
64     bool                stopped;
65     CONFIGPROTO         config;
66     USERS *             users;
67     ADMINS *            admins;
68     TARIFFS *           tariffs;
69     STORE *             store;
70     MODULE_SETTINGS     settings;
71     const SETTINGS *    stgSettings;
72
73     std::list<ConnectionThread *> connections;
74
75     int                 sd;
76 };
77 //-----------------------------------------------------------------------------