wip remove json-cpp

This commit is contained in:
jbnadal
2018-04-04 11:45:05 +02:00
parent 98e209ef09
commit 69e71281b2
8 changed files with 90 additions and 114 deletions

View File

@@ -44,9 +44,8 @@ file(
add_executable (domod ${source_files}) add_executable (domod ${source_files})
target_link_libraries (domod target_link_libraries (domod
# LINK_PUBLIC LINK_PUBLIC
# json-cpp ubus-cpp
# ubus-cpp
json-c json-c
ubox ubox
ubus ubus

View File

@@ -1,5 +1,5 @@
/*! /*!
* Device.cpp * device.cpp
* *
* Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved. * Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved.
* *
@@ -52,7 +52,7 @@ Device::~Device(void)
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn from_json * @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) int Device::from_json(struct json_object *a_node)
{ {

View File

@@ -95,29 +95,6 @@ int DevicesManager::load(void)
/* Clean the json object. */ /* Clean the json object. */
json_object_put(the_root_node); 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; return 0;
} }
@@ -128,21 +105,24 @@ int DevicesManager::load(void)
*/ */
int DevicesManager::save(void) int DevicesManager::save(void)
{ {
#if 0 int the_result;
Json::StyledStreamWriter theWriter; struct json_object *the_root_node;
Json::Value theRoot(Json::objectValue); the_root_node = json_object_new_object();
fprintf (stderr, "Devices::Save...\n");
theRoot["Lights"] = mLights.to_json(); // Lights
theRoot["Shutters"] = mShutters.to_json(); json_object_object_add(the_root_node, kLightEntry, m_lights.to_json());
theRoot["Sprinklers"] = mSprinklers.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());
/* Save to the File. */ the_result = json_object_to_file(m_file_path.c_str(), the_root_node);
std::ofstream theOutput (mFilePath.c_str());
theWriter.write (theOutput, theRoot); /* Clean the json object. */
#endif json_object_put(the_root_node);
return 0;
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) int DevicesManager::set(const std::string &a_capability, int an_id, bool a_state)
{ {
#if 0 int the_result = -1;
int theResult = -1;
if (aCapability == "Lights") { if (a_capability == kLightEntry)
{
theResult = mLights.set (anID, aState); the_result = m_lights.set(an_id, a_state);
} }
else if (aCapability == "Shutters") { else if (a_capability == kShutterEntry)
{
theResult = mShutters.set (anID, aState); the_result = m_shutters.set(an_id, a_state);
} }
else if (aCapability == "Sprinklers") { else if (a_capability == kSprinklerEntry)
{
theResult = mSprinklers.set (anID, aState); the_result = m_sprinklers.set(an_id, a_state);
} }
if (theResult == 0) if (the_result == 0) {
save (); save();
}
return theResult; return the_result;
#endif
} }

View File

@@ -115,17 +115,18 @@ struct json_object *LightDevice::to_json(void)
* *
* @brief set the new light state. * @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 std::vector<Light>::iterator the_light_it;
int theID;
bool theState;
theID = anElement["id"].asInt(); for (the_light_it = m_lights.begin(); the_light_it != m_lights.end(); the_light_it++)
theState = anElement["state"].asBool(); {
if ((*the_light_it).get_id() == an_id)
return set (theID, theState); {
#endif 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. * @brief set the new light state.
*/ */
int LightDevice::set(int an_id, bool a_state)
{
#if 0 #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 set (theID, theState);
{
return (*theLight_it).update(aState);
}
}
#endif
return -1;
} }
#endif

View File

@@ -46,7 +46,7 @@ class LightDevice : public Device
int from_json(struct json_object *a_node); int from_json(struct json_object *a_node);
struct json_object *to_json(void); 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); int set(int anID, bool aState);
private: private:

View File

@@ -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) int Light::send_state(void)
{ {
#if 0 int the_result;
UBusCall theCmd; std::string the_output_result;
Json::Value theParam; struct json_object *the_parameter_doc;
Json::StyledWriter theWriter; UBusCall the_cmd;
std::string theResult;
theParam["sender"] = mSender; the_parameter_doc = json_object_new_object();
theParam["interruptor"] = mInterruptor; json_object_object_add(the_parameter_doc, k_entry_state, json_object_new_boolean(m_state));
theParam["state"] = mState; 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));
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult); the_result = the_cmd.exec("chacon", "set", json_object_to_json_string(the_parameter_doc), the_output_result);
#endif
json_object_put(the_parameter_doc);
return the_result;
} }

View File

@@ -115,17 +115,19 @@ struct json_object *SprinklerDevice::to_json(void)
* *
* @brief set the new Sprinkler state. * @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 std::vector<Sprinkler>::iterator the_sprinkler_it;
int theID;
bool theState;
theID = anElement["id"].asInt(); for (the_sprinkler_it = m_sprinklers.begin(); the_sprinkler_it != m_sprinklers.end(); the_sprinkler_it++)
theState = anElement["state"].asBool(); {
if ((*the_sprinkler_it).get_id() == an_id)
{
return (*the_sprinkler_it).update(a_state);
}
}
return set (theID, theState); return -1;
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
@@ -133,18 +135,15 @@ int SprinklerDevice::set(struct json_object *a_node)
* *
* @brief set the new Sprinkler state. * @brief set the new Sprinkler state.
*/ */
int SprinklerDevice::set(int anID, bool aState)
{
#if 0 #if 0
std::vector<Sprinkler>::iterator theSprinkler_it; int SprinklerDevice::set(struct json_object *a_node)
{
int theID;
bool theState;
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) { theID = anElement["id"].asInt();
theState = anElement["state"].asBool();
if ((*theSprinkler_it).getID() == anID) { return set (theID, theState);
return (*theSprinkler_it).update (aState);
}
}
#endif
return -1;
} }
#endif

View File

@@ -47,7 +47,7 @@ class SprinklerDevice : public Device
int from_json(struct json_object *a_node); int from_json(struct json_object *a_node);
struct json_object *to_json(void); 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); int set(int an_id, bool a_state);
private: private: