Kea  2.3.4-git
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 
10 #include <exceptions/exceptions.h>
11 #include <hooks/library_handle.h>
12 #include <hooks/server_hooks.h>
13 
14 #include <boost/shared_ptr.hpp>
15 
16 #include <climits>
17 #include <map>
18 #include <string>
19 
20 namespace isc {
21 namespace hooks {
22 
27 class NoSuchLibrary : public Exception {
28 public:
29  NoSuchLibrary(const char* file, size_t line, const char* what) :
30  isc::Exception(file, line, what) {}
31 };
32 
127 
129 private:
130 
131  // Private typedefs
132 
136  typedef std::pair<int, CalloutPtr> CalloutEntry;
137 
140  typedef std::vector<CalloutEntry> CalloutVector;
141 
142 public:
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 
365 private:
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
int(* CalloutPtr)(CalloutHandle &)
Typedef for a callout pointer. (Callouts must have "C" linkage.)
LibraryHandle & getPreLibraryHandle()
Return pre-user callouts library handle.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
LibraryHandle & getPostLibraryHandle()
Return post-user callouts library handle.
Per-packet callout handle.
int getLibraryIndex() const
Get current library index.
void setLibraryIndex(int library_index)
Set current library index.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
size_t getHookLibsVectorSize() const
Return number of currently available hooks.
int getNumLibraries() const
Get number of libraries.
LibraryHandle & getLibraryHandle()
Return library handle.
NoSuchLibrary(const char *file, size_t line, const char *what)
Server hook collection.
Definition: server_hooks.h:62