SystemResources.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #pragma once
  2. //#pragma warning(disable : 4251)
  3. #include <mutex>
  4. #include <cstddef>
  5. #include "Aclapi.h"
  6. #include "dt.h"
  7. #ifdef SYSTEM_RESOURCE_EXPORTS
  8. #define SYSTEM_RESOURCE_DLL_API __declspec(dllexport)
  9. #else
  10. #define SYSTEM_RESOURCE_DLL_API //__declspec(dllimport)
  11. #endif
  12. enum DEVICE_RUN_MODE { NONE = 0, AUTO = 1, DRY_RUN = 2,};
  13. #define BOND_KEY_START_EVENT "Global\\__BOND_KEY_START__"
  14. #define BOND_KEY_STOP_EVENT "Global\\__BOND_KEY_STOP__"
  15. #define CLOSE_EVENT(e) \
  16. if (e) { CloseHandle(e); e = NULL;}
  17. #define OPEN_EVENT(e,strName) \
  18. (e) = OpenEvent(EVENT_ALL_ACCESS ,FALSE,strName);
  19. #define CREATE_EVENT(e, bManual, bInitState,strName) \
  20. if ((e) == NULL) { \
  21. (e) = ::CreateEventA(NULL, (bManual), (bInitState), strName); \
  22. } \
  23. if ((e) != NULL) { \
  24. if (bInitState == TRUE) { \
  25. SetEvent(e); \
  26. } else if(bInitState == FALSE) { \
  27. ResetEvent(e); \
  28. } \
  29. }
  30. #define SET_EVENT(e) \
  31. if (e) SetEvent(e);
  32. #define RESET_EVENT(e) \
  33. if (e) ResetEvent(e);
  34. #define OPEN_BOND_KEY \
  35. SystemResources::GetInstance()->OpenBondKey();
  36. #define SET_BOND_STOP_KEY \
  37. SystemResources::GetInstance()->SetBondStartKey(false);
  38. #define SET_BOND_START_KEY \
  39. SystemResources::GetInstance()->SetBondStartKey(true);
  40. #define CHECK_STOP_KEY \
  41. (SystemResources::GetInstance()->IsBondStartKey() == false)
  42. #define CHECK_BOND_STOP_BREAK \
  43. if (SystemResources::GetInstance()->IsBondStartKey() == false) { break; }
  44. #define CHECK_BOND_STOP_RETURN \
  45. if (SystemResources::GetInstance()->IsBondStartKey() == false) { return STOP; }
  46. #define CHECK_BOND_STOP_RETURN_FAIL \
  47. if (SystemResources::GetInstance()->IsBondStartKey() == false) { return FAIL;}
  48. #define CHECK_BOND_STOP_GOTO \
  49. if (SystemResources::GetInstance()->IsBondStartKey() == false) { goto DONE; }
  50. #define WAIT_EVENT(e,t) \
  51. if(SystemResources::GetInstance()->WaitEvent(e,t)) { return FAIL;};
  52. #define CHECK_IS_DRY_RUN\
  53. SystemResources::GetInstance()->GetIsDryRunMode()
  54. class SYSTEM_RESOURCE_DLL_API SystemResources
  55. {
  56. private:
  57. static SystemResources* m_pSysRes;
  58. static std::mutex m_Mutex;
  59. bool g_bPause; //暂停运行
  60. DEVICE_RUN_MODE g_eDeviceRunMode; //设备运行模式
  61. HANDLE g_hBondKeyStartEvent = NULL; //固晶开始事件
  62. HANDLE g_hBondKeyStopEvent = NULL; //固晶停止事件
  63. PTP_POOL sm_tPool;
  64. TP_CALLBACK_ENVIRON* m_tcEnv;
  65. void CreateThreadPool();
  66. SystemResources();
  67. public:
  68. static SystemResources* GetInstance();
  69. bool IsBondStartKey();
  70. bool OpenBondKey();
  71. VOID SetBondStartKey(bool isStart);
  72. VOID SetDeviceRunMode(DEVICE_RUN_MODE bMode);
  73. bool GetIsDryRunMode();
  74. bool GetAutoMode();
  75. //设置暂停标志
  76. void SetPause(bool bPause);
  77. //获取暂停标志
  78. bool GetPause();
  79. //获取线程池资源
  80. TP_CALLBACK_ENVIRON* GetThreadPoolEnviron();
  81. LONG ThreadPoolWork(PTP_WORK_CALLBACK pfnwk, PVOID pv);
  82. bool WaitEvent(HANDLE hEvent, ULONG nWaitTime);
  83. };