/* -*- C++ -*- */ // $Id$ // ============================================================================ // // = LIBRARY // ace // // = FILENAME // Timer_Queue_T.h // // = AUTHOR // Doug Schmidt and Irfan Pyarali // // ============================================================================ #if !defined (ACE_TIMER_QUEUE_T_H) #define ACE_TIMER_QUEUE_T_H #include "ace/Time_Value.h" // Forward declarations. template class ACE_Timer_Queue_T; template class ACE_Timer_List_T; template class ACE_Timer_List_Iterator_T; template class ACE_Timer_Heap_T; template class ACE_Timer_Heap_Iterator_T; template class ACE_Timer_Wheel_T; template class ACE_Timer_Wheel_Iterator_T; // This should be nested within the ACE_Timer_Queue class but some C++ // compilers still don't like this... template class ACE_Timer_Node_T // = TITLE // Maintains the state associated with a Timer entry. { // = The use of friends should be replaced with accessors... friend class ACE_Timer_Queue_T; friend class ACE_Timer_List_T; friend class ACE_Timer_List_Iterator_T; friend class ACE_Timer_Heap_T; friend class ACE_Timer_Heap_Iterator_T; friend class ACE_Timer_Wheel_T; friend class ACE_Timer_Wheel_Iterator_T; // = Initialization methods. ACE_Timer_Node_T (const TYPE &type, const void *a, const ACE_Time_Value &t, const ACE_Time_Value &i, ACE_Timer_Node_T *n, long timer_id); // Constructor. ACE_Timer_Node_T (const TYPE &type, const void *a, const ACE_Time_Value &t, const ACE_Time_Value &i, ACE_Timer_Node_T *p, ACE_Timer_Node_T *n, long timer_id); // Constructor for the doubly linked list version. ACE_Timer_Node_T (void); // Default constructor. TYPE type_; // Type of object stored in the Queue const void *act_; // Act associated with the timer. ACE_Time_Value timer_value_; // Time until the timer expires. ACE_Time_Value interval_; // If this is a periodic timer this holds the time until the next // timeout. ACE_Timer_Node_T *prev_; // Pointer to previous timer. ACE_Timer_Node_T *next_; // Pointer to next timer. long timer_id_; // Id of this timer (used to cancel timers before they expire). ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. void dump (void) const; // Dump the state of an TYPE. }; template class ACE_Timer_Queue_Iterator_T // = TITLE // Generic interfae for iterating over a subclass of // . // // = DESCRIPTION // This is a special type of iterator that "advances" by moving // the head of the timer queue up by one every time. { public: // = Initialization and termination methods. ACE_Timer_Queue_Iterator_T (void); // Constructor. virtual ~ACE_Timer_Queue_Iterator_T (void); // Destructor. virtual int next (ACE_Timer_Node_T *&timer_node, const ACE_Time_Value &cur_time) = 0; // Pass back the next that hasn't been seen yet, if its // <= . In addition, moves the timer queue // forward by one node. Returns 0 when all have been // seen, else 1. }; template class ACE_Timer_Queue_T // = TITLE // Provides an interface to timers. // // = DESCRIPTION // This is an abstract base class that provides hook for // implementing specialized policies such as // and . { public: typedef ACE_Timer_Queue_Iterator_T ITERATOR; // Type of Iterator // = Initialization and termination methods. ACE_Timer_Queue_T (FUNCTOR *upcall_functor = 0); // Default constructor. is the instance of the // FUNCTOR to be used by the queue. If is 0, Timer // Queue will create a default FUNCTOR. virtual ~ACE_Timer_Queue_T (void); // Destructor - make virtual for proper destruction of inherited // classes. virtual int is_empty (void) const = 0; // True if queue is empty, else false. virtual const ACE_Time_Value &earliest_time (void) const = 0; // Returns the time of the earlier node in the Timer_Queue. virtual long schedule (const TYPE &type, const void *act, const ACE_Time_Value &delay, const ACE_Time_Value &interval = ACE_Time_Value::zero) = 0; // Schedule that will expire after amount of time. // If it expires then is passed in as the value to the // . If is != to then it // is used to reschedule the automatically. This method // returns a that uniquely identifies the the // entry in an internal list. This can be used to cancel // the timer before it expires. The cancellation ensures that // are unique up to values of greater than 2 billion // timers. As long as timers don't stay around longer than this // there should be no problems with accidentally deleting the wrong // timer. Returns -1 on failure (which is guaranteed never to be a // valid ). virtual int cancel (const TYPE &type, int dont_call_handle_close = 1) = 0; // Cancel all timer associated with . If is 0 // then the will be invoked. Returns number of timers // cancelled. virtual int cancel (long timer_id, const void **act = 0, int dont_call_handle_close = 1) = 0; // Cancel the single timer that matches the value (which // was returned from the method). If act is non-NULL // then it will be set to point to the ``magic cookie'' argument // passed in when the timer was registered. This makes it possible // to free up the memory and avoid memory leaks. If is // 0 then the will be invoked. Returns 1 if cancellation // succeeded and 0 if the wasn't found. virtual int expire (const ACE_Time_Value ¤t_time); // Run the for all timers whose values are <= . // This does not account for . Returns the number of // timers canceled. virtual int expire (void); // Run the for all timers whose values are <= // . Also accounts for . Returns // the number of timers canceled. virtual ACE_Time_Value gettimeofday (void); // Returns the current time of day. This allows different // implementations of the timer queue to use special high resolution // timers. void gettimeofday (ACE_Time_Value (*gettimeofday)(void)); // Allows applications to control how the timer queue gets the time // of day. virtual ACE_Time_Value *calculate_timeout (ACE_Time_Value *max); // Determine the next event to timeout. Returns if there are // no pending timers or if all pending timers are longer than max. // = Set/get the timer skew for the Timer_Queue. void timer_skew (const ACE_Time_Value &skew); const ACE_Time_Value &timer_skew (void) const; LOCK &mutex (void); // Synchronization variable used by the queue FUNCTOR &upcall_functor (void); // Accessor to the upcall functor virtual void dump (void) const; // Dump the state of a object. ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. protected: virtual void upcall (TYPE &type, const void *act, const ACE_Time_Value &cur_time); // This method will call the with the , and //