Kea 1.5.0
callout_manager.h
Go to the documentation of this file.
1// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef CALLOUT_MANAGER_H
8#define CALLOUT_MANAGER_H
9
12#include <hooks/server_hooks.h>
13
14#include <boost/shared_ptr.hpp>
15
16#include <climits>
17#include <map>
18#include <string>
19
20namespace isc {
21namespace hooks {
22
27class NoSuchLibrary : public Exception {
28public:
29 NoSuchLibrary(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) {}
31};
32
133
135private:
136
137 // Private typedefs
138
142 typedef std::pair<int, CalloutPtr> CalloutEntry;
143
146 typedef std::vector<CalloutEntry> CalloutVector;
147
148public:
149
158 CalloutManager(int num_libraries = 0);
159
173 void registerCallout(const std::string& name, CalloutPtr callout);
174
190 bool deregisterCallout(const std::string& name, CalloutPtr callout);
191
203 bool deregisterAllCallouts(const std::string& name);
204
215 bool calloutsPresent(int hook_index) const;
216
226 bool commandHandlersPresent(const std::string& command_name) const;
227
239 void callCallouts(int hook_index, CalloutHandle& callout_handle);
240
254 void callCommandHandlers(const std::string& command_name,
255 CalloutHandle& callout_handle);
256
267 void registerCommandHook(const std::string& command_name);
268
273 int getHookIndex() const {
274 return (current_hook_);
275 }
276
283 int getNumLibraries() const {
284 return (num_libraries_);
285 }
286
299 int getLibraryIndex() const {
300 return (current_library_);
301 }
302
317 void setLibraryIndex(int library_index) {
318 checkLibraryIndex(library_index);
319 current_library_ = library_index;
320 }
321
330 // callouts to run prior to user-library callouts.
333
334
345 return (library_handle_);
346 }
347
355 return (pre_library_handle_);
356 }
357
365 return (post_library_handle_);
366 }
367
369
371 size_t getHookLibsVectorSize() const {
372 return (hook_vector_.size());
373 }
374
375private:
376
396 void ensureHookLibsVectorSize();
397
408 void checkLibraryIndex(int library_index) const;
409
420 class CalloutLibraryEqual :
421 public std::binary_function<CalloutEntry, CalloutEntry, bool> {
422 public:
423 bool operator()(const CalloutEntry& ent1,
424 const CalloutEntry& ent2) const {
425 return (ent1.first == ent2.first);
426 }
427 };
428
429 // Member variables
430
434 ServerHooks& server_hooks_;
435
439 int current_hook_;
440
444 int current_library_;
445
449 std::vector<CalloutVector> hook_vector_;
450
455 LibraryHandle library_handle_;
456
459 LibraryHandle pre_library_handle_;
460
463 LibraryHandle post_library_handle_;
464
466 int num_libraries_;
467};
468
469} // namespace util
470} // namespace isc
471
472#endif // CALLOUT_MANAGER_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Per-packet callout handle.
void registerCallout(const std::string &name, CalloutPtr callout)
Register a callout on a hook for the current library.
int getHookIndex() const
Get current hook index.
LibraryHandle & getLibraryHandle()
Return library handle.
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.
size_t getHookLibsVectorSize() const
Return number of currently available hooks.
void callCommandHandlers(const std::string &command_name, CalloutHandle &callout_handle)
Calls the callouts/command handlers for a given command name.
LibraryHandle & getPostLibraryHandle()
Return post-user callouts library handle.
bool deregisterCallout(const std::string &name, CalloutPtr callout)
De-Register a callout on a hook for the current library.
int getLibraryIndex() const
Get current library index.
int getNumLibraries() const
Get number of libraries.
void setLibraryIndex(int library_index)
Set current library index.
bool calloutsPresent(int hook_index) const
Checks if callouts are present on a hook.
bool deregisterAllCallouts(const std::string &name)
Removes all callouts on a hook for the current library.
void registerCommandHook(const std::string &command_name)
Registers a hook point for the specified command name.
LibraryHandle & getPreLibraryHandle()
Return pre-user callouts library handle.
NoSuchLibrary(const char *file, size_t line, const char *what)
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
Defines the logger used by the top-level component of kea-dhcp-ddns.