move deprecated files and rename light as outlet

This commit is contained in:
jbnadal
2018-05-07 11:27:21 +02:00
parent 20cee78636
commit 7d8b653d08
19 changed files with 92 additions and 64 deletions

View File

@@ -23,31 +23,25 @@ file(
${workspaceRoot}/src/prog/domod/src/devices/outlet-dio.cpp
${workspaceRoot}/src/prog/domod/src/devices/sprinkler.cpp
${workspaceRoot}/src/prog/domod/src/devices/shutter.cpp
# ${workspaceRoot}/src/prog/domod/src/devices/light-device.cpp
# ${workspaceRoot}/src/prog/domod/src/devices/shutter-device.cpp
# ${workspaceRoot}/src/prog/domod/src/devices/sprinkler-device.cpp
# ubus models
${workspaceRoot}/src/prog/domod/src/ubus/capabilities-controller.cpp
${workspaceRoot}/src/prog/domod/src/ubus/lights-controller.cpp
${workspaceRoot}/src/prog/domod/src/ubus/outlets-controller.cpp
${workspaceRoot}/src/prog/domod/src/ubus/shutters-controller.cpp
${workspaceRoot}/src/prog/domod/src/ubus/sprinklers-controller.cpp
${workspaceRoot}/src/prog/domod/src/ubus/sequences-controller.cpp
# timers
${workspaceRoot}/src/prog/domod/src/sequences/sequences-manager.cpp
${workspaceRoot}/src/prog/domod/src/sequences/sequence.cpp
${workspaceRoot}/src/prog/domod/src/sequences/timer.cpp
${workspaceRoot}/src/prog/domod/src/sequences/action.cpp
${workspaceRoot}/src/prog/domod/src/sequences/clock.cpp
# helper
${workspaceRoot}/src/prog/domod/src/helpers/strings.cpp
${workspaceRoot}/src/prog/domod/src/helpers/controller.cpp
)
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp
# $ENV{SRC_DIR}/src/prog/domod/src/helpers/Tokenizer.cpp
#)
add_executable (domod ${source_files})

View File

@@ -31,7 +31,7 @@
/* Device */
/* Device type. */
#define kLightEntry "lights"
#define kOutletEntry "outlets"
#define kShutterEntry "shutters"
#define kSprinklerEntry "sprinklers"
@@ -39,12 +39,14 @@
#define k_entry_sequences "sequences"
/* common */
/* device */
#define k_entry_id "id"
#define k_entry_name "name"
#define k_entry_speech_name "speech_name"
#define k_entry_zone "zone"
#define k_entry_state "state"
/* outlet */
#define k_entry_zone "zone"
#define k_entry_sender "sender"
#define k_entry_switch "switch"
@@ -61,4 +63,4 @@
#define k_entry_duration "duration"
#define k_entry_actions "actions"
#endif /* _DOMO_H */
#endif /* _DOMO_H */

View File

@@ -74,21 +74,18 @@ int DevicesManager::load(void)
return -1;
}
if (json_object_object_get_ex(the_root_node, kLightEntry, &the_value_node))
if (json_object_object_get_ex(the_root_node, kOutletEntry, &the_value_node))
{
printf(" On a des Lights.\n");
load_lights(the_value_node);
}
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
{
printf(" On a des shutters.\n");
load_shutters(the_value_node);
}
if (json_object_object_get_ex(the_root_node, kSprinklerEntry, &the_value_node))
{
printf(" On a des sprintkler.\n");
load_sprinklers(the_value_node);
}
@@ -137,9 +134,9 @@ std::string DevicesManager::get(const std::string &a_capability)
// fprintf(stderr, "Devices::get (%s)...\n", a_capability.c_str());
the_output_node = json_object_new_object();
if (a_capability == kLightEntry)
if (a_capability == kOutletEntry)
{
json_object_object_add(the_output_node, kLightEntry, m_lights.to_json());
json_object_object_add(the_output_node, kOutletEntry, m_lights.to_json());
}
else if (a_capability == kShutterEntry)
{
@@ -167,7 +164,7 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
std::string the_output;
int the_pos;
if (a_capability == kLightEntry)
if (a_capability == kOutletEntry)
{
the_pos = m_lights.find(an_id);
if (the_pos != -1)
@@ -210,7 +207,7 @@ int DevicesManager::set(const std::string &a_capability, struct json_object *a_n
/*! ----------------------------------------------------------------------------
* @fn set_state
*
* @brief set the state for device with the id from a specific capabilitiy.
* @brief set the state for device with the id from a specific capability.
*/
int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a_state)
{
@@ -237,6 +234,16 @@ int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a
return the_result;
}
/*! ----------------------------------------------------------------------------
* @fn create
*
* @brief set the state for device with the id from a specific capability.
*/
int DevicesManager::create(const std::string &a_capability, struct json_object *a_node)
{
}
/*! ----------------------------------------------------------------------------
* @fn load_lights
*

View File

@@ -53,9 +53,12 @@ class DevicesManager
std::string get(const std::string &a_capability);
std::string get(const std::string &a_capability, uint32_t an_id);
int set(const std::string &a_capability, struct json_object *a_node);
int set_state(const std::string &a_capability, int an_id, bool a_state);
int create(const std::string &a_capability, struct json_object *a_node);
private:
int load_lights(struct json_object *a_node);
int load_shutters(struct json_object *a_node);

View File

@@ -41,7 +41,7 @@ extern "C" {
#include "devices/devices-manager.h"
#include "ubus/capabilities-controller.h"
#include "ubus/lights-controller.h"
#include "ubus/outlets-controller.h"
#include "ubus/shutters-controller.h"
#include "ubus/sprinklers-controller.h"
#include "ubus/sequences-controller.h"
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
/* Setup the UBus Models. */
CapabilitiesController the_capabilities(the_config_path + "./capabilities.json");
LightsController the_lights(&the_devices_manager);
OutletsController the_outlets(&the_devices_manager);
ShuttersController the_shutters(&the_devices_manager);
SprinklersController the_sprinklers(&the_devices_manager);
SequencesController the_sequences(&the_sequences_manager);
@@ -170,7 +170,7 @@ printf("ctx: %p\n", the_ctx);
fprintf (stderr, "Failed to register: %d\n", the_ret);
return -2;
}
if (ubus_add_object(the_ctx, &the_lights) != UBUS_STATUS_OK)
if (ubus_add_object(the_ctx, &the_outlets) != UBUS_STATUS_OK)
return -2;
if (ubus_add_object(the_ctx, &the_shutters) != UBUS_STATUS_OK)
return -2;

View File

@@ -1,5 +1,5 @@
/*!
* capabilities_lights.cpp
* outlets-controller.cpp
*
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
*
@@ -37,7 +37,7 @@ extern "C" {
#include "domo.h"
#include "lights-controller.h"
#include "outlets-controller.h"
namespace
{
@@ -45,31 +45,31 @@ namespace
using namespace UBus;
static ObjectType gLightsControllerUbus_types(
"lightsController",
Method("create", UBUS_CPP(LightsController, create)),
Method("list", UBUS_CPP(LightsController, list)),
Method("read", UBUS_CPP(LightsController, read), Int32Arg("id")),
Method("update", UBUS_CPP(LightsController, update), Int32Arg("id")),
Method("delete", UBUS_CPP(LightsController, del), Int32Arg("id"))
"OutletsController",
Method("create", UBUS_CPP(OutletsController, create)),
Method("list", UBUS_CPP(OutletsController, list)),
Method("read", UBUS_CPP(OutletsController, read), Int32Arg("id")),
Method("update", UBUS_CPP(OutletsController, update), Int32Arg("id")),
Method("delete", UBUS_CPP(OutletsController, del), Int32Arg("id"))
);
}
/*! ----------------------------------------------------------------------------
* @fn LightsController
* @fn OutletsController
*
* @brief Constructor of the Lights Controller.
* @brief Constructor of the Outlets Controller.
*/
LightsController::LightsController(DevicesManager *a_device_manager) : UBusObject(gLightsControllerUbus_types, "domo.lights"),
OutletsController::OutletsController(DevicesManager *a_device_manager) : UBusObject(gLightsControllerUbus_types, "domo.outlets"),
m_devices_manager(a_device_manager)
{
}
/*! ----------------------------------------------------------------------------
* @fn ~LightsController
* @fn ~OutletsController
*
* @brief Destructor of the Lights Controller.
* @brief Destructor of the Outlets Controller.
*/
LightsController::~LightsController(void)
OutletsController::~OutletsController(void)
{
}
@@ -77,20 +77,42 @@ LightsController::~LightsController(void)
/*! ----------------------------------------------------------------------------
* @fn create
*
* @brief Create a new Sequence Object.
* @brief Create a new Outlet Object.
*/
int LightsController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
int OutletsController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg)
{
int the_result = 0;
struct blob_buf the_buf = {0};
char *the_string;
struct json_object *the_root_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->create(kOutletEntry, the_root_node) < 0)
{
fprintf(stderr, "Failed to create a new light.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
}
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn list
*
* @brief List all the sequences
* @brief List all the outlets
*/
int LightsController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *)
int OutletsController::list(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *)
{
int the_result;
struct blob_buf the_buf = {0};
@@ -98,7 +120,7 @@ int LightsController::list(struct ubus_context *a_ctx, struct ubus_request_data
blob_buf_init(&the_buf, 0);
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kLightEntry).c_str());
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kOutletEntry).c_str());
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
@@ -110,9 +132,9 @@ int LightsController::list(struct ubus_context *a_ctx, struct ubus_request_data
/*! ----------------------------------------------------------------------------
* @fn read
*
* @brief Read a specific sequence object.
* @brief Read a specific outlet object.
*/
int LightsController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
int OutletsController::read(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
{
uint32_t the_id, the_result;
struct blob_buf the_buf = {0};
@@ -126,7 +148,7 @@ int LightsController::read(struct ubus_context *a_ctx, struct ubus_request_data
// printf ("update id: %d\n", the_id);
blob_buf_init(&the_buf, 0);
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kLightEntry, the_id).c_str());
blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kOutletEntry, the_id).c_str());
the_result = ubus_send_reply(a_ctx, a_req, the_buf.head);
@@ -138,9 +160,9 @@ int LightsController::read(struct ubus_context *a_ctx, struct ubus_request_data
/*! ----------------------------------------------------------------------------
* @fn update
*
* @brief Update a specific sequence.
* @brief Update a specific outlet.
*/
int LightsController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
int OutletsController::update(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg)
{
int the_result = 0;
struct blob_buf the_buf = {0};
@@ -159,7 +181,7 @@ int LightsController::update(struct ubus_context *a_ctx, struct ubus_request_dat
return UBUS_STATUS_INVALID_ARGUMENT;
}
if (m_devices_manager->set(kLightEntry, the_root_node) < 0)
if (m_devices_manager->set(kOutletEntry, the_root_node) < 0)
{
fprintf(stderr, "Failed to set the new state.\n");
return UBUS_STATUS_INVALID_ARGUMENT;
@@ -167,7 +189,7 @@ int LightsController::update(struct ubus_context *a_ctx, struct ubus_request_dat
// Create the output node.
the_output_node = json_object_new_object();
json_object_object_add(the_output_node, kLightEntry, the_root_node);
json_object_object_add(the_output_node, kOutletEntry, the_root_node);
blob_buf_init(&the_buf, 0);
@@ -186,9 +208,9 @@ int LightsController::update(struct ubus_context *a_ctx, struct ubus_request_dat
/*! ----------------------------------------------------------------------------
* @fn del
*
* @brief delete a specific sequence.
* @brief delete a specific outlet.
*/
int LightsController::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
int OutletsController::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *)
{
printf("%s\n", __PRETTY_FUNCTION__);
return 0;

View File

@@ -1,5 +1,5 @@
/*!
* lights-controller.h
* outlets-controller.h
*
* Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved.
*
@@ -23,8 +23,8 @@
*
*/
#ifndef _UBUS_LIGHTS_CONTROLLER_H
#define _UBUS_LIGHTS_CONTROLLER_H
#ifndef _UBUS_OUTLETS_CONTROLLER_H
#define _UBUS_OUTLETS_CONTROLLER_H
/*------------------------------- INCLUDES ----------------------------------*/
@@ -38,12 +38,12 @@ class DevicesManager;
/*--------------------------------- CLASS ----------------------------------*/
class LightsController : public UBusObject
class OutletsController : public UBusObject
{
public:
LightsController(DevicesManager *a_device_manager);
~LightsController(void);
OutletsController(DevicesManager *a_device_manager);
~OutletsController(void);
int create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
int list(struct ubus_context *, struct ubus_request_data *, struct blob_attr *);
@@ -55,4 +55,4 @@ class LightsController : public UBusObject
DevicesManager *m_devices_manager;
};
#endif /* _UBUS_LIGHTS_CONTROLLER_H */
#endif /* _UBUS_OUTLETS_CONTROLLER_H */