wip replate json-cpp by json-c

This commit is contained in:
jbnadal
2018-04-03 18:26:16 +02:00
parent 52df6f68bd
commit 130f8bba33
21 changed files with 317 additions and 294 deletions

View File

@@ -33,5 +33,5 @@ target_include_directories (ubus-cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
install (TARGETS ubus-cpp LIBRARY DESTINATION local/lib) install (TARGETS ubus-cpp LIBRARY DESTINATION local/lib)
file (GLOB headers $ENV{SRC_DIR}/src/lib/libubus-cpp/include/ubus-cpp/*) file (GLOB headers ${workspaceRoot}/src/lib/libubus-cpp/include/ubus-cpp/*)
install (FILES ${headers} DESTINATION include/ubus-cpp) install (FILES ${headers} DESTINATION include/ubus-cpp)

View File

@@ -15,22 +15,23 @@ file(
GLOB_RECURSE GLOB_RECURSE
source_files source_files
${workspaceRoot}/src/prog/domod/src/main.cpp ${workspaceRoot}/src/prog/domod/src/main.cpp
${workspaceRoot}/src/prog/domod/src/devices/device.cpp ${workspaceRoot}/src/prog/domod/src/devices/devices-manager.cpp
${workspaceRoot}/src/prog/domod/src/devices/devices.cpp ${workspaceRoot}/src/prog/domod/src/devices/device.cpp
${workspaceRoot}/src/prog/domod/src/timers/event.cpp ${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp ${workspaceRoot}/src/prog/domod/src/devices/shutter-device.cpp
${workspaceRoot}/src/prog/domod/src/devices/sprinkler-device.cpp
${workspaceRoot}/src/prog/domod/src/devices/light.cpp
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
#${workspaceRoot}/src/prog/domod/src/timers/event.cpp
#${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp
) )
# $ENV{SRC_DIR}/src/prog/domod/src/timers/Timers.cpp # $ENV{SRC_DIR}/src/prog/domod/src/timers/Timers.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/timers/Clock.cpp # $ENV{SRC_DIR}/src/prog/domod/src/timers/Clock.cpp
# #
# $ENV{SRC_DIR}/src/prog/domod/src/devices/LightDevice.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/devices/ShutterDevice.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/devices/SprinklerDevice.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Light.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Shutter.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/devices/Sprinkler.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities.cpp # $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_lights.cpp # $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_lights.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_shutters.cpp # $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_shutters.cpp

View File

@@ -29,24 +29,24 @@
/*------------------------------- INCLUDES ----------------------------------*/ /*------------------------------- INCLUDES ----------------------------------*/
#include <string> #include <string>
/*------------------------------ DEPENDENCIES -------------------------------*/ /*------------------------------ DEPENDENCIES -------------------------------*/
struct json_object; struct json_object;
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Device { class Device
{
public:
Device(void);
virtual ~Device(void);
public: virtual int from_json(const std::string &a_json);
Device (void); virtual struct json_object *to_json(void) const;
virtual ~Device (void);
virtual int from_json (const std::string &a_json); protected:
virtual struct json_object *to_json (void) const; std::string m_speach_name;
protected:
std::string mspeach_name;
}; };
#endif /* _DEVICE_H */ #endif /* _DEVICE_H */

View File

@@ -28,39 +28,71 @@
#include <cstdio> #include <cstdio>
#include <fstream> #include <fstream>
#include <jsoncpp/json.h> #include <json-c/json.h>
#include <json-c/json_util.h>
#include "devices/Devices.h" #include "devices/devices-manager.h"
/*------------------------------- DEFINES ----------------------------------*/
#define kLightEntry "Lights"
#define kShutterEntry "Shutters"
#define kSprinklerEntry "Sprinklers"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn Devices * @fn DevicesManager
* *
* @brief Constructor of the Devices Managagers. * @brief Constructor of the Devices Managagers.
*/ */
Devices::Devices (std::string aPath): DevicesManager::DevicesManager(const std::string &a_path) : m_file_path(a_path)
mFilePath (aPath)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn ~Devices * @fn ~DevicesManager
* *
* @brief Destructor of the Devices Managagers. * @brief Destructor of the Devices Managagers.
*/ */
Devices::~Devices (void) DevicesManager::~DevicesManager(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load * @fn load
* *
* @brief Load the Devices from the Json File. * @brief Load the Devices from the Json File.
*/ */
int Devices::load (void) int DevicesManager::load(void)
{ {
struct json_object *the_root_node, *the_value_node;
fprintf(stderr, "Devices::load...\n");
the_root_node = json_object_from_file(m_file_path.c_str());
if (the_root_node == NULL)
{
fprintf(stderr, "Failed to parse the Devices File (%s).\n", m_file_path.c_str());
return -1;
}
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
{
printf(" On a des Lights.\n");
}
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
{
printf(" On a des shutters.\n");
}
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
{
printf(" On a des sprintkler.\n");
}
/* Clean the json object. */
json_object_put(the_root_node);
#if 0
Json::Reader theReader; Json::Reader theReader;
Json::Value theRoot; Json::Value theRoot;
std::ifstream theDevicesFile (mFilePath.c_str()); std::ifstream theDevicesFile (mFilePath.c_str());
@@ -82,18 +114,18 @@ int Devices::load (void)
/* Open Sprinklers. */ /* Open Sprinklers. */
mSprinklers.load_from_json (theRoot["Sprinklers"]); mSprinklers.load_from_json (theRoot["Sprinklers"]);
#endif
return 0; return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn save * @fn save
* *
* @brief Save the Devices from the Json File. * @brief Save the Devices from the Json File.
*/ */
int Devices::save (void) int DevicesManager::save(void)
{ {
#if 0
Json::StyledStreamWriter theWriter; Json::StyledStreamWriter theWriter;
Json::Value theRoot(Json::objectValue); Json::Value theRoot(Json::objectValue);
@@ -106,18 +138,18 @@ int Devices::save (void)
/* Save to the File. */ /* Save to the File. */
std::ofstream theOutput (mFilePath.c_str()); std::ofstream theOutput (mFilePath.c_str());
theWriter.write (theOutput, theRoot); theWriter.write (theOutput, theRoot);
#endif
return 0; return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn get * @fn get
* *
* @brief get the list of devices of a specific capabilities. * @brief get the list of devices of a specific capabilities.
*/ */
std::string Devices::get (const std::string &aCapability) std::string DevicesManager::get(const std::string &a_capability)
{ {
#if 0
Json::StyledWriter theWriter; Json::StyledWriter theWriter;
Json::Value theOutput; Json::Value theOutput;
fprintf (stderr, "Devices::get...\n"); fprintf (stderr, "Devices::get...\n");
@@ -136,14 +168,15 @@ std::string Devices::get (const std::string &aCapability)
} }
return theWriter.write (theOutput).c_str(); return theWriter.write (theOutput).c_str();
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn set * @fn set
* *
* @brief get the device of a specific capabilities, with the ID. * @brief get the device of a specific capabilities, with the ID.
*/ */
#if 0
int Devices::set (const std::string &aCapability, Json::Value anElement) int Devices::set (const std::string &aCapability, Json::Value anElement)
{ {
int theResult = -1; int theResult = -1;
@@ -166,15 +199,16 @@ int Devices::set (const std::string &aCapability, Json::Value anElement)
return theResult; return theResult;
} }
#endif
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn set * @fn set
* *
* @brief get the device of a specific capabilities, with the ID. * @brief get the device of a specific capabilities, with the ID.
*/ */
int Devices::set (const std::string &aCapability, int anID, bool aState) int DevicesManager::set(const std::string &a_capability, int an_id, bool a_state)
{ {
#if 0
int theResult = -1; int theResult = -1;
if (aCapability == "Lights") { if (aCapability == "Lights") {
@@ -194,4 +228,5 @@ int Devices::set (const std::string &aCapability, int anID, bool aState)
save (); save ();
return theResult; return theResult;
#endif
} }

View File

@@ -23,44 +23,42 @@
* *
*/ */
#ifndef _DEVICES_H #ifndef _DEVICES_MANAGER_H
#define _DEVICES_H #define _DEVICES_MANAGER_H
/*------------------------------- INCLUDES ----------------------------------*/ /*------------------------------- INCLUDES ----------------------------------*/
#include <string> #include <string>
#include "devices/LightDevice.h" #include "devices/light-device.h"
#include "devices/ShutterDevice.h" #include "devices/shutter-device.h"
#include "devices/SprinklerDevice.h" #include "devices/sprinkler-device.h"
#include "devices/Device.h" #include "devices/device.h"
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Devices { class DevicesManager
{
public:
DevicesManager(const std::string &a_path);
~DevicesManager(void);
public: int load(void);
Devices (std::string aPath); int save(void);
~Devices (void);
int load (void); std::string get(const std::string &a_capability);
int save (void); //int set (const std::string &aCapability, Json::Value anElement);
int set(const std::string &a_capability, int an_id, bool a_state);
std::string get (const std::string &aCapability); private:
int set (const std::string &aCapability, Json::Value anElement); std::string m_file_path;
int set (const std::string &aCapability, int anID, bool aState);
private: LightDevice m_lights;
std::string mFilePath; ShutterDevice m_shutters;
SprinklerDevice m_sprinklers;
LightDevice mLights;
ShutterDevice mShutters;
SprinklerDevice mSprinklers;
}; };
#endif /* _DEVICES_MANAGER_H */
#endif /* _DEVICES_H */

View File

@@ -23,46 +23,41 @@
* *
*/ */
/*------------------------------- INCLUDES ----------------------------------*/ /*------------------------------- INCLUDES ----------------------------------*/
#include <cstdio> #include <cstdio>
#include "devices/Light.h" #include "devices/light.h"
#include "devices/LightDevice.h"
#include "devices/light-device.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn LightDevice * @fn LightDevice
* *
* @brief Constructor of the LightDevice Object. * @brief Constructor of the LightDevice Object.
*/ */
LightDevice::LightDevice (void) : Device() LightDevice::LightDevice(void) : Device()
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn LightDevice * @fn LightDevice
* *
* @brief Destructor of the Device Object. * @brief Destructor of the Device Object.
*/ */
LightDevice::~LightDevice (void) LightDevice::~LightDevice(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load LightDevice Object From a Json Object. * @brief Load LightDevice Object From a Json Object.
*/ */
int LightDevice::load_from_json (Json::Value anElem) int LightDevice::from_json(struct json_object *a_node)
{ {
fprintf (stderr, "LightDevice::load_from_json\n"); fprintf(stderr, "LightDevice::load_from_json\n");
#if 0
mspeach_name = anElem["speach_name"].asString(); mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) { for (Json::Value& theElement : anElem["data"]) {
@@ -72,18 +67,18 @@ int LightDevice::load_from_json (Json::Value anElem)
mLights.push_back (theLight); mLights.push_back (theLight);
} }
} }
#endif
return 0; return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn to_json * @fn to_json
* *
* @brief Export LightDevice Object as JSON Object. * @brief Export LightDevice Object as JSON Object.
*/ */
Json::Value LightDevice::to_json (bool bDataOnly) struct json_object *LightDevice::to_json(void)
{ {
#if 0
Json::Value theResult; Json::Value theResult;
Json::Value data_json(Json::arrayValue); Json::Value data_json(Json::arrayValue);
std::vector<Light>::iterator theLight_it; std::vector<Light>::iterator theLight_it;
@@ -102,16 +97,17 @@ Json::Value LightDevice::to_json (bool bDataOnly)
return data_json; return data_json;
return theResult; return theResult;
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn set * @fn set
* *
* @brief set the new light state. * @brief set the new light state.
*/ */
int LightDevice::set (Json::Value anElement) int LightDevice::set(struct json_object *a_node)
{ {
#if 0
int theID; int theID;
bool theState; bool theState;
@@ -119,25 +115,28 @@ int LightDevice::set (Json::Value anElement)
theState = anElement["state"].asBool(); theState = anElement["state"].asBool();
return set (theID, theState); return set (theID, theState);
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn set * @fn set
* *
* @brief set the new light state. * @brief set the new light state.
*/ */
int LightDevice::set (int anID, bool aState) int LightDevice::set(int an_id, bool a_state)
{ {
#if 0
std::vector<Light>::iterator theLight_it; std::vector<Light>::iterator theLight_it;
for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++) { for (theLight_it = mLights.begin(); theLight_it != mLights.end(); theLight_it++)
{
if ((*theLight_it).getID() == anID) {
return (*theLight_it).update (aState); if ((*theLight_it).getID() == anID)
{
return (*theLight_it).update(aState);
} }
} }
#endif
return -1; return -1;
} }

View File

@@ -30,30 +30,27 @@
#include <vector> #include <vector>
#include "devices/Light.h" #include "devices/light.h"
#include "devices/Device.h" #include "devices/device.h"
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class LightDevice : public Device { class LightDevice : public Device
{
public:
LightDevice(void);
~LightDevice(void);
public: int from_json(struct json_object *a_node);
LightDevice (void); struct json_object *to_json(void);
~LightDevice (void);
int load_from_json (Json::Value anElem);
Json::Value to_json (bool bDataOnly = false);
int set (Json::Value anElement); int set(struct json_object *a_node);
int set (int anID, bool aState); int set(int anID, bool aState);
private: private:
std::vector <Light> mLights; std::vector<Light> mLights;
}; };
#endif /* _LIGHT_DEVICE_H */ #endif /* _LIGHT_DEVICE_H */

View File

@@ -27,9 +27,9 @@
#include <cstdio> #include <cstdio>
#include <ubus-cpp/UBusCall.h> #include <ubus-cpp/ubus-call.h>
#include "devices/Light.h" #include "devices/light.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
@@ -53,12 +53,13 @@ Light::~Light (void)
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load a Light Element from a Json Entry. * @brief Load a Light Element from a Json Entry.
*/ */
int Light::load_from_json (Json::Value anElem) int Light::from_json (struct json_object *a_node)
{ {
#if 0
mID = anElem["id"].asInt(); mID = anElem["id"].asInt();
mName = anElem["name"].asString(); mName = anElem["name"].asString();
mSpeach_name = anElem["speach_name"].asString(); mSpeach_name = anElem["speach_name"].asString();
@@ -66,7 +67,7 @@ int Light::load_from_json (Json::Value anElem)
mState = anElem["state"].asBool(); mState = anElem["state"].asBool();
mSender = anElem["sender"].asInt(); mSender = anElem["sender"].asInt();
mInterruptor = anElem["interruptor"].asInt(); mInterruptor = anElem["interruptor"].asInt();
#endif
return 0; return 0;
} }
@@ -76,8 +77,9 @@ int Light::load_from_json (Json::Value anElem)
* *
* @brief Return Light Object as a Json Object. * @brief Return Light Object as a Json Object.
*/ */
Json::Value Light::to_json (void) const struct json_object *Light::to_json (void) const
{ {
#if 0
Json::Value aResult(Json::objectValue); Json::Value aResult(Json::objectValue);
fprintf (stderr, "Light::to_json\n"); fprintf (stderr, "Light::to_json\n");
aResult["id"] = mID; aResult["id"] = mID;
@@ -89,6 +91,7 @@ Json::Value Light::to_json (void) const
aResult["interruptor"] = mInterruptor; aResult["interruptor"] = mInterruptor;
return aResult; return aResult;
#endif
} }
@@ -97,25 +100,25 @@ Json::Value Light::to_json (void) const
* *
* @brief Update the Light State. * @brief Update the Light State.
*/ */
int Light::update (bool aState) int Light::update (bool a_state)
{ {
if (mState == aState) if (m_state == a_state)
return 1; return 1;
mState = aState; m_state = a_state;
return sendState (); return send_state ();
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn getID * @fn get_id
* *
* @brief Return the ID of the Light. * @brief Return the ID of the Light.
*/ */
uint16_t Light::getID (void) uint16_t Light::get_id (void)
{ {
return mID; return m_id;
} }
@@ -124,8 +127,9 @@ uint16_t Light::getID (void)
* *
* @brief Send the Curent State of the Light. * @brief Send the Curent State of the Light.
*/ */
int Light::sendState (void) int Light::send_state (void)
{ {
#if 0
UBusCall theCmd; UBusCall theCmd;
Json::Value theParam; Json::Value theParam;
Json::StyledWriter theWriter; Json::StyledWriter theWriter;
@@ -136,4 +140,5 @@ int Light::sendState (void)
theParam["state"] = mState; theParam["state"] = mState;
return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult); return theCmd.Exec ("chacon", "set", theWriter.write(theParam).c_str(),theResult);
#endif
} }

View File

@@ -32,38 +32,34 @@
#include <string> #include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Light { class Light
{
public:
Light(void);
~Light(void);
public: int from_json(struct json_object *a_node);
Light (void); struct json_object *to_json(void) const;
~Light (void);
int load_from_json (Json::Value anElem); int update(bool a_state);
Json::Value to_json (void) const;
int update (bool aState); uint16_t get_id(void);
uint16_t getID (void); private:
int send_state(void);
private: private:
int sendState (void); uint16_t m_id;
std::string m_name;
private: std::string m_speach_name;
uint16_t mID; std::string m_zone;
std::string mName; bool m_state;
std::string mSpeach_name; uint32_t m_sender;
std::string mZone; uint8_t m_interruptor;
bool mState;
uint32_t mSender;
uint8_t mInterruptor;
}; };
#endif /* _LIGHT_H */ #endif /* _LIGHT_H */

View File

@@ -29,7 +29,7 @@
#include <cstdio> #include <cstdio>
#include "devices/ShutterDevice.h" #include "devices/shutter-device.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
@@ -53,14 +53,14 @@ ShutterDevice::~ShutterDevice (void)
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load ShutterDevice Object From a Json Object. * @brief Load ShutterDevice Object From a Json Object.
*/ */
int ShutterDevice::load_from_json (Json::Value anElem) int ShutterDevice::from_json (struct json_object *a_node)
{ {
fprintf (stderr, "ShutterDevice::load_from_json\n"); fprintf (stderr, "ShutterDevice::load_from_json\n");
#if 0
mspeach_name = anElem["speach_name"].asString(); mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) { for (Json::Value& theElement : anElem["data"]) {
@@ -70,7 +70,7 @@ int ShutterDevice::load_from_json (Json::Value anElem)
mShutter.push_back (theShutter); mShutter.push_back (theShutter);
} }
} }
#endif
return 0; return 0;
} }
@@ -80,8 +80,9 @@ int ShutterDevice::load_from_json (Json::Value anElem)
* *
* @brief Export ShutterDevice Object as JSON Object. * @brief Export ShutterDevice Object as JSON Object.
*/ */
Json::Value ShutterDevice::to_json (bool bDataOnly) struct json_object *ShutterDevice::to_json (void)
{ {
#if 0
Json::Value theResult; Json::Value theResult;
Json::Value data_json(Json::arrayValue); Json::Value data_json(Json::arrayValue);
std::vector<Shutter>::iterator theShutter_it; std::vector<Shutter>::iterator theShutter_it;
@@ -100,6 +101,7 @@ Json::Value ShutterDevice::to_json (bool bDataOnly)
return data_json; return data_json;
return theResult; return theResult;
#endif
} }
@@ -108,7 +110,7 @@ Json::Value ShutterDevice::to_json (bool bDataOnly)
* *
* @brief set the new Shutter state. * @brief set the new Shutter state.
*/ */
int ShutterDevice::set (Json::Value anElement) int ShutterDevice::set (struct json_object *a_node)
{ {
return 0; return 0;
} }
@@ -119,7 +121,7 @@ int ShutterDevice::set (Json::Value anElement)
* *
* @brief set the new Shutter state. * @brief set the new Shutter state.
*/ */
int ShutterDevice::set (int anID, bool aState) int ShutterDevice::set (int an_id, bool a_state)
{ {
return 0; return 0;
} }

View File

@@ -30,29 +30,27 @@
#include <vector> #include <vector>
#include "devices/Shutter.h" #include "devices/shutter.h"
#include "devices/Device.h" #include "devices/device.h"
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class ShutterDevice : public Device { class ShutterDevice : public Device
{
public:
ShutterDevice(void);
~ShutterDevice(void);
public: int from_json(struct json_object *a_node);
ShutterDevice (void); struct json_object *to_json(void);
~ShutterDevice (void);
int load_from_json (Json::Value anElem); int set(struct json_object *a_node);
Json::Value to_json (bool bDataOnly = false); int set(int an_id, bool a_state);
int set (Json::Value anElement); private:
int set (int anID, bool aState); std::vector<Shutter> m_shutter;
private:
std::vector <Shutter> mShutter;
}; };
#endif /* _SHUTTER_DEVICE_H */ #endif /* _SHUTTER_DEVICE_H */

View File

@@ -27,38 +27,36 @@
#include <cstdio> #include <cstdio>
#include <ubus-cpp/UBusCall.h> #include <ubus-cpp/ubus-call.h>
#include "devices/Shutter.h"
#include "devices/shutter.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn Shutter * @fn Shutter
* *
* @brief Constructor of the Shutter Object. * @brief Constructor of the Shutter Object.
*/ */
Shutter::Shutter (void) Shutter::Shutter(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn ~Shutter * @fn ~Shutter
* *
* @brief Destructor of the Shutter Object. * @brief Destructor of the Shutter Object.
*/ */
Shutter::~Shutter (void) Shutter::~Shutter(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load a Shutter Element from a Json Entry. * @brief Load a Shutter Element from a Json Entry.
*/ */
int Shutter::load_from_json (Json::Value anElem) int Shutter::from_json(struct json_object *a_node)
{ {
#if 0
mID = anElem["id"].asInt(); mID = anElem["id"].asInt();
mName = anElem["name"].asString(); mName = anElem["name"].asString();
mSpeach_name = anElem["speach_name"].asString(); mSpeach_name = anElem["speach_name"].asString();
@@ -68,18 +66,18 @@ int Shutter::load_from_json (Json::Value anElem)
mInterruptor = anElem["interruptor"].asInt(); mInterruptor = anElem["interruptor"].asInt();
mSpeed_up = anElem["speed_up"].asInt(); mSpeed_up = anElem["speed_up"].asInt();
mSpeed_down = anElem["speed_down"].asInt(); mSpeed_down = anElem["speed_down"].asInt();
#endif
return 0; return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn to_json * @fn to_json
* *
* @brief Return Shutter Object as a Json Object. * @brief Return Shutter Object as a Json Object.
*/ */
Json::Value Shutter::to_json (void) const struct json_object *Shutter::to_json(void) const
{ {
#if 0
Json::Value aResult(Json::objectValue); Json::Value aResult(Json::objectValue);
fprintf (stderr, "Shutter::to_json\n"); fprintf (stderr, "Shutter::to_json\n");
aResult["id"] = mID; aResult["id"] = mID;
@@ -93,42 +91,40 @@ Json::Value Shutter::to_json (void) const
aResult["speach_name"] = mSpeach_name; aResult["speach_name"] = mSpeach_name;
return aResult; return aResult;
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn update * @fn update
* *
* @brief Update the Shutter State. * @brief Update the Shutter State.
*/ */
int Shutter::update (bool aState) int Shutter::update(bool a_state)
{ {
if (mState == aState) if (m_state == a_state)
return 1; return 1;
mState = aState; m_state = a_state;
return sendState (); return send_state();
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn getID * @fn get_id
* *
* @brief Return the ID of the Shutter. * @brief Return the ID of the Shutter.
*/ */
uint16_t Shutter::getID (void) uint16_t Shutter::get_id(void)
{ {
return mID; return m_id;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn sendState * @fn send_state
* *
* @brief Send the Curent State of the Light. * @brief Send the Curent State of the Light.
*/ */
int Shutter::sendState (void) int Shutter::send_state(void)
{ {
return 0; return 0;
} }

View File

@@ -32,39 +32,36 @@
#include <string> #include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Shutter { class Shutter
{
public:
Shutter(void);
~Shutter(void);
public: int from_json(struct json_object *a_node);
Shutter (void); struct json_object *to_json(void) const;
~Shutter (void);
int load_from_json (Json::Value anElem); int update(bool a_state);
Json::Value to_json (void) const;
int update (bool aState); uint16_t get_id(void);
uint16_t getID (void); private:
int send_state(void);
private: private:
int sendState (void); uint16_t m_id;
std::string m_name;
private: std::string m_speach_name;
uint16_t mID; std::string m_zone;
std::string mName; bool m_state;
std::string mSpeach_name; uint32_t m_sender;
std::string mZone; uint8_t m_interruptor;
bool mState; uint8_t m_speed_up;
uint32_t mSender; uint8_t m_speed_down;
uint8_t mInterruptor;
uint8_t mSpeed_up;
uint8_t mSpeed_down;
}; };
#endif /* _SHUTTER_H */ #endif /* _SHUTTER_H */

View File

@@ -53,14 +53,14 @@ SprinklerDevice::~SprinklerDevice (void)
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load SprinklerDevice Object From a Json Object. * @brief Load SprinklerDevice Object From a Json Object.
*/ */
int SprinklerDevice::load_from_json (Json::Value anElem) int SprinklerDevice::from_json (struct json_object *a_node)
{ {
fprintf (stderr, "SprinklerDevice::load_from_json\n"); fprintf (stderr, "SprinklerDevice::load_from_json\n");
#if 0
mspeach_name = anElem["speach_name"].asString(); mspeach_name = anElem["speach_name"].asString();
for (Json::Value& theElement : anElem["data"]) { for (Json::Value& theElement : anElem["data"]) {
@@ -70,7 +70,7 @@ int SprinklerDevice::load_from_json (Json::Value anElem)
mSprinkler.push_back (theSprinkler); mSprinkler.push_back (theSprinkler);
} }
} }
#endif
return 0; return 0;
} }
@@ -80,8 +80,9 @@ int SprinklerDevice::load_from_json (Json::Value anElem)
* *
* @brief Export SprinklerDevice Object as JSON Object. * @brief Export SprinklerDevice Object as JSON Object.
*/ */
Json::Value SprinklerDevice::to_json (bool bDataOnly) struct json_object *SprinklerDevice::to_json (void)
{ {
#if 0
Json::Value theResult; Json::Value theResult;
Json::Value data_json(Json::arrayValue); Json::Value data_json(Json::arrayValue);
std::vector<Sprinkler>::iterator theSprinkler_it; std::vector<Sprinkler>::iterator theSprinkler_it;
@@ -100,6 +101,7 @@ Json::Value SprinklerDevice::to_json (bool bDataOnly)
return data_json; return data_json;
return theResult; return theResult;
#endif
} }
@@ -108,8 +110,9 @@ Json::Value SprinklerDevice::to_json (bool bDataOnly)
* *
* @brief set the new Sprinkler state. * @brief set the new Sprinkler state.
*/ */
int SprinklerDevice::set (Json::Value anElement) int SprinklerDevice::set (struct json_object *a_node)
{ {
#if 0
int theID; int theID;
bool theState; bool theState;
@@ -117,6 +120,7 @@ int SprinklerDevice::set (Json::Value anElement)
theState = anElement["state"].asBool(); theState = anElement["state"].asBool();
return set (theID, theState); return set (theID, theState);
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
@@ -126,6 +130,7 @@ int SprinklerDevice::set (Json::Value anElement)
*/ */
int SprinklerDevice::set (int anID, bool aState) int SprinklerDevice::set (int anID, bool aState)
{ {
#if 0
std::vector<Sprinkler>::iterator theSprinkler_it; std::vector<Sprinkler>::iterator theSprinkler_it;
for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) { for (theSprinkler_it = mSprinkler.begin(); theSprinkler_it != mSprinkler.end(); theSprinkler_it++) {
@@ -135,6 +140,6 @@ int SprinklerDevice::set (int anID, bool aState)
return (*theSprinkler_it).update (aState); return (*theSprinkler_it).update (aState);
} }
} }
#endif
return -1; return -1;
} }

View File

@@ -35,24 +35,23 @@
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class SprinklerDevice : public Device { class SprinklerDevice : public Device
{
public: public:
SprinklerDevice (void); SprinklerDevice(void);
~SprinklerDevice (void); ~SprinklerDevice(void);
int load_from_json (Json::Value anElem);
Json::Value to_json (bool bDataOnly = false);
int set (Json::Value anElement); int from_json(struct json_object *a_node);
int set (int anID, bool aState); struct json_object *to_json(void);
private: int set(struct json_object *a_node);
std::vector <Sprinkler> mSprinkler; int set(int an_id, bool a_state);
private:
std::vector<Sprinkler> m_sprinkler;
}; };
#endif /* _SPRINKLER_DEVICE_H */ #endif /* _SPRINKLER_DEVICE_H */

View File

@@ -27,54 +27,52 @@
#include <cstdio> #include <cstdio>
#include <ubus-cpp/UBusCall.h> #include <ubus-cpp/ubus-call.h>
#include "devices/Sprinkler.h"
#include "devices/sprinkler.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn Sprinkler * @fn Sprinkler
* *
* @brief Constructor of the Sprinkler Object. * @brief Constructor of the Sprinkler Object.
*/ */
Sprinkler::Sprinkler (void) Sprinkler::Sprinkler(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn ~Sprinkler * @fn ~Sprinkler
* *
* @brief Destructor of the Sprinkler Object. * @brief Destructor of the Sprinkler Object.
*/ */
Sprinkler::~Sprinkler (void) Sprinkler::~Sprinkler(void)
{ {
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_from_json * @fn from_json
* *
* @brief Load a Sprinkler Element from a Json Entry. * @brief Load a Sprinkler Element from a Json Entry.
*/ */
int Sprinkler::load_from_json (Json::Value anElem) int Sprinkler::from_json(struct json_object *a_node)
{ {
#if 0
mID = anElem["id"].asInt(); mID = anElem["id"].asInt();
mName = anElem["name"].asString(); mName = anElem["name"].asString();
mSpeach_name = anElem["speach_name"].asString(); mSpeach_name = anElem["speach_name"].asString();
mState = anElem["state"].asBool(); mState = anElem["state"].asBool();
#endif
return 0; return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn to_json * @fn to_json
* *
* @brief Return Sprinkler Object as a Json Object. * @brief Return Sprinkler Object as a Json Object.
*/ */
Json::Value Sprinkler::to_json (void) const struct json_object *Sprinkler::to_json(void) const
{ {
#if 0
Json::Value aResult(Json::objectValue); Json::Value aResult(Json::objectValue);
fprintf (stderr, "Sprinkler::to_json\n"); fprintf (stderr, "Sprinkler::to_json\n");
aResult["id"] = mID; aResult["id"] = mID;
@@ -83,43 +81,42 @@ Json::Value Sprinkler::to_json (void) const
aResult["state"] = mState; aResult["state"] = mState;
return aResult; return aResult;
#endif
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn update * @fn update
* *
* @brief Update the Sprinkler State. * @brief Update the Sprinkler State.
*/ */
int Sprinkler::update (bool aState) int Sprinkler::update(bool a_state)
{ {
if (mState == aState) if (m_state == a_state)
return 1; return 1;
mState = aState; m_state = a_state;
return sendState (); return send_state();
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn getID * @fn get_id
* *
* @brief Return the ID of the Sprinkler. * @brief Return the ID of the Sprinkler.
*/ */
uint16_t Sprinkler::getID (void) uint16_t Sprinkler::get_id(void)
{ {
return mID; return m_id;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn sendState * @fn send_state
* *
* @brief Send the Curent State of the Light. * @brief Send the Curent State of the Light.
*/ */
int Sprinkler::sendState (void) int Sprinkler::send_state(void)
{ {
#if 0
UBusCall theCmd; UBusCall theCmd;
Json::Value theParam; Json::Value theParam;
Json::StyledWriter theWriter; Json::StyledWriter theWriter;
@@ -129,4 +126,5 @@ int Sprinkler::sendState (void)
theParam["state"] = mState; theParam["state"] = mState;
return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult); return theCmd.Exec ("sprinklers", "set", theWriter.write(theParam).c_str(),theResult);
#endif
} }

View File

@@ -32,34 +32,32 @@
#include <string> #include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Sprinkler { class Sprinkler
{
public: public:
Sprinkler (void); Sprinkler(void);
~Sprinkler (void); ~Sprinkler(void);
int load_from_json (Json::Value anElem); int from_json(struct json_object *a_node);
Json::Value to_json (void) const; struct json_object *to_json (void) const;
int update (bool aState);
uint16_t getID (void); int update(bool aState);
private: uint16_t get_id(void);
int sendState (void);
private: private:
uint16_t mID; int send_state(void);
private:
uint16_t m_id;
std::string mName; std::string mName;
std::string mSpeach_name; std::string mSpeach_name;
bool mState; bool m_state;
}; };
#endif /* _SPRINKLER_H */ #endif /* _SPRINKLER_H */

View File

@@ -38,7 +38,7 @@ extern "C" {
} }
#include "timers/timers.h" #include "timers/timers.h"
#include "devices/devices.h" #include "devices/devices-manager.h"
/*-------------------------------- DEFINES ---------------------------------*/ /*-------------------------------- DEFINES ---------------------------------*/
@@ -128,19 +128,20 @@ int main(int argc, char *argv[])
printf ("config path: %s\n", the_config_path.c_str()); printf ("config path: %s\n", the_config_path.c_str());
/* Setup the devices. */ /* Setup the devices. */
Devices the_devices(the_config_path + "/Devices.json"); DevicesManager the_devices_manager(the_config_path + "/Devices.json");
if (theDevices.load() != 0) { if (the_devices_manager.load() != 0) {
fprintf(stderr, "Failed to load devices.\n"); fprintf(stderr, "Failed to load devices.\n");
return -1; return -1;
} }
/* Setup the Timers. */ /* Setup the Timers. */
Timers the_timers(the_config_path + "/Timers.json", &the_devices); #if 0
Timers the_timers(the_config_path + "/Timers.json", &the_devices_manager);
if (the_timers.load() != 0) { if (the_timers.load() != 0) {
fprintf(stderr, "Failed to load timers.\n"); fprintf(stderr, "Failed to load timers.\n");
return -2; return -2;
} }
#endif
return 0; return 0;
/* Setup the Ubus context. */ /* Setup the Ubus context. */

View File

@@ -26,9 +26,9 @@
/*------------------------------- INCLUDES ----------------------------------*/ /*------------------------------- INCLUDES ----------------------------------*/
#include "devices/Devices.h" #include "devices/devices-manager.h"
#include "timers/Event.h" #include "timers/event.h"
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn Event * @fn Event

View File

@@ -31,11 +31,9 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <jsoncpp/json.h>
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
class Devices; class DevicesManager;
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
@@ -45,11 +43,11 @@ public:
Event (void); Event (void);
~Event (void); ~Event (void);
int load_from_json (Json::Value anElem); //int load_from_json (Json::Value anElem);
Json::Value to_json (void) const; //Json::Value to_json (void) const;
int start (Devices *aDevices); int start (DevicesManager *aDevices);
int stop (Devices *aDevices); int stop (DevicesManager *aDevices);
void dump (void); void dump (void);

View File

@@ -37,14 +37,14 @@
/*---------------------------------- Deps -----------------------------------*/ /*---------------------------------- Deps -----------------------------------*/
class Devices; class DevicesManager;
/*--------------------------------- CLASS ----------------------------------*/ /*--------------------------------- CLASS ----------------------------------*/
class Timers : public ULoopTimer { class Timers : public ULoopTimer {
public: public:
Timers (const std::string &a_path, Devices *a_device); Timers (const std::string &a_path, DevicesManager *a_device);
~Timers (void); ~Timers (void);
int expire (void); int expire (void);
@@ -55,10 +55,10 @@ public:
Event get (uint16_t anID); Event get (uint16_t anID);
int remove (uint16_t anID); int remove (uint16_t anID);
Json::Value to_json (void); //Json::Value to_json (void);
private: private:
Devices *mDevices; DevicesManager *mDevices;
std::string mTimersPath; std::string mTimersPath;
std::vector <Event> mTimers; std::vector <Event> mTimers;
}; };