#include <iostream>
#include <unistd.h>
#include "ace/Timer_Queue_Adapters.h"
#include "ace/Event_Handler.h"
#include "ace/Timer_Wheel.h"
#include "ace/reactor.h"
#include "ace/High_Res_Timer.h"
using namespace std;
ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Wheel> active_timer_ ;
class CTaskTimerHandler: public ACE_Event_Handler
{
public:
CTaskTimerHandler(void){};
virtual ~CTaskTimerHandler(void){};
enum { TIMER_NOTSET = -1, TIMER_CANCELLED = -2, TIMER_FIRED = -3 };
virtual int handle_timeout (const ACE_Time_Value ¤t_time, const void *act)
{
cout<< "time out "<< endl;
return 0;
}
};
void startTimer()
{
static CTaskTimerHandler hdl;
// active_timer_.reactor(ACE_Reactor::instance());
// active_timer_.reactor()->timer_queue()->gettimeofday(ACE_High_Res_Timer::gettimeofday_hr);
const ACE_Time_Value curr_tv = ACE_High_Res_Timer::gettimeofday_hr();
long timerID = active_timer_.schedule(&hdl, 0, curr_tv + ACE_Time_Value(1), ACE_Time_Value(1));
if(timerID < 0)
{
cout<<"schedule time failed"<<endl;
}
active_timer_.timer_queue()->gettimeofday(ACE_High_Res_Timer::gettimeofday_hr);
active_timer_.activate();
}
int main()
{
ACE_High_Res_Timer::global_scale_factor();
startTimer();
sleep(2);
for(;;)
{
sleep(7);
sleep(1);
}
}
/*
int ACE_TMAIN (int, ACE_TCHAR *[])
{
ACE_High_Res_Timer::global_scale_factor();
startTimer();
Sleep(2);
for(;;)
{
Sleep(7000);
Sleep(1);
}
}
*/