From 9df77ec9e3c438863196000b3b148ab971a5b921 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Wed, 4 Apr 2018 23:17:25 +0200 Subject: [PATCH] device manager is complete --- .../domod/src/devices/devices-manager.cpp | 32 +++++++++++-------- src/prog/domod/src/devices/light.cpp | 14 ++++---- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/prog/domod/src/devices/devices-manager.cpp b/src/prog/domod/src/devices/devices-manager.cpp index 22fbdbd4..d454d403 100644 --- a/src/prog/domod/src/devices/devices-manager.cpp +++ b/src/prog/domod/src/devices/devices-manager.cpp @@ -126,26 +126,32 @@ int DevicesManager::save(void) */ std::string DevicesManager::get(const std::string &a_capability) { -#if 0 - Json::StyledWriter theWriter; - Json::Value theOutput; - fprintf (stderr, "Devices::get...\n"); - - if (aCapability == "Lights") { + std::string the_output; + struct json_object *the_output_node; + fprintf(stderr, "Devices::get...\n"); - theOutput[aCapability] = mLights.to_json (true); + the_output_node = json_object_new_object(); + + if (a_capability == kLightEntry) + { + json_object_object_add(the_output_node, kLightEntry, m_lights.to_json()); } - else if (aCapability == "Shutters") { + else if (a_capability == kShutterEntry) + { - theOutput[aCapability] = mShutters.to_json (true); + json_object_object_add(the_output_node, kShutterEntry, m_shutters.to_json()); } - else if (aCapability == "Sprinklers") { + else if (a_capability == kSprinklerEntry) + { - theOutput[aCapability] = mSprinklers.to_json (true); + json_object_object_add(the_output_node, kSprinklerEntry, m_sprinklers.to_json()); } - return theWriter.write (theOutput).c_str(); -#endif + the_output = json_object_to_json_string(the_output_node); + + json_object_put(the_output_node); + + return the_output; } /*! ---------------------------------------------------------------------------- diff --git a/src/prog/domod/src/devices/light.cpp b/src/prog/domod/src/devices/light.cpp index 30add525..e9e33690 100644 --- a/src/prog/domod/src/devices/light.cpp +++ b/src/prog/domod/src/devices/light.cpp @@ -163,17 +163,17 @@ int Light::send_state(void) { int the_result; std::string the_output_result; - struct json_object *the_parameter_doc; + struct json_object *the_parameter_node; UBusCall the_cmd; - the_parameter_doc = json_object_new_object(); - json_object_object_add(the_parameter_doc, k_entry_state, json_object_new_boolean(m_state)); - json_object_object_add(the_parameter_doc, k_entry_sender, json_object_new_int(m_sender)); - json_object_object_add(the_parameter_doc, k_entry_interruptor, json_object_new_int(m_interruptor)); + the_parameter_node = json_object_new_object(); + json_object_object_add(the_parameter_node, k_entry_state, json_object_new_boolean(m_state)); + json_object_object_add(the_parameter_node, k_entry_sender, json_object_new_int(m_sender)); + json_object_object_add(the_parameter_node, k_entry_interruptor, json_object_new_int(m_interruptor)); - the_result = the_cmd.exec("chacon", "set", json_object_to_json_string(the_parameter_doc), the_output_result); + the_result = the_cmd.exec("chacon", "set", json_object_to_json_string(the_parameter_node), the_output_result); - json_object_put(the_parameter_doc); + json_object_put(the_parameter_node); return the_result; }