UniSet 2.32.1
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/Extensions.h"
27// --------------------------------------------------------------------------
28namespace uniset
29{
30 // -----------------------------------------------------------------------------
83 // -----------------------------------------------------------------------------
85 class RRDServer:
86 public UObject_SK
87 {
88 public:
89 RRDServer( uniset::ObjectId objId, xmlNode* cnode, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
90 const std::string& prefix = "rrd" );
91 virtual ~RRDServer();
92
94 static std::shared_ptr<RRDServer> init_rrdstorage( int argc, const char* const* argv,
95 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
96 const std::string& prefix = "rrd" );
97
99 static void help_print( int argc, const char* const* argv );
100
101 inline std::shared_ptr<LogAgregator> getLogAggregator()
102 {
103 return loga;
104 }
105 inline std::shared_ptr<DebugStream> log()
106 {
107 return mylog;
108 }
109
110 const size_t RRD_MAX_DSNAME_LEN = 19;
112 protected:
113 RRDServer();
114
115 virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
116 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
117 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
118 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
119
120 void initRRD( xmlNode* cnode, int tmID );
121
122 std::shared_ptr<SMInterface> shm;
123
124 struct DSInfo
125 {
127 std::string dsname;
128 long value;
129
130 DSInfo( uniset::ObjectId id, const std::string& dsname, long defval ):
131 sid(id), dsname(dsname), value(defval) {}
132 };
133
134 // Т.к. RRD требует чтобы данные записывались именно в том порядке в котором они были добавлены
135 // при инициализации и при этом, нам нужен быстрый доступ в обработчике sensorInfo.
136 // То создаём vector<> для последовательного прохода по элементам в нужном порядке
137 // и unordered_map<> для быстрого доступа к элементам в sensorInfo
138 // При этом используем shared_ptr чтобы элементы указывали на один и тот же DSInfo
139 typedef std::unordered_map<uniset::ObjectId, std::shared_ptr<DSInfo>> DSMap;
140 typedef std::vector<std::shared_ptr<DSInfo>> DSList;
141
142 struct RRDInfo
143 {
144 std::string filename;
145 long tid;
146 long sec;
147 DSMap dsmap;
148 DSList dslist;
149
150 RRDInfo( const std::string& fname, long tmID, long sec, const DSList& lst );
151 };
152
153 typedef std::vector<RRDInfo> RRDList;
154
155 RRDList rrdlist;
156
157 private:
158
159 std::string prefix;
160 };
161 // --------------------------------------------------------------------------
162} // end of namespace uniset
163// -----------------------------------------------------------------------------
164#endif // _RRDServer_H_
165// -----------------------------------------------------------------------------
Definition UObject_SK.h:30
Definition RRDServer.h:87
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:288
const size_t RRD_MAX_DSNAME_LEN
Definition RRDServer.h:110
static void help_print(int argc, const char *const *argv)
Definition RRDServer.cc:264
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition Calibration.h:27
long ObjectId
Definition UniSetTypes_i.idl:30
Definition RRDServer.h:125
Definition RRDServer.h:143