diff --git a/src/prog/domod/builders/cmake/CMakeLists.txt b/src/prog/domod/builders/cmake/CMakeLists.txt index 35f6810f..338dcc76 100644 --- a/src/prog/domod/builders/cmake/CMakeLists.txt +++ b/src/prog/domod/builders/cmake/CMakeLists.txt @@ -27,13 +27,13 @@ file( # ubus models ${workspaceRoot}/src/prog/domod/src/ubus/capabilities.cpp ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_lights.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_shutters.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_shutters.cpp # $ENV{SRC_DIR}/src/prog/domod/src/ubus/capabilities_sprinklers.cpp # $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp # $ENV{SRC_DIR}/src/prog/domod/src/helpers/Tokenizer.cpp diff --git a/src/prog/domod/src/main.cpp b/src/prog/domod/src/main.cpp index 413e8383..84e9fb6b 100644 --- a/src/prog/domod/src/main.cpp +++ b/src/prog/domod/src/main.cpp @@ -42,10 +42,11 @@ extern "C" { #include "ubus/capabilities.h" #include "ubus/capabilities_lights.h" +#include "ubus/capabilities_shutters.h" /*-------------------------------- DEFINES ---------------------------------*/ -#define k_dir_sep '/' +#define k_dir_sep '/' #define k_config_dir "share/domo/" /*! ---------------------------------------------------------------------------- @@ -82,8 +83,6 @@ static struct ubus_context *setup_ubus(void) } } - - /*! ---------------------------------------------------------------------------- * @fn get_config_path * @@ -98,10 +97,11 @@ const std::string get_config_path(char *an_exec_path) the_pos = the_exec_path.rfind(k_dir_sep); // get exec path. - the_config_path = the_exec_path.substr(0, the_pos + 1); + the_config_path = the_exec_path.substr(0, the_pos + 1); // remove last / is necessary. - if (the_config_path[the_config_path.size()-1] == k_dir_sep) { + if (the_config_path[the_config_path.size() - 1] == k_dir_sep) + { the_config_path = the_exec_path.substr(0, the_config_path.size() - 1); } @@ -128,16 +128,17 @@ int main(int argc, char *argv[]) /* Get the Path of the binary to load configs. */ the_config_path = get_config_path(argv[0]); - printf ("config path: %s\n", the_config_path.c_str()); + printf("config path: %s\n", the_config_path.c_str()); /* Setup the devices. */ DevicesManager the_devices_manager(the_config_path + "/Devices.json"); - if (the_devices_manager.load() != 0) { + if (the_devices_manager.load() != 0) + { fprintf(stderr, "Failed to load devices.\n"); return -1; } - /* Setup the Timers. */ + /* Setup the Timers. */ #if 0 Timers the_timers(the_config_path + "/Timers.json", &the_devices_manager); if (the_timers.load() != 0) { @@ -145,11 +146,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); - + CapabilitiesShuttersModel the_cap_shutters(&the_devices_manager); return 0; /* Setup the Ubus context. */ @@ -162,6 +163,7 @@ int main(int argc, char *argv[]) /* Add the UBus to the model exposed. */ ubus_add_object(the_ctx, &the_capabilities); ubus_add_object(the_ctx, &the_cap_lights); + ubus_add_object(the_ctx, &the_cap_shutters); /* Main Event Loop. */ uloop_run(); @@ -174,8 +176,6 @@ int main(int argc, char *argv[]) #if 0 - -#include "ubus/capabilities_shutters.h" #include "ubus/capabilities_sprinklers.h" #include "ubus/speach_command.h" #include "ubus/timers.h" @@ -229,7 +229,7 @@ int main (void) /* Setup the UBus Models. */ CapabilitiesModel theCapabilities; CapabilitiesLightsModel theCapLights (&theDevices); - CapabilitiesShuttersModel theCapShutters (&theDevices); + CapabilitiesSprinklersModel theCapSprinklers (&theDevices); SpeachCommandModel theSpeachCommand (&theDevices); TimersModel theTimersModel (&theTimers); @@ -246,7 +246,7 @@ int main (void) /* Add the UBus to the model exposed. */ ubus_add_object (theCtx, &theCapabilities); ubus_add_object (theCtx, &theCapLights); - ubus_add_object (theCtx, &theCapShutters); + ubus_add_object (theCtx, &theCapSprinklers); ubus_add_object (theCtx, &theSpeachCommand); ubus_add_object (theCtx, &theTimersModel); diff --git a/src/prog/domod/src/ubus/capabilities_shutters.cpp b/src/prog/domod/src/ubus/capabilities_shutters.cpp index 545ea7f1..75fad2af 100644 --- a/src/prog/domod/src/ubus/capabilities_shutters.cpp +++ b/src/prog/domod/src/ubus/capabilities_shutters.cpp @@ -29,32 +29,31 @@ extern "C" { #include } -#include +#include -#include "devices/Devices.h" +#include "devices/devices-manager.h" #include "capabilities_shutters.h" -namespace { +namespace +{ using namespace UBus; static ObjectType gCapabilitiesShuttersModelUbus_types( "shutters", - Method("get", UBUS_CPP(CapabilitiesShuttersModel, Get)), - Method("delete", UBUS_CPP(CapabilitiesShuttersModel, Delete)), - Method("put", UBUS_CPP(CapabilitiesShuttersModel, Put)), - Method("post", UBUS_CPP(CapabilitiesShuttersModel, Post)), + Method("get", UBUS_CPP(CapabilitiesShuttersModel, get)), + Method("delete", UBUS_CPP(CapabilitiesShuttersModel, del)), + Method("put", UBUS_CPP(CapabilitiesShuttersModel, put)), + Method("post", UBUS_CPP(CapabilitiesShuttersModel, post)), - Method("open", UBUS_CPP(CapabilitiesShuttersModel, Open)), - Method("close", UBUS_CPP(CapabilitiesShuttersModel, Close)), + Method("open", UBUS_CPP(CapabilitiesShuttersModel, open)), + Method("close", UBUS_CPP(CapabilitiesShuttersModel, close)), - Method("up", UBUS_CPP(CapabilitiesShuttersModel, Up)), - Method("down", UBUS_CPP(CapabilitiesShuttersModel, Down)), - - Method("position", UBUS_CPP(CapabilitiesShuttersModel, Position)) -); + Method("up", UBUS_CPP(CapabilitiesShuttersModel, up)), + Method("down", UBUS_CPP(CapabilitiesShuttersModel, down)), + Method("position", UBUS_CPP(CapabilitiesShuttersModel, position))); } /*! ---------------------------------------------------------------------------- @@ -62,143 +61,133 @@ static ObjectType gCapabilitiesShuttersModelUbus_types( * * @brief Constructor of the UBus Mixer Volume. */ -CapabilitiesShuttersModel::CapabilitiesShuttersModel (Devices *aDevice) : - UBusObject (gCapabilitiesShuttersModelUbus_types, "domo.capabilities.shutters"), - mDevices (aDevice) +CapabilitiesShuttersModel::CapabilitiesShuttersModel(DevicesManager *a_device_manager) : UBusObject(gCapabilitiesShuttersModelUbus_types, "domo.capabilities.shutters"), + m_devices_manager(a_device_manager) { } - /*! ---------------------------------------------------------------------------- * @fn ~CapabilitiesShuttersModel * * @brief Destructor of the UBus Mixer Volume. */ -CapabilitiesShuttersModel::~CapabilitiesShuttersModel (void) +CapabilitiesShuttersModel::~CapabilitiesShuttersModel(void) { - } - /*! ---------------------------------------------------------------------------- - * @fn Get + * @fn get * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) +int CapabilitiesShuttersModel::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}; - blob_buf_init (&theBuf, 0); - - blobmsg_add_json_from_string (&theBuf, mDevices->get("Shutters").c_str()); - - theResult = ubus_send_reply (aCtx, aReq, theBuf.head); - - blob_buf_free (&theBuf); - - return theResult; + blob_buf_init(&the_buf, 0); + + blobmsg_add_json_from_string(&the_buf, m_devices_manager->get(kShutterEntry).c_str()); + + the_result = ubus_send_reply(a_ctx, a_req, the_buf.head); + + blob_buf_free(&the_buf); + + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Delete + * @fn del * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - - return theResult; + int the_result = 0; + + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Put + * @fn put * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Put (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::put(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - - return theResult; + int the_result = 0; + + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Post + * @fn post * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Post (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::post(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - - return theResult; + int the_result = 0; + + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Open + * @fn open * * @brief Open the Shutter */ -int CapabilitiesShuttersModel::Open (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::open(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - printf ("Open the Shutter\n"); - return theResult; -} - - -/*! ---------------------------------------------------------------------------- - * @fn Close - * - * @brief Get the List of the Capabilities. - */ -int CapabilitiesShuttersModel::Close (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) -{ - int theResult = 0; - printf ("Close the Shutter\n"); - return theResult; + int the_result = 0; + printf("Open the Shutter\n"); + return the_result; } /*! ---------------------------------------------------------------------------- - * @fn Up + * @fn close * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Up (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::close(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - printf ("Up the Shutter\n"); - return theResult; + int the_result = 0; + printf("Close the Shutter\n"); + return the_result; } /*! ---------------------------------------------------------------------------- - * @fn Down + * @fn up * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Down (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::up(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - printf ("Down the Shutter\n"); - return theResult; + int the_result = 0; + printf("Up the Shutter\n"); + return the_result; } /*! ---------------------------------------------------------------------------- - * @fn Position + * @fn down * * @brief Get the List of the Capabilities. */ -int CapabilitiesShuttersModel::Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*) +int CapabilitiesShuttersModel::down(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) { - int theResult = 0; - printf ("Position the Shutter\n"); - return theResult; + int the_result = 0; + printf("Down the Shutter\n"); + return the_result; +} + +/*! ---------------------------------------------------------------------------- + * @fn position + * + * @brief Get the List of the Capabilities. + */ +int CapabilitiesShuttersModel::position(struct ubus_context *, struct ubus_request_data *, struct blob_attr *) +{ + int the_result = 0; + printf("Position the Shutter\n"); + return the_result; } diff --git a/src/prog/domod/src/ubus/capabilities_shutters.h b/src/prog/domod/src/ubus/capabilities_shutters.h index be6d08ad..a8bab718 100644 --- a/src/prog/domod/src/ubus/capabilities_shutters.h +++ b/src/prog/domod/src/ubus/capabilities_shutters.h @@ -1,5 +1,5 @@ /*! - * capabilities_shutters.h + * capabilities_shutters * * Copyright (c) 2015-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -29,36 +29,36 @@ /*------------------------------- INCLUDES ----------------------------------*/ #include - -#include + +#include /*--------------------------------- Define ----------------------------------*/ -class Devices; +class DevicesManager; /*--------------------------------- CLASS ----------------------------------*/ -class CapabilitiesShuttersModel : public UBusObject { +class CapabilitiesShuttersModel : public UBusObject +{ + public: + CapabilitiesShuttersModel(DevicesManager *a_device_manager); + ~CapabilitiesShuttersModel(void); -public: - CapabilitiesShuttersModel (Devices *aDevice); - ~CapabilitiesShuttersModel (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 *); - 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 open(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); + int close(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 up(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); + int down(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); - int Position (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); + int position(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); -private: - Devices *mDevices; + private: + DevicesManager *m_devices_manager; }; #endif /* _UBUS_CAPABILITIES_SHUTTERS_MODEL_H */