callout_library_common.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /// @file
  15. /// @brief Marker file callout library
  16. ///
  17. /// This is the source of a test library for the DHCP parser and configuration
  18. /// tests.
  19. ///
  20. /// To check that they libraries are loaded and unloaded correctly, the load
  21. /// and unload functions in this library maintain two marker files - the load
  22. /// marker file and the unload marker file. The functions append a single
  23. /// line to the file, creating the file if need be. In this way, the test code
  24. /// can determine whether the load/unload functions have been run and, if so,
  25. /// in what order.
  26. ///
  27. /// This file is the common library file for the tests. It will not compile
  28. /// by itself - it is included into each callout library which specifies the
  29. /// missing constant LIBRARY_NUMBER before the inclusion.
  30. #include <hooks/hooks.h>
  31. #include "marker_file.h"
  32. #include <fstream>
  33. extern "C" {
  34. /// @brief Append digit to marker file
  35. ///
  36. /// If the marker file does not exist, create it. Then append the single
  37. /// digit (given by the constant LIBRARY_NUMBER) defined earlier to it and
  38. /// close the file.
  39. ///
  40. /// @param name Name of the file to open
  41. ///
  42. /// @return 0 on success, non-zero on error.
  43. int
  44. appendDigit(const char* name) {
  45. // Open the file and check if successful.
  46. std::fstream file(name, std::fstream::out | std::fstream::app);
  47. if (!file.good()) {
  48. return (1);
  49. }
  50. // Add the library number to it and close.
  51. file << LIBRARY_NUMBER;
  52. file.close();
  53. return (0);
  54. }
  55. // Framework functions
  56. int
  57. version() {
  58. return (BIND10_HOOKS_VERSION);
  59. }
  60. int
  61. load(isc::hooks::LibraryHandle&) {
  62. return (appendDigit(LOAD_MARKER_FILE));
  63. }
  64. int
  65. unload() {
  66. return (appendDigit(UNLOAD_MARKER_FILE));
  67. }
  68. };