00001 // $Id: IIOP_Current_Impl.cpp 81738 2008-05-20 12:13:49Z elliott_c $ 00002 00003 #include "ace/INET_Addr.h" 00004 #include "tao/IIOP_Connection_Handler.h" 00005 #include "tao/IIOP_Transport.h" 00006 #include "tao/Transport_Selection_Guard.h" 00007 #include "tao/SystemException.h" 00008 00009 #if TAO_HAS_TRANSPORT_CURRENT == 1 00010 00011 #include "IIOP_Current_Impl.h" 00012 00013 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00014 00015 00016 namespace TAO 00017 { 00018 namespace Transport 00019 { 00020 00021 00022 /// Obtains the IIOP_Connection_Handler associated with the 00023 /// Transport. Will throw NoContext if the (selected) transport 00024 /// () == 0, or if transport->connection_handler () == 0. Will 00025 /// throw NoContext, if no transport has been selected yet. 00026 00027 TAO_IIOP_Connection_Handler* 00028 IIOP_Current_Impl::handler (void) 00029 { 00030 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00031 const TAO_Transport* t = this->transport (); 00032 if (t == 0) 00033 throw NoContext (); 00034 00035 TAO_Connection_Handler *ch = const_cast<TAO_Transport*>(t)->connection_handler (); 00036 if (ch == 0) 00037 throw NoContext (); 00038 00039 // Make sure that this connection handler is for IIOP. This 00040 // implementation is not intended to operate under SSLIOP. 00041 TAO_IIOP_Connection_Handler* iiop_ch = 00042 dynamic_cast <TAO_IIOP_Connection_Handler*> (ch); 00043 if (iiop_ch == 0) 00044 throw NoContext (); 00045 00046 return iiop_ch; 00047 #else 00048 throw ::CORBA::NO_IMPLEMENT (); 00049 #endif 00050 } 00051 00052 00053 /// Ctor 00054 00055 IIOP_Current_Impl::IIOP_Current_Impl (TAO_ORB_Core* core, size_t tss_slot_id) 00056 : Current_Impl (core, tss_slot_id) 00057 { 00058 } 00059 00060 00061 /// Dtor 00062 00063 IIOP_Current_Impl::~IIOP_Current_Impl (void) 00064 { 00065 } 00066 00067 CORBA::Long 00068 IIOP_Current_Impl::id (void) 00069 { 00070 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00071 // Need to use cast to pacify windows compilers complaining 00072 // about the implicit HANDLE -> CORBA::Long conversion. 00073 return (CORBA::Long) this->handler ()->get_handle (); 00074 #else 00075 throw ::CORBA::NO_IMPLEMENT (); 00076 #endif 00077 } 00078 00079 ::SSLIOP::Current_ptr 00080 IIOP_Current_Impl::ssliop_current (void) 00081 { 00082 throw ::CORBA::NO_IMPLEMENT (); 00083 } 00084 00085 00086 CORBA::Long 00087 IIOP_Current_Impl::remote_port (void) 00088 { 00089 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00090 TAO_IIOP_Connection_Handler *iiopch = 00091 this->handler (); 00092 00093 ACE_INET_Addr a; 00094 iiopch->peer ().get_remote_addr (a); 00095 00096 return a.get_port_number (); 00097 #else 00098 throw ::CORBA::NO_IMPLEMENT (); 00099 #endif 00100 } 00101 00102 char* 00103 IIOP_Current_Impl::remote_host (void) 00104 { 00105 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00106 TAO_IIOP_Connection_Handler *iiopch = 00107 this->handler (); 00108 00109 ACE_INET_Addr a; 00110 iiopch->peer ().get_remote_addr (a); 00111 00112 return CORBA::string_dup (a.get_host_addr ()); 00113 #else 00114 throw ::CORBA::NO_IMPLEMENT (); 00115 #endif 00116 } 00117 00118 CORBA::Long 00119 IIOP_Current_Impl::local_port (void) 00120 { 00121 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00122 TAO_IIOP_Connection_Handler *iiopch = 00123 this->handler (); 00124 00125 ACE_INET_Addr a; 00126 iiopch->peer ().get_local_addr (a); 00127 00128 return a.get_port_number (); 00129 #else 00130 throw ::CORBA::NO_IMPLEMENT (); 00131 #endif 00132 } 00133 00134 char* 00135 IIOP_Current_Impl::local_host (void) 00136 { 00137 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0) 00138 TAO_IIOP_Connection_Handler *iiopch = 00139 this->handler (); 00140 00141 ACE_INET_Addr a; 00142 iiopch->peer ().get_local_addr (a); 00143 00144 return CORBA::string_dup (a.get_host_addr ()); 00145 #else 00146 throw ::CORBA::NO_IMPLEMENT (); 00147 #endif 00148 } 00149 00150 } 00151 } 00152 00153 00154 TAO_END_VERSIONED_NAMESPACE_DECL 00155 00156 00157 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */