]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/other/userstat/userstat.h
18b128c1f5d5f2fbefd5f7d5d8124ab756bf95dc
[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 SetStore(BASE_STORE * st) { store = st; }
51     virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; }
52     virtual int  ParseSettings();
53
54     virtual int  Start();
55     virtual int  Stop();
56     virtual bool IsRunning() { return isRunning; }
57     virtual const string  & GetStrError() const { return errorStr; }
58     virtual const string    GetVersion() const { return version; }
59     virtual uint16_t        GetStartPosition() const { return 10; }
60     virtual uint16_t        GetStopPosition() const { return 10; }
61
62 private:
63     struct IsDone : public unary_function<DataThread, bool>
64     {
65         bool operator()(const DataThread & info) { return info.IsDone(); }
66     };
67     struct ToLower : public unary_function<char, char>
68     {
69         char operator() (char c) const  { return std::tolower(c); }
70     };
71     bool isRunning;
72     bool nonstop;
73     std::string errorStr;
74     std::string version;
75     std::vector<DataThread> pool;
76     int listenSocket;
77     int threads;
78     unsigned maxThreads;
79     uint16_t port;
80     struct sockaddr_in listenAddr;
81     pthread_t thread;
82     pthread_mutex_t mutex;
83     USERS * users;
84     BASE_STORE * store;
85
86     MODULE_SETTINGS settings;
87
88     int Prepare();
89     int Finalize();
90     static void * Run(void *);
91     static void * Operate(void *);
92 };
93
94 #endif