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