ubus model work in progress.
This commit is contained in:
@@ -15,6 +15,7 @@ file(
|
||||
GLOB_RECURSE
|
||||
source_files
|
||||
${workspaceRoot}/src/prog/domod/src/main.cpp
|
||||
# devices
|
||||
${workspaceRoot}/src/prog/domod/src/devices/devices-manager.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/device.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
|
||||
@@ -23,17 +24,15 @@ file(
|
||||
${workspaceRoot}/src/prog/domod/src/devices/light.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
|
||||
# ubus models
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/capabilities.cpp
|
||||
${workspaceRoot}/src/prog/domod/src/ubus/capabilities_lights.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/Clock.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_shutters.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_sprinklers.cpp
|
||||
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp
|
||||
|
||||
@@ -33,12 +33,6 @@
|
||||
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define kLightEntry "Lights"
|
||||
#define kShutterEntry "Shutters"
|
||||
#define kSprinklerEntry "Sprinklers"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn DevicesManager
|
||||
*
|
||||
|
||||
@@ -36,6 +36,12 @@
|
||||
|
||||
#include "devices/device.h"
|
||||
|
||||
/*------------------------------- DEFINES ----------------------------------*/
|
||||
|
||||
#define kLightEntry "Lights"
|
||||
#define kShutterEntry "Shutters"
|
||||
#define kSprinklerEntry "Sprinklers"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
@@ -40,6 +40,9 @@ extern "C" {
|
||||
#include "timers/timers.h"
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
#include "ubus/capabilities.h"
|
||||
#include "ubus/capabilities_lights.h"
|
||||
|
||||
/*-------------------------------- DEFINES ---------------------------------*/
|
||||
|
||||
#define k_dir_sep '/'
|
||||
@@ -142,6 +145,11 @@ int main(int argc, char *argv[])
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Setup the UBus Models. */
|
||||
CapabilitiesModel the_capabilities(the_config_path + "./capabilities.json");
|
||||
CapabilitiesLightsModel the_cap_lights(&the_devices_manager);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Setup the Ubus context. */
|
||||
@@ -151,6 +159,10 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Add the UBus to the model exposed. */
|
||||
ubus_add_object(the_ctx, &the_capabilities);
|
||||
ubus_add_object(the_ctx, &the_cap_lights);
|
||||
|
||||
/* Main Event Loop. */
|
||||
uloop_run();
|
||||
|
||||
@@ -161,8 +173,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include "ubus/capabilities.h"
|
||||
#include "ubus/capabilities_lights.h"
|
||||
|
||||
|
||||
#include "ubus/capabilities_shutters.h"
|
||||
#include "ubus/capabilities_sprinklers.h"
|
||||
#include "ubus/speach_command.h"
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <fstream>
|
||||
@@ -36,15 +35,14 @@ extern "C" {
|
||||
|
||||
#include "capabilities.h"
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gCapabilitiesModelUbus_types(
|
||||
"capabilities",
|
||||
Method("get", UBUS_CPP(CapabilitiesModel, Get))
|
||||
);
|
||||
|
||||
Method("get", UBUS_CPP(CapabilitiesModel, get)));
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -52,12 +50,11 @@ static ObjectType gCapabilitiesModelUbus_types(
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesModel::CapabilitiesModel (void) :
|
||||
UBusObject (gCapabilitiesModelUbus_types, "domo.capabilities")
|
||||
CapabilitiesModel::CapabilitiesModel(const std::string &a_capability_file) : UBusObject(gCapabilitiesModelUbus_types, "domo.capabilities"),
|
||||
m_capability_file(a_capability_file)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~CapabilitiesModel
|
||||
*
|
||||
@@ -65,32 +62,29 @@ CapabilitiesModel::CapabilitiesModel (void) :
|
||||
*/
|
||||
CapabilitiesModel::~CapabilitiesModel(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
* @fn get
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
||||
struct blob_attr *aMsg)
|
||||
int CapabilitiesModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *)
|
||||
{
|
||||
int theResult;
|
||||
struct blob_buf theBuf = {0};
|
||||
int the_result;
|
||||
struct blob_buf the_buf = {0};
|
||||
|
||||
std::ifstream theCapFile ("./rsc/capabilities.json");
|
||||
std::stringstream theBuffer;
|
||||
theBuffer << theCapFile.rdbuf();
|
||||
std::ifstream the_cap_file(m_capability_file);
|
||||
std::stringstream the_buffer;
|
||||
the_buffer << the_cap_file.rdbuf();
|
||||
|
||||
blob_buf_init (&theBuf, 0);
|
||||
blob_buf_init(&the_buf, 0);
|
||||
|
||||
blobmsg_add_json_from_string (&theBuf, theBuffer.str().c_str());
|
||||
blobmsg_add_json_from_string(&the_buf, the_buffer.str().c_str());
|
||||
|
||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
|
||||
|
||||
blob_buf_free (&theBuf);
|
||||
blob_buf_free(&the_buf);
|
||||
|
||||
return theResult;
|
||||
return the_result;
|
||||
}
|
||||
|
||||
@@ -28,23 +28,25 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <ubus-cpp/UBusObject.h>
|
||||
#include <ubus-cpp/ubus-object.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class CapabilitiesModel : public UBusObject {
|
||||
|
||||
class CapabilitiesModel : public UBusObject
|
||||
{
|
||||
public:
|
||||
CapabilitiesModel (void);
|
||||
CapabilitiesModel(const std::string &a_capability_file);
|
||||
~CapabilitiesModel(void);
|
||||
|
||||
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
int get(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||
|
||||
private:
|
||||
std::string m_capability_file;
|
||||
};
|
||||
|
||||
#endif /* _UBUS_CAPABILITIES_MODEL_H */
|
||||
|
||||
@@ -25,30 +25,27 @@
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <json-c/json.h>
|
||||
|
||||
extern "C" {
|
||||
#include <libubox/blobmsg_json.h>
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
|
||||
#include "devices/Devices.h"
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
#include "capabilities_lights.h"
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
|
||||
using namespace UBus;
|
||||
|
||||
static ObjectType gCapabilitiesLightsUbus_types(
|
||||
"lights",
|
||||
Method("get", UBUS_CPP(CapabilitiesLightsModel, Get)),
|
||||
Method("delete", UBUS_CPP(CapabilitiesLightsModel, Delete)),
|
||||
Method("put", UBUS_CPP(CapabilitiesLightsModel, Put)),
|
||||
Method("post", UBUS_CPP(CapabilitiesLightsModel, Post))
|
||||
);
|
||||
|
||||
Method("get", UBUS_CPP(CapabilitiesLightsModel, get)),
|
||||
Method("delete", UBUS_CPP(CapabilitiesLightsModel, del)),
|
||||
Method("put", UBUS_CPP(CapabilitiesLightsModel, put)),
|
||||
Method("post", UBUS_CPP(CapabilitiesLightsModel, post)));
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
@@ -56,13 +53,12 @@ static ObjectType gCapabilitiesLightsUbus_types(
|
||||
*
|
||||
* @brief Constructor of the UBus Mixer Volume.
|
||||
*/
|
||||
CapabilitiesLightsModel::CapabilitiesLightsModel (Devices *aDevice) :
|
||||
CapabilitiesLightsModel::CapabilitiesLightsModel(DevicesManager *a_device_manager) :
|
||||
UBusObject(gCapabilitiesLightsUbus_types, "domo.capabilities.lights"),
|
||||
mDevices (aDevice)
|
||||
m_devices_manager(a_device_manager)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~CapabilitiesLightsModel
|
||||
*
|
||||
@@ -70,67 +66,61 @@ CapabilitiesLightsModel::CapabilitiesLightsModel (Devices *aDevice) :
|
||||
*/
|
||||
CapabilitiesLightsModel::~CapabilitiesLightsModel(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn get
|
||||
*
|
||||
* @brief get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLightsModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||
{
|
||||
int the_result;
|
||||
struct blob_buf the_buf = { 0 };
|
||||
|
||||
blob_buf_init(&the_buf, 0);
|
||||
|
||||
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kLightEntry).c_str());
|
||||
|
||||
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
|
||||
|
||||
blob_buf_free(&the_buf);
|
||||
|
||||
return the_result;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Get
|
||||
* @fn del
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLightsModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
||||
struct blob_attr *aMsg)
|
||||
int CapabilitiesLightsModel::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
||||
{
|
||||
int theResult;
|
||||
struct blob_buf theBuf = {0};
|
||||
int the_result = 0;
|
||||
|
||||
blob_buf_init (&theBuf, 0);
|
||||
|
||||
blobmsg_add_json_from_string (&theBuf, mDevices->get("Lights").c_str());
|
||||
|
||||
theResult = ubus_send_reply (aCtx, aReq, theBuf.head);
|
||||
|
||||
blob_buf_free (&theBuf);
|
||||
|
||||
return theResult;
|
||||
return the_result;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Delete
|
||||
* @fn put
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLightsModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
int CapabilitiesLightsModel::put(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
||||
{
|
||||
int theResult = 0;
|
||||
int the_result = 0;
|
||||
|
||||
return theResult;
|
||||
return the_result;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Put
|
||||
* @fn post
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLightsModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*)
|
||||
{
|
||||
int theResult = 0;
|
||||
|
||||
return theResult;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn Post
|
||||
*
|
||||
* @brief Get the List of the Capabilities.
|
||||
*/
|
||||
int CapabilitiesLightsModel::Post (struct ubus_context *aCtx, struct ubus_request_data *aReq,
|
||||
struct blob_attr *aMsg)
|
||||
int CapabilitiesLightsModel::post(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||
{
|
||||
#if 0
|
||||
int theResult = 0;
|
||||
struct blob_buf theBuf = {0};
|
||||
char *theString = blobmsg_format_json(aMsg, true);
|
||||
@@ -141,13 +131,15 @@ int CapabilitiesLightsModel::Post (struct ubus_context *aCtx, struct ubus_reques
|
||||
Json::Value theElement;
|
||||
fprintf(stderr, "CapabilitiesLights::Post \n");
|
||||
|
||||
if (!theReader.parse (theString, theRoot)) {
|
||||
if (!theReader.parse(theString, theRoot))
|
||||
{
|
||||
|
||||
fprintf(stderr, "Failed parse the parameters.\n");
|
||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (mDevices->set ("Lights", theRoot) < 0) {
|
||||
if (mDevices->set("Lights", theRoot) < 0)
|
||||
{
|
||||
|
||||
fprintf(stderr, "Failed to set the new state.\n");
|
||||
return -1;
|
||||
@@ -164,4 +156,5 @@ int CapabilitiesLightsModel::Post (struct ubus_context *aCtx, struct ubus_reques
|
||||
blob_buf_free(&theBuf);
|
||||
|
||||
return theResult;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -30,30 +30,28 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <jsoncpp/json.h>
|
||||
#include <ubus-cpp/UBusObject.h>
|
||||
|
||||
|
||||
#include <ubus-cpp/ubus-object.h>
|
||||
|
||||
/*--------------------------------- Define ----------------------------------*/
|
||||
|
||||
class Devices;
|
||||
class DevicesManager;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class CapabilitiesLightsModel : public UBusObject {
|
||||
class CapabilitiesLightsModel : public UBusObject
|
||||
{
|
||||
|
||||
public:
|
||||
CapabilitiesLightsModel (Devices *aDevice);
|
||||
CapabilitiesLightsModel(DevicesManager *a_device_manager);
|
||||
~CapabilitiesLightsModel(void);
|
||||
|
||||
int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
int Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
int Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*);
|
||||
int get(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||
int del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||
int put(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||
int post(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||
|
||||
private:
|
||||
Devices *mDevices;
|
||||
DevicesManager *m_devices_manager;
|
||||
};
|
||||
|
||||
#endif /* _UBUS_CAPABILITIES_LIGHTS_MODEL_H */
|
||||
|
||||
Reference in New Issue
Block a user