00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
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 
00027 
00028 #if defined (ACE_HAS_WIN32_OVERLAPPED_IO) || defined (ACE_HAS_AIO_CALLS)
00029 
00030 
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 
00043 class ACE_Proactor_Impl;
00044 class ACE_Proactor_Timer_Handler;
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 class ACE_Proactor_Handle_Timeout_Upcall
00055 {
00056 
00057 
00058   typedef ACE_Timer_Queue_T<ACE_Handler *,
00059                             ACE_Proactor_Handle_Timeout_Upcall,
00060                             ACE_SYNCH_RECURSIVE_MUTEX>
00061   TIMER_QUEUE;
00062 
00063 
00064   friend class ACE_Proactor;
00065 
00066 public:
00067 
00068   ACE_Proactor_Handle_Timeout_Upcall (void);
00069 
00070 
00071   int registration (TIMER_QUEUE &timer_queue,
00072                     ACE_Handler *handler,
00073                     const void *arg);
00074 
00075 
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 
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 
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 
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 
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 
00111 
00112   int deletion (TIMER_QUEUE &timer_queue,
00113                 ACE_Handler *handler,
00114                 const void *arg);
00115 
00116 protected:
00117 
00118   int proactor (ACE_Proactor &proactor);
00119 
00120 
00121 
00122   ACE_Proactor *proactor_;
00123 };
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 class ACE_Export ACE_Proactor
00135 {
00136   
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   
00168 
00169 
00170 
00171   friend class ACE_Proactor_Timer_Handler;
00172 
00173 public:
00174 
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 
00182 
00183 
00184 
00185 
00186   ACE_Proactor (ACE_Proactor_Impl *implementation = 0,
00187                 int delete_implementation = 0,
00188                 TIMER_QUEUE *tq = 0);
00189 
00190 
00191   ~ACE_Proactor (void);
00192 
00193 
00194 
00195   static ACE_Proactor *instance (size_t threads = 0);
00196 
00197 
00198 
00199   static ACE_Proactor *instance (ACE_Proactor * proactor,
00200                                  int delete_proactor = 0);
00201 
00202 
00203   static void close_singleton (void);
00204 
00205 
00206 
00207   static void cleanup (void *instance, void *arg);
00208 
00209 
00210   static const ACE_TCHAR *dll_name (void);
00211 
00212 
00213   static const ACE_TCHAR *name (void);
00214 
00215   
00216 
00217 
00218 
00219   static int run_event_loop (void);
00220 
00221 
00222 
00223 
00224 
00225 
00226   static int run_event_loop (ACE_Time_Value &tv);
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234   static int end_event_loop (void);
00235 
00236 
00237 
00238 
00239 
00240   static int reset_event_loop (void);
00241 
00242 
00243 
00244 
00245 
00246 
00247   static int check_reconfiguration (ACE_Proactor *);
00248 
00249 
00250   static int event_loop_done (void);
00251 
00252 
00253 
00254 
00255 
00256 
00257   int close (void);
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266   typedef int (*PROACTOR_EVENT_HOOK)(ACE_Proactor *);
00267 
00268   
00269 
00270 
00271 
00272 
00273 
00274   int proactor_run_event_loop (PROACTOR_EVENT_HOOK = 0);
00275 
00276 
00277 
00278 
00279 
00280 
00281 
00282 
00283   int proactor_run_event_loop (ACE_Time_Value &tv,
00284                                PROACTOR_EVENT_HOOK = 0);
00285 
00286 
00287 
00288 
00289 
00290 
00291   int proactor_end_event_loop (void);
00292 
00293 
00294   int proactor_event_loop_done (void);
00295 
00296 
00297 
00298   int proactor_reset_event_loop (void);
00299 
00300 
00301 
00302 
00303   int register_handle (ACE_HANDLE handle,
00304                        const void *completion_key);
00305 
00306   
00307 
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
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   
00327   
00328 
00329 
00330 
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 
00337 
00338   int cancel_timer (ACE_Handler &handler,
00339                     int dont_call_handle_close = 1);
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350   int cancel_timer (long timer_id,
00351                     const void **act = 0,
00352                     int dont_call_handle_close = 1);
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364   int handle_events (ACE_Time_Value &wait_time);
00365 
00366 
00367 
00368 
00369 
00370 
00371   int handle_events (void);
00372 
00373 
00374   int wake_up_dispatch_threads (void);
00375 
00376 
00377   int close_dispatch_threads (int wait);
00378 
00379 
00380   size_t number_of_threads (void) const;
00381 
00382 
00383   void number_of_threads (size_t threads);
00384 
00385 
00386   TIMER_QUEUE *timer_queue (void) const;
00387 
00388 
00389   void timer_queue (TIMER_QUEUE *timer_queue);
00390 
00391 
00392 
00393 
00394 
00395 
00396   ACE_HANDLE get_handle (void) const;
00397 
00398 
00399   ACE_Proactor_Impl *implementation (void) const;
00400 
00401   
00402 
00403   
00404   
00405 
00406 
00407 
00408   ACE_Asynch_Read_Stream_Impl *create_asynch_read_stream (void);
00409 
00410 
00411 
00412   ACE_Asynch_Write_Stream_Impl *create_asynch_write_stream (void);
00413 
00414 
00415 
00416   ACE_Asynch_Read_File_Impl *create_asynch_read_file (void);
00417 
00418 
00419 
00420   ACE_Asynch_Write_File_Impl *create_asynch_write_file (void);
00421 
00422 
00423   ACE_Asynch_Accept_Impl *create_asynch_accept (void);
00424 
00425 
00426   ACE_Asynch_Connect_Impl *create_asynch_connect (void);
00427 
00428 
00429 
00430   ACE_Asynch_Transmit_File_Impl *create_asynch_transmit_file (void);
00431 
00432 
00433 
00434   ACE_Asynch_Read_Dgram_Impl *create_asynch_read_dgram (void);
00435 
00436 
00437 
00438   ACE_Asynch_Write_Dgram_Impl *create_asynch_write_dgram (void);
00439 
00440   
00441 
00442   
00443   
00444 
00445 
00446 
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 
00458 
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 
00470 
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 
00484 
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 
00498 
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 
00512 
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 
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 
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 
00546 
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 
00564 
00565 
00566 
00567 
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 
00581 
00582 
00583 
00584   static int post_wakeup_completions (int how_many);
00585 
00586 
00587 
00588 
00589 
00590 
00591   int proactor_post_wakeup_completions (int how_many);
00592 
00593 
00594   void implementation (ACE_Proactor_Impl *implementation);
00595 
00596 
00597 
00598   ACE_Proactor_Impl *implementation_;
00599 
00600 
00601 
00602   int delete_implementation_;
00603 
00604 
00605   static ACE_Proactor *proactor_;
00606 
00607 
00608   static int delete_proactor_;
00609 
00610 
00611   ACE_Proactor_Timer_Handler *timer_handler_;
00612 
00613 
00614   ACE_Thread_Manager thr_mgr_;
00615 
00616 
00617   TIMER_QUEUE *timer_queue_;
00618 
00619 
00620   int delete_timer_queue_;
00621 
00622 
00623   sig_atomic_t end_event_loop_;
00624 
00625 
00626   sig_atomic_t event_loop_thread_count_;
00627 
00628 
00629   ACE_SYNCH_MUTEX mutex_;
00630 
00631 
00632 private:
00633 
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 
00643 
00644 #else 
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  = 0,
00658                 Timer_Queue *  = 0) {}
00659   ~ACE_Proactor (void) {}
00660   int handle_events (void) { return -1; }
00661   int handle_events (ACE_Time_Value &) { return -1; }
00662 
00663 
00664   static ACE_Proactor *instance (size_t threads = 0);
00665 
00666 
00667   static ACE_Proactor *instance (ACE_Proactor *);
00668 
00669 
00670   static void close_singleton (void);
00671 
00672 
00673   static int run_event_loop (void);
00674 
00675 
00676   static int run_event_loop (ACE_Time_Value &tv);
00677 
00678 
00679   static int end_event_loop (void);
00680 
00681 
00682   static sig_atomic_t event_loop_done (void);
00683 };
00684 
00685 ACE_END_VERSIONED_NAMESPACE_DECL
00686 
00687 #endif 
00688 
00689 #include  "ace/post.h"
00690 
00691 #endif