Defs.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // "$Id: Defs.h 129930 2013-08-02 07:51:01Z sun_xiaohui $"
  3. //
  4. // Copyright (c)1992-2007, ZheJiang Dahua Technology Stock CO.LTD.
  5. // All Rights Reserved.
  6. //
  7. // Description:
  8. // Revisions: Year-Month-Day SVN-Author Modification
  9. //
  10. #ifndef __INFRA3_DEFS_H__
  11. #define __INFRA3_DEFS_H__
  12. #include "Types/Types.h"
  13. #include "Types/IntTypes.h"
  14. // WIN32 Dynamic Link Library
  15. #ifdef _MSC_VER
  16. #ifdef INFRA_DLL_BUILD
  17. #define INFRA_API _declspec(dllexport)
  18. #elif defined( INFRA_DLL_USE ) || defined( UNIVERSAL_DLL_USE )
  19. #define INFRA_API _declspec(dllimport)
  20. #else
  21. #define INFRA_API
  22. #endif
  23. #else
  24. #define INFRA_API
  25. #endif
  26. #ifndef NULL
  27. #define NULL 0
  28. #endif
  29. #ifndef __GNUC__
  30. #define __attribute__(x)
  31. #endif
  32. //////////////////////////////////////////////////////////////////////////
  33. // useful definition
  34. #define DAHUA_BITMSK(bit) ((unsigned int)1 << (bit))
  35. #ifndef BITMSK
  36. // 为兼容老接口保留,请勿使用
  37. #define BITMSK(bit) ((unsigned int)1 << (bit))
  38. #endif
  39. //////////////////////////////////////////////////////////////////////////
  40. // Join two variables
  41. #define DAHUA_JOIN( X, Y ) DAHUA_DO_JOIN( X, Y )
  42. #define DAHUA_DO_JOIN( X, Y ) DAHUA_DO_JOIN2(X,Y)
  43. #define DAHUA_DO_JOIN2( X, Y ) X##Y
  44. // 为兼容老接口保留,请勿使用
  45. #define MACRO_JOIN( X, Y ) MACRO_DO_JOIN( X, Y )
  46. #define MACRO_DO_JOIN( X, Y ) MACRO_DO_JOIN2(X,Y)
  47. #define MACRO_DO_JOIN2( X, Y ) X##Y
  48. //////////////////////////////////////////////////////////////////////////
  49. // use the unified 'DEBUG' macro
  50. #if (!defined(NDEBUG)) && !defined(DEBUG)
  51. # define DEBUG
  52. #endif
  53. //////////////////////////////////////////////////////////////////////////
  54. // print message, controlled by messsage level
  55. int INFRA_API logTrace(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  56. int INFRA_API logDebug(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  57. int INFRA_API logInfo(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  58. int INFRA_API logWarn(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  59. int INFRA_API logError(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  60. int INFRA_API logFatal(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
  61. int logLibName(int nLevel, const char *, const char* fmt, ...)
  62. __attribute__((format(printf, 3, 4)));
  63. #undef debugf
  64. #undef tracef
  65. #undef infof
  66. #undef warnf
  67. #undef errorf
  68. #undef fatalf
  69. #undef tracepoint
  70. #ifdef __linux__ // perform complete xxxxf macro replacement
  71. #ifdef DEBUG
  72. # ifdef LOG_LIB_NAME
  73. # define debugf(format, ...) logLibName(6, LOG_LIB_NAME, format, ## __VA_ARGS__)
  74. # define tracef(format, ...) logLibName(5, LOG_LIB_NAME, format, ## __VA_ARGS__)
  75. # define infof(format, ...) logLibName(4, LOG_LIB_NAME, format, ## __VA_ARGS__)
  76. # define warnf(format, ...) logLibName(3, LOG_LIB_NAME, format, ## __VA_ARGS__)
  77. # define errorf(format, ...) logLibName(2, LOG_LIB_NAME, format, ## __VA_ARGS__)
  78. # define fatalf(format, ...) logLibName(1, LOG_LIB_NAME, format, ## __VA_ARGS__)
  79. # else
  80. # define tracef(format, ...) logTrace(format, ## __VA_ARGS__)
  81. # define debugf(format, ...) logDebug(format, ## __VA_ARGS__)
  82. # define infof(format, ...) logInfo(format, ## __VA_ARGS__)
  83. # define warnf(format, ...) logWarn(format, ## __VA_ARGS__)
  84. # define errorf(format, ...) logError(format, ## __VA_ARGS__)
  85. # define fatalf(format, ...) logFatal(format, ## __VA_ARGS__)
  86. # endif
  87. #else
  88. # define tracef(format, ...)
  89. # define debugf(format, ...)
  90. # ifdef LOG_LIB_NAME
  91. # define infof(format, ...) logLibName(4, LOG_LIB_NAME, format, ## __VA_ARGS__)
  92. # define warnf(format, ...) logLibName(3, LOG_LIB_NAME, format, ## __VA_ARGS__)
  93. # define errorf(format, ...) logLibName(2, LOG_LIB_NAME, format, ## __VA_ARGS__)
  94. # define fatalf(format, ...) logLibName(1, LOG_LIB_NAME, format, ## __VA_ARGS__)
  95. # else
  96. # define infof(format, ...) logInfo(format, ## __VA_ARGS__)
  97. # define warnf(format, ...) logWarn(format, ## __VA_ARGS__)
  98. # define errorf(format, ...) logError(format, ## __VA_ARGS__)
  99. # define fatalf(format, ...) logFatal(format, ## __VA_ARGS__)
  100. # endif
  101. #endif
  102. #else
  103. #ifdef DEBUG
  104. # define tracef logTrace
  105. # define debugf logDebug
  106. # define infof logInfo
  107. # define warnf logWarn
  108. # define errorf logError
  109. # define fatalf logFatal
  110. #else
  111. # define tracef if(0)logTrace
  112. # define debugf if(0)logDebug
  113. # define infof logInfo
  114. # define warnf logWarn
  115. # define errorf logError
  116. # define fatalf logFatal
  117. #endif
  118. #endif
  119. #define tracepoint() debugf("tracepoint: %s, %d.\n",__FILE__,__LINE__)
  120. #endif //__INFRA_DEFS_H__