File: DatabaseConnectionPool.h

package info (click to toggle)
tango 10.0.2%2Bdfsg1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 89,480 kB
  • sloc: cpp: 201,245; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 269; sql: 72; ruby: 24
file content (52 lines) | stat: -rw-r--r-- 1,638 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef DATABASECONNECTIONPOOL_H
#define DATABASECONNECTIONPOOL_H

#include <memory>
#include "common.h"

class DatabaseConnectionPool;
using DatabaseConnectionPoolPtr = std::shared_ptr<DatabaseConnectionPool>;

/// Management class for the database connection pool
class DatabaseConnectionPool : public Tango::LogAdapter
{
public:
  DatabaseConnectionPool(Tango::DeviceImpl *dev,
                         const char* mysql_user,
                         const char* mysql_password,
                         const char* mysql_host,
                         const char* mysql_db_name);

  ~DatabaseConnectionPool();

  DatabaseConnectionPool(const DatabaseConnectionPool&) = delete;
  DatabaseConnectionPool& operator=(const DatabaseConnectionPool&) = delete;
  DatabaseConnectionPool(DatabaseConnectionPool&&) = delete;
  DatabaseConnectionPool& operator=(DatabaseConnectionPool&&) = delete;

  /// Only user: DatabaseConnectionHandle
  /// @{
  MYSQL* GetDatabase(int con_nb);
  int get_connection();
  void release_connection(int con_nb);
  /// @}

  /// Set the connection pool size from main() before the DS is created
	static void set_conn_pool_size(int si);

private:
	static int conn_pool_size;
  int m_last_sem_wait;
	unsigned long	m_mysql_svr_version;
  struct DbConnection;
  DbConnection *m_conn_pool;
	omni_mutex m_sem_wait_mutex;

  void base_connect(int loop);
  void create_connection_pool(const char* mysql_user,
                              const char* mysql_password,
                              const char* mysql_host,
                              const char* mysql_db_name);
};

#endif // DATABASECONNECTIONPOOL_H