Device.Mediator.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. #include <string>
  3. #include <list>
  4. #include <vector>
  5. #include <functional>
  6. #pragma warning (disable:4251) // “Mediator::OnXX”: class“CXXHelper::Event<int>”需要有 dll 接口由 class“Mediator”的客户端使用
  7. #include "TmplEvent.tlh"
  8. #ifdef MEDIATOR_EXPORTS
  9. #define _DeviceMediator_API __declspec(dllexport)
  10. #else
  11. #define _DeviceMediator_API __declspec(dllimport)
  12. #endif
  13. namespace DIOS
  14. {
  15. namespace Dev
  16. {
  17. using JSONString = std::string;
  18. struct tIODeviceGUID
  19. {
  20. using IODeviceGUID = std::function <std::string ()>;
  21. DWORD ID;
  22. IODeviceGUID funDeviceGUID;
  23. };
  24. class tIOAction
  25. {
  26. public:
  27. using IOAction = std::function <int (JSONString, JSONString &)>;
  28. DWORD ID;
  29. std::string ProtoFuncName;
  30. IOAction funAction;
  31. };
  32. struct tIOAttribute
  33. {
  34. using IOAttribute = std::function <int (JSONString &)>;
  35. DWORD ID;
  36. std::string ProtoFuncName;
  37. IOAttribute funAttribute;
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Mediator
  41. //-----------------------------------------------------------------------------
  42. class _DeviceMediator_API Mediator
  43. {
  44. public:
  45. Mediator ();
  46. virtual ~Mediator ();
  47. public:
  48. bool Unregister (DWORD ID);
  49. //< Used by Driver or host
  50. public:
  51. int Action (std::string FuncName, JSONString, JSONString &);
  52. int Get (std::string FuncName, JSONString &);
  53. std::string GetDeviceType ();
  54. std::string GetDeviceResource ();
  55. //>
  56. //< Used by Device module
  57. public:
  58. DWORD RegistDeviceGUID (tIODeviceGUID::IODeviceGUID fun);
  59. DWORD RegistAction (std::string FuncName, tIOAction::IOAction fun);
  60. DWORD RegistAttribute (std::string FuncName, tIOAttribute::IOAttribute fun);
  61. //>
  62. //< Notify (callback) interface
  63. public:
  64. CXXHelper::Event <int, std::string, JSONString> OnNotify;
  65. CXXHelper::Event <int, std::string, JSONString, JSONString, char *, int> OnDataNotify;
  66. CXXHelper::Event <std::string, DWORD, DWORD, DWORD, DWORD> OnMaxBlockSize;
  67. //>
  68. private:
  69. std::list <tIODeviceGUID> m_DeviceGUID;
  70. std::list <tIOAction> m_Action;
  71. std::list <tIOAttribute> m_Attribute;
  72. };
  73. }
  74. }