Kea 2.7.6
hooks_manager.h
Go to the documentation of this file.
1// Copyright (C) 2013-2023 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
19namespace isc {
20namespace hooks {
21
29public:
30 LibrariesStillOpened(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) {}
32};
33
34// Forward declarations
35class CalloutHandle;
36class CalloutManager;
37class LibraryHandle;
38class LibraryManagerCollection;
39
49
50class HooksManager : boost::noncopyable {
51public:
52
76 static bool loadLibraries(const HookLibsCollection& libraries,
77 bool multi_threading_enabled = false);
78
97 static bool unloadLibraries();
98
114 static void prepareUnloadLibraries();
115
125 static bool calloutsPresent(int index);
126
136 static bool commandHandlersPresent(const std::string& command_name);
137
149 static void callCallouts(int index, CalloutHandle& handle);
150
164 static void callCommandHandlers(const std::string& command_name,
165 CalloutHandle& handle);
166
182
198
208 static boost::shared_ptr<CalloutHandle> createCalloutHandle();
209
226 static int registerHook(const std::string& name);
227
233 static std::vector<std::string> getLibraryNames();
234
241
258 static std::vector<std::string> validateLibraries(const std::vector<std::string>& libraries,
259 bool multi_threading_enabled = false);
260
264
295 template<typename T>
296 static void park(const std::string& hook_name, T parked_object,
297 std::function<void()> unpark_callback) {
299 getParkingLotPtr(hook_name)->park(parked_object, unpark_callback);
300 }
301
312 template<typename T>
313 static bool unpark(const std::string& hook_name, T parked_object) {
315 getParkingLotPtr(hook_name)->unpark(parked_object, true));
316 }
317
324 template<typename T>
325 static bool drop(const std::string& hook_name, T parked_object) {
327 getParkingLotPtr(hook_name)->drop(parked_object));
328 }
329
339 template<typename T>
340 static void reference(const std::string& hook_name, T parked_object) {
342 getParkingLotPtr(hook_name)->reference(parked_object);
343 }
344
350 static void clearParkingLots() {
352 }
353
362 static void setTestMode(bool mode);
363
367 static bool getTestMode();
368
369private:
370
375 HooksManager();
376
380 static HooksManager& getHooksManager();
381
383
386
398 bool loadLibrariesInternal(const HookLibsCollection& libraries,
399 bool multi_threading_enabled);
400
405 bool unloadLibrariesInternal();
406
408 void prepareUnloadLibrariesInternal();
409
416 bool calloutsPresentInternal(int index);
417
427 bool commandHandlersPresentInternal(const std::string& command_name);
428
434 void callCalloutsInternal(int index, CalloutHandle& handle);
435
444 void callCommandHandlersInternal(const std::string& command_name,
445 CalloutHandle& handle);
446
450 boost::shared_ptr<CalloutHandle> createCalloutHandleInternal();
451
456 LibraryHandle& preCalloutsLibraryHandleInternal();
457
462 LibraryHandle& postCalloutsLibraryHandleInternal();
463
467 std::vector<std::string> getLibraryNamesInternal() const;
468
470 HookLibsCollection getLibraryInfoInternal() const;
471
473
474 // Members
475
479 boost::shared_ptr<LibraryManagerCollection> lm_collection_;
480
484 boost::shared_ptr<CalloutManager> callout_manager_;
485
490 bool test_mode_;
491};
492
493} // namespace util
494} // namespace hooks
495
496#endif // HOOKS_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.
static int registerHook(const std::string &name)
Register Hook.
static LibraryHandle & postCalloutsLibraryHandle()
Return post-callouts library handle.
static bool calloutsPresent(int index)
Are callouts present?
static bool unpark(const std::string &hook_name, T parked_object)
Forces unparking the object (packet).
static void setTestMode(bool mode)
Set test mode.
static std::vector< std::string > getLibraryNames()
Return list of loaded libraries.
static void callCommandHandlers(const std::string &command_name, CalloutHandle &handle)
Calls the callouts/command handlers for a given command name.
static const int CONTEXT_CREATE
Index numbers for pre-defined hooks.
static std::vector< std::string > validateLibraries(const std::vector< std::string > &libraries, bool multi_threading_enabled=false)
Validate library list.
static bool unloadLibraries()
Unload libraries.
static bool loadLibraries(const HookLibsCollection &libraries, bool multi_threading_enabled=false)
Load and reload libraries.
static const int CONTEXT_DESTROY
static void park(const std::string &hook_name, T parked_object, std::function< void()> unpark_callback)
Park an object (packet).
static LibraryHandle & preCalloutsLibraryHandle()
Return pre-callouts library handle.
static bool commandHandlersPresent(const std::string &command_name)
Checks if control command handlers are present for the specified command.
static boost::shared_ptr< CalloutHandle > createCalloutHandle()
Return callout handle.
static void reference(const std::string &hook_name, T parked_object)
Increases reference counter for the parked object.
static void callCallouts(int index, CalloutHandle &handle)
Calls the callouts for a given hook.
static bool getTestMode()
Get test mode.
static HookLibsCollection getLibraryInfo()
Return list of loaded libraries with its parameters.
static void prepareUnloadLibraries()
Prepare the unloading of libraries.
static bool drop(const std::string &hook_name, T parked_object)
Removes parked object without calling a callback.
static void clearParkingLots()
Clears any parking packets.
Libraries still opened.
LibrariesStillOpened(const char *file, size_t line, const char *what)
static ServerHooks & getServerHooks()
Return ServerHooks object.
static const int CONTEXT_DESTROY
ParkingLotsPtr getParkingLotsPtr() const
Returns pointer to all parking lots.
static const int CONTEXT_CREATE
Index numbers for pre-defined hooks.
std::vector< HookLibInfo > HookLibsCollection
A storage for information about hook libraries.
Definition libinfo.h:31
Defines the logger used by the top-level component of kea-lfc.