UniSet  2.6.0
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 // -------------------------------------------------------------------------
30 namespace uniset
31 {
32  //------------------------------------------------------------------------------------------
138  public DBServer
139  {
140  public:
141  DBServer_SQLite( uniset::ObjectId id, const std::string& prefix );
142  explicit DBServer_SQLite( const std::string& prefix );
143  virtual ~DBServer_SQLite();
144 
146  static std::shared_ptr<DBServer_SQLite> init_dbserver( int argc, const char* const* argv, const std::string& prefix = "sqlite" );
147 
149  static void help_print( int argc, const char* const* argv );
150 
151  inline std::shared_ptr<LogAgregator> logAggregator()
152  {
153  return loga;
154  }
155  inline std::shared_ptr<DebugStream> log()
156  {
157  return dblog;
158  }
159 
160  protected:
161  typedef std::unordered_map<int, std::string> DBTableMap;
162 
163  virtual void initDBServer() override;
164  virtual void initDB( std::shared_ptr<SQLiteInterface>& db ) {};
165  virtual void initDBTableMap(DBTableMap& tblMap) {};
166 
167  virtual void timerInfo( const uniset::TimerMessage* tm ) override;
168  virtual void sysCommand( const uniset::SystemMessage* sm ) override;
169  virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
170  virtual void confirmInfo( const uniset::ConfirmMessage* cmsg ) override;
171 
172  bool writeToBase( const string& query );
173  void createTables( SQLiteInterface* db );
174 
175  inline std::string tblName(int key)
176  {
177  return tblMap[key];
178  }
179 
180  enum Timers
181  {
184  lastNumberOfTimer
185  };
186 
187 
188  std::shared_ptr<SQLiteInterface> db;
189  int PingTime;
190  int ReconnectTime;
191  bool connect_ok;
193  bool activate;
194 
195  typedef std::queue<std::string> QueryBuffer;
196 
197  QueryBuffer qbuf;
198  unsigned int qbufSize; // размер буфера сообщений.
199  bool lastRemove;
200 
201  void flushBuffer();
203 
204  private:
205  DBTableMap tblMap;
206 
207  };
208  // ----------------------------------------------------------------------------------
209 } // end of namespace uniset
210 //------------------------------------------------------------------------------------------
211 #endif
static std::shared_ptr< DBServer_SQLite > init_dbserver(int argc, const char *const *argv, const std::string &prefix="sqlite")
Definition: DBServer_SQLite.cc:379
Definition: CallbackTimer.h:29
Definition: SQLiteInterface.h:85
Definition: DBServer.h:51
static void help_print(int argc, const char *const *argv)
Definition: DBServer_SQLite.cc:402
Definition: MessageType.h:166
Definition: MessageType.h:232
Definition: DBServer_SQLite.h:182
Timers
Definition: DBServer_SQLite.h:180
Definition: MessageType.h:122
bool activate
Definition: DBServer_SQLite.h:193
Definition: DBServer_SQLite.h:183
Definition: DBServer_SQLite.h:137
Definition: Mutex.h:32
Definition: MessageType.h:209
static KeyType key(const uniset::ObjectId id, const uniset::ObjectId node)
Definition: UniSetTypes.h:72
long ObjectId
Definition: UniSetTypes_i.idl:30