00001 /* -*- C++ -*- */ 00002 00003 /** 00004 * @file Current_Impl.cpp 00005 * 00006 * $Id: Current_Impl.cpp 83332 2008-10-20 13:52:34Z johnnyw $ 00007 * 00008 * @author Iliyan Jeliazkov <iliyan@ociweb.com> 00009 * 00010 */ 00011 00012 #include "tao/Transport.h" 00013 00014 #if TAO_HAS_TRANSPORT_CURRENT == 1 00015 00016 #include "tao/Transport_Selection_Guard.h" 00017 #include "tao/TransportCurrent/Current_Loader.h" 00018 #include "tao/TransportCurrent/Current_Impl.h" 00019 00020 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00021 00022 00023 namespace TAO 00024 { 00025 namespace Transport 00026 { 00027 00028 /// ctor 00029 Current_Impl::Current_Impl (TAO_ORB_Core* core, size_t tss_slot_id) 00030 : core_ (core) 00031 , tss_slot_id_ (tss_slot_id) 00032 { 00033 } 00034 00035 /// dtor 00036 Current_Impl::~Current_Impl (void) 00037 { 00038 } 00039 00040 /// Obtains the current transport. Throws a NoContext exception 00041 /// if, there was no "current" transport selected on the current 00042 /// thread. 00043 const TAO_Transport* 00044 Current_Impl::transport (void) const 00045 { 00046 Transport_Selection_Guard* topguard = 00047 Transport_Selection_Guard::current (this->core_, this->tss_slot_id_); 00048 00049 if (topguard == 0) 00050 throw NoContext(); 00051 00052 return topguard->get (); 00053 } 00054 00055 static const TAO::Transport::Stats dummy_transport_stats; 00056 00057 /// Obtains the current transport's stats 00058 const TAO::Transport::Stats* 00059 Current_Impl::transport_stats (void) const 00060 { 00061 static const TAO::Transport::Stats dummy; 00062 00063 const TAO_Transport* t = this->transport (); 00064 00065 return (t==0 || t->stats () == 0) ? &dummy_transport_stats : t->stats (); 00066 } 00067 00068 CORBA::Long Current_Impl::id (void) 00069 { 00070 const TAO_Transport* t = this->transport (); 00071 00072 return (t==0) ? 0 : t->id (); 00073 } 00074 00075 CounterT Current_Impl::bytes_sent (void) 00076 { 00077 return transport_stats ()->bytes_sent (); 00078 } 00079 00080 CounterT Current_Impl::bytes_received (void) 00081 { 00082 return transport_stats ()->bytes_received (); 00083 } 00084 00085 CounterT Current_Impl::messages_sent (void) 00086 { 00087 return transport_stats ()->messages_sent (); 00088 } 00089 00090 CounterT Current_Impl::messages_received (void) 00091 { 00092 return transport_stats ()->messages_received (); 00093 } 00094 00095 TimeBase::TimeT Current_Impl::open_since (void) 00096 { 00097 TimeBase::TimeT msecs = 0; 00098 transport_stats ()->opened_since ().msec (msecs); 00099 return msecs; 00100 } 00101 00102 } 00103 00104 } 00105 00106 TAO_END_VERSIONED_NAMESPACE_DECL 00107 00108 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */ 00109