IODeviceWithSCF.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 int Connect () override;
  50. virtual void Disconnect () override;
  51. virtual bool isConnected () const override;
  52. virtual void FireNotify (int Code, std::string Key, std::string Content) = 0;
  53. protected:
  54. virtual void Dequeue (const char * Packet, DWORD Length) = 0;
  55. protected:
  56. nsSCF::SCF m_SCF;
  57. SyncEvent::Auto OnNewPacket;
  58. std::thread::id m_TID;
  59. std::string m_SCFDllName;
  60. int m_msWaitSCFTimeOut; //
  61. static const int CMD_LEN_MAX = 1024;
  62. };
  63. }