#include <ace/Proactor.h>
class ACE_Proactor : public ACE_Event_Handler {
public:
friend class ACE_Proactor_Timer_Handler;
friend class ACE_Proactor_Handle_Timeout_Upcall;
typedef ACE_Timer_Queue_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Queue; typedef ACE_Timer_Queue_Iterator_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Queue_Iterator; typedef ACE_Timer_List_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_List; typedef ACE_Timer_List_Iterator_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_List_Iterator; typedef ACE_Timer_Heap_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Heap; typedef ACE_Timer_Heap_Iterator_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Heap_Iterator; typedef ACE_Timer_Wheel_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Wheel; typedef ACE_Timer_Wheel_Iterator_T<ACE_Handler *, ACE_Proactor_Handle_Timeout_Upcall, ACE_SYNCH_RECURSIVE_MUTEX> Timer_Wheel_Iterator;ACE_Proactor ( size_t number_of_threads = 0, Timer_Queue *tq = 0, int used_with_reactor_event_loop = 0 );
virtual ~ACE_Proactor (void);
static ACE_Proactor *instance (size_t threads = 0);
static ACE_Proactor *instance (ACE_Proactor *);
static void close_singleton (void);
static int run_event_loop (void);
static int run_event_loop (ACE_Time_Value &tv);
static int end_event_loop (void);
static int event_loop_done (void);
virtual int close (void);
virtual int register_handle ( ACE_HANDLE handle, const void *completion_key );
virtual long schedule_timer ( ACE_Handler &handler, const void *act, const ACE_Time_Value &time );
virtual long schedule_repeating_timer ( ACE_Handler &handler, const void *act, const ACE_Time_Value &interval );
virtual long schedule_timer ( ACE_Handler &handler, const void *act, const ACE_Time_Value &time, const ACE_Time_Value &interval );
virtual int cancel_timer ( ACE_Handler &handler, int dont_call_handle_close = 1 );
virtual int cancel_timer ( long timer_id, const void **act = 0, int dont_call_handle_close = 1 );
virtual int handle_events (ACE_Time_Value &wait_time);
virtual int handle_events (void);
virtual int post_completion (ACE_Asynch_Result *result);
int wake_up_dispatch_threads (void);
int close_dispatch_threads (int wait);
size_t number_of_threads (void) const;
void number_of_threads (size_t threads);
Timer_Queue *timer_queue (void) const;
void timer_queue (Timer_Queue *);
virtual ACE_HANDLE get_handle (void) const;
inline ACE_Proactor (size_t = 0, Timer_Queue * = 0);
static ACE_Proactor *instance (size_t threads = 0);
static ACE_Proactor *instance (ACE_Proactor *);
static void close_singleton (void);
static int run_event_loop (void);
static int run_event_loop (ACE_Time_Value &tv);
static int end_event_loop (void);
static sig_atomic_t event_loop_done (void);
protected:
virtual int handle_signal ( int signum, siginfo_t * = 0, ucontext_t * = 0 );
virtual int handle_close ( ACE_HANDLE handle, ACE_Reactor_Mask close_mask );
void application_specific_code ( ACE_Asynch_Result *asynch_result, u_long bytes_transferred, int success, const void *completion_key, u_long error );
virtual int handle_events (unsigned long milli_seconds);
class Asynch_Timer : protected ACE_Asynch_Result {
public:
friend class ACE_Proactor_Handle_Timeout_Upcall;
Asynch_Timer ( ACE_Handler &handler, const void *act, const ACE_Time_Value &tv, ACE_HANDLE event = ACE_INVALID_HANDLE );
protected:
virtual void complete ( u_long bytes_transferred, int success, const void *completion_key, u_long error = 0 );
ACE_Time_Value time_;
};
ACE_HANDLE completion_port_;
size_t number_of_threads_;
Timer_Queue *timer_queue_;
int delete_timer_queue_;
ACE_Proactor_Timer_Handler *timer_handler_;
ACE_Thread_Manager thr_mgr_;
ACE_Auto_Event event_;
int used_with_reactor_event_loop_;
private:
static ACE_Proactor *proactor_;
static int delete_proactor_;
static sig_atomic_t end_event_loop_;
};
static int run_event_loop (void);
ACE_Proactor::handle_events
method returns -1 or the end_event_loop
method
is invoked.
static int run_event_loop (ACE_Time_Value &tv);
ACE_Proactor::handle_events
method returns -1, the end_event_loop
method
is invoked, or the ACE_Time_Value
expires.
static int end_event_loop (void);
ACE_Proactor::instance
to terminate its event loop.
static int event_loop_done (void);
ACE_Proactor::instance
event loop is finished.
virtual int close (void);
virtual int register_handle (
ACE_HANDLE handle,
const void *completion_key
);
handle
to the I/O completion port
virtual long schedule_timer (
ACE_Handler &handler,
const void *act,
const ACE_Time_Value &time
);
handler
that will expire after time
. If it
expires then act
is passed in as the value to the handler
's
handle_timeout
callback method. This method returns a
timer_id
. This timer_id
can be used to cancel a timer before
it expires. The cancellation ensures that timer_ids
are unique
up to values of greater than 2 billion timers. As long as timers
don't stay around longer than this there should be no problems
with accidentally deleting the wrong timer. Returns -1 on
failure (which is guaranteed never to be a valid timer_id
.
virtual long schedule_repeating_timer (
ACE_Handler &handler,
const void *act,
const ACE_Time_Value &interval
);
Same as above except interval
it is used to reschedule the
handler
automatically.
virtual long schedule_timer (
ACE_Handler &handler,
const void *act,
const ACE_Time_Value &time,
const ACE_Time_Value &interval
);
virtual int cancel_timer (
ACE_Handler &handler,
int dont_call_handle_close = 1
);
handler
. Returns number
of timers cancelled.
virtual int cancel_timer (
long timer_id,
const void **act = 0,
int dont_call_handle_close = 1
);
ACE_Handler
that matches the timer_id
value
(which was returned from the schedule
method). If act
is
non-NULL then it will be set to point to the ``magic cookie''
argument passed in when the Handler
was registered. This makes
it possible to free up the memory and avoid memory leaks.
Returns 1 if cancellation succeeded and 0 if the timer_id
wasn't found.
virtual int handle_events (ACE_Time_Value &wait_time);
wait_time
elapses before
any events occur, return.
virtual int handle_events (void);
virtual int post_completion (ACE_Asynch_Result *result);
int wake_up_dispatch_threads (void);
int close_dispatch_threads (int wait);
size_t number_of_threads (void) const;
void number_of_threads (size_t threads);
Timer_Queue *timer_queue (void) const;
void timer_queue (Timer_Queue *);
virtual ACE_HANDLE get_handle (void) const;