13#include <boost/foreach.hpp>
14#include <boost/tuple/tuple.hpp>
30 return (result.second);
67 auto range = idx.equal_range(boost::make_tuple(type, subnet_id, lease_type));
68 if (range.first != range.second) {
70 if (std::find_if(range.first, range.second,
71 [&owner] (
const Callback& cb) ->
bool {
72 return (cb.owner == owner);
75 <<
", for subnet ID " << subnet_id
77 <<
" has already been registered in the lease manager");
97 auto range = idx.equal_range(boost::make_tuple(subnet_id, lease_type));
98 if (range.first != range.second) {
99 idx.erase(range.first, range.second);
117 return (
"add_lease");
119 return (
"update_lease");
121 return (
"delete_lease");
139 auto cbs = idx.equal_range(boost::make_tuple(type, subnet_id, lease->getType()));
140 if (cbs.first == cbs.second) {
143 BOOST_FOREACH(
auto const& cb, cbs) {
146 }
catch (
const std::exception& ex) {
150 .arg(lease->addr_.toText())
156 .arg(lease->addr_.toText());
A generic exception that is thrown if a function is called in a prohibited way.
Introduces callbacks into the LeaseMgr.
CallbackType
An enumeration differentiating between lease write operations.
bool isLocked(const LeasePtr &lease)
Checks if the lease is locked.
void trackAddLease(const LeasePtr &lease)
Invokes the callbacks when a new lease is added.
void unlock(const LeasePtr &lease)
Attempts to unlock a lease.
void trackUpdateLease(const LeasePtr &lease)
Invokes the callbacks when a lease is updated.
void runCallbacks(CallbackType type, const LeasePtr &lease)
Runs registered callbacks of the particular type.
void trackDeleteLease(const LeasePtr &lease)
Invokes the callbacks when a lease is deleted.
boost::multi_index_container< Callback, boost::multi_index::indexed_by< boost::multi_index::ordered_non_unique< boost::multi_index::composite_key< Callback, boost::multi_index::member< Callback, CallbackType, &Callback::type >, boost::multi_index::member< Callback, SubnetID, &Callback::subnet_id >, boost::multi_index::member< Callback, Lease::Type, &Callback::lease_type > > >, boost::multi_index::ordered_non_unique< boost::multi_index::composite_key< Callback, boost::multi_index::member< Callback, SubnetID, &Callback::subnet_id >, boost::multi_index::member< Callback, Lease::Type, &Callback::lease_type > > > > > CallbackContainer
A multi-index container holding registered callbacks.
void unregisterCallbacks(SubnetID subnet_id, Lease::Type lease_type)
Unregisters all callbacks for a given subnet identifier.
static std::string callbackTypeToString(CallbackType type)
Converts callback type to string for logging purposes.
void registerCallback(CallbackType type, std::string owner, SubnetID subnet_id, Lease::Type lease_type, CallbackFn callback_fn)
Registers a callback function for a subnet.
bool tryLock(const LeasePtr &lease)
Attempts to lock a lease.
std::unordered_set< asiolink::IOAddress, asiolink::IOAddress::Hash > locked_leases_
A set of locked leases.
TrackingLeaseMgr()
Constructor.
void runCallbacksForSubnetID(CallbackType type, SubnetID subnet_id, const LeasePtr &lease)
Runs registered callbacks of the particular type for a subnet id.
CallbackContainerPtr callbacks_
The multi-index container holding registered callbacks.
void unregisterAllCallbacks()
Unregisters all callbacks.
std::function< void(LeasePtr)> CallbackFn
Type of a callback function invoked upon a lease insertion, update or deletion.
bool hasCallbacks() const
Checks if any callbacks have been registered.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_LEASE_MGR_CALLBACK_UNKNOWN_EXCEPTION
const isc::log::MessageID DHCPSRV_LEASE_MGR_CALLBACK_EXCEPTION
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
boost::shared_ptr< Lease > LeasePtr
Pointer to the lease object.
Defines the logger used by the top-level component of kea-lfc.
Type
Type of lease or pool.
static std::string typeToText(Type type)
returns text representation of a lease type
A structure representing a registered callback.