]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/userstat/userstat.h
9dd01f2524e6a6a38ef7afe52c3b8b4244f708e9
[stg.git] / projects / stargazer / plugins / other / userstat / userstat.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 : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 /*
22  $Revision: $
23  $Date: $
24  $Author: $
25 */
26
27 #ifndef __USERSTAT_H__
28 #define __USERSTAT_H__
29
30 #include <string>
31 #include <map>
32 #include <functional>
33
34 #include <pthread.h>
35 #include <netinet/in.h>
36
37 #include "base_plugin.h"
38
39 #define USTAT_VERSION "UserStats 1.0_alt"
40
41 extern "C" BASE_PLUGIN * GetPlugin();
42
43 class USERSTAT : public BASE_PLUGIN
44 {
45 public:
46     USERSTAT();
47     ~USERSTAT();
48
49     virtual void SetUsers(USERS * u) { users = u; };
50     virtual void SetTariffs(TARIFFS * t) {};
51     virtual void SetAdmins(ADMINS * a) {};
52     virtual void SetTraffcounter(TRAFFCOUNTER * tc) {};
53     virtual void SetStore(BASE_STORE * st) { store = st; };
54     virtual void SetStgSettings(const SETTINGS * s) {};
55     virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; };
56     virtual int  ParseSettings();
57
58     virtual int  Start();
59     virtual int  Stop();
60     virtual bool IsRunning() { return isRunning; };
61     virtual const string  & GetStrError() const { return errorStr; };
62     virtual const string    GetVersion() const { return version; };
63     virtual uint16_t        GetStartPosition() const { return 0; };
64     virtual uint16_t        GetStopPosition() const { return 0; };
65
66 private:
67     struct IsDone : public unary_function<DataThread, bool>
68     {
69         bool operator()(const DataThread & info) { return info.IsDone(); };
70     };
71     struct ToLower : public unary_function<char, char>
72     {
73         char operator() (char c) const  { return std::tolower(c); }
74     };
75     bool isRunning;
76     bool nonstop;
77     std::string errorStr;
78     std::string version;
79     std::vector<DataThread> pool;
80     int listenSocket;
81     int threads;
82     unsigned maxThreads;
83     uint16_t port;
84     struct sockaddr_in listenAddr;
85     pthread_t thread;
86     pthread_mutex_t mutex;
87     USERS * users;
88     BASE_STORE * store;
89
90     MODULE_SETTINGS settings;
91
92     int Prepare();
93     int Finalize();
94     static void * Run(void *);
95     static void * Operate(void *);
96 };
97
98 #endif