Parcourir la source

[3569_rebase] alternate_source renamed, added comments

Tomek Mrugalski il y a 9 ans
Parent
commit
08499ad49c

+ 25 - 17
src/lib/dhcpsrv/host_mgr.cc

@@ -49,12 +49,20 @@ HostMgr::create(const std::string& access) {
     getHostMgrPtr().reset(new HostMgr());
 
     if (!access.empty()) {
+        // If the user specified parameters, let's pass them to the create
+        // method. It will destroy any prior instances and will create
+        // the new one.
         HostDataSourceFactory::create(access);
-
+    } else {
+        // Ok, no parameters were specified. We should destroy the existing
+        // insteance.
+        HostDataSourceFactory::destroy();
     }
 
-    // Now store the host data source pointer.
-    getHostMgrPtr()->alternate_source = HostDataSourceFactory::getHostDataSourcePtr();
+    // Now store the host data source pointer. It may be NULL. That's ok as
+    // NULL value indicates that there's no host data source configured.
+    getHostMgrPtr()->alternate_source_ =
+        HostDataSourceFactory::getHostDataSourcePtr();
 }
 
 HostMgr&
@@ -69,8 +77,8 @@ HostMgr::instance() {
 ConstHostCollection
 HostMgr::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
     ConstHostCollection hosts = getCfgHosts()->getAll(hwaddr, duid);
-    if (alternate_source) {
-        ConstHostCollection hosts_plus = alternate_source->getAll(hwaddr, duid);
+    if (alternate_source_) {
+        ConstHostCollection hosts_plus = alternate_source_->getAll(hwaddr, duid);
         hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
     }
     return (hosts);
@@ -79,8 +87,8 @@ HostMgr::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
 ConstHostCollection
 HostMgr::getAll4(const IOAddress& address) const {
     ConstHostCollection hosts = getCfgHosts()->getAll4(address);
-    if (alternate_source) {
-        ConstHostCollection hosts_plus = alternate_source->getAll4(address);
+    if (alternate_source_) {
+        ConstHostCollection hosts_plus = alternate_source_->getAll4(address);
         hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
     }
     return (hosts);
@@ -90,13 +98,13 @@ ConstHostPtr
 HostMgr::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
               const DuidPtr& duid) const {
     ConstHostPtr host = getCfgHosts()->get4(subnet_id, hwaddr, duid);
-    if (!host && alternate_source) {
+    if (!host && alternate_source_) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
                   HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_HWADDR_DUID)
             .arg(subnet_id)
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)")
             .arg(duid ? duid->toText() : "(duid)");
-        host = alternate_source->get4(subnet_id, hwaddr, duid);
+        host = alternate_source_->get4(subnet_id, hwaddr, duid);
     }
     return (host);
 }
@@ -105,12 +113,12 @@ ConstHostPtr
 HostMgr::get4(const SubnetID& subnet_id,
               const asiolink::IOAddress& address) const {
     ConstHostPtr host = getCfgHosts()->get4(subnet_id, address);
-    if (!host && alternate_source) {
+    if (!host && alternate_source_) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
                   HOSTS_MGR_ALTERNATE_GET4_SUBNET_ID_ADDRESS4)
             .arg(subnet_id)
             .arg(address.toText());
-        host = alternate_source->get4(subnet_id, address);
+        host = alternate_source_->get4(subnet_id, address);
     }
     return (host);
 }
@@ -120,13 +128,13 @@ ConstHostPtr
 HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
                const HWAddrPtr& hwaddr) const {
     ConstHostPtr host = getCfgHosts()->get6(subnet_id, duid, hwaddr);
-    if (!host && alternate_source) {
+    if (!host && alternate_source_) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
                   HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_DUID_HWADDR)
             .arg(subnet_id)
             .arg(duid ? duid->toText() : "(duid)")
             .arg(hwaddr ? hwaddr->toText() : "(no-hwaddr)");
-        host = alternate_source->get6(subnet_id, duid, hwaddr);
+        host = alternate_source_->get6(subnet_id, duid, hwaddr);
     }
     return (host);
 }
@@ -134,12 +142,12 @@ HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
 ConstHostPtr
 HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len) const {
     ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
-    if (!host && alternate_source) {
+    if (!host && alternate_source_) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
                   HOSTS_MGR_ALTERNATE_GET6_PREFIX)
             .arg(prefix.toText())
             .arg(static_cast<int>(prefix_len));
-        host = alternate_source->get6(prefix, prefix_len);
+        host = alternate_source_->get6(prefix, prefix_len);
     }
     return (host);
 }
@@ -148,12 +156,12 @@ ConstHostPtr
 HostMgr::get6(const SubnetID& subnet_id,
               const asiolink::IOAddress& addr) const {
     ConstHostPtr host = getCfgHosts()->get6(subnet_id, addr);
-    if (!host && alternate_source) {
+    if (!host && alternate_source_) {
         LOG_DEBUG(hosts_logger, HOSTS_DBG_TRACE,
                   HOSTS_MGR_ALTERNATE_GET6_SUBNET_ID_ADDRESS6)
             .arg(subnet_id)
             .arg(addr.toText());
-        host = alternate_source->get6(subnet_id, addr);
+        host = alternate_source_->get6(subnet_id, addr);
     }
     return (host);
 }

+ 2 - 2
src/lib/dhcpsrv/host_mgr.h

@@ -212,7 +212,7 @@ public:
     /// May return NULL
     /// @return pointer to the host data source (or NULL)
     HostDataSourcePtr getHostDataSource() const {
-        return (alternate_source);
+        return (alternate_source_);
     }
 
 private:
@@ -223,7 +223,7 @@ private:
     /// @brief Pointer to an alternate host data source.
     ///
     /// If this pointer is NULL, the source is not in use.
-    HostDataSourcePtr alternate_source;
+    HostDataSourcePtr alternate_source_;
 
     /// @brief Returns a pointer to the currently used instance of the
     /// @c HostMgr.

+ 3 - 2
src/lib/dhcpsrv/parsers/dbaccess_parser.cc

@@ -155,8 +155,9 @@ DbAccessParser::commit() {
     case HOSTS_DB:
     {
         // Let's instantiate HostMgr with new parameters. Note that HostMgr's
-        // constructor will call HostDataSourceFactory::create() with appropriate
-        // parameters.
+        // create method will call HostDataSourceFactory::create() with
+        // appropriate parameters. It will also destroy a pre-existing
+        // instance, if it existed.
         HostMgr::create(getDbAccessString());
         break;
     }