Kea  2.3.3-git
hooks_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 HOOKS_MANAGER_H
8 #define HOOKS_MANAGER_H
9 
10 #include <hooks/server_hooks.h>
11 #include <hooks/libinfo.h>
12 
13 #include <boost/noncopyable.hpp>
14 #include <boost/shared_ptr.hpp>
15 
16 #include <string>
17 #include <vector>
18 
19 namespace isc {
20 namespace hooks {
21 
29 public:
30  LibrariesStillOpened(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) {}
32 };
33 
34 // Forward declarations
35 class CalloutHandle;
36 class CalloutManager;
37 class LibraryHandle;
39 
49 
50 class HooksManager : boost::noncopyable {
51 public:
52 
74  static bool loadLibraries(const HookLibsCollection& libraries);
75 
94  static bool unloadLibraries();
95 
111  static void prepareUnloadLibraries();
112 
122  static bool calloutsPresent(int index);
123 
133  static bool commandHandlersPresent(const std::string& command_name);
134 
146  static void callCallouts(int index, CalloutHandle& handle);
147 
161  static void callCommandHandlers(const std::string& command_name,
162  CalloutHandle& handle);
163 
178  static LibraryHandle& preCalloutsLibraryHandle();
179 
194  static LibraryHandle& postCalloutsLibraryHandle();
195 
205  static boost::shared_ptr<CalloutHandle> createCalloutHandle();
206 
223  static int registerHook(const std::string& name);
224 
230  static std::vector<std::string> getLibraryNames();
231 
237  static HookLibsCollection getLibraryInfo();
238 
253  static std::vector<std::string> validateLibraries(
254  const std::vector<std::string>& libraries);
255 
257  static const int CONTEXT_CREATE = ServerHooks::CONTEXT_CREATE;
258  static const int CONTEXT_DESTROY = ServerHooks::CONTEXT_DESTROY;
259 
290  template<typename T>
291  static void park(const std::string& hook_name, T parked_object,
292  std::function<void()> unpark_callback) {
294  getParkingLotPtr(hook_name)->park(parked_object, unpark_callback);
295  }
296 
307  template<typename T>
308  static bool unpark(const std::string& hook_name, T parked_object) {
309  return (ServerHooks::getServerHooks().
310  getParkingLotPtr(hook_name)->unpark(parked_object, true));
311  }
312 
319  template<typename T>
320  static bool drop(const std::string& hook_name, T parked_object) {
321  return (ServerHooks::getServerHooks().
322  getParkingLotPtr(hook_name)->drop(parked_object));
323  }
324 
334  template<typename T>
335  static void reference(const std::string& hook_name, T parked_object) {
337  getParkingLotPtr(hook_name)->reference(parked_object);
338  }
339 
345  static void clearParkingLots() {
347  }
348 
357  static void setTestMode(bool mode);
358 
362  static bool getTestMode();
363 
364 private:
365 
370  HooksManager();
371 
375  static HooksManager& getHooksManager();
376 
378 
390  std::string validateLibrariesInternal(
391  const std::vector<std::string>& libraries) const;
392 
402  bool loadLibrariesInternal(const HookLibsCollection& libraries);
403 
408  bool unloadLibrariesInternal();
409 
411  void prepareUnloadLibrariesInternal();
412 
419  bool calloutsPresentInternal(int index);
420 
430  bool commandHandlersPresentInternal(const std::string& command_name);
431 
437  void callCalloutsInternal(int index, CalloutHandle& handle);
438 
447  void callCommandHandlersInternal(const std::string& command_name,
448  CalloutHandle& handle);
449 
453  boost::shared_ptr<CalloutHandle> createCalloutHandleInternal();
454 
459  LibraryHandle& preCalloutsLibraryHandleInternal();
460 
465  LibraryHandle& postCalloutsLibraryHandleInternal();
466 
470  std::vector<std::string> getLibraryNamesInternal() const;
471 
473  HookLibsCollection getLibraryInfoInternal() const;
474 
476 
477  // Members
478 
482  boost::shared_ptr<LibraryManagerCollection> lm_collection_;
483 
487  boost::shared_ptr<CalloutManager> callout_manager_;
488 
493  bool test_mode_;
494 };
495 
496 } // namespace util
497 } // namespace hooks
498 
499 #endif // HOOKS_MANAGER_H
LibrariesStillOpened(const char *file, size_t line, const char *what)
Definition: hooks_manager.h:30
static const int CONTEXT_CREATE
Index numbers for pre-defined hooks.
Definition: server_hooks.h:66
static ServerHooks & getServerHooks()
Return ServerHooks object.
Libraries still opened.
Definition: hooks_manager.h:28
static void clearParkingLots()
Clears any parking packets.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
Definition: libinfo.h:31
static void reference(const std::string &hook_name, T parked_object)
Increases reference counter for the parked object.
Per-packet callout handle.
static void park(const std::string &hook_name, T parked_object, std::function< void()> unpark_callback)
Park an object (packet).
static bool unpark(const std::string &hook_name, T parked_object)
Forces unparking the object (packet).
static const int CONTEXT_DESTROY
Definition: server_hooks.h:67
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.
static bool drop(const std::string &hook_name, T parked_object)
Removes parked object without calling a callback.
ParkingLotsPtr getParkingLotsPtr() const
Returns pointer to all parking lots.