19 mutex ResourceHandler::mutex_;
21 ResourceHandler::ResourceContainer ResourceHandler::resources_;
23 ResourceHandler::ResourceHandler() : owned_() {
27 lock_guard<mutex> lock_(mutex_);
28 for (
auto res : owned_) {
29 unLockInternal(res->type_, res->addr_);
34 ResourceHandler::ResourcePtr
36 auto key = boost::make_tuple(type, addr.
toBytes());
37 auto it = resources_.find(key);
38 if (it == resources_.end()) {
39 return (ResourcePtr());
45 ResourceHandler::lock(
Lease::Type type,
const asiolink::IOAddress& addr) {
46 ResourcePtr res(
new Resource(type, addr));
48 resources_.insert(res);
54 const asiolink::IOAddress& addr) {
55 auto key = boost::make_tuple(type, addr.toBytes());
56 auto it = resources_.find(key);
57 if (it == resources_.end()) {
67 lock_guard<mutex> lock_(mutex_);
68 holder = lookup(type, addr);
78 auto key = boost::make_tuple(type, addr.
toBytes());
79 lock_guard<mutex> lock_(mutex_);
80 auto it = owned_.find(key);
81 return (it != owned_.end());
86 auto key = boost::make_tuple(type, addr.
toBytes());
87 lock_guard<mutex> lock_(mutex_);
88 auto it = owned_.find(key);
89 if (it == owned_.end()) {
93 unLockInternal(type, addr);
static std::string typeToText(Type type)
returns text representation of a lease type
virtual ~ResourceHandler()
Destructor.
std::vector< uint8_t > toBytes() const
Return address as set of bytes.
bool tryLock(Lease::Type type, const asiolink::IOAddress &addr)
Tries to acquires a resource.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void unLock(Lease::Type type, const asiolink::IOAddress &addr)
Releases a resource.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Type
Type of lease or pool.
std::string toText() const
Convert the address to a string.
A generic exception that is thrown when an object can not be found.
The IOAddress class represents an IP addresses (version agnostic)
bool isLocked(Lease::Type type, const asiolink::IOAddress &addr)
Checks if a resource is owned by this handler.