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&
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
#ifndef HOST_MGR_H
#define HOST_MGR_H
+#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
namespace isc {
/// 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.
/// 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();
+
};
}
}