7#ifndef BASE_CONFIG_BACKEND_MGR_H
8#define BASE_CONFIG_BACKEND_MGR_H
14#include <boost/shared_ptr.hpp>
58template<
typename ConfigBackendPoolType>
69 typedef std::function<
typename ConfigBackendPoolType::ConfigBackendTypePtr
104 factories_.insert(std::make_pair(db_type, factory));
126 pool_->delAllBackends(db_type);
154 db::DatabaseConnection::ParameterMap::iterator it = parameters.find(
"type");
155 if (it == parameters.end()) {
160 std::string db_type = it->second;
165 if ((db_type ==
"mysql") || (db_type ==
"postgresql")) {
166 std::string with = (db_type ==
"postgresql" ?
"pgsql" : db_type);
168 "support for configuration database type: " << db_type
169 <<
". Did you forget to use --with-"
170 << with <<
" during compilation or to load libdhcp_"
171 << with <<
" hook library?");
174 db_type <<
"' is not supported");
178 auto backend = index->second(parameters);
181 " factory returned NULL");
185 pool_->addBackend(backend);
190 pool_->delAllBackends();
206 bool delBackend(
const std::string& db_type,
const std::string& dbaccess,
208 return (
pool_->del(db_type, dbaccess, if_unusable));
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
Base class for Configuration Backend Managers (CBM).
bool delBackend(const std::string &db_type, const std::string &dbaccess, bool if_unusable)
Delete a config backend manager.
bool registerBackendFactory(const std::string &db_type, const Factory &factory)
Registers new backend factory function for a given backend type.
void addBackend(const std::string &dbaccess)
Create an instance of a configuration backend.
BaseConfigBackendMgr()
Constructor.
ConfigBackendPoolPtr getPool() const
Returns underlying config backend pool.
std::function< typename ConfigBackendPoolType::ConfigBackendTypePtr(const db::DatabaseConnection::ParameterMap &)> Factory
Type of the backend factory function.
boost::shared_ptr< ConfigBackendPoolType > ConfigBackendPoolPtr
Pointer to the configuration backend pool.
void delAllBackends()
Removes all backends from the pool.
std::map< std::string, Factory > factories_
A map holding registered backend factory functions.
bool unregisterBackendFactory(const std::string &db_type)
Unregisters the backend factory function for a given backend type.
ConfigBackendPoolPtr pool_
Pointer to the configuration backends pool.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.