Event_Handler.cpp

Go to the documentation of this file.
00001 // Event_Handler.cpp
00002 // $Id: Event_Handler.cpp 80826 2008-03-04 14:51:23Z wotte $
00003 
00004 #include "ace/Event_Handler.h"
00005 #include "ace/OS_Errno.h"
00006 #include "ace/Reactor.h"
00007 #include "ace/Thread_Manager.h"
00008 /* Need to see if ACE_HAS_BUILTIN_ATOMIC_OP defined */
00009 #include "ace/Atomic_Op.h"
00010 
00011 #if !defined (__ACE_INLINE__)
00012 #include "ace/Event_Handler.inl"
00013 #endif /* __ACE_INLINE__ */
00014 
00015 #include <algorithm>
00016 
00017 ACE_RCSID(ace, Event_Handler, "$Id: Event_Handler.cpp 80826 2008-03-04 14:51:23Z wotte $")
00018 
00019 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 // Implement conceptually abstract virtual functions in the base class
00022 // so derived classes don't have to implement unused ones.
00023 
00024 ACE_Event_Handler::ACE_Event_Handler (ACE_Reactor *r,
00025                                       int p)
00026   : reference_count_ (1),
00027     priority_ (p),
00028     reactor_ (r),
00029     reference_counting_policy_ (Reference_Counting_Policy::DISABLED)
00030 {
00031   // ACE_TRACE ("ACE_Event_Handler::ACE_Event_Handler");
00032 }
00033 
00034 ACE_Event_Handler::~ACE_Event_Handler (void)
00035 {
00036   // ACE_TRACE ("ACE_Event_Handler::~ACE_Event_Handler");
00037 }
00038 
00039 // Gets the file descriptor associated with this I/O device.
00040 
00041 ACE_HANDLE
00042 ACE_Event_Handler::get_handle (void) const
00043 {
00044   ACE_TRACE ("ACE_Event_Handler::get_handle");
00045   return ACE_INVALID_HANDLE;
00046 }
00047 
00048 // Sets the file descriptor associated with this I/O device.
00049 
00050 void
00051 ACE_Event_Handler::set_handle (ACE_HANDLE)
00052 {
00053   ACE_TRACE ("ACE_Event_Handler::set_handle");
00054 }
00055 
00056 // Gets the priority of this handler.
00057 
00058 int
00059 ACE_Event_Handler::priority (void) const
00060 {
00061   ACE_TRACE ("ACE_Event_Handler::priority");
00062   return this->priority_;
00063 }
00064 
00065 // Sets the priority
00066 
00067 void
00068 ACE_Event_Handler::priority (int priority)
00069 {
00070   ACE_TRACE ("ACE_Event_Handler::priority");
00071   this->priority_ = priority;
00072 }
00073 
00074 // Called when the object is about to be removed from the Dispatcher
00075 // tables.
00076 
00077 int
00078 ACE_Event_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
00079 {
00080   ACE_TRACE ("ACE_Event_Handler::handle_close");
00081   return -1;
00082 }
00083 
00084 // Called when input becomes available on fd.
00085 
00086 int
00087 ACE_Event_Handler::handle_input (ACE_HANDLE)
00088 {
00089   ACE_TRACE ("ACE_Event_Handler::handle_input");
00090   return -1;
00091 }
00092 
00093 // Called when output is possible on fd.
00094 
00095 int
00096 ACE_Event_Handler::handle_output (ACE_HANDLE)
00097 {
00098   ACE_TRACE ("ACE_Event_Handler::handle_output");
00099   return -1;
00100 }
00101 
00102 // Called when urgent data is available on fd.
00103 
00104 int
00105 ACE_Event_Handler::handle_exception (ACE_HANDLE)
00106 {
00107   ACE_TRACE ("ACE_Event_Handler::handle_exception");
00108   return -1;
00109 }
00110 
00111 // Called when timer expires, TV stores the current time.
00112 
00113 int
00114 ACE_Event_Handler::handle_timeout (const ACE_Time_Value &, const void *)
00115 {
00116   ACE_TRACE ("ACE_Event_Handler::handle_timeout");
00117   return -1;
00118 }
00119 
00120 // Called when a monitored Process exits
00121 
00122 int
00123 ACE_Event_Handler::handle_exit (ACE_Process *)
00124 {
00125   ACE_TRACE ("ACE_Event_Handler::handle_exit");
00126   return -1;
00127 }
00128 
00129 // Called when a registered signal occurs.
00130 
00131 int
00132 ACE_Event_Handler::handle_signal (int, siginfo_t *, ucontext_t *)
00133 {
00134   ACE_TRACE ("ACE_Event_Handler::handle_signal");
00135   return -1;
00136 }
00137 
00138 int
00139 ACE_Event_Handler::resume_handler (void)
00140 {
00141   ACE_TRACE ("ACE_Event_Handler::resume_handler");
00142 
00143   // Return a default value and allow the reactor to take care of
00144   // resuming the handler
00145   return ACE_Event_Handler::ACE_REACTOR_RESUMES_HANDLER;
00146 }
00147 
00148 
00149 int
00150 ACE_Event_Handler::handle_qos (ACE_HANDLE)
00151 {
00152   ACE_TRACE ("ACE_Event_Handler::handle_qos");
00153   return -1;
00154 }
00155 
00156 int
00157 ACE_Event_Handler::handle_group_qos (ACE_HANDLE)
00158 {
00159   ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
00160   return -1;
00161 }
00162 
00163 void
00164 ACE_Event_Handler::reactor (ACE_Reactor *reactor)
00165 {
00166   ACE_TRACE ("ACE_Event_Handler::reactor");
00167   this->reactor_ = reactor;
00168 }
00169 
00170 ACE_Reactor *
00171 ACE_Event_Handler::reactor (void) const
00172 {
00173   ACE_TRACE ("ACE_Event_Handler::reactor");
00174   return this->reactor_;
00175 }
00176 
00177 ACE_Reactor_Timer_Interface *
00178 ACE_Event_Handler::reactor_timer_interface (void) const
00179 {
00180   ACE_TRACE ("ACE_Event_Handler::reactor_timer_interface");
00181   return this->reactor_;
00182 }
00183 
00184 ACE_Event_Handler::Reference_Count
00185 ACE_Event_Handler::add_reference (void)
00186 {
00187   bool const reference_counting_required =
00188     this->reference_counting_policy ().value () ==
00189     ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00190 
00191   if (reference_counting_required)
00192     return ++this->reference_count_;
00193   else
00194     return 1;
00195 }
00196 
00197 ACE_Event_Handler::Reference_Count
00198 ACE_Event_Handler::remove_reference (void)
00199 {
00200   bool const reference_counting_required =
00201     this->reference_counting_policy ().value () ==
00202     ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00203 
00204   if (reference_counting_required)
00205     {
00206       Reference_Count result =
00207         --this->reference_count_;
00208 
00209       if (result == 0)
00210         delete this;
00211 
00212       return result;
00213     }
00214   else
00215     {
00216       return 1;
00217     }
00218 }
00219 
00220 ACE_Event_Handler::Policy::~Policy (void)
00221 {
00222 }
00223 
00224 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value)
00225   : value_ (value)
00226 {
00227 }
00228 
00229 ACE_Event_Handler::Reference_Counting_Policy::Value
00230 ACE_Event_Handler::Reference_Counting_Policy::value (void) const
00231 {
00232   return this->value_;
00233 }
00234 
00235 void
00236 ACE_Event_Handler::Reference_Counting_Policy::value (ACE_Event_Handler::Reference_Counting_Policy::Value value)
00237 {
00238   this->value_ = value;
00239 }
00240 
00241 ACE_Event_Handler::Reference_Counting_Policy &
00242 ACE_Event_Handler::reference_counting_policy (void)
00243 {
00244   return this->reference_counting_policy_;
00245 }
00246 
00247 //#if !defined (ACE_HAS_WINCE)
00248 
00249 ACE_THR_FUNC_RETURN
00250 ACE_Event_Handler::read_adapter (void *args)
00251 {
00252   ACE_Event_Handler *this_ptr = static_cast<ACE_Event_Handler *> (args);
00253   ACE_Reactor *r = this_ptr->reactor ();
00254 
00255   while (this_ptr->handle_input (ACE_STDIN) != -1)
00256     continue;
00257 
00258   this_ptr->handle_close (ACE_STDIN, ACE_Event_Handler::READ_MASK);
00259   // It's possible for handle_close() to "delete this" so we need to
00260   // cache the reactor pointer and use it here.
00261   r->notify ();
00262 
00263   return 0;
00264 }
00265 
00266 int
00267 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler *eh,
00268                                            ACE_Reactor *reactor,
00269                                            ACE_Thread_Manager *thr_mgr,
00270                                            int flags)
00271 {
00272 #if defined (ACE_WIN32)
00273   ACE_UNUSED_ARG (reactor);
00274 
00275   eh->reactor (reactor);
00276   return thr_mgr->spawn (&read_adapter, static_cast<void *> (eh), flags);
00277 #else
00278   // Keep compilers happy.
00279   ACE_UNUSED_ARG (flags);
00280   ACE_UNUSED_ARG (thr_mgr);
00281   return reactor->register_handler (ACE_STDIN,
00282                                     eh,
00283                                     ACE_Event_Handler::READ_MASK);
00284 #endif /* ACE_WIN32 */
00285 }
00286 
00287 int
00288 ACE_Event_Handler::remove_stdin_handler (ACE_Reactor *reactor,
00289                                          ACE_Thread_Manager * /* thr_mgr */)
00290 {
00291 #if defined (ACE_WIN32)
00292   ACE_UNUSED_ARG (reactor);
00293 
00294   // What should we do here?
00295   ACE_NOTSUP_RETURN (-1);
00296 #else
00297   return reactor->remove_handler (ACE_STDIN,
00298                                   ACE_Event_Handler::READ_MASK);
00299 #endif /* ACE_WIN32 */
00300 }
00301 
00302 //#endif /* ACE_HAS_WINCE */
00303 
00304 // ---------------------------------------------------------------------
00305 
00306 ACE_Event_Handler_var::ACE_Event_Handler_var (void)
00307   : ptr_ (0)
00308 {
00309 }
00310 
00311 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler *p)
00312   : ptr_ (p)
00313 {
00314 }
00315 
00316 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var &b)
00317   : ptr_ (b.ptr_)
00318 {
00319   if (this->ptr_ != 0)
00320     {
00321       this->ptr_->add_reference ();
00322     }
00323 }
00324 
00325 ACE_Event_Handler_var::~ACE_Event_Handler_var (void)
00326 {
00327   if (this->ptr_ != 0)
00328     {
00329       ACE_Errno_Guard eguard (errno);
00330       this->ptr_->remove_reference ();
00331     }
00332 }
00333 
00334 ACE_Event_Handler_var &
00335 ACE_Event_Handler_var::operator= (ACE_Event_Handler *p)
00336 {
00337   if (this->ptr_ != p)
00338     {
00339       ACE_Event_Handler_var tmp (p);
00340       std::swap (this->ptr_, tmp.ptr_);
00341     }
00342 
00343   return *this;
00344 }
00345 
00346 ACE_Event_Handler_var &
00347 ACE_Event_Handler_var::operator= (const ACE_Event_Handler_var &b)
00348 {
00349   ACE_Event_Handler_var tmp (b);
00350   std::swap (this->ptr_, tmp.ptr_);
00351 
00352   return *this;
00353 }
00354 
00355 ACE_Event_Handler *
00356 ACE_Event_Handler_var::operator->() const
00357 {
00358   return this->ptr_;
00359 }
00360 
00361 ACE_Event_Handler *
00362 ACE_Event_Handler_var::handler (void) const
00363 {
00364   return this->ptr_;
00365 }
00366 
00367 ACE_Event_Handler *
00368 ACE_Event_Handler_var::release (void)
00369 {
00370   ACE_Event_Handler * const old = this->ptr_;
00371   this->ptr_ = 0;
00372   return old;
00373 }
00374 
00375 void
00376 ACE_Event_Handler_var::reset (ACE_Event_Handler *p)
00377 {
00378   *this = p;
00379 }
00380 
00381 // ---------------------------------------------------------------------
00382 
00383 ACE_Notification_Buffer::ACE_Notification_Buffer (void)
00384 {
00385   ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
00386 }
00387 
00388 ACE_Notification_Buffer::ACE_Notification_Buffer (ACE_Event_Handler *eh,
00389                                                   ACE_Reactor_Mask mask)
00390   : eh_ (eh),
00391     mask_ (mask)
00392 {
00393   ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
00394 }
00395 
00396 ACE_END_VERSIONED_NAMESPACE_DECL

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