Device for similar timers with ACE_REACTOR
Examples of monomers present a ACE_Reactor, it has schedule_timer method, a four parameters schedule_timer (ACE_Event_Handler * event_handler, const void * arg, const ACE_Time_Value & delay, const ACE_Time_Value & interval = ACE_Time_Value :: zero);
The first parameter points to an ACE_EVENT_HANDLER class, which provides the Virtual Int Handle_timeout (const void * arg) method, and the Handle_Timeout method will be triggered when the set interval arrives
The parameter transmitted by the second parameter table, corresponding to the arg parameters of the Handle_Timeout method
The third parameter table timer starts to work, the time class corresponds to the ACE_TIME_VALUE class
The time of the fourth parameter table timer is executed, if 0 is 0, the table timer is only once in time.
The example procedure is as follows: (Example from the ACE library) #include "ace / reactor.h" #include "ace / service_config.h" #include "ace / os_main.h"
class Timeout_Handler: public ACE_Event_Handler {public: Timeout_Handler (void): count_ (0) {} virtual int handle_timeout (const ACE_Time_Value & tv, const void * arg) {ACE_DEBUG ((LM_DEBUG, "% d timeout occurred for% s / n." , count_, (char *) arg); return 0;}
PRIVATE: INT COUNT_;
INTACE_TMAIN (int, ACE_TCHAR * []) {Timeout_Handler Handler;
// Performed once every 1 second, delayed 1 second to start timing ACE_TIME_VALUE BAR_TV (1); ace_reactor :: instance () -> schedule_timer (& handler, (void *) "bar", bar_tv, bar_tv);
// Performed once every 1 second, delayed 1 second to start timing ACE_TIME_VALUE FOO_TV (1); ACE_RAAAACTAN :: Instance () -> Schedule_timer (Void *) "foo", foo_tv, foo_tv); // Setting events Processing timeout is 12 seconds ACE_TIME_VALUE RUN_TIME (12); if (ACE_RAACTOR :: Run_Event_LOOP (Run_TIME) == -1) ACE_ERROR_RETURN ((LM_ERROR, "% p. / N", "main"), -1); returnograph }