Kea 2.2.0
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
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
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
179
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
238
253 static std::vector<std::string> validateLibraries(
254 const std::vector<std::string>& libraries);
255
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) {
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) {
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
364private:
365
370 HooksManager();
371
375 static HooksManager& getHooksManager();
376
378
381
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
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 bool unloadLibraries()
Unload libraries.
static bool loadLibraries(const HookLibsCollection &libraries)
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.
static std::vector< std::string > validateLibraries(const std::vector< std::string > &libraries)
Validate library list.
Libraries still opened.
Definition: hooks_manager.h:28
LibrariesStillOpened(const char *file, size_t line, const char *what)
Definition: hooks_manager.h:30
static ServerHooks & getServerHooks()
Return ServerHooks object.
static const int CONTEXT_DESTROY
Definition: server_hooks.h:67
ParkingLotsPtr getParkingLotsPtr() const
Returns pointer to all parking lots.
static const int CONTEXT_CREATE
Index numbers for pre-defined hooks.
Definition: server_hooks.h:66
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.