CCOS.Dev.IODevice.hpp 4.3 KB

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