messages.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __DIRECT__MESSAGES_H__
  24. #define __DIRECT__MESSAGES_H__
  25. #include <direct/build.h>
  26. #include <direct/types.h>
  27. #if __GNUC__ >= 3
  28. #define D_FORMAT_PRINTF(n) __attribute__((__format__ (__printf__, n, n+1)))
  29. #else
  30. #define D_FORMAT_PRINTF(n)
  31. #endif
  32. typedef enum {
  33. DMT_NONE = 0x00000000, /* No message type. */
  34. DMT_BANNER = 0x00000001, /* Startup banner. */
  35. DMT_INFO = 0x00000002, /* Info messages. */
  36. DMT_WARNING = 0x00000004, /* Warnings. */
  37. DMT_ERROR = 0x00000008, /* Error messages: regular, with DFBResult, bugs,
  38. system call errors, dlopen errors */
  39. DMT_UNIMPLEMENTED = 0x00000010, /* Messages notifying unimplemented functionality. */
  40. DMT_ONCE = 0x00000020, /* One-shot messages .*/
  41. DMT_ALL = 0x0000003f /* All types. */
  42. } DirectMessageType;
  43. #if DIRECT_BUILD_TEXT
  44. #include <errno.h>
  45. #include <direct/conf.h>
  46. void direct_messages_info ( const char *format, ... ) D_FORMAT_PRINTF(1);
  47. void direct_messages_error ( const char *format, ... ) D_FORMAT_PRINTF(1);
  48. void direct_messages_derror ( DirectResult result,
  49. const char *format, ... ) D_FORMAT_PRINTF(2);
  50. void direct_messages_perror ( int erno,
  51. const char *format, ... ) D_FORMAT_PRINTF(2);
  52. void direct_messages_dlerror ( const char *dlerr,
  53. const char *format, ... ) D_FORMAT_PRINTF(2);
  54. void direct_messages_once ( const char *func,
  55. const char *file,
  56. int line,
  57. const char *format, ... ) D_FORMAT_PRINTF(4);
  58. void direct_messages_unimplemented( const char *func,
  59. const char *file,
  60. int line );
  61. void direct_messages_bug ( const char *func,
  62. const char *file,
  63. int line,
  64. const char *format, ... ) D_FORMAT_PRINTF(4);
  65. void direct_messages_warn ( const char *func,
  66. const char *file,
  67. int line,
  68. const char *format, ... ) D_FORMAT_PRINTF(4);
  69. #define D_INFO(x...) do { \
  70. if (!(direct_config->quiet & DMT_INFO)) \
  71. direct_messages_info( x ); \
  72. } while (0)
  73. #define D_ERROR(x...) do { \
  74. if (!(direct_config->quiet & DMT_ERROR)) \
  75. direct_messages_error( x ); \
  76. } while (0)
  77. #define D_DERROR(r,x...) do { \
  78. if (!(direct_config->quiet & DMT_ERROR)) \
  79. direct_messages_derror( (DirectResult) r, x ); \
  80. } while (0)
  81. #define D_PERROR(x...) do { \
  82. if (!(direct_config->quiet & DMT_ERROR)) \
  83. direct_messages_perror( errno, x ); \
  84. } while (0)
  85. #define D_DLERROR(x...) do { \
  86. if (!(direct_config->quiet & DMT_ERROR)) \
  87. direct_messages_dlerror( dlerror(), x ); \
  88. } while (0)
  89. #define D_ONCE(x...) do { \
  90. if (!(direct_config->quiet & DMT_ONCE)) { \
  91. static bool first = true; \
  92. if (first) { \
  93. direct_messages_once( __FUNCTION__, \
  94. __FUNCTION__, __LINE__, x ); \
  95. first = false; \
  96. } \
  97. } \
  98. } while (0)
  99. #define D_UNIMPLEMENTED() do { \
  100. if (!(direct_config->quiet & DMT_UNIMPLEMENTED)) { \
  101. static bool first = true; \
  102. if (first) { \
  103. direct_messages_unimplemented( __FUNCTION__, \
  104. __FUNCTION__, __LINE__ ); \
  105. first = false; \
  106. } \
  107. } \
  108. } while (0)
  109. #define D_BUG(x...) do { \
  110. if (!(direct_config->quiet & DMT_ERROR)) \
  111. direct_messages_bug( __FUNCTION__, __FUNCTION__, __LINE__, x ); \
  112. } while (0)
  113. #define D_WARN(x...) do { \
  114. if (!(direct_config->quiet & DMT_WARNING)) \
  115. direct_messages_warn( __FUNCTION__, __FUNCTION__, __LINE__, x );\
  116. } while (0)
  117. #define D_OOM() (direct_messages_warn( __FUNCTION__, __FUNCTION__, __LINE__, \
  118. "out of memory" ), DR_NOLOCALMEMORY)
  119. #else
  120. #define D_INFO(x...) do { } while (0)
  121. #define D_ERROR(x...) do { } while (0)
  122. #define D_DERROR(x...) do { } while (0)
  123. #define D_PERROR(x...) do { } while (0)
  124. #define D_DLERROR(x...) do { } while (0)
  125. #define D_ONCE(x...) do { } while (0)
  126. #define D_UNIMPLEMENTED() do { } while (0)
  127. #define D_BUG(x...) do { } while (0)
  128. #define D_WARN(x...) do { } while (0)
  129. #define D_OOM() (printf("out of memory\n"), DR_NOLOCALMEMORY)
  130. #endif
  131. #endif