From 7d8b653d089b5aaeb148263a04e6b63c95606726 Mon Sep 17 00:00:00 2001 From: jbnadal Date: Mon, 7 May 2018 11:27:21 +0200 Subject: [PATCH] move deprecated files and rename light as outlet --- .../usr/local/share/domo/capabilities.json | 8 +- .../ovl/usr/local/share/domo/devices.json | 2 +- src/prog/domod/builders/cmake/CMakeLists.txt | 12 +-- src/prog/domod/include/domo.h | 10 ++- .../{ => deprecated}/devices/light-device.cpp | 0 .../{ => deprecated}/devices/light-device.h | 0 .../devices/shutter-device.cpp | 0 .../{ => deprecated}/devices/shutter-device.h | 0 .../devices/sprinkler-device.cpp | 0 .../devices/sprinkler-device.h | 0 .../{ => deprecated}/helpers/Tokenizer.cpp | 0 .../src/{ => deprecated}/helpers/Tokenizer.h | 0 .../{ => deprecated}/ubus/speach_command.cpp | 0 .../{ => deprecated}/ubus/speach_command.h | 0 .../domod/src/devices/devices-manager.cpp | 23 ++++-- src/prog/domod/src/devices/devices-manager.h | 3 + src/prog/domod/src/main.cpp | 6 +- ...-controller.cpp => outlets-controller.cpp} | 78 ++++++++++++------- ...ghts-controller.h => outlets-controller.h} | 14 ++-- 19 files changed, 92 insertions(+), 64 deletions(-) rename src/prog/domod/src/{ => deprecated}/devices/light-device.cpp (100%) rename src/prog/domod/src/{ => deprecated}/devices/light-device.h (100%) rename src/prog/domod/src/{ => deprecated}/devices/shutter-device.cpp (100%) rename src/prog/domod/src/{ => deprecated}/devices/shutter-device.h (100%) rename src/prog/domod/src/{ => deprecated}/devices/sprinkler-device.cpp (100%) rename src/prog/domod/src/{ => deprecated}/devices/sprinkler-device.h (100%) rename src/prog/domod/src/{ => deprecated}/helpers/Tokenizer.cpp (100%) rename src/prog/domod/src/{ => deprecated}/helpers/Tokenizer.h (100%) rename src/prog/domod/src/{ => deprecated}/ubus/speach_command.cpp (100%) rename src/prog/domod/src/{ => deprecated}/ubus/speach_command.h (100%) rename src/prog/domod/src/ubus/{lights-controller.cpp => outlets-controller.cpp} (63%) rename src/prog/domod/src/ubus/{lights-controller.h => outlets-controller.h} (86%) diff --git a/bsp/board/domo/ovl/usr/local/share/domo/capabilities.json b/bsp/board/domo/ovl/usr/local/share/domo/capabilities.json index fda4fc8e..96a45da3 100644 --- a/bsp/board/domo/ovl/usr/local/share/domo/capabilities.json +++ b/bsp/board/domo/ovl/usr/local/share/domo/capabilities.json @@ -1,16 +1,16 @@ { "capabilities": [ { - "name": "lights", - "speach_name": "lumière" + "name": "outlets", + "speech_name": "lumière" }, { "name": "shutters", - "speach_name": "volet" + "speech_name": "volet" }, { "name": "sprinklers", - "speach_name": "station" + "speech_name": "station" } ] } \ No newline at end of file diff --git a/bsp/board/domo/ovl/usr/local/share/domo/devices.json b/bsp/board/domo/ovl/usr/local/share/domo/devices.json index 3decb4d9..850ff069 100644 --- a/bsp/board/domo/ovl/usr/local/share/domo/devices.json +++ b/bsp/board/domo/ovl/usr/local/share/domo/devices.json @@ -1,5 +1,5 @@ { - "lights": [ + "outlets": [ { "id": 1, "name": "Bureau JB", diff --git a/src/prog/domod/builders/cmake/CMakeLists.txt b/src/prog/domod/builders/cmake/CMakeLists.txt index a3449b54..fdf77765 100644 --- a/src/prog/domod/builders/cmake/CMakeLists.txt +++ b/src/prog/domod/builders/cmake/CMakeLists.txt @@ -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}) diff --git a/src/prog/domod/include/domo.h b/src/prog/domod/include/domo.h index 9447bb8a..8c3d7830 100644 --- a/src/prog/domod/include/domo.h +++ b/src/prog/domod/include/domo.h @@ -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 */ \ No newline at end of file +#endif /* _DOMO_H */ diff --git a/src/prog/domod/src/devices/light-device.cpp b/src/prog/domod/src/deprecated/devices/light-device.cpp similarity index 100% rename from src/prog/domod/src/devices/light-device.cpp rename to src/prog/domod/src/deprecated/devices/light-device.cpp diff --git a/src/prog/domod/src/devices/light-device.h b/src/prog/domod/src/deprecated/devices/light-device.h similarity index 100% rename from src/prog/domod/src/devices/light-device.h rename to src/prog/domod/src/deprecated/devices/light-device.h diff --git a/src/prog/domod/src/devices/shutter-device.cpp b/src/prog/domod/src/deprecated/devices/shutter-device.cpp similarity index 100% rename from src/prog/domod/src/devices/shutter-device.cpp rename to src/prog/domod/src/deprecated/devices/shutter-device.cpp diff --git a/src/prog/domod/src/devices/shutter-device.h b/src/prog/domod/src/deprecated/devices/shutter-device.h similarity index 100% rename from src/prog/domod/src/devices/shutter-device.h rename to src/prog/domod/src/deprecated/devices/shutter-device.h diff --git a/src/prog/domod/src/devices/sprinkler-device.cpp b/src/prog/domod/src/deprecated/devices/sprinkler-device.cpp similarity index 100% rename from src/prog/domod/src/devices/sprinkler-device.cpp rename to src/prog/domod/src/deprecated/devices/sprinkler-device.cpp diff --git a/src/prog/domod/src/devices/sprinkler-device.h b/src/prog/domod/src/deprecated/devices/sprinkler-device.h similarity index 100% rename from src/prog/domod/src/devices/sprinkler-device.h rename to src/prog/domod/src/deprecated/devices/sprinkler-device.h diff --git a/src/prog/domod/src/helpers/Tokenizer.cpp b/src/prog/domod/src/deprecated/helpers/Tokenizer.cpp similarity index 100% rename from src/prog/domod/src/helpers/Tokenizer.cpp rename to src/prog/domod/src/deprecated/helpers/Tokenizer.cpp diff --git a/src/prog/domod/src/helpers/Tokenizer.h b/src/prog/domod/src/deprecated/helpers/Tokenizer.h similarity index 100% rename from src/prog/domod/src/helpers/Tokenizer.h rename to src/prog/domod/src/deprecated/helpers/Tokenizer.h diff --git a/src/prog/domod/src/ubus/speach_command.cpp b/src/prog/domod/src/deprecated/ubus/speach_command.cpp similarity index 100% rename from src/prog/domod/src/ubus/speach_command.cpp rename to src/prog/domod/src/deprecated/ubus/speach_command.cpp diff --git a/src/prog/domod/src/ubus/speach_command.h b/src/prog/domod/src/deprecated/ubus/speach_command.h similarity index 100% rename from src/prog/domod/src/ubus/speach_command.h rename to src/prog/domod/src/deprecated/ubus/speach_command.h diff --git a/src/prog/domod/src/devices/devices-manager.cpp b/src/prog/domod/src/devices/devices-manager.cpp index c7800b31..06cd038c 100644 --- a/src/prog/domod/src/devices/devices-manager.cpp +++ b/src/prog/domod/src/devices/devices-manager.cpp @@ -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 * diff --git a/src/prog/domod/src/devices/devices-manager.h b/src/prog/domod/src/devices/devices-manager.h index 477875a1..bb240a5c 100644 --- a/src/prog/domod/src/devices/devices-manager.h +++ b/src/prog/domod/src/devices/devices-manager.h @@ -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); diff --git a/src/prog/domod/src/main.cpp b/src/prog/domod/src/main.cpp index b6e63f1e..5daede13 100644 --- a/src/prog/domod/src/main.cpp +++ b/src/prog/domod/src/main.cpp @@ -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; diff --git a/src/prog/domod/src/ubus/lights-controller.cpp b/src/prog/domod/src/ubus/outlets-controller.cpp similarity index 63% rename from src/prog/domod/src/ubus/lights-controller.cpp rename to src/prog/domod/src/ubus/outlets-controller.cpp index b500cf11..c0217afe 100644 --- a/src/prog/domod/src/ubus/lights-controller.cpp +++ b/src/prog/domod/src/ubus/outlets-controller.cpp @@ -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; diff --git a/src/prog/domod/src/ubus/lights-controller.h b/src/prog/domod/src/ubus/outlets-controller.h similarity index 86% rename from src/prog/domod/src/ubus/lights-controller.h rename to src/prog/domod/src/ubus/outlets-controller.h index 69a99194..944ac18a 100644 --- a/src/prog/domod/src/ubus/lights-controller.h +++ b/src/prog/domod/src/ubus/outlets-controller.h @@ -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 */