Kea  2.1.7-git
isc::dhcp::HostDataSourceFactory Class Reference

Host Data Source Factory. More...

#include <host_data_source_factory.h>

Public Types

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

Static Public Member Functions

static void add (HostDataSourceList &sources, const std::string &dbaccess)
 Create and add an instance of a host data source. More...
 
static bool del (HostDataSourceList &sources, const std::string &db_type)
 Delete a host data source. More...
 
static bool del (HostDataSourceList &sources, const std::string &db_type, const std::string &dbaccess, bool if_unusable=true)
 Delete a host data source. More...
 
static bool deregisterFactory (const std::string &db_type, bool no_log=false)
 Deregister a host data source factory. More...
 
static void printRegistered ()
 Prints out all registered backends. More...
 
static bool registeredFactory (const std::string &db_type)
 Check if a host data source factory was registered. More...
 
static bool registerFactory (const std::string &db_type, const Factory &factory, bool no_log=false)
 Register a host data source factory. More...
 

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 43 of file host_data_source_factory.h.

Member Typedef Documentation

◆ 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 101 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 42 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 83 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().

◆ 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 98 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 146 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.

◆ printRegistered()

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

Prints 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 168 of file host_data_source_factory.cc.

References isc::dhcp::DHCPSRV_MYSQL_HOST_DB, isc::dhcp::DHCPSRV_PGSQL_HOST_DB, isc::dhcp::HOSTS_BACKENDS_REGISTERED, isc::dhcp::hosts_logger, LOG_INFO, and isc::db::DatabaseConnection::redactedAccessString().

+ Here is the call graph for this function:

◆ 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 162 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 
)
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)
Returns
true if the factory was successfully added to the map, false if it already exists.

Definition at line 126 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: