UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / include / statmgr.h
blobf02deb6565e6a942cdb713fa4eef1638bec18caf
1 /*
2 * Copyright (C) 2007 Adam Kropelin
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General
6 * Public License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the Free
15 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
19 #ifndef STATMGR_H
20 #define STATMGR_H
22 #include "apc.h"
23 #include "amutex.h"
24 #include "alist.h"
25 #include "astring.h"
27 #define MAX_STATS 256
28 #define MAX_DATA 100
31 class StatMgr
33 public:
35 StatMgr(const char *host, unsigned short port);
36 ~StatMgr();
38 bool Update();
39 astring Get(const char* key);
40 bool GetAll(alist<astring> &keys, alist<astring> &values);
41 bool GetEvents(alist<astring> &events);
42 bool GetSummary(int &battstat, astring &statstr, astring &upsname);
44 private:
46 bool open();
47 void close();
49 char *ltrim(char *str);
50 void rtrim(char *str);
51 char *trim(char *str);
53 void lock();
54 void unlock();
56 struct keyval {
57 const char *key;
58 const char *value;
59 char data[MAX_DATA];
62 keyval m_stats[MAX_STATS];
63 astring m_host;
64 unsigned short m_port;
65 int m_socket;
66 amutex m_mutex;
69 #endif // STATMGR_H