CCOS.Dev.IODevice.Detail.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. #include "CCOS.Dev.IODevice.hpp"
  3. #include "CCOS.Dev.IODevice.Detail.hpp"
  4. #include "EasyJSONEncoder.hpp"
  5. #define AJSON EasyJSONEncoder ()
  6. using namespace CCOS::Dev::Detail;
  7. namespace nDev = CCOS::Dev;
  8. #if 0
  9. //-----------------------------------------------------------------------------
  10. // IOLog
  11. //-----------------------------------------------------------------------------
  12. auto IOLog::GetLog ()->ECOM::Log::ShareLog
  13. {
  14. return ECOM::Log::ShareLog ();
  15. }
  16. #endif
  17. //-----------------------------------------------------------------------------
  18. // IODeviceDetail
  19. //-----------------------------------------------------------------------------
  20. IODeviceDetail::IODeviceDetail (std::shared_ptr <IOEventCenter> center) : m_Dispatch (new struct Dispatch)
  21. {
  22. this->EventCenter = center;
  23. }
  24. IODeviceDetail::~IODeviceDetail ()
  25. {
  26. }
  27. void IODeviceDetail::SubscribeSelf(ccos_mqtt_connection *conn)
  28. {
  29. //ÕâÀï¶©ÔÄ topic
  30. }
  31. RET_STATUS IODeviceDetail::Add (const std::string funcName, JSONString In, JSONString& Out)
  32. {
  33. return m_Dispatch.Lock ()->Add.Invoke (funcName, In, Out);
  34. }
  35. RET_STATUS IODeviceDetail::Delete (const std::string funcName, JSONString In, JSONString& Out)
  36. {
  37. return m_Dispatch.Lock ()->Delete.Invoke (funcName, In, Out);
  38. }
  39. RET_STATUS IODeviceDetail::Get(const std::string funcName, JSONString& Out)
  40. {
  41. return m_Dispatch.Lock ()->Get.Invoke (funcName, Out);
  42. }
  43. RET_STATUS IODeviceDetail::Set (const std::string funcName, JSONString In)
  44. {
  45. return m_Dispatch.Lock ()->Set.Invoke (funcName, In);
  46. }
  47. RET_STATUS IODeviceDetail::Update (const std::string funcName, JSONString In, JSONString& Out)
  48. {
  49. return m_Dispatch.Lock ()->Update.Invoke (funcName, In, Out);
  50. }
  51. RET_STATUS IODeviceDetail::Action (const std::string funcName, JSONString In, JSONString& Out)
  52. {
  53. return m_Dispatch.Lock ()->Action.Invoke (funcName, In, Out);
  54. }
  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. }