00001 // QoS_Decorator.cpp 00002 // $Id: QoS_Decorator.cpp 80826 2008-03-04 14:51:23Z wotte $ 00003 00004 #include "QoS_Decorator.h" 00005 00006 ACE_RCSID(ace, QoS_Decorator, "$Id: QoS_Decorator.cpp 80826 2008-03-04 14:51:23Z wotte $") 00007 00008 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00009 00010 ACE_ALLOC_HOOK_DEFINE(ACE_QOS_DECORATOR) 00011 00012 // Constructor. 00013 ACE_QoS_Decorator_Base::ACE_QoS_Decorator_Base (void) 00014 {} 00015 00016 // Constructor. 00017 ACE_QoS_Decorator_Base::ACE_QoS_Decorator_Base (ACE_Event_Handler 00018 *event_handler) 00019 : event_handler_ (event_handler) 00020 { 00021 } 00022 00023 // Destructor. 00024 ACE_QoS_Decorator_Base::~ACE_QoS_Decorator_Base (void) 00025 { 00026 } 00027 00028 // Forward the call to ACE_Event_Handler component. 00029 ACE_HANDLE 00030 ACE_QoS_Decorator_Base::get_handle (void) const 00031 { 00032 return this->event_handler_->get_handle (); 00033 } 00034 00035 // Forward the call to ACE_Event_Handler component. 00036 int 00037 ACE_QoS_Decorator_Base::handle_input (ACE_HANDLE fd) 00038 { 00039 return this->event_handler_->handle_input (fd); 00040 } 00041 00042 // Forward the call to ACE_Event_Handler component. 00043 int 00044 ACE_QoS_Decorator_Base::handle_qos (ACE_HANDLE fd) 00045 { 00046 return this->event_handler_->handle_qos (fd); 00047 } 00048 00049 // Constructor. 00050 ACE_QoS_Decorator::ACE_QoS_Decorator (void) 00051 {} 00052 00053 // Constructor. 00054 ACE_QoS_Decorator::ACE_QoS_Decorator (ACE_Event_Handler *event_handler, 00055 ACE_QoS_Session *qos_session, 00056 ACE_Reactor *reactor) 00057 : qos_session_ (qos_session), 00058 reactor_ (reactor) 00059 { 00060 ACE_NEW (this->decorator_base_, 00061 ACE_QoS_Decorator_Base (event_handler)); 00062 00063 ACE_NEW (this->qos_event_handler_, 00064 ACE_QoS_Event_Handler (this->decorator_base_)); 00065 } 00066 00067 // Destructor. 00068 ACE_QoS_Decorator::~ACE_QoS_Decorator (void) 00069 { 00070 delete this->decorator_base_; 00071 delete this->qos_event_handler_; 00072 } 00073 00074 // Implements the undecorated functionality. This is sufficient for 00075 // GQoS. RAPI needs additional QoS decoration. This is done by the 00076 // ACE_QoS_Event_Handler class. 00077 ACE_HANDLE 00078 ACE_QoS_Decorator::get_handle (void) const 00079 { 00080 return this->decorator_base_->get_handle (); 00081 } 00082 00083 // Implements the undecorated functionality. This is sufficient for 00084 // GQoS. RAPI needs additional QoS decoration. This is done by the 00085 // ACE_QoS_Event_Handler class. 00086 int 00087 ACE_QoS_Decorator::handle_input (ACE_HANDLE fd) 00088 { 00089 return this->decorator_base_->handle_input (fd); 00090 } 00091 00092 // Implements the undecorated functionality. This is sufficient for 00093 // GQoS. RAPI needs additional QoS decoration. This is done by the 00094 // ACE_QoS_Event_Handler class. 00095 int 00096 ACE_QoS_Decorator::handle_qos (ACE_HANDLE fd) 00097 { 00098 return this->decorator_base_->handle_qos (fd); 00099 } 00100 00101 // This method registers the RAPI QoS event handler with the reactor 00102 // if the application is using RAPI. Note that it is a no-op for GQoS 00103 // because an extra socket for handling QoS events is not required. 00104 int 00105 ACE_QoS_Decorator::init (void) 00106 { 00107 #if defined (ACE_HAS_RAPI) 00108 00109 // Pass the QoS session to QoS Event Handler. 00110 this->qos_event_handler_->qos_session (this->qos_session_); 00111 00112 // Register the QoS Event Handler with the Reactor. 00113 return this->reactor_->register_handler (this->qos_event_handler_, 00114 ACE_Event_Handler::READ_MASK); 00115 #endif 00116 return 0; 00117 00118 } 00119 00120 // Constructor. 00121 ACE_QoS_Event_Handler::ACE_QoS_Event_Handler (void) 00122 { 00123 } 00124 00125 // Constructor. 00126 ACE_QoS_Event_Handler::ACE_QoS_Event_Handler (ACE_QoS_Decorator_Base 00127 *decorator_base) 00128 : decorator_base_ (decorator_base) 00129 { 00130 } 00131 00132 // Destructor. 00133 ACE_QoS_Event_Handler::~ACE_QoS_Event_Handler (void) 00134 { 00135 } 00136 00137 // Set the QoS session. 00138 void 00139 ACE_QoS_Event_Handler::qos_session (ACE_QoS_Session *qos_session) 00140 { 00141 this->qos_session_ = qos_session; 00142 } 00143 00144 // Returns the RAPI file descriptor for listening to RAPI evnets. 00145 ACE_HANDLE 00146 ACE_QoS_Event_Handler::get_handle (void) const 00147 { 00148 return this->qos_session_->rsvp_events_handle (); 00149 } 00150 00151 // Note, here the handle_input () calls the handle_qos () of the 00152 // Decorator Base which then calls handle_qos () of the 00153 // ACE_Event_Handler component within it. This helps to translate the 00154 // normal read events into qos events in case of RAPI so the 00155 // application using the API is oblivious to the fact that in RAPI, 00156 // QoS events are received on a different socket. This helps to 00157 // maintain a uniform design for the application irrespective of 00158 // whether it is using RAPI or GQoS. 00159 int 00160 ACE_QoS_Event_Handler::handle_input (ACE_HANDLE fd) 00161 { 00162 return this->decorator_base_->handle_qos (fd); 00163 } 00164 00165 ACE_END_VERSIONED_NAMESPACE_DECL