/* -*- C++ -*- */ // $Id$ // ============================================================================ // // = LIBRARY // ace // // = FILENAME // Proactor.h // // = AUTHOR // Irfan Pyarali , // Tim Harrison and // Alexander Babu Arulanthu // // ============================================================================ #if !defined (ACE_PROACTOR_H) #define ACE_PROACTOR_H #include "ace/OS.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) #pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #if ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS))) // This only works on Win32 platforms and on Unix platforms supporting // POSIX aio calls. #include "ace/Asynch_IO.h" #include "ace/Asynch_IO_Impl.h" #include "ace/Thread_Manager.h" #include "ace/Timer_Queue.h" #include "ace/Timer_List.h" #include "ace/Timer_Heap.h" #include "ace/Timer_Wheel.h" // Forward declarations. class ACE_Proactor_Impl; class ACE_Proactor_Timer_Handler; class ACE_Export ACE_Proactor_Handle_Timeout_Upcall { // = TITLE // Functor for . // // = DESCRIPTION // This class implements the functor required by the Timer // Queue to call on ACE_Handlers. typedef ACE_Timer_Queue_T TIMER_QUEUE; // Type def for the timer queue. friend class ACE_Proactor; // The main Proactor class has special permissions. public: ACE_Proactor_Handle_Timeout_Upcall (void); // Constructor. int timeout (TIMER_QUEUE &timer_queue, ACE_Handler *handler, const void *arg, const ACE_Time_Value &cur_time); // This method is called when the timer expires. int cancellation (TIMER_QUEUE &timer_queue, ACE_Handler *handler); // This method is called when the timer is canceled. int deletion (TIMER_QUEUE &timer_queue, ACE_Handler *handler, const void *arg); // This method is called when the timer queue is destroyed and the // timer is still contained in it. protected: int proactor (ACE_Proactor &proactor); // Set the proactor. This will fail, if one is already set! ACE_Proactor *proactor_; // Handle to the proactor. This is needed for posting a timer result // to the Proactor's completion queue. }; class ACE_Export ACE_Proactor { // = TITLE // A manager for asynchronous event demultiplexing. // // = DESCRIPTION // See the Proactor pattern description at // http://www.cs.wustl.edu/~schmidt/proactor.ps.gz for more // details. // = Here are the private typedefs that the uses. typedef ACE_Timer_Queue_Iterator_T TIMER_QUEUE_ITERATOR; typedef ACE_Timer_List_T TIMER_LIST; typedef ACE_Timer_List_Iterator_T TIMER_LIST_ITERATOR; typedef ACE_Timer_Heap_T TIMER_HEAP; typedef ACE_Timer_Heap_Iterator_T TIMER_HEAP_ITERATOR; typedef ACE_Timer_Wheel_T TIMER_WHEEL; typedef ACE_Timer_Wheel_Iterator_T TIMER_WHEEL_ITERATOR; // = Friendship. friend class ACE_Proactor_Timer_Handler; // Timer handler runs a thread and manages the timers, on behalf of // the Proactor. public: typedef ACE_Timer_Queue_T TIMER_QUEUE; // Public type. ACE_Proactor (ACE_Proactor_Impl *implementation = 0, int delete_implementation = 0, TIMER_QUEUE *tq = 0); // Constructor. If is 0, the correct implementation // object will be created. flag determines // whether the implementation object should be deleted by the // Proactor or not. If is 0, a new TIMER_QUEUE is created. virtual ~ACE_Proactor (void); // Virtual destruction. static ACE_Proactor *instance (size_t threads = 0); // Get pointer to a process-wide . should // be part of another method. static ACE_Proactor *instance (ACE_Proactor *); // Set pointer to a process-wide and return existing // pointer. static void close_singleton (void); // Delete the dynamically allocated Singleton. // = Proactor event loop management methods. static int run_event_loop (void); // Run the event loop until the method // returns -1 or the method is invoked. static int run_event_loop (ACE_Time_Value &tv); // Run the event loop until the method // returns -1, the method is invoked, or the // expires. static int end_event_loop (void); // Instruct the to terminate its event // loop. static int event_loop_done (void); // Report if the event loop is finished. virtual int close (void); // Close the IO completion port. virtual int register_handle (ACE_HANDLE handle, const void *completion_key); // This method adds the to the I/O completion port. This // function is a no-op function for Unix systems and returns 0; // = Timer management. virtual long schedule_timer (ACE_Handler &handler, const void *act, const ACE_Time_Value &time); // Schedule a that will expire after