diff --git a/src/prog/domod/builders/cmake/CMakeLists.txt b/src/prog/domod/builders/cmake/CMakeLists.txt index c6ad6a19..c5e6c2f7 100644 --- a/src/prog/domod/builders/cmake/CMakeLists.txt +++ b/src/prog/domod/builders/cmake/CMakeLists.txt @@ -34,7 +34,7 @@ file( # 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/timers/clock.cpp ) # $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp diff --git a/src/prog/domod/src/timers/timers-manager.cpp b/src/prog/domod/src/timers/timers-manager.cpp index ae1a9795..514c85fe 100644 --- a/src/prog/domod/src/timers/timers-manager.cpp +++ b/src/prog/domod/src/timers/timers-manager.cpp @@ -35,7 +35,6 @@ #include "devices/devices-manager.h" - #include "timers/clock.h" #include "timers/timers-manager.h" @@ -49,29 +48,26 @@ * * @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) +TimerManager::TimerManager(const std::string &a_path, DevicesManager *a_device_manager) : m_devices_manager(a_device_manager), + m_timers_path(a_path) { } - /*! ---------------------------------------------------------------------------- * @fn ~TimerManager * * @brief Destructors of the Timer Managers. */ -TimerManager::~TimerManager (void) +TimerManager::~TimerManager(void) { } - /*! ---------------------------------------------------------------------------- * @fn load * * @brief Load the Timer Managers. */ -int TimerManager::load (void) +int TimerManager::load(void) { struct json_object *the_root_node, *the_data_node; @@ -101,133 +97,135 @@ int TimerManager::load (void) /* Clean the json object. */ json_object_put(the_root_node); - start (k60s, true); + start(k60s, true); return 0; } - /*! ---------------------------------------------------------------------------- * @fn save * * @brief Method to save the Timers Object into a Json File. */ -int TimerManager::save (void) +int TimerManager::save(void) { -#if 0 - Json::StyledStreamWriter theWriter; + int the_result; + struct json_object *the_root_node; - /* Save to the File. */ - std::ofstream theOutput (mTimersPath.c_str()); - theWriter.write (theOutput, to_json()); -#endif - return 0; + the_root_node = to_json(); + + the_result = json_object_to_file(m_timers_path.c_str(), the_root_node); + + /* Clean the json object. */ + json_object_put(the_root_node); + + return the_result; } - /*! ---------------------------------------------------------------------------- * @fn get * * @brief Method to get a specific Timers Object. */ -const Event &TimerManager::get (uint16_t an_id) +const Event &TimerManager::get(uint16_t an_id) { std::vector::iterator the_timer_evt; - for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) { - + for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) + { if ((*the_timer_evt).get_id() == an_id) - + { return (*the_timer_evt); + } } } - /*! ---------------------------------------------------------------------------- * @fn remove * * @brief Method to remove a specific Timers Object. */ -int TimerManager::remove (uint16_t an_id) +int TimerManager::remove(uint16_t an_id) { std::vector::iterator the_timer_evt; - for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) { - + for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) + { if ((*the_timer_evt).get_id() == an_id) - - m_timers.erase (the_timer_evt); + { + m_timers.erase(the_timer_evt); return 0; + } } return -1; } - /*! ---------------------------------------------------------------------------- * @fn to_json * * @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 *TimerManager::to_json(void) { -#if 0 - std::vector::iterator timer_evt; - Json::Value theRoot(Json::objectValue), timers_json(Json::arrayValue); + std::vector::iterator the_timer_evt; + struct json_object *the_root_node, *the_timer_list_node; - for (timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) { + the_root_node = json_object_new_object(); - timers_json.append ((*timer_evt).to_json()); + 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++) + { + json_object_array_add(the_timer_list_node, (*the_timer_evt).to_json()); } - theRoot["timers"] = timers_json; - - return theRoot; -#endif - return NULL; + return the_root_node; } - /*! ---------------------------------------------------------------------------- * @fn Expire * * @brief Method Call when the Timer has expired. */ -int TimerManager::expire (void) +int TimerManager::expire(void) { -#if 0 - std::vector::iterator timer_evt; - Clock theClock; - fprintf (stderr, "**** >> Manage timers....\n"); + std::vector::iterator the_timer_evt; + Clock the_clock; + fprintf(stderr, "**** >> Manage timers....\n"); - for(timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) { + for (the_timer_evt = m_timers.begin(); the_timer_evt != m_timers.end(); the_timer_evt++) + { + if ((*the_timer_evt).is_active()) + { + the_clock.set((*the_timer_evt)); - if ((*timer_evt).isActive()) { - - theClock.set ((*timer_evt)); - - if ((*timer_evt).isInProgress()) { - if (theClock.isExpired()) { - + if ((*the_timer_evt).is_in_progress()) + { + if (the_clock.is_expired()) + { // Action Stop. - fprintf (stdout, "Timer Stop\n"); - (*timer_evt).stop (mDevices); + fprintf(stdout, "Timer Stop\n"); + (*the_timer_evt).stop(m_devices_manager); } - else { - fprintf (stdout, "Not expired yet.\n"); + else + { + fprintf(stdout, "Not expired yet.\n"); } } - else { - - if (theClock.isEqualToCurrentTime ()) { + else + { + if (the_clock.is_equal_to_current_time()) + { // Action START. - fprintf (stdout, "Timer Start\n"); - (*timer_evt).start (mDevices); + fprintf(stdout, "Timer Start\n"); + (*the_timer_evt).start(m_devices_manager); } } } } -#endif + return 0; }