dkdebug.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  9. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  10. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  13. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  14. * PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. * This module implements a mask-style diagnostic printing/selection system.
  18. * Each diagnostic is enabled by including an associated keyletter in a
  19. * selector string given at initialization time (typically as a command-line
  20. * option).
  21. */
  22. #ifndef DKDEBUG_H
  23. #define DKDEBUG_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdarg.h>
  28. #define DK_ALL (~0), /* Select all diagnostics */
  29. /*
  30. * Elements of this type are used to map the available diagnostic keyletters to
  31. * mask bits.
  32. */
  33. struct dkdesc {
  34. char keyletter;
  35. unsigned mask;
  36. };
  37. /*
  38. * Initialize diagnostic mask.
  39. *
  40. * Input variables:
  41. *
  42. * diag_str is a string giving the keyletters for diagnostics to enable.
  43. *
  44. * diags describes the available diagnostics, mapping each keyletter to any
  45. * number of mask bits. It should be terminated with an element with keyletter
  46. * set to the null character.
  47. *
  48. * Return value:
  49. * If an invalid character is given in diag_str, that character; otherwise a
  50. * null character.
  51. */
  52. char dk_setup(const char* diag_str, const struct dkdesc* diags);
  53. /*
  54. * The remaining functions test the mask bitset diag_req against the currently
  55. * enabled diagnostics, as set by dk_setup(). If any bits set in diag_req are
  56. * among the enabled diagnostics, the diagnostic operation is enabled.
  57. */
  58. /*
  59. * If diagnostic operation is enabled, use the remaining arguments to print
  60. * like fprintf(stderr, )
  61. */
  62. void dkprintf(unsigned diag_req, const char format[], ...);
  63. /*
  64. * If diagnostic operation is enabled, use the remaining arguments to print
  65. * like vfprintf(stderr, )
  66. */
  67. void vdkprintf(unsigned diag_req, const char format[], va_list ap);
  68. /*
  69. * If diagnostic operation is enabled, return 1; else return false.
  70. */
  71. int dk_set(unsigned diag_req);
  72. #ifdef __cplusplus
  73. }
  74. #endif
  75. #endif