From cfe5726e0e346adda97cf5d30bd84eea5d8072ce Mon Sep 17 00:00:00 2001 From: jbnadal Date: Wed, 11 Apr 2018 16:28:34 +0200 Subject: [PATCH] wip rename timer as sequence --- src/prog/domod/builders/cmake/CMakeLists.txt | 17 +++-- src/prog/domod/include/domo.h | 2 + src/prog/domod/src/main.cpp | 16 ++-- .../event.cpp => sequences/action.cpp} | 54 ++++++------- .../{timers/event.h => sequences/action.h} | 12 +-- .../domod/src/{timers => sequences}/clock.cpp | 13 ++-- .../domod/src/{timers => sequences}/clock.h | 6 +- src/prog/domod/src/sequences/sequence.cpp | 68 +++++++++++++++++ src/prog/domod/src/sequences/sequence.h | 51 +++++++++++++ .../sequences-manager.cpp} | 75 ++++++++++--------- .../sequences-manager.h} | 20 ++--- ...ghts.cpp => capabilities_lights_model.cpp} | 2 +- ...s_lights.h => capabilities_lights_model.h} | 0 ...apabilities.cpp => capabilities_model.cpp} | 2 +- .../{capabilities.h => capabilities_model.h} | 0 ...rs.cpp => capabilities_shutters_model.cpp} | 2 +- ...utters.h => capabilities_shutters_model.h} | 0 ....cpp => capabilities_sprinklers_model.cpp} | 2 +- ...lers.h => capabilities_sprinklers_model.h} | 0 .../ubus/{timers.cpp => sequences_model.cpp} | 29 +++---- .../src/ubus/{timers.h => sequences_model.h} | 16 ++-- 21 files changed, 259 insertions(+), 128 deletions(-) rename src/prog/domod/src/{timers/event.cpp => sequences/action.cpp} (87%) rename src/prog/domod/src/{timers/event.h => sequences/action.h} (95%) rename src/prog/domod/src/{timers => sequences}/clock.cpp (97%) rename src/prog/domod/src/{timers => sequences}/clock.h (94%) create mode 100644 src/prog/domod/src/sequences/sequence.cpp create mode 100644 src/prog/domod/src/sequences/sequence.h rename src/prog/domod/src/{timers/timers-manager.cpp => sequences/sequences-manager.cpp} (72%) rename src/prog/domod/src/{timers/timers-manager.h => sequences/sequences-manager.h} (78%) rename src/prog/domod/src/ubus/{capabilities_lights.cpp => capabilities_lights_model.cpp} (99%) rename src/prog/domod/src/ubus/{capabilities_lights.h => capabilities_lights_model.h} (100%) rename src/prog/domod/src/ubus/{capabilities.cpp => capabilities_model.cpp} (98%) rename src/prog/domod/src/ubus/{capabilities.h => capabilities_model.h} (100%) rename src/prog/domod/src/ubus/{capabilities_shutters.cpp => capabilities_shutters_model.cpp} (99%) rename src/prog/domod/src/ubus/{capabilities_shutters.h => capabilities_shutters_model.h} (100%) rename src/prog/domod/src/ubus/{capabilities_sprinklers.cpp => capabilities_sprinklers_model.cpp} (99%) rename src/prog/domod/src/ubus/{capabilities_sprinklers.h => capabilities_sprinklers_model.h} (100%) rename src/prog/domod/src/ubus/{timers.cpp => sequences_model.cpp} (80%) rename src/prog/domod/src/ubus/{timers.h => sequences_model.h} (83%) diff --git a/src/prog/domod/builders/cmake/CMakeLists.txt b/src/prog/domod/builders/cmake/CMakeLists.txt index 84afb554..c12e7169 100644 --- a/src/prog/domod/builders/cmake/CMakeLists.txt +++ b/src/prog/domod/builders/cmake/CMakeLists.txt @@ -26,15 +26,16 @@ file( ${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/ubus/capabilities_shutters.cpp - ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_sprinklers.cpp - ${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_model.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_lights_model.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_shutters_model.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_sprinklers_model.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/sequences_model.cpp # Timers - ${workspaceRoot}/src/prog/domod/src/timers/timers-manager.cpp - ${workspaceRoot}/src/prog/domod/src/timers/event.cpp - ${workspaceRoot}/src/prog/domod/src/timers/clock.cpp + ${workspaceRoot}/src/prog/domod/src/sequences/sequences-manager.cpp + ${workspaceRoot}/src/prog/domod/src/sequences/sequence.cpp + ${workspaceRoot}/src/prog/domod/src/sequences/action.cpp + ${workspaceRoot}/src/prog/domod/src/sequences/clock.cpp ) # $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp diff --git a/src/prog/domod/include/domo.h b/src/prog/domod/include/domo.h index 7835e5ec..2a8ad40e 100644 --- a/src/prog/domod/include/domo.h +++ b/src/prog/domod/include/domo.h @@ -37,6 +37,8 @@ #define k_entry_devices "devices" +#define k_entry_timers "timers" + /* common */ #define k_entry_id "id" #define k_entry_name "name" diff --git a/src/prog/domod/src/main.cpp b/src/prog/domod/src/main.cpp index c47f81f2..df77f3ca 100644 --- a/src/prog/domod/src/main.cpp +++ b/src/prog/domod/src/main.cpp @@ -37,13 +37,13 @@ extern "C" { #include } -#include "timers/timers-manager.h" +#include "sequences/sequences-manager.h" #include "devices/devices-manager.h" -#include "ubus/capabilities.h" -#include "ubus/capabilities_lights.h" -#include "ubus/capabilities_shutters.h" -#include "ubus/capabilities_sprinklers.h" +#include "ubus/capabilities_model.h" +#include "ubus/capabilities_lights_model.h" +#include "ubus/capabilities_shutters_model.h" +#include "ubus/capabilities_sprinklers_model.h" /*-------------------------------- DEFINES ---------------------------------*/ @@ -139,9 +139,9 @@ int main(int argc, char *argv[]) return -1; } - /* Setup the Timers. */ - TimerManager the_timers_manager(the_config_path + "/timers.json", &the_devices_manager); - if (the_timers_manager.load() != 0) + /* Setup the Sequences Manager. */ + SequencesManager the_sequences_manager(the_config_path + "/sequences.json", &the_devices_manager); + if (the_sequences_manager.load() != 0) { fprintf(stderr, "Failed to load timers.\n"); return -2; diff --git a/src/prog/domod/src/timers/event.cpp b/src/prog/domod/src/sequences/action.cpp similarity index 87% rename from src/prog/domod/src/timers/event.cpp rename to src/prog/domod/src/sequences/action.cpp index e799f593..00e6f109 100644 --- a/src/prog/domod/src/timers/event.cpp +++ b/src/prog/domod/src/sequences/action.cpp @@ -31,7 +31,7 @@ #include "domo.h" -#include "timers/event.h" +#include "sequences/action.h" /*------------------------------- DEFINES ----------------------------------*/ @@ -44,11 +44,11 @@ #define k_entry_action "action" /*! ---------------------------------------------------------------------------- - * @fn Event + * @fn Action * - * @brief Constructor of Timer Event Object. + * @brief Constructor of Action Object. */ -Event::Event(void) : m_active(false), +Action::Action(void) : m_active(false), m_id(0), m_device_id(0), m_hour(0), @@ -60,20 +60,20 @@ Event::Event(void) : m_active(false), } /*! ---------------------------------------------------------------------------- - * @fn ~Event + * @fn ~Action * - * @brief Destructor of Timer Event Object. + * @brief Destructor of Action Object. */ -Event::~Event(void) +Action::~Action(void) { } /*! ---------------------------------------------------------------------------- * @fn from_json * - * @brief Load Event Object. + * @brief Load Action Object. */ -int Event::from_json(struct json_object *a_node) +int Action::from_json(struct json_object *a_node) { struct json_object *the_value_node; @@ -134,9 +134,9 @@ int Event::from_json(struct json_object *a_node) /*! ---------------------------------------------------------------------------- * @fn to_json * - * @brief Export Event Object as JSON Object. + * @brief Export Action Object as JSON Object. */ -struct json_object *Event::to_json(void) const +struct json_object *Action::to_json(void) const { struct json_object *the_root_node; @@ -165,9 +165,9 @@ struct json_object *Event::to_json(void) const /*! ---------------------------------------------------------------------------- * @fn start * - * @brief Start the Event. + * @brief Start the Action. */ -int Event::start(DevicesManager *a_device_manager) +int Action::start(DevicesManager *a_device_manager) { set_in_progress(true); @@ -177,9 +177,9 @@ int Event::start(DevicesManager *a_device_manager) /*! ---------------------------------------------------------------------------- * @fn stop * - * @brief Stop the Event. + * @brief Stop the Action. */ -int Event::stop(DevicesManager *a_device_manager) +int Action::stop(DevicesManager *a_device_manager) { set_in_progress(false); @@ -191,7 +191,7 @@ int Event::stop(DevicesManager *a_device_manager) * * @brief dump the Event Object. */ -void Event::dump(void) +void Action::dump(void) { fprintf(stdout, "Timer Event:\n"); fprintf(stdout, "=========== \n"); @@ -210,7 +210,7 @@ void Event::dump(void) * * @brief return true if the Timer event is active. */ -bool Event::is_active(void) const +bool Action::is_active(void) const { return m_active; } @@ -220,7 +220,7 @@ bool Event::is_active(void) const * * @brief return the capability of the Event. */ -const std::string &Event::get_capability(void) const +const std::string &Action::get_capability(void) const { return m_capability; } @@ -230,7 +230,7 @@ const std::string &Event::get_capability(void) const * * @brief return the ID of the Event. */ -uint16_t Event::get_id(void) const +uint16_t Action::get_id(void) const { return m_id; } @@ -240,7 +240,7 @@ uint16_t Event::get_id(void) const * * @brief return the Device ID of the Event. */ -uint16_t Event::get_device_id(void) const +uint16_t Action::get_device_id(void) const { return m_device_id; } @@ -250,7 +250,7 @@ uint16_t Event::get_device_id(void) const * * @brief Return the Hour of the Event. */ -uint8_t Event::get_hour(void) const +uint8_t Action::get_hour(void) const { return m_hour; } @@ -260,7 +260,7 @@ uint8_t Event::get_hour(void) const * * @brief Return the Minute of the Event. */ -uint8_t Event::get_minute(void) const +uint8_t Action::get_minute(void) const { return m_minute; } @@ -270,7 +270,7 @@ uint8_t Event::get_minute(void) const * * @brief Return the Recurrency of the Event. */ -uint16_t Event::get_recurrence(void) const +uint16_t Action::get_recurrence(void) const { return m_recurrence; } @@ -280,7 +280,7 @@ uint16_t Event::get_recurrence(void) const * * @brief Return the Duration of the Event. */ -uint16_t Event::get_duration(void) const +uint16_t Action::get_duration(void) const { return m_duration; } @@ -290,7 +290,7 @@ uint16_t Event::get_duration(void) const * * @brief Return the Action of the Event. */ -const std::string &Event::get_action(void) const +const std::string &Action::get_action(void) const { return m_action; } @@ -300,7 +300,7 @@ const std::string &Event::get_action(void) const * * @brief Return true if the Event Is in Progress. */ -bool Event::is_in_progress(void) const +bool Action::is_in_progress(void) const { return m_in_progress; } @@ -310,7 +310,7 @@ bool Event::is_in_progress(void) const * * @brief Set the InProgress to a new state. */ -void Event::set_in_progress(bool a_state) +void Action::set_in_progress(bool a_state) { m_in_progress = a_state; } diff --git a/src/prog/domod/src/timers/event.h b/src/prog/domod/src/sequences/action.h similarity index 95% rename from src/prog/domod/src/timers/event.h rename to src/prog/domod/src/sequences/action.h index 3b4d4a02..3009b312 100644 --- a/src/prog/domod/src/timers/event.h +++ b/src/prog/domod/src/sequences/action.h @@ -1,5 +1,5 @@ /*! - * event.h + * action.h * * Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -23,8 +23,8 @@ * */ -#ifndef _EVENT_H -#define _EVENT_H +#ifndef _ACTION_H +#define _ACTION_H /*------------------------------- INCLUDES ----------------------------------*/ @@ -37,11 +37,11 @@ class DevicesManager; /*--------------------------------- CLASS ----------------------------------*/ -class Event +class Action { public: - Event(void); - ~Event(void); + Action(void); + ~Action(void); int from_json(struct json_object *a_node); struct json_object *to_json(void) const; diff --git a/src/prog/domod/src/timers/clock.cpp b/src/prog/domod/src/sequences/clock.cpp similarity index 97% rename from src/prog/domod/src/timers/clock.cpp rename to src/prog/domod/src/sequences/clock.cpp index 8ceca85a..358be5e3 100644 --- a/src/prog/domod/src/timers/clock.cpp +++ b/src/prog/domod/src/sequences/clock.cpp @@ -22,11 +22,12 @@ * @Date: 20/05/2016 * */ + /*------------------------------- INCLUDES ----------------------------------*/ #include -#include "timers/clock.h" +#include "sequences/clock.h" /*! ---------------------------------------------------------------------------- * @fn Clock @@ -51,6 +52,7 @@ Clock::~Clock(void) * * @brief Set an Event to the Clock. */ +#if 0 int Clock::set(const Event &an_event) { m_event = an_event; @@ -59,7 +61,7 @@ int Clock::set(const Event &an_event) return 0; } - +#endif /*! ---------------------------------------------------------------------------- * @fn is_equal_to_current_time * @@ -72,9 +74,10 @@ bool Clock::is_equal_to_current_time(void) the_compared_time = *localtime(&m_now); +#if 0 the_compared_time.tm_hour = m_event.get_hour(); the_compared_time.tm_min = m_event.get_minute(); - +#endif the_diff = difftime(m_now, mktime(&the_compared_time)); //printf ("%.f seconds of diff between current time and Timer time.\n", theDiff); @@ -97,12 +100,12 @@ bool Clock::is_expired(void) double the_diff; the_compared_time = *localtime(&m_now); - +#if 0 the_compared_time.tm_hour = m_event.get_hour(); the_compared_time.tm_min = m_event.get_minute(); the_expired = mktime(&the_compared_time) + (m_event.get_duration() * 60); - +#endif the_diff = difftime(m_now, the_expired); //printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired); diff --git a/src/prog/domod/src/timers/clock.h b/src/prog/domod/src/sequences/clock.h similarity index 94% rename from src/prog/domod/src/timers/clock.h rename to src/prog/domod/src/sequences/clock.h index ed77973a..e1a60776 100644 --- a/src/prog/domod/src/timers/clock.h +++ b/src/prog/domod/src/sequences/clock.h @@ -30,7 +30,7 @@ #include -#include "timers/event.h" +//#include "timers/event.h" /*---------------------------------- Deps -----------------------------------*/ @@ -42,12 +42,12 @@ class Clock Clock(void); ~Clock(void); - int set(const Event &an_event); + //int set(const Event &an_event); bool is_equal_to_current_time(void); bool is_expired(void); private: - Event m_event; + //Event m_event; time_t m_now; }; diff --git a/src/prog/domod/src/sequences/sequence.cpp b/src/prog/domod/src/sequences/sequence.cpp new file mode 100644 index 00000000..2e5cd65a --- /dev/null +++ b/src/prog/domod/src/sequences/sequence.cpp @@ -0,0 +1,68 @@ +/*! + * sequence.cpp + * + * Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 11/04/2018 + * + */ + +/*------------------------------- INCLUDES ----------------------------------*/ + +#include + +#include "sequence.h" + +/*! ---------------------------------------------------------------------------- + * @fn Sequence + * + * @brief Constructor of the Sequence Object. + */ +Sequence::Sequence(void) +{ +} + +/*! ---------------------------------------------------------------------------- + * @fn ~Sequence + * + * @brief Constructor of the Sequence Object. + */ +Sequence::~Sequence(void) +{ +} + +/*! ---------------------------------------------------------------------------- + * @fn to_json + * + * @brief Export Event Object as JSON Object. + */ +struct json_object *Sequence::to_json(void) const +{ + return NULL; +} + +/*! ---------------------------------------------------------------------------- + * @fn get_id + * + * @brief return the ID of the Sequence. + */ +uint16_t Sequence::get_id(void) const +{ + return m_id; +} diff --git a/src/prog/domod/src/sequences/sequence.h b/src/prog/domod/src/sequences/sequence.h new file mode 100644 index 00000000..42ca10cd --- /dev/null +++ b/src/prog/domod/src/sequences/sequence.h @@ -0,0 +1,51 @@ +/*! + * sequence.h + * + * Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * @Author: NADAL Jean-Baptiste + * @Date: 11/04/2018 + * + */ + +#ifndef _SEQUENCE_H +#define _SEQUENCE_H + +/*------------------------------- INCLUDES ----------------------------------*/ + +/*---------------------------------- Deps -----------------------------------*/ + +struct json_object; + +/*--------------------------------- CLASS ----------------------------------*/ + +class Sequence +{ +public: + Sequence(void); + ~Sequence(void); + + struct json_object *to_json(void) const; + + uint16_t get_id(void) const; + +private: + uint16_t m_id; +}; + +#endif /* _SEQUENCE_H */ diff --git a/src/prog/domod/src/timers/timers-manager.cpp b/src/prog/domod/src/sequences/sequences-manager.cpp similarity index 72% rename from src/prog/domod/src/timers/timers-manager.cpp rename to src/prog/domod/src/sequences/sequences-manager.cpp index ea176a7c..5c9f4621 100644 --- a/src/prog/domod/src/timers/timers-manager.cpp +++ b/src/prog/domod/src/sequences/sequences-manager.cpp @@ -30,35 +30,34 @@ #include -//#include -//#include - #include "devices/devices-manager.h" -#include "timers/clock.h" +#include "sequences/clock.h" -#include "timers/timers-manager.h" +#include "domo.h" + +#include "sequences/sequences-manager.h" //#define k60s 60000 #define k60s 2000 -#define k_entry_timers "timers" + /*! ---------------------------------------------------------------------------- - * @fn TimerManager + * @fn SequencesManager * * @brief Constructor of the Timers Managagers. */ -TimerManager::TimerManager(const std::string &a_path, DevicesManager *a_device_manager) : m_devices_manager(a_device_manager), - m_timers_path(a_path) +SequencesManager::SequencesManager(const std::string &a_path, DevicesManager *a_device_manager) : m_devices_manager(a_device_manager), + m_sequences_file_path(a_path) { } /*! ---------------------------------------------------------------------------- - * @fn ~TimerManager + * @fn ~SequencesManager * * @brief Destructors of the Timer Managers. */ -TimerManager::~TimerManager(void) +SequencesManager::~SequencesManager(void) { } @@ -67,14 +66,14 @@ TimerManager::~TimerManager(void) * * @brief Load the Timer Managers. */ -int TimerManager::load(void) +int SequencesManager::load(void) { struct json_object *the_root_node, *the_timers_node; - the_root_node = json_object_from_file(m_timers_path.c_str()); + the_root_node = json_object_from_file(m_sequences_file_path.c_str()); if (the_root_node == NULL) { - fprintf(stderr, "Failed to parse the Timers File (%s).\n", m_timers_path.c_str()); + fprintf(stderr, "Failed to parse the Timers File (%s).\n", m_sequences_file_path.c_str()); return -1; } @@ -86,11 +85,13 @@ int TimerManager::load(void) the_len = json_object_array_length(the_timers_node); for (int i = 0; i < the_len; i++) { +#if 0 Event the_event; the_event_node = json_object_array_get_idx(the_timers_node, i); the_event.from_json(the_event_node); m_timers.push_back(the_event); +#endif } } @@ -107,14 +108,14 @@ int TimerManager::load(void) * * @brief Method to save the Timers Object into a Json File. */ -int TimerManager::save(void) +int SequencesManager::save(void) { int the_result; struct json_object *the_root_node; the_root_node = to_json(); - the_result = json_object_to_file(m_timers_path.c_str(), the_root_node); + the_result = json_object_to_file(m_sequences_file_path.c_str(), the_root_node); /* Clean the json object. */ json_object_put(the_root_node); @@ -127,8 +128,9 @@ int TimerManager::save(void) * * @brief Method to get a specific Timers Object. */ -bool TimerManager::get(uint16_t an_id, Event &an_event) +bool SequencesManager::get(uint16_t an_id, Sequence &a_sequence) { +#if 0 std::vector::iterator the_timer_evt; for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) @@ -139,6 +141,7 @@ bool TimerManager::get(uint16_t an_id, Event &an_event) return true; } } +#endif return false; } @@ -147,15 +150,15 @@ bool TimerManager::get(uint16_t an_id, Event &an_event) * * @brief Method to remove a specific Timers Object. */ -int TimerManager::remove(uint16_t an_id) +int SequencesManager::remove(uint16_t an_id) { - std::vector::iterator the_timer_evt; + std::vector::iterator the_seq_it; - for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) + for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++) { - if ((*the_timer_evt).get_id() == an_id) + if ((*the_seq_it).get_id() == an_id) { - m_timers.erase(the_timer_evt); + m_sequences.erase(the_seq_it); return 0; } } @@ -168,9 +171,9 @@ int TimerManager::remove(uint16_t an_id) * * @brief Method to return the Timers Object into a Json formar into a Json Object. */ -struct json_object *TimerManager::to_json(void) +struct json_object *SequencesManager::to_json(void) { - std::vector::iterator the_timer_evt; + std::vector::iterator the_seq_it; struct json_object *the_root_node, *the_timer_list_node; the_root_node = json_object_new_object(); @@ -178,38 +181,40 @@ struct json_object *TimerManager::to_json(void) the_timer_list_node = json_object_new_array(); json_object_object_add(the_root_node, k_entry_timers, the_timer_list_node); - for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) + for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++) { - json_object_array_add(the_timer_list_node, (*the_timer_evt).to_json()); + json_object_array_add(the_timer_list_node, (*the_seq_it).to_json()); } return the_root_node; } /*! ---------------------------------------------------------------------------- - * @fn Expire + * @fn expire * * @brief Method Call when the Timer has expired. */ -int TimerManager::expire(void) +int SequencesManager::expire(void) { - std::vector::iterator the_timer_evt; + std::vector::iterator the_seq_it; Clock the_clock; fprintf(stderr, "**** >> Manage timers....\n"); - for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) +#if 0 + for (the_seq_it = m_sequences.begin(); the_seq_it != m_sequences.end(); the_seq_it++) { - if ((*the_timer_evt).is_active()) + if ((*the_seq_it).is_active()) { + the_clock.set((*the_timer_evt)); - if ((*the_timer_evt).is_in_progress()) + if ((*the_seq_it).is_in_progress()) { if (the_clock.is_expired()) { // Action Stop. fprintf(stdout, "Timer Stop\n"); - (*the_timer_evt).stop(m_devices_manager); + (*the_seq_it).stop(m_devices_manager); } else { @@ -223,11 +228,11 @@ int TimerManager::expire(void) { // Action START. fprintf(stdout, "Timer Start\n"); - (*the_timer_evt).start(m_devices_manager); + (*the_seq_it).start(m_devices_manager); } } } } - +#endif return 0; } diff --git a/src/prog/domod/src/timers/timers-manager.h b/src/prog/domod/src/sequences/sequences-manager.h similarity index 78% rename from src/prog/domod/src/timers/timers-manager.h rename to src/prog/domod/src/sequences/sequences-manager.h index 3e55a260..556802cb 100644 --- a/src/prog/domod/src/timers/timers-manager.h +++ b/src/prog/domod/src/sequences/sequences-manager.h @@ -23,8 +23,8 @@ * */ -#ifndef _TIMERS_MANAGER_H -#define _TIMERS_MANAGER_H +#ifndef _SEQUENCES_MANAGER_H +#define _SEQUENCES_MANAGER_H /*------------------------------- INCLUDES ----------------------------------*/ @@ -33,7 +33,7 @@ #include -#include "timers/event.h" +#include "sequences/sequence.h" /*---------------------------------- Deps -----------------------------------*/ @@ -42,26 +42,26 @@ struct json_object; /*--------------------------------- CLASS ----------------------------------*/ -class TimerManager : public ULoopTimer +class SequencesManager : public ULoopTimer { public: - TimerManager(const std::string &a_path, DevicesManager *a_device_manager); - ~TimerManager(void); + SequencesManager(const std::string &a_path, DevicesManager *a_device_manager); + ~SequencesManager(void); int expire(void); int load(void); int save(void); - bool get(uint16_t an_id, Event &a_event); + bool get(uint16_t an_id, Sequence &a_sequence); int remove(uint16_t an_id); struct json_object *to_json(void); private: DevicesManager *m_devices_manager; - std::string m_timers_path; - std::vector m_timers; + std::string m_sequences_file_path; + std::vector m_sequences; }; -#endif /* _TIMERS_MANAGER_H */ +#endif /* _SEQUENCES_MANAGER_H */ diff --git a/src/prog/domod/src/ubus/capabilities_lights.cpp b/src/prog/domod/src/ubus/capabilities_lights_model.cpp similarity index 99% rename from src/prog/domod/src/ubus/capabilities_lights.cpp rename to src/prog/domod/src/ubus/capabilities_lights_model.cpp index 102e2c25..80c188d1 100644 --- a/src/prog/domod/src/ubus/capabilities_lights.cpp +++ b/src/prog/domod/src/ubus/capabilities_lights_model.cpp @@ -35,7 +35,7 @@ extern "C" { #include "domo.h" -#include "capabilities_lights.h" +#include "capabilities_lights_model.h" namespace { diff --git a/src/prog/domod/src/ubus/capabilities_lights.h b/src/prog/domod/src/ubus/capabilities_lights_model.h similarity index 100% rename from src/prog/domod/src/ubus/capabilities_lights.h rename to src/prog/domod/src/ubus/capabilities_lights_model.h diff --git a/src/prog/domod/src/ubus/capabilities.cpp b/src/prog/domod/src/ubus/capabilities_model.cpp similarity index 98% rename from src/prog/domod/src/ubus/capabilities.cpp rename to src/prog/domod/src/ubus/capabilities_model.cpp index 18607aac..e6b72932 100644 --- a/src/prog/domod/src/ubus/capabilities.cpp +++ b/src/prog/domod/src/ubus/capabilities_model.cpp @@ -33,7 +33,7 @@ extern "C" { #include } -#include "capabilities.h" +#include "capabilities_model.h" namespace { diff --git a/src/prog/domod/src/ubus/capabilities.h b/src/prog/domod/src/ubus/capabilities_model.h similarity index 100% rename from src/prog/domod/src/ubus/capabilities.h rename to src/prog/domod/src/ubus/capabilities_model.h diff --git a/src/prog/domod/src/ubus/capabilities_shutters.cpp b/src/prog/domod/src/ubus/capabilities_shutters_model.cpp similarity index 99% rename from src/prog/domod/src/ubus/capabilities_shutters.cpp rename to src/prog/domod/src/ubus/capabilities_shutters_model.cpp index 8d0c18ce..30ac4d8f 100644 --- a/src/prog/domod/src/ubus/capabilities_shutters.cpp +++ b/src/prog/domod/src/ubus/capabilities_shutters_model.cpp @@ -35,7 +35,7 @@ extern "C" { #include "domo.h" -#include "capabilities_shutters.h" +#include "capabilities_shutters_model.h" namespace { diff --git a/src/prog/domod/src/ubus/capabilities_shutters.h b/src/prog/domod/src/ubus/capabilities_shutters_model.h similarity index 100% rename from src/prog/domod/src/ubus/capabilities_shutters.h rename to src/prog/domod/src/ubus/capabilities_shutters_model.h diff --git a/src/prog/domod/src/ubus/capabilities_sprinklers.cpp b/src/prog/domod/src/ubus/capabilities_sprinklers_model.cpp similarity index 99% rename from src/prog/domod/src/ubus/capabilities_sprinklers.cpp rename to src/prog/domod/src/ubus/capabilities_sprinklers_model.cpp index d0e59eaf..4a60296d 100644 --- a/src/prog/domod/src/ubus/capabilities_sprinklers.cpp +++ b/src/prog/domod/src/ubus/capabilities_sprinklers_model.cpp @@ -37,7 +37,7 @@ extern "C" { #include "domo.h" -#include "capabilities_sprinklers.h" +#include "capabilities_sprinklers_model.h" namespace { diff --git a/src/prog/domod/src/ubus/capabilities_sprinklers.h b/src/prog/domod/src/ubus/capabilities_sprinklers_model.h similarity index 100% rename from src/prog/domod/src/ubus/capabilities_sprinklers.h rename to src/prog/domod/src/ubus/capabilities_sprinklers_model.h diff --git a/src/prog/domod/src/ubus/timers.cpp b/src/prog/domod/src/ubus/sequences_model.cpp similarity index 80% rename from src/prog/domod/src/ubus/timers.cpp rename to src/prog/domod/src/ubus/sequences_model.cpp index a3b0cd57..6cda7aee 100644 --- a/src/prog/domod/src/ubus/timers.cpp +++ b/src/prog/domod/src/ubus/sequences_model.cpp @@ -1,5 +1,5 @@ /*! - * TimersModel.cpp + * SequencesModel.cpp * * Copyright (c) 2016-2018, NADAL Jean-Baptiste. All rights reserved. * @@ -33,37 +33,38 @@ extern "C" { #include -#include "timers/timers-manager.h" +#include "sequences/sequences-manager.h" -#include "timers.h" +#include "sequences_model.h" namespace { using namespace UBus; -static ObjectType gTimersModelUbus_types( - "TimersModel", - Method("get", UBUS_CPP(TimersModel, get)), - Method("delete", UBUS_CPP(TimersModel, del))); +static ObjectType gSequencesModelUbus_types( + "SequencesModel", + Method("get", UBUS_CPP(SequencesModel, get)), + Method("delete", UBUS_CPP(SequencesModel, del))); } /*! ---------------------------------------------------------------------------- - * @fn TimersModel + * @fn SequencesModel * * @brief Constructor of the Timer Objects. */ -TimersModel::TimersModel(TimerManager *a_timer_manager) : UBusObject(gTimersModelUbus_types, "domo.timers"), - m_timer_manager(a_timer_manager) +SequencesModel::SequencesModel(SequencesManager *a_sequences_manager) : + UBusObject(gSequencesModelUbus_types, "domo.sequences"), + m_sequences_manager(a_sequences_manager) { } /*! ---------------------------------------------------------------------------- - * @fn ~TimersModel + * @fn ~SequencesModel * * @brief Destructor of the Timer Objects. */ -TimersModel::~TimersModel(void) +SequencesModel::~SequencesModel(void) { } @@ -72,7 +73,7 @@ TimersModel::~TimersModel(void) * * @brief Get the List of timer objects. */ -int TimersModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) +int SequencesModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { int the_result = 0; #if 0 @@ -114,7 +115,7 @@ int TimersModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req * * @brief Delete a Timer Object. */ -int TimersModel::del(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) +int SequencesModel::del(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { int the_result = 0; #if 0 diff --git a/src/prog/domod/src/ubus/timers.h b/src/prog/domod/src/ubus/sequences_model.h similarity index 83% rename from src/prog/domod/src/ubus/timers.h rename to src/prog/domod/src/ubus/sequences_model.h index 916dfbb4..f7b02a1e 100644 --- a/src/prog/domod/src/ubus/timers.h +++ b/src/prog/domod/src/ubus/sequences_model.h @@ -23,8 +23,8 @@ * */ -#ifndef _UBUS_TIMERS_H -#define _UBUS_TIMERS_H +#ifndef _UBUS_SEQUENCES_H +#define _UBUS_SEQUENCES_H /*------------------------------- INCLUDES ----------------------------------*/ @@ -34,22 +34,22 @@ /*--------------------------------- Define ----------------------------------*/ -class TimerManager; +class SequencesManager; /*--------------------------------- CLASS ----------------------------------*/ -class TimersModel : public UBusObject +class SequencesModel : public UBusObject { public: - TimersModel(TimerManager *a_timer_manager); - ~TimersModel(void); + SequencesModel(SequencesManager *a_sequences_manager); + ~SequencesModel(void); int get(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); int del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); private: - TimerManager *m_timer_manager; + SequencesManager *m_sequences_manager; }; -#endif /* _UBUS_TIMERS_H */ +#endif /* _UBUS_SEQUENCES_H */