timer wip

This commit is contained in:
jbnadal
2018-04-06 18:12:42 +02:00
parent 62c1b6ba32
commit b5f6a813d3
14 changed files with 332 additions and 315 deletions

View File

@@ -36,26 +36,26 @@ extern "C" {
/*----------------------------- Dependencies --------------------------------*/
/*--------------------------------- CLASS ----------------------------------*/
class ULoopTimer : public uloop_timeout {
// Disable copy construction and copy assignement
ULoopTimer (const ULoopTimer&);
ULoopTimer &operator=(const ULoopTimer&);
public:
ULoopTimer (void);
virtual ~ULoopTimer (void);
class ULoopTimer : public uloop_timeout
{
// Disable copy construction and copy assignement
ULoopTimer(const ULoopTimer &);
ULoopTimer &operator=(const ULoopTimer &);
virtual int expire (void);
int start (unsigned int a_timer_value, bool a_is_repeated = false);
int stop (void);
int tick (void);
public:
ULoopTimer(void);
virtual ~ULoopTimer(void);
private:
virtual int expire(void) = 0;
int start(unsigned int a_timer_value, bool a_is_repeated = false);
int stop(void);
int tick(void);
private:
bool m_is_repeated;
uint16_t m_timer_value;
};

View File

@@ -29,26 +29,24 @@
#include "ubus-cpp/uloop-timer.h"
/*! ----------------------------------------------------------------------------
* @fn timer_callback
*
* @brief Callback used when a Timer has expired.
*/
static void timer_callback (struct uloop_timeout *a_timeout)
static void timer_callback(struct uloop_timeout *a_timeout)
{
ULoopTimer *the_timer = static_cast<ULoopTimer *>(a_timeout);
the_timer->tick();
}
/*! ----------------------------------------------------------------------------
* @fn ULoopTimer
*
* @brief Constructor of the Uloop Timer Object.
*/
ULoopTimer::ULoopTimer (void)
ULoopTimer::ULoopTimer(void)
{
// Uloop Timer Init.
cb = timer_callback;
@@ -59,66 +57,50 @@ ULoopTimer::ULoopTimer (void)
m_timer_value = 0;
}
/*! ----------------------------------------------------------------------------
* @fn ~ULoopTimer
*
* @brief Destructor of the Ullop Timer Object.
*/
ULoopTimer::~ULoopTimer (void)
ULoopTimer::~ULoopTimer(void)
{
}
/*! ----------------------------------------------------------------------------
* @fn start
* @param aTimerValue is the amount of time (in milliseconds) before the timer
* expires.
* @brief Start the Timer object.
*/
int ULoopTimer::start (unsigned int a_timer_value, bool a_is_repeated)
int ULoopTimer::start(unsigned int a_timer_value, bool a_is_repeated)
{
m_timer_value = a_timer_value;
m_is_repeated = a_is_repeated;
return uloop_timeout_set (this, m_timer_value);
return uloop_timeout_set(this, m_timer_value);
}
/*! ----------------------------------------------------------------------------
* @fn stop
*
* @brief Stop the Timer object.
*/
int ULoopTimer::stop (void)
int ULoopTimer::stop(void)
{
return uloop_timeout_cancel (this);
return uloop_timeout_cancel(this);
}
/*! ----------------------------------------------------------------------------
* @fn expire
*
* @brief Method Should be overrided.
*/
int ULoopTimer::expire (void)
{
//fprintf (stderr, "UBusTimer::Expire\n");
return 0;
}
/*! ----------------------------------------------------------------------------
* @fn tick
*
* @brief Method called when the Timer has expired.
*/
int ULoopTimer::tick (void)
int ULoopTimer::tick(void)
{
// fprintf (stderr, "UBusTimer::Tick\n");
if (m_is_repeated == true)
uloop_timeout_set (this, m_timer_value);
return expire ();
uloop_timeout_set(this, m_timer_value);
return expire();
}