log.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. *
  3. * oFono - Open Telephony stack for Linux
  4. *
  5. * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #ifndef __OFONO_LOG_H
  22. #define __OFONO_LOG_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * SECTION:log
  28. * @title: Logging premitives
  29. * @short_description: Functions for logging error and debug information
  30. */
  31. extern void ofono_info(const char *format, ...)
  32. __attribute__((format(printf, 1, 2)));
  33. extern void ofono_warn(const char *format, ...)
  34. __attribute__((format(printf, 1, 2)));
  35. extern void ofono_error(const char *format, ...)
  36. __attribute__((format(printf, 1, 2)));
  37. extern void ofono_debug(const char *format, ...)
  38. __attribute__((format(printf, 1, 2)));
  39. struct ofono_debug_desc {
  40. const char *name;
  41. const char *file;
  42. #define OFONO_DEBUG_FLAG_DEFAULT (0)
  43. #define OFONO_DEBUG_FLAG_PRINT (1 << 0)
  44. unsigned int flags;
  45. } __attribute__((aligned(8)));
  46. /**
  47. * DBG:
  48. * @fmt: format string
  49. * @arg...: list of arguments
  50. *
  51. * Simple macro around ofono_debug() which also include the function
  52. * name it is called in.
  53. */
  54. #define DBG(fmt, arg...) do { \
  55. static struct ofono_debug_desc __ofono_debug_desc \
  56. __attribute__((used, section("__debug"), aligned(8))) = { \
  57. .file = __FILE__, .flags = OFONO_DEBUG_FLAG_DEFAULT, \
  58. }; \
  59. if (__ofono_debug_desc.flags & OFONO_DEBUG_FLAG_PRINT) \
  60. ofono_debug("%s:%s() " fmt, \
  61. __FILE__, __FUNCTION__ , ## arg); \
  62. } while (0)
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif /* __OFONO_LOG_H */