15 #include <boost/static_assert.hpp> 28 CalloutManager::CalloutManager(
int num_libraries)
30 current_hook_(-1), current_library_(-1),
31 hook_vector_(
ServerHooks::getServerHooks().getCount()),
32 library_handle_(this), pre_library_handle_(this, 0),
33 post_library_handle_(this, INT_MAX), num_libraries_(num_libraries)
35 if (num_libraries < 0) {
37 "CalloutManager must be >= 0");
47 CalloutManager::checkLibraryIndex(
int library_index)
const {
48 if (((library_index >= -1) && (library_index <= num_libraries_)) ||
49 (library_index == INT_MAX)) {
53 isc_throw(NoSuchLibrary,
"library index " << library_index <<
54 " is not valid for the number of loaded libraries (" <<
55 num_libraries_ <<
")");
64 .arg(current_library_).arg(name);
67 checkLibraryIndex(current_library_);
70 ensureHookLibsVectorSize();
74 int hook_index = server_hooks_.
getIndex(name);
79 for (CalloutVector::iterator i = hook_vector_[hook_index].begin();
80 i != hook_vector_[hook_index].end(); ++i) {
81 if (i->first > current_library_) {
84 hook_vector_[hook_index].insert(i, make_pair(current_library_,
93 hook_vector_[hook_index].push_back(make_pair(current_library_, callout));
101 if ((hook_index < 0) || (hook_index >= hook_vector_.size())) {
103 " is not valid for the list of registered hooks");
107 return (!hook_vector_[hook_index].empty());
147 current_hook_ = hook_index;
154 CalloutVector callouts(hook_vector_[hook_index]);
162 .arg(server_hooks_.
getName(current_hook_));
165 for (CalloutVector::const_iterator i = callouts.begin();
166 i != callouts.end(); ++i) {
170 current_library_ = i->first;
175 int status = (*i->second)(callout_handle);
179 HOOKS_CALLOUT_CALLED).arg(current_library_)
180 .arg(server_hooks_.
getName(current_hook_))
185 .arg(current_library_)
186 .arg(server_hooks_.
getName(current_hook_))
190 }
catch (
const std::exception& e) {
196 .arg(current_library_)
197 .arg(server_hooks_.
getName(current_hook_))
208 .arg(server_hooks_.
getName(current_hook_))
214 current_library_ = -1;
237 checkLibraryIndex(current_library_);
240 ensureHookLibsVectorSize();
244 int hook_index = server_hooks_.
getIndex(name);
247 if (hook_index >= hook_vector_.size()) {
253 CalloutEntry target(current_library_, callout);
258 size_t initial_size = hook_vector_[hook_index].size();
269 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
270 hook_vector_[hook_index].end(),
271 bind1st(equal_to<CalloutEntry>(),
273 hook_vector_[hook_index].end());
276 bool removed = initial_size != hook_vector_[hook_index].size();
279 HOOKS_CALLOUT_DEREGISTERED).arg(current_library_).arg(name);
291 ensureHookLibsVectorSize();
295 int hook_index = server_hooks_.
getIndex(name);
299 CalloutEntry target(current_library_, static_cast<CalloutPtr>(0));
304 size_t initial_size = hook_vector_[hook_index].size();
307 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
308 hook_vector_[hook_index].end(),
309 bind1st(CalloutLibraryEqual(),
311 hook_vector_[hook_index].end());
314 bool removed = initial_size != hook_vector_[hook_index].size();
317 HOOKS_ALL_CALLOUTS_DEREGISTERED).arg(current_library_)
328 ensureHookLibsVectorSize();
332 if (hook_index < 0) {
340 hook_vector_.resize(server_hooks_.
getCount());
345 CalloutManager::ensureHookLibsVectorSize() {
347 if (hooks.
getCount() > hook_vector_.size()) {
349 hook_vector_.resize(hooks.
getCount());
void setStatus(const CalloutNextStep next)
Sets the next processing step.
const int HOOKS_DBG_EXTENDED_CALLS
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
void registerCommandHook(const std::string &command_name)
Registers a hook point for the specified command name.
int findIndex(const std::string &name) const
Find hook index.
void callCallouts(int hook_index, CalloutHandle &callout_handle)
Calls the callouts for a given hook.
void registerCallout(const std::string &name, CalloutPtr callout)
Register a callout on a hook for the current library.
static ServerHooks & getServerHooks()
Return ServerHooks object.
bool commandHandlersPresent(const std::string &command_name) const
Checks if control command handlers are present for the specified command.
int getCount() const
Return number of hooks.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
std::string getName(int index) const
Get hook name.
void * dlsymPtr() const
Return pointer returned by dlsym call.
Local class for conversion of void pointers to function pointers.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
void stop()
Stops the stopwatch.
isc::log::Logger callouts_logger("callouts")
Callouts logger.
bool deregisterCallout(const std::string &name, CalloutPtr callout)
De-Register a callout on a hook for the current library.
Per-packet callout handle.
bool calloutsPresent(int hook_index) const
Checks if callouts are present on a hook.
Utility class to measure code execution times.
std::string logFormatLastDuration() const
Returns the last measured duration in the format directly usable in log messages.
bool deregisterAllCallouts(const std::string &name)
Removes all callouts on a hook for the current library.
const int HOOKS_DBG_CALLS
Defines the logger used by the top-level component of kea-dhcp-ddns.
static std::string commandToHookName(const std::string &command_name)
Generates hook point name for the given control command name.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
int getIndex(const std::string &name) const
Get hook index.
std::string logFormatTotalDuration() const
Returns the total measured duration in the format directly usable in the log messages.
void callCommandHandlers(const std::string &command_name, CalloutHandle &callout_handle)
Calls the callouts/command handlers for a given command name.
int registerHook(const std::string &name)
Register a hook.
void start()
Starts the stopwatch.