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) ||
 
   99        (
static_cast<size_t>(hook_index) >= hook_vector_.size())) {
 
  101                  " is not valid for the list of registered hooks");
 
  105    return (!hook_vector_[hook_index].empty());
 
 
  153        for (
auto const& i : hook_vector_[hook_index]) {
 
  163                int status = (*i.second)(callout_handle);
 
  179            } 
catch (
const std::exception& e) {
 
  200                    .arg(
"Unspecified exception")
 
 
  236    checkLibraryIndex(library_index);
 
  239    ensureHookLibsVectorSize();
 
  243    int hook_index = server_hooks_.getIndex(name);
 
  246    if (
static_cast<size_t>(hook_index) >= hook_vector_.size()) {
 
  252    CalloutEntry target(library_index, callout);
 
  257    size_t initial_size = hook_vector_[hook_index].size();
 
  268    hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
 
  269                                             hook_vector_[hook_index].end(),
 
  270                                             [&target] (CalloutEntry x) {
 
  271                                                 return (x == target); }),
 
  272                                   hook_vector_[hook_index].end());
 
  275    bool removed = initial_size != hook_vector_[hook_index].size();
 
 
  289    ensureHookLibsVectorSize();
 
  293    int hook_index = server_hooks_.getIndex(name);
 
  297    CalloutEntry target(library_index, 
static_cast<CalloutPtr>(0));
 
  302    size_t initial_size = hook_vector_[hook_index].size();
 
  305    hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
 
  306                                             hook_vector_[hook_index].end(),
 
  307                                             [&target] (CalloutEntry x) {
 
  308                                                 return (x.first == target.first);
 
  310                                   hook_vector_[hook_index].end());
 
  313    bool removed = initial_size != hook_vector_[hook_index].size();
 
 
  325    ensureHookLibsVectorSize();
 
  329    if (hook_index < 0) {
 
  337        hook_vector_.resize(server_hooks_.getCount());
 
 
  342CalloutManager::ensureHookLibsVectorSize() {
 
  344    if (
static_cast<size_t>(
hooks.getCount()) > hook_vector_.size()) {
 
  346        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.
static std::string commandToHookName(const std::string &command_name)
Generates hook point name for the given control command 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.