|
|
|
@ -7,24 +7,49 @@
|
|
|
|
|
#include <string.h> // strerror
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @note not used now
|
|
|
|
|
// static void sigHandler(int sig, siginfo_t *si, void *uc)
|
|
|
|
|
// {
|
|
|
|
|
// TRACE_STATIC;
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct sigaction& sigActionInit( struct sigaction &sigAct, const int signal )
|
|
|
|
|
{
|
|
|
|
|
sigAct.sa_flags = SA_SIGINFO;
|
|
|
|
|
// sigAct.sa_sigaction = sigHandler;
|
|
|
|
|
sigemptyset( &sigAct.sa_mask );
|
|
|
|
|
sigaddset( &sigAct.sa_mask, signal );
|
|
|
|
|
sigaction( signal, &sigAct, 0 );
|
|
|
|
|
return sigAct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sigset_t& sigSetInit( sigset_t &sigSet, const int signal )
|
|
|
|
|
{
|
|
|
|
|
sigemptyset( &sigSet );
|
|
|
|
|
sigaddset(&sigSet, signal );
|
|
|
|
|
sigprocmask(SIG_SETMASK, &sigSet, NULL);
|
|
|
|
|
return sigSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer::Timer( const Timer& timer )
|
|
|
|
|
: m_signal( timer.m_signal )
|
|
|
|
|
Timer::Timer( const int signal )
|
|
|
|
|
: m_signal( signal )
|
|
|
|
|
, m_sigAction( sigActionInit( m_sigAction , m_signal ) )
|
|
|
|
|
, m_timerId( 0 )
|
|
|
|
|
, m_periodic( false )
|
|
|
|
|
, m_running( true )
|
|
|
|
|
, m_mask( sigSetInit( m_mask, m_signal ) )
|
|
|
|
|
{
|
|
|
|
|
TRACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer::~Timer()
|
|
|
|
|
{
|
|
|
|
|
TRACE;
|
|
|
|
|
|
|
|
|
|
sigprocmask(SIG_UNBLOCK, &m_mask, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -40,7 +65,10 @@ void Timer::createTimer( const time_t interval_sec,
|
|
|
|
|
sigev.sigev_notify = SIGEV_SIGNAL;
|
|
|
|
|
sigev.sigev_signo = m_signal;
|
|
|
|
|
sigev.sigev_value.sival_ptr = &m_timerId;
|
|
|
|
|
timer_create( CLOCK_MONOTONIC, &sigev, &m_timerId );
|
|
|
|
|
timer_create( CLOCK_REALTIME, &sigev, &m_timerId );
|
|
|
|
|
|
|
|
|
|
LOG( Logger::FINEST, ( std::string( "Timer created with ID: " ) +
|
|
|
|
|
stringify( m_timerId ) ).c_str() );
|
|
|
|
|
|
|
|
|
|
// arm it
|
|
|
|
|
struct itimerspec its;
|
|
|
|
@ -58,15 +86,30 @@ void Timer::wait()
|
|
|
|
|
{
|
|
|
|
|
TRACE;
|
|
|
|
|
|
|
|
|
|
int sig;
|
|
|
|
|
sigwait( &m_sigAction.sa_mask, &sig );
|
|
|
|
|
/// @note timerID is acquired from the siginfo after all
|
|
|
|
|
long* tidp;
|
|
|
|
|
siginfo_t sigInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sigwaitinfo( &(m_sigAction.sa_mask), &sigInfo);
|
|
|
|
|
tidp = (long*)sigInfo.si_value.sival_ptr;
|
|
|
|
|
// LOG( Logger::FINEST, ( std::string( "Timer expired with ID: " ) +
|
|
|
|
|
// stringify( (timer_t)*tidp ) ).c_str() );
|
|
|
|
|
|
|
|
|
|
timerExpired();
|
|
|
|
|
|
|
|
|
|
if ( m_periodic ) {
|
|
|
|
|
while ( m_running ) {
|
|
|
|
|
sigwait( &m_sigAction.sa_mask, &sig );
|
|
|
|
|
|
|
|
|
|
sigwaitinfo( &(m_sigAction.sa_mask), &sigInfo);
|
|
|
|
|
tidp = (long*)sigInfo.si_value.sival_ptr;
|
|
|
|
|
// LOG( Logger::FINEST, ( std::string( "Timer expired with ID:" ) +
|
|
|
|
|
// stringify( (timer_t)*tidp ) ).c_str() );
|
|
|
|
|
|
|
|
|
|
periodicTimerExpired();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -88,21 +131,3 @@ void Timer::gracefulStop()
|
|
|
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer::Timer( const int signal )
|
|
|
|
|
: m_signal( signal )
|
|
|
|
|
, m_sigAction( sigActionInit( m_sigAction , m_signal ) )
|
|
|
|
|
, m_timerId( 0 )
|
|
|
|
|
, m_periodic( false )
|
|
|
|
|
, m_running( true )
|
|
|
|
|
{
|
|
|
|
|
TRACE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer& Timer::operator=( const Timer& )
|
|
|
|
|
{
|
|
|
|
|
TRACE;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|