wip remove json-cpp
This commit is contained in:
@@ -44,9 +44,8 @@ file(
|
||||
add_executable (domod ${source_files})
|
||||
|
||||
target_link_libraries (domod
|
||||
# LINK_PUBLIC
|
||||
# json-cpp
|
||||
# ubus-cpp
|
||||
LINK_PUBLIC
|
||||
ubus-cpp
|
||||
json-c
|
||||
ubox
|
||||
ubus
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Device.cpp
|
||||
* device.cpp
|
||||
*
|
||||
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -52,7 +52,7 @@ Device::~Device(void)
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn from_json
|
||||
*
|
||||
* @brief Load Device Object From a Json Object stringified.
|
||||
* @brief Load Device Object From a Json Object.
|
||||
*/
|
||||
int Device::from_json(struct json_object *a_node)
|
||||
{
|
||||
|
||||
@@ -95,29 +95,6 @@ int DevicesManager::load(void)
|
||||
/* Clean the json object. */
|
||||
json_object_put(the_root_node);
|
||||
|
||||
#if 0
|
||||
Json::Reader theReader;
|
||||
Json::Value theRoot;
|
||||
std::ifstream theDevicesFile (mFilePath.c_str());
|
||||
fprintf (stderr, "Devices::load...\n");
|
||||
|
||||
/* Load and Parse the Json File. */
|
||||
if (!theReader.parse (theDevicesFile, theRoot)) {
|
||||
|
||||
fprintf (stderr, "Failed to parse the Devices File (%s).\n",
|
||||
mFilePath.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Open Lights. */
|
||||
mLights.load_from_json (theRoot["Lights"]);
|
||||
|
||||
/* Open Shutters. */
|
||||
mShutters.load_from_json (theRoot["Shutters"]);
|
||||
|
||||
/* Open Sprinklers. */
|
||||
mSprinklers.load_from_json (theRoot["Sprinklers"]);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -128,21 +105,24 @@ int DevicesManager::load(void)
|
||||
*/
|
||||
int DevicesManager::save(void)
|
||||
{
|
||||
#if 0
|
||||
Json::StyledStreamWriter theWriter;
|
||||
|
||||
Json::Value theRoot(Json::objectValue);
|
||||
fprintf (stderr, "Devices::Save...\n");
|
||||
int the_result;
|
||||
struct json_object *the_root_node;
|
||||
|
||||
theRoot["Lights"] = mLights.to_json();
|
||||
theRoot["Shutters"] = mShutters.to_json();
|
||||
theRoot["Sprinklers"] = mSprinklers.to_json();
|
||||
the_root_node = json_object_new_object();
|
||||
|
||||
/* Save to the File. */
|
||||
std::ofstream theOutput (mFilePath.c_str());
|
||||
theWriter.write (theOutput, theRoot);
|
||||
#endif
|
||||
return 0;
|
||||
// Lights
|
||||
json_object_object_add(the_root_node, kLightEntry, m_lights.to_json());
|
||||
// Shutters
|
||||
json_object_object_add(the_root_node, kShutterEntry, m_shutters.to_json());
|
||||
// Sprinklers
|
||||
json_object_object_add(the_root_node, kSprinklerEntry, m_sprinklers.to_json());
|
||||
|
||||
the_result = json_object_to_file(m_file_path.c_str(), the_root_node);
|
||||
|
||||
/* Clean the json object. */
|
||||
json_object_put(the_root_node);
|
||||
|
||||
return the_result;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -211,25 +191,24 @@ int Devices::set (const std::string &aCapability, Json::Value anElement)
|
||||
*/
|
||||
int DevicesManager::set(const std::string &a_capability, int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
int theResult = -1;
|
||||
int the_result = -1;
|
||||
|
||||
if (aCapability == "Lights") {
|
||||
|
||||
theResult = mLights.set (anID, aState);
|
||||
if (a_capability == kLightEntry)
|
||||
{
|
||||
the_result = m_lights.set(an_id, a_state);
|
||||
}
|
||||
else if (aCapability == "Shutters") {
|
||||
|
||||
theResult = mShutters.set (anID, aState);
|
||||
else if (a_capability == kShutterEntry)
|
||||
{
|
||||
the_result = m_shutters.set(an_id, a_state);
|
||||
}
|
||||
else if (aCapability == "Sprinklers") {
|
||||
|
||||
theResult = mSprinklers.set (anID, aState);
|
||||
else if (a_capability == kSprinklerEntry)
|
||||
{
|
||||
the_result = m_sprinklers.set(an_id, a_state);
|
||||
}
|
||||
|
||||
if (theResult == 0)
|
||||
save ();
|
||||
if (the_result == 0) {
|
||||
save();
|
||||
}
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
return the_result;
|
||||
}
|
||||
|
||||
@@ -115,17 +115,18 @@ struct json_object *LightDevice::to_json(void)
|
||||
*
|
||||
* @brief set the new light state.
|
||||
*/
|
||||
int LightDevice::set(struct json_object *a_node)
|
||||
int LightDevice::set(int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
int theID;
|
||||
bool theState;
|
||||
std::vector<Light>::iterator the_light_it;
|
||||
|
||||
theID = anElement["id"].asInt();
|
||||
theState = anElement["state"].asBool();
|
||||
|
||||
return set (theID, theState);
|
||||
#endif
|
||||
for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++)
|
||||
{
|
||||
if ((*the_light_it).get_id() == an_id)
|
||||
{
|
||||
return (*the_light_it).update(a_state);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -133,20 +134,15 @@ int LightDevice::set(struct json_object *a_node)
|
||||
*
|
||||
* @brief set the new light state.
|
||||
*/
|
||||
int LightDevice::set(int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Light>::iterator theLight_it;
|
||||
int LightDevice::set(struct json_object *a_node)
|
||||
{
|
||||
int theID;
|
||||
bool theState;
|
||||
|
||||
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++)
|
||||
{
|
||||
theID = anElement["id"].asInt();
|
||||
theState = anElement["state"].asBool();
|
||||
|
||||
if ((*theLight_it).getID() == anID)
|
||||
{
|
||||
|
||||
return (*theLight_it).update(aState);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
return set (theID, theState);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -46,7 +46,7 @@ class LightDevice : public Device
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void);
|
||||
|
||||
int set(struct json_object *a_node);
|
||||
//int set(struct json_object *a_node);
|
||||
int set(int anID, bool aState);
|
||||
|
||||
private:
|
||||
|
||||
@@ -164,22 +164,25 @@ uint16_t Light::get_id(void)
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn sendState
|
||||
* @fn send_state
|
||||
*
|
||||
* @brief Send the Curent State of the Light.
|
||||
* @brief Send the Curent State of the Light to be applyed.
|
||||
*/
|
||||
int Light::send_state(void)
|
||||
{
|
||||
#if 0
|
||||
UBusCall theCmd;
|
||||
Json::Value theParam;
|
||||
Json::StyledWriter theWriter;
|
||||
std::string theResult;
|
||||
|
||||
theParam["sender"] = mSender;
|
||||
theParam["interruptor"] = mInterruptor;
|
||||
theParam["state"] = mState;
|
||||
int the_result;
|
||||
std::string the_output_result;
|
||||
struct json_object *the_parameter_doc;
|
||||
UBusCall the_cmd;
|
||||
|
||||
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
|
||||
#endif
|
||||
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_result = the_cmd.exec("chacon", "set", json_object_to_json_string(the_parameter_doc), the_output_result);
|
||||
|
||||
json_object_put(the_parameter_doc);
|
||||
|
||||
return the_result;
|
||||
}
|
||||
|
||||
@@ -115,17 +115,19 @@ struct json_object *SprinklerDevice::to_json(void)
|
||||
*
|
||||
* @brief set the new Sprinkler state.
|
||||
*/
|
||||
int SprinklerDevice::set(struct json_object *a_node)
|
||||
int SprinklerDevice::set(int an_id, bool a_state)
|
||||
{
|
||||
#if 0
|
||||
int theID;
|
||||
bool theState;
|
||||
std::vector<Sprinkler>::iterator the_sprinkler_it;
|
||||
|
||||
theID = anElement["id"].asInt();
|
||||
theState = anElement["state"].asBool();
|
||||
for (the_sprinkler_it = m_sprinklers.begin(); the_sprinkler_it != m_sprinklers.end(); the_sprinkler_it++)
|
||||
{
|
||||
if ((*the_sprinkler_it).get_id() == an_id)
|
||||
{
|
||||
return (*the_sprinkler_it).update(a_state);
|
||||
}
|
||||
}
|
||||
|
||||
return set (theID, theState);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -133,18 +135,15 @@ int SprinklerDevice::set(struct json_object *a_node)
|
||||
*
|
||||
* @brief set the new Sprinkler state.
|
||||
*/
|
||||
int SprinklerDevice::set(int anID, bool aState)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Sprinkler>::iterator theSprinkler_it;
|
||||
|
||||
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) {
|
||||
|
||||
if ((*theSprinkler_it).getID() == anID) {
|
||||
|
||||
return (*theSprinkler_it).update (aState);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
int SprinklerDevice::set(struct json_object *a_node)
|
||||
{
|
||||
int theID;
|
||||
bool theState;
|
||||
|
||||
theID = anElement["id"].asInt();
|
||||
theState = anElement["state"].asBool();
|
||||
|
||||
return set (theID, theState);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -47,7 +47,7 @@ class SprinklerDevice : public Device
|
||||
int from_json(struct json_object *a_node);
|
||||
struct json_object *to_json(void);
|
||||
|
||||
int set(struct json_object *a_node);
|
||||
//int set(struct json_object *a_node);
|
||||
int set(int an_id, bool a_state);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user