mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-05 15:48:19 +00:00
Roughly define database pool interface
This commit is contained in:
parent
d59cdf47b5
commit
295ce95d64
|
@ -1840,6 +1840,8 @@ set_src(ENGINE_SERVER GLOB_RECURSE src/engine/server
|
|||
authmanager.cpp
|
||||
authmanager.h
|
||||
databases/connection.h
|
||||
databases/connection_pool.cpp
|
||||
databases/connection_pool.h
|
||||
databases/mysql.cpp
|
||||
databases/mysql.h
|
||||
name_ban.cpp
|
||||
|
|
|
@ -25,8 +25,9 @@ public:
|
|||
SUCCESS,
|
||||
ERROR,
|
||||
};
|
||||
// returns true if connection was established
|
||||
// tries to allocate the connection from the pool established
|
||||
virtual Status Connect() = 0;
|
||||
// has to be called to return the connection back to the pool
|
||||
virtual void Disconnect() = 0;
|
||||
|
||||
// get exclusive read/write access to the database
|
||||
|
|
42
src/engine/server/databases/connection_pool.cpp
Normal file
42
src/engine/server/databases/connection_pool.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "connection_pool.h"
|
||||
|
||||
// helper struct to hold thread data
|
||||
struct CSqlExecData
|
||||
{
|
||||
CSqlExecData(
|
||||
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
|
||||
const ISqlData *pSqlRequestData
|
||||
);
|
||||
~CSqlExecData();
|
||||
|
||||
bool (*m_pFuncPtr) (IDbConnection*, const ISqlData *);
|
||||
std::unique_ptr<const ISqlData> m_pSqlRequestData;
|
||||
};
|
||||
|
||||
CDbConnectionPool::CDbConnectionPool()
|
||||
{
|
||||
}
|
||||
|
||||
CDbConnectionPool::~CDbConnectionPool()
|
||||
{
|
||||
}
|
||||
|
||||
void CDbConnectionPool::RegisterDatabase(std::unique_ptr<IDbConnection> pDatabase, Mode DatabaseMode)
|
||||
{
|
||||
}
|
||||
|
||||
void CDbConnectionPool::Execute(
|
||||
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
|
||||
std::unique_ptr<ISqlData> pSqlRequestData)
|
||||
{
|
||||
}
|
||||
|
||||
void CDbConnectionPool::ExecuteWrite(
|
||||
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
|
||||
std::unique_ptr<ISqlData> pSqlRequestData)
|
||||
{
|
||||
}
|
||||
|
||||
void CDbConnectionPool::Shutdown()
|
||||
{
|
||||
}
|
46
src/engine/server/databases/connection_pool.h
Normal file
46
src/engine/server/databases/connection_pool.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef ENGINE_SERVER_DATABASES_CONNECTION_POOL_H
|
||||
#define ENGINE_SERVER_DATABASES_CONNECTION_POOL_H
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
#include <base/tl/threading.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
struct ISqlData
|
||||
{
|
||||
virtual ~ISqlData();
|
||||
};
|
||||
|
||||
class CDbConnectionPool
|
||||
{
|
||||
public:
|
||||
CDbConnectionPool();
|
||||
~CDbConnectionPool();
|
||||
|
||||
enum Mode
|
||||
{
|
||||
READ,
|
||||
WRITE,
|
||||
WRITE_BACKUP,
|
||||
NUM_MODES,
|
||||
};
|
||||
|
||||
void RegisterDatabase(std::unique_ptr<IDbConnection> pDatabase, Mode DatabaseMode);
|
||||
|
||||
void Execute(
|
||||
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
|
||||
std::unique_ptr<ISqlData> pSqlRequestData);
|
||||
// writes to WRITE_BACKUP server in case of failure
|
||||
void ExecuteWrite(
|
||||
bool (*pFuncPtr) (IDbConnection *, const ISqlData *),
|
||||
std::unique_ptr<ISqlData> pSqlRequestData);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<IDbConnection>> m_aapDbConnections[NUM_MODES];
|
||||
lock m_ConnectionLookupLock[NUM_MODES];
|
||||
};
|
||||
|
||||
#endif // ENGINE_SERVER_DATABASES_CONNECTION_POOL_H
|
Loading…
Reference in a new issue