35 ServerHooks::ServerHooks() {
44 ServerHooks::registerHook(
const string& name) {
47 int index = hooks_.size();
48 pair<HookCollection::iterator, bool> result =
49 hooks_.insert(make_pair(name, index));
69 return (getIndex(name));
78 inverse_hooks_[index] = name;
87 ServerHooks::initialize() {
91 inverse_hooks_.clear();
95 int create = registerHook(
"context_create");
96 int destroy = registerHook(
"context_destroy");
99 if ((create != CONTEXT_CREATE) || (destroy != CONTEXT_DESTROY)) {
101 "context_create: expected = " << CONTEXT_CREATE <<
102 ", actual = " << create <<
103 ". context_destroy: expected = " << CONTEXT_DESTROY <<
104 ", actual = " << destroy);
111 ServerHooks::reset() {
124 ServerHooks::getName(
int index)
const {
127 InverseHookCollection::const_iterator i = inverse_hooks_.find(index);
128 if (i == inverse_hooks_.end()) {
138 ServerHooks::getIndex(
const string& name)
const {
141 HookCollection::const_iterator i = hooks_.find(name);
142 if (i == hooks_.end()) {
150 ServerHooks::findIndex(
const std::string& name)
const {
152 auto i = hooks_.find(name);
153 return ((i == hooks_.end()) ? -1 : i->second);
160 ServerHooks::getHookNames()
const {
162 vector<string> names;
163 HookCollection::const_iterator i;
164 for (i = hooks_.begin(); i != hooks_.end(); ++i) {
165 names.push_back(i->first);
174 ServerHooks::getServerHooks() {
175 return (*getServerHooksPtr());
179 ServerHooks::getServerHooksPtr() {
185 ServerHooks::getParkingLotsPtr()
const {
186 return (parking_lots_);
190 ServerHooks::getParkingLotPtr(
const int hook_index) {
191 return (parking_lots_->getParkingLotPtr(hook_index));
195 ServerHooks::getParkingLotPtr(
const std::string& hook_name) {
196 return (parking_lots_->getParkingLotPtr(getServerHooks().getIndex(hook_name)));
200 ServerHooks::commandToHookName(
const std::string& command_name) {
202 std::string hook_name = std::string(
"$") + command_name;
204 std::replace(hook_name.begin(), hook_name.end(),
'-',
'_');
209 ServerHooks::hookToCommandName(
const std::string& hook_name) {
210 if (!hook_name.empty() && hook_name.front() ==
'$') {
211 std::string command_name = hook_name.substr(1);
212 std::replace(command_name.begin(), command_name.end(),
'_',
'-');
213 return (command_name);
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< ParkingLot > ParkingLotPtr
Type of the pointer to the parking lot.
boost::shared_ptr< ServerHooks > ServerHooksPtr
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Collection of parking lots for various hook points.
const isc::log::MessageID HOOKS_HOOK_LIST_RESET
A generic exception that is thrown when an unexpected error condition occurs.
boost::shared_ptr< ParkingLots > ParkingLotsPtr
Type of the pointer to the parking lots.
Defines the logger used by the top-level component of kea-dhcp-ddns.
isc::log::Logger hooks_logger("hooks")
Hooks Logger.