Fast RTPS  Version 2.8.1
Fast RTPS
XMLProfileManager.h
1 // Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 #ifndef XML_PROFILE_MANAGER_H_
16 #define XML_PROFILE_MANAGER_H_
17 
18 #include <fastrtps/attributes/ParticipantAttributes.h>
19 #include <fastrtps/attributes/PublisherAttributes.h>
20 #include <fastrtps/attributes/SubscriberAttributes.h>
21 #include <fastrtps/xmlparser/XMLParserCommon.h>
22 #include <fastrtps/xmlparser/XMLParser.h>
23 #include <fastrtps/types/DynamicTypeBuilderFactory.h>
24 #include <fastrtps/types/DynamicTypeBuilder.h>
25 #include <fastrtps/types/DynamicPubSubType.h>
26 
27 #include <stdio.h>
28 #include <string>
29 #include <map>
30 
31 namespace eprosima {
32 namespace fastrtps {
33 namespace xmlparser {
34 
35 using participant_map_t = std::map<std::string, up_participant_t>;
36 using part_map_iterator_t = participant_map_t::iterator;
37 using publisher_map_t = std::map<std::string, up_publisher_t>;
38 using publ_map_iterator_t = publisher_map_t::iterator;
39 using subscriber_map_t = std::map<std::string, up_subscriber_t>;
40 using subs_map_iterator_t = subscriber_map_t::iterator;
41 using topic_map_t = std::map<std::string, up_topic_t>;
42 using topic_map_iterator_t = topic_map_t::iterator;
43 using requester_map_t = std::map<std::string, up_requester_t>;
44 using requester_map_iterator_t = requester_map_t::iterator;
45 using replier_map_t = std::map<std::string, up_replier_t>;
46 using replier_map_iterator_t = replier_map_t::iterator;
47 using xmlfiles_map_t = std::map<std::string, XMLP_ret>;
48 using xmlfile_map_iterator_t = xmlfiles_map_t::iterator;
49 
55 {
56 public:
57 
61  RTPS_DllAPI static void loadDefaultXMLFile();
62 
69  RTPS_DllAPI static XMLP_ret loadXMLFile(
70  const std::string& filename);
71 
79  RTPS_DllAPI static XMLP_ret loadXMLString(
80  const char* data,
81  size_t length);
82 
89  RTPS_DllAPI static XMLP_ret loadXMLNode(
90  tinyxml2::XMLDocument& doc);
91 
98  RTPS_DllAPI static XMLP_ret loadXMLProfiles(
99  tinyxml2::XMLElement& profiles);
100 
106  RTPS_DllAPI static XMLP_ret loadXMLDynamicTypes(
107  tinyxml2::XMLElement& types);
108 
113  RTPS_DllAPI static void library_settings(
115 
120  RTPS_DllAPI static const LibrarySettingsAttributes& library_settings();
121 
130  const std::string& profile_name,
131  ParticipantAttributes& atts,
132  bool log_error = true);
133 
135  RTPS_DllAPI static void getDefaultParticipantAttributes(
136  ParticipantAttributes& participant_attributes);
137 
145  RTPS_DllAPI static XMLP_ret fillPublisherAttributes(
146  const std::string& profile_name,
147  PublisherAttributes& atts,
148  bool log_error = true);
149 
151  RTPS_DllAPI static void getDefaultPublisherAttributes(
152  PublisherAttributes& publisher_attributes);
153 
161  RTPS_DllAPI static XMLP_ret fillSubscriberAttributes(
162  const std::string& profile_name,
163  SubscriberAttributes& atts,
164  bool log_error = true);
165 
167  RTPS_DllAPI static void getDefaultSubscriberAttributes(
168  SubscriberAttributes& subscriber_attributes);
169 
171  RTPS_DllAPI static bool insertTransportById(
172  const std::string& transport_id,
173  sp_transport_t transport);
174 
176  RTPS_DllAPI static sp_transport_t getTransportById(
177  const std::string& transport_id);
178 
185  RTPS_DllAPI static XMLP_ret fillTopicAttributes(
186  const std::string& profile_name,
187  TopicAttributes& atts);
188 
190  RTPS_DllAPI static void getDefaultTopicAttributes(
191  TopicAttributes& topic_attributes);
192 
194  RTPS_DllAPI static bool insertDynamicTypeByName(
195  const std::string& type_name,
197 
200  const std::string& type_name);
201 
202 
209  RTPS_DllAPI static XMLP_ret fillRequesterAttributes(
210  const std::string& profile_name,
211  RequesterAttributes& atts);
212 
219  RTPS_DllAPI static XMLP_ret fillReplierAttributes(
220  const std::string& profile_name,
221  ReplierAttributes& atts);
222 
228  RTPS_DllAPI static void DeleteInstance()
229  {
230  participant_profiles_.clear();
231  publisher_profiles_.clear();
232  subscriber_profiles_.clear();
233  requester_profiles_.clear();
234  replier_profiles_.clear();
235  topic_profiles_.clear();
236  xml_files_.clear();
237  transport_profiles_.clear();
238  }
239 
246  const std::string& type_name)
247  {
248  if (dynamic_types_.find(type_name) != dynamic_types_.end())
249  {
250  return new types::DynamicPubSubType(dynamic_types_[type_name]->build());
251  }
252  return nullptr;
253  }
254 
259  RTPS_DllAPI static void DeleteDynamicPubSubType(
261  {
262  delete type;
263  }
264 
265 private:
266 
267  RTPS_DllAPI static XMLP_ret extractProfiles(
268  up_base_node_t properties,
269  const std::string& filename);
270 
271  RTPS_DllAPI static XMLP_ret extractParticipantProfile(
272  up_base_node_t& profile,
273  const std::string& filename);
274 
275  RTPS_DllAPI static XMLP_ret extractPublisherProfile(
276  up_base_node_t& profile,
277  const std::string& filename);
278 
279  RTPS_DllAPI static XMLP_ret extractSubscriberProfile(
280  up_base_node_t& profile,
281  const std::string& filename);
282 
283  RTPS_DllAPI static XMLP_ret extractTopicProfile(
284  up_base_node_t& profile,
285  const std::string& filename);
286 
287  RTPS_DllAPI static XMLP_ret extractRequesterProfile(
288  up_base_node_t& profile,
289  const std::string& filename);
290 
291  RTPS_DllAPI static XMLP_ret extractReplierProfile(
292  up_base_node_t& profile,
293  const std::string& filename);
294 
295  static BaseNode* root;
296 
297  static LibrarySettingsAttributes library_settings_;
298 
299  static participant_map_t participant_profiles_;
300 
301  static publisher_map_t publisher_profiles_;
302 
303  static subscriber_map_t subscriber_profiles_;
304 
305  static topic_map_t topic_profiles_;
306 
307  static requester_map_t requester_profiles_;
308 
309  static replier_map_t replier_profiles_;
310 
311  static xmlfiles_map_t xml_files_;
312 
313  static sp_transport_map_t transport_profiles_;
314 
315  static p_dynamictype_map_t dynamic_types_;
316 };
317 
318 } /* xmlparser */
319 } /* namespace */
320 } /* namespace eprosima */
321 
322 #endif // ifndef XML_PROFILE_MANAGER_H_
Class LibraySettingsAttributes, used by the user to define the FastRTPS library behaviour.
Definition: LibrarySettingsAttributes.h:38
Class ParticipantAttributes, used by the user to define the attributes of a Participant.
Definition: ParticipantAttributes.h:35
Class PublisherAttributes, used by the user to define the attributes of a Publisher.
Definition: PublisherAttributes.h:41
Definition: ReplierAttributes.hpp:29
Definition: RequesterAttributes.hpp:29
Class SubscriberAttributes, used by the user to define the attributes of a Subscriber.
Definition: SubscriberAttributes.h:39
Class TopicAttributes, used by the user to define the attributes of the topic associated with a Publi...
Definition: TopicAttributes.h:36
Definition: DynamicPubSubType.h:29
Definition: DynamicTypeBuilder.h:32
Class XMLProfileManager, used to make available profiles from XML file.
Definition: XMLProfileManager.h:55
static RTPS_DllAPI XMLP_ret fillParticipantAttributes(const std::string &profile_name, ParticipantAttributes &atts, bool log_error=true)
Search for the profile specified and fill the structure.
static RTPS_DllAPI void library_settings(const LibrarySettingsAttributes &library_settings)
Library settings setter.
static RTPS_DllAPI void getDefaultTopicAttributes(TopicAttributes &topic_attributes)
Fills topic_attributes with the default values.
static RTPS_DllAPI XMLP_ret fillTopicAttributes(const std::string &profile_name, TopicAttributes &atts)
Search for the profile specified and fill the structure.
static RTPS_DllAPI types::DynamicPubSubType * CreateDynamicPubSubType(const std::string &type_name)
Retrieves a DynamicPubSubType for the given dynamic type name.
Definition: XMLProfileManager.h:245
static RTPS_DllAPI void getDefaultParticipantAttributes(ParticipantAttributes &participant_attributes)
Fills participant_attributes with the default values.
static RTPS_DllAPI XMLP_ret loadXMLNode(tinyxml2::XMLDocument &doc)
Load a profiles XML node.
static RTPS_DllAPI XMLP_ret fillReplierAttributes(const std::string &profile_name, ReplierAttributes &atts)
Search for the profile specified and fill the structure.
static RTPS_DllAPI bool insertTransportById(const std::string &transport_id, sp_transport_t transport)
Add a new transport instance along with its id.
static RTPS_DllAPI bool insertDynamicTypeByName(const std::string &type_name, p_dynamictypebuilder_t type)
Add a new dynamic type instance along with its name.
static RTPS_DllAPI void loadDefaultXMLFile()
Load the default profiles XML file.
static RTPS_DllAPI void getDefaultPublisherAttributes(PublisherAttributes &publisher_attributes)
Fills publisher_attributes with the default values.
static RTPS_DllAPI XMLP_ret loadXMLDynamicTypes(tinyxml2::XMLElement &types)
Load a dynamic types XML node.
static RTPS_DllAPI const LibrarySettingsAttributes & library_settings()
Library settings getter.
static RTPS_DllAPI void getDefaultSubscriberAttributes(SubscriberAttributes &subscriber_attributes)
Fills subscriber_attributes with the default values.
static RTPS_DllAPI XMLP_ret fillPublisherAttributes(const std::string &profile_name, PublisherAttributes &atts, bool log_error=true)
Search for the profile specified and fill the structure.
static RTPS_DllAPI void DeleteDynamicPubSubType(types::DynamicPubSubType *type)
Deletes the given DynamicPubSubType previously created by calling XMLProfileManager::CreateDynamicPub...
Definition: XMLProfileManager.h:259
static RTPS_DllAPI XMLP_ret fillRequesterAttributes(const std::string &profile_name, RequesterAttributes &atts)
Search for the profile specified and fill the structure.
static RTPS_DllAPI XMLP_ret loadXMLString(const char *data, size_t length)
Load a profiles XML string.
static RTPS_DllAPI XMLP_ret loadXMLFile(const std::string &filename)
Load a profiles XML file.
static RTPS_DllAPI void DeleteInstance()
Deletes the XMLProfileManager instance.
Definition: XMLProfileManager.h:228
static RTPS_DllAPI XMLP_ret fillSubscriberAttributes(const std::string &profile_name, SubscriberAttributes &atts, bool log_error=true)
Search for the profile specified and fill the structure.
static RTPS_DllAPI sp_transport_t getTransportById(const std::string &transport_id)
Retrieves a transport instance by its id.
static RTPS_DllAPI XMLP_ret loadXMLProfiles(tinyxml2::XMLElement &profiles)
Load a profiles XML node.
static RTPS_DllAPI p_dynamictypebuilder_t getDynamicTypeByName(const std::string &type_name)
Retrieves a transport instance by its name.
topic_map_t::iterator topic_map_iterator_t
Definition: XMLProfileManager.h:42
replier_map_t::iterator replier_map_iterator_t
Definition: XMLProfileManager.h:46
std::map< std::string, up_participant_t > participant_map_t
Definition: XMLProfileManager.h:35
std::map< std::string, sp_transport_t > sp_transport_map_t
Definition: XMLParser.h:51
std::shared_ptr< fastdds::rtps::TransportDescriptorInterface > sp_transport_t
Definition: XMLParser.h:50
std::map< std::string, up_publisher_t > publisher_map_t
Definition: XMLProfileManager.h:37
std::map< std::string, up_subscriber_t > subscriber_map_t
Definition: XMLProfileManager.h:39
XMLP_ret
Enum class XMLP_ret, used to provide a strongly typed result from the operations within this module.
Definition: XMLParserCommon.h:27
std::map< std::string, XMLP_ret > xmlfiles_map_t
Definition: XMLProfileManager.h:47
std::map< std::string, up_topic_t > topic_map_t
Definition: XMLProfileManager.h:41
xmlfiles_map_t::iterator xmlfile_map_iterator_t
Definition: XMLProfileManager.h:48
std::map< std::string, up_requester_t > requester_map_t
Definition: XMLProfileManager.h:43
std::map< std::string, p_dynamictypebuilder_t > p_dynamictype_map_t
Definition: XMLParser.h:53
requester_map_t::iterator requester_map_iterator_t
Definition: XMLProfileManager.h:44
std::map< std::string, up_replier_t > replier_map_t
Definition: XMLProfileManager.h:45
std::unique_ptr< BaseNode > up_base_node_t
Definition: XMLParser.h:42
participant_map_t::iterator part_map_iterator_t
Definition: XMLProfileManager.h:36
publisher_map_t::iterator publ_map_iterator_t
Definition: XMLProfileManager.h:38
subscriber_map_t::iterator subs_map_iterator_t
Definition: XMLProfileManager.h:40
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23