15#include <boost/static_assert.hpp>
29 : server_hooks_(
ServerHooks::getServerHooks()), current_library_(-1),
30 hook_vector_(
ServerHooks::getServerHooks().getCount()),
31 library_handle_(*this), pre_library_handle_(*this, 0),
32 post_library_handle_(*this, INT_MAX), num_libraries_(num_libraries) {
33 if (num_libraries < 0) {
35 "CalloutManager must be >= 0");
44CalloutManager::checkLibraryIndex(
int library_index)
const {
45 if (((library_index >= -1) && (library_index <= num_libraries_)) ||
46 (library_index == INT_MAX)) {
50 isc_throw(NoSuchLibrary,
"library index " << library_index <<
51 " is not valid for the number of loaded libraries (" <<
52 num_libraries_ <<
")");
62 .arg(library_index).arg(name);
65 checkLibraryIndex(library_index);
68 ensureHookLibsVectorSize();
72 int hook_index = server_hooks_.
getIndex(name);
77 for (CalloutVector::iterator i = hook_vector_[hook_index].begin();
78 i != hook_vector_[hook_index].end(); ++i) {
79 if (i->first > library_index) {
82 hook_vector_[hook_index].insert(i, make_pair(library_index,
91 hook_vector_[hook_index].push_back(make_pair(library_index, callout));
98 if ((hook_index < 0) || (hook_index >= hook_vector_.size())) {
100 " is not valid for the list of registered hooks");
104 return (!hook_vector_[hook_index].empty());
152 for (
auto const& i : hook_vector_[hook_index]) {
162 int status = (*i.second)(callout_handle);
178 }
catch (
const std::exception& e) {
199 .arg(
"Unspecified exception")
235 checkLibraryIndex(library_index);
238 ensureHookLibsVectorSize();
242 int hook_index = server_hooks_.
getIndex(name);
245 if (hook_index >= hook_vector_.size()) {
251 CalloutEntry target(library_index, callout);
256 size_t initial_size = hook_vector_[hook_index].size();
267 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
268 hook_vector_[hook_index].end(),
269 [&target] (CalloutEntry x) {
270 return (x == target); }),
271 hook_vector_[hook_index].end());
274 bool removed = initial_size != hook_vector_[hook_index].size();
288 ensureHookLibsVectorSize();
292 int hook_index = server_hooks_.
getIndex(name);
296 CalloutEntry target(library_index,
static_cast<CalloutPtr>(0));
301 size_t initial_size = hook_vector_[hook_index].size();
304 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
305 hook_vector_[hook_index].end(),
306 [&target] (CalloutEntry x) {
307 return (x.first == target.first);
309 hook_vector_[hook_index].end());
312 bool removed = initial_size != hook_vector_[hook_index].size();
324 ensureHookLibsVectorSize();
328 if (hook_index < 0) {
336 hook_vector_.resize(server_hooks_.
getCount());
341CalloutManager::ensureHookLibsVectorSize() {
343 if (hooks.
getCount() > hook_vector_.size()) {
345 hook_vector_.resize(hooks.
getCount());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Per-packet callout handle.
void setCurrentLibrary(int library_index)
Set current library index.
@ NEXT_STEP_CONTINUE
continue normally
@ NEXT_STEP_DROP
drop the packet
void setStatus(const CalloutNextStep next)
Sets the next processing step.
void setCurrentHook(int hook_index)
Set current hook index.
int getCurrentHook() const
Get current hook index.
int getCurrentLibrary() const
Get current library index.
void callCallouts(int hook_index, CalloutHandle &callout_handle)
Calls the callouts for a given hook.
bool commandHandlersPresent(const std::string &command_name) const
Checks if control command handlers are present for the specified command.
void callCommandHandlers(const std::string &command_name, CalloutHandle &callout_handle)
Calls the callouts/command handlers for a given command name.
CalloutManager(int num_libraries=0)
Constructor.
bool deregisterAllCallouts(const std::string &name, int library_index)
Removes all callouts on a hook for the current library.
bool deregisterCallout(const std::string &name, CalloutPtr callout, int library_index)
De-Register a callout on a hook for the current library.
bool calloutsPresent(int hook_index) const
Checks if callouts are present on a hook.
void registerCommandHook(const std::string &command_name)
Registers a hook point for the specified command name.
void registerCallout(const std::string &name, CalloutPtr callout, int library_index)
Register a callout on a hook for the current library.
Local class for conversion of void pointers to function pointers.
void * dlsymPtr() const
Return pointer returned by dlsym call.
int getIndex(const std::string &name) const
Get hook index.
static ServerHooks & getServerHooks()
Return ServerHooks object.
int findIndex(const std::string &name) const
Find hook index.
int getCount() const
Return number of hooks.
static std::string commandToHookName(const std::string &command_name)
Generates hook point name for the given control command name.
int registerHook(const std::string &name)
Register a hook.
std::string getName(int index) const
Get hook name.
Utility class to measure code execution times.
void stop()
Stops the stopwatch.
void start()
Starts the stopwatch.
std::string logFormatTotalDuration() const
Returns the total measured duration in the format directly usable in the log messages.
std::string logFormatLastDuration() const
Returns the last measured duration in the format directly usable in log messages.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
const int HOOKS_DBG_EXTENDED_CALLS
const isc::log::MessageID HOOKS_CALLOUTS_COMPLETE
const isc::log::MessageID HOOKS_CALLOUT_EXCEPTION
const isc::log::MessageID HOOKS_CALLOUTS_BEGIN
const isc::log::MessageID HOOKS_CALLOUT_REGISTRATION
const int HOOKS_DBG_CALLS
isc::log::Logger callouts_logger("callouts")
Callouts logger.
const isc::log::MessageID HOOKS_ALL_CALLOUTS_DEREGISTERED
const isc::log::MessageID HOOKS_CALLOUT_ERROR
const isc::log::MessageID HOOKS_CALLOUT_DEREGISTERED
const isc::log::MessageID HOOKS_CALLOUT_CALLED
Defines the logger used by the top-level component of kea-lfc.