Reactor.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Reactor.h
00006  *
00007  *  $Id: Reactor.h 81138 2008-03-28 09:18:15Z johnnyw $
00008  *
00009  *  @author Irfan Pyarali <irfan@cs.wustl.edu>
00010  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_REACTOR_H
00015 #define ACE_REACTOR_H
00016 
00017 #include /**/ "ace/pre.h"
00018 
00019 // Timer Queue is a complicated template class. A simple forward
00020 // declaration will not work.
00021 #include "ace/Timer_Queuefwd.h"
00022 
00023 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00024 # pragma once
00025 #endif /* ACE_LACKS_PRAGMA_ONCE */
00026 
00027 // Contains the timer related interface for the Reactor.
00028 #include "ace/Reactor_Timer_Interface.h"
00029 
00030 // Event_Handler.h contains the definition of ACE_Reactor_Mask
00031 #include "ace/Event_Handler.h"
00032 
00033 // Get ACE_Time_Value in
00034 #include "ace/Time_Value.h"
00035 
00036 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 class ACE_Reactor_Impl;
00039 class ACE_Handle_Set;
00040 class ACE_Sig_Action;
00041 class ACE_Sig_Handler;
00042 class ACE_Sig_Set;
00043 
00044 /*
00045  * Hook to specialize the Reactor implementation with the concrete
00046  * Reactor type, for exmaple, select, thread pool reactor known
00047  * at compile time.
00048  */
00049 //@@ REACTOR_SPL_INCLUDE_FORWARD_DECL_ADD_HOOK
00050 
00051 /**
00052  * @class ACE_Reactor
00053  *
00054  * @brief The responsibility of this class is to forward all methods to
00055  * its delegation/implementation class, e.g.,
00056  * ACE_Select_Reactor or ACE_WFMO_Reactor.
00057  */
00058 class ACE_Export ACE_Reactor : public ACE_Reactor_Timer_Interface
00059 {
00060 public:
00061   /// Operations on the "ready" mask and the "dispatch" mask.
00062   enum
00063   {
00064     /// Retrieve current value of the the "ready" mask or the
00065     /// "dispatch" mask.
00066     GET_MASK = 1,
00067     /// Set value of bits to new mask (changes the entire mask).
00068     SET_MASK = 2,
00069     /// Bitwise "or" the value into the mask (only changes enabled
00070     /// bits).
00071     ADD_MASK = 3,
00072     /// Bitwise "and" the negation of the value out of the mask (only
00073     /// changes enabled bits).
00074     CLR_MASK = 4
00075   };
00076 
00077   /**
00078    * You can specify a hook function to event-handling methods that will
00079    * be called after each iteration of event handling.  If the hook function
00080    * returns a non-zero value, the event loop will immediately resume
00081    * waiting for the next event(s) to process without checking the error
00082    * status of the just-completed iteration of event handling or the
00083    * end-of-loop indication. If the hook function returns 0, the event
00084    * handling error status and the end-of-loop indication will be checked
00085    * as normal, just as if there is no hook function specified.
00086    */
00087   typedef int (*REACTOR_EVENT_HOOK)(ACE_Reactor *);
00088 
00089   /// Get pointer to a process-wide ACE_Reactor.
00090   static ACE_Reactor *instance (void);
00091 
00092   /**
00093    * Set pointer to a process-wide ACE_Reactor and return existing
00094    * pointer.  If @a delete_reactor == true then we'll delete the Reactor
00095    * at destruction time.
00096    */
00097   static ACE_Reactor *instance (ACE_Reactor *, bool delete_reactor = false);
00098 
00099   /// Delete the dynamically allocated Singleton
00100   static void close_singleton (void);
00101 
00102   /// Name of the dll in which the dll lives.
00103   static const ACE_TCHAR *dll_name (void);
00104 
00105   /// Name of the component--ACE_Reactor in this case.
00106   static const ACE_TCHAR *name (void);
00107 
00108   // = Singleton reactor event loop management methods.
00109 
00110   // Note that these method ONLY work on the "Singleton Reactor,"
00111   // i.e., the one returned from <ACE_Reactor::instance>.
00112   /**
00113    * Run the event loop until the
00114    * <ACE_Reactor::handle_events/ACE_Reactor::alertable_handle_events>
00115    * method returns -1 or the <end_event_loop> method is invoked.
00116    * Note that this method can only be used by the singleton
00117    * <ACE_Reactor::instance>.  Thus, to run another reactor use
00118    * <ACE_Reactor::run_reactor_event_loop>.
00119    *
00120    * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
00121    */
00122   static int run_event_loop (void);
00123   static int run_alertable_event_loop (void);
00124 
00125   /**
00126    * Run the event loop until the <ACE_Reactor::handle_events> or
00127    * <ACE_Reactor::alertable_handle_events> methods returns -1, the
00128    * <end_event_loop> method is invoked, or the ACE_Time_Value
00129    * expires.  Note that this method can only be used by the singleton
00130    * <ACE_Reactor::instance>.  Thus, to run another reactor use
00131    * <ACE_Reactor::run_reactor_event_loop>.
00132    *
00133    * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
00134    */
00135   static int run_event_loop (ACE_Time_Value &tv);
00136   static int run_alertable_event_loop (ACE_Time_Value &tv);
00137 
00138   /**
00139    * Instruct the <ACE_Reactor::instance> to terminate its event loop
00140    * and notifies the <ACE_Reactor::instance> so that it can wake up
00141    * and close down gracefully.  Note that this method can only be
00142    * used by the singleton <ACE_Reactor::instance>.  Thus, to
00143    * terminate another reactor, use
00144    * <ACE_Reactor::end_reactor_event_loop>.
00145    *
00146    * @deprecated Use ACE_Reactor::instance()->end_reactor_event_loop() instead
00147    */
00148   static int end_event_loop (void);
00149 
00150   /**
00151    * Report if the <ACE_Reactor::instance>'s event loop is finished.
00152    * Note that this method can only be used by the singleton
00153    * <ACE_Reactor::instance>.  Thus, to check another reactor use
00154    * <ACE_Reactor::reactor_event_loop_done>.
00155    *
00156    * @deprecated Use ACE_Reactor::instance()->reactor_event_loop_done() instead
00157    */
00158   static int event_loop_done (void);
00159 
00160   /**
00161    * Resets the <ACE_Reactor::end_event_loop_> static so that the
00162    * <run_event_loop> method can be restarted.  Note that this method
00163    * can only be used by the singleton <ACE_Reactor::instance>.  Thus,
00164    * to reset another reactor use <ACE_Reactor::reset_reactor_event_loop>.
00165    *
00166    * @deprecated Use ACE_Reactor::instance()->reset_reactor_event_loop()
00167    * instead
00168    */
00169   static void reset_event_loop (void);
00170 
00171   /**
00172    * The singleton reactor is used by the ACE_Service_Config.
00173    * Therefore, we must check for the reconfiguration request and
00174    * handle it after handling an event.
00175    */
00176   static int check_reconfiguration (ACE_Reactor *);
00177 
00178   // = Reactor event loop management methods.
00179 
00180   // These methods work with an instance of a reactor.
00181   /**
00182    * Run the event loop until the
00183    * <ACE_Reactor::handle_events/ACE_Reactor::alertable_handle_events>
00184    * method returns -1 or the <end_reactor_event_loop> method is invoked.
00185    */
00186   int run_reactor_event_loop (REACTOR_EVENT_HOOK = 0);
00187   int run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK = 0);
00188 
00189   /**
00190    * Run the event loop until the <ACE_Reactor::handle_events> or
00191    * <ACE_Reactor::alertable_handle_events> methods returns -1, the
00192    * <end_reactor_event_loop> method is invoked, or the ACE_Time_Value
00193    * expires.
00194    */
00195   int run_reactor_event_loop (ACE_Time_Value &tv,
00196                               REACTOR_EVENT_HOOK = 0);
00197   int run_alertable_reactor_event_loop (ACE_Time_Value &tv,
00198                                         REACTOR_EVENT_HOOK = 0);
00199 
00200   /**
00201    * Instruct the Reactor to terminate its event loop and notifies the
00202    * Reactor so that it can wake up and deactivate
00203    * itself. Deactivating the Reactor would allow the Reactor to be
00204    * shutdown gracefully. Internally the Reactor calls deactivate ()
00205    * on the underlying implementation.
00206    * Any queued notifications remain queued on return from this method.
00207    * If the event loop is restarted in the future, the notifications
00208    * will be dispatched then. If the reactor is closed or deleted without
00209    * further dispatching, the notifications will be lost.
00210    */
00211   int end_reactor_event_loop (void);
00212 
00213   /// Indicate if the Reactor's event loop has been ended.
00214   int reactor_event_loop_done (void);
00215 
00216   /// Resets the <ACE_Reactor::end_event_loop_> static so that the
00217   /// <run_event_loop> method can be restarted.
00218   void reset_reactor_event_loop (void);
00219 
00220   /**
00221    * Create the Reactor using @a implementation.  The flag
00222    * @a delete_implementation tells the Reactor whether or not to
00223    * delete the @a implementation on destruction.
00224    */
00225   ACE_Reactor (ACE_Reactor_Impl *implementation = 0,
00226                bool delete_implementation = false);
00227 
00228   /// Close down and release all resources.
00229   /**
00230    * Any notifications that remain queued on this reactor instance are
00231    * lost.
00232    */
00233   virtual ~ACE_Reactor (void);
00234 
00235   /**
00236    * Initialize the ACE_Reactor to manage <max_number_of_handles>.
00237    * If <restart> is non-0 then the ACE_Reactor's <handle_events>
00238    * method will be restarted automatically when <EINTR> occurs.  If
00239    * <signal_handler> or <timer_queue> are non-0 they are used as the
00240    * signal handler and timer queue, respectively.
00241    */
00242   int open (size_t max_number_of_handles,
00243             int restart = 0,
00244             ACE_Sig_Handler *signal_handler = 0,
00245             ACE_Timer_Queue *timer_queue = 0);
00246 
00247   /// Use a user specified signal handler instead.
00248   int set_sig_handler (ACE_Sig_Handler *signal_handler);
00249 
00250   /// Set a user-specified timer queue.
00251   int timer_queue (ACE_Timer_Queue *tq);
00252 
00253   /// Return the current ACE_Timer_Queue.
00254   ACE_Timer_Queue *timer_queue (void) const;
00255 
00256   /// Close down and release all resources.
00257   int close (void);
00258 
00259   // = Event loop drivers.
00260 
00261   /**
00262    * Returns non-zero if there are I/O events "ready" for dispatching,
00263    * but does not actually dispatch the event handlers.  By default,
00264    * don't block while checking this, i.e., "poll".
00265    */
00266   int work_pending (const ACE_Time_Value &max_wait_time = ACE_Time_Value::zero);
00267 
00268   /**
00269    * This event loop driver blocks for up to @a max_wait_time before
00270    * returning.  It will return earlier if events occur.  Note that
00271    * @a max_wait_time can be 0, in which case this method blocks
00272    * indefinitely until events occur.
00273    *
00274    * @a max_wait_time is decremented to reflect how much time this call
00275    * took.  For instance, if a time value of 3 seconds is passed to
00276    * handle_events and an event occurs after 2 seconds,
00277    * @a max_wait_time will equal 1 second.  This can be used if an
00278    * application wishes to handle events for some fixed amount of
00279    * time.
00280    *
00281    * Returns the total number of timers and I/O ACE_Event_Handlers
00282    * that were dispatched, 0 if the @a max_wait_time elapsed without
00283    * dispatching any handlers, or -1 if an error occurs.
00284    *
00285    * The only difference between <alertable_handle_events> and
00286    * <handle_events> is that in the alertable case, the eventloop will
00287    * return when the system queues an I/O completion routine or an
00288    * Asynchronous Procedure Call.
00289    */
00290   int handle_events (ACE_Time_Value *max_wait_time = 0);
00291   int alertable_handle_events (ACE_Time_Value *max_wait_time = 0);
00292 
00293   /**
00294    * This method is just like the one above, except the
00295    * @a max_wait_time value is a reference and can therefore never be
00296    * NULL.
00297    *
00298    * The only difference between <alertable_handle_events> and
00299    * <handle_events> is that in the alertable case, the eventloop will
00300    * return when the system queues an I/O completion routine or an
00301    * Asynchronous Procedure Call.
00302    */
00303   int handle_events (ACE_Time_Value &max_wait_time);
00304   int alertable_handle_events (ACE_Time_Value &max_wait_time);
00305 
00306   // = Register and remove handlers.
00307 
00308   /**
00309    * Register handler for I/O events.
00310    *
00311    * A handler can be associated with multiple handles. A handle
00312    * cannot be associated with multiple handlers.
00313    *
00314    * The handle will come from ACE_Event_Handler::get_handle().
00315    *
00316    * Reactor will call ACE_Event_Handler::add_reference() for a new
00317    * handler/handle pair.
00318    *
00319    * If this handler/handle pair has already been registered, any new
00320    * masks specified will be added. In this case,
00321    * ACE_Event_Handler::add_reference() will not be called.
00322    *
00323    * If the registered handler is currently suspended, it will remain
00324    * suspended.  When the handler is resumed, it will have the
00325    * existing masks plus any masks added through this call. Handlers
00326    * do not have partial suspensions.
00327    */
00328   int register_handler (ACE_Event_Handler *event_handler,
00329                         ACE_Reactor_Mask mask);
00330 
00331   /**
00332    * Register handler for I/O events.
00333    *
00334    * Same as register_handler(ACE_Event_Handler*,ACE_Reactor_Mask),
00335    * except handle is explicitly specified.
00336    */
00337   int register_handler (ACE_HANDLE io_handle,
00338                         ACE_Event_Handler *event_handler,
00339                         ACE_Reactor_Mask mask);
00340 
00341 #if defined (ACE_WIN32)
00342 
00343   /**
00344    * Register handler for OS events.
00345    *
00346    * Register an @a event_handler that will be notified when
00347    * <event_handle> is signaled.  This will call back its
00348    * <handle_signal> hook method.
00349    *
00350    * Reactor will call ACE_Event_Handler::add_reference() for a new
00351    * handler/handle pair.
00352    *
00353    * This interface is only available Win32 platforms because
00354    * ACE_HANDLE is an int on non-Win32 platforms and compilers are not
00355    * able to tell the difference between
00356    * register_handler(ACE_Event_Handler*,ACE_Reactor_Mask) and
00357    * register_handler(ACE_Event_Handler*,ACE_HANDLE).
00358    */
00359   int register_handler (ACE_Event_Handler *event_handler,
00360                         ACE_HANDLE event_handle = ACE_INVALID_HANDLE);
00361 
00362 #endif /* ACE_WIN32 */
00363 
00364   /**
00365    * Register handler for I/O events.
00366    *
00367    * Similar to
00368    * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
00369    * except that the user gets to specify the event handle that will
00370    * be used for this registration.  This only applies to Reactors
00371    * that use event handles for I/O registrations.
00372    */
00373   int register_handler (ACE_HANDLE event_handle,
00374                         ACE_HANDLE io_handle,
00375                         ACE_Event_Handler *event_handler,
00376                         ACE_Reactor_Mask mask);
00377 
00378   /**
00379    * Register handler for multiple I/O events.
00380    *
00381    * Shorthand for calling
00382    * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
00383    * multiple times for the same @a event_handler and @a masks but
00384    * different <handles>.
00385    */
00386   int register_handler (const ACE_Handle_Set &handles,
00387                         ACE_Event_Handler *event_handler,
00388                         ACE_Reactor_Mask masks);
00389 
00390   /**
00391    * Register handler for signals.
00392    *
00393    * Register @a new_sh to handle the signal @a signum using the
00394    * @a new_disp.  Returns the @a old_sh that was previously registered
00395    * (if any), along with the @a old_disp of the signal handler.
00396    *
00397    * Reactor will call ACE_Event_Handler::add_reference() on @a new_sh
00398    * and ACE_Event_Handler::remove_reference() on @a old_sh.
00399    */
00400   int register_handler (int signum,
00401                         ACE_Event_Handler *new_sh,
00402                         ACE_Sig_Action *new_disp = 0,
00403                         ACE_Event_Handler **old_sh = 0,
00404                         ACE_Sig_Action *old_disp = 0);
00405 
00406   /**
00407    * Register handler for multiple signals.
00408    *
00409    * Shorthand for calling
00410    * register_handler(int,ACE_Event_Handler*,ACE_Sig_Action*,ACE_Event_Handler**,ACE_Sig_Action*)
00411    * multiple times for the same @a event_handler and @a sig_action but
00412    * different <signals>.
00413    */
00414   int register_handler (const ACE_Sig_Set &sigset,
00415                         ACE_Event_Handler *event_handler,
00416                         ACE_Sig_Action *sig_action = 0);
00417 
00418   /**
00419    * Remove @a masks from @a handle registration.
00420    *
00421    * For I/O handles, @a masks are removed from the Reactor.  Unless
00422    * @a masks includes ACE_Event_Handler::DONT_CALL,
00423    * ACE_Event_Handler::handle_close() will be called with the @a masks
00424    * that have been removed.  If all masks have been removed,
00425    * ACE_Event_Handler::remove_reference() will be called.
00426    *
00427    * For OS handles, the @a handle is removed from the Reactor.  Unless
00428    * @a masks includes ACE_Event_Handler::DONT_CALL,
00429    * ACE_Event_Handler::handle_close() will be called with
00430    * ACE_Event_Handler::NULL_MASK.
00431    * ACE_Event_Handler::remove_reference() will also be called.
00432    */
00433   int remove_handler (ACE_HANDLE handle,
00434                       ACE_Reactor_Mask masks);
00435 
00436   /**
00437    * Remove @a masks from @a event_handler registration.
00438    *
00439    * Same as remove_handler(ACE_HANDLE,ACE_Reactor_Mask), except
00440    * @a handle comes from ACE_Event_Handler::get_handle().
00441    */
00442   int remove_handler (ACE_Event_Handler *event_handler,
00443                       ACE_Reactor_Mask masks);
00444 
00445   /**
00446    * Remove @a masks from multiple <handle> registrations.
00447    *
00448    * Shorthand for calling remove_handler(ACE_HANDLE,ACE_Reactor_Mask)
00449    * multiple times for the same @a masks but different @a handles.
00450    */
00451   int remove_handler (const ACE_Handle_Set &handles,
00452                       ACE_Reactor_Mask masks);
00453 
00454   /**
00455    * Remove signal handler registration.
00456    *
00457    * Remove the ACE_Event_Handler currently associated with @a signum.
00458    * Install the new disposition (if given) and return the previous
00459    * disposition (if desired by the caller).
00460    *
00461    * ACE_Event_Handler::handle_close() will be called with
00462    * @c ACE_Event_Handler::SIGNAL_MASK.
00463    * ACE_Event_Handler::remove_reference() will also be called.
00464    */
00465   int remove_handler (int signum,
00466                       ACE_Sig_Action *new_disp,
00467                       ACE_Sig_Action *old_disp = 0,
00468                       int sigkey = -1);
00469 
00470   /**
00471    * Remove multiple signal handler registrations.
00472    *
00473    * Shorthand for calling
00474    * remove_handler(int,ACE_Sig_Action*,ACE_Sig_Action*,int) multiple
00475    * times for every signal in @a sigset.
00476    */
00477   int remove_handler (const ACE_Sig_Set &sigset);
00478 
00479   // = Suspend and resume Handlers.
00480 
00481   /**
00482    * Suspend @a handle temporarily.
00483    */
00484   int suspend_handler (ACE_HANDLE handle);
00485 
00486   /**
00487    * Suspend @a event_handler temporarily.
00488    *
00489    * Handle is obtained from ACE_Event_Handler::get_handle().
00490    */
00491   int suspend_handler (ACE_Event_Handler *event_handler);
00492 
00493   /**
00494    * Suspend @a handles temporarily.
00495    *
00496    * Shorthand for calling suspend_handler(ACE_HANDLE) with multiple
00497    * @a handles.
00498    */
00499   int suspend_handler (const ACE_Handle_Set &handles);
00500 
00501   /**
00502    * Suspend all registered handles temporarily.
00503    */
00504   int suspend_handlers (void);
00505 
00506   /**
00507    * Resume @a handle.
00508    */
00509   int resume_handler (ACE_HANDLE handle);
00510 
00511   /**
00512    * Resume @a event_handler.
00513    *
00514    * Handle is obtained from ACE_Event_Handler::get_handle().
00515    */
00516   int resume_handler (ACE_Event_Handler *event_handler);
00517 
00518   /**
00519    * Resume @a handles.
00520    *
00521    * Shorthand for calling resume_handler(ACE_HANDLE) with multiple
00522    * <handles>.
00523    */
00524   int resume_handler (const ACE_Handle_Set &handles);
00525 
00526   /**
00527    * Resume all registered handles.
00528    */
00529   int resume_handlers (void);
00530 
00531   /// Does the reactor allow the application to resume the handle on
00532   /// its own ie. can it pass on the control of handle resumption to
00533   /// the application. A positive value indicates that the handlers
00534   /// are application resumable. A value of 0 indicates otherwise.
00535   int resumable_handler (void);
00536 
00537   // = Timer management.
00538 
00539   /**
00540    * Schedule a timer event.
00541    *
00542    * Schedule a timer event that will expire after an <delay> amount
00543    * of time.  The return value of this method, a timer_id value,
00544    * uniquely identifies the @a event_handler in the ACE_Reactor's
00545    * internal list of timers.  This timer_id value can be used to
00546    * cancel the timer with the cancel_timer() call.
00547    *
00548    * Reactor will call ACE_Event_Handler::add_reference() on the
00549    * handler.  After the timeout occurs and
00550    * ACE_Event_Handler::handle_timeout() has completed, the handler
00551    * will be implicitly removed from the Reactor and
00552    * ACE_Event_Handler::remove_reference() will be called.
00553    *
00554    * @see cancel_timer()
00555    * @see reset_timer_interval()
00556    *
00557    * @param event_handler Event handler to schedule on reactor
00558    * @param arg Argument passed to the handle_timeout() method of
00559    * event_handler
00560    * @param delay Time interval after which the timer will expire
00561    * @param interval Time interval after which the timer will be automatically
00562    * rescheduled
00563    * @return -1 on failure, a timer_id value on success
00564    */
00565   virtual long schedule_timer (ACE_Event_Handler *event_handler,
00566                                const void *arg,
00567                                const ACE_Time_Value &delay,
00568                                const ACE_Time_Value &interval =
00569                                 ACE_Time_Value::zero);
00570 
00571   /**
00572    * Reset recurring timer interval.
00573    *
00574    * Resets the interval of the timer represented by @a timer_id to
00575    * @a interval, which is specified in relative time to the current
00576    * <gettimeofday>.  If @a interval is equal to
00577    * ACE_Time_Value::zero, the timer will become a non-rescheduling
00578    * timer.  Returns 0 if successful, -1 if not.
00579    *
00580    * This change will not take effect until the next timeout.
00581    */
00582   virtual int reset_timer_interval (long timer_id,
00583                                     const ACE_Time_Value &interval);
00584 
00585   /**
00586    * Cancel timer.
00587    *
00588    * Cancel timer associated with @a timer_id that was returned from
00589    * the schedule_timer() method.  If arg is non-NULL then it will be
00590    * set to point to the ``magic cookie'' argument passed in when the
00591    * handler was registered.  This makes it possible to free up the
00592    * memory and avoid memory leaks.  Returns 1 if cancellation
00593    * succeeded and 0 if the @a timer_id wasn't found.
00594    *
00595    * On successful cancellation, ACE_Event_Handler::handle_close()
00596    * will be called with ACE_Event_Handler::TIMER_MASK.
00597    * ACE_Event_Handler::remove_reference() will also be called.
00598    */
00599   virtual int cancel_timer (long timer_id,
00600                             const void **arg = 0,
00601                             int dont_call_handle_close = 1);
00602 
00603   /**
00604    * Cancel all timers associated with event handler.
00605    *
00606    * Shorthand for calling cancel_timer(long,const void **,int)
00607    * multiple times for all timer associated with @a event_handler.
00608    *
00609    * ACE_Event_Handler::handle_close() will be called with
00610    * ACE_Event_Handler::TIMER_MASK only once irrespective of the
00611    * number of timers associated with the event handler.
00612    * ACE_Event_Handler::remove_reference() will also be called once
00613    * for every timer associated with the event handler.
00614    *
00615    * Returns number of handlers cancelled.
00616    */
00617   virtual int cancel_timer (ACE_Event_Handler *event_handler,
00618                             int dont_call_handle_close = 1);
00619 
00620   // = High-level Event_Handler scheduling operations
00621 
00622   /// Add @a masks_to_be_added to the @a event_handler's entry.
00623   /// @a event_handler must already have been registered.
00624   /// Note that this call does not cause the Reactor to re-examine
00625   /// its set of handlers - the new masks will be noticed the next
00626   /// time the Reactor waits for activity. If there is no other
00627   /// activity expected, or you need immediate re-examination of the
00628   /// wait masks, either call ACE_Reactor::notify after this call, or
00629   /// use ACE_Reactor::register_handler instead.
00630   int schedule_wakeup (ACE_Event_Handler *event_handler,
00631                        ACE_Reactor_Mask masks_to_be_added);
00632 
00633   /// Add @a masks_to_be_added to the @a handle's entry.  <event_handler>
00634   /// associated with @a handle must already have been registered.
00635   /// Note that this call does not cause the Reactor to re-examine
00636   /// its set of handlers - the new masks will be noticed the next
00637   /// time the Reactor waits for activity. If there is no other
00638   /// activity expected, or you need immediate re-examination of
00639   /// the wait masks, either call ACE_Reactor::notify after this call,
00640   /// or use ACE_Reactor::register_handler instead.
00641   int schedule_wakeup (ACE_HANDLE handle,
00642                        ACE_Reactor_Mask masks_to_be_added);
00643 
00644   /// Clear @a masks_to_be_cleared from the @a event_handler's entry.
00645   /// Note that this call does not cause the Reactor to re-examine
00646   /// its set of handlers - the new masks will be noticed the next
00647   /// time the Reactor waits for activity. If there is no other
00648   /// activity expected, or you need immediate re-examination of
00649   /// the wait masks, either call ACE_Reactor::notify after this
00650   /// call, or use ACE_Reactor::register_handler instead.
00651   int cancel_wakeup (ACE_Event_Handler *event_handler,
00652                      ACE_Reactor_Mask masks_to_be_cleared);
00653 
00654   /// Clear @a masks_to_be_cleared from the <handle>'s entry.
00655   /// Note that this call does not cause the Reactor to re-examine
00656   /// its set of handlers - the new masks will be noticed the next
00657   /// time the Reactor waits for activity. If there is no other
00658   /// activity expected, or you need immediate re-examination of
00659   /// the wait masks, either call ACE_Reactor::notify after this
00660   /// call, or use ACE_Reactor::register_handler instead.
00661   int cancel_wakeup (ACE_HANDLE handle,
00662                      ACE_Reactor_Mask masks_to_be_cleared);
00663 
00664   // = Notification methods.
00665 
00666   /**
00667    * Dispatch user specified events.
00668    *
00669    * Handler will be dispatched irrespective of whether it is
00670    * registered, not registered, or suspended in the Reactor.
00671    *
00672    * If user specified event is successfully queued,
00673    * ACE_Event_Handler::add_reference() will be called.  After the
00674    * notify occurs and the upcall to the handler completes, the
00675    * handler will be implicitly removed from the Reactor and
00676    * ACE_Event_Handler::remove_reference() will be called.  No other
00677    * upcall reference counting is done.
00678    *
00679    * For I/O or OS events, the upcall is invoked with an
00680    * ACE_INVALID_HANDLE.
00681    *
00682    * For timer events, the upcall is invoked with a null ACT.
00683    *
00684    * @param event_handler: IN - Handler on which the event will be
00685    * dispatched.
00686    * @param masks: IN - Events to be dispatched - multiple events can
00687    * be OR'd together.
00688    * @param timeout: INOUT - Relative time up to which to wait for
00689    * user specified event to be queued.  If tv is 0, wait
00690    * indefinitely.  When the call returns, tv has the time remaining
00691    * after the call completes.
00692    */
00693   int notify (ACE_Event_Handler *event_handler = 0,
00694               ACE_Reactor_Mask masks = ACE_Event_Handler::EXCEPT_MASK,
00695               ACE_Time_Value *timeout = 0);
00696 
00697   /**
00698    * Set the maximum number of times that ACE_Reactor will
00699    * iterate and dispatch the ACE_Event_Handlers that are passed in
00700    * via the notify queue before breaking out of its
00701    * <ACE_Message_Queue::dequeue> loop.  By default, this is set to
00702    * -1, which means "iterate until the queue is empty."  Setting this
00703    * to a value like "1 or 2" will increase "fairness" (and thus
00704    * prevent starvation) at the expense of slightly higher dispatching
00705    * overhead.
00706    */
00707   void max_notify_iterations (int iterations);
00708 
00709   /**
00710    * Get the maximum number of times that the ACE_Reactor will
00711    * iterate and dispatch the ACE_Event_Handler's that are passed in
00712    * via the notify queue before breaking out of its
00713    * <ACE_Message_Queue::dequeue> loop.
00714    */
00715   int max_notify_iterations (void);
00716 
00717   /**
00718    * Purge any notifications pending in this reactor for the specified
00719    * ACE_Event_Handler object. If @a eh == 0, all notifications for
00720    * all handlers are removed (but not any notifications posted just
00721    * to wake up the reactor itself). Returns the number of
00722    * notifications purged.  Returns -1 on error.
00723    *
00724    * After the purging occurs, the handler will be implicitly removed
00725    * from the Reactor and ACE_Event_Handler::remove_reference() will
00726    * be called.
00727    */
00728   int purge_pending_notifications (ACE_Event_Handler *eh,
00729                                    ACE_Reactor_Mask =
00730                                             ACE_Event_Handler::ALL_EVENTS_MASK);
00731 
00732   // = Assorted helper methods.
00733 
00734   /**
00735    * Return the Event_Handler associated with @a handle.  Return 0 if
00736    * @a handle is not registered.
00737    *
00738    * Reactor will call ACE_Event_Handler::add_reference() on the
00739    * handler before returning it.
00740    */
00741   ACE_Event_Handler *find_handler (ACE_HANDLE handle);
00742 
00743   /**
00744    * Check to see if @a handle is associated with a valid Event_Handler
00745    * bound to @a mask.  Return the @c event_handler associated with this
00746    * @a handler if @a event_handler != 0.
00747    *
00748    * Reactor will call ACE_Event_Handler::add_reference() on the
00749    * handler before returning it if @a event_handler != 0.
00750    */
00751   int handler (ACE_HANDLE handle,
00752                ACE_Reactor_Mask mask,
00753                ACE_Event_Handler **event_handler = 0);
00754 
00755   /**
00756    * Check to see if @a signum is associated with a valid Event_Handler
00757    * bound to a signal.  Return the @a event_handler associated with
00758    * this @c handler if @a event_handler != 0.
00759    */
00760   int handler (int signum,
00761                ACE_Event_Handler **event_handler = 0);
00762 
00763   /// Returns true if Reactor has been successfully initialized, else
00764   /// false.
00765   int initialized (void);
00766 
00767   /// Returns the current size of the Reactor's internal descriptor
00768   /// table.
00769   size_t size (void) const;
00770 
00771   /// Returns a reference to the Reactor's internal lock.
00772   ACE_Lock &lock (void);
00773 
00774   /// Wake up all threads in waiting in the event loop
00775   void wakeup_all_threads (void);
00776 
00777   /// Transfers ownership of Reactor to the @a new_owner.
00778   int owner (ACE_thread_t new_owner,
00779              ACE_thread_t *old_owner = 0);
00780 
00781   /// Return the ID of the "owner" thread.
00782   int owner (ACE_thread_t *owner);
00783 
00784   /// Set position of the owner thread.
00785   void requeue_position (int position);
00786 
00787   /// Get position of the owner thread.
00788   int requeue_position (void);
00789 
00790   /// Get the existing restart value.
00791   int restart (void);
00792 
00793   /// Set a new value for restart and return the original value.
00794   int restart (int r);
00795 
00796   // = Low-level wait_set mask manipulation methods.
00797 
00798   /// GET/SET/ADD/CLR the dispatch mask "bit" bound with the
00799   /// @a event_handler and @a mask.
00800   int mask_ops (ACE_Event_Handler *event_handler,
00801                 ACE_Reactor_Mask mask,
00802                 int ops);
00803 
00804   /// GET/SET/ADD/CLR the dispatch MASK "bit" bound with the @a handle
00805   /// and @a mask.
00806   int mask_ops (ACE_HANDLE handle,
00807                 ACE_Reactor_Mask mask,
00808                 int ops);
00809 
00810   // = Low-level ready_set mask manipulation methods.
00811   /// GET/SET/ADD/CLR the ready "bit" bound with the @a event_handler
00812   /// and @a mask.
00813   int ready_ops (ACE_Event_Handler *event_handler,
00814                  ACE_Reactor_Mask mask,
00815                  int ops);
00816 
00817   /// GET/SET/ADD/CLR the ready "bit" bound with the <handle> and @a mask.
00818   int ready_ops (ACE_HANDLE handle,
00819                  ACE_Reactor_Mask mask,
00820                  int ops);
00821 
00822   /// Get the implementation class
00823   ACE_Reactor_Impl *implementation (void) const;
00824 
00825   /**
00826    * Returns 0, if the size of the current message has been put in
00827    * @a size returns -1, if not.  ACE_HANDLE allows the reactor to
00828    * check if the caller is valid.  Used for CLASSIX Reactor
00829    * implementation.
00830    */
00831   int current_info (ACE_HANDLE handle, size_t &msg_size);
00832 
00833   /// Return 1 if we any event associations were made by the reactor
00834   /// for the handles that it waits on, 0 otherwise.
00835   int uses_event_associations (void);
00836 
00837   /// Declare the dynamic allocation hooks.
00838   ACE_ALLOC_HOOK_DECLARE;
00839 
00840   /// Dump the state of the object.
00841   void dump (void) const;
00842 
00843 protected:
00844   /// Set the implementation class.
00845   void implementation (ACE_Reactor_Impl *implementation);
00846 
00847   /// Delegation/implementation class that all methods will be
00848   /// forwarded to.
00849   ACE_Reactor_Impl *implementation_;
00850 
00851   /// Flag used to indicate whether we are responsible for cleaning up
00852   /// the implementation instance
00853   bool delete_implementation_;
00854 
00855   /// Pointer to a process-wide ACE_Reactor singleton.
00856   static ACE_Reactor *reactor_;
00857 
00858   /// Must delete the reactor_ singleton if true.
00859   static bool delete_reactor_;
00860 
00861   /// Deny access since member-wise won't work...
00862   ACE_Reactor (const ACE_Reactor &);
00863   ACE_Reactor &operator = (const ACE_Reactor &);
00864 };
00865 
00866 ACE_END_VERSIONED_NAMESPACE_DECL
00867 
00868 
00869 #if defined (__ACE_INLINE__)
00870 #include "ace/Reactor.inl"
00871 #endif /* __ACE_INLINE__ */
00872 
00873 #include /**/ "ace/post.h"
00874 
00875 #endif /* ACE_REACTOR_H */

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7