Kea 2.5.8
isc::hooks::ServerHooks Class Reference

Server hook collection. More...

#include <server_hooks.h>

+ Inheritance diagram for isc::hooks::ServerHooks:

Public Member Functions

int findIndex (const std::string &name) const
 Find hook index.
 
int getCount () const
 Return number of hooks.
 
std::vector< std::string > getHookNames () const
 Get hook names.
 
int getIndex (const std::string &name) const
 Get hook index.
 
std::string getName (int index) const
 Get hook name.
 
ParkingLotPtr getParkingLotPtr (const int hook_index)
 Returns pointer to the ParkingLot for the specified hook index.
 
ParkingLotPtr getParkingLotPtr (const std::string &hook_name)
 Returns pointer to the ParkingLot for the specified hook name.
 
ParkingLotsPtr getParkingLotsPtr () const
 Returns pointer to all parking lots.
 
int registerHook (const std::string &name)
 Register a hook.
 
void reset ()
 Reset to Initial State.
 

Static Public Member Functions

static std::string commandToHookName (const std::string &command_name)
 Generates hook point name for the given control command name.
 
static ServerHooksgetServerHooks ()
 Return ServerHooks object.
 
static ServerHooksPtr getServerHooksPtr ()
 Returns pointer to ServerHooks object.
 
static std::string hookToCommandName (const std::string &hook_name)
 Returns command name for a specified hook name.
 

Static Public Attributes

static const int CONTEXT_CREATE = 0
 Index numbers for pre-defined hooks.
 
static const int CONTEXT_DESTROY = 1
 

Detailed Description

Server hook collection.

This class is used by the server-side code to register hooks - points in the server processing at which libraries can register functions (callouts) that the server will call. These functions can modify data and so affect the processing of the server.

The ServerHooks class is little more than a wrapper around the std::map class. It stores a hook, assigning to it a unique index number. This number is then used by the server code to identify the hook being called. (Although it would be feasible to use a name as an index, using an integer will speed up the time taken to locate the callouts, which may make a difference in a frequently-executed piece of code.)

ServerHooks is a singleton object and is only accessible by the static method getServerHooks().

Definition at line 62 of file server_hooks.h.

Member Function Documentation

◆ commandToHookName()

std::string isc::hooks::ServerHooks::commandToHookName ( const std::string &  command_name)
static

Generates hook point name for the given control command name.

This function is called to generate the name of the hook point when the hook point is used to install command handlers for the given control command.

The name of the hook point is generated as follows:

  • command name is prefixed with a dollar sign,
  • all hyphens are replaced with underscores.

For example, if the command_name is 'foo-bar', the resulting hook point name will be '$foo_bar'.

Parameters
command_nameCommand name for which the hook point name is to be generated.
Returns
Hook point name, or an empty string if the command name can't be converted to a hook name (e.g. when it lacks dollar sign).

Definition at line 198 of file server_hooks.cc.

Referenced by isc::hooks::CalloutManager::callCommandHandlers(), isc::hooks::CalloutManager::commandHandlersPresent(), isc::hooks::LibraryHandle::registerCommandCallout(), and isc::hooks::CalloutManager::registerCommandHook().

◆ findIndex()

int isc::hooks::ServerHooks::findIndex ( const std::string &  name) const

Find hook index.

Provides exception safe method of retrieving an index of the specified hook.

Parameters
nameName of the hook
Returns
Index of the hook if the hook point exists, or -1 if the hook point doesn't exist.

Definition at line 150 of file server_hooks.cc.

Referenced by isc::hooks::CalloutManager::commandHandlersPresent(), and isc::hooks::CalloutManager::registerCommandHook().

◆ getCount()

int isc::hooks::ServerHooks::getCount ( ) const
inline

Return number of hooks.

Returns the total number of hooks registered.

Returns
Number of hooks registered.

Definition at line 133 of file server_hooks.h.

Referenced by isc::hooks::CalloutManager::registerCommandHook().

◆ getHookNames()

vector< string > isc::hooks::ServerHooks::getHookNames ( ) const

Get hook names.

Return list of hooks registered in the object.

Returns
Vector of strings holding hook names.

Definition at line 160 of file server_hooks.cc.

Referenced by isc::hooks::LibraryManager::prepareUnloadLibrary(), and isc::hooks::LibraryManager::registerStandardCallouts().

◆ getIndex()

int isc::hooks::ServerHooks::getIndex ( const std::string &  name) const

Get hook index.

Returns the index of a hook.

Parameters
nameName of the hook
Returns
Index of the hook, to be used in subsequent calls.
Exceptions
NoSuchHookif the hook name is unknown to the caller.

Definition at line 138 of file server_hooks.cc.

References isc_throw.

Referenced by isc::hooks::CalloutManager::callCommandHandlers(), isc::hooks::CalloutManager::deregisterAllCallouts(), isc::hooks::CalloutManager::deregisterCallout(), getParkingLotPtr(), isc::hooks::CalloutManager::registerCallout(), and registerHook().

◆ getName()

std::string isc::hooks::ServerHooks::getName ( int  index) const

Get hook name.

Returns the name of a hook given the index. This is most likely to be used in log messages.

Parameters
indexIndex of the hook
Returns
Name of the hook.
Exceptions
NoSuchHookif the hook index is invalid.

Definition at line 124 of file server_hooks.cc.

References isc_throw.

Referenced by isc::hooks::CalloutManager::callCallouts(), and isc::hooks::CalloutHandle::getHookName().

◆ getParkingLotPtr() [1/2]

ParkingLotPtr isc::hooks::ServerHooks::getParkingLotPtr ( const int  hook_index)

Returns pointer to the ParkingLot for the specified hook index.

Parameters
hook_indexindex of the hook point for which the parking lot should be returned.
Returns
Pointer to the ParkingLot object.

Definition at line 188 of file server_hooks.cc.

Referenced by isc::hooks::CalloutHandle::getParkingLotHandlePtr().

◆ getParkingLotPtr() [2/2]

ParkingLotPtr isc::hooks::ServerHooks::getParkingLotPtr ( const std::string &  hook_name)

Returns pointer to the ParkingLot for the specified hook name.

Parameters
hook_namename of the hook point for which the parking lot should be returned.
Returns
Pointer to the ParkingLot object.

Definition at line 193 of file server_hooks.cc.

References getIndex(), and getServerHooks().

+ Here is the call graph for this function:

◆ getParkingLotsPtr()

ParkingLotsPtr isc::hooks::ServerHooks::getParkingLotsPtr ( ) const

Returns pointer to all parking lots.

Returns
pointer to all parking lots.

Definition at line 183 of file server_hooks.cc.

Referenced by isc::hooks::HooksManager::clearParkingLots().

◆ getServerHooks()

◆ getServerHooksPtr()

ServerHooksPtr isc::hooks::ServerHooks::getServerHooksPtr ( )
static

Returns pointer to ServerHooks object.

Returns
Pointer to the global ServerHooks object.

Definition at line 177 of file server_hooks.cc.

Referenced by getServerHooks(), and isc::config::HookedCommandMgr::handleCommand().

◆ hookToCommandName()

std::string isc::hooks::ServerHooks::hookToCommandName ( const std::string &  hook_name)
static

Returns command name for a specified hook name.

This function removes leading dollar sign and replaces underscores with hyphens.

Parameters
hook_nameHook name for which command name should be returned.
Returns
Command name.

Definition at line 207 of file server_hooks.cc.

Referenced by isc::config::HookedCommandMgr::handleCommand().

◆ registerHook()

int isc::hooks::ServerHooks::registerHook ( const std::string &  name)

Register a hook.

Registers a hook and returns the hook index.

Parameters
nameName of the hook
Returns
Index of the hook, to be used in subsequent hook-related calls. This will be greater than or equal to zero (so allowing a negative value to indicate an invalid index).
Exceptions
DuplicateHookA hook with the same name has already been registered.
Todo:
: We also need to call CalloutManager::ensureVectorSize(), so it adjusts its vector. Since CalloutManager is not a singleton, there's no getInstance() or similar. Also, CalloutManager uses ServerHooks, so such a call would induce circular dependencies. Ugh.
Todo:
: See ticket 5251 and 5208 for details.

Definition at line 44 of file server_hooks.cc.

References getIndex().

Referenced by isc::hooks::CalloutManager::registerCommandHook().

+ Here is the call graph for this function:

◆ reset()

void isc::hooks::ServerHooks::reset ( )

Reset to Initial State.

Resets the collection of hooks to the initial state, with just the context_create and context_destroy hooks set. This used during testing to reset the global ServerHooks object; it should never be used in production.

Exceptions
isc::Unexpectedif the registration of the pre-defined hooks fails in some way.

Definition at line 111 of file server_hooks.cc.

References isc::hooks::HOOKS_HOOK_LIST_RESET, isc::hooks::hooks_logger, and LOG_WARN.

Member Data Documentation

◆ CONTEXT_CREATE

const int isc::hooks::ServerHooks::CONTEXT_CREATE = 0
static

Index numbers for pre-defined hooks.

Definition at line 66 of file server_hooks.h.

Referenced by isc::hooks::CalloutHandle::CalloutHandle().

◆ CONTEXT_DESTROY

const int isc::hooks::ServerHooks::CONTEXT_DESTROY = 1
static

Definition at line 67 of file server_hooks.h.

Referenced by isc::hooks::CalloutHandle::~CalloutHandle().


The documentation for this class was generated from the following files: