base.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2013 Hugh Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <stdarg.h>
  18. #include "c99defs.h"
  19. /*
  20. * Just contains logging/crash related stuff
  21. */
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. #define STRINGIFY(x) #x
  26. #define STRINGIFY_(x) STRINGIFY(x)
  27. #define S__LINE__ STRINGIFY_(__LINE__)
  28. #define INT_CUR_LINE __LINE__
  29. #define FILE_LINE __FILE__ " (" S__LINE__ "): "
  30. enum {
  31. /**
  32. * Use if there's a problem that can potentially affect the program,
  33. * but isn't enough to require termination of the program.
  34. *
  35. * Use in creation functions and core subsystem functions. Places that
  36. * should definitely not fail.
  37. */
  38. LOG_ERROR = 100,
  39. /**
  40. * Use if a problem occurs that doesn't affect the program and is
  41. * recoverable.
  42. *
  43. * Use in places where failure isn't entirely unexpected, and can
  44. * be handled safely.
  45. */
  46. LOG_WARNING = 200,
  47. /**
  48. * Informative message to be displayed in the log.
  49. */
  50. LOG_INFO = 300,
  51. /**
  52. * Debug message to be used mostly by developers.
  53. */
  54. LOG_DEBUG = 400
  55. };
  56. typedef void (*log_handler_t)(int lvl, const char *msg, va_list args, void *p);
  57. EXPORT void base_get_log_handler(log_handler_t *handler, void **param);
  58. EXPORT void base_set_log_handler(log_handler_t handler, void *param);
  59. EXPORT void base_set_crash_handler(void (*handler)(const char *, va_list,
  60. void *),
  61. void *param);
  62. EXPORT void blogva(int log_level, const char *format, va_list args);
  63. #if !defined(_MSC_VER) && !defined(SWIG)
  64. #define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
  65. #else
  66. #define PRINTFATTR(f, a)
  67. #endif
  68. PRINTFATTR(2, 3)
  69. EXPORT void blog(int log_level, const char *format, ...);
  70. PRINTFATTR(1, 2)
  71. #ifndef SWIG
  72. OBS_NORETURN
  73. #endif
  74. EXPORT void bcrash(const char *format, ...);
  75. #undef PRINTFATTR
  76. #ifdef __cplusplus
  77. }
  78. #endif