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 
00019 #if !defined (__ACE_INLINE__)
00020 # include "TransportInst.inl"
00021 #endif /* !__ACE_INLINE__ */
00022 
00023 OpenDDS::DCPS::TransportInst::~TransportInst()
00024 {
00025   DBG_ENTRY_LVL("TransportInst","~TransportInst",6);
00026 }
00027 
00028 int
00029 OpenDDS::DCPS::TransportInst::load(ACE_Configuration_Heap& cf,
00030                                    ACE_Configuration_Section_Key& sect)
00031 {
00032   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("queue_messages_per_pool"), this->queue_messages_per_pool_, size_t)
00033   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("queue_initial_pools"), this->queue_initial_pools_, size_t)
00034   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("max_packet_size"), this->max_packet_size_, ACE_UINT32)
00035   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("max_samples_per_packet"), this->max_samples_per_packet_, size_t)
00036   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("optimum_packet_size"), this->optimum_packet_size_, ACE_UINT32)
00037   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("thread_per_connection"), this->thread_per_connection_, bool)
00038   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("datalink_release_delay"), this->datalink_release_delay_, int)
00039 
00040   // Undocumented - this option is not in the Developer's Guide
00041   // Controls the number of chunks in the allocators used by the datalink
00042   // for control messages.
00043   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("datalink_control_chunks"), this->datalink_control_chunks_, size_t)
00044 
00045   ACE_TString stringvalue;
00046   if (cf.get_string_value (sect, ACE_TEXT("passive_connect_duration"), stringvalue) == 0) {
00047     ACE_DEBUG ((LM_WARNING,
00048                 ACE_TEXT ("(%P|%t) WARNING: passive_connect_duration option ")
00049                 ACE_TEXT ("is deprecated in the transport inst, must be ")
00050                 ACE_TEXT ("defined in transport config.\n")));
00051   }
00052 
00053   adjust_config_value();
00054   return 0;
00055 }
00056 
00057 void
00058 OpenDDS::DCPS::TransportInst::dump()
00059 {
00060   ACE_DEBUG((LM_DEBUG,
00061              ACE_TEXT("\n(%P|%t) TransportInst::dump() -\n%C"),
00062              dump_to_str().c_str()));
00063 }
00064 
00065 namespace {
00066   static const int NAME_INDENT(3);
00067   static const int NAME_WIDTH(30); // Includes ":"
00068 }
00069 
00070 OPENDDS_STRING
00071 OpenDDS::DCPS::TransportInst::formatNameForDump(const char* name)
00072 {
00073   OPENDDS_STRING formatted_name;
00074   formatted_name.reserve(NAME_INDENT + NAME_WIDTH);
00075   formatted_name += OPENDDS_STRING(NAME_INDENT, ' ');
00076   formatted_name += name;
00077   formatted_name += ":";
00078   if ((NAME_WIDTH + NAME_INDENT) > formatted_name.length()) {
00079     formatted_name += OPENDDS_STRING((NAME_WIDTH + NAME_INDENT- formatted_name.length()), ' ');
00080   }
00081   return formatted_name;
00082 }
00083 
00084 OPENDDS_STRING
00085 OpenDDS::DCPS::TransportInst::dump_to_str()
00086 {
00087   OPENDDS_STRING ret;
00088   ret += formatNameForDump("transport_type")          + this->transport_type_ + '\n';
00089   ret += formatNameForDump("name")                    + this->name_ + '\n';
00090   ret += formatNameForDump("queue_messages_per_pool") + to_dds_string(unsigned(this->queue_messages_per_pool_)) + '\n';
00091   ret += formatNameForDump("queue_initial_pools")     + to_dds_string(unsigned(this->queue_initial_pools_)) + '\n';
00092   ret += formatNameForDump("max_packet_size")         + to_dds_string(unsigned(this->max_packet_size_)) + '\n';
00093   ret += formatNameForDump("max_samples_per_packet")  + to_dds_string(unsigned(this->max_samples_per_packet_)) + '\n';
00094   ret += formatNameForDump("optimum_packet_size")     + to_dds_string(unsigned(this->optimum_packet_size_)) + '\n';
00095   ret += formatNameForDump("thread_per_connection")   + (this->thread_per_connection_ ? "true" : "false") + '\n';
00096   ret += formatNameForDump("datalink_release_delay")  + to_dds_string(this->datalink_release_delay_) + '\n';
00097   ret += formatNameForDump("datalink_control_chunks") + to_dds_string(unsigned(this->datalink_control_chunks_)) + '\n';
00098   return ret;
00099 }
00100 
00101 void
00102 OpenDDS::DCPS::TransportInst::shutdown()
00103 {
00104   ACE_GUARD(ACE_SYNCH_MUTEX, g, this->lock_);
00105   if (!this->impl_.is_nil()) {
00106     this->impl_->shutdown();
00107     this->impl_ = 0;
00108   }
00109 }
00110 
00111 OpenDDS::DCPS::TransportImpl_rch
00112 OpenDDS::DCPS::TransportInst::impl()
00113 {
00114   ACE_GUARD_RETURN(ACE_SYNCH_MUTEX, g, this->lock_, TransportImpl_rch());
00115   if (this->impl_.is_nil()) {
00116     try {
00117       this->impl_ = this->new_impl(TransportInst_rch(this, false));
00118     } catch (const OpenDDS::DCPS::Transport::UnableToCreate& ) {
00119       return 0;
00120     }
00121   }
00122   return this->impl_;
00123 }

Generated on Fri Feb 12 20:05:28 2016 for OpenDDS by  doxygen 1.4.7