/* -*- C++ -*- */ // $Id$ // ============================================================================ // // = LIBRARY // ace // // = FILENAME // Proactor.h // // = AUTHOR // Irfan Pyarali (irfan@cs.wustl.edu), // Tim Harrison (harrison@cs.wustl.edu) and // Alexander Babu Arulanthu // // ============================================================================ #ifndef ACE_PROACTOR_H #define ACE_PROACTOR_H #include "ace/OS.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "ace/Asynch_IO.h" #include "ace/Thread_Manager.h" #include "ace/Event_Handler.h" #include "ace/Timer_Queue.h" #include "ace/Timer_List.h" #include "ace/Timer_Heap.h" #include "ace/Timer_Wheel.h" #include "ace/Free_List.h" #include "ace/Pipe.h" #if (defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || \ (defined (ACE_HAS_AIO_CALLS)) // This only works on Win32 platforms and on Unix platforms supporting // aio calls. // Forward declarations. class ACE_Asynch_Result; class ACE_Asynch_Operation; class ACE_Proactor_Timer_Handler; class ACE_Proactor; #if defined (ACE_HAS_AIO_CALLS) class ACE_AIO_Accept_Handler; #endif /* ACE_HAS_AIO_CALLS */ 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. public: friend class ACE_Proactor; // Proactor has special privileges, access needed to: proactor (). typedef ACE_Timer_Queue_T TIMER_QUEUE; 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 the completion port. }; class ACE_Export ACE_Proactor : public ACE_Event_Handler { // = 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. public: friend class ACE_Proactor_Timer_Handler; // Timer Handler has special privileges because Access needed to: // thr_mgr_ friend class ACE_Proactor_Handle_Timeout_Upcall; // Access needed to: Asynch_Timer, and completion_port_. friend class ACE_Asynch_Operation; // For POSIX4-compliant-Unix systems, the // call is used by // to store some information with the // Proactor after an call is issued, so that the Proactor can // retrive this information to do and . #if defined (ACE_HAS_AIO_CALLS) friend class ACE_Asynch_Accept_Handler; // For POSIX4 implementation, this class takes care of doing the // Asynch_Accept. friend class ACE_AIO_Accept_Handler; // We need also this class with the Proactor to take care of // Asynch_Accept when we use AIO_CONTROL_BLOCKS. #endif /* ACE_HAS_AIO_CALLS */ // = Here are the typedefs that the uses. // @@ Can these typedefs be capitalized? typedef ACE_Timer_Queue_T Timer_Queue; 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; enum POSIX_COMPLETION_STRATEGY { // Use the real time signals and do on the // signals. RT_SIGNALS, // Store the control blocks with the and do // on them, AIO_CONTROL_BLOCKS }; // For Posix4-Compliat-Unix systems how the completion of the // asynchronous calls should be got from the OS. ACE_Proactor (size_t number_of_threads = 0, Timer_Queue *tq = 0, int used_with_reactor_event_loop = 0, POSIX_COMPLETION_STRATEGY completion_strategy = AIO_CONTROL_BLOCKS); // A do nothing constructor. 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. // = Timer management. virtual long schedule_timer (ACE_Handler &handler, const void *act, const ACE_Time_Value &time); // Schedule a that will expire after