123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- //
- #include "CCOS.Dev.IODevice.hpp"
- #include "CCOS.Dev.IODevice.Detail.hpp"
- using namespace CCOS::Dev::Detail;
- namespace nDev = CCOS::Dev;
- #if 0
- //-----------------------------------------------------------------------------
- // IOLog
- //-----------------------------------------------------------------------------
- auto IOLog::GetLog ()->ECOM::Log::ShareLog
- {
- return ECOM::Log::ShareLog ();
- }
- #endif
- //-----------------------------------------------------------------------------
- // IODeviceDetail
- //-----------------------------------------------------------------------------
- IODeviceDetail::IODeviceDetail (std::shared_ptr <IOEventCenter> center) : m_Dispatch (new struct Dispatch)
- {
- this->EventCenter = center;
- }
- IODeviceDetail::~IODeviceDetail ()
- {
- }
- void IODeviceDetail::SubscribeSelf(ccos_mqtt_connection *conn)
- {
- //ÕâÀï¶©ÔÄ topic
- }
- RET_STATUS IODeviceDetail::Add (const std::string funcName, JSONString In, JSONString& Out)
- {
- return m_Dispatch.Lock ()->Add.Invoke (funcName, In, Out);
- }
- RET_STATUS IODeviceDetail::Delete (const std::string funcName, JSONString In, JSONString& Out)
- {
- return m_Dispatch.Lock ()->Delete.Invoke (funcName, In, Out);
- }
- RET_STATUS IODeviceDetail::Get(const std::string funcName, JSONString& Out)
- {
- return m_Dispatch.Lock ()->Get.Invoke (funcName, Out);
- }
- RET_STATUS IODeviceDetail::Set (const std::string funcName, JSONString In)
- {
- return m_Dispatch.Lock ()->Set.Invoke (funcName, In);
- }
- RET_STATUS IODeviceDetail::Update (const std::string funcName, JSONString In, JSONString& Out)
- {
- return m_Dispatch.Lock ()->Update.Invoke (funcName, In, Out);
- }
- RET_STATUS IODeviceDetail::Action (const std::string funcName, JSONString In, JSONString& Out)
- {
- return m_Dispatch.Lock ()->Action.Invoke (funcName, In, Out);
- }
- #include "EasyJSONEncoder.hpp"
- #define AJSON EasyJSONEncoder ()
- std::string IODeviceDetail::GetResource () const
- {
- auto lock = m_Dispatch.Lock ();
- auto & disp = *lock;
- EasyJSONEncoder Add; for (const auto & Item : disp.Add) Add .Set (Item.first, "");
- EasyJSONEncoder Delete; for (const auto & Item : disp.Delete) Delete .Set (Item.first, "");
- EasyJSONEncoder Set; for (const auto & Item : disp.Set) Set .Set (Item.first, "");
- EasyJSONEncoder Update; for (const auto & Item : disp.Update) Update .Set (Item.first, "");
- EasyJSONEncoder Action; for (const auto & Item : disp.Action) Action .Set (Item.first, "");
- EasyJSONEncoder Get;
- for (const auto& Item : disp.Get)
- {
- std::string strValue;
- //get value
- disp.Get.Invoke(Item.first, strValue);
- Get.Set(Item.first, strValue.c_str());
- }
- static std::string a = R"("Add":)";
- static std::string d = R"("Delete":)";
- static std::string g = R"("Attribute":)";
- static std::string u = R"("Update":)";
- static std::string s = R"("Set":)";
- static std::string n = R"("Action":)";
- auto rc = "{\r\n" +
- a + Add.ToString () + ",\r\n" +
- d + Delete.ToString () + ",\r\n" +
- g + Get.ToString () + ",\r\n" +
- u + Update.ToString () + ",\r\n" +
- s + Set.ToString () + ",\r\n" +
- n + Action.ToString () +
- "\r\n}\r\n";
- return rc;
- }
- bool IODeviceDetail::Prepare()
- {
- return true;
- }
|