27 : server_hooks_(
ServerHooks::getServerHooks()), current_library_(-1),
28 hook_vector_(
ServerHooks::getServerHooks().getCount()),
29 library_handle_(*this), pre_library_handle_(*this, 0),
30 post_library_handle_(*this, INT_MAX), num_libraries_(num_libraries) {
31 if (num_libraries < 0) {
33 "CalloutManager must be >= 0");
42CalloutManager::checkLibraryIndex(
int library_index)
const {
43 if (((library_index >= -1) && (library_index <= num_libraries_)) ||
44 (library_index == INT_MAX)) {
48 isc_throw(NoSuchLibrary,
"library index " << library_index <<
49 " is not valid for the number of loaded libraries (" <<
50 num_libraries_ <<
")");
60 .arg(library_index).arg(name);
63 checkLibraryIndex(library_index);
66 ensureHookLibsVectorSize();
70 int hook_index = server_hooks_.getIndex(name);
75 for (CalloutVector::iterator i = hook_vector_[hook_index].begin();
76 i != hook_vector_[hook_index].end(); ++i) {
77 if (i->first > library_index) {
80 hook_vector_[hook_index].insert(i, make_pair(library_index,
89 hook_vector_[hook_index].push_back(make_pair(library_index, callout));
96 if ((hook_index < 0) ||
97 (
static_cast<size_t>(hook_index) >= hook_vector_.size())) {
99 " is not valid for the list of registered hooks");
103 return (!hook_vector_[hook_index].empty());
151 for (
auto const& i : hook_vector_[hook_index]) {
161 int status = (*i.second)(callout_handle);
177 }
catch (
const std::exception& e) {
198 .arg(
"Unspecified exception")
234 checkLibraryIndex(library_index);
237 ensureHookLibsVectorSize();
241 int hook_index = server_hooks_.getIndex(name);
244 if (
static_cast<size_t>(hook_index) >= hook_vector_.size()) {
250 CalloutEntry target(library_index, callout);
255 size_t initial_size = hook_vector_[hook_index].size();
266 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
267 hook_vector_[hook_index].end(),
268 [&target] (CalloutEntry x) {
269 return (x == target); }),
270 hook_vector_[hook_index].end());
273 bool removed = initial_size != hook_vector_[hook_index].size();
287 ensureHookLibsVectorSize();
291 int hook_index = server_hooks_.getIndex(name);
295 CalloutEntry target(library_index,
static_cast<CalloutPtr>(0));
300 size_t initial_size = hook_vector_[hook_index].size();
303 hook_vector_[hook_index].erase(remove_if(hook_vector_[hook_index].begin(),
304 hook_vector_[hook_index].end(),
305 [&target] (CalloutEntry x) {
306 return (x.first == target.first);
308 hook_vector_[hook_index].end());
311 bool removed = initial_size != hook_vector_[hook_index].size();
323 ensureHookLibsVectorSize();
327 if (hook_index < 0) {
335 hook_vector_.resize(server_hooks_.getCount());
340CalloutManager::ensureHookLibsVectorSize() {
342 if (
static_cast<size_t>(
hooks.getCount()) > hook_vector_.size()) {
344 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.