ACE_Proactor_Timer_Handler Class Reference

A Handler for timer. It helps in the management of timers registered with the Proactor. More...

Inheritance diagram for ACE_Proactor_Timer_Handler:

Inheritance graph
[legend]
Collaboration diagram for ACE_Proactor_Timer_Handler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Proactor_Timer_Handler (ACE_Proactor &proactor)
 Constructor.

virtual ~ACE_Proactor_Timer_Handler (void)
 Destructor.

int destroy (void)

Protected Member Functions

virtual int svc (void)

Protected Attributes

ACE_Auto_Event timer_event_
 Event to wait on.

ACE_Proactorproactor_
 Proactor.

int shutting_down_
 Flag used to indicate when we are shutting down.


Friends

class ACE_Proactor

Detailed Description

A Handler for timer. It helps in the management of timers registered with the Proactor.

This object has a thread that will wait on the earliest time in a list of timers and an event. When a timer expires, the thread will post a completion event on the port and go back to waiting on the timer queue and event. If the event is signaled, the thread will refresh the time it is currently waiting on (in case the earliest time has changed).

Definition at line 64 of file Proactor.cpp.


Constructor & Destructor Documentation

ACE_Proactor_Timer_Handler::ACE_Proactor_Timer_Handler ACE_Proactor proactor  ) 
 

Constructor.

Definition at line 99 of file Proactor.cpp.

References ACE_NULL_SYNCH.

00100   : ACE_Task <ACE_NULL_SYNCH> (&proactor.thr_mgr_),
00101     proactor_ (proactor),
00102     shutting_down_ (0)
00103 {
00104 }

ACE_Proactor_Timer_Handler::~ACE_Proactor_Timer_Handler void   )  [virtual]
 

Destructor.

Definition at line 106 of file Proactor.cpp.

References ACE_Event::signal(), ACE_Task_Base::thr_mgr(), timer_event_, and ACE_Thread_Manager::wait_grp().

00107 {
00108   // Mark for closing down.
00109   this->shutting_down_ = 1;
00110 
00111   // Signal timer event.
00112   this->timer_event_.signal ();
00113 
00114   // Wait for the Timer Handler thread to exit.
00115   this->thr_mgr ()->wait_grp (this->grp_id ());
00116 }


Member Function Documentation

int ACE_Proactor_Timer_Handler::destroy void   ) 
 

Proactor calls this to shut down the timer handler gracefully. Just calling the destructor alone doesnt do what does. make sure the thread exits properly.

int ACE_Proactor_Timer_Handler::svc void   )  [protected, virtual]
 

Run by a daemon thread to handle deferred processing. In other words, this method will do the waiting on the earliest timer and event.

Reimplemented from ACE_Task_Base.

Definition at line 119 of file Proactor.cpp.

References ACE_ERROR_RETURN, ACE_TEXT, ETIME, LM_ERROR, proactor_, timer_event_, and ACE_Event::wait().

00120 {
00121   ACE_Time_Value absolute_time;
00122   ACE_Time_Value relative_time;
00123   int result = 0;
00124 
00125   while (this->shutting_down_ == 0)
00126     {
00127       // Check whether the timer queue has any items in it.
00128       if (this->proactor_.timer_queue ()->is_empty () == 0)
00129         {
00130           // Get the earliest absolute time.
00131           absolute_time = this->proactor_.timer_queue ()->earliest_time ();
00132 
00133           // Get current time from timer queue since we don't know
00134           // which <gettimeofday> was used.
00135           ACE_Time_Value cur_time = this->proactor_.timer_queue ()->gettimeofday ();
00136 
00137           // Compare absolute time with curent time received from the
00138           // timer queue.
00139           if (absolute_time > cur_time)
00140             relative_time = absolute_time - cur_time;
00141           else
00142             relative_time = ACE_Time_Value::zero;
00143 
00144           // Block for relative time.
00145           result = this->timer_event_.wait (&relative_time, 0);
00146         }
00147       else
00148         // The timer queue has no entries, so wait indefinitely.
00149         result = this->timer_event_.wait ();
00150 
00151       // Check for timer expiries.
00152       if (result == -1)
00153         {
00154           switch (errno)
00155             {
00156             case ETIME:
00157               // timeout: expire timers
00158               this->proactor_.timer_queue ()->expire ();
00159               break;
00160             default:
00161               // Error.
00162               ACE_ERROR_RETURN ((LM_ERROR,
00163                                  ACE_TEXT ("%N:%l:(%P | %t):%p\n"),
00164                                  ACE_TEXT ("ACE_Proactor_Timer_Handler::svc:wait failed")),
00165                                 -1);
00166             }
00167         }
00168     }
00169   return 0;
00170 }


Friends And Related Function Documentation

friend class ACE_Proactor [friend]
 

Proactor has special privileges Access needed to: timer_event_

Definition at line 69 of file Proactor.cpp.


Member Data Documentation

ACE_Proactor& ACE_Proactor_Timer_Handler::proactor_ [protected]
 

Proactor.

Definition at line 93 of file Proactor.cpp.

Referenced by svc().

int ACE_Proactor_Timer_Handler::shutting_down_ [protected]
 

Flag used to indicate when we are shutting down.

Definition at line 96 of file Proactor.cpp.

ACE_Auto_Event ACE_Proactor_Timer_Handler::timer_event_ [protected]
 

Event to wait on.

Definition at line 90 of file Proactor.cpp.

Referenced by svc(), and ~ACE_Proactor_Timer_Handler().


The documentation for this class was generated from the following file:
Generated on Sun Jan 27 12:56:24 2008 for ACE by doxygen 1.3.6