hooks.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (C) 2013-2016 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. #ifndef HOOKS_H
  7. #define HOOKS_H
  8. #include <hooks/callout_handle.h>
  9. #include <hooks/library_handle.h>
  10. namespace {
  11. // Version 4 of the hooks framework, set for Kea 1.1.
  12. const int KEA_HOOKS_VERSION = 4;
  13. // Names of the framework functions.
  14. const char* const LOAD_FUNCTION_NAME = "load";
  15. const char* const UNLOAD_FUNCTION_NAME = "unload";
  16. const char* const VERSION_FUNCTION_NAME = "version";
  17. // Typedefs for pointers to the framework functions.
  18. typedef int (*version_function_ptr)();
  19. typedef int (*load_function_ptr)(isc::hooks::LibraryHandle&);
  20. typedef int (*unload_function_ptr)();
  21. } // Anonymous namespace
  22. namespace isc {
  23. namespace hooks {
  24. /// @brief User-Library Initialization for Statically-Linked Kea
  25. ///
  26. /// If Kea is statically-linked, a user-created hooks library will not be
  27. /// able to access symbols in it. In particular, it will not be able to access
  28. /// singleton objects.
  29. ///
  30. /// The hooks framework handles some of this. For example, although there is
  31. /// a singleton ServerHooks object, hooks framework objects store a reference
  32. /// to it when they are created. When the user library needs to register a
  33. /// callout (which requires access to the ServerHooks information), it accesses
  34. /// the ServerHooks object through a pointer passed from the Kea image.
  35. ///
  36. /// The logging framework is more problematical. Here the code is partly
  37. /// statically linked (the Kea logging library) and partly shared (the
  38. /// log4cplus). The state of the former is not accessible to the user library,
  39. /// but the state of the latter is. So within the user library, we need to
  40. /// initialize the Kea logging library but not initialize the log4cplus
  41. /// code. Some of the initialization is done when the library is loaded, but
  42. /// other parts are done at run-time.
  43. ///
  44. /// This function - to be called by the user library code in its load() function
  45. /// when running against a statically linked Kea - initializes the Kea
  46. /// logging library. In particular, it loads the message dictionary with the
  47. /// text of the Kea messages.
  48. ///
  49. /// @note This means that the virtual address space is loaded with two copies
  50. /// of the message dictionary. Depending on how the user libraries are linked,
  51. /// loading multiple user libraries may involve loading one message dictionary
  52. /// per library.
  53. void hooksStaticLinkInit();
  54. } // namespace hooks
  55. } // namespace isc
  56. #endif // HOOKS_H