OpenDDS  Snapshot(2023/04/28-20:55)
TransportRegistry.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_TRANSPORT_FRAMEWORK_TRANSPORTREGISTRY_H
9 #define OPENDDS_DCPS_TRANSPORT_FRAMEWORK_TRANSPORTREGISTRY_H
10 
11 #include "dds/DCPS/dcps_export.h"
12 #include "TransportDefs.h"
13 #include "TransportImpl_rch.h"
15 #include "TransportType.h"
16 #include "TransportType_rch.h"
17 #include "TransportInst_rch.h"
18 #include "TransportConfig_rch.h"
19 #include "TransportConfig.h"
20 #include "dds/DCPS/PoolAllocator.h"
21 #include "dds/DCPS/ConfigUtils.h"
22 #include "dds/DdsDcpsInfrastructureC.h"
23 #include "ace/Synch_Traits.h"
24 
28 
30 
31 namespace DDS {
32  class Entity;
33  typedef Entity* Entity_ptr;
34 }
35 
36 #define TheTransportRegistry OpenDDS::DCPS::TransportRegistry::instance()
37 
38 namespace OpenDDS {
39 namespace DCPS {
40 
41 /**
42  * The TransportRegistry is a singleton object which provides a mechanism to
43  * the application code to configure OpenDDS's use of the transport layer.
44  */
46 public:
47 
48  /// Return a singleton instance of this class.
49  static TransportRegistry* instance();
50 
51  /// Close the singleton instance of this class.
52  static void close();
53 
54  /// This will shutdown all TransportImpl objects.
55  ///
56  /// Client Application calls this method to tear down the transport
57  /// framework.
58  void release();
59 
60  TransportInst_rch create_inst(const OPENDDS_STRING& name,
61  const OPENDDS_STRING& transport_type);
62  TransportInst_rch get_inst(const OPENDDS_STRING& name) const;
63 
64  /// Removing a TransportInst from the registry shuts down the underlying
65  /// transport implementation (if one was started) and therefore should only
66  /// be attempted after DDS Entities using this transport have been deleted.
67  void remove_inst(const TransportInst_rch& inst);
68  void remove_inst(const OPENDDS_STRING& inst_name);
69 
70  static const char DEFAULT_CONFIG_NAME[];
71  static const char DEFAULT_INST_PREFIX[];
72 
73  TransportConfig_rch create_config(const OPENDDS_STRING& name);
74  TransportConfig_rch get_config(const OPENDDS_STRING& name) const;
75  void remove_config(const TransportConfig_rch& cfg);
76  void remove_config(const OPENDDS_STRING& config_name);
77 
78  void remove_transport_template_instance(const OPENDDS_STRING& config_name);
79 
80  TransportConfig_rch global_config() const;
81  void global_config(const TransportConfig_rch& cfg);
82 
83  void domain_default_config(DDS::DomainId_t domain,
84  const TransportConfig_rch& cfg);
85  TransportConfig_rch domain_default_config(DDS::DomainId_t domain) const;
86 
87  void bind_config(const OPENDDS_STRING& name, DDS::Entity_ptr entity);
88  void bind_config(const TransportConfig_rch& cfg, DDS::Entity_ptr entity);
89 
90  /// SPI (Service Provider Interface) for specific transport types:
91  /// This function is called as the concrete transport library is
92  /// loaded. The concrete transport library creates a concrete
93  /// transport type object and registers it with TransportRegistry
94  /// singleton. Returns true for success.
95  bool register_type(const TransportType_rch& type);
96 
97  /// For internal use by OpenDDS DCPS layer:
98  /// Transfer the configuration in ACE_Configuration_Heap object to
99  /// the TransportRegistry. This is called by the Service_Participant
100  /// at initialization time. This function iterates each section in
101  /// the configuration file, and creates TransportInst and
102  /// TransportConfig objects and adds them to the registry.
103  int load_transport_configuration(const OPENDDS_STRING& file_name,
105 
106  /// For internal use by OpenDDS DCPS layer:
107  /// Process the transport_template configuration in the
108  /// ACE_Configuration_Heap object.
109  /// Called by the Service_Participant at initialization time.
110  int load_transport_templates(ACE_Configuration_Heap& cf);
111 
112  /// For internal use by OpenDDS DCPS layer:
113  /// If the default config is empty when it's about to be used, allow the
114  /// TransportRegistry to attempt to load a fallback option.
115  TransportConfig_rch fix_empty_default();
116 
117  /// For internal use by OpenDDS DCPS layer:
118  /// Dynamically load the library for the supplied transport type.
119  void load_transport_lib(const OPENDDS_STRING& transport_type);
120 
121  bool released() const;
122 
123  bool config_has_transport_template(const ACE_TString& config_name) const;
124 
125  int create_transport_template_instance(DDS::DomainId_t domain, const ACE_TString& config_name);
126 
127  OPENDDS_STRING get_transport_template_instance_name(DDS::DomainId_t id);
128 
129  OPENDDS_STRING get_config_instance_name(DDS::DomainId_t id);
130 
131  // the new config and instance names are returned by reference.
132  bool create_new_transport_instance_for_participant(DDS::DomainId_t id, OPENDDS_STRING& transport_config_name, OPENDDS_STRING& transport_instance_name);
133 
134  void update_config_template_instance_info(const OPENDDS_STRING& config_name, const OPENDDS_STRING& inst_name);
135 
136 private:
138 
141 
142  typedef OPENDDS_MAP(OPENDDS_STRING, TransportType_rch) TypeMap;
143  typedef OPENDDS_MAP(OPENDDS_STRING, TransportConfig_rch) ConfigMap;
144  typedef OPENDDS_MAP(OPENDDS_STRING, TransportInst_rch) InstMap;
145  typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) LibDirectiveMap;
146  typedef OPENDDS_MAP(DDS::DomainId_t, TransportConfig_rch) DomainConfigMap;
147  typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ConfigTemplateToInstanceMap;
148 
151 
152  TypeMap type_map_;
153  ConfigMap config_map_;
154  InstMap inst_map_;
155  LibDirectiveMap lib_directive_map_;
156  DomainConfigMap domain_default_config_map_;
157  ConfigTemplateToInstanceMap config_template_to_instance_map_;
158 
160  bool released_;
161 
162  mutable LockType lock_;
163 
164  // transport template support
167 
169  {
173  ValueMap customizations;
174  ValueMap transport_info;
175  };
176 
177  TransportType_rch load_transport_lib_i(const OPENDDS_STRING& transport_type);
178 
179  OPENDDS_VECTOR(TransportTemplate) transport_templates_;
180 
181  bool get_transport_template_info(const ACE_TString& config_name, TransportTemplate& inst);
182 
183  bool process_customizations(const DDS::DomainId_t id, const TransportTemplate& tr_inst, ValueMap& customs);
184 
185  bool has_transport_templates() const;
186 
188  {
191  ValueMap transport_info;
192  };
193 
194  OPENDDS_VECTOR(TransportEntry) transports_;
195 
196  bool get_transport_info(const ACE_TString& config_name, TransportEntry& inst);
197 
198  bool has_transports() const;
199 };
200 
201 } // namespace DCPS
202 } // namespace OpenDDS
203 
205 
206 #if defined (__ACE_INLINE__)
207 #include "TransportRegistry.inl"
208 #endif /* __ACE_INLINE__ */
209 
210 #endif /* OPENDDS_DCPS_TRANSPORTREGISTRY_H */
#define ACE_BEGIN_VERSIONED_NAMESPACE_DECL
#define ACE_SYNCH_MUTEX
void release(T x)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
ConfigTemplateToInstanceMap config_template_to_instance_map_
int close(ACE_HANDLE handle)
#define OPENDDS_STRING
DOMAINID_TYPE_NATIVE DomainId_t
Entity * Entity_ptr
#define ACE_END_VERSIONED_NAMESPACE_DECL
The End User API.
const char *const name
Definition: debug.cpp:60
#define OPENDDS_MAP(K, V)
#define OPENDDS_VECTOR(T)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
static const OPENDDS_STRING CUSTOM_ADD_DOMAIN_TO_PORT
static const OPENDDS_STRING CUSTOM_ADD_DOMAIN_TO_IP