hooks.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef HOOKS_H
  15. #define HOOKS_H
  16. #include <config.h>
  17. #include <hooks/callout_handle.h>
  18. #include <hooks/library_handle.h>
  19. namespace {
  20. // Version 1 of the hooks framework.
  21. const int BIND10_HOOKS_VERSION = 1;
  22. // Names of the framework functions.
  23. const char* const LOAD_FUNCTION_NAME = "load";
  24. const char* const UNLOAD_FUNCTION_NAME = "unload";
  25. const char* const VERSION_FUNCTION_NAME = "version";
  26. // Typedefs for pointers to the framework functions.
  27. typedef int (*version_function_ptr)();
  28. typedef int (*load_function_ptr)(isc::hooks::LibraryHandle&);
  29. typedef int (*unload_function_ptr)();
  30. } // Anonymous namespace
  31. namespace isc {
  32. namespace hooks {
  33. /// @brief User-Library Initialization for Statically-Linked BIND 10
  34. ///
  35. /// If BIND 10 is statically-linked, a user-created hooks library will not be
  36. /// able to access symbols in it. In particular, it will not be able to access
  37. /// singleton objects.
  38. ///
  39. /// The hooks framework handles some of this. For example, although there is
  40. /// a singleton ServerHooks object, hooks framework objects store a reference
  41. /// to it when they are created. When the user library needs to register a
  42. /// callout (which requires access to the ServerHooks information), it accesses
  43. /// the ServerHooks object through a pointer passed from the BIND 10 image.
  44. ///
  45. /// The logging framework is more problematical. Here the code is partly
  46. /// statically linked (the BIND 10 logging library) and partly shared (the
  47. /// log4cplus). The state of the former is not accessible to the user library,
  48. /// but the state of the latter is. So within the user library, we need to
  49. /// initialize the BIND 10 logging library but not initialize the log4cplus
  50. /// code. Some of the initialization is done when the library is loaded, but
  51. /// other parts are done at run-time.
  52. ///
  53. /// This function - to be called by the user library code in its load() function
  54. /// when running against a statically linked BIND 10 - initializes the BIND 10
  55. /// logging library. In particular, it loads the message dictionary with the
  56. /// text of the BIND 10 messages.
  57. ///
  58. /// @note This means that the virtual address space is loaded with two copies
  59. /// of the message dictionary. Depending on how the user libraries are linked,
  60. /// loading multiple user libraries may involve loading one message dictionary
  61. /// per library.
  62. void hooksStaticLinkInit();
  63. } // namespace hooks
  64. } // namespace isc
  65. #endif // HOOKS_H