basic_library.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (C) 2017 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. /// @file
  7. /// @brief Basic callout library
  8. ///
  9. /// This is source of a test library for Control Agent.
  10. ///
  11. /// - Only the "version" framework function is supplied.
  12. ///
  13. /// - hookpt_one callout is supplied.
  14. #include <config.h>
  15. #include <hooks/hooks.h>
  16. using namespace isc::hooks;
  17. using namespace std;
  18. namespace {
  19. extern "C" {
  20. // Callouts. All return their result through the "result" argument.
  21. int
  22. context_create(CalloutHandle& handle) {
  23. handle.setContext("result", static_cast<int>(10));
  24. handle.setArgument("result", static_cast<int>(10));
  25. return (0);
  26. }
  27. // First callout adds the passed "integer" argument to the initialized context
  28. // value of 10. (Note that the value set by context_create is accessed through
  29. // context and not the argument, so checking that context is correctly passed
  30. // between callouts in the same library.)
  31. int
  32. hookpt_one(CalloutHandle& handle) {
  33. int data;
  34. handle.getArgument("integer", data);
  35. int result;
  36. handle.getArgument("result", result);
  37. result += data;
  38. handle.setArgument("result", result);
  39. return (0);
  40. }
  41. // Framework functions.
  42. int
  43. version() {
  44. return (KEA_HOOKS_VERSION);
  45. }
  46. // load() initializes the user library if the main image was statically linked.
  47. int
  48. load(isc::hooks::LibraryHandle&) {
  49. #ifdef USE_STATIC_LINK
  50. hooksStaticLinkInit();
  51. #endif
  52. return (0);
  53. }
  54. }
  55. }