UniSet 2.32.1
DBServer_MySQL.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// --------------------------------------------------------------------------
20// --------------------------------------------------------------------------
21#ifndef DBServer_MySQL_H_
22#define DBServer_MySQL_H_
23// --------------------------------------------------------------------------
24#include <unordered_map>
25#include <queue>
26#include "UniSetTypes.h"
27#include "MySQLInterface.h"
28#include "DBServer.h"
29// -------------------------------------------------------------------------
30namespace uniset
31{
32 //------------------------------------------------------------------------------------------
150 //------------------------------------------------------------------------------------------
153 public DBServer
154 {
155 public:
156 DBServer_MySQL( uniset::ObjectId id, const std::string& prefix );
157 explicit DBServer_MySQL( const std::string& prefix );
158 virtual ~DBServer_MySQL();
159
161 static std::shared_ptr<DBServer_MySQL> init_dbserver( int argc, const char* const* argv, const std::string& prefix = "mysql" );
162
164 static void help_print( int argc, const char* const* argv );
165
166 inline std::shared_ptr<LogAgregator> logAggregator()
167 {
168 return loga;
169 }
170 inline std::shared_ptr<DebugStream> log()
171 {
172 return dblog;
173 }
174
175 protected:
176 typedef std::unordered_map<int, std::string> DBTableMap;
177
178 virtual void initDBServer() override;
179 virtual void onReconnect(const std::unique_ptr<MySQLInterface>& db ) {};
180
181 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
182 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
183 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
184 virtual void confirmInfo( const uniset::ConfirmMessage* cmsg ) override;
185 virtual void onTextMessage( const uniset::TextMessage* msg ) override;
186 virtual std::string getMonitInfo( const std::string& params ) override;
187
188 bool writeToBase( const std::string& query );
189
190 inline std::string tblName( int key )
191 {
192 return tblMap[key].c_str();
193 }
194
196 {
199 lastNumberOfTimer
200 };
201
202 std::unique_ptr<MySQLInterface> db;
203 int PingTime = { 15000 };
204 int ReconnectTime = { 30000 };
205 bool connect_ok = { false };
207 bool activate = { false };
208
209 typedef std::queue<std::string> QueryBuffer;
210
211 QueryBuffer qbuf;
212 size_t qbufSize = { 200 }; // размер буфера сообщений.
213 bool lastRemove = { false };
214
215 void flushBuffer();
217
218 private:
219 DBTableMap tblMap;
220
221 };
222 // ----------------------------------------------------------------------------------
223} // end of namespace uniset
224//------------------------------------------------------------------------------------------
225#endif
Definition MessageType.h:240
Definition DBServer_MySQL.h:154
static void help_print(int argc, const char *const *argv)
Definition DBServer_MySQL.cc:434
Timers
Definition DBServer_MySQL.h:196
@ PingTimer
Definition DBServer_MySQL.h:197
@ ReconnectTimer
Definition DBServer_MySQL.h:198
static std::shared_ptr< DBServer_MySQL > init_dbserver(int argc, const char *const *argv, const std::string &prefix="mysql")
Definition DBServer_MySQL.cc:411
bool activate
Definition DBServer_MySQL.h:207
Definition DBServer.h:45
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:283
Definition MessageType.h:214
Definition Mutex.h:32
Definition Calibration.h:27
KeyType key(const uniset::ObjectId id, const uniset::ObjectId node)
Definition UniSetTypes.cc:980
long ObjectId
Definition UniSetTypes_i.idl:30