add timer manager
This commit is contained in:
@@ -34,7 +34,7 @@ file(
|
|||||||
# Timers
|
# Timers
|
||||||
${workspaceRoot}/src/prog/domod/src/timers/timers-manager.cpp
|
${workspaceRoot}/src/prog/domod/src/timers/timers-manager.cpp
|
||||||
${workspaceRoot}/src/prog/domod/src/timers/event.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
|
# $ENV{SRC_DIR}/src/prog/domod/src/ubus/speach_command.cpp
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
|
|
||||||
#include "devices/devices-manager.h"
|
#include "devices/devices-manager.h"
|
||||||
|
|
||||||
|
|
||||||
#include "timers/clock.h"
|
#include "timers/clock.h"
|
||||||
|
|
||||||
#include "timers/timers-manager.h"
|
#include "timers/timers-manager.h"
|
||||||
@@ -49,29 +48,26 @@
|
|||||||
*
|
*
|
||||||
* @brief Constructor of the Timers Managagers.
|
* @brief Constructor of the Timers Managagers.
|
||||||
*/
|
*/
|
||||||
TimerManager::TimerManager (const std::string &a_path, DevicesManager *a_device_manager):
|
TimerManager::TimerManager(const std::string &a_path, DevicesManager *a_device_manager) : m_devices_manager(a_device_manager),
|
||||||
m_devices_manager (a_device_manager),
|
m_timers_path(a_path)
|
||||||
m_timers_path (a_path)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn ~TimerManager
|
* @fn ~TimerManager
|
||||||
*
|
*
|
||||||
* @brief Destructors of the Timer Managers.
|
* @brief Destructors of the Timer Managers.
|
||||||
*/
|
*/
|
||||||
TimerManager::~TimerManager (void)
|
TimerManager::~TimerManager(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn load
|
* @fn load
|
||||||
*
|
*
|
||||||
* @brief Load the Timer Managers.
|
* @brief Load the Timer Managers.
|
||||||
*/
|
*/
|
||||||
int TimerManager::load (void)
|
int TimerManager::load(void)
|
||||||
{
|
{
|
||||||
struct json_object *the_root_node, *the_data_node;
|
struct json_object *the_root_node, *the_data_node;
|
||||||
|
|
||||||
@@ -101,133 +97,135 @@ int TimerManager::load (void)
|
|||||||
/* Clean the json object. */
|
/* Clean the json object. */
|
||||||
json_object_put(the_root_node);
|
json_object_put(the_root_node);
|
||||||
|
|
||||||
start (k60s, true);
|
start(k60s, true);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn save
|
* @fn save
|
||||||
*
|
*
|
||||||
* @brief Method to save the Timers Object into a Json File.
|
* @brief Method to save the Timers Object into a Json File.
|
||||||
*/
|
*/
|
||||||
int TimerManager::save (void)
|
int TimerManager::save(void)
|
||||||
{
|
{
|
||||||
#if 0
|
int the_result;
|
||||||
Json::StyledStreamWriter theWriter;
|
struct json_object *the_root_node;
|
||||||
|
|
||||||
/* Save to the File. */
|
the_root_node = to_json();
|
||||||
std::ofstream theOutput (mTimersPath.c_str());
|
|
||||||
theWriter.write (theOutput, to_json());
|
the_result = json_object_to_file(m_timers_path.c_str(), the_root_node);
|
||||||
#endif
|
|
||||||
return 0;
|
/* Clean the json object. */
|
||||||
|
json_object_put(the_root_node);
|
||||||
|
|
||||||
|
return the_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn get
|
* @fn get
|
||||||
*
|
*
|
||||||
* @brief Method to get a specific Timers Object.
|
* @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<Event>::iterator the_timer_evt;
|
std::vector<Event>::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)
|
if ((*the_timer_evt).get_id() == an_id)
|
||||||
|
{
|
||||||
return (*the_timer_evt);
|
return (*the_timer_evt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn remove
|
* @fn remove
|
||||||
*
|
*
|
||||||
* @brief Method to remove a specific Timers Object.
|
* @brief Method to remove a specific Timers Object.
|
||||||
*/
|
*/
|
||||||
int TimerManager::remove (uint16_t an_id)
|
int TimerManager::remove(uint16_t an_id)
|
||||||
{
|
{
|
||||||
std::vector<Event>::iterator the_timer_evt;
|
std::vector<Event>::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)
|
if ((*the_timer_evt).get_id() == an_id)
|
||||||
|
{
|
||||||
m_timers.erase (the_timer_evt);
|
m_timers.erase(the_timer_evt);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn to_json
|
* @fn to_json
|
||||||
*
|
*
|
||||||
* @brief Method to return the Timers Object into a Json formar into a Json Object.
|
* @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<Event>::iterator the_timer_evt;
|
||||||
std::vector<Event>::iterator timer_evt;
|
struct json_object *the_root_node, *the_timer_list_node;
|
||||||
Json::Value theRoot(Json::objectValue), timers_json(Json::arrayValue);
|
|
||||||
|
|
||||||
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 the_root_node;
|
||||||
|
|
||||||
return theRoot;
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn Expire
|
* @fn Expire
|
||||||
*
|
*
|
||||||
* @brief Method Call when the Timer has expired.
|
* @brief Method Call when the Timer has expired.
|
||||||
*/
|
*/
|
||||||
int TimerManager::expire (void)
|
int TimerManager::expire(void)
|
||||||
{
|
{
|
||||||
#if 0
|
std::vector<Event>::iterator the_timer_evt;
|
||||||
std::vector<Event>::iterator timer_evt;
|
Clock the_clock;
|
||||||
Clock theClock;
|
fprintf(stderr, "**** >> Manage timers....\n");
|
||||||
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()) {
|
if ((*the_timer_evt).is_in_progress())
|
||||||
|
{
|
||||||
theClock.set ((*timer_evt));
|
if (the_clock.is_expired())
|
||||||
|
{
|
||||||
if ((*timer_evt).isInProgress()) {
|
|
||||||
if (theClock.isExpired()) {
|
|
||||||
|
|
||||||
// Action Stop.
|
// Action Stop.
|
||||||
fprintf (stdout, "Timer Stop\n");
|
fprintf(stdout, "Timer Stop\n");
|
||||||
(*timer_evt).stop (mDevices);
|
(*the_timer_evt).stop(m_devices_manager);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
fprintf (stdout, "Not expired yet.\n");
|
{
|
||||||
|
fprintf(stdout, "Not expired yet.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
if (theClock.isEqualToCurrentTime ()) {
|
|
||||||
|
|
||||||
|
if (the_clock.is_equal_to_current_time())
|
||||||
|
{
|
||||||
// Action START.
|
// Action START.
|
||||||
fprintf (stdout, "Timer Start\n");
|
fprintf(stdout, "Timer Start\n");
|
||||||
(*timer_evt).start (mDevices);
|
(*the_timer_evt).start(m_devices_manager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user