00001
00002
00003
00004
00005
00006
00007
00008 #include "UdpInst.h"
00009 #include "UdpLoader.h"
00010
00011 #include "dds/DCPS/transport/framework/TransportDefs.h"
00012 #include "dds/DCPS/transport/framework/NetworkAddress.h"
00013
00014 #include "ace/Configuration.h"
00015
00016 #include <iostream>
00017 #include <sstream>
00018
00019 namespace OpenDDS {
00020 namespace DCPS {
00021
00022 UdpInst::UdpInst(const std::string& name)
00023 : TransportInst("udp", name),
00024 #if defined (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00025 send_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ),
00026 rcv_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00027 #else
00028 send_buffer_size_(0),
00029 rcv_buffer_size_(0)
00030 #endif
00031 {
00032 }
00033
00034 UdpTransport*
00035 UdpInst::new_impl(const TransportInst_rch& inst)
00036 {
00037 return new UdpTransport(inst);
00038 }
00039
00040 int
00041 UdpInst::load(ACE_Configuration_Heap& cf,
00042 ACE_Configuration_Section_Key& sect)
00043 {
00044 TransportInst::load(cf, sect);
00045
00046 ACE_TString local_address_s;
00047 GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("local_address"),
00048 local_address_s);
00049 this->local_address(ACE_TEXT_ALWAYS_CHAR(local_address_s.c_str()));
00050
00051 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("send_buffer_size"), this->send_buffer_size_, ACE_UINT32);
00052
00053 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("rcv_buffer_size"), this->rcv_buffer_size_, ACE_UINT32);
00054
00055 return 0;
00056 }
00057
00058 OPENDDS_STRING
00059 UdpInst::dump_to_str()
00060 {
00061 std::ostringstream os;
00062 os << TransportInst::dump_to_str() << std::endl;
00063
00064 os << formatNameForDump("local_address") << this->local_address().get_host_addr()
00065 << ":" << this->local_address().get_port_number() << std::endl;
00066 os << formatNameForDump("send_buffer_size") << this->send_buffer_size_ << std::endl;
00067 os << formatNameForDump("rcv_buffer_size") << this->rcv_buffer_size_ << std::endl;
00068 return OPENDDS_STRING(os.str());
00069 }
00070
00071 size_t
00072 UdpInst::populate_locator(OpenDDS::DCPS::TransportLocator& info) const
00073 {
00074 if (this->local_address() != ACE_INET_Addr()) {
00075 NetworkAddress network_address;
00076 if (!this->local_address_string().empty()) {
00077 network_address = NetworkAddress(this->local_address_string());
00078 } else {
00079 network_address = NetworkAddress(this->local_address(), true);
00080 }
00081 ACE_OutputCDR cdr;
00082 cdr << network_address;
00083
00084 const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length());
00085 char* buffer = const_cast<char*>(cdr.buffer());
00086
00087 info.transport_type = "udp";
00088 info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer));
00089 return 1;
00090 } else {
00091 return 0;
00092 }
00093 }
00094
00095 }
00096 }