-
Notifications
You must be signed in to change notification settings - Fork 939
Expand file tree
/
Copy pathXMLProfileManager.cpp
More file actions
814 lines (727 loc) · 24.7 KB
/
Copy pathXMLProfileManager.cpp
File metadata and controls
814 lines (727 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
// Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <tinyxml2.h>
#include <fastrtps/xmlparser/XMLProfileManager.h>
#include <fastrtps/xmlparser/XMLTree.h>
#include <fastdds/dds/log/Log.hpp>
#include <cstdlib>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif // _WIN32
using namespace eprosima::fastrtps;
using namespace ::xmlparser;
LibrarySettingsAttributes XMLProfileManager::library_settings_;
std::map<std::string, up_participant_t> XMLProfileManager::participant_profiles_;
ParticipantAttributes default_participant_attributes;
std::map<std::string, up_publisher_t> XMLProfileManager::publisher_profiles_;
PublisherAttributes default_publisher_attributes;
std::map<std::string, up_subscriber_t> XMLProfileManager::subscriber_profiles_;
SubscriberAttributes default_subscriber_attributes;
std::map<std::string, up_topic_t> XMLProfileManager::topic_profiles_;
TopicAttributes default_topic_attributes;
std::map<std::string, up_requester_t> XMLProfileManager::requester_profiles_;
std::map<std::string, up_replier_t> XMLProfileManager::replier_profiles_;
std::map<std::string, XMLP_ret> XMLProfileManager::xml_files_;
sp_transport_map_t XMLProfileManager::transport_profiles_;
p_dynamictype_map_t XMLProfileManager::dynamic_types_;
BaseNode* XMLProfileManager::root = nullptr;
XMLP_ret XMLProfileManager::fillParticipantAttributes(
const std::string& profile_name,
ParticipantAttributes& atts,
bool log_error)
{
part_map_iterator_t it = participant_profiles_.find(profile_name);
if (it == participant_profiles_.end())
{
if (log_error)
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
}
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::fillPublisherAttributes(
const std::string& profile_name,
PublisherAttributes& atts,
bool log_error)
{
publ_map_iterator_t it = publisher_profiles_.find(profile_name);
if (it == publisher_profiles_.end())
{
if (log_error)
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
}
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::fillSubscriberAttributes(
const std::string& profile_name,
SubscriberAttributes& atts,
bool log_error)
{
subs_map_iterator_t it = subscriber_profiles_.find(profile_name);
if (it == subscriber_profiles_.end())
{
if (log_error)
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
}
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::fillTopicAttributes(
const std::string& profile_name,
TopicAttributes& atts)
{
topic_map_iterator_t it = topic_profiles_.find(profile_name);
if (it == topic_profiles_.end())
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::fillRequesterAttributes(
const std::string& profile_name,
RequesterAttributes& atts)
{
requester_map_iterator_t it = requester_profiles_.find(profile_name);
if (it == requester_profiles_.end())
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::fillReplierAttributes(
const std::string& profile_name,
ReplierAttributes& atts)
{
replier_map_iterator_t it = replier_profiles_.find(profile_name);
if (it == replier_profiles_.end())
{
logError(XMLPARSER, "Profile '" << profile_name << "' not found");
return XMLP_ret::XML_ERROR;
}
atts = *(it->second);
return XMLP_ret::XML_OK;
}
void XMLProfileManager::getDefaultParticipantAttributes(
ParticipantAttributes& participant_attributes)
{
participant_attributes = default_participant_attributes;
}
void XMLProfileManager::getDefaultPublisherAttributes(
PublisherAttributes& publisher_attributes)
{
publisher_attributes = default_publisher_attributes;
}
void XMLProfileManager::getDefaultSubscriberAttributes(
SubscriberAttributes& subscriber_attributes)
{
subscriber_attributes = default_subscriber_attributes;
}
void XMLProfileManager::getDefaultTopicAttributes(
TopicAttributes& topic_attributes)
{
topic_attributes = default_topic_attributes;
}
void XMLProfileManager::loadDefaultXMLFile()
{
// Try to load the default XML file set with an environment variable.
#ifdef _WIN32
char file_path[MAX_PATH];
char absolute_path[MAX_PATH];
char current_directory[MAX_PATH];
char** filename = {nullptr};
size_t size = MAX_PATH;
if (getenv_s(&size, file_path, size, DEFAULT_FASTRTPS_ENV_VARIABLE) == 0 && size > 0)
{
// Use absolute path to ensure the file is loaded only once
if (GetFullPathName(file_path, MAX_PATH, absolute_path, filename) == 0)
{
logError(XMLPARSER, "GetFullPathName failed " << GetLastError());
}
else
{
loadXMLFile(absolute_path);
}
}
// Should take into account '\0'
char skip_xml[2];
size = 2;
// Try to load the default XML file if variable does not exist or is not set to '1'
if (!(getenv_s(&size, skip_xml, size, SKIP_DEFAULT_XML_FILE) == 0 && skip_xml[0] == '1'))
{
// Try to load the default XML file.
if (GetCurrentDirectory(MAX_PATH, current_directory) == 0)
{
logError(XMLPARSER, "GetCurrentDirectory failed " << GetLastError());
}
else
{
strcat_s(current_directory, MAX_PATH, "\\");
strcat_s(current_directory, MAX_PATH, DEFAULT_FASTRTPS_PROFILES);
loadXMLFile(current_directory, true);
}
}
#else
char absolute_path[PATH_MAX];
if (const char* file_path = std::getenv(DEFAULT_FASTRTPS_ENV_VARIABLE))
{
char* res = realpath(file_path, absolute_path);
if (res)
{
loadXMLFile(absolute_path);
}
else
{
logError(XMLPARSER, "realpath failed " << std::strerror(errno));
}
}
const char* skip_xml = std::getenv(SKIP_DEFAULT_XML_FILE);
// Try to load the default XML file if variable does not exist or is not set to '1'
if (!(skip_xml != nullptr && skip_xml[0] == '1'))
{
if (getcwd(absolute_path, PATH_MAX) == NULL)
{
logError(XMLPARSER, "getcwd failed " << std::strerror(errno));
}
else
{
strcat(absolute_path, "/");
strcat(absolute_path, DEFAULT_FASTRTPS_PROFILES);
loadXMLFile(absolute_path, true);
}
}
#endif // ifdef _WIN32
}
XMLP_ret XMLProfileManager::loadXMLProfiles(
tinyxml2::XMLElement& profiles)
{
up_base_node_t root_node;
if (strcmp(profiles.Name(), PROFILES) != 0)
{
logError(XMLPARSER, "<profiles> element not found");
return XMLP_ret::XML_ERROR;
}
if (XMLParser::loadXMLProfiles(profiles, root_node) == XMLP_ret::XML_OK)
{
logInfo(XMLPARSER, "Node parsed successfully");
return XMLProfileManager::extractProfiles(std::move(root_node), "-XML Node-");
}
else
{
logError(XMLPARSER, "Error parsing profiles");
return XMLP_ret::XML_ERROR;
}
}
XMLP_ret XMLProfileManager::loadXMLDynamicTypes(
tinyxml2::XMLElement& types)
{
return XMLParser::loadXMLDynamicTypes(types);
}
XMLP_ret XMLProfileManager::loadXMLNode(
tinyxml2::XMLDocument& doc)
{
up_base_node_t root_node;
XMLP_ret parse_ret;
XMLP_ret loaded_ret = XMLParser::loadXML(doc, root_node);
if (!root_node)
{
logError(XMLPARSER, "Error parsing node");
return XMLP_ret::XML_ERROR;
}
logInfo(XMLPARSER, "Node parsed successfully");
if (NodeType::PROFILES == root_node->getType())
{
parse_ret = XMLProfileManager::extractProfiles(std::move(root_node), "-XML Node-");
if (parse_ret == XMLP_ret::XML_OK && loaded_ret != XMLP_ret::XML_OK)
{
return XMLP_ret::XML_NOK;
}
else
{
return parse_ret;
}
}
if (NodeType::ROOT == root_node->getType())
{
for (auto&& child: root_node->getChildren())
{
if (NodeType::PROFILES == child.get()->getType())
{
parse_ret = XMLProfileManager::extractProfiles(std::move(child), "-XML Node-");
if (parse_ret == XMLP_ret::XML_OK && loaded_ret != XMLP_ret::XML_OK)
{
return XMLP_ret::XML_NOK;
}
else
{
return parse_ret;
}
}
}
}
return XMLP_ret::XML_ERROR;
}
XMLP_ret XMLProfileManager::loadXMLFile(
const std::string& filename)
{
return loadXMLFile(filename, false);
}
XMLP_ret XMLProfileManager::loadXMLFile(
const std::string& filename,
bool is_default)
{
if (filename.empty())
{
logError(XMLPARSER, "Error loading XML file, filename empty");
return XMLP_ret::XML_ERROR;
}
xmlfile_map_iterator_t it = xml_files_.find(filename);
if (it != xml_files_.end() && XMLP_ret::XML_OK == it->second)
{
logInfo(XMLPARSER, "XML file '" << filename << "' already parsed");
return XMLP_ret::XML_OK;
}
up_base_node_t root_node;
XMLP_ret loaded_ret = XMLParser::loadXML(filename, root_node, is_default);
if (!root_node || loaded_ret != XMLP_ret::XML_OK)
{
if (!is_default)
{
logError(XMLPARSER, "Error parsing '" << filename << "'");
}
xml_files_.emplace(filename, XMLP_ret::XML_ERROR);
return XMLP_ret::XML_ERROR;
}
logInfo(XMLPARSER, "File '" << filename << "' parsed successfully");
if (NodeType::ROOT == root_node->getType())
{
for (auto&& child: root_node->getChildren())
{
if (NodeType::PROFILES == child.get()->getType())
{
return XMLProfileManager::extractProfiles(std::move(child), filename);
}
}
return loaded_ret;
}
else if (NodeType::PROFILES == root_node->getType())
{
return XMLProfileManager::extractProfiles(std::move(root_node), filename);
}
return loaded_ret;
}
XMLP_ret XMLProfileManager::loadXMLString(
const char* data,
size_t length)
{
up_base_node_t root_node;
XMLP_ret loaded_ret = XMLParser::loadXML(data, length, root_node);
if (!root_node || loaded_ret != XMLP_ret::XML_OK)
{
logError(XMLPARSER, "Error parsing string");
return XMLP_ret::XML_ERROR;
}
if (NodeType::ROOT == root_node->getType())
{
for (auto&& child: root_node->getChildren())
{
if (NodeType::PROFILES == child.get()->getType())
{
return XMLProfileManager::extractProfiles(std::move(child), "inmem");
}
}
return loaded_ret;
}
else if (NodeType::PROFILES == root_node->getType())
{
return XMLProfileManager::extractProfiles(std::move(root_node), "inmem");
}
return loaded_ret;
}
types::DynamicPubSubType* XMLProfileManager::CreateDynamicPubSubType(
const std::string& type_name)
{
if (dynamic_types_.find(type_name) != dynamic_types_.end())
{
return new types::DynamicPubSubType(dynamic_types_[type_name]->build());
}
return nullptr;
}
void XMLProfileManager::DeleteDynamicPubSubType(
types::DynamicPubSubType* type)
{
delete type;
}
XMLP_ret XMLProfileManager::extractProfiles(
up_base_node_t profiles,
const std::string& filename)
{
assert(profiles != nullptr);
unsigned int profile_count = 0u;
XMLP_ret ret = XMLP_ret::XML_OK;
for (auto&& profile: profiles->getChildren())
{
if (NodeType::PARTICIPANT == profile->getType())
{
if (XMLP_ret::XML_OK == extractParticipantProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
else if (NodeType::PUBLISHER == profile.get()->getType())
{
if (XMLP_ret::XML_OK == extractPublisherProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
else if (NodeType::SUBSCRIBER == profile.get()->getType())
{
if (XMLP_ret::XML_OK == extractSubscriberProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
else if (NodeType::TOPIC == profile.get()->getType())
{
if (XMLP_ret::XML_OK == extractTopicProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
else if (NodeType::REQUESTER == profile.get()->getType())
{
if (XMLP_ret::XML_OK == extractRequesterProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
else if (NodeType::REPLIER == profile.get()->getType())
{
if (XMLP_ret::XML_OK == extractReplierProfile(profile, filename))
{
++profile_count;
}
else
{
ret = XMLP_ret::XML_NOK;
}
}
}
profile_count += static_cast<unsigned int>(transport_profiles_.size()); // Count transport profiles
if (profile_count == 0)
{
logError(XMLProfileManager, "Could not extract any profile")
ret = XMLP_ret::XML_ERROR;
}
xml_files_.emplace(filename, ret);
return ret;
}
XMLP_ret XMLProfileManager::extractParticipantProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_participant_t node_part = dynamic_cast<p_node_participant_t>(profile.get());
if (node_part == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_part->getAttributes().find(PROFILE_NAME);
if (it == node_part->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<part_map_iterator_t, bool> emplace = participant_profiles_.emplace(profile_name, node_part->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
it = node_part->getAttributes().find(DEFAULT_PROF);
if (it != node_part->getAttributes().end() && it->second == "true") // Set as default profile
{
// +V+ TODO: LOG ERROR IN SECOND ATTEMPT
default_participant_attributes = *(emplace.first->second.get());
}
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::extractPublisherProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_publisher_t node_part = dynamic_cast<p_node_publisher_t>(profile.get());
if (node_part == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_part->getAttributes().find(PROFILE_NAME);
if (it == node_part->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<publ_map_iterator_t, bool> emplace = publisher_profiles_.emplace(profile_name, node_part->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
it = node_part->getAttributes().find(DEFAULT_PROF);
if (it != node_part->getAttributes().end() && it->second == "true") // Set as default profile
{
// +V+ TODO: LOG ERROR IN SECOND ATTEMPT
default_publisher_attributes = *(emplace.first->second.get());
}
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::extractSubscriberProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_subscriber_t node_part = dynamic_cast<p_node_subscriber_t>(profile.get());
if (node_part == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_part->getAttributes().find(PROFILE_NAME);
if (it == node_part->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<subs_map_iterator_t, bool> emplace = subscriber_profiles_.emplace(profile_name, node_part->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
it = node_part->getAttributes().find(DEFAULT_PROF);
if (it != node_part->getAttributes().end() && it->second == "true") // Set as default profile
{
// +V+ TODO: LOG ERROR IN SECOND ATTEMPT
default_subscriber_attributes = *(emplace.first->second.get());
}
return XMLP_ret::XML_OK;
}
bool XMLProfileManager::insertTransportById(
const std::string& transport_id,
sp_transport_t transport)
{
if (transport_profiles_.find(transport_id) == transport_profiles_.end())
{
transport_profiles_[transport_id] = transport;
return true;
}
logError(XMLPARSER, "Error adding the transport " << transport_id << ". There is other transport with the same id");
return false;
}
const LibrarySettingsAttributes& XMLProfileManager::library_settings()
{
return library_settings_;
}
void XMLProfileManager::library_settings(
const LibrarySettingsAttributes& library_settings)
{
library_settings_ = library_settings;
}
sp_transport_t XMLProfileManager::getTransportById(
const std::string& transport_id)
{
if (transport_profiles_.find(transport_id) != transport_profiles_.end())
{
return transport_profiles_[transport_id];
}
return nullptr;
}
bool XMLProfileManager::insertDynamicTypeByName(
const std::string& type_name,
p_dynamictypebuilder_t type)
{
if (dynamic_types_.find(type_name) == dynamic_types_.end())
{
dynamic_types_[type_name] = type;
return true;
}
logError(XMLPARSER, "Error adding the type " << type_name << ". There is other type with the same name.");
return false;
}
p_dynamictypebuilder_t XMLProfileManager::getDynamicTypeByName(
const std::string& type_name)
{
if (dynamic_types_.find(type_name) != dynamic_types_.end())
{
return dynamic_types_[type_name];
}
return nullptr;
}
XMLP_ret XMLProfileManager::extractTopicProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_topic_t node_topic = dynamic_cast<p_node_topic_t>(profile.get());
if (node_topic == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_topic->getAttributes().find(PROFILE_NAME);
if (it == node_topic->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<topic_map_iterator_t, bool> emplace = topic_profiles_.emplace(profile_name, node_topic->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
it = node_topic->getAttributes().find(DEFAULT_PROF);
if (it != node_topic->getAttributes().end() && it->second == "true")
{
// +V+ TODO: LOG ERROR IN SECOND ATTEMPT
default_topic_attributes = *(emplace.first->second.get());
}
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::extractRequesterProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_requester_t node_requester = dynamic_cast<p_node_requester_t>(profile.get());
if (node_requester == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_requester->getAttributes().find(PROFILE_NAME);
if (it == node_requester->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<requester_map_iterator_t, bool> emplace = requester_profiles_.emplace(profile_name,
node_requester->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
return XMLP_ret::XML_OK;
}
XMLP_ret XMLProfileManager::extractReplierProfile(
up_base_node_t& profile,
const std::string& filename)
{
(void)(filename);
std::string profile_name = "";
p_node_replier_t node_replier = dynamic_cast<p_node_replier_t>(profile.get());
if (node_replier == nullptr)
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': unexpected node type");
return XMLP_ret::XML_ERROR;
}
node_att_map_cit_t it = node_replier->getAttributes().find(PROFILE_NAME);
if (it == node_replier->getAttributes().end() || it->second.empty())
{
logError(XMLPARSER, "Error adding profile from file '" << filename << "': no name found");
return XMLP_ret::XML_ERROR;
}
profile_name = it->second;
std::pair<replier_map_iterator_t, bool> emplace = replier_profiles_.emplace(profile_name, node_replier->getData());
if (false == emplace.second)
{
logError(XMLPARSER, "Error adding profile '" << profile_name << "' from file '" << filename << "'");
return XMLP_ret::XML_ERROR;
}
return XMLP_ret::XML_OK;
}
void XMLProfileManager::DeleteInstance()
{
participant_profiles_.clear();
publisher_profiles_.clear();
subscriber_profiles_.clear();
requester_profiles_.clear();
replier_profiles_.clear();
topic_profiles_.clear();
xml_files_.clear();
transport_profiles_.clear();
// Delete the registered dynamic types builders
{
namespace dyn_types = eprosima::fastrtps::types;
auto factory = dyn_types::DynamicTypeBuilderFactory::get_instance();
for (auto&& type : dynamic_types_)
{
factory->delete_builder(type.second);
}
dynamic_types_.clear();
}
// Clear XML Parser collections
XMLParser::clear();
}