wip light transform
This commit is contained in:
@@ -57,7 +57,7 @@ Device::~Device (void)
|
|||||||
*
|
*
|
||||||
* @brief Load Device Object From a Json Object stringified.
|
* @brief Load Device Object From a Json Object stringified.
|
||||||
*/
|
*/
|
||||||
int Device::from_json (const std::string &a_json)
|
int Device::from_json (struct json_object *a_node)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Device::load_from_json...\n");
|
fprintf(stderr, "Device::load_from_json...\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class Device
|
|||||||
Device(void);
|
Device(void);
|
||||||
virtual ~Device(void);
|
virtual ~Device(void);
|
||||||
|
|
||||||
virtual int from_json(const std::string &a_json);
|
virtual int from_json(struct json_object *a_node);
|
||||||
virtual struct json_object *to_json(void) const;
|
virtual struct json_object *to_json(void) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -27,10 +27,15 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#include "devices/light.h"
|
#include "devices/light.h"
|
||||||
|
|
||||||
#include "devices/light-device.h"
|
#include "devices/light-device.h"
|
||||||
|
|
||||||
|
#define k_entry_speach_name "speach_name"
|
||||||
|
#define k_entry_data "data"
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn LightDevice
|
* @fn LightDevice
|
||||||
*
|
*
|
||||||
@@ -56,18 +61,31 @@ LightDevice::~LightDevice(void)
|
|||||||
*/
|
*/
|
||||||
int LightDevice::from_json(struct json_object *a_node)
|
int LightDevice::from_json(struct json_object *a_node)
|
||||||
{
|
{
|
||||||
|
struct json_object *the_value_node, *the_data_node;
|
||||||
fprintf(stderr, "LightDevice::load_from_json\n");
|
fprintf(stderr, "LightDevice::load_from_json\n");
|
||||||
#if 0
|
|
||||||
mspeach_name = anElem["speach_name"].asString();
|
|
||||||
|
|
||||||
for (Json::Value& theElement : anElem["data"]) {
|
// speach name
|
||||||
Light theLight;
|
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node)) {
|
||||||
if (theLight.load_from_json (theElement) == 0) {
|
|
||||||
|
|
||||||
mLights.push_back (theLight);
|
m_speach_name = json_object_get_string(the_value_node);
|
||||||
|
}
|
||||||
|
// Get Light
|
||||||
|
else if (json_object_object_get_ex(a_node, k_entry_data, &the_data_node) && (json_object_get_type(the_data_node) == json_type_array)) {
|
||||||
|
|
||||||
|
int the_len;
|
||||||
|
struct json_object *the_light_node;
|
||||||
|
|
||||||
|
the_len = json_object_array_length(the_data_node);
|
||||||
|
for (int i = 0; i < the_len; i++)
|
||||||
|
{
|
||||||
|
Light the_light;
|
||||||
|
the_light_node = json_object_array_get_idx(the_data_node, i);
|
||||||
|
the_light.from_json(the_light_node);
|
||||||
|
|
||||||
|
m_lights.push_back (the_light);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,26 +96,23 @@ int LightDevice::from_json(struct json_object *a_node)
|
|||||||
*/
|
*/
|
||||||
struct json_object *LightDevice::to_json(void)
|
struct json_object *LightDevice::to_json(void)
|
||||||
{
|
{
|
||||||
#if 0
|
struct json_object *the_root_node, *the_data_node;
|
||||||
Json::Value theResult;
|
std::vector<Light>::iterator the_light_it;
|
||||||
Json::Value data_json(Json::arrayValue);
|
|
||||||
std::vector<Light>::iterator theLight_it;
|
|
||||||
|
|
||||||
fprintf (stderr, "LightDevice::to_json\n");
|
the_root_node = json_object_new_object();
|
||||||
|
the_data_node = json_object_new_array();
|
||||||
|
|
||||||
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++) {
|
// 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_data, the_data_node);
|
||||||
|
|
||||||
data_json.append ((*theLight_it).to_json());
|
|
||||||
|
for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++) {
|
||||||
|
json_object_array_add(the_data_node, (*the_light_it).to_json());
|
||||||
}
|
}
|
||||||
|
|
||||||
theResult["speach_name"] = mspeach_name;
|
return the_root_node;
|
||||||
theResult["data"] = data_json;
|
|
||||||
|
|
||||||
if (bDataOnly == true)
|
|
||||||
return data_json;
|
|
||||||
|
|
||||||
return theResult;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class LightDevice : public Device
|
|||||||
int set(int anID, bool aState);
|
int set(int anID, bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Light> mLights;
|
std::vector<Light> m_lights;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _LIGHT_DEVICE_H */
|
#endif /* _LIGHT_DEVICE_H */
|
||||||
|
|||||||
@@ -27,11 +27,23 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#include <ubus-cpp/ubus-call.h>
|
#include <ubus-cpp/ubus-call.h>
|
||||||
|
|
||||||
#include "devices/light.h"
|
#include "devices/light.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define k_entry_id "id"
|
||||||
|
#define k_entry_name "name"
|
||||||
|
#define k_entry_speach_name "speach_name"
|
||||||
|
#define k_entry_zone "zone"
|
||||||
|
#define k_entry_state "state"
|
||||||
|
#define k_entry_sender "sender"
|
||||||
|
#define k_entry_interruptor "interruptor"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn Light
|
* @fn Light
|
||||||
*
|
*
|
||||||
@@ -59,15 +71,37 @@ Light::~Light (void)
|
|||||||
*/
|
*/
|
||||||
int Light::from_json (struct json_object *a_node)
|
int Light::from_json (struct json_object *a_node)
|
||||||
{
|
{
|
||||||
#if 0
|
struct json_object *the_value_node;
|
||||||
mID = anElem["id"].asInt();
|
|
||||||
mName = anElem["name"].asString();
|
// id
|
||||||
mSpeach_name = anElem["speach_name"].asString();
|
if (json_object_object_get_ex(a_node, k_entry_id, &the_value_node)) {
|
||||||
mZone = anElem["zone"].asString();
|
m_id = json_object_get_int(the_value_node);
|
||||||
mState = anElem["state"].asBool();
|
}
|
||||||
mSender = anElem["sender"].asInt();
|
// name
|
||||||
mInterruptor = anElem["interruptor"].asInt();
|
if (json_object_object_get_ex(a_node, k_entry_name, &the_value_node)) {
|
||||||
#endif
|
m_name = json_object_get_string(the_value_node);
|
||||||
|
}
|
||||||
|
// speach_name
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_speach_name, &the_value_node)) {
|
||||||
|
m_speach_name = json_object_get_string(the_value_node);
|
||||||
|
}
|
||||||
|
// zone
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_zone, &the_value_node)) {
|
||||||
|
m_zone = json_object_get_string(the_value_node);
|
||||||
|
}
|
||||||
|
// state
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_state, &the_value_node)) {
|
||||||
|
m_state = json_object_get_boolean(the_value_node);
|
||||||
|
}
|
||||||
|
// sender
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_sender, &the_value_node)) {
|
||||||
|
m_sender = json_object_get_int(the_value_node);
|
||||||
|
}
|
||||||
|
// interruptor
|
||||||
|
if (json_object_object_get_ex(a_node, k_entry_interruptor, &the_value_node)) {
|
||||||
|
m_interruptor = json_object_get_int(the_value_node);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,19 +113,26 @@ int Light::from_json (struct json_object *a_node)
|
|||||||
*/
|
*/
|
||||||
struct json_object *Light::to_json (void) const
|
struct json_object *Light::to_json (void) const
|
||||||
{
|
{
|
||||||
#if 0
|
struct json_object *the_root_node;
|
||||||
Json::Value aResult(Json::objectValue);
|
|
||||||
fprintf (stderr, "Light::to_json\n");
|
|
||||||
aResult["id"] = mID;
|
|
||||||
aResult["name"] = mName;
|
|
||||||
aResult["speach_name"] = mSpeach_name;
|
|
||||||
aResult["zone"] = mZone;
|
|
||||||
aResult["state"] = mState;
|
|
||||||
aResult["sender"] = mSender;
|
|
||||||
aResult["interruptor"] = mInterruptor;
|
|
||||||
|
|
||||||
return aResult;
|
the_root_node = json_object_new_object();
|
||||||
#endif
|
|
||||||
|
// id
|
||||||
|
json_object_object_add(the_root_node, k_entry_id, json_object_new_int(m_id));
|
||||||
|
// name
|
||||||
|
json_object_object_add(the_root_node, k_entry_name, json_object_new_string(m_name.c_str()));
|
||||||
|
// speach_name
|
||||||
|
json_object_object_add(the_root_node, k_entry_speach_name, json_object_new_string(m_speach_name.c_str()));
|
||||||
|
// zone
|
||||||
|
json_object_object_add(the_root_node, k_entry_zone, json_object_new_string(m_zone.c_str()));
|
||||||
|
// state
|
||||||
|
json_object_object_add(the_root_node, k_entry_state, json_object_new_boolean(m_state));
|
||||||
|
// sender
|
||||||
|
json_object_object_add(the_root_node, k_entry_sender, json_object_new_int(m_sender));
|
||||||
|
// interruptor
|
||||||
|
json_object_object_add(the_root_node, k_entry_interruptor, json_object_new_int(m_interruptor));
|
||||||
|
|
||||||
|
return the_root_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user