TransportInst.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "DCPS/DdsDcps_pch.h" //Only the _pch include should start with DCPS/
00009 #include "TransportInst.h"
00010 #include "TransportImpl.h"
00011 #include "TransportExceptions.h"
00012 #include "EntryExit.h"
00013 #include "DCPS/SafetyProfileStreams.h"
00014 
00015 #include "ace/Configuration.h"
00016 
00017 #include <cstring>
00018 #include <algorithm>
00019 
00020 #if !defined (__ACE_INLINE__)
00021 # include "TransportInst.inl"
00022 #endif /* !__ACE_INLINE__ */
00023 
00024 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00025 
00026 OpenDDS::DCPS::TransportInst::~TransportInst()
00027 {
00028   DBG_ENTRY_LVL("TransportInst","~TransportInst",6);
00029 }
00030 
00031 int
00032 OpenDDS::DCPS::TransportInst::load(ACE_Configuration_Heap& cf,
00033                                    ACE_Configuration_Section_Key& sect)
00034 {
00035   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("queue_messages_per_pool"), this->queue_messages_per_pool_, size_t)
00036   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("queue_initial_pools"), this->queue_initial_pools_, size_t)
00037   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("max_packet_size"), this->max_packet_size_, ACE_UINT32)
00038   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("max_samples_per_packet"), this->max_samples_per_packet_, size_t)
00039   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("optimum_packet_size"), this->optimum_packet_size_, ACE_UINT32)
00040   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("thread_per_connection"), this->thread_per_connection_, bool)
00041   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("datalink_release_delay"), this->datalink_release_delay_, int)
00042 
00043   // Undocumented - this option is not in the Developer's Guide
00044   // Controls the number of chunks in the allocators used by the datalink
00045   // for control messages.
00046   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("datalink_control_chunks"), this->datalink_control_chunks_, size_t)
00047 
00048   ACE_TString stringvalue;
00049   if (cf.get_string_value (sect, ACE_TEXT("passive_connect_duration"), stringvalue) == 0) {
00050     ACE_DEBUG ((LM_WARNING,
00051                 ACE_TEXT ("(%P|%t) WARNING: passive_connect_duration option ")
00052                 ACE_TEXT ("is deprecated in the transport inst, must be ")
00053                 ACE_TEXT ("defined in transport config.\n")));
00054   }
00055 
00056   adjust_config_value();
00057   return 0;
00058 }
00059 
00060 void
00061 OpenDDS::DCPS::TransportInst::dump() const
00062 {
00063   ACE_DEBUG((LM_DEBUG,
00064              ACE_TEXT("\n(%P|%t) TransportInst::dump() -\n%C"),
00065              dump_to_str().c_str()));
00066 }
00067 
00068 namespace {
00069   static const int NAME_INDENT(3);
00070   static const int NAME_WIDTH(30); // Includes ":"
00071 }
00072 
00073 OPENDDS_STRING
00074 OpenDDS::DCPS::TransportInst::formatNameForDump(const char* name)
00075 {
00076   OPENDDS_STRING formatted_name;
00077   formatted_name.reserve(NAME_INDENT + NAME_WIDTH);
00078   formatted_name += OPENDDS_STRING(NAME_INDENT, ' ');
00079   formatted_name += name;
00080   formatted_name += ":";
00081   if ((NAME_WIDTH + NAME_INDENT) > formatted_name.length()) {
00082     formatted_name += OPENDDS_STRING((NAME_WIDTH + NAME_INDENT- formatted_name.length()), ' ');
00083   }
00084   return formatted_name;
00085 }
00086 
00087 OPENDDS_STRING
00088 OpenDDS::DCPS::TransportInst::dump_to_str() const
00089 {
00090   OPENDDS_STRING ret;
00091   ret += formatNameForDump("transport_type")          + this->transport_type_ + '\n';
00092   ret += formatNameForDump("name")                    + this->name_ + '\n';
00093   ret += formatNameForDump("queue_messages_per_pool") + to_dds_string(unsigned(this->queue_messages_per_pool_)) + '\n';
00094   ret += formatNameForDump("queue_initial_pools")     + to_dds_string(unsigned(this->queue_initial_pools_)) + '\n';
00095   ret += formatNameForDump("max_packet_size")         + to_dds_string(unsigned(this->max_packet_size_)) + '\n';
00096   ret += formatNameForDump("max_samples_per_packet")  + to_dds_string(unsigned(this->max_samples_per_packet_)) + '\n';
00097   ret += formatNameForDump("optimum_packet_size")     + to_dds_string(unsigned(this->optimum_packet_size_)) + '\n';
00098   ret += formatNameForDump("thread_per_connection")   + (this->thread_per_connection_ ? "true" : "false") + '\n';
00099   ret += formatNameForDump("datalink_release_delay")  + to_dds_string(this->datalink_release_delay_) + '\n';
00100   ret += formatNameForDump("datalink_control_chunks") + to_dds_string(unsigned(this->datalink_control_chunks_)) + '\n';
00101   return ret;
00102 }
00103 
00104 void
00105 OpenDDS::DCPS::TransportInst::shutdown()
00106 {
00107   ACE_GUARD(ACE_SYNCH_MUTEX, g, this->lock_);
00108   if (!this->impl_.is_nil()) {
00109     this->impl_->shutdown();
00110   }
00111 }
00112 
00113 OpenDDS::DCPS::TransportImpl*
00114 OpenDDS::DCPS::TransportInst::impl()
00115 {
00116   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, g, this->lock_, 0);
00117   if (!this->impl_) {
00118     try {
00119       this->impl_ = this->new_impl();
00120     } catch (const OpenDDS::DCPS::Transport::UnableToCreate& ) {
00121       return 0;
00122     }
00123   }
00124   return this->impl_.in();
00125 }
00126 
00127 void
00128 OpenDDS::DCPS::TransportInst::set_port_in_addr_string(OPENDDS_STRING& addr_str, u_short port_number)
00129 {
00130 #ifdef BUFSIZE
00131 #undef BUFSIZE
00132 #endif
00133   const int BUFSIZE=1024;
00134   char result[BUFSIZE];
00135 
00136 #ifdef __SUNPRO_CC
00137   int count = 0;
00138   std::count(addr_str.begin(), addr_str.end(), ':', count);
00139   if (count < 2) {
00140 #else
00141   if (std::count(addr_str.begin(), addr_str.end(), ':') < 2) {
00142 #endif
00143     OPENDDS_STRING::size_type pos = addr_str.find_last_of(":");
00144     ACE_OS::snprintf(result, BUFSIZE, "%.*s:%hu", static_cast<int>(pos), addr_str.c_str(), port_number);
00145   }
00146   else {
00147     // this is the numeric form of ipv6 address because it has more than one ':'
00148     if (addr_str[0] != '[') {
00149       ACE_OS::snprintf(result, BUFSIZE, "[%s]:%hu", addr_str.c_str(), port_number);
00150     }
00151     else {
00152       OPENDDS_STRING::size_type pos = addr_str.find_last_of("]");
00153       ACE_OS::snprintf(result, BUFSIZE, "%.*s:%hu", static_cast<int>(pos+1), addr_str.c_str(), port_number);
00154     }
00155   }
00156   addr_str = result;
00157 }
00158 
00159 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1