From: Razvan Becheriu Date: Thu, 18 Mar 2021 21:32:07 +0000 (+0200) Subject: [#1621] addressed comments X-Git-Tag: Kea-1.9.6~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d976bf91f315b505aa629459f102f7a871b330b0;p=thirdparty%2Fkea.git [#1621] addressed comments --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 6b1acb9b14..c9b596939a 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -48,7 +48,7 @@ MySqlConfigBackendImpl:: MySqlConfigBackendImpl(const DatabaseConnection::ParameterMap& parameters, const DbCallback db_reconnect_callback) : conn_(parameters, - IOServiceAccessCallbackPtr(new IOServiceAccessCallback(MySqlConfigBackendImpl::getIOService)), + IOServiceAccessorPtr(new IOServiceAccessor(MySqlConfigBackendImpl::getIOService)), db_reconnect_callback), timer_name_(""), audit_revision_created_(false), parameters_(parameters) { // Test schema version first. diff --git a/src/lib/database/database_connection.h b/src/lib/database/database_connection.h index 5ae2b2209d..3d69895e95 100644 --- a/src/lib/database/database_connection.h +++ b/src/lib/database/database_connection.h @@ -172,12 +172,17 @@ typedef boost::shared_ptr ReconnectCtlPtr; /// @brief Defines a callback prototype for propagating events upward typedef std::function DbCallback; -/// @brief Callback which returns the IOService that can be used to recover the +/// @brief Function which returns the IOService that can be used to recover the /// connection. -typedef std::function IOServiceAccessCallback; - -/// @brief Pointer to an instance of IOServiceAccessCallbackPtr -typedef boost::shared_ptr IOServiceAccessCallbackPtr; +/// +/// This accessor is used to lazy retrieve the IOService when the connection is +/// lost. It is useful to retrieve it at a later time to support hook libraries +/// which create managers on load and set IOService later on by using the +/// dhcp4_srv_configured and dhcp6_srv_configured hooks. +typedef std::function IOServiceAccessor; + +/// @brief Pointer to an instance of IOServiceAccessor +typedef boost::shared_ptr IOServiceAccessorPtr; /// @brief Common database connection class. /// diff --git a/src/lib/dhcpsrv/mysql_host_data_source.cc b/src/lib/dhcpsrv/mysql_host_data_source.cc index e2e482213d..df50155e4d 100644 --- a/src/lib/dhcpsrv/mysql_host_data_source.cc +++ b/src/lib/dhcpsrv/mysql_host_data_source.cc @@ -1951,10 +1951,10 @@ public: /// @brief Constructor /// /// @param parameters See MySqlHostMgr constructor. - /// @param io_service_access_callback The IOService access callback. + /// @param io_service_accessor The IOService accessor function. /// @param db_reconnect_callback The connection recovery callback. MySqlHostContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback); /// The exchange objects are used for transfer of data to/from the database. @@ -2731,9 +2731,9 @@ TaggedStatementArray tagged_statements = { { // MySqlHostContext Constructor MySqlHostContext::MySqlHostContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback) - : conn_(parameters, io_service_access_callback, db_reconnect_callback), + : conn_(parameters, io_service_accessor, db_reconnect_callback), is_readonly_(true) { } @@ -2808,7 +2808,7 @@ MySqlHostDataSourceImpl::MySqlHostDataSourceImpl(const DatabaseConnection::Param MySqlHostContextPtr MySqlHostDataSourceImpl::createContext() const { MySqlHostContextPtr ctx(new MySqlHostContext(parameters_, - IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&HostMgr::getIOService)), + IOServiceAccessorPtr(new IOServiceAccessor(&HostMgr::getIOService)), &MySqlHostDataSourceImpl::dbReconnect)); // Open the database. diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 2c9abe76a5..f7668540ea 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -1737,9 +1737,9 @@ bool MySqlLeaseStatsQuery::negative_count_ = false; // MySqlLeaseContext Constructor MySqlLeaseContext::MySqlLeaseContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, DbCallback db_reconnect_callback) - : conn_(parameters, io_service_access_callback, db_reconnect_callback) { + : conn_(parameters, io_service_accessor, db_reconnect_callback) { } // MySqlLeaseContextAlloc Constructor and Destructor @@ -1881,7 +1881,7 @@ MySqlLeaseMgr::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) { MySqlLeaseContextPtr MySqlLeaseMgr::createContext() const { MySqlLeaseContextPtr ctx(new MySqlLeaseContext(parameters_, - IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&LeaseMgr::getIOService)), + IOServiceAccessorPtr(new IOServiceAccessor(&LeaseMgr::getIOService)), &MySqlLeaseMgr::dbReconnect)); // Open the database. diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.h b/src/lib/dhcpsrv/mysql_lease_mgr.h index 6b428e4560..edad80c4a6 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.h +++ b/src/lib/dhcpsrv/mysql_lease_mgr.h @@ -44,10 +44,10 @@ public: /// @brief Constructor /// /// @param parameters See MySqlLeaseMgr constructor. - /// @param io_service_access_callback The IOService access callback. + /// @param io_service_accessor The IOService accessor function. /// @param db_reconnect_callback The connection recovery callback. MySqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters, - db::IOServiceAccessCallbackPtr io_service_access_callback, + db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback); /// The exchange objects are used for transfer of data to/from the database. diff --git a/src/lib/dhcpsrv/pgsql_host_data_source.cc b/src/lib/dhcpsrv/pgsql_host_data_source.cc index 6fec6459a9..1f5164494d 100644 --- a/src/lib/dhcpsrv/pgsql_host_data_source.cc +++ b/src/lib/dhcpsrv/pgsql_host_data_source.cc @@ -1313,10 +1313,10 @@ public: /// @brief Constructor /// /// @param parameters See PgSqlHostMgr constructor. - /// @param io_service_access_callback The IOService access callback. + /// @param io_service_accessor The IOService accessor function. /// @param db_reconnect_callback The connection recovery callback. PgSqlHostContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback); /// The exchange objects are used for transfer of data to/from the database. @@ -2172,9 +2172,9 @@ TaggedStatementArray tagged_statements = { { // PgSqlHostContext Constructor PgSqlHostContext::PgSqlHostContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback) - : conn_(parameters, io_service_access_callback, db_reconnect_callback), + : conn_(parameters, io_service_accessor, db_reconnect_callback), is_readonly_(true) { } @@ -2249,7 +2249,7 @@ PgSqlHostDataSourceImpl::PgSqlHostDataSourceImpl(const DatabaseConnection::Param PgSqlHostContextPtr PgSqlHostDataSourceImpl::createContext() const { PgSqlHostContextPtr ctx(new PgSqlHostContext(parameters_, - IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&HostMgr::getIOService)), + IOServiceAccessorPtr(new IOServiceAccessor(&HostMgr::getIOService)), &PgSqlHostDataSourceImpl::dbReconnect)); // Open the database. diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.cc b/src/lib/dhcpsrv/pgsql_lease_mgr.cc index eed79d2eec..8b009f7e27 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.cc +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.cc @@ -1171,9 +1171,9 @@ bool PgSqlLeaseStatsQuery::negative_count_ = false; // PgSqlLeaseContext Constructor PgSqlLeaseContext::PgSqlLeaseContext(const DatabaseConnection::ParameterMap& parameters, - IOServiceAccessCallbackPtr io_service_access_callback, + IOServiceAccessorPtr io_service_accessor, DbCallback db_reconnect_callback) - : conn_(parameters, io_service_access_callback, db_reconnect_callback) { + : conn_(parameters, io_service_accessor, db_reconnect_callback) { } // PgSqlLeaseContextAlloc Constructor and Destructor @@ -1315,7 +1315,7 @@ PgSqlLeaseMgr::dbReconnect(ReconnectCtlPtr db_reconnect_ctl) { PgSqlLeaseContextPtr PgSqlLeaseMgr::createContext() const { PgSqlLeaseContextPtr ctx(new PgSqlLeaseContext(parameters_, - IOServiceAccessCallbackPtr(new IOServiceAccessCallback(&LeaseMgr::getIOService)), + IOServiceAccessorPtr(new IOServiceAccessor(&LeaseMgr::getIOService)), &PgSqlLeaseMgr::dbReconnect)); // Open the database. diff --git a/src/lib/dhcpsrv/pgsql_lease_mgr.h b/src/lib/dhcpsrv/pgsql_lease_mgr.h index f420058954..6ea58ca0c1 100644 --- a/src/lib/dhcpsrv/pgsql_lease_mgr.h +++ b/src/lib/dhcpsrv/pgsql_lease_mgr.h @@ -43,10 +43,10 @@ public: /// @brief Constructor /// /// @param parameters See PgSqlLeaseMgr constructor. - /// @param io_service_access_callback The IOService access callback. + /// @param io_service_accessor The IOService accessor function. /// @param db_reconnect_callback The connection recovery callback. PgSqlLeaseContext(const db::DatabaseConnection::ParameterMap& parameters, - db::IOServiceAccessCallbackPtr io_service_access_callback, + db::IOServiceAccessorPtr io_service_accessor, db::DbCallback db_reconnect_callback); /// The exchange objects are used for transfer of data to/from the database. diff --git a/src/lib/mysql/mysql_connection.h b/src/lib/mysql/mysql_connection.h index 43e804eb57..dff65e9d3b 100644 --- a/src/lib/mysql/mysql_connection.h +++ b/src/lib/mysql/mysql_connection.h @@ -241,13 +241,12 @@ public: /// Initialize MySqlConnection object with parameters needed for connection. /// /// @param parameters Specify the connection details. - /// @param io_access_callback The IOService access callback. + /// @param io_accessor The IOService accessor function. /// @param callback The connection recovery callback. MySqlConnection(const ParameterMap& parameters, - IOServiceAccessCallbackPtr io_access_callback = IOServiceAccessCallbackPtr(), + IOServiceAccessorPtr io_accessor = IOServiceAccessorPtr(), DbCallback callback = DbCallback()) - : DatabaseConnection(parameters), - io_service_access_callback_(io_access_callback), + : DatabaseConnection(parameters), io_service_accessor_(io_accessor), io_service_(), callback_(callback) { } @@ -659,9 +658,9 @@ public: /// @note The recover function must be run on the IO Service thread. void startRecoverDbConnection() { if (callback_) { - if (!io_service_ && io_service_access_callback_) { - io_service_ = (*io_service_access_callback_)(); - io_service_access_callback_.reset(); + if (!io_service_ && io_service_accessor_) { + io_service_ = (*io_service_accessor_)(); + io_service_accessor_.reset(); } if (io_service_) { @@ -688,9 +687,14 @@ public: /// and will be from MySqlHostDataSource. MySqlHolder mysql_; - /// @brief Callback which returns the IOService that can be used to recover - /// the connection. - IOServiceAccessCallbackPtr io_service_access_callback_; + /// @brief Accessor function which returns the IOService that can be used to + /// recover the connection. + /// + /// This accessor is used to lazy retrieve the IOService when the connection + /// is lost. It is useful to retrieve it at a later time to support hook + /// libraries which create managers on load and set IOService later on by + /// using the dhcp4_srv_configured and dhcp6_srv_configured hooks. + IOServiceAccessorPtr io_service_accessor_; /// @brief IOService object, used for all ASIO operations. isc::asiolink::IOServicePtr io_service_; diff --git a/src/lib/pgsql/pgsql_connection.h b/src/lib/pgsql/pgsql_connection.h index c2503b77ea..e338446e12 100644 --- a/src/lib/pgsql/pgsql_connection.h +++ b/src/lib/pgsql/pgsql_connection.h @@ -307,13 +307,12 @@ public: /// Initialize PgSqlConnection object with parameters needed for connection. /// /// @param parameters Specify the connection details. - /// @param io_access_callback The IOService access callback. + /// @param io_accessor The IOService accessor function. /// @param callback The connection recovery callback. PgSqlConnection(const ParameterMap& parameters, - IOServiceAccessCallbackPtr io_access_callback = IOServiceAccessCallbackPtr(), + IOServiceAccessorPtr io_accessor = IOServiceAccessorPtr(), DbCallback callback = DbCallback()) - : DatabaseConnection(parameters), - io_service_access_callback_(io_access_callback), + : DatabaseConnection(parameters), io_service_accessor_(io_accessor), io_service_(), callback_(callback) { } @@ -427,9 +426,9 @@ public: /// @note The recover function must be run on the IO Service thread. void startRecoverDbConnection() { if (callback_) { - if (!io_service_ && io_service_access_callback_) { - io_service_ = (*io_service_access_callback_)(); - io_service_access_callback_.reset(); + if (!io_service_ && io_service_accessor_) { + io_service_ = (*io_service_accessor_)(); + io_service_accessor_.reset(); } if (io_service_) { @@ -459,9 +458,14 @@ public: return (conn_); } - /// @brief Callback which returns the IOService that can be used to recover - /// the connection. - IOServiceAccessCallbackPtr io_service_access_callback_; + /// @brief Accessor function which returns the IOService that can be used to + /// recover the connection. + /// + /// This accessor is used to lazy retrieve the IOService when the connection + /// is lost. It is useful to retrieve it at a later time to support hook + /// libraries which create managers on load and set IOService later on by + /// using the dhcp4_srv_configured and dhcp6_srv_configured hooks. + IOServiceAccessorPtr io_service_accessor_; /// @brief IOService object, used for all ASIO operations. isc::asiolink::IOServicePtr io_service_;