DIOS.Dev.IODevice.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #pragma once
  2. #include <memory>
  3. #include <string>
  4. #include "TmplEvent.tlh"
  5. #ifndef DIOSLOGICDEVICE_EXPORTS
  6. #ifdef _WIN64
  7. #ifdef _DEBUG
  8. #pragma comment(lib, "DIOS.Device.IODevice64D.lib")
  9. #else
  10. #pragma comment(lib, "DIOS.Device.IODevice64.lib")
  11. #endif
  12. #else
  13. #ifdef _DEBUG
  14. #pragma comment(lib, "DIOS.Device.IODeviceD.lib")
  15. #else
  16. #pragma comment(lib, "DIOS.Device.IODevice.lib")
  17. #endif
  18. #endif
  19. #endif
  20. #ifdef DIOSLOGICDEVICE_EXPORTS
  21. #define _DIOSLogicDevice_API __declspec(dllexport)
  22. #else
  23. #define _DIOSLogicDevice_API __declspec(dllimport)
  24. #endif
  25. #pragma warning (disable:4251) // warning C4251: class“std::unique_ptr<DIOS::Dev::Detail::IODeviceDetail,std::default_delete<_Ty>>”需要有 dll 接口由 class“DIOS::Dev::IODevice”的客户端使用
  26. namespace DIOS::Dev
  27. {
  28. using JSONString = std::string;
  29. namespace Detail
  30. {
  31. class IODeviceDetail;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // IOEventCenter
  35. //-----------------------------------------------------------------------------
  36. class _DIOSLogicDevice_API IOEventCenter
  37. {
  38. public:
  39. CXXHelper::Event <int, std::string, std::string> OnNotify;
  40. CXXHelper::Event <int, std::string, JSONString, JSONString, char*, int> OnDataNotify;
  41. CXXHelper::Event <std::string, DWORD, DWORD, DWORD, DWORD> OnMaxBlockSize;
  42. CXXHelper::Event <int, std::string, std::string> OnSystemLog;
  43. CXXHelper::Event <int, std::string> OnLog;
  44. CXXHelper::Event <> OnPassiveDisconnected;
  45. };
  46. //-----------------------------------------------------------------------------
  47. // IODevice
  48. // The root / base class for any IODevice
  49. //-----------------------------------------------------------------------------
  50. enum class RET_STATUS {
  51. RET_THREAD_INVALID = -4,//the calling thread is not owner
  52. RET_INVALID = -3,//the handle is invalid
  53. RET_NOSUPPORT = -2,//device not support
  54. RET_TIMEOUT = -1,//超时(无接收命令)
  55. RET_FAILED = 0,//执行命令失败
  56. RET_PENDING,//设备有接收命令,但无反馈(在一定时间内无反馈情况)
  57. RET_SUCCEED,//设备执行命令成功
  58. RET_ONGOING,//设备执行命令已经完成,但是没有达成目标.
  59. RET_FINISHED,//设备执行命令已经完成,且有达成目标.
  60. RET_WARNING
  61. };
  62. class _DIOSLogicDevice_API IODevice
  63. {
  64. private:
  65. IODevice (const IODevice &) = delete;
  66. IODevice (IODevice &&) = delete;
  67. IODevice & operator = (const IODevice &) = delete;
  68. IODevice & operator = (IODevice &&) = delete;
  69. public:
  70. IODevice (Detail::IODeviceDetail * detal); // 由内部类来构造
  71. virtual ~IODevice ();
  72. public:
  73. std::string GetGUID () const;
  74. std::string GetResource () const;
  75. bool Prepare();
  76. RET_STATUS Add (const std::string funcName, JSONString In, JSONString & Out);
  77. RET_STATUS Delete (const std::string funcName, JSONString In, JSONString & Out);
  78. RET_STATUS Update (const std::string funcName, JSONString In, JSONString & Out);
  79. RET_STATUS Action (const std::string funcName, JSONString In, JSONString & Out);
  80. RET_STATUS Get(const std::string funcName, JSONString& Out);
  81. RET_STATUS Set (const std::string funcName, JSONString In);
  82. public:
  83. std::shared_ptr <IOEventCenter> EventCenter;
  84. protected:
  85. std::unique_ptr <Detail::IODeviceDetail> m_Detail;
  86. };
  87. //-----------------------------------------------------------------------------
  88. // IODriver
  89. // The manager for IODevice
  90. //-----------------------------------------------------------------------------
  91. class _DIOSLogicDevice_API IODriver
  92. {
  93. private:
  94. IODriver (const IODriver &) = delete;
  95. IODriver (IODriver &&) = delete;
  96. IODriver & operator = (const IODriver &) = delete;
  97. IODriver & operator = (IODriver &&) = delete;
  98. public:
  99. IODriver ();
  100. virtual ~IODriver ();
  101. public:
  102. virtual void Prepare ();
  103. //< DIOS 运行环境将调用如下 API
  104. virtual bool DriverEntry (std::string CfgFileName);
  105. virtual std::string DriverProbe () = 0;
  106. virtual std::string GetGUID () const = 0;
  107. virtual std::string GetResource () = 0;
  108. virtual std::string DeviceProbe () = 0;
  109. virtual bool OnHeartBeat ();
  110. //>
  111. // Connect () 返回值的定义, 待定 !!!
  112. virtual int Connect ();
  113. virtual void Disconnect ();
  114. virtual bool isConnected () const;
  115. virtual auto CreateDevice (int index) -> std::unique_ptr <IODevice> = 0;
  116. virtual bool GetDeviceConfig(std::string & Cfg);
  117. virtual bool SetDeviceConfig(std::string Cfg);
  118. protected:
  119. std::string m_ConfigFileName;
  120. public:
  121. std::shared_ptr <IOEventCenter> EventCenter;
  122. };
  123. }