add timer manager
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
|
||||
#include "devices/devices-manager.h"
|
||||
|
||||
|
||||
#include "timers/clock.h"
|
||||
|
||||
#include "timers/timers-manager.h"
|
||||
@@ -49,13 +48,11 @@
|
||||
*
|
||||
* @brief Constructor of the Timers Managagers.
|
||||
*/
|
||||
TimerManager::TimerManager (const std::string &a_path, DevicesManager *a_device_manager):
|
||||
m_devices_manager (a_device_manager),
|
||||
TimerManager::TimerManager(const std::string &a_path, DevicesManager *a_device_manager) : m_devices_manager(a_device_manager),
|
||||
m_timers_path(a_path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ~TimerManager
|
||||
*
|
||||
@@ -65,7 +62,6 @@ TimerManager::~TimerManager (void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn load
|
||||
*
|
||||
@@ -106,7 +102,6 @@ int TimerManager::load (void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn save
|
||||
*
|
||||
@@ -114,17 +109,19 @@ int TimerManager::load (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
|
||||
*
|
||||
@@ -134,14 +131,14 @@ const Event &TimerManager::get (uint16_t an_id)
|
||||
{
|
||||
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)
|
||||
|
||||
{
|
||||
return (*the_timer_evt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn remove
|
||||
@@ -152,18 +149,18 @@ int TimerManager::remove (uint16_t an_id)
|
||||
{
|
||||
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)
|
||||
|
||||
{
|
||||
m_timers.erase(the_timer_evt);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn to_json
|
||||
*
|
||||
@@ -171,23 +168,22 @@ int TimerManager::remove (uint16_t an_id)
|
||||
*/
|
||||
struct json_object *TimerManager::to_json(void)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Event>::iterator timer_evt;
|
||||
Json::Value theRoot(Json::objectValue), timers_json(Json::arrayValue);
|
||||
std::vector<Event>::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
|
||||
*
|
||||
@@ -195,39 +191,41 @@ struct json_object *TimerManager::to_json (void)
|
||||
*/
|
||||
int TimerManager::expire(void)
|
||||
{
|
||||
#if 0
|
||||
std::vector<Event>::iterator timer_evt;
|
||||
Clock theClock;
|
||||
std::vector<Event>::iterator the_timer_evt;
|
||||
Clock the_clock;
|
||||
fprintf(stderr, "**** >> Manage timers....\n");
|
||||
|
||||
for(timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) {
|
||||
|
||||
if ((*timer_evt).isActive()) {
|
||||
|
||||
theClock.set ((*timer_evt));
|
||||
|
||||
if ((*timer_evt).isInProgress()) {
|
||||
if (theClock.isExpired()) {
|
||||
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 ((*the_timer_evt).is_in_progress())
|
||||
{
|
||||
if (the_clock.is_expired())
|
||||
{
|
||||
// Action Stop.
|
||||
fprintf(stdout, "Timer Stop\n");
|
||||
(*timer_evt).stop (mDevices);
|
||||
(*the_timer_evt).stop(m_devices_manager);
|
||||
}
|
||||
else {
|
||||
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);
|
||||
(*the_timer_evt).start(m_devices_manager);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user