CCOS.Dev.IODevice.Detail.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. #include "CCOS.Dev.IODevice.hpp"
  3. #include "CCOS.Dev.IODevice.Detail.hpp"
  4. using namespace CCOS::Dev::Detail;
  5. namespace nDev = CCOS::Dev;
  6. #if 0
  7. //-----------------------------------------------------------------------------
  8. // IOLog
  9. //-----------------------------------------------------------------------------
  10. auto IOLog::GetLog ()->ECOM::Log::ShareLog
  11. {
  12. return ECOM::Log::ShareLog ();
  13. }
  14. #endif
  15. //-----------------------------------------------------------------------------
  16. // IODeviceDetail
  17. //-----------------------------------------------------------------------------
  18. IODeviceDetail::IODeviceDetail (std::shared_ptr <IOEventCenter> center) : m_Dispatch (new struct Dispatch)
  19. {
  20. this->EventCenter = center;
  21. }
  22. IODeviceDetail::~IODeviceDetail ()
  23. {
  24. }
  25. void IODeviceDetail::SubscribeSelf(ccos_mqtt_connection *conn)
  26. {
  27. //ÕâÀï¶©ÔÄ topic
  28. }
  29. RET_STATUS IODeviceDetail::Add (const std::string funcName, JSONString In, JSONString& Out)
  30. {
  31. return m_Dispatch.Lock ()->Add.Invoke (funcName, In, Out);
  32. }
  33. RET_STATUS IODeviceDetail::Delete (const std::string funcName, JSONString In, JSONString& Out)
  34. {
  35. return m_Dispatch.Lock ()->Delete.Invoke (funcName, In, Out);
  36. }
  37. RET_STATUS IODeviceDetail::Get(const std::string funcName, JSONString& Out)
  38. {
  39. return m_Dispatch.Lock ()->Get.Invoke (funcName, Out);
  40. }
  41. RET_STATUS IODeviceDetail::Set (const std::string funcName, JSONString In)
  42. {
  43. return m_Dispatch.Lock ()->Set.Invoke (funcName, In);
  44. }
  45. RET_STATUS IODeviceDetail::Update (const std::string funcName, JSONString In, JSONString& Out)
  46. {
  47. return m_Dispatch.Lock ()->Update.Invoke (funcName, In, Out);
  48. }
  49. RET_STATUS IODeviceDetail::Action (const std::string funcName, JSONString In, JSONString& Out)
  50. {
  51. return m_Dispatch.Lock ()->Action.Invoke (funcName, In, Out);
  52. }
  53. #include "EasyJSONEncoder.hpp"
  54. #define AJSON EasyJSONEncoder ()
  55. std::string IODeviceDetail::GetResource () const
  56. {
  57. auto lock = m_Dispatch.Lock ();
  58. auto & disp = *lock;
  59. EasyJSONEncoder Add; for (const auto & Item : disp.Add) Add .Set (Item.first, "");
  60. EasyJSONEncoder Delete; for (const auto & Item : disp.Delete) Delete .Set (Item.first, "");
  61. EasyJSONEncoder Set; for (const auto & Item : disp.Set) Set .Set (Item.first, "");
  62. EasyJSONEncoder Update; for (const auto & Item : disp.Update) Update .Set (Item.first, "");
  63. EasyJSONEncoder Action; for (const auto & Item : disp.Action) Action .Set (Item.first, "");
  64. EasyJSONEncoder Get;
  65. for (const auto& Item : disp.Get)
  66. {
  67. std::string strValue;
  68. //get value
  69. disp.Get.Invoke(Item.first, strValue);
  70. Get.Set(Item.first, strValue.c_str());
  71. }
  72. static std::string a = R"("Add":)";
  73. static std::string d = R"("Delete":)";
  74. static std::string g = R"("Attribute":)";
  75. static std::string u = R"("Update":)";
  76. static std::string s = R"("Set":)";
  77. static std::string n = R"("Action":)";
  78. auto rc = "{\r\n" +
  79. a + Add.ToString () + ",\r\n" +
  80. d + Delete.ToString () + ",\r\n" +
  81. g + Get.ToString () + ",\r\n" +
  82. u + Update.ToString () + ",\r\n" +
  83. s + Set.ToString () + ",\r\n" +
  84. n + Action.ToString () +
  85. "\r\n}\r\n";
  86. return rc;
  87. }
  88. bool IODeviceDetail::Prepare()
  89. {
  90. return true;
  91. }