11#include <boost/any.hpp> 
   12#include <boost/make_shared.hpp> 
   13#include <boost/shared_ptr.hpp> 
   19#include <unordered_map> 
   83    void park(T parked_object, std::function<
void()> unpark_callback) {
 
   84        std::lock_guard<std::mutex> lock(mutex_);
 
   85        auto it = find(parked_object);
 
   86        if (it != parking_.end()) {
 
   92        parking_[makeKey(parked_object)] = pinfo;
 
 
  106        std::lock_guard<std::mutex> lock(mutex_);
 
  107        auto it = find(parked_object);
 
  108        if (it == parking_.end()) {
 
  110                      " that has not been parked.");
 
  114        return (++it->second.refcount_);
 
 
  127        std::lock_guard<std::mutex> lock(mutex_);
 
  128        auto it = find(parked_object);
 
  129        if (it == parking_.end()) {
 
  131                      " that has not been parked.");
 
  135        return (--it->second.refcount_);
 
 
  152    bool unpark(T parked_object, 
bool force = 
false) {
 
  154        std::function<void()> 
cb;
 
  156            std::lock_guard<std::mutex> lock(mutex_);
 
  157            auto it = find(parked_object);
 
  158            if (it == parking_.end()) {
 
  164                it->second.refcount_ = 0;
 
  166                --it->second.refcount_;
 
  169            if (it->second.refcount_ <= 0) {
 
  171                cb = it->second.unpark_callback_;
 
 
  196        std::lock_guard<std::mutex> lock(mutex_);
 
  197        auto it = find(parked_object);
 
  198        if (it != parking_.end()) {
 
 
  210        std::lock_guard<std::mutex> lock(mutex_);
 
  211        return (parking_.size());
 
 
  237                    std::function<
void()> callback = 0)
 
 
  245        void update(
const boost::any& parked_object,
 
  246                    std::function<
void()> callback) {
 
 
 
  255    typedef std::unordered_map<std::string, ParkingInfo> ParkingInfoList;
 
  258    typedef ParkingInfoList::iterator ParkingInfoListIterator;
 
  261    ParkingInfoList parking_;
 
  269    std::string makeKey(T parked_object) {
 
  270        std::stringstream ss;
 
  271        ss << boost::any_cast<T>(parked_object);
 
  282    ParkingInfoListIterator find(T parked_object) {
 
  283        return (parking_.find(makeKey(parked_object)));
 
 
  314        : parking_lot_(parking_lot) {
 
 
  328        return (parking_lot_->reference(parked_object));
 
 
  341        return (parking_lot_->dereference(parked_object));
 
 
  357        return (parking_lot_->unpark(parked_object));
 
 
  370        return (parking_lot_->drop(parked_object));
 
 
 
  391        std::lock_guard<std::mutex> lock(mutex_);
 
  392        parking_lots_.clear();
 
 
  404        std::lock_guard<std::mutex> lock(mutex_);
 
  405        if (parking_lots_.count(hook_index) == 0) {
 
  406            parking_lots_[hook_index] = boost::make_shared<ParkingLot>();
 
  408        return (parking_lots_[hook_index]);
 
 
  414    std::unordered_map<int, ParkingLotPtr> parking_lots_;
 
 
A generic exception that is thrown if a function is called in a prohibited way.
bool drop(T parked_object)
Removes parked object without calling a callback.
bool unpark(T parked_object)
Signals that the object should be unparked.
int reference(T parked_object)
Increases reference counter for the parked object.
int dereference(T parked_object)
Decreases the reference counter for the parked object.
ParkingLotHandle(const ParkingLotPtr &parking_lot)
Constructor.
Parking lot for objects, e.g.
bool unpark(T parked_object, bool force=false)
Signals that the object should be unparked.
bool drop(T parked_object)
Removes parked object without calling a callback.
size_t size()
Returns the current number of objects.
int dereference(T parked_object)
Decreases the reference counter for the parked object.
int reference(T parked_object)
Increases reference counter for the parked object.
void park(T parked_object, std::function< void()> unpark_callback)
Parks an object.
Collection of parking lots for various hook points.
ParkingLotPtr getParkingLotPtr(const int hook_index)
Returns pointer to the parking lot for a hook points.
void clear()
Removes all parked objects.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< ParkingLots > ParkingLotsPtr
Type of the pointer to the parking lots.
boost::shared_ptr< ParkingLotHandle > ParkingLotHandlePtr
Pointer to the parking lot handle.
boost::shared_ptr< ParkingLot > ParkingLotPtr
Type of the pointer to the parking lot.
Defines the logger used by the top-level component of kea-lfc.
Holds information about parked object.
int refcount_
The current reference count.
boost::any parked_object_
The parked object.
void update(const boost::any &parked_object, std::function< void()> callback)
Update parking information.
ParkingInfo(const boost::any &parked_object, std::function< void()> callback=0)
Constructor.
ParkingInfo()
Constructor.
std::function< void()> unpark_callback_
The pointer to callback.