Fix New device format.
This commit is contained in:
@@ -58,23 +58,19 @@ LightDevice::~LightDevice(void)
|
||||
*/
|
||||
int LightDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_devices_node;
|
||||
fprintf(stderr, "LightDevice::load_from_json\n");
|
||||
|
||||
// speach name
|
||||
Device::from_json(a_node);
|
||||
|
||||
// Get Light
|
||||
if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array))
|
||||
// Get Lights
|
||||
if (json_object_get_type(a_node) == json_type_array)
|
||||
{
|
||||
int the_len;
|
||||
struct json_object *the_light_node;
|
||||
|
||||
the_len = json_object_array_length(the_devices_node);
|
||||
the_len = json_object_array_length(a_node);
|
||||
for (int i = 0; i < the_len; i++)
|
||||
{
|
||||
Light the_light;
|
||||
the_light_node = json_object_array_get_idx(the_devices_node, i);
|
||||
the_light_node = json_object_array_get_idx(a_node, i);
|
||||
the_light.from_json(the_light_node);
|
||||
|
||||
m_lights.push_back(the_light);
|
||||
@@ -91,20 +87,14 @@ int LightDevice::from_json(struct json_object *a_node)
|
||||
*/
|
||||
struct json_object *LightDevice::to_json(void)
|
||||
{
|
||||
struct json_object *the_root_node, *the_devices_node;
|
||||
struct json_object *the_root_node;
|
||||
std::vector<Light>::iterator the_light_it;
|
||||
|
||||
the_root_node = json_object_new_object();
|
||||
the_devices_node = json_object_new_array();
|
||||
|
||||
// speach_name
|
||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||
// data
|
||||
json_object_object_add(the_root_node, k_entry_devices, the_devices_node);
|
||||
the_root_node = json_object_new_array();
|
||||
|
||||
for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++)
|
||||
{
|
||||
json_object_array_add(the_devices_node, (*the_light_it).to_json());
|
||||
json_object_array_add(the_root_node, (*the_light_it).to_json());
|
||||
}
|
||||
|
||||
return the_root_node;
|
||||
|
||||
@@ -58,24 +58,19 @@ ShutterDevice::~ShutterDevice(void)
|
||||
*/
|
||||
int ShutterDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_devices_node;
|
||||
fprintf(stderr, "ShutterDevice::load_from_json\n");
|
||||
|
||||
// speach name
|
||||
Device::from_json(a_node);
|
||||
|
||||
// Get Shutter
|
||||
if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array))
|
||||
if (json_object_get_type(a_node) == json_type_array)
|
||||
{
|
||||
|
||||
int the_len;
|
||||
struct json_object *the_shutter_node;
|
||||
|
||||
the_len = json_object_array_length(the_devices_node);
|
||||
the_len = json_object_array_length(a_node);
|
||||
for (int i = 0; i < the_len; i++)
|
||||
{
|
||||
Shutter the_shutter;
|
||||
the_shutter_node = json_object_array_get_idx(the_devices_node, i);
|
||||
the_shutter_node = json_object_array_get_idx(a_node, i);
|
||||
the_shutter.from_json(the_shutter_node);
|
||||
|
||||
m_shutters.push_back(the_shutter);
|
||||
@@ -92,21 +87,15 @@ int ShutterDevice::from_json(struct json_object *a_node)
|
||||
*/
|
||||
struct json_object *ShutterDevice::to_json(void)
|
||||
{
|
||||
struct json_object *the_root_node, *the_devices_node;
|
||||
struct json_object *the_root_node;
|
||||
std::vector<Shutter>::iterator the_shutter_it;
|
||||
fprintf(stderr, "ShutterDevice::to_json\n");
|
||||
|
||||
the_root_node = json_object_new_object();
|
||||
the_devices_node = json_object_new_array();
|
||||
|
||||
// speach_name
|
||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||
// devices
|
||||
json_object_object_add(the_root_node, k_entry_devices, the_devices_node);
|
||||
the_root_node = json_object_new_array();
|
||||
|
||||
for (the_shutter_it = m_shutters.begin(); the_shutter_it != m_shutters.end(); the_shutter_it++)
|
||||
{
|
||||
json_object_array_add(the_devices_node, (*the_shutter_it).to_json());
|
||||
json_object_array_add(the_root_node, (*the_shutter_it).to_json());
|
||||
}
|
||||
|
||||
return the_root_node;
|
||||
|
||||
@@ -58,24 +58,19 @@ SprinklerDevice::~SprinklerDevice(void)
|
||||
*/
|
||||
int SprinklerDevice::from_json(struct json_object *a_node)
|
||||
{
|
||||
struct json_object *the_devices_node;
|
||||
fprintf(stderr, "SprinklerDevice::load_from_json\n");
|
||||
|
||||
// speach name
|
||||
Device::from_json(a_node);
|
||||
|
||||
// Get Sprinkler
|
||||
if (json_object_object_get_ex(a_node, k_entry_devices, &the_devices_node) && (json_object_get_type(the_devices_node) == json_type_array))
|
||||
// Get Sprinklers
|
||||
if (json_object_get_type(a_node) == json_type_array)
|
||||
{
|
||||
|
||||
int the_len;
|
||||
struct json_object *the_sprinkler_node;
|
||||
|
||||
the_len = json_object_array_length(the_devices_node);
|
||||
the_len = json_object_array_length(a_node);
|
||||
for (int i = 0; i < the_len; i++)
|
||||
{
|
||||
Sprinkler the_sprinkler;
|
||||
the_sprinkler_node = json_object_array_get_idx(the_devices_node, i);
|
||||
the_sprinkler_node = json_object_array_get_idx(a_node, i);
|
||||
the_sprinkler.from_json(the_sprinkler_node);
|
||||
|
||||
m_sprinklers.push_back(the_sprinkler);
|
||||
@@ -92,21 +87,15 @@ int SprinklerDevice::from_json(struct json_object *a_node)
|
||||
*/
|
||||
struct json_object *SprinklerDevice::to_json(void)
|
||||
{
|
||||
struct json_object *the_root_node, *the_devices_node;
|
||||
struct json_object *the_root_node;
|
||||
std::vector<Sprinkler>::iterator the_sprintkler_it;
|
||||
fprintf(stderr, "SprinklerDevice::to_json\n");
|
||||
|
||||
the_root_node = json_object_new_object();
|
||||
the_devices_node = json_object_new_array();
|
||||
|
||||
// speach_name
|
||||
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||
// data
|
||||
json_object_object_add(the_root_node, k_entry_devices, the_devices_node);
|
||||
the_root_node = json_object_new_array();
|
||||
|
||||
for (the_sprintkler_it = m_sprinklers.begin(); the_sprintkler_it != m_sprinklers.end(); the_sprintkler_it++)
|
||||
{
|
||||
json_object_array_add(the_devices_node, (*the_sprintkler_it).to_json());
|
||||
json_object_array_add(the_root_node, (*the_sprintkler_it).to_json());
|
||||
}
|
||||
|
||||
return the_root_node;
|
||||
|
||||
Reference in New Issue
Block a user