00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Connection_Handler.h 00006 * 00007 * Connection_Handler.h,v 1.48 2005/11/24 11:05:44 ossama Exp 00008 * 00009 * @author Balachandran Natarajan <bala@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef TAO_CONNECTION_HANDLER_H 00014 #define TAO_CONNECTION_HANDLER_H 00015 00016 #include /**/ "ace/pre.h" 00017 00018 #include "tao/LF_CH_Event.h" 00019 00020 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00021 # pragma once 00022 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00023 00024 #include "tao/Basic_Types.h" 00025 00026 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00027 class ACE_SOCK; 00028 class ACE_Lock; 00029 class ACE_Event_Handler; 00030 ACE_END_VERSIONED_NAMESPACE_DECL 00031 00032 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00033 00034 class TAO_ORB_Core; 00035 class TAO_Transport; 00036 00037 /* 00038 * Hook to specialize the connection handler with the 00039 * concrete connection handler implementation. 00040 */ 00041 //@@ CONNECTION_HANDLER_SPL_INCLUDE_FORWARD_DECL_ADD_HOOK 00042 00043 /** 00044 * @class TAO_Connection_Handler 00045 * 00046 * @brief TAO_Connection_Handler 00047 * 00048 * This class is an abstraction for the connection handlers. The 00049 * connections handler in every protocol can derive from this 00050 * class as well as the ACE_Svc_Handler specialised for the 00051 * right protocol. This way, most of the common code for the 00052 * different protocols would be in this implementation. 00053 */ 00054 class TAO_Export TAO_Connection_Handler : public TAO_LF_CH_Event 00055 { 00056 public: 00057 00058 /// Constructor 00059 TAO_Connection_Handler (void); 00060 00061 /// Constructor 00062 TAO_Connection_Handler (TAO_ORB_Core *orb_core); 00063 00064 /// Destructor 00065 virtual ~TAO_Connection_Handler (void); 00066 00067 /// Return the underlying transport object 00068 TAO_Transport *transport (void); 00069 00070 /// Set the underlying transport object 00071 void transport (TAO_Transport* transport); 00072 00073 /// Is the handler closed? 00074 bool is_closed (void) const; 00075 00076 /// Is the handler open? 00077 bool is_open (void) const; 00078 00079 /// Is the handler in the process of being connected? 00080 bool is_connecting (void) const; 00081 00082 /// Close the underlying connection. 00083 /** 00084 * Used by the ORB to actively close connections that are idle, 00085 * stale or somehow are determined to be broken before the Reactor 00086 * does. 00087 * 00088 * @return Return 0 if the connection was already closed, non-zero 00089 * otherwise. 00090 */ 00091 virtual int close_connection (void) = 0; 00092 00093 /// The event handler calls, here so that other objects who hold a 00094 /// reference to this object can call the event handler methods. 00095 virtual int handle_input (ACE_HANDLE fd) = 0; 00096 00097 /// This method is invoked from the svc () method of the Svc_Handler 00098 /// Object. 00099 int svc_i (void); 00100 00101 /// A open () hook 00102 /** 00103 * See Thread_Per_Connection_Handler for a use case 00104 */ 00105 virtual int open_handler (void *) = 0; 00106 00107 /// A close() hook, called by the Transport Connector when they want to close 00108 /// this handler 00109 virtual int close_handler (void); 00110 00111 /// Set the Diff-Serv codepoint on outgoing packets. Only has 00112 /// effect for remote protocols (e.g., IIOP); no effect for local 00113 /// protocols (UIOP). Default implementation is for local 00114 /// protocols. Remote protocols must overwrite implementation. 00115 virtual int set_dscp_codepoint (CORBA::Boolean set_network_priority); 00116 00117 /// Release the OS resources related to this handler. 00118 virtual int release_os_resources (void); 00119 00120 /* 00121 * Hook to add public methods from concrete connection handler 00122 * implementation onto the base connection handler. 00123 */ 00124 00125 //@@ CONNECTION_HANDLER_SPL_PUBLIC_METHODS_ADD_HOOK 00126 00127 protected: 00128 00129 /// Return our TAO_ORB_Core pointer 00130 TAO_ORB_Core *orb_core (void); 00131 00132 /// Set options on the socket 00133 int set_socket_option (ACE_SOCK &sock, 00134 int snd_size, 00135 int rcv_size); 00136 00137 //@{ 00138 /** 00139 * @name Helper methods for Event_Handler-based derived classes. 00140 * 00141 * Many (actually all so far) implementations of 00142 * TAO_Connection_Handler are a mixin of TAO_Connection_Handler and 00143 * some form of ACE_Event_Handler. The following methods simplify 00144 * such implementations by capturing the common code in a single 00145 * place. 00146 */ 00147 00148 /// Implement the handle_output() callback 00149 int handle_output_eh (ACE_HANDLE h, ACE_Event_Handler * eh); 00150 00151 /// Implement the handle_input() callback 00152 // We're actually going to pull the code from the protocol-specific 00153 // handlers back into this class, because they ALL look exactly the same. 00154 // If some other protocol comes along and needs to do something different, 00155 // it is always free to override handle_input() as it sees fit. 00156 int handle_input_eh (ACE_HANDLE h, ACE_Event_Handler * eh); 00157 int handle_input_internal (ACE_HANDLE h, ACE_Event_Handler *eh); 00158 00159 /// Implement close_connection() for Connection_Handlers that are 00160 /// also Event_Handlers. 00161 int close_connection_eh (ACE_Event_Handler * eh); 00162 00163 /// Pre-invocation hook for I/O operations (handle_input() & 00164 /// handle_output()) 00165 /** 00166 * See the SSLIOP protocol for an interesting use-case 00167 */ 00168 virtual void pre_io_hook (int & return_value); 00169 00170 /// Post-invocation hook for I/O operations (handle_input() & 00171 /// handle_output()) 00172 /** 00173 * See the SSLIOP protocol for an interesting use-case 00174 */ 00175 virtual void pos_io_hook (int & return_value); 00176 //@} 00177 00178 00179 private: 00180 /// Pointer to the TAO_ORB_Core 00181 TAO_ORB_Core * const orb_core_; 00182 00183 /// Transport object reference 00184 TAO_Transport* transport_; 00185 00186 /// Internal state lock, needs to be separate from the reference 00187 /// count / pending upcalls lock because they interleave. 00188 ACE_Lock * lock_; 00189 00190 /* 00191 * Hook to add instance members from derived class 00192 * onto base Connection_Handler class. Any further 00193 * additions to this class should go before this 00194 * hook. 00195 */ 00196 //@@ CONNECTION_HANDLER_SPL_PRIVATE_DATA_ADD_HOOK 00197 }; 00198 00199 //@@ CONNECTION_HANDLER_SPL_EXTERN_ADD_HOOK 00200 00201 TAO_END_VERSIONED_NAMESPACE_DECL 00202 00203 #if defined (__ACE_INLINE__) 00204 #include "tao/Connection_Handler.inl" 00205 #endif /* __ACE_INLINE__ */ 00206 00207 #include /**/ "ace/post.h" 00208 00209 #endif /*TAO_CONNECTION_HANDLER_H*/