add sprinkler
This commit is contained in:
@@ -199,9 +199,9 @@ int DevicesController::update(struct ubus_context *a_ctx, struct ubus_request_da
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn del
|
* @fn remove
|
||||||
*
|
*
|
||||||
* @brief delete a specific outlet.
|
* @brief remove a specific outlet.
|
||||||
*/
|
*/
|
||||||
int DevicesController::remove(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg)
|
int DevicesController::remove(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class DevicesController : public UBusObject
|
|||||||
public:
|
public:
|
||||||
DevicesController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name);
|
DevicesController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name);
|
||||||
DevicesController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name, ubus_object_type &anObjType);
|
DevicesController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name, ubus_object_type &anObjType);
|
||||||
~DevicesController(void);
|
virtual ~DevicesController(void);
|
||||||
|
|
||||||
int create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int list(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int list(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ static ObjectType gShuttersControllerUbus_types(
|
|||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ShuttersController
|
* @fn ShuttersController
|
||||||
*
|
*
|
||||||
* @brief Constructor of the UBus Mixer Volume.
|
* @brief Constructor of the Shutters Controller.
|
||||||
*/
|
*/
|
||||||
ShuttersController::ShuttersController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name) : DevicesController(a_device_manager, a_cap, a_service_name, gShuttersControllerUbus_types)
|
ShuttersController::ShuttersController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name) : DevicesController(a_device_manager, a_cap, a_service_name, gShuttersControllerUbus_types)
|
||||||
{
|
{
|
||||||
@@ -67,32 +67,57 @@ ShuttersController::ShuttersController(DevicesManager *a_device_manager, const s
|
|||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~ShuttersController
|
* @fn ~ShuttersController
|
||||||
*
|
*
|
||||||
* @brief Destructor of the UBus Mixer Volume.
|
* @brief Destructor of the Shutters Controller.
|
||||||
*/
|
*/
|
||||||
ShuttersController::~ShuttersController(void)
|
ShuttersController::~ShuttersController(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn create
|
||||||
|
*
|
||||||
|
* @brief Create a new Shutters.
|
||||||
|
*/
|
||||||
int ShuttersController::create(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int ShuttersController::create(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
return DevicesController::create(a_ctx, a_req, a_msg);
|
return DevicesController::create(a_ctx, a_req, a_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn list
|
||||||
|
*
|
||||||
|
* @brief List all the Shutters
|
||||||
|
*/
|
||||||
int ShuttersController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int ShuttersController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
return DevicesController::list(a_ctx, a_req, a_msg);
|
return DevicesController::list(a_ctx, a_req, a_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn read
|
||||||
|
*
|
||||||
|
* @brief Read a specific Shutters object.
|
||||||
|
*/
|
||||||
int ShuttersController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int ShuttersController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
return DevicesController::read(a_ctx, a_req, a_msg);
|
return DevicesController::read(a_ctx, a_req, a_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn update
|
||||||
|
*
|
||||||
|
* @brief Update a specific Shutters.
|
||||||
|
*/
|
||||||
int ShuttersController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int ShuttersController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
return DevicesController::update(a_ctx, a_req, a_msg);
|
return DevicesController::update(a_ctx, a_req, a_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ----------------------------------------------------------------------------
|
||||||
|
* @fn remove
|
||||||
|
*
|
||||||
|
* @brief remove a specific outlet.
|
||||||
|
*/
|
||||||
int ShuttersController::remove(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int ShuttersController::remove(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
return DevicesController::remove(a_ctx, a_req, a_msg);
|
return DevicesController::remove(a_ctx, a_req, a_msg);
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
/*--------------------------------- Define ----------------------------------*/
|
/*--------------------------------- Define ----------------------------------*/
|
||||||
|
|
||||||
class DevicesManager;
|
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
@@ -52,7 +51,6 @@ class ShuttersController : public DevicesController
|
|||||||
|
|
||||||
int up(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int up(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int down(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int down(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UBUS_SHUTTERS_CONTROLLER_H */
|
#endif /* _UBUS_SHUTTERS_CONTROLLER_H */
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ static ObjectType gSprinklersControllerUbus_types(
|
|||||||
Method("list", UBUS_CPP(SprinklersController, list)),
|
Method("list", UBUS_CPP(SprinklersController, list)),
|
||||||
Method("read", UBUS_CPP(SprinklersController, read), Int32Arg("id")),
|
Method("read", UBUS_CPP(SprinklersController, read), Int32Arg("id")),
|
||||||
Method("update", UBUS_CPP(SprinklersController, update), Int32Arg("id")),
|
Method("update", UBUS_CPP(SprinklersController, update), Int32Arg("id")),
|
||||||
Method("delete", UBUS_CPP(SprinklersController, del), Int32Arg("id")),
|
Method("delete", UBUS_CPP(SprinklersController, remove), Int32Arg("id")),
|
||||||
|
|
||||||
Method("open", UBUS_CPP(SprinklersController, open), Int32Arg("id")),
|
Method("open", UBUS_CPP(SprinklersController, open), Int32Arg("id")),
|
||||||
Method("close", UBUS_CPP(SprinklersController, close), Int32Arg("id"))
|
Method("close", UBUS_CPP(SprinklersController, close), Int32Arg("id"))
|
||||||
@@ -62,8 +62,7 @@ static ObjectType gSprinklersControllerUbus_types(
|
|||||||
*
|
*
|
||||||
* @brief Constructor of the UBus Sprinkler controller.
|
* @brief Constructor of the UBus Sprinkler controller.
|
||||||
*/
|
*/
|
||||||
SprinklersController::SprinklersController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name) : UBusObject(gSprinklersControllerUbus_types, a_service_name.c_str()),
|
SprinklersController::SprinklersController(DevicesManager *a_device_manager, const std::string &a_cap, const std::string &a_service_name) : DevicesController(a_device_manager, a_cap, a_service_name, gSprinklersControllerUbus_types)
|
||||||
m_devices_manager(a_device_manager)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,10 +80,9 @@ SprinklersController::~SprinklersController(void)
|
|||||||
*
|
*
|
||||||
* @brief Create a new sprinkler.
|
* @brief Create a new sprinkler.
|
||||||
*/
|
*/
|
||||||
int SprinklersController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
int SprinklersController::create(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
printf("%s\n", __PRETTY_FUNCTION__);
|
return DevicesController::create(a_ctx, a_req, a_msg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
@@ -92,21 +90,9 @@ int SprinklersController::create(struct ubus_context *, struct ubus_request_data
|
|||||||
*
|
*
|
||||||
* @brief List all the sequences
|
* @brief List all the sequences
|
||||||
*/
|
*/
|
||||||
int SprinklersController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *)
|
int SprinklersController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
int the_result;
|
return DevicesController::list(a_ctx, a_req, a_msg);
|
||||||
struct blob_buf the_buf = {0};
|
|
||||||
printf("%s\n", __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
blob_buf_init(&the_buf, 0);
|
|
||||||
|
|
||||||
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kSprinklerEntry).c_str());
|
|
||||||
|
|
||||||
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
|
|
||||||
|
|
||||||
blob_buf_free(&the_buf);
|
|
||||||
|
|
||||||
return the_result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
@@ -114,10 +100,9 @@ int SprinklersController::list(struct ubus_context *a_ctx, struct ubus_request_d
|
|||||||
*
|
*
|
||||||
* @brief Read a specific sequence object.
|
* @brief Read a specific sequence object.
|
||||||
*/
|
*/
|
||||||
int SprinklersController::read(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
int SprinklersController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
printf("%s\n", __PRETTY_FUNCTION__);
|
return DevicesController::read(a_ctx, a_req, a_msg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
@@ -127,56 +112,17 @@ int SprinklersController::read(struct ubus_context *, struct ubus_request_data *
|
|||||||
*/
|
*/
|
||||||
int SprinklersController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
int SprinklersController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
int the_result = 0;
|
return DevicesController::update(a_ctx, a_req, a_msg);
|
||||||
struct blob_buf the_buf = {0};
|
|
||||||
char *the_string;
|
|
||||||
struct json_object *the_root_node, *the_output_node;
|
|
||||||
printf("%s\n", __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
the_string = blobmsg_format_json(a_msg, true);
|
|
||||||
|
|
||||||
the_root_node = json_tokener_parse(the_string);
|
|
||||||
free(the_string);
|
|
||||||
|
|
||||||
if (the_root_node == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed parse the parameters.\n");
|
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_devices_manager->set(kSprinklerEntry, the_root_node) < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to set the new state.\n");
|
|
||||||
return UBUS_STATUS_INVALID_ARGUMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the output node.
|
|
||||||
the_output_node = json_object_new_object();
|
|
||||||
json_object_object_add(the_output_node, kSprinklerEntry, the_root_node);
|
|
||||||
|
|
||||||
blob_buf_init(&the_buf, 0);
|
|
||||||
|
|
||||||
blobmsg_add_json_from_string(&the_buf, json_object_to_json_string(the_output_node));
|
|
||||||
|
|
||||||
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
|
|
||||||
|
|
||||||
blob_buf_free(&the_buf);
|
|
||||||
|
|
||||||
json_object_put(the_root_node);
|
|
||||||
json_object_put(the_output_node);
|
|
||||||
|
|
||||||
return the_result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn del
|
* @fn remove
|
||||||
*
|
*
|
||||||
* @brief delete a specific sequence.
|
* @brief remove a specific sequence.
|
||||||
*/
|
*/
|
||||||
int SprinklersController::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
|
int SprinklersController::remove(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
|
||||||
{
|
{
|
||||||
printf("%s\n", __PRETTY_FUNCTION__);
|
return DevicesController::remove(a_ctx, a_req, a_msg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -30,15 +30,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <ubus-cpp/ubus-object.h>
|
#include "devices-controller.h"
|
||||||
|
|
||||||
/*--------------------------------- Define ----------------------------------*/
|
/*--------------------------------- Define ----------------------------------*/
|
||||||
|
|
||||||
class DevicesManager;
|
|
||||||
|
|
||||||
/*--------------------------------- CLASS ----------------------------------*/
|
/*--------------------------------- CLASS ----------------------------------*/
|
||||||
|
|
||||||
class SprinklersController : public UBusObject
|
class SprinklersController : public DevicesController
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -49,13 +47,10 @@ class SprinklersController : public UBusObject
|
|||||||
int list(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int list(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int read(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int read(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int update(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int update(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int remove(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
|
|
||||||
int open(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int open(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
int close(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
int close(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
|
||||||
|
|
||||||
private:
|
|
||||||
DevicesManager *m_devices_manager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _UBUS_SPRINKLERS_CONTROLLER_H */
|
#endif /* _UBUS_SPRINKLERS_CONTROLLER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user