Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2011 Joakim Sindholt <opensource@zhasha.com>
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  8.  * license, and/or sell copies of the Software, and to permit persons to whom
  9.  * the Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21.  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22.  
  23. #ifndef _NINE_DEBUG_H_
  24. #define _NINE_DEBUG_H_
  25.  
  26. #include "util/u_debug.h"
  27.  
  28. void
  29. _nine_debug_printf( unsigned long flag,
  30.                     const char *func,
  31.                     const char *fmt,
  32.                     ... ) _util_printf_format(3,4);
  33.  
  34. #define ERR(fmt, ...) _nine_debug_printf(DBG_ERROR, __FUNCTION__, fmt, ## __VA_ARGS__)
  35.  
  36. #ifdef DEBUG
  37. #define WARN(fmt, ...) _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__)
  38. #define WARN_ONCE(fmt, ...) \
  39.     do { \
  40.         static boolean once = TRUE; \
  41.         if (once) { \
  42.             once = FALSE; \
  43.             _nine_debug_printf(DBG_WARN, __FUNCTION__, fmt, ## __VA_ARGS__); \
  44.         } \
  45.     } while(0)
  46. #else
  47. #define WARN(fmt, ...)
  48. #define WARN_ONCE(fmt, ...)
  49. #endif
  50.  
  51. #ifdef DEBUG
  52. #define DBG_FLAG(flag, fmt, ...) \
  53.     _nine_debug_printf(flag, __FUNCTION__, fmt, ## __VA_ARGS__)
  54. #else
  55. #define DBG_FLAG(flag, fmt, ...)
  56. #endif
  57. #define DBG(fmt, ...) DBG_FLAG(DBG_CHANNEL, fmt, ## __VA_ARGS__)
  58.  
  59. #define DBG_UNKNOWN              (1<< 0)
  60. #define DBG_ADAPTER              (1<< 1)
  61. #define DBG_OVERLAYEXTENSION     (1<< 2)
  62. #define DBG_AUTHENTICATEDCHANNEL (1<< 3)
  63. #define DBG_BASETEXTURE          (1<< 4)
  64. #define DBG_CRYPTOSESSION        (1<< 5)
  65. #define DBG_CUBETEXTURE          (1<< 6)
  66. #define DBG_DEVICE               (1<< 7)
  67. #define DBG_DEVICEVIDEO          (1<< 8)
  68. #define DBG_INDEXBUFFER          (1<< 9)
  69. #define DBG_PIXELSHADER          (1<<10)
  70. #define DBG_QUERY                (1<<11)
  71. #define DBG_RESOURCE             (1<<12)
  72. #define DBG_STATEBLOCK           (1<<13)
  73. #define DBG_SURFACE              (1<<14)
  74. #define DBG_SWAPCHAIN            (1<<15)
  75. #define DBG_TEXTURE              (1<<16)
  76. #define DBG_VERTEXBUFFER         (1<<17)
  77. #define DBG_VERTEXDECLARATION    (1<<18)
  78. #define DBG_VERTEXSHADER         (1<<19)
  79. #define DBG_VOLUME               (1<<20)
  80. #define DBG_VOLUMETEXTURE        (1<<21)
  81. #define DBG_SHADER               (1<<22)
  82. #define DBG_FF                   (1<<23)
  83. #define DBG_USER                 (1<<24)
  84. #define DBG_ERROR                (1<<25)
  85. #define DBG_WARN                 (1<<26)
  86.  
  87. void
  88. _nine_stub( const char *file,
  89.             const char *func,
  90.             unsigned line );
  91.  
  92. #ifdef DEBUG
  93. #define STUB(ret) \
  94.     do { \
  95.         _nine_stub(__FILE__, __FUNCTION__, __LINE__); \
  96.         return ret; \
  97.     } while (0)
  98. #else
  99. #define STUB(ret) do { return ret; } while (0)
  100. #endif
  101.  
  102. /* the expression for this macro is equivalent of that to assert, however this
  103.  * macro is designed to be used in conditionals ala
  104.  * if (user_error(required condition)) { assertion failed }
  105.  * It also prints debug message if the assertion fails. */
  106. #ifdef DEBUG
  107. #define user_error(x) \
  108.     (!(x) ? (DBG_FLAG(DBG_USER, "User assertion failed: `%s'\n", #x), TRUE) \
  109.           : FALSE)
  110. #else
  111. #define user_error(x) (!(x) ? TRUE : FALSE)
  112. #endif
  113.  
  114. #ifdef DEBUG
  115. #define user_warn(x) \
  116.     if ((x)) { DBG_FLAG(DBG_USER, "User warning: `%s'\n", #x); }
  117. #else
  118. #define user_warn(x)
  119. #endif
  120.  
  121. /* nonfatal assert */
  122. #define user_assert(x, r) \
  123.     do { \
  124.         if (user_error(x)) { \
  125.             return r; \
  126.         } \
  127.     } while (0)
  128.  
  129. #define ret_err(x, r) \
  130.     do { \
  131.         ERR(x); \
  132.         return r; \
  133.     } while(0)
  134.  
  135. #endif /* _NINE_DEBUG_H_ */
  136.