SpComm.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef _SP_COMM_H__
  2. #define _SP_COMM_H__
  3. #define _CRTDBG_MAP_ALLOC
  4. #include <stdlib.h>
  5. #ifdef RVC_OS_WIN
  6. #include <crtdbg.h>
  7. #endif //RVC_OS_WIN
  8. #include <cstring>
  9. #include <iostream>
  10. #include <sstream>
  11. #include "SpBase.h"
  12. namespace SP
  13. {
  14. //depecrated, to use defined at Module/include/CommEntityUtil.hpp
  15. struct MachineFormat
  16. {
  17. enum Site
  18. {
  19. CMB_UNKNOWN,
  20. CMB_LIB, /** 行内大堂*/
  21. CMB_FLB, /** 离行机器*/
  22. };
  23. #define SITE_ENUM_TYPE(MACRO) \
  24. MACRO(LIB)\
  25. MACRO(FLB)
  26. #define ENUM_MAP_CONVERT(elem) \
  27. if (stricmp(lpcszSiteName, "CMB."#elem) == 0) return CMB_##elem;
  28. /*!
  29. * convert cmb site name to enum type.
  30. */
  31. static Site Str2Site(LPCSTR lpcszSiteName)
  32. {
  33. if (lpcszSiteName == NULL || strlen(lpcszSiteName) == 0)
  34. return CMB_UNKNOWN;
  35. SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
  36. return CMB_UNKNOWN;
  37. }
  38. #undef ENUM_MAP_CONVERT
  39. #define ENUM_MAP_CONVERT(elem) case CMB_##elem: return "CMB."#elem;
  40. static LPCSTR Site2Str(Site site) {
  41. switch (site) {
  42. SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
  43. default:
  44. break;
  45. }
  46. return "Unkown";
  47. }
  48. enum What
  49. {
  50. RVC_UNKNOWN,
  51. RVC_Stand2S, /** 落地式大机*/
  52. RVC_Stand1SPlus /** 单屏大机*/
  53. };
  54. #define MACHINE_ENUM_TYPE(MACRO) \
  55. MACRO(Stand2S)\
  56. MACRO(Stand1SPlus)
  57. #undef ENUM_MAP_CONVERT
  58. #define ENUM_MAP_CONVERT(elem) \
  59. if (stricmp(lpcszTypeName, "RVC."#elem) == 0) return RVC_##elem;
  60. /*!
  61. * convert cmb site name to enum type.
  62. */
  63. static What Str2Type(LPCSTR lpcszTypeName)
  64. {
  65. if (lpcszTypeName == NULL || strlen(lpcszTypeName) == 0)
  66. return RVC_UNKNOWN;
  67. MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
  68. return RVC_UNKNOWN;
  69. }
  70. #undef ENUM_MAP_CONVERT
  71. #define ENUM_MAP_CONVERT(elem) case RVC_##elem: return "RVC."#elem;
  72. static LPCSTR Type2Str(What what) {
  73. switch (what) {
  74. MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
  75. default:
  76. break;
  77. }
  78. return "Unkown";
  79. }
  80. };
  81. /** Leak Detector*/
  82. namespace Perf
  83. {
  84. struct LeakDetector
  85. {
  86. LeakDetector()
  87. {
  88. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  89. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  90. flag |= _CRTDBG_LEAK_CHECK_DF;
  91. flag |= _CRTDBG_ALLOC_MEM_DF;
  92. _CrtSetDbgFlag(flag);
  93. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  94. }
  95. ~LeakDetector()
  96. {
  97. }
  98. };
  99. struct LineLeakDetector
  100. {
  101. LineLeakDetector() {
  102. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  103. _CrtMemCheckpoint(&s1);
  104. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  105. }
  106. ~LineLeakDetector()
  107. {
  108. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  109. _CrtMemCheckpoint(&s2);
  110. if (_CrtMemDifference(&s3, &s1, &s2))
  111. _CrtMemDumpStatistics(&s3);
  112. //_CrtDumpMemoryLeaks();
  113. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  114. }
  115. #if defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  116. _CrtMemState s1, s2, s3;
  117. #endif //defined(RVC_OS_WIN) && defined(WITH_DEBUG)
  118. };
  119. }
  120. }
  121. #ifdef RVC_OS_WIN
  122. #define SP_SLEEP(ms) Sleep(ms)
  123. #else
  124. #include <unistd.h>
  125. #define SP_SLEEP(ms) usleep((ms) * 1000)
  126. #endif
  127. #ifndef ASSERT
  128. #include <assert.h>
  129. #define ASSERT assert
  130. #endif
  131. #endif // _SP_COMM_H__