Kea 2.7.6
isc::dhcp::HostDataSourceFactory Class Reference

Host Data Source Factory. More...

#include <host_data_source_factory.h>

Public Types

typedef std::function< std::string()> DBVersion
 Type of host mgr version.
 
typedef std::function< HostDataSourcePtr(const db::DatabaseConnection::ParameterMap &)> Factory
 Type of host data source factory.
 

Static Public Member Functions

static void add (HostDataSourceList &sources, const std::string &dbaccess)
 Create and add an instance of a host data source.
 
static bool del (HostDataSourceList &sources, const std::string &db_type)
 Delete a host data source.
 
static bool del (HostDataSourceList &sources, const std::string &db_type, const std::string &dbaccess, bool if_unusable=true)
 Delete a host data source.
 
static bool deregisterFactory (const std::string &db_type, bool no_log=false)
 Deregister a host data source factory.
 
static std::list< std::string > getDBVersions ()
 Return extended version info for registered backends.
 
static void logRegistered ()
 Logs out all registered backends.
 
static bool registeredFactory (const std::string &db_type)
 Check if a host data source factory was registered.
 
static bool registerFactory (const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
 Register a host data source factory.
 

Detailed Description

Host Data Source Factory.

This class comprises nothing but static methods used to create a host data source object. It analyzes the database information passed to the creation function and instantiates an appropriate host data source object based on the type requested.

Strictly speaking these functions could be stand-alone functions. However, it is convenient to encapsulate them in a class for naming purposes.

Definition at line 42 of file host_data_source_factory.h.

Member Typedef Documentation

◆ DBVersion

std::function<std::string ()> isc::dhcp::HostDataSourceFactory::DBVersion

Type of host mgr version.

Definition at line 103 of file host_data_source_factory.h.

◆ Factory

Type of host data source factory.

A factory takes a parameter map and returns a pointer to a host data source. In case of failure it must throw and not return null.

Definition at line 100 of file host_data_source_factory.h.

Member Function Documentation

◆ add()

void isc::dhcp::HostDataSourceFactory::add ( HostDataSourceList & sources,
const std::string & dbaccess )
static

Create and add an instance of a host data source.

Each database backend has its own host data source type. This static method adds an object of the appropriate type to a list of host data sources.

dbaccess is a generic way of passing parameters. Parameters are passed in the "name=value" format, separated by spaces. The data MUST include a keyword/value pair of the form "type=dbtype" giving the database type, e.q. "mysql" or "sqlite3".

Parameters
sourceshost data source list (new backend will be added here)
dbaccessDatabase access parameters. These are in the form of "keyword=value" pairs, separated by spaces. They are backend- -end specific, although must include the "type" keyword which gives the backend in use.
Exceptions
isc::InvalidParameterdbaccess string does not contain the "type" keyword.
isc::dhcp::InvalidTypeThe "type" keyword in dbaccess does not identify a supported backend.

Definition at line 32 of file host_data_source_factory.cc.

References isc_throw, and isc::db::DatabaseConnection::parse().

Referenced by isc::dhcp::HostMgr::addBackend().

+ Here is the call graph for this function:

◆ del() [1/2]

bool isc::dhcp::HostDataSourceFactory::del ( HostDataSourceList & sources,
const std::string & db_type )
static

Delete a host data source.

Delete the first instance of a host data source of the given type. This should have the effect of closing the database connection.

Parameters
sourceshost data source list.
db_typedatabase backend type.
Returns
true when found and removed, false when not found.

Definition at line 74 of file host_data_source_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::HOSTS_CFG_CLOSE_HOST_DATA_SOURCE, isc::dhcp::hosts_logger, and LOG_DEBUG.

Referenced by isc::dhcp::HostMgr::delBackend(), and isc::dhcp::HostMgr::delBackend().

◆ del() [2/2]

bool isc::dhcp::HostDataSourceFactory::del ( HostDataSourceList & sources,
const std::string & db_type,
const std::string & dbaccess,
bool if_unusable = true )
static

Delete a host data source.

Delete the first instance of a host data source which matches specific parameters. This should have the effect of closing the database connection.

Parameters
sourceshost data source list.
db_typedatabase backend type.
dbaccessDatabase access parameters. These are in the form of "keyword=value" pairs, separated by spaces. They are backend- -end specific, although must include the "type" keyword which gives the backend in use.
if_unusableflag which indicates if the host data source 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 89 of file host_data_source_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::HOSTS_CFG_CLOSE_HOST_DATA_SOURCE, isc::dhcp::hosts_logger, LOG_DEBUG, and isc::db::DatabaseConnection::parse().

+ Here is the call graph for this function:

◆ deregisterFactory()

bool isc::dhcp::HostDataSourceFactory::deregisterFactory ( const std::string & db_type,
bool no_log = false )
static

Deregister a host data source factory.

Disassociate the factory to a database type in the map. The no_log is to avoid logging during global object deinitialization.

Parameters
db_typedatabase type
no_logdo not log (default false)
Returns
true if the factory was successfully removed from the map, false if it was not found.

Definition at line 147 of file host_data_source_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::HOSTS_BACKEND_DEREGISTER, isc::dhcp::hosts_logger, and LOG_DEBUG.

◆ getDBVersions()

std::list< std::string > isc::dhcp::HostDataSourceFactory::getDBVersions ( )
static

Return extended version info for registered backends.

Definition at line 184 of file host_data_source_factory.cc.

References version().

Referenced by isc::dhcp::Dhcpv4Srv::getVersion(), and isc::dhcp::Dhcpv6Srv::getVersion().

+ Here is the call graph for this function:

◆ logRegistered()

void isc::dhcp::HostDataSourceFactory::logRegistered ( )
static

Logs out all registered backends.

We need a dedicated method for this, because we sometimes can't log the backend type when doing early initialization for backends initialized statically.

Definition at line 169 of file host_data_source_factory.cc.

References isc::dhcp::HOSTS_BACKENDS_REGISTERED, isc::dhcp::hosts_logger, and LOG_INFO.

Referenced by isc::dhcp::configureDhcp4Server(), and isc::dhcp::configureDhcp6Server().

◆ registeredFactory()

bool isc::dhcp::HostDataSourceFactory::registeredFactory ( const std::string & db_type)
static

Check if a host data source factory was registered.

Parameters
db_typedatabase type
Returns
true if a factory was registered for db_type, false if not.

Definition at line 163 of file host_data_source_factory.cc.

Referenced by isc::dhcp::CfgDbAccess::createManagers().

◆ registerFactory()

bool isc::dhcp::HostDataSourceFactory::registerFactory ( const std::string & db_type,
const Factory & factory,
bool no_log = false,
DBVersion db_version = DBVersion() )
static

Register a host data source factory.

Associate the factory to a database type in the map. The no_log is to avoid logging before the logger is initialized as when called at global object initialization.

Parameters
db_typedatabase type
factoryhost data source factory
no_logdo not log (default false)
db_versionhost mgr version
Returns
true if the factory was successfully added to the map, false if it already exists.

Definition at line 117 of file host_data_source_factory.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::HOSTS_BACKEND_REGISTER, isc::dhcp::hosts_logger, and LOG_DEBUG.


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