This commit is contained in:
jbnadal
2016-05-23 18:18:54 +02:00
parent 111c608361
commit e05c267cec
5 changed files with 104 additions and 4 deletions

View File

@@ -50,3 +50,27 @@ Device::Device (void)
Device::~Device (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load LightDevice Object From a Json Object.
*/
int Device::load_from_json (Json::Value anElem)
{
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export LightDevice Object as JSON Object.
*/
Json::Value Device::to_json (void) const
{
Json::Value theResult;
return theResult;
}

View File

@@ -28,6 +28,7 @@
/*------------------------------- INCLUDES ----------------------------------*/
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/
@@ -39,6 +40,9 @@ class Device {
public:
Device (void);
virtual ~Device (void);
virtual int load_from_json (Json::Value anElem);
virtual Json::Value to_json (void) const;
};

View File

@@ -30,6 +30,10 @@
#include <jsoncpp/json.h>
#include "devices/LightDevice.h"
#include "devices/ShutterDevice.h"
#include "devices/SprinklerDevice.h"
#include "devices/Devices.h"
@@ -64,7 +68,7 @@ int Devices::load (void)
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)) {
@@ -72,7 +76,22 @@ int Devices::load (void)
mFilePath.c_str());
return -1;
}
//TODO
/* Open Lights. */
LightDevice theLights;
theLights.load_from_json (theRoot["Lights"]);
mDevices["Lights"] = theLights;
/* Open Shutters. */
ShutterDevice theShutters;
theShutters.load_from_json (theRoot["Shutters"]);
mDevices["Shutters"] = theShutters;
/* Open Sprinklers. */
SprinklerDevice theSprinklers;
theSprinklers.load_from_json (theRoot["Sprinklers"]);
mDevices["Sprinklers"] = theSprinklers;
return 0;
}

View File

@@ -50,3 +50,53 @@ LightDevice::LightDevice (void) : Device()
LightDevice::~LightDevice (void)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_from_json
*
* @brief Load LightDevice Object From a Json Object.
*/
int LightDevice::load_from_json (Json::Value anElem)
{
fprintf (stderr, "LightDevice::load_from_json\n");
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn to_json
*
* @brief Export LightDevice Object as JSON Object.
*/
Json::Value LightDevice::to_json (void) const
{
fprintf (stderr, "LightDevice::to_json\n");
}
/*
int Timers::load (void)
{
Json::Reader theReader;
Json::Value theRoot;
std::ifstream theTimerFile (mTimersPath.c_str());
if (!theReader.parse (theTimerFile, theRoot)) {
fprintf (stderr, "Failed to parse the Timers File (%s).\n",
mTimersPath.c_str());
return -1;
}
for (Json::Value& theElement : theRoot["timers"]) {
Event theEvent;
if (theEvent.load_from_json (theElement) == 0) {
mTimers.push_back (theEvent);
}
}
Start (k60s, true);
return 0;
}*/

View File

@@ -45,6 +45,9 @@ public:
LightDevice (void);
~LightDevice (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (void) const;
private:
std::string mspeach_name;
std::vector <Light> mLights;