IODeviceWithSCF.tlh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. #pragma once
  3. #include <thread>
  4. #include <chrono>
  5. using namespace std::chrono_literals;
  6. #include "SyncEvent.hpp"
  7. #include "DIOS.Dev.IODevice.Detail.hpp"
  8. #include "SCF.hpp"
  9. namespace nsSCF = DIOS::Dev::Communication;
  10. //-----------------------------------------------------------------------------
  11. // IODeviceWithSCF
  12. //-----------------------------------------------------------------------------
  13. namespace DIOS::Dev::Detail
  14. {
  15. template <typename T>
  16. class IODeviceWithSCF : public T
  17. {
  18. using super = typename T;
  19. protected:
  20. nsSCF::SCF m_SCF;
  21. public:
  22. IODeviceWithSCF (std::shared_ptr <IOEventCenter> center, nsSCF::SCF SCF) : super (center)
  23. {
  24. m_SCF = SCF;
  25. }
  26. };
  27. }
  28. //-----------------------------------------------------------------------------
  29. // IODeviceWithSCF
  30. //-----------------------------------------------------------------------------
  31. namespace DIOS::Dev::Detail
  32. {
  33. template <typename T>
  34. class IODriverWithSCF : public T
  35. {
  36. using super = typename T;
  37. public:
  38. IODriverWithSCF ()
  39. {
  40. m_msWaitSCFTimeOut = 200; // 如果子类不重新设置, 默认就是 0.2 秒
  41. }
  42. ~IODriverWithSCF ()
  43. {
  44. std::this_thread::sleep_for (100ms);
  45. Disconnect ();
  46. }
  47. public:
  48. virtual void Prepare () override;
  49. virtual bool DATA_ACTION Connect () override;
  50. virtual void Disconnect () override;
  51. virtual bool isConnected () const override;
  52. bool DecodePack(bool action);
  53. void SetThread_Priority(int level);
  54. void SetThread_Affinity(const std::vector<int>& cpus);
  55. protected:
  56. virtual void Dequeue (const char * Packet, DWORD Length) = 0;
  57. virtual void FireNotify (int Code, std::string Key, std::string Content) = 0;
  58. protected:
  59. nsSCF::SCF m_SCF;
  60. SyncEvent::Auto OnNewPacket;
  61. std::thread::id m_TID;
  62. std::string m_SCFDllName;
  63. int m_msWaitSCFTimeOut;
  64. bool isActDecodeFun{ true };
  65. int m_nPriority{ 0 };
  66. HANDLE m_ThreadHandle{ NULL };
  67. static const int CMD_LEN_MAX = 1024;
  68. };
  69. }