Commit 1c6d459b authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3561] HostMgr now uses alternate host data source, if specified.

parent 9b2b59ba
......@@ -44,6 +44,9 @@ HostMgr::getHostMgrPtr() {
void
HostMgr::create(const std::string&) {
getHostMgrPtr().reset(new HostMgr());
/// @todo Initialize alternate_source here, using the parameter.
/// For example: alternate_source.reset(new MysqlHostDataSource(access)).
}
HostMgr&
......@@ -57,29 +60,51 @@ HostMgr::instance() {
ConstHostCollection
HostMgr::getAll(const HWAddrPtr& hwaddr, const DuidPtr& duid) const {
return (getCfgHosts()->getAll(hwaddr, duid));
ConstHostCollection hosts = getCfgHosts()->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);
}
ConstHostCollection
HostMgr::getAll4(const IOAddress& address) const {
ConstHostCollection hosts = getCfgHosts()->getAll4(address);
if (alternate_source) {
ConstHostCollection hosts_plus = alternate_source->getAll4(address);
hosts.insert(hosts.end(), hosts_plus.begin(), hosts_plus.end());
}
return (getCfgHosts()->getAll4(address));
}
ConstHostPtr
HostMgr::get4(const SubnetID& subnet_id, const HWAddrPtr& hwaddr,
const DuidPtr& duid) const {
return (getCfgHosts()->get4(subnet_id, hwaddr, duid));
ConstHostPtr host = getCfgHosts()->get4(subnet_id, hwaddr, duid);
if (!host && alternate_source) {
host = alternate_source->get4(subnet_id, hwaddr, duid);
}
return (host);
}
ConstHostPtr
HostMgr::get6(const SubnetID& subnet_id, const DuidPtr& duid,
const HWAddrPtr& hwaddr) const {
return (getCfgHosts()->get6(subnet_id, duid, hwaddr));
ConstHostPtr host = getCfgHosts()->get6(subnet_id, duid, hwaddr);
if (!host && alternate_source) {
host = alternate_source->get6(subnet_id, duid, hwaddr);
}
return (host);
}
ConstHostPtr
HostMgr::get6(const IOAddress& prefix, const uint8_t prefix_len) const {
return (getCfgHosts()->get6(prefix, prefix_len));
ConstHostPtr host = getCfgHosts()->get6(prefix, prefix_len);
if (!host && alternate_source) {
host = alternate_source->get6(prefix, prefix_len);
}
return (host);
}
void
......
......@@ -15,6 +15,7 @@
#ifndef HOST_MGR_H
#define HOST_MGR_H
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
namespace isc {
......@@ -54,7 +55,7 @@ namespace dhcp {
/// reservations specified in the configuration file) can't be disabled.
///
/// @todo Implement alternate host data sources: MySQL, PostgreSQL, etc.
class HostMgr : public BaseHostDataSource {
class HostMgr : public boost::noncopyable, BaseHostDataSource {
public:
/// @brief Creates new instance of the @c HostMgr.
......@@ -158,14 +159,23 @@ public:
/// This method will throw an exception if no alternate data source is
/// in use.
///
/// @param Pointer to the new @c Host object being added.
/// @param host Pointer to the new @c Host object being added.
virtual void add(const HostPtr& host);
private:
/// @brief Private default constructor.
HostMgr() { }
/// @brief Pointer to an alternate host data source.
///
/// If this pointer is NULL, the source is not in use.
boost::scoped_ptr<BaseHostDataSource> alternate_source;
/// @brief Returns a pointer to the currently used instance of the
/// @c HostMgr.
static boost::scoped_ptr<HostMgr>& getHostMgrPtr();
};
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment