[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Reactor.h
blobf3d2a37ae15fb648d42c5837309f165af6f2f531
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Reactor.h
7 * $Id: Reactor.h 82117 2008-06-22 17:05:12Z schmidt $
9 * @author Irfan Pyarali <irfan@cs.wustl.edu>
10 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
12 //=============================================================================
14 #ifndef ACE_REACTOR_H
15 #define ACE_REACTOR_H
17 #include /**/ "ace/pre.h"
19 // Timer Queue is a complicated template class. A simple forward
20 // declaration will not work.
21 #include "ace/Timer_Queuefwd.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 # pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 // Contains the timer related interface for the Reactor.
28 #include "ace/Reactor_Timer_Interface.h"
30 // Event_Handler.h contains the definition of ACE_Reactor_Mask
31 #include "ace/Event_Handler.h"
33 // Get ACE_Time_Value in
34 #include "ace/Time_Value.h"
36 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
38 class ACE_Reactor_Impl;
39 class ACE_Handle_Set;
40 class ACE_Sig_Action;
41 class ACE_Sig_Handler;
42 class ACE_Sig_Set;
45 * Hook to specialize the Reactor implementation with the concrete
46 * Reactor type, for exmaple, select, thread pool reactor known
47 * at compile time.
49 //@@ REACTOR_SPL_INCLUDE_FORWARD_DECL_ADD_HOOK
51 /**
52 * @class ACE_Reactor
54 * @brief This class forwards all methods to its delegation/implementation class, e.g.,
55 * ACE_Select_Reactor or ACE_WFMO_Reactor.
57 class ACE_Export ACE_Reactor : public ACE_Reactor_Timer_Interface
59 public:
60 /// Operations on the "ready" mask and the "dispatch" mask.
61 enum
63 /// Retrieve current value of the the "ready" mask or the
64 /// "dispatch" mask.
65 GET_MASK = 1,
66 /// Set value of bits to new mask (changes the entire mask).
67 SET_MASK = 2,
68 /// Bitwise "or" the value into the mask (only changes enabled
69 /// bits).
70 ADD_MASK = 3,
71 /// Bitwise "and" the negation of the value out of the mask (only
72 /// changes enabled bits).
73 CLR_MASK = 4
76 /**
77 * You can specify a hook function to event-handling methods that will
78 * be called after each iteration of event handling. If the hook function
79 * returns a non-zero value, the event loop will immediately resume
80 * waiting for the next event(s) to process without checking the error
81 * status of the just-completed iteration of event handling or the
82 * end-of-loop indication. If the hook function returns 0, the event
83 * handling error status and the end-of-loop indication will be checked
84 * as normal, just as if there is no hook function specified.
86 typedef int (*REACTOR_EVENT_HOOK)(ACE_Reactor *);
88 /// Get pointer to a process-wide ACE_Reactor.
89 static ACE_Reactor *instance (void);
91 /**
92 * Set pointer to a process-wide ACE_Reactor and return existing
93 * pointer. If @a delete_reactor == true then we'll delete the Reactor
94 * at destruction time.
96 static ACE_Reactor *instance (ACE_Reactor *, bool delete_reactor = false);
98 /// Delete the dynamically allocated Singleton
99 static void close_singleton (void);
101 /// Name of the dll in which the dll lives.
102 static const ACE_TCHAR *dll_name (void);
104 /// Name of the component--ACE_Reactor in this case.
105 static const ACE_TCHAR *name (void);
107 // = Singleton reactor event loop management methods.
109 // Note that these method ONLY work on the "Singleton Reactor,"
110 // i.e., the one returned from <ACE_Reactor::instance>.
112 * Run the event loop until the
113 * <ACE_Reactor::handle_events/ACE_Reactor::alertable_handle_events>
114 * method returns -1 or the <end_event_loop> method is invoked.
115 * Note that this method can only be used by the singleton
116 * <ACE_Reactor::instance>. Thus, to run another reactor use
117 * <ACE_Reactor::run_reactor_event_loop>.
119 * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
121 static int run_event_loop (void);
122 static int run_alertable_event_loop (void);
125 * Run the event loop until the <ACE_Reactor::handle_events> or
126 * <ACE_Reactor::alertable_handle_events> methods returns -1, the
127 * <end_event_loop> method is invoked, or the ACE_Time_Value
128 * expires. Note that this method can only be used by the singleton
129 * <ACE_Reactor::instance>. Thus, to run another reactor use
130 * <ACE_Reactor::run_reactor_event_loop>.
132 * @deprecated Use ACE_Reactor::instance()->run_reactor_event_loop() instead
134 static int run_event_loop (ACE_Time_Value &tv);
135 static int run_alertable_event_loop (ACE_Time_Value &tv);
138 * Instruct the <ACE_Reactor::instance> to terminate its event loop
139 * and notifies the <ACE_Reactor::instance> so that it can wake up
140 * and close down gracefully. Note that this method can only be
141 * used by the singleton <ACE_Reactor::instance>. Thus, to
142 * terminate another reactor, use
143 * <ACE_Reactor::end_reactor_event_loop>.
145 * @deprecated Use ACE_Reactor::instance()->end_reactor_event_loop() instead
147 static int end_event_loop (void);
150 * Report if the <ACE_Reactor::instance>'s event loop is finished.
151 * Note that this method can only be used by the singleton
152 * <ACE_Reactor::instance>. Thus, to check another reactor use
153 * <ACE_Reactor::reactor_event_loop_done>.
155 * @deprecated Use ACE_Reactor::instance()->reactor_event_loop_done() instead
157 static int event_loop_done (void);
160 * Resets the <ACE_Reactor::end_event_loop_> static so that the
161 * <run_event_loop> method can be restarted. Note that this method
162 * can only be used by the singleton <ACE_Reactor::instance>. Thus,
163 * to reset another reactor use <ACE_Reactor::reset_reactor_event_loop>.
165 * @deprecated Use ACE_Reactor::instance()->reset_reactor_event_loop()
166 * instead
168 static void reset_event_loop (void);
171 * The singleton reactor is used by the ACE_Service_Config.
172 * Therefore, we must check for the reconfiguration request and
173 * handle it after handling an event.
175 static int check_reconfiguration (ACE_Reactor *);
177 // = Reactor event loop management methods.
179 // These methods work with an instance of a reactor.
181 * Run the event loop until the
182 * <ACE_Reactor::handle_events/ACE_Reactor::alertable_handle_events>
183 * method returns -1 or the <end_reactor_event_loop> method is invoked.
185 int run_reactor_event_loop (REACTOR_EVENT_HOOK = 0);
186 int run_alertable_reactor_event_loop (REACTOR_EVENT_HOOK = 0);
189 * Run the event loop until the <ACE_Reactor::handle_events> or
190 * <ACE_Reactor::alertable_handle_events> methods returns -1, the
191 * <end_reactor_event_loop> method is invoked, or the ACE_Time_Value
192 * expires.
194 int run_reactor_event_loop (ACE_Time_Value &tv,
195 REACTOR_EVENT_HOOK = 0);
196 int run_alertable_reactor_event_loop (ACE_Time_Value &tv,
197 REACTOR_EVENT_HOOK = 0);
200 * Instruct the Reactor to terminate its event loop and notifies the
201 * Reactor so that it can wake up and deactivate
202 * itself. Deactivating the Reactor would allow the Reactor to be
203 * shutdown gracefully. Internally the Reactor calls deactivate ()
204 * on the underlying implementation.
205 * Any queued notifications remain queued on return from this method.
206 * If the event loop is restarted in the future, the notifications
207 * will be dispatched then. If the reactor is closed or deleted without
208 * further dispatching, the notifications will be lost.
210 int end_reactor_event_loop (void);
212 /// Indicate if the Reactor's event loop has been ended.
213 int reactor_event_loop_done (void);
215 /// Resets the <ACE_Reactor::end_event_loop_> static so that the
216 /// <run_event_loop> method can be restarted.
217 void reset_reactor_event_loop (void);
220 * Create the Reactor using @a implementation. The flag
221 * @a delete_implementation tells the Reactor whether or not to
222 * delete the @a implementation on destruction.
224 ACE_Reactor (ACE_Reactor_Impl *implementation = 0,
225 bool delete_implementation = false);
227 /// Close down and release all resources.
229 * Any notifications that remain queued on this reactor instance are
230 * lost.
232 virtual ~ACE_Reactor (void);
235 * Initialize the ACE_Reactor to manage <max_number_of_handles>.
236 * If <restart> is non-0 then the ACE_Reactor's <handle_events>
237 * method will be restarted automatically when <EINTR> occurs. If
238 * <signal_handler> or <timer_queue> are non-0 they are used as the
239 * signal handler and timer queue, respectively.
241 int open (size_t max_number_of_handles,
242 int restart = 0,
243 ACE_Sig_Handler *signal_handler = 0,
244 ACE_Timer_Queue *timer_queue = 0);
246 /// Use a user specified signal handler instead.
247 int set_sig_handler (ACE_Sig_Handler *signal_handler);
249 /// Set a user-specified timer queue.
250 int timer_queue (ACE_Timer_Queue *tq);
252 /// Return the current ACE_Timer_Queue.
253 ACE_Timer_Queue *timer_queue (void) const;
255 /// Close down and release all resources.
256 int close (void);
258 // = Event loop drivers.
261 * Returns non-zero if there are I/O events "ready" for dispatching,
262 * but does not actually dispatch the event handlers. By default,
263 * don't block while checking this, i.e., "poll".
265 int work_pending (const ACE_Time_Value &max_wait_time = ACE_Time_Value::zero);
268 * This event loop driver blocks for up to @a max_wait_time before
269 * returning. It will return earlier if events occur. Note that
270 * @a max_wait_time can be 0, in which case this method blocks
271 * indefinitely until events occur.
273 * @a max_wait_time is decremented to reflect how much time this call
274 * took. For instance, if a time value of 3 seconds is passed to
275 * handle_events and an event occurs after 2 seconds,
276 * @a max_wait_time will equal 1 second. This can be used if an
277 * application wishes to handle events for some fixed amount of
278 * time.
280 * Returns the total number of timers and I/O ACE_Event_Handlers
281 * that were dispatched, 0 if the @a max_wait_time elapsed without
282 * dispatching any handlers, or -1 if an error occurs.
284 * The only difference between <alertable_handle_events> and
285 * <handle_events> is that in the alertable case, the eventloop will
286 * return when the system queues an I/O completion routine or an
287 * Asynchronous Procedure Call.
289 int handle_events (ACE_Time_Value *max_wait_time = 0);
290 int alertable_handle_events (ACE_Time_Value *max_wait_time = 0);
293 * This method is just like the one above, except the
294 * @a max_wait_time value is a reference and can therefore never be
295 * NULL.
297 * The only difference between <alertable_handle_events> and
298 * <handle_events> is that in the alertable case, the eventloop will
299 * return when the system queues an I/O completion routine or an
300 * Asynchronous Procedure Call.
302 int handle_events (ACE_Time_Value &max_wait_time);
303 int alertable_handle_events (ACE_Time_Value &max_wait_time);
305 // = Register and remove handlers.
308 * Register handler for I/O events.
310 * A handler can be associated with multiple handles. A handle
311 * cannot be associated with multiple handlers.
313 * The handle will come from ACE_Event_Handler::get_handle().
315 * Reactor will call ACE_Event_Handler::add_reference() for a new
316 * handler/handle pair.
318 * If this handler/handle pair has already been registered, any new
319 * masks specified will be added. In this case,
320 * ACE_Event_Handler::add_reference() will not be called.
322 * If the registered handler is currently suspended, it will remain
323 * suspended. When the handler is resumed, it will have the
324 * existing masks plus any masks added through this call. Handlers
325 * do not have partial suspensions.
327 int register_handler (ACE_Event_Handler *event_handler,
328 ACE_Reactor_Mask mask);
331 * Register handler for I/O events.
333 * Same as register_handler(ACE_Event_Handler*,ACE_Reactor_Mask),
334 * except handle is explicitly specified.
336 int register_handler (ACE_HANDLE io_handle,
337 ACE_Event_Handler *event_handler,
338 ACE_Reactor_Mask mask);
340 #if defined (ACE_WIN32)
343 * Register handler for OS events.
345 * Register an @a event_handler that will be notified when
346 * <event_handle> is signaled. This will call back its
347 * <handle_signal> hook method.
349 * Reactor will call ACE_Event_Handler::add_reference() for a new
350 * handler/handle pair.
352 * This interface is only available Win32 platforms because
353 * ACE_HANDLE is an int on non-Win32 platforms and compilers are not
354 * able to tell the difference between
355 * register_handler(ACE_Event_Handler*,ACE_Reactor_Mask) and
356 * register_handler(ACE_Event_Handler*,ACE_HANDLE).
358 int register_handler (ACE_Event_Handler *event_handler,
359 ACE_HANDLE event_handle = ACE_INVALID_HANDLE);
361 #endif /* ACE_WIN32 */
364 * Register handler for I/O events.
366 * Similar to
367 * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
368 * except that the user gets to specify the event handle that will
369 * be used for this registration. This only applies to Reactors
370 * that use event handles for I/O registrations.
372 int register_handler (ACE_HANDLE event_handle,
373 ACE_HANDLE io_handle,
374 ACE_Event_Handler *event_handler,
375 ACE_Reactor_Mask mask);
378 * Register handler for multiple I/O events.
380 * Shorthand for calling
381 * register_handler(ACE_HANDLE,ACE_Event_Handler*,ACE_Reactor_Mask),
382 * multiple times for the same @a event_handler and @a masks but
383 * different <handles>.
385 int register_handler (const ACE_Handle_Set &handles,
386 ACE_Event_Handler *event_handler,
387 ACE_Reactor_Mask masks);
390 * Register handler for signals.
392 * Register @a new_sh to handle the signal @a signum using the
393 * @a new_disp. Returns the @a old_sh that was previously registered
394 * (if any), along with the @a old_disp of the signal handler.
396 * Reactor will call ACE_Event_Handler::add_reference() on @a new_sh
397 * and ACE_Event_Handler::remove_reference() on @a old_sh.
399 int register_handler (int signum,
400 ACE_Event_Handler *new_sh,
401 ACE_Sig_Action *new_disp = 0,
402 ACE_Event_Handler **old_sh = 0,
403 ACE_Sig_Action *old_disp = 0);
406 * Register handler for multiple signals.
408 * Shorthand for calling
409 * register_handler(int,ACE_Event_Handler*,ACE_Sig_Action*,ACE_Event_Handler**,ACE_Sig_Action*)
410 * multiple times for the same @a event_handler and @a sig_action but
411 * different <signals>.
413 int register_handler (const ACE_Sig_Set &sigset,
414 ACE_Event_Handler *event_handler,
415 ACE_Sig_Action *sig_action = 0);
418 * Remove @a masks from @a handle registration.
420 * For I/O handles, @a masks are removed from the Reactor. Unless
421 * @a masks includes ACE_Event_Handler::DONT_CALL,
422 * ACE_Event_Handler::handle_close() will be called with the @a masks
423 * that have been removed. If all masks have been removed,
424 * ACE_Event_Handler::remove_reference() will be called.
426 * For OS handles, the @a handle is removed from the Reactor. Unless
427 * @a masks includes ACE_Event_Handler::DONT_CALL,
428 * ACE_Event_Handler::handle_close() will be called with
429 * ACE_Event_Handler::NULL_MASK.
430 * ACE_Event_Handler::remove_reference() will also be called.
432 int remove_handler (ACE_HANDLE handle,
433 ACE_Reactor_Mask masks);
436 * Remove @a masks from @a event_handler registration.
438 * Same as remove_handler(ACE_HANDLE,ACE_Reactor_Mask), except
439 * @a handle comes from ACE_Event_Handler::get_handle().
441 int remove_handler (ACE_Event_Handler *event_handler,
442 ACE_Reactor_Mask masks);
445 * Remove @a masks from multiple <handle> registrations.
447 * Shorthand for calling remove_handler(ACE_HANDLE,ACE_Reactor_Mask)
448 * multiple times for the same @a masks but different @a handles.
450 int remove_handler (const ACE_Handle_Set &handles,
451 ACE_Reactor_Mask masks);
454 * Remove signal handler registration.
456 * Remove the ACE_Event_Handler currently associated with @a signum.
457 * Install the new disposition (if given) and return the previous
458 * disposition (if desired by the caller).
460 * Note that, unlike removing handler for I/O events,
461 * ACE_Event_Handler::handle_close() will not be called when the
462 * handler is removed. Neither will any reference-counting activity be
463 * involved.
465 * @note There's an existing enhancement request in Bugzilla,
466 * #2368, to change this behavior so that ACE_Event_Handler::handle_close()
467 * is called when the signal handler is removed. Thus, there's some chance
468 * this behavior will change in a future version of ACE.
470 int remove_handler (int signum,
471 ACE_Sig_Action *new_disp,
472 ACE_Sig_Action *old_disp = 0,
473 int sigkey = -1);
476 * Remove multiple signal handler registrations.
478 * Shorthand for calling
479 * remove_handler(int,ACE_Sig_Action*,ACE_Sig_Action*,int) multiple
480 * times for every signal in @a sigset.
482 int remove_handler (const ACE_Sig_Set &sigset);
484 // = Suspend and resume Handlers.
487 * Suspend @a handle temporarily.
489 int suspend_handler (ACE_HANDLE handle);
492 * Suspend @a event_handler temporarily.
494 * Handle is obtained from ACE_Event_Handler::get_handle().
496 int suspend_handler (ACE_Event_Handler *event_handler);
499 * Suspend @a handles temporarily.
501 * Shorthand for calling suspend_handler(ACE_HANDLE) with multiple
502 * @a handles.
504 int suspend_handler (const ACE_Handle_Set &handles);
507 * Suspend all registered handles temporarily.
509 int suspend_handlers (void);
512 * Resume @a handle.
514 int resume_handler (ACE_HANDLE handle);
517 * Resume @a event_handler.
519 * Handle is obtained from ACE_Event_Handler::get_handle().
521 int resume_handler (ACE_Event_Handler *event_handler);
524 * Resume @a handles.
526 * Shorthand for calling resume_handler(ACE_HANDLE) with multiple
527 * <handles>.
529 int resume_handler (const ACE_Handle_Set &handles);
532 * Resume all registered handles.
534 int resume_handlers (void);
536 /// Does the reactor allow the application to resume the handle on
537 /// its own ie. can it pass on the control of handle resumption to
538 /// the application. A positive value indicates that the handlers
539 /// are application resumable. A value of 0 indicates otherwise.
540 int resumable_handler (void);
542 // = Timer management.
545 * Schedule a timer event.
547 * Schedule a timer event that will expire after an <delay> amount
548 * of time. The return value of this method, a timer_id value,
549 * uniquely identifies the @a event_handler in the ACE_Reactor's
550 * internal list of timers. This timer_id value can be used to
551 * cancel the timer with the cancel_timer() call.
553 * Reactor will call ACE_Event_Handler::add_reference() on the
554 * handler. After the timeout occurs and
555 * ACE_Event_Handler::handle_timeout() has completed, the handler
556 * will be implicitly removed from the Reactor and
557 * ACE_Event_Handler::remove_reference() will be called.
559 * @see cancel_timer()
560 * @see reset_timer_interval()
562 * @param event_handler Event handler to schedule on reactor
563 * @param arg Argument passed to the handle_timeout() method of
564 * event_handler
565 * @param delay Time interval after which the timer will expire
566 * @param interval Time interval after which the timer will be automatically
567 * rescheduled
568 * @return -1 on failure, a timer_id value on success
570 virtual long schedule_timer (ACE_Event_Handler *event_handler,
571 const void *arg,
572 const ACE_Time_Value &delay,
573 const ACE_Time_Value &interval =
574 ACE_Time_Value::zero);
577 * Reset recurring timer interval.
579 * Resets the interval of the timer represented by @a timer_id to
580 * @a interval, which is specified in relative time to the current
581 * <gettimeofday>. If @a interval is equal to
582 * ACE_Time_Value::zero, the timer will become a non-rescheduling
583 * timer. Returns 0 if successful, -1 if not.
585 * This change will not take effect until the next timeout.
587 virtual int reset_timer_interval (long timer_id,
588 const ACE_Time_Value &interval);
591 * Cancel timer.
593 * Cancel timer associated with @a timer_id that was returned from
594 * the schedule_timer() method. If arg is non-NULL then it will be
595 * set to point to the ``magic cookie'' argument passed in when the
596 * handler was registered. This makes it possible to free up the
597 * memory and avoid memory leaks. Returns 1 if cancellation
598 * succeeded and 0 if the @a timer_id wasn't found.
600 * On successful cancellation, ACE_Event_Handler::handle_close()
601 * will be called with ACE_Event_Handler::TIMER_MASK.
602 * ACE_Event_Handler::remove_reference() will also be called.
604 virtual int cancel_timer (long timer_id,
605 const void **arg = 0,
606 int dont_call_handle_close = 1);
609 * Cancel all timers associated with event handler.
611 * Shorthand for calling cancel_timer(long,const void **,int)
612 * multiple times for all timer associated with @a event_handler.
614 * ACE_Event_Handler::handle_close() will be called with
615 * ACE_Event_Handler::TIMER_MASK only once irrespective of the
616 * number of timers associated with the event handler.
617 * ACE_Event_Handler::remove_reference() will also be called once
618 * for every timer associated with the event handler.
620 * Returns number of handlers cancelled.
622 virtual int cancel_timer (ACE_Event_Handler *event_handler,
623 int dont_call_handle_close = 1);
625 // = High-level Event_Handler scheduling operations
627 /// Add @a masks_to_be_added to the @a event_handler's entry.
628 /// @a event_handler must already have been registered.
629 /// Note that this call does not cause the Reactor to re-examine
630 /// its set of handlers - the new masks will be noticed the next
631 /// time the Reactor waits for activity. If there is no other
632 /// activity expected, or you need immediate re-examination of the
633 /// wait masks, either call ACE_Reactor::notify after this call, or
634 /// use ACE_Reactor::register_handler instead.
635 int schedule_wakeup (ACE_Event_Handler *event_handler,
636 ACE_Reactor_Mask masks_to_be_added);
638 /// Add @a masks_to_be_added to the @a handle's entry. <event_handler>
639 /// associated with @a handle must already have been registered.
640 /// Note that this call does not cause the Reactor to re-examine
641 /// its set of handlers - the new masks will be noticed the next
642 /// time the Reactor waits for activity. If there is no other
643 /// activity expected, or you need immediate re-examination of
644 /// the wait masks, either call ACE_Reactor::notify after this call,
645 /// or use ACE_Reactor::register_handler instead.
646 int schedule_wakeup (ACE_HANDLE handle,
647 ACE_Reactor_Mask masks_to_be_added);
649 /// Clear @a masks_to_be_cleared from the @a event_handler's entry.
650 /// Note that this call does not cause the Reactor to re-examine
651 /// its set of handlers - the new masks will be noticed the next
652 /// time the Reactor waits for activity. If there is no other
653 /// activity expected, or you need immediate re-examination of
654 /// the wait masks, either call ACE_Reactor::notify after this
655 /// call, or use ACE_Reactor::register_handler instead.
656 int cancel_wakeup (ACE_Event_Handler *event_handler,
657 ACE_Reactor_Mask masks_to_be_cleared);
659 /// Clear @a masks_to_be_cleared from the <handle>'s entry.
660 /// Note that this call does not cause the Reactor to re-examine
661 /// its set of handlers - the new masks will be noticed the next
662 /// time the Reactor waits for activity. If there is no other
663 /// activity expected, or you need immediate re-examination of
664 /// the wait masks, either call ACE_Reactor::notify after this
665 /// call, or use ACE_Reactor::register_handler instead.
666 int cancel_wakeup (ACE_HANDLE handle,
667 ACE_Reactor_Mask masks_to_be_cleared);
669 // = Notification methods.
672 * Dispatch user specified events.
674 * Handler will be dispatched irrespective of whether it is
675 * registered, not registered, or suspended in the Reactor.
677 * If user specified event is successfully queued,
678 * ACE_Event_Handler::add_reference() will be called. After the
679 * notify occurs and the upcall to the handler completes, the
680 * handler will be implicitly removed from the Reactor and
681 * ACE_Event_Handler::remove_reference() will be called. No other
682 * upcall reference counting is done.
684 * For I/O or OS events, the upcall is invoked with an
685 * ACE_INVALID_HANDLE.
687 * For timer events, the upcall is invoked with a null ACT.
689 * @param event_handler: IN - Handler on which the event will be
690 * dispatched.
691 * @param masks: IN - Events to be dispatched - multiple events can
692 * be OR'd together.
693 * @param timeout: INOUT - Relative time up to which to wait for
694 * user specified event to be queued. If tv is 0, wait
695 * indefinitely. When the call returns, tv has the time remaining
696 * after the call completes.
698 int notify (ACE_Event_Handler *event_handler = 0,
699 ACE_Reactor_Mask masks = ACE_Event_Handler::EXCEPT_MASK,
700 ACE_Time_Value *timeout = 0);
703 * Set the maximum number of times that ACE_Reactor will
704 * iterate and dispatch the ACE_Event_Handlers that are passed in
705 * via the notify queue before breaking out of its
706 * <ACE_Message_Queue::dequeue> loop. By default, this is set to
707 * -1, which means "iterate until the queue is empty." Setting this
708 * to a value like "1 or 2" will increase "fairness" (and thus
709 * prevent starvation) at the expense of slightly higher dispatching
710 * overhead.
712 void max_notify_iterations (int iterations);
715 * Get the maximum number of times that the ACE_Reactor will
716 * iterate and dispatch the ACE_Event_Handler's that are passed in
717 * via the notify queue before breaking out of its
718 * <ACE_Message_Queue::dequeue> loop.
720 int max_notify_iterations (void);
723 * Purge any notifications pending in this reactor for the specified
724 * ACE_Event_Handler object. If @a eh == 0, all notifications for
725 * all handlers are removed (but not any notifications posted just
726 * to wake up the reactor itself). Returns the number of
727 * notifications purged. Returns -1 on error.
729 * After the purging occurs, the handler will be implicitly removed
730 * from the Reactor and ACE_Event_Handler::remove_reference() will
731 * be called.
733 int purge_pending_notifications (ACE_Event_Handler *eh,
734 ACE_Reactor_Mask =
735 ACE_Event_Handler::ALL_EVENTS_MASK);
737 // = Assorted helper methods.
740 * Return the Event_Handler associated with @a handle. Return 0 if
741 * @a handle is not registered.
743 * Reactor will call ACE_Event_Handler::add_reference() on the
744 * handler before returning it.
746 ACE_Event_Handler *find_handler (ACE_HANDLE handle);
749 * Check to see if @a handle is associated with a valid Event_Handler
750 * bound to @a mask. Return the @c event_handler associated with this
751 * @a handler if @a event_handler != 0.
753 * Reactor will call ACE_Event_Handler::add_reference() on the
754 * handler before returning it if @a event_handler != 0.
756 int handler (ACE_HANDLE handle,
757 ACE_Reactor_Mask mask,
758 ACE_Event_Handler **event_handler = 0);
761 * Check to see if @a signum is associated with a valid Event_Handler
762 * bound to a signal. Return the @a event_handler associated with
763 * this @c handler if @a event_handler != 0.
765 int handler (int signum,
766 ACE_Event_Handler **event_handler = 0);
768 /// Returns true if Reactor has been successfully initialized, else
769 /// false.
770 int initialized (void);
772 /// Returns the current size of the Reactor's internal descriptor
773 /// table.
774 size_t size (void) const;
776 /// Returns a reference to the Reactor's internal lock.
777 ACE_Lock &lock (void);
779 /// Wake up all threads in waiting in the event loop
780 void wakeup_all_threads (void);
782 /// Transfers ownership of Reactor to the @a new_owner.
783 int owner (ACE_thread_t new_owner,
784 ACE_thread_t *old_owner = 0);
786 /// Return the ID of the "owner" thread.
787 int owner (ACE_thread_t *owner);
789 /// Set position of the owner thread.
790 void requeue_position (int position);
792 /// Get position of the owner thread.
793 int requeue_position (void);
795 /// Get the existing restart value.
796 int restart (void);
798 /// Set a new value for restart and return the original value.
799 int restart (int r);
801 // = Low-level wait_set mask manipulation methods.
803 /// GET/SET/ADD/CLR the dispatch mask "bit" bound with the
804 /// @a event_handler and @a mask.
805 int mask_ops (ACE_Event_Handler *event_handler,
806 ACE_Reactor_Mask mask,
807 int ops);
809 /// GET/SET/ADD/CLR the dispatch MASK "bit" bound with the @a handle
810 /// and @a mask.
811 int mask_ops (ACE_HANDLE handle,
812 ACE_Reactor_Mask mask,
813 int ops);
815 // = Low-level ready_set mask manipulation methods.
816 /// GET/SET/ADD/CLR the ready "bit" bound with the @a event_handler
817 /// and @a mask.
818 int ready_ops (ACE_Event_Handler *event_handler,
819 ACE_Reactor_Mask mask,
820 int ops);
822 /// GET/SET/ADD/CLR the ready "bit" bound with the <handle> and @a mask.
823 int ready_ops (ACE_HANDLE handle,
824 ACE_Reactor_Mask mask,
825 int ops);
827 /// Get the implementation class
828 ACE_Reactor_Impl *implementation (void) const;
831 * Returns 0, if the size of the current message has been put in
832 * @a size returns -1, if not. ACE_HANDLE allows the reactor to
833 * check if the caller is valid. Used for CLASSIX Reactor
834 * implementation.
836 int current_info (ACE_HANDLE handle, size_t &msg_size);
838 /// Return 1 if we any event associations were made by the reactor
839 /// for the handles that it waits on, 0 otherwise.
840 int uses_event_associations (void);
842 /// Declare the dynamic allocation hooks.
843 ACE_ALLOC_HOOK_DECLARE;
845 /// Dump the state of the object.
846 void dump (void) const;
848 protected:
849 /// Set the implementation class.
850 void implementation (ACE_Reactor_Impl *implementation);
852 /// Delegation/implementation class that all methods will be
853 /// forwarded to.
854 ACE_Reactor_Impl *implementation_;
856 /// Flag used to indicate whether we are responsible for cleaning up
857 /// the implementation instance
858 bool delete_implementation_;
860 /// Pointer to a process-wide ACE_Reactor singleton.
861 static ACE_Reactor *reactor_;
863 /// Must delete the reactor_ singleton if true.
864 static bool delete_reactor_;
866 /// Deny access since member-wise won't work...
867 ACE_Reactor (const ACE_Reactor &);
868 ACE_Reactor &operator = (const ACE_Reactor &);
871 ACE_END_VERSIONED_NAMESPACE_DECL
874 #if defined (__ACE_INLINE__)
875 #include "ace/Reactor.inl"
876 #endif /* __ACE_INLINE__ */
878 #include /**/ "ace/post.h"
880 #endif /* ACE_REACTOR_H */