Kea 2.7.5
|
Server hook collection. More...
#include <server_hooks.h>
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 ServerHooks & | getServerHooks () |
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 |
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.
|
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:
For example, if the command_name is 'foo-bar', the resulting hook point name will be '$foo_bar'.
command_name | Command name for which the hook point name is to be generated. |
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().
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.
name | Name of the hook |
Definition at line 150 of file server_hooks.cc.
Referenced by isc::hooks::CalloutManager::registerCommandHook().
|
inline |
Return number of hooks.
Returns the total number of hooks registered.
Definition at line 133 of file server_hooks.h.
Referenced by isc::hooks::CalloutManager::registerCommandHook().
vector< string > isc::hooks::ServerHooks::getHookNames | ( | ) | const |
Get hook names.
Return list of hooks registered in the object.
Definition at line 160 of file server_hooks.cc.
int isc::hooks::ServerHooks::getIndex | ( | const std::string & | name | ) | const |
Get hook index.
Returns the index of a hook.
name | Name of the hook |
NoSuchHook | if 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::deregisterAllCallouts(), isc::hooks::CalloutManager::deregisterCallout(), getParkingLotPtr(), isc::hooks::CalloutManager::registerCallout(), and registerHook().
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.
index | Index of the hook |
NoSuchHook | if 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().
ParkingLotPtr isc::hooks::ServerHooks::getParkingLotPtr | ( | const int | hook_index | ) |
Returns pointer to the ParkingLot for the specified hook index.
hook_index | index of the hook point for which the parking lot should be returned. |
Definition at line 188 of file server_hooks.cc.
Referenced by isc::hooks::CalloutHandle::getParkingLotHandlePtr().
ParkingLotPtr isc::hooks::ServerHooks::getParkingLotPtr | ( | const std::string & | hook_name | ) |
Returns pointer to the ParkingLot for the specified hook name.
hook_name | name of the hook point for which the parking lot should be returned. |
Definition at line 193 of file server_hooks.cc.
References getIndex(), and getServerHooks().
ParkingLotsPtr isc::hooks::ServerHooks::getParkingLotsPtr | ( | ) | const |
Returns pointer to all parking lots.
Definition at line 183 of file server_hooks.cc.
|
static |
Return ServerHooks object.
Returns the global ServerHooks object.
Definition at line 172 of file server_hooks.cc.
References getServerHooksPtr().
Referenced by isc::hooks::CalloutManager::callCommandHandlers(), isc::hooks::HooksManager::clearParkingLots(), isc::hooks::CalloutManager::commandHandlersPresent(), isc::hooks::HooksManager::drop(), getParkingLotPtr(), isc::hooks::HooksManager::park(), isc::hooks::LibraryManager::prepareUnloadLibrary(), isc::dhcp::Dhcpv6Srv::processLocalizedQuery6(), isc::hooks::HooksManager::reference(), isc::hooks::CalloutManager::registerCommandHook(), isc::hooks::LibraryManager::registerStandardCallouts(), and isc::hooks::HooksManager::unpark().
|
static |
Returns pointer to ServerHooks object.
Definition at line 177 of file server_hooks.cc.
Referenced by getServerHooks(), and isc::config::HookedCommandMgr::handleCommand().
|
static |
Returns command name for a specified hook name.
This function removes leading dollar sign and replaces underscores with hyphens.
hook_name | Hook name for which command name should be returned. |
Definition at line 207 of file server_hooks.cc.
Referenced by isc::config::HookedCommandMgr::handleCommand().
int isc::hooks::ServerHooks::registerHook | ( | const std::string & | name | ) |
Register a hook.
Registers a hook and returns the hook index.
name | Name of the hook |
DuplicateHook | A hook with the same name has already been registered. |
Definition at line 44 of file server_hooks.cc.
References getIndex().
Referenced by isc::hooks::CalloutManager::registerCommandHook().
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.
isc::Unexpected | if 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.
|
static |
Index numbers for pre-defined hooks.
Definition at line 66 of file server_hooks.h.
Referenced by isc::hooks::CalloutHandle::CalloutHandle().
|
static |
Definition at line 67 of file server_hooks.h.
Referenced by isc::hooks::CalloutHandle::~CalloutHandle().