Kea 2.7.0
isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType > Class Template Reference

Base class for Configuration Backend Managers (CBM). More...

#include <base_config_backend_mgr.h>

Public Types

typedef boost::shared_ptr< ConfigBackendPoolType > ConfigBackendPoolPtr
 Pointer to the configuration backend pool.
 
typedef std::function< typename ConfigBackendPoolType::ConfigBackendTypePtr(const db::DatabaseConnection::ParameterMap &) Factory)
 Type of the backend factory function.
 

Public Member Functions

 BaseConfigBackendMgr ()
 Constructor.
 
void addBackend (const std::string &dbaccess)
 Create an instance of a configuration backend.
 
void delAllBackends ()
 Removes all backends from the pool.
 
bool delBackend (const std::string &db_type, const std::string &dbaccess, bool if_unusable)
 Delete a config backend manager.
 
ConfigBackendPoolPtr getPool () const
 Returns underlying config backend pool.
 
bool registerBackendFactory (const std::string &db_type, const Factory &factory)
 Registers new backend factory function for a given backend type.
 
bool unregisterBackendFactory (const std::string &db_type)
 Unregisters the backend factory function for a given backend type.
 

Protected Attributes

std::map< std::string, Factoryfactories_
 A map holding registered backend factory functions.
 
ConfigBackendPoolPtr pool_
 Pointer to the configuration backends pool.
 

Detailed Description

template<typename ConfigBackendPoolType>
class isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >

Base class for Configuration Backend Managers (CBM).

Each Kea server supporting Configuration Backend feature implements a "manager" class which holds information about supported and configured backends and provides access to the backends. This is similar to HostMgr and LeaseMgr singletons being used by the DHCP servers.

The Config Backend Managers are typically implemented as singletons which can be accessed from any place within the server code. This includes server configuration, data fetching during normal server operation and data management, including processing of control commands implemented within hooks libraries.

The BaseConfigBackendMgr is a base class for all CBMs implemented for respective Kea servers. It includes mechanisms to register config backend factory functions and to create instances of the backends using those factory functions as a result of server configuration. The mechanism of factory functions registration is useful in cases when the config backend is implemented within the hook library. Such hook library registers factory function in its load function and the server simply calls this function to create the instance of this backend when instructed to do so via configuration. Similar mechanism exists in DHCP HostMgr.

Unlike HostMgr, the CBMs do not directly expose API to fetch and manipulate the data in the database. This is done via, so called, Configuration Backends Pools. See BaseConfigBackendPool for details. The BaseConfigBackendMgr is provided with the pool type via class template parameter. Respective CBM implementations use their own pools, which provide APIs appropriate for those implementations.

Template Parameters
ConfgBackendPoolTypeType of the configuration backend pool to be used by the manager. It must derive from BaseConfigBackendPool template class.

Definition at line 59 of file base_config_backend_mgr.h.

Member Typedef Documentation

◆ ConfigBackendPoolPtr

template<typename ConfigBackendPoolType >
typedef boost::shared_ptr<ConfigBackendPoolType> isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::ConfigBackendPoolPtr

Pointer to the configuration backend pool.

Definition at line 63 of file base_config_backend_mgr.h.

◆ Factory

template<typename ConfigBackendPoolType >
typedef std::function<typename ConfigBackendPoolType::ConfigBackendTypePtr (const db::DatabaseConnection::ParameterMap&) isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::Factory)

Type of the backend factory function.

Factory function returns a pointer to the instance of the configuration backend created.

Definition at line 70 of file base_config_backend_mgr.h.

Constructor & Destructor Documentation

◆ BaseConfigBackendMgr()

template<typename ConfigBackendPoolType >
isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::BaseConfigBackendMgr ( )
inline

Constructor.

Definition at line 73 of file base_config_backend_mgr.h.

Member Function Documentation

◆ addBackend()

template<typename ConfigBackendPoolType >
void isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::addBackend ( const std::string & dbaccess)
inline

Create an instance of a configuration backend.

This method uses provided dbaccess string representing database connection information to create an instance of the database backend. If the specified backend type is not supported, i.e. there is no relevant factory function registered, an exception is thrown.

Parameters
dbaccessDatabase access string being a collection of key=value pairs.
Exceptions
InvalidParameterif access string lacks database type value.
db::InvalidTypeif the type of the database backend is not supported.
Unexpectedif the backend factory function returned NULL.

Definition at line 148 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_, isc_throw, isc::db::DatabaseConnection::parse(), and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.

+ Here is the call graph for this function:

◆ delAllBackends()

template<typename ConfigBackendPoolType >
void isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::delAllBackends ( )
inline

Removes all backends from the pool.

Definition at line 181 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.

◆ delBackend()

template<typename ConfigBackendPoolType >
bool isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::delBackend ( const std::string & db_type,
const std::string & dbaccess,
bool if_unusable )
inline

Delete a config backend manager.

Delete the first instance of a config database manager which matches specific parameters. This should have the effect of closing the database connection.

Parameters
db_typeBackend to remove.
dbaccessDatabase access string being a collection of key=value pairs.
if_unusableFlag which indicates if the config backend should be deleted only if it is unusable.
Returns
false when not removed because it is not found or because it is still usable (if_unusable is true), true otherwise.

Definition at line 198 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.

◆ getPool()

template<typename ConfigBackendPoolType >
ConfigBackendPoolPtr isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::getPool ( ) const
inline

Returns underlying config backend pool.

Definition at line 204 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.

◆ registerBackendFactory()

template<typename ConfigBackendPoolType >
bool isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::registerBackendFactory ( const std::string & db_type,
const Factory & factory )
inline

Registers new backend factory function for a given backend type.

The typical usage of this function is to make the CBM aware of a configuration backend implementation. This implementation may exist in a hooks library. In such case, this function should be called from the load function in this library. When the backend is registered, the server will use it when required by the configuration, i.e. a user includes configuration backend of that type in the "config-databases" list.

If the backend of the given type has already been registered, perhaps by another hooks library, the CBM will refuse to register another backend of the same type.

Parameters
db_typeBackend type, e.g. "mysql".
factoryPointer to the backend factory function.
Returns
true if the backend has been successfully registered, false if another backend of this type already exists.

Definition at line 96 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_.

◆ unregisterBackendFactory()

template<typename ConfigBackendPoolType >
bool isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::unregisterBackendFactory ( const std::string & db_type)
inline

Unregisters the backend factory function for a given backend type.

This function is used to remove the factory function and all backend instances for a given backend type. Typically, it would be called when unloading the a config backend hook library, and thus called by the library's unload function.

Parameters
db_typeBackend type, e.g. "mysql".
Returns
false if no factory for the given type was unregistered, true if the factory was removed.

Definition at line 119 of file base_config_backend_mgr.h.

References isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_, and isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::pool_.

Member Data Documentation

◆ factories_

template<typename ConfigBackendPoolType >
std::map<std::string, Factory> isc::cb::BaseConfigBackendMgr< ConfigBackendPoolType >::factories_
protected

◆ pool_


The documentation for this class was generated from the following file: