Proactor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Proactor.h
00006  *
00007  *  Proactor.h,v 4.94 2006/04/19 12:31:52 jwillemsen Exp
00008  *
00009  *  @author Irfan Pyarali <irfan@cs.wustl.edu>
00010  *  @author Tim Harrison <harrison@cs.wustl.edu>
00011  *  @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
00012  *  @author Alexander Libman <alibman@ihug.com.au>
00013  */
00014 //=============================================================================
00015 
00016 #ifndef ACE_PROACTOR_H
00017 #define ACE_PROACTOR_H
00018 
00019 #include /**/ "ace/pre.h"
00020 
00021 #include "ace/config-all.h"
00022 #include "ace/ACE_export.h"
00023 
00024 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 #pragma once
00026 #endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #if ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS)))
00029 // This only works on Win32 platforms and on Unix platforms supporting
00030 // POSIX aio calls.
00031 
00032 #  include "ace/Asynch_IO.h"
00033 #  include "ace/Asynch_IO_Impl.h"
00034 #  include "ace/Thread_Manager.h"
00035 #  include "ace/Timer_Queue.h"
00036 #  include "ace/Timer_List.h"
00037 #  include "ace/Timer_Heap.h"
00038 #  include "ace/Timer_Wheel.h"
00039 
00040 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00041 
00042 // Forward declarations.
00043 class ACE_Proactor_Impl;
00044 class ACE_Proactor_Timer_Handler;
00045 
00046 /**
00047  * @class ACE_Proactor_Handle_Timeout_Upcall
00048  *
00049  * @brief Functor for ACE_Timer_Queue.
00050  *
00051  * This class implements the functor required by the Timer
00052  * Queue to call <handle_timeout> on ACE_Handlers.
00053  */
00054 class ACE_Proactor_Handle_Timeout_Upcall
00055 {
00056 
00057   /// Type def for the timer queue.
00058   typedef ACE_Timer_Queue_T<ACE_Handler *,
00059                             ACE_Proactor_Handle_Timeout_Upcall,
00060                             ACE_SYNCH_RECURSIVE_MUTEX>
00061   TIMER_QUEUE;
00062 
00063   /// The main Proactor class has special permissions.
00064   friend class ACE_Proactor;
00065 
00066 public:
00067   /// Constructor.
00068   ACE_Proactor_Handle_Timeout_Upcall (void);
00069 
00070   /// This method is called when a timer is registered.
00071   int registration (TIMER_QUEUE &timer_queue,
00072                     ACE_Handler *handler,
00073                     const void *arg);
00074 
00075   /// This method is called before the timer expires.
00076   int preinvoke (TIMER_QUEUE &timer_queue,
00077                  ACE_Handler *handler,
00078                  const void *arg,
00079                  int recurring_timer,
00080                  const ACE_Time_Value &cur_time,
00081                  const void *&upcall_act);
00082 
00083   /// This method is called when the timer expires.
00084   int timeout (TIMER_QUEUE &timer_queue,
00085                ACE_Handler *handler,
00086                const void *arg,
00087                int recurring_timer,
00088                const ACE_Time_Value &cur_time);
00089 
00090   /// This method is called after the timer expires.
00091   int postinvoke (TIMER_QUEUE &timer_queue,
00092                   ACE_Handler *handler,
00093                   const void *arg,
00094                   int recurring_timer,
00095                   const ACE_Time_Value &cur_time,
00096                   const void *upcall_act);
00097 
00098   /// This method is called when a handler is canceled.
00099   int cancel_type (TIMER_QUEUE &timer_queue,
00100                    ACE_Handler *handler,
00101                    int dont_call_handle_close,
00102                    int &requires_reference_counting);
00103 
00104   /// This method is called when a timer is canceled.
00105   int cancel_timer (TIMER_QUEUE &timer_queue,
00106                     ACE_Handler *handler,
00107                     int dont_call_handle_close,
00108                     int requires_reference_counting);
00109 
00110   /// This method is called when the timer queue is destroyed and the
00111   /// timer is still contained in it.
00112   int deletion (TIMER_QUEUE &timer_queue,
00113                 ACE_Handler *handler,
00114                 const void *arg);
00115 
00116 protected:
00117   /// Set the proactor. This will fail, if one is already set!
00118   int proactor (ACE_Proactor &proactor);
00119 
00120   /// Handle to the proactor. This is needed for posting a timer result
00121   /// to the Proactor's completion queue.
00122   ACE_Proactor *proactor_;
00123 };
00124 
00125 /**
00126  * @class ACE_Proactor
00127  *
00128  * @brief A manager for asynchronous event demultiplexing.
00129  *
00130  * See the Proactor pattern description at
00131  * http://www.cs.wustl.edu/~schmidt/proactor.ps.gz for more
00132  * details.
00133  */
00134 class ACE_Export ACE_Proactor
00135 {
00136   // = Here are the private typedefs that the <ACE_Proactor> uses.
00137 
00138   typedef ACE_Timer_Queue_Iterator_T<ACE_Handler *,
00139     ACE_Proactor_Handle_Timeout_Upcall,
00140     ACE_SYNCH_RECURSIVE_MUTEX>
00141   TIMER_QUEUE_ITERATOR;
00142   typedef ACE_Timer_List_T<ACE_Handler *,
00143     ACE_Proactor_Handle_Timeout_Upcall,
00144     ACE_SYNCH_RECURSIVE_MUTEX>
00145   TIMER_LIST;
00146   typedef ACE_Timer_List_Iterator_T<ACE_Handler *,
00147     ACE_Proactor_Handle_Timeout_Upcall,
00148     ACE_SYNCH_RECURSIVE_MUTEX>
00149   TIMER_LIST_ITERATOR;
00150   typedef ACE_Timer_Heap_T<ACE_Handler *,
00151     ACE_Proactor_Handle_Timeout_Upcall,
00152     ACE_SYNCH_RECURSIVE_MUTEX>
00153   TIMER_HEAP;
00154   typedef ACE_Timer_Heap_Iterator_T<ACE_Handler *,
00155     ACE_Proactor_Handle_Timeout_Upcall,
00156     ACE_SYNCH_RECURSIVE_MUTEX>
00157   TIMER_HEAP_ITERATOR;
00158   typedef ACE_Timer_Wheel_T<ACE_Handler *,
00159     ACE_Proactor_Handle_Timeout_Upcall,
00160     ACE_SYNCH_RECURSIVE_MUTEX>
00161   TIMER_WHEEL;
00162   typedef ACE_Timer_Wheel_Iterator_T<ACE_Handler *,
00163     ACE_Proactor_Handle_Timeout_Upcall,
00164     ACE_SYNCH_RECURSIVE_MUTEX>
00165   TIMER_WHEEL_ITERATOR;
00166 
00167   // = Friendship.
00168 
00169   /// Timer handler runs a thread and manages the timers, on behalf of
00170   /// the Proactor.
00171   friend class ACE_Proactor_Timer_Handler;
00172 
00173 public:
00174   /// Public type.
00175   typedef ACE_Timer_Queue_T<ACE_Handler *,
00176     ACE_Proactor_Handle_Timeout_Upcall,
00177     ACE_SYNCH_RECURSIVE_MUTEX>
00178   TIMER_QUEUE;
00179 
00180   /**
00181    * Constructor. If <implementation> is 0, the correct implementation
00182    * object will be created. <delete_implementation> flag determines
00183    * whether the implementation object should be deleted by the
00184    * Proactor or not. If <tq> is 0, a new TIMER_QUEUE is created.
00185    */
00186   ACE_Proactor (ACE_Proactor_Impl *implementation = 0,
00187                 int delete_implementation = 0,
00188                 TIMER_QUEUE *tq = 0);
00189 
00190   /// Destruction.
00191   ~ACE_Proactor (void);
00192 
00193   /// Get pointer to a process-wide <ACE_Proactor>.  <threads> should
00194   /// be part of another method.
00195   static ACE_Proactor *instance (size_t threads = 0);
00196 
00197   /// Set pointer to a process-wide <ACE_Proactor> and return existing
00198   /// pointer.
00199   static ACE_Proactor *instance (ACE_Proactor * proactor,
00200                                  int delete_proactor = 0);
00201 
00202   /// Delete the dynamically allocated Singleton.
00203   static void close_singleton (void);
00204 
00205   /// Cleanup method, used by the <ACE_Object_Manager> to destroy the
00206   /// singleton.
00207   static void cleanup (void *instance, void *arg);
00208 
00209   /// Name of dll in which the singleton instance lives.
00210   static const ACE_TCHAR *dll_name (void);
00211 
00212   /// Name of component--ACE_Proactor in this case.
00213   static const ACE_TCHAR *name (void);
00214 
00215   // = Proactor event loop management methods.
00216 
00217   /// Run the event loop until the <ACE_Proactor::handle_events> method
00218   /// returns -1 or the <end_event_loop> method is invoked.
00219   static int run_event_loop (void);
00220 
00221   /**
00222    * Run the event loop until the <ACE_Proactor::handle_events> method
00223    * returns -1, the <end_event_loop> method is invoked, or the
00224    * <ACE_Time_Value> expires, in which case 0 is returned.
00225    */
00226   static int run_event_loop (ACE_Time_Value &tv);
00227 
00228   /**
00229    * Instruct the <ACE_Proactor::instance> to terminate its event
00230    * loop.
00231    * This method wakes up all the threads blocked on waiting for
00232    * completions and end the event loop.
00233    */
00234   static int end_event_loop (void);
00235 
00236   /**
00237    * Resets the <ACE_Proactor::end_event_loop_> static so that the
00238    * <run_event_loop> method can be restarted.
00239    */
00240   static int reset_event_loop (void);
00241 
00242   /**
00243    * The singleton proactor is used by the ACE_Service_Config.
00244    * Therefore, we must check for the reconfiguration request and
00245    * handle it after handling an event.
00246    */
00247   static int check_reconfiguration (ACE_Proactor *);
00248 
00249   /// Report if the <ACE_Proactor::instance> event loop is finished.
00250   static int event_loop_done (void);
00251 
00252   /// Close the associated @c ACE_Proactor_Impl implementation object.
00253   /**
00254    * If @arg delete_implementation was specified to the @c open() method,
00255    * the implementation object is also deleted.
00256    */
00257   int close (void);
00258 
00259    /**
00260    * You can add a hook to various run_event methods and the hook will
00261    * be called after handling every proactor event.  If this function
00262    * returns 0, proactor_run_event_loop will check for the return value of
00263    * handle_events.  If it is -1, the the proactor_run_event_loop will return
00264    * (pre-maturely.)
00265    */
00266   typedef int (*PROACTOR_EVENT_HOOK)(ACE_Proactor *);
00267 
00268   // These methods work with an instance of a proactor.
00269   /**
00270    * Run the event loop until the
00271    * <ACE_Proactor::handle_events>
00272    * method returns -1 or the <end_proactor_event_loop> method is invoked.
00273    */
00274   int proactor_run_event_loop (PROACTOR_EVENT_HOOK = 0);
00275 
00276   /**
00277    * Run the event loop until the <ACE_Proactor::handle_events>
00278    * method returns -1, the
00279    * <end_proactor_event_loop> method is invoked,
00280    * or the <ACE_Time_Value>
00281    * expires, in which case a 0 is returned.
00282    */
00283   int proactor_run_event_loop (ACE_Time_Value &tv,
00284                                PROACTOR_EVENT_HOOK = 0);
00285 
00286   /**
00287    * Instruct the ACE_Proactor to terminate its event loop
00288    * and notifies the ACE_Proactor so that it can wake up
00289    * and close down gracefully.
00290    */
00291   int proactor_end_event_loop (void);
00292 
00293   /// Report if the ACE_Proactor event loop is finished.
00294   int proactor_event_loop_done (void);
00295 
00296   /// Resets the <ACE_Proactor::end_event_loop_> static so that the
00297   /// <run_event_loop> method can be restarted.
00298   int proactor_reset_event_loop (void);
00299 
00300 
00301   /// This method adds the <handle> to the I/O completion port. This
00302   /// function is a no-op function for Unix systems and returns 0;
00303   int register_handle (ACE_HANDLE handle,
00304                        const void *completion_key);
00305 
00306   // = Timer management.
00307   /**
00308    * Schedule a <handler> that will expire after <time>.  If it
00309    * expires then <act> is passed in as the value to the <handler>'s
00310    * <handle_timeout> callback method.  This method returns a
00311    * <timer_id>. This <timer_id> can be used to cancel a timer before
00312    * it expires.  The cancellation ensures that <timer_ids> are unique
00313    * up to values of greater than 2 billion timers.  As long as timers
00314    * don't stay around longer than this there should be no problems
00315    * with accidentally deleting the wrong timer.  Returns -1 on
00316    * failure (which is guaranteed never to be a valid <timer_id>).
00317    */
00318   long schedule_timer (ACE_Handler &handler,
00319                        const void *act,
00320                        const ACE_Time_Value &time);
00321 
00322   long schedule_repeating_timer (ACE_Handler &handler,
00323                                  const void *act,
00324                                  const ACE_Time_Value &interval);
00325 
00326   // Same as above except <interval> it is used to reschedule the
00327   // <handler> automatically.
00328 
00329   /// This combines the above two methods into one. Mostly for backward
00330   /// compatibility.
00331   long schedule_timer (ACE_Handler &handler,
00332                        const void *act,
00333                        const ACE_Time_Value &time,
00334                        const ACE_Time_Value &interval);
00335 
00336   /// Cancel all timers associated with this <handler>.  Returns number
00337   /// of timers cancelled.
00338   int cancel_timer (ACE_Handler &handler,
00339                     int dont_call_handle_close = 1);
00340 
00341   /**
00342    * Cancel the single <ACE_Handler> that matches the <timer_id> value
00343    * (which was returned from the <schedule> method).  If <act> is
00344    * non-NULL then it will be set to point to the ``magic cookie''
00345    * argument passed in when the <Handler> was registered.  This makes
00346    * it possible to free up the memory and avoid memory leaks.
00347    * Returns 1 if cancellation succeeded and 0 if the <timer_id>
00348    * wasn't found.
00349    */
00350   int cancel_timer (long timer_id,
00351                     const void **act = 0,
00352                     int dont_call_handle_close = 1);
00353 
00354   /**
00355    * Dispatch a single set of events, waiting up to a specified time limit
00356    * if necessary.
00357    * @param wait_time the time to wait for an event to occur. This is
00358    * a relative time. On successful return, the time is updated to
00359    * reflect the amount of time spent waiting for event(s) to occur.
00360    * @return Returns 0 if no events occur before the wait_time expires.
00361    * Returns 1 when a completion is dispatched. On error, returns -1
00362    * and sets errno accordingly.
00363    */
00364   int handle_events (ACE_Time_Value &wait_time);
00365 
00366   /**
00367    * Block indefinitely until at least one event is dispatched.
00368    * @return Returns 1 when a completion is dispatched. On error, returns -1
00369    * and sets errno accordingly.
00370    */
00371   int handle_events (void);
00372 
00373   /// Add wakeup dispatch threads (reinit).
00374   int wake_up_dispatch_threads (void);
00375 
00376   /// Close all dispatch threads.
00377   int close_dispatch_threads (int wait);
00378 
00379   /// Get number of thread used as a parameter to CreatIoCompletionPort.
00380   size_t number_of_threads (void) const;
00381 
00382   /// Set number of thread used as a parameter to CreatIoCompletionPort.
00383   void number_of_threads (size_t threads);
00384 
00385   /// Get timer queue.
00386   TIMER_QUEUE *timer_queue (void) const;
00387 
00388   /// Set timer queue.
00389   void timer_queue (TIMER_QUEUE *timer_queue);
00390 
00391   /**
00392    * Get the event handle.
00393    * It is a no-op in POSIX platforms and it returns
00394    * ACE_INVALID_HANDLE.
00395    */
00396   ACE_HANDLE get_handle (void) const;
00397 
00398   /// Get the implementation class.
00399   ACE_Proactor_Impl *implementation (void) const;
00400 
00401   // = Factory methods for the operations
00402 
00403   // Note that the user does not have to use or know about these
00404   // methods.
00405 
00406   /// Create the correct implementation class for doing
00407   /// Asynch_Read_Stream.
00408   ACE_Asynch_Read_Stream_Impl *create_asynch_read_stream (void);
00409 
00410   /// Create the correct implementation class for doing
00411   /// Asynch_Write_Stream.
00412   ACE_Asynch_Write_Stream_Impl *create_asynch_write_stream (void);
00413 
00414   /// Create the correct implementation class for doing
00415   /// Asynch_Read_File.
00416   ACE_Asynch_Read_File_Impl *create_asynch_read_file (void);
00417 
00418   /// Create the correct implementation class for doing
00419   /// Asynch_Write_File.
00420   ACE_Asynch_Write_File_Impl *create_asynch_write_file (void);
00421 
00422   /// Create the correct implementation class for doing Asynch_Accept.
00423   ACE_Asynch_Accept_Impl *create_asynch_accept (void);
00424 
00425   /// Create the correct implementation class for doing Asynch_Connect.
00426   ACE_Asynch_Connect_Impl *create_asynch_connect (void);
00427 
00428   /// Create the correct implementation class for doing
00429   /// Asynch_Transmit_File.
00430   ACE_Asynch_Transmit_File_Impl *create_asynch_transmit_file (void);
00431 
00432   /// Create the correct implementation class for doing
00433   /// Asynch_Read_Dgram.
00434   ACE_Asynch_Read_Dgram_Impl *create_asynch_read_dgram (void);
00435 
00436   /// Create the correct implementation class for doing
00437   /// Asynch_Write_Dgram.
00438   ACE_Asynch_Write_Dgram_Impl *create_asynch_write_dgram (void);
00439 
00440   // = Factory methods for the results
00441 
00442   // Note that the user does not have to use or know about these
00443   // methods unless they want to "fake" results.
00444 
00445   /// Create the correct implementation class for
00446   /// ACE_Asynch_Read_Stream::Result class.
00447   ACE_Asynch_Read_Stream_Result_Impl *
00448     create_asynch_read_stream_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00449                                       ACE_HANDLE handle,
00450                                       ACE_Message_Block &message_block,
00451                                       u_long bytes_to_read,
00452                                       const void* act,
00453                                       ACE_HANDLE event = ACE_INVALID_HANDLE,
00454                                       int priority = 0,
00455                                       int signal_number = ACE_SIGRTMIN);
00456 
00457   /// Create the correct implementation class for
00458   /// ACE_Asynch_Write_Stream::Result.
00459   ACE_Asynch_Write_Stream_Result_Impl *
00460     create_asynch_write_stream_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00461                                        ACE_HANDLE handle,
00462                                        ACE_Message_Block &message_block,
00463                                        u_long bytes_to_write,
00464                                        const void* act,
00465                                        ACE_HANDLE event = ACE_INVALID_HANDLE,
00466                                        int priority = 0,
00467                                        int signal_number = ACE_SIGRTMIN);
00468 
00469   /// Create the correct implementation class for
00470   /// ACE_Asynch_Read_File::Result.
00471   ACE_Asynch_Read_File_Result_Impl *
00472     create_asynch_read_file_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00473                                     ACE_HANDLE handle,
00474                                     ACE_Message_Block &message_block,
00475                                     u_long bytes_to_read,
00476                                     const void* act,
00477                                     u_long offset,
00478                                     u_long offset_high,
00479                                     ACE_HANDLE event = ACE_INVALID_HANDLE,
00480                                     int priority = 0,
00481                                     int signal_number = ACE_SIGRTMIN);
00482 
00483   /// Create the correct implementation class for
00484   /// ACE_Asynch_Write_File::Result.
00485   ACE_Asynch_Write_File_Result_Impl *
00486     create_asynch_write_file_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00487                                      ACE_HANDLE handle,
00488                                      ACE_Message_Block &message_block,
00489                                      u_long bytes_to_write,
00490                                      const void* act,
00491                                      u_long offset,
00492                                      u_long offset_high,
00493                                      ACE_HANDLE event = ACE_INVALID_HANDLE,
00494                                      int priority = 0,
00495                                      int signal_number = ACE_SIGRTMIN);
00496 
00497   /// Create the correct implementation class for
00498   /// ACE_Asynch_Read_Dgram::Result.
00499   ACE_Asynch_Read_Dgram_Result_Impl *
00500     create_asynch_read_dgram_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00501                                      ACE_HANDLE handle,
00502                                      ACE_Message_Block *message_block,
00503                                      size_t bytes_to_read,
00504                                      int flags,
00505                                      int protocol_family,
00506                                      const void* act,
00507                                      ACE_HANDLE event = ACE_INVALID_HANDLE,
00508                                      int priority = 0,
00509                                      int signal_number = ACE_SIGRTMIN);
00510 
00511   /// Create the correct implementation class for
00512   /// ACE_Asynch_Write_Dgram::Result.
00513   ACE_Asynch_Write_Dgram_Result_Impl *
00514     create_asynch_write_dgram_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00515                                       ACE_HANDLE handle,
00516                                       ACE_Message_Block *message_block,
00517                                       size_t bytes_to_write,
00518                                       int flags,
00519                                       const void* act,
00520                                       ACE_HANDLE event = ACE_INVALID_HANDLE,
00521                                       int priority = 0,
00522                                       int signal_number = ACE_SIGRTMIN);
00523 
00524   /// Create the correct implementation class for ACE_Asynch_Accept::Result.
00525   ACE_Asynch_Accept_Result_Impl *
00526     create_asynch_accept_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00527                                  ACE_HANDLE listen_handle,
00528                                  ACE_HANDLE accept_handle,
00529                                  ACE_Message_Block &message_block,
00530                                  u_long bytes_to_read,
00531                                  const void* act,
00532                                  ACE_HANDLE event = ACE_INVALID_HANDLE,
00533                                  int priority = 0,
00534                                  int signal_number = ACE_SIGRTMIN);
00535 
00536   /// Create the correct implementation class for ACE_Asynch_Connect::Result
00537   ACE_Asynch_Connect_Result_Impl *
00538     create_asynch_connect_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00539                                   ACE_HANDLE  connect_handle,
00540                                   const void* act,
00541                                   ACE_HANDLE event = ACE_INVALID_HANDLE,
00542                                   int priority = 0,
00543                                   int signal_number = ACE_SIGRTMIN);
00544 
00545   /// Create the correct implementation class for
00546   /// ACE_Asynch_Transmit_File::Result.
00547   ACE_Asynch_Transmit_File_Result_Impl *
00548     create_asynch_transmit_file_result (ACE_Handler::Proxy_Ptr &handler_proxy,
00549                                         ACE_HANDLE socket,
00550                                         ACE_HANDLE file,
00551                                         ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer,
00552                                         u_long bytes_to_write,
00553                                         u_long offset,
00554                                         u_long offset_high,
00555                                         u_long bytes_per_send,
00556                                         u_long flags,
00557                                         const void *act,
00558                                         ACE_HANDLE event = ACE_INVALID_HANDLE,
00559                                         int priority = 0,
00560                                         int signal_number = ACE_SIGRTMIN);
00561 
00562   /**
00563    * Create a timer result object which can be used with the Timer
00564    * mechanism of the Proactor.
00565    * If <signal_number> is -1, <POSIX_SIG_Proactor> will create a
00566    * Timer object with a meaningful signal number, choosing the
00567    * largest signal number from the signal mask of the Proactor.
00568    */
00569   ACE_Asynch_Result_Impl *
00570     create_asynch_timer (ACE_Handler::Proxy_Ptr &handler_proxy,
00571                          const void *act,
00572                          const ACE_Time_Value &tv,
00573                          ACE_HANDLE event = ACE_INVALID_HANDLE,
00574                          int priority = 0,
00575                          int signal_number = ACE_SIGRTMIN);
00576 
00577 protected:
00578 
00579   /**
00580    * Post <how_many> completions to the completion port so that all
00581    * threads can wake up. This is used in conjunction with the
00582    * <run_event_loop>.
00583    */
00584   static int post_wakeup_completions (int how_many);
00585 
00586   /**
00587    * Post <how_many> completions to the completion port so that all
00588    * threads can wake up. This is used in conjunction with the
00589    * <proactor_run_event_loop>.
00590    */
00591   int proactor_post_wakeup_completions (int how_many);
00592 
00593   /// Set the implementation class.
00594   void implementation (ACE_Proactor_Impl *implementation);
00595 
00596   /// Delegation/implementation class that all methods will be
00597   /// forwarded to.
00598   ACE_Proactor_Impl *implementation_;
00599 
00600   /// Flag used to indicate whether we are responsible for cleaning up
00601   /// the implementation instance.
00602   int delete_implementation_;
00603 
00604   /// Pointer to a process-wide <ACE_Proactor>.
00605   static ACE_Proactor *proactor_;
00606 
00607   /// Must delete the <proactor_> if non-0.
00608   static int delete_proactor_;
00609 
00610   /// Handles timeout events.
00611   ACE_Proactor_Timer_Handler *timer_handler_;
00612 
00613   /// This will manage the thread in the Timer_Handler.
00614   ACE_Thread_Manager thr_mgr_;
00615 
00616   /// Timer Queue.
00617   TIMER_QUEUE *timer_queue_;
00618 
00619   /// Flag on whether to delete the timer queue.
00620   int delete_timer_queue_;
00621 
00622   /// Terminate the proactor event loop.
00623   sig_atomic_t end_event_loop_;
00624 
00625   /// Number of threads in the event loop.
00626   sig_atomic_t event_loop_thread_count_;
00627 
00628   /// Mutex to protect work with lists.
00629   ACE_SYNCH_MUTEX mutex_;
00630 
00631 
00632 private:
00633   /// Deny access since member-wise won't work...
00634   ACE_Proactor (const ACE_Proactor &);
00635   ACE_Proactor &operator= (const ACE_Proactor &);
00636 };
00637 
00638 ACE_END_VERSIONED_NAMESPACE_DECL
00639 
00640 #  if defined (__ACE_INLINE__)
00641 #    include "ace/Proactor.inl"
00642 #  endif /* __ACE_INLINE__ */
00643 
00644 #else /* NOT WIN32 or POSIX with AIO features. */
00645 
00646 #  include "ace/os_include/os_stddef.h"
00647 #  include "ace/os_include/os_signal.h"
00648 
00649 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00650 
00651 class ACE_Time_Value;
00652 
00653 class ACE_Export ACE_Proactor
00654 {
00655 public:
00656   class Timer_Queue {};
00657   ACE_Proactor (size_t /* number_of_threads */ = 0,
00658                 Timer_Queue * /* tq */ = 0) {}
00659   ~ACE_Proactor (void) {}
00660   int handle_events (void) { return -1; }
00661   int handle_events (ACE_Time_Value &) { return -1; }
00662 
00663   /// Placeholder to enable compilation on non-Win32 platforms
00664   static ACE_Proactor *instance (size_t threads = 0);
00665 
00666   /// Placeholder to enable compilation on non-Win32 platforms
00667   static ACE_Proactor *instance (ACE_Proactor *);
00668 
00669   /// Placeholder to enable compilation on non-Win32 platforms
00670   static void close_singleton (void);
00671 
00672   /// Placeholder to enable compilation on non-Win32 platforms
00673   static int run_event_loop (void);
00674 
00675   /// Placeholder to enable compilation on non-Win32 platforms
00676   static int run_event_loop (ACE_Time_Value &tv);
00677 
00678   /// Placeholder to enable compilation on non-Win32 platforms
00679   static int end_event_loop (void);
00680 
00681   /// Placeholder to enable compilation on non-Win32 platforms
00682   static sig_atomic_t event_loop_done (void);
00683 };
00684 
00685 ACE_END_VERSIONED_NAMESPACE_DECL
00686 
00687 #endif /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS*/
00688 
00689 #include /**/ "ace/post.h"
00690 
00691 #endif /* ACE_PROACTOR_H */

Generated on Thu Nov 9 09:42:00 2006 for ACE by doxygen 1.3.6