00001
00002
00003
00004 #include "ace/Event_Handler.h"
00005 #include "ace/Message_Block.h"
00006 #include "ace/OS_Errno.h"
00007 #include "ace/Reactor.h"
00008 #include "ace/Thread_Manager.h"
00009
00010 #include "ace/Atomic_Op.h"
00011
00012 #if !defined (__ACE_INLINE__)
00013 #include "ace/Event_Handler.inl"
00014 #endif
00015
00016 ACE_RCSID(ace, Event_Handler, "Event_Handler.cpp,v 4.37 2006/05/09 07:22:02 jwillemsen Exp")
00017
00018 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00019
00020
00021
00022
00023 ACE_Event_Handler::ACE_Event_Handler (ACE_Reactor *r,
00024 int p)
00025 : reference_count_ (1),
00026 priority_ (p),
00027 reactor_ (r),
00028 reference_counting_policy_ (Reference_Counting_Policy::DISABLED)
00029 {
00030
00031 }
00032
00033 ACE_Event_Handler::~ACE_Event_Handler (void)
00034 {
00035
00036 if (this->reactor_ != 0)
00037 {
00038 ACE_Errno_Guard guard (errno);
00039 this->reactor_->purge_pending_notifications (this);
00040 }
00041 }
00042
00043
00044
00045 ACE_HANDLE
00046 ACE_Event_Handler::get_handle (void) const
00047 {
00048 ACE_TRACE ("ACE_Event_Handler::get_handle");
00049 return ACE_INVALID_HANDLE;
00050 }
00051
00052
00053
00054 void
00055 ACE_Event_Handler::set_handle (ACE_HANDLE)
00056 {
00057 ACE_TRACE ("ACE_Event_Handler::set_handle");
00058 }
00059
00060
00061
00062 int
00063 ACE_Event_Handler::priority (void) const
00064 {
00065 ACE_TRACE ("ACE_Event_Handler::priority");
00066 return this->priority_;
00067 }
00068
00069
00070
00071 void
00072 ACE_Event_Handler::priority (int priority)
00073 {
00074 ACE_TRACE ("ACE_Event_Handler::priority");
00075 this->priority_ = priority;
00076 }
00077
00078
00079
00080
00081 int
00082 ACE_Event_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
00083 {
00084 ACE_TRACE ("ACE_Event_Handler::handle_close");
00085 return -1;
00086 }
00087
00088
00089
00090 int
00091 ACE_Event_Handler::handle_input (ACE_HANDLE)
00092 {
00093 ACE_TRACE ("ACE_Event_Handler::handle_input");
00094 return -1;
00095 }
00096
00097
00098
00099 int
00100 ACE_Event_Handler::handle_output (ACE_HANDLE)
00101 {
00102 ACE_TRACE ("ACE_Event_Handler::handle_output");
00103 return -1;
00104 }
00105
00106
00107
00108 int
00109 ACE_Event_Handler::handle_exception (ACE_HANDLE)
00110 {
00111 ACE_TRACE ("ACE_Event_Handler::handle_exception");
00112 return -1;
00113 }
00114
00115
00116
00117 int
00118 ACE_Event_Handler::handle_timeout (const ACE_Time_Value &, const void *)
00119 {
00120 ACE_TRACE ("ACE_Event_Handler::handle_timeout");
00121 return -1;
00122 }
00123
00124
00125
00126 int
00127 ACE_Event_Handler::handle_exit (ACE_Process *)
00128 {
00129 ACE_TRACE ("ACE_Event_Handler::handle_exit");
00130 return -1;
00131 }
00132
00133
00134
00135 int
00136 ACE_Event_Handler::handle_signal (int, siginfo_t *, ucontext_t *)
00137 {
00138 ACE_TRACE ("ACE_Event_Handler::handle_signal");
00139 return -1;
00140 }
00141
00142 int
00143 ACE_Event_Handler::resume_handler (void)
00144 {
00145 ACE_TRACE ("ACE_Event_Handler::resume_handler");
00146
00147
00148
00149 return ACE_Event_Handler::ACE_REACTOR_RESUMES_HANDLER;
00150 }
00151
00152
00153 int
00154 ACE_Event_Handler::handle_qos (ACE_HANDLE)
00155 {
00156 ACE_TRACE ("ACE_Event_Handler::handle_qos");
00157 return -1;
00158 }
00159
00160 int
00161 ACE_Event_Handler::handle_group_qos (ACE_HANDLE)
00162 {
00163 ACE_TRACE ("ACE_Event_Handler::handle_group_qos");
00164 return -1;
00165 }
00166
00167 void
00168 ACE_Event_Handler::reactor (ACE_Reactor *reactor)
00169 {
00170 ACE_TRACE ("ACE_Event_Handler::reactor");
00171 this->reactor_ = reactor;
00172 }
00173
00174 ACE_Reactor *
00175 ACE_Event_Handler::reactor (void) const
00176 {
00177 ACE_TRACE ("ACE_Event_Handler::reactor");
00178 return this->reactor_;
00179 }
00180
00181 ACE_Reactor_Timer_Interface *
00182 ACE_Event_Handler::reactor_timer_interface (void) const
00183 {
00184 ACE_TRACE ("ACE_Event_Handler::reactor_timer_interface");
00185 return this->reactor_;
00186 }
00187
00188 ACE_Event_Handler::Reference_Count
00189 ACE_Event_Handler::add_reference (void)
00190 {
00191 int reference_counting_required =
00192 this->reference_counting_policy ().value () ==
00193 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00194
00195 if (reference_counting_required)
00196 return ++this->reference_count_;
00197 else
00198 return 1;
00199 }
00200
00201 ACE_Event_Handler::Reference_Count
00202 ACE_Event_Handler::remove_reference (void)
00203 {
00204 int reference_counting_required =
00205 this->reference_counting_policy ().value () ==
00206 ACE_Event_Handler::Reference_Counting_Policy::ENABLED;
00207
00208 if (reference_counting_required)
00209 {
00210 Reference_Count result =
00211 --this->reference_count_;
00212
00213 if (result == 0)
00214 delete this;
00215
00216 return result;
00217 }
00218 else
00219 {
00220 return 1;
00221 }
00222 }
00223
00224 ACE_Event_Handler::Policy::~Policy (void)
00225 {
00226 }
00227
00228 ACE_Event_Handler::Reference_Counting_Policy::Reference_Counting_Policy (Reference_Counting_Policy::Value value)
00229 : value_ (value)
00230 {
00231 }
00232
00233 ACE_Event_Handler::Reference_Counting_Policy::Value
00234 ACE_Event_Handler::Reference_Counting_Policy::value (void) const
00235 {
00236 return this->value_;
00237 }
00238
00239 void
00240 ACE_Event_Handler::Reference_Counting_Policy::value (ACE_Event_Handler::Reference_Counting_Policy::Value value)
00241 {
00242 this->value_ = value;
00243 }
00244
00245 ACE_Event_Handler::Reference_Counting_Policy &
00246 ACE_Event_Handler::reference_counting_policy (void)
00247 {
00248 return this->reference_counting_policy_;
00249 }
00250
00251
00252
00253 ACE_THR_FUNC_RETURN
00254 ACE_Event_Handler::read_adapter (void *args)
00255 {
00256 ACE_Event_Handler *this_ptr = static_cast<ACE_Event_Handler *> (args);
00257 ACE_Reactor *r = this_ptr->reactor ();
00258
00259 while (this_ptr->handle_input (ACE_STDIN) != -1)
00260 continue;
00261
00262 this_ptr->handle_close (ACE_STDIN, ACE_Event_Handler::READ_MASK);
00263
00264
00265 r->notify ();
00266
00267 return 0;
00268 }
00269
00270 int
00271 ACE_Event_Handler::register_stdin_handler (ACE_Event_Handler *eh,
00272 ACE_Reactor *reactor,
00273 ACE_Thread_Manager *thr_mgr,
00274 int flags)
00275 {
00276 #if defined (ACE_WIN32)
00277 ACE_UNUSED_ARG (reactor);
00278
00279 eh->reactor (reactor);
00280 return thr_mgr->spawn (&read_adapter, static_cast<void *> (eh), flags);
00281 #else
00282
00283 ACE_UNUSED_ARG (flags);
00284 ACE_UNUSED_ARG (thr_mgr);
00285 return reactor->register_handler (ACE_STDIN,
00286 eh,
00287 ACE_Event_Handler::READ_MASK);
00288 #endif
00289 }
00290
00291 int
00292 ACE_Event_Handler::remove_stdin_handler (ACE_Reactor *reactor,
00293 ACE_Thread_Manager *thr_mgr)
00294 {
00295 #if defined (ACE_WIN32)
00296 ACE_UNUSED_ARG (reactor);
00297 ACE_UNUSED_ARG (thr_mgr);
00298
00299
00300 ACE_NOTSUP_RETURN (-1);
00301 #else
00302
00303 ACE_UNUSED_ARG (thr_mgr);
00304 return reactor->remove_handler (ACE_STDIN,
00305 ACE_Event_Handler::READ_MASK);
00306 #endif
00307 }
00308
00309
00310
00311 ACE_Event_Handler_var::ACE_Event_Handler_var (void)
00312 : ptr_ (0)
00313 {
00314 }
00315
00316 ACE_Event_Handler_var::ACE_Event_Handler_var (ACE_Event_Handler *p)
00317 : ptr_ (p)
00318 {
00319 }
00320
00321 ACE_Event_Handler_var::ACE_Event_Handler_var (const ACE_Event_Handler_var &b)
00322 : ptr_ (b.ptr_)
00323 {
00324 if (this->ptr_ != 0)
00325 {
00326 this->ptr_->add_reference ();
00327 }
00328 }
00329
00330 ACE_Event_Handler_var::~ACE_Event_Handler_var (void)
00331 {
00332 if (this->ptr_ != 0)
00333 {
00334 this->ptr_->remove_reference ();
00335 }
00336 }
00337
00338 ACE_Event_Handler_var &
00339 ACE_Event_Handler_var::operator= (ACE_Event_Handler *p)
00340 {
00341 if (this->ptr_ == p)
00342 return *this;
00343
00344 if (this->ptr_ != 0)
00345 this->ptr_->remove_reference ();
00346
00347 this->ptr_ = p;
00348
00349 return *this;
00350 }
00351
00352 ACE_Event_Handler_var &
00353 ACE_Event_Handler_var::operator= (const ACE_Event_Handler_var &b)
00354 {
00355 if (this->ptr_ != b.ptr_)
00356 {
00357 if (this->ptr_ != 0)
00358 {
00359 this->ptr_->remove_reference ();
00360 }
00361
00362 if ((this->ptr_ = b.ptr_) != 0)
00363 {
00364 this->ptr_->add_reference ();
00365 }
00366 }
00367
00368 return *this;
00369 }
00370
00371 ACE_Event_Handler *
00372 ACE_Event_Handler_var::operator->() const
00373 {
00374 return this->ptr_;
00375 }
00376
00377 ACE_Event_Handler *
00378 ACE_Event_Handler_var::handler (void) const
00379 {
00380 return this->ptr_;
00381 }
00382
00383 ACE_Event_Handler *
00384 ACE_Event_Handler_var::release (void)
00385 {
00386 ACE_Event_Handler *old = this->ptr_;
00387 this->ptr_ = 0;
00388 return old;
00389 }
00390
00391 void
00392 ACE_Event_Handler_var::reset (ACE_Event_Handler *p)
00393 {
00394 *this = p;
00395 }
00396
00397 ACE_Notification_Buffer::ACE_Notification_Buffer (void)
00398 {
00399 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
00400 }
00401
00402 ACE_Notification_Buffer::ACE_Notification_Buffer (ACE_Event_Handler *eh,
00403 ACE_Reactor_Mask mask)
00404 : eh_ (eh),
00405 mask_ (mask)
00406 {
00407 ACE_TRACE ("ACE_Notification_Buffer::ACE_Notification_Buffer");
00408 }
00409
00410 ACE_END_VERSIONED_NAMESPACE_DECL