SystemResources.h 3.0 KB

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