UniSet @VERSION@
RRDServer.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// -----------------------------------------------------------------------------
17#ifndef _RRDServer_H_
18#define _RRDServer_H_
19// -----------------------------------------------------------------------------
20#include <unordered_map>
21#include <list>
22#include <memory>
23#include "UObject_SK.h"
24#include "SMInterface.h"
25#include "SharedMemory.h"
26#include "Extensions.h"
27#include "USingleProcess.h"
28// --------------------------------------------------------------------------
29namespace uniset
30{
31 // -----------------------------------------------------------------------------
84 // -----------------------------------------------------------------------------
86 class RRDServer:
87 private USingleProcess,
88 public UObject_SK
89 {
90 public:
91 RRDServer( uniset::ObjectId objId, xmlNode* cnode, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
92 const std::string& prefix = "rrd" );
93 virtual ~RRDServer();
94
96 static std::shared_ptr<RRDServer> init_rrdstorage( int argc, const char* const* argv,
97 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
98 const std::string& prefix = "rrd" );
99
101 static void help_print( int argc, const char* const* argv );
102
103 inline std::shared_ptr<LogAgregator> getLogAggregator()
104 {
105 return loga;
106 }
107 inline std::shared_ptr<DebugStream> log()
108 {
109 return mylog;
110 }
111
112 const size_t RRD_MAX_DSNAME_LEN = 19;
114 protected:
115 RRDServer();
116
117 virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
118 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
119 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
120 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
121
122 void initRRD( xmlNode* cnode, int tmID );
123
124 std::shared_ptr<SMInterface> shm;
125
126 struct DSInfo
127 {
129 std::string dsname;
130 long value;
131
132 DSInfo( uniset::ObjectId id, const std::string& dsname, long defval ):
133 sid(id), dsname(dsname), value(defval) {}
134 };
135
136 // Т.к. RRD требует чтобы данные записывались именно в том порядке в котором они были добавлены
137 // при инициализации и при этом, нам нужен быстрый доступ в обработчике sensorInfo.
138 // То создаём vector<> для последовательного прохода по элементам в нужном порядке
139 // и unordered_map<> для быстрого доступа к элементам в sensorInfo
140 // При этом используем shared_ptr чтобы элементы указывали на один и тот же DSInfo
141 typedef std::unordered_map<uniset::ObjectId, std::shared_ptr<DSInfo>> DSMap;
142 typedef std::vector<std::shared_ptr<DSInfo>> DSList;
143
144 struct RRDInfo
145 {
146 std::string filename;
147 long tid;
148 long sec;
149 DSMap dsmap;
150 DSList dslist;
151
152 RRDInfo( const std::string& fname, long tmID, long sec, const DSList& lst );
153 };
154
155 typedef std::vector<RRDInfo> RRDList;
156
157 RRDList rrdlist;
158
159 private:
160
161 std::string prefix;
162 };
163 // --------------------------------------------------------------------------
164} // end of namespace uniset
165// -----------------------------------------------------------------------------
166#endif // _RRDServer_H_
167// -----------------------------------------------------------------------------
Definition UObject_SK.h:30
Definition RRDServer.h:89
static std::shared_ptr< RRDServer > init_rrdstorage(int argc, const char *const *argv, uniset::ObjectId shmID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="rrd")
Definition RRDServer.cc:289
const size_t RRD_MAX_DSNAME_LEN
Definition RRDServer.h:112
static void help_print(int argc, const char *const *argv)
Definition RRDServer.cc:265
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition USingleProcess.h:28
Definition AccessConfig.h:30
long ObjectId
Definition UniSetTypes_i.idl:30
Definition RRDServer.h:127
Definition RRDServer.h:145