Kea 2.7.6
callout_manager.h
Go to the documentation of this file.
1// Copyright (C) 2013-2021 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
127
129private:
130
131 // Private typedefs
132
136 typedef std::pair<int, CalloutPtr> CalloutEntry;
137
140 typedef std::vector<CalloutEntry> CalloutVector;
141
142public:
143
152 CalloutManager(int num_libraries = 0);
153
167 void registerCallout(const std::string& name,
168 CalloutPtr callout,
169 int library_index);
170
186 bool deregisterCallout(const std::string& name,
187 CalloutPtr callout,
188 int library_index);
189
201 bool deregisterAllCallouts(const std::string& name, int library_index);
202
213 bool calloutsPresent(int hook_index) const;
214
224 bool commandHandlersPresent(const std::string& command_name) const;
225
237 void callCallouts(int hook_index, CalloutHandle& callout_handle);
238
252 void callCommandHandlers(const std::string& command_name,
253 CalloutHandle& callout_handle);
254
265 void registerCommandHook(const std::string& command_name);
266
273 int getNumLibraries() const {
274 return (num_libraries_);
275 }
276
289 int getLibraryIndex() const {
290 return (current_library_);
291 }
292
307 void setLibraryIndex(int library_index) {
308 checkLibraryIndex(library_index);
309 current_library_ = library_index;
310 }
311
320 // callouts to run prior to user-library callouts.
323
324
335 return (library_handle_);
336 }
337
345 return (pre_library_handle_);
346 }
347
355 return (post_library_handle_);
356 }
357
359
361 size_t getHookLibsVectorSize() const {
362 return (hook_vector_.size());
363 }
364
365private:
366
386 void ensureHookLibsVectorSize();
387
398 void checkLibraryIndex(int library_index) const;
399
400 // Member variables
401
405 ServerHooks& server_hooks_;
406
410 int current_library_;
411
415 std::vector<CalloutVector> hook_vector_;
416
421 LibraryHandle library_handle_;
422
425 LibraryHandle pre_library_handle_;
426
429 LibraryHandle post_library_handle_;
430
432 int num_libraries_;
433};
434
435} // namespace util
436} // namespace isc
437
438#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.
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.
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.
LibraryHandle & getPostLibraryHandle()
Return post-user callouts library handle.
int getLibraryIndex() const
Get current library index.
int getNumLibraries() const
Get number of libraries.
void setLibraryIndex(int library_index)
Set current library index.
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.
LibraryHandle & getPreLibraryHandle()
Return pre-user callouts library handle.
NoSuchLibrary(const char *file, size_t line, const char *what)
Server hook collection.
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
Defines the logger used by the top-level component of kea-lfc.