OpenDDS  Snapshot(2023/04/28-20:55)
ShmemInst.cpp
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #include "ShmemInst.h"
7 #include "ShmemLoader.h"
8 
10 
11 #include <ace/Configuration.h>
12 #include <ace/OS_NS_unistd.h>
13 
14 #include <iostream>
15 #include <sstream>
16 
18 
19 namespace OpenDDS {
20 namespace DCPS {
21 
22 const TimeDuration ShmemInst::default_association_resend_period(0, 250000);
23 
24 ShmemInst::ShmemInst(const std::string& name)
25  : TransportInst("shmem", name)
26  , pool_size_(16 * 1024 * 1024)
27  , datalink_control_size_(4 * 1024)
28  , hostname_(get_fully_qualified_hostname())
29  , association_resend_period_(default_association_resend_period)
30 {
31  std::ostringstream pool;
32  pool << "OpenDDS-" << ACE_OS::getpid() << '-' << this->name();
33  poolname_ = pool.str();
34 }
35 
38 {
39  return make_rch<ShmemTransport>(rchandle_from(this));
40 }
41 
42 int
45 {
46  TransportInst::load(cf, sect);
47 
48  std::string host_name;
49  GET_CONFIG_STRING_VALUE(cf, sect, ACE_TEXT("host_name"), host_name);
50 
51  if (!host_name.empty()) {
52  hostname_ = host_name;
53  }
54 
55  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("pool_size"), pool_size_, size_t)
56  GET_CONFIG_VALUE(cf, sect, ACE_TEXT("datalink_control_size"),
57  datalink_control_size_, size_t)
58  GET_CONFIG_TIME_VALUE(cf, sect,
59  ACE_TEXT("association_resend_period"), association_resend_period_);
60 
61  return 0;
62 }
63 
66 {
67  std::ostringstream os;
69  os << formatNameForDump("pool_size") << pool_size_ << "\n"
70  << formatNameForDump("datalink_control_size") << datalink_control_size_ << "\n"
71  << formatNameForDump("pool_name") << this->poolname_ << "\n"
72  << formatNameForDump("host_name") << this->hostname_ << "\n"
73  << formatNameForDump("association_resend_period") << association_resend_period_.str() << "\n";
74  return OPENDDS_STRING(os.str());
75 }
76 
77 size_t
79 {
80  info.transport_type = "shmem";
81 
82  const size_t len = hostname_.size() + 1 /* null */ + poolname_.size();
83  info.data.length(static_cast<CORBA::ULong>(len));
84 
85  CORBA::Octet* buff = info.data.get_buffer();
86  std::memcpy(buff, hostname_.c_str(), hostname_.size());
87  buff += hostname_.size();
88 
89  *(buff++) = 0;
90  std::memcpy(buff, poolname_.c_str(), poolname_.size());
91 
92  return 1;
93 }
94 
95 } // namespace DCPS
96 } // namespace OpenDDS
97 
RcHandle< T > rchandle_from(T *pointer)
Definition: RcHandle_T.h:310
Base class to hold configuration settings for TransportImpls.
Definition: TransportInst.h:64
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
Definition: ShmemInst.cpp:43
std::string poolname_
Definition: ShmemInst.h:58
#define GET_CONFIG_STRING_VALUE(CF, SECT, KEY, VALUE)
Definition: TransportDefs.h:76
const OPENDDS_STRING & name() const
Definition: TransportInst.h:70
std::string hostname_
Definition: ShmemInst.h:57
#define OPENDDS_STRING
#define GET_CONFIG_VALUE(CF, SECT, KEY, VALUE, TYPE)
Definition: TransportDefs.h:45
const char *const name
Definition: debug.cpp:60
static const TimeDuration default_association_resend_period
Definition: ShmemInst.h:22
#define GET_CONFIG_TIME_VALUE(CF, SECT, KEY, VALUE)
ACE_TEXT("TCP_Factory")
virtual int load(ACE_Configuration_Heap &cf, ACE_Configuration_Section_Key &sect)
virtual OPENDDS_STRING dump_to_str() const
Definition: ShmemInst.cpp:65
String str(unsigned decimal_places=3, bool just_sec=false) const
ACE_CDR::Octet Octet
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
string transport_type
The transport type (e.g. tcp or udp)
String get_fully_qualified_hostname(ACE_INET_Addr *addr)
virtual size_t populate_locator(OpenDDS::DCPS::TransportLocator &trans_info, ConnectionInfoFlags flags) const
Populate a transport locator sequence. Return the number of "locators.".
Definition: ShmemInst.cpp:78
TransportImpl_rch new_impl()
Definition: ShmemInst.cpp:37
static OPENDDS_STRING formatNameForDump(const char *name)
ShmemInst(const std::string &name)
Definition: ShmemInst.cpp:24
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
pid_t getpid(void)
TimeDuration association_resend_period_
Definition: ShmemInst.h:59
virtual OPENDDS_STRING dump_to_str() const
size_t ConnectionInfoFlags