Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

OpenCodeShare/Fast-DDS

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (375)
Tags (141)
master
bugfix/compile-openssl
feature/flowcontrol-update
feature/writer-side-cft-late-joiners
feature/empty-payload-dispose-unregister
mergify/bp/3.2.x/pr-6227
mergify/bp/3.3.x/pr-6227
mergify/bp/3.4.x/pr-6227
3.5.x
3.x
hotfix/depth_vs_max_spi
fast/poc/keep_alive
3.4.x
3.3.x
3.2.x
2.14.x
2.x
2.6.11
2.6.x
feature/ubuntu-noble
v2.6.11
v3.4.1
v3.2.3
v3.4.0
v2.14.5
v3.3.0
v3.1.3
v2.10.7
v3.2.2
v2.6.10
v3.2.1
v3.2.0
v3.0.2
v3.1.2
v3.2.0-vulcanexus
v3.1.1
v2.14.4
v2.10.6
v3.1.0
v2.10.5
master
Branches (375)
Tags (141)
master
bugfix/compile-openssl
feature/flowcontrol-update
feature/writer-side-cft-late-joiners
feature/empty-payload-dispose-unregister
mergify/bp/3.2.x/pr-6227
mergify/bp/3.3.x/pr-6227
mergify/bp/3.4.x/pr-6227
3.5.x
3.x
hotfix/depth_vs_max_spi
fast/poc/keep_alive
3.4.x
3.3.x
3.2.x
2.14.x
2.x
2.6.11
2.6.x
feature/ubuntu-noble
v2.6.11
v3.4.1
v3.2.3
v3.4.0
v2.14.5
v3.3.0
v3.1.3
v2.10.7
v3.2.2
v2.6.10
v3.2.1
v3.2.0
v3.0.2
v3.1.2
v3.2.0-vulcanexus
v3.1.1
v2.14.4
v2.10.6
v3.1.0
v2.10.5
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (375)
Tags (141)
master
bugfix/compile-openssl
feature/flowcontrol-update
feature/writer-side-cft-late-joiners
feature/empty-payload-dispose-unregister
mergify/bp/3.2.x/pr-6227
mergify/bp/3.3.x/pr-6227
mergify/bp/3.4.x/pr-6227
3.5.x
3.x
hotfix/depth_vs_max_spi
fast/poc/keep_alive
3.4.x
3.3.x
3.2.x
2.14.x
2.x
2.6.11
2.6.x
feature/ubuntu-noble
v2.6.11
v3.4.1
v3.2.3
v3.4.0
v2.14.5
v3.3.0
v3.1.3
v2.10.7
v3.2.2
v2.6.10
v3.2.1
v3.2.0
v3.0.2
v3.1.2
v3.2.0-vulcanexus
v3.1.1
v2.14.4
v2.10.6
v3.1.0
v2.10.5
Fast-DDS
/
src
/
cpp
/
xmlparser
/
XMLEndpointParser.cpp
Fast-DDS
/
src
/
cpp
/
xmlparser
/
XMLEndpointParser.cpp
XMLEndpointParser.cpp 32.67 KB
Copy Edit Raw Blame History
Ricardo González authored 2025年06月25日 15:52 +08:00 . New version of EDP static discovery (#5860)
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 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
// Copyright 2016 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.
/**
* @file XMLEndpointParser.cpp
*
*/
#include <xmlparser/XMLEndpointParser.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <tinyxml2.h>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/utils/IPLocator.hpp>
#include <rtps/builtin/data/ReaderProxyData.hpp>
#include <rtps/builtin/data/WriterProxyData.hpp>
#include <utils/TimeConversion.hpp>
#include <xmlparser/XMLParserUtils.hpp>
namespace eprosima {
namespace fastdds {
namespace xmlparser {
using namespace eprosima::fastdds::rtps;
using namespace eprosima::fastdds::xml::detail;
XMLEndpointParser::XMLEndpointParser()
{
}
XMLEndpointParser::~XMLEndpointParser()
{
for (std::vector<StaticRTPSParticipantInfo*>::iterator pit = m_RTPSParticipants.begin();
pit != m_RTPSParticipants.end(); ++pit)
{
for (std::vector<ReaderProxyData*>::iterator rit = (*pit)->m_readers.begin();
rit != (*pit)->m_readers.end(); ++rit)
{
delete(*rit);
}
for (std::vector<WriterProxyData*>::iterator wit = (*pit)->m_writers.begin();
wit != (*pit)->m_writers.end(); ++wit)
{
delete(*wit);
}
delete(*pit);
}
}
XMLP_ret XMLEndpointParser::loadXMLFile(
std::string& filename)
{
tinyxml2::XMLDocument doc;
tinyxml2::XMLError eResult;
if (0 == filename.rfind("data://", 0))
{
EPROSIMA_LOG_INFO(RTPS_EDP, filename);
eResult = doc.Parse(filename.c_str() + 7, filename.size() - 7);
}
else if (0 == filename.rfind("file://", 0))
{
EPROSIMA_LOG_INFO(RTPS_EDP, filename);
eResult = doc.LoadFile(filename.substr(7).c_str());
}
else
{
EPROSIMA_LOG_INFO(RTPS_EDP, "FileName: " << filename);
eResult = doc.LoadFile(filename.c_str());
}
if (tinyxml2::XML_SUCCESS != eResult)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, filename << " bad file");
return XMLP_ret::XML_ERROR;
}
tinyxml2::XMLNode* root = doc.FirstChildElement(STATICDISCOVERY);
if (!root)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, filename << " XML has errors");
return XMLP_ret::XML_ERROR;
}
tinyxml2::XMLElement* xml_RTPSParticipant = root->FirstChildElement();
while (xml_RTPSParticipant != nullptr)
{
std::string key(xml_RTPSParticipant->Name());
if (key == PARTICIPANT)
{
StaticRTPSParticipantInfo* pdata = new StaticRTPSParticipantInfo();
loadXMLParticipantEndpoint(xml_RTPSParticipant, pdata);
m_RTPSParticipants.push_back(pdata);
}
xml_RTPSParticipant = xml_RTPSParticipant->NextSiblingElement();
}
EPROSIMA_LOG_INFO(RTPS_EDP, "Finished parsing, " << m_RTPSParticipants.size() << " participants found.");
return XMLP_ret::XML_OK;
}
XMLP_ret XMLEndpointParser::loadXMLNode(
tinyxml2::XMLDocument& doc)
{
EPROSIMA_LOG_INFO(RTPS_EDP, "XML node");
tinyxml2::XMLNode* root = doc.FirstChildElement(STATICDISCOVERY);
if (!root)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "XML node has errors");
return XMLP_ret::XML_ERROR;
}
tinyxml2::XMLElement* xml_RTPSParticipant = root->FirstChildElement();
while (xml_RTPSParticipant != nullptr)
{
std::string key(xml_RTPSParticipant->Name());
if (key == PARTICIPANT)
{
StaticRTPSParticipantInfo* pdata = new StaticRTPSParticipantInfo();
loadXMLParticipantEndpoint(xml_RTPSParticipant, pdata);
m_RTPSParticipants.push_back(pdata);
}
xml_RTPSParticipant = xml_RTPSParticipant->NextSiblingElement();
}
EPROSIMA_LOG_INFO(RTPS_EDP, "Finished parsing, " << m_RTPSParticipants.size() << " participants found.");
return XMLP_ret::XML_OK;
}
void XMLEndpointParser::loadXMLParticipantEndpoint(
tinyxml2::XMLElement* xml_endpoint,
StaticRTPSParticipantInfo* pdata)
{
tinyxml2::XMLNode* xml_RTPSParticipant_child = xml_endpoint;
tinyxml2::XMLElement* element = xml_RTPSParticipant_child->FirstChildElement();
while (element != nullptr)
{
std::string key(element->Name());
if (key == NAME)
{
pdata->m_RTPSParticipantName = get_element_text(element);
}
else if (key == READER)
{
if (loadXMLReaderEndpoint(element, pdata) != XMLP_ret::XML_OK)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Reader Endpoint has error, ignoring");
}
}
else if (key == WRITER)
{
if (loadXMLWriterEndpoint(element, pdata) != XMLP_ret::XML_OK)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Writer Endpoint has error, ignoring");
}
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Unknown XMK tag: " << key);
}
element = element->NextSiblingElement();
}
}
XMLP_ret XMLEndpointParser::loadXMLReaderEndpoint(
tinyxml2::XMLElement* xml_endpoint,
StaticRTPSParticipantInfo* pdata)
{
LocatorList_t unicast_locators;
LocatorList_t multicast_locators;
tinyxml2::XMLNode* xml_endpoint_child = xml_endpoint;
tinyxml2::XMLElement* element = xml_endpoint_child->FirstChildElement();
// Parse locators first
while (element != nullptr)
{
std::string key(element->Name());
if (key == UNICAST_LOCATOR)
{
Locator_t loc;
loc.kind = 1;
const char* address = element->Attribute(ADDRESS);
std::string auxString(address ? address : "");
IPLocator::setIPv4(loc, auxString);
int port = 0;
element->QueryIntAttribute(PORT, &port);
loc.port = static_cast<uint16_t>(port);
unicast_locators.push_back(loc);
}
else if (key == MULTICAST_LOCATOR)
{
Locator_t loc;
loc.kind = 1;
const char* address = element->Attribute(ADDRESS);
std::string auxString(address ? address : "");
IPLocator::setIPv4(loc, auxString);
int port = 0;
element->QueryIntAttribute(PORT, &port);
loc.port = static_cast<uint16_t>(port);
multicast_locators.push_back(loc);
}
element = element->NextSiblingElement();
}
ReaderProxyData* rdata = new ReaderProxyData(unicast_locators.size(), multicast_locators.size());
xml_endpoint_child = xml_endpoint;
element = xml_endpoint_child->FirstChildElement();
while (element != nullptr)
{
std::string key(element->Name());
if (key == USER_ID)
{
int16_t id = static_cast<int16_t>(std::strtol(get_element_text(element).c_str(), nullptr, 10));
if (id <= 0 || m_endpointIds.insert(id).second == false)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Repeated or negative ID in XML file");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
rdata->user_defined_id(id);
}
else if (key == ENTITY_ID)
{
int32_t id = std::strtol(get_element_text(element).c_str(), nullptr, 10);
if (id <= 0 || m_entityIds.insert(id).second == false)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Repeated or negative entityId in XML file");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
octet* c = (octet*)&id;
rdata->guid.entityId.value[2] = c[0];
rdata->guid.entityId.value[1] = c[1];
rdata->guid.entityId.value[0] = c[2];
}
else if (key == EXPECT_INLINE_QOS)
{
std::string auxString(get_element_text(element));
if (auxString == "true")
{
rdata->expects_inline_qos = true;
}
else if (auxString == "false")
{
rdata->expects_inline_qos = false;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP,
"Bad XML file, endpoint of expects_inline_qos: " << auxString << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == TOPIC) // deprecated api
{
const char* topicName = element->Attribute(NAME);
const char* typeName = element->Attribute(DATA_TYPE);
const char* kind = element->Attribute(KIND);
rdata->topic_name = (topicName != nullptr) ? std::string(topicName) : std::string("");
rdata->type_name = (topicName != nullptr) ? std::string(typeName) : std::string("");
std::string auxString(kind ? kind : "");
if (auxString == _NO_KEY)
{
rdata->topic_kind = NO_KEY;
rdata->guid.entityId.value[3] = 0x04;
}
else if (auxString == _WITH_KEY)
{
rdata->topic_kind = WITH_KEY;
rdata->guid.entityId.value[3] = 0x07;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, topic of kind: " << auxString << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
if (rdata->topic_name == EPROSIMA_UNKNOWN_STRING || rdata->type_name == EPROSIMA_UNKNOWN_STRING)
{
EPROSIMA_LOG_ERROR(RTPS_EDP,
"Bad XML file, topic: " << rdata->topic_name << " or typeName: " << rdata->type_name <<
" undefined");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == TOPIC_NAME)
{
rdata->topic_name = get_element_text(element);
}
else if (key == TOPIC_DATA_TYPE)
{
rdata->type_name = get_element_text(element);
}
else if (key == TOPIC_KIND)
{
std::string auxString(get_element_text(element));
if (auxString == _NO_KEY)
{
rdata->topic_kind = NO_KEY;
rdata->guid.entityId.value[3] = 0x04;
}
else if (auxString == _WITH_KEY)
{
rdata->topic_kind = WITH_KEY;
rdata->guid.entityId.value[3] = 0x07;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, topic of kind: " << auxString << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == RELIABILITY_QOS)
{
std::string auxString(get_element_text(element));
if (auxString == _RELIABLE_RELIABILITY_QOS)
{
rdata->reliability.kind = dds::RELIABLE_RELIABILITY_QOS;
}
else if (auxString == _BEST_EFFORT_RELIABILITY_QOS)
{
rdata->reliability.kind = dds::BEST_EFFORT_RELIABILITY_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, endpoint of stateKind: " << auxString << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == UNICAST_LOCATOR)
{
// Empty but necessary to avoid warning on last else
}
else if (key == MULTICAST_LOCATOR)
{
// Empty but necessary to avoid warning on last else
}
else if (key == DURABILITY_QOS)
{
std::string auxstring(get_element_text(element));
if (auxstring == _PERSISTENT_DURABILITY_QOS)
{
rdata->durability.kind = dds::PERSISTENT_DURABILITY_QOS;
}
else if (auxstring == _TRANSIENT_DURABILITY_QOS)
{
rdata->durability.kind = dds::TRANSIENT_DURABILITY_QOS;
}
else if (auxstring == _TRANSIENT_LOCAL_DURABILITY_QOS)
{
rdata->durability.kind = dds::TRANSIENT_LOCAL_DURABILITY_QOS;
}
else if (auxstring == _VOLATILE_DURABILITY_QOS)
{
rdata->durability.kind = dds::VOLATILE_DURABILITY_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, durability of kind: " << auxstring << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == OWNERSHIP_QOS)
{
const char* ownership = element->Attribute(KIND);
std::string auxstring(ownership ? ownership : OWNERSHIP_KIND_NOT_PRESENT);
if (auxstring == _SHARED_OWNERSHIP_QOS)
{
rdata->ownership.kind = dds::SHARED_OWNERSHIP_QOS;
}
else if (auxstring == _EXCLUSIVE_OWNERSHIP_QOS)
{
rdata->ownership.kind = dds::EXCLUSIVE_OWNERSHIP_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, ownership of kind: " << auxstring << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == PARTITION_QOS)
{
rdata->partition.push_back(get_element_text(element).c_str());
}
else if (key == LIVELINESS_QOS)
{
const char* kind = element->Attribute(KIND);
std::string auxstring(kind ? kind : LIVELINESS_KIND_NOT_PRESENT);
if (auxstring == _AUTOMATIC_LIVELINESS_QOS)
{
rdata->liveliness.kind = dds::AUTOMATIC_LIVELINESS_QOS;
}
else if (auxstring == _MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
{
rdata->liveliness.kind = dds::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS;
}
else if (auxstring == _MANUAL_BY_TOPIC_LIVELINESS_QOS)
{
rdata->liveliness.kind = dds::MANUAL_BY_TOPIC_LIVELINESS_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, liveliness of kind: " << auxstring << " is not valid");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
const char* leaseDuration_ms = element->Attribute(LEASE_DURATION_MS);
auxstring = std::string(leaseDuration_ms ? leaseDuration_ms : _INF);
if (auxstring == _INF)
{
rdata->liveliness.lease_duration = dds::c_TimeInfinite;
}
else
{
uint32_t milliseclease = std::strtoul(auxstring.c_str(), nullptr, 10);
rdata->liveliness.lease_duration =
fastdds::rtps::TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t();
if (milliseclease == 0)
{
EPROSIMA_LOG_WARNING(RTPS_EDP, "BAD XML:livelinessQos leaseDuration is 0");
}
}
}
else if (key == DISABLE_POSITIVE_ACKS)
{
// Disable positive acks
if (XMLP_ret::XML_OK !=
XMLParser::getXMLDisablePositiveAcksQos(element, rdata->disable_positive_acks, 0))
{
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_WARNING(RTPS_EDP, "Unkown Endpoint-XML tag, ignoring " << key);
}
element = element->NextSiblingElement();
}
if (rdata->user_defined_id() == 0)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Reader XML endpoint with NO ID defined");
delete(rdata);
return XMLP_ret::XML_ERROR;
}
for (const Locator_t& loc : unicast_locators)
{
rdata->add_unicast_locator(loc);
}
for (const Locator_t& loc : multicast_locators)
{
rdata->add_multicast_locator(loc);
}
pdata->m_readers.push_back(rdata);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLEndpointParser::loadXMLWriterEndpoint(
tinyxml2::XMLElement* xml_endpoint,
StaticRTPSParticipantInfo* pdata)
{
LocatorList_t unicast_locators;
LocatorList_t multicast_locators;
tinyxml2::XMLNode* xml_endpoint_child = xml_endpoint;
tinyxml2::XMLElement* element = xml_endpoint_child->FirstChildElement();
while (element != nullptr)
{
std::string key(element->Name());
if (key == UNICAST_LOCATOR)
{
Locator_t loc;
loc.kind = 1;
const char* address = element->Attribute(ADDRESS);
std::string auxString(address ? address : "");
IPLocator::setIPv4(loc, auxString);
int port = 0;
element->QueryIntAttribute(PORT, &port);
loc.port = static_cast<uint16_t>(port);
unicast_locators.push_back(loc);
}
else if (key == MULTICAST_LOCATOR)
{
Locator_t loc;
loc.kind = 1;
const char* address = element->Attribute(ADDRESS);
std::string auxString(address ? address : "");
IPLocator::setIPv4(loc, auxString);
int port = 0;
element->QueryIntAttribute(PORT, &port);
loc.port = static_cast<uint16_t>(port);
multicast_locators.push_back(loc);
}
element = element->NextSiblingElement();
}
WriterProxyData* wdata = new WriterProxyData(unicast_locators.size(), multicast_locators.size());
xml_endpoint_child = xml_endpoint;
element = xml_endpoint_child->FirstChildElement();
while (element != nullptr)
{
std::string key(element->Name());
if (key == USER_ID)
{
int16_t id = static_cast<int16_t>(std::strtol(get_element_text(element).c_str(), nullptr, 10));
if (id <= 0 || m_endpointIds.insert(id).second == false)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Repeated or negative ID in XML file");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
wdata->user_defined_id(id);
}
else if (key == ENTITY_ID)
{
int32_t id = std::strtol(get_element_text(element).c_str(), nullptr, 10);
if (id <= 0 || m_entityIds.insert(id).second == false)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Repeated or negative entityId in XML file");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
octet* c = (octet*)&id;
wdata->guid.entityId.value[2] = c[0];
wdata->guid.entityId.value[1] = c[1];
wdata->guid.entityId.value[0] = c[2];
}
else if (key == EXPECT_INLINE_QOS)
{
EPROSIMA_LOG_WARNING(RTPS_EDP, "BAD XML tag: Writers don't use expectInlineQos tag");
}
else if (key == TOPIC)
{
const char* topicName = element->Attribute(NAME);
wdata->topic_name = std::string(topicName ? topicName : EPROSIMA_UNKNOWN_STRING);
const char* typeName = element->Attribute(DATA_TYPE);
wdata->type_name = std::string(typeName ? typeName : EPROSIMA_UNKNOWN_STRING);
const char* kind = element->Attribute(KIND);
std::string auxString(kind ? kind : "");
if (auxString == _NO_KEY)
{
wdata->topic_kind = NO_KEY;
wdata->guid.entityId.value[3] = 0x03;
}
else if (auxString == _WITH_KEY)
{
wdata->topic_kind = WITH_KEY;
wdata->guid.entityId.value[3] = 0x02;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, topic of kind: " << auxString << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
if (wdata->topic_name == EPROSIMA_UNKNOWN_STRING || wdata->type_name == EPROSIMA_UNKNOWN_STRING)
{
EPROSIMA_LOG_ERROR(RTPS_EDP,
"Bad XML file, topic: " << wdata->topic_name << " or typeName: " << wdata->type_name <<
" undefined");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == TOPIC_NAME)
{
wdata->topic_name = std::string(get_element_text(element));
}
else if (key == TOPIC_DATA_TYPE)
{
wdata->type_name = std::string(get_element_text(element));
}
else if (key == TOPIC_KIND)
{
std::string auxString = std::string(get_element_text(element));
if (auxString == _NO_KEY)
{
wdata->topic_kind = NO_KEY;
wdata->guid.entityId.value[3] = 0x03;
}
else if (auxString == _WITH_KEY)
{
wdata->topic_kind = WITH_KEY;
wdata->guid.entityId.value[3] = 0x02;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, topic of kind: " << auxString << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == RELIABILITY_QOS)
{
std::string auxString = std::string(get_element_text(element));
if (auxString == _RELIABLE_RELIABILITY_QOS)
{
wdata->reliability.kind = dds::RELIABLE_RELIABILITY_QOS;
}
else if (auxString == _BEST_EFFORT_RELIABILITY_QOS)
{
wdata->reliability.kind = dds::BEST_EFFORT_RELIABILITY_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, endpoint of stateKind: " << auxString << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == UNICAST_LOCATOR)
{
// Empty but necessary to avoid warning on last else
}
else if (key == MULTICAST_LOCATOR)
{
// Empty but necessary to avoid warning on last else
}
else if (key == DURABILITY_QOS)
{
std::string auxstring = std::string(get_element_text(element));
if (auxstring == _PERSISTENT_DURABILITY_QOS)
{
wdata->durability.kind = dds::PERSISTENT_DURABILITY_QOS;
}
else if (auxstring == _TRANSIENT_DURABILITY_QOS)
{
wdata->durability.kind = dds::TRANSIENT_DURABILITY_QOS;
}
else if (auxstring == _TRANSIENT_LOCAL_DURABILITY_QOS)
{
wdata->durability.kind = dds::TRANSIENT_LOCAL_DURABILITY_QOS;
}
else if (auxstring == _VOLATILE_DURABILITY_QOS)
{
wdata->durability.kind = dds::VOLATILE_DURABILITY_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, durability of kind: " << auxstring << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
}
else if (key == OWNERSHIP_QOS)
{
const char* kind = element->Attribute(KIND);
std::string auxstring(kind ? kind : OWNERSHIP_KIND_NOT_PRESENT);
if (auxstring == _SHARED_OWNERSHIP_QOS)
{
wdata->ownership.kind = dds::SHARED_OWNERSHIP_QOS;
}
else if (auxstring == _EXCLUSIVE_OWNERSHIP_QOS)
{
wdata->ownership.kind = dds::EXCLUSIVE_OWNERSHIP_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, ownership of kind: " << auxstring << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
int strength = 0;
element->QueryIntAttribute(STRENGTH, &strength);
wdata->ownership_strength.value = strength;
}
else if (key == PARTITION_QOS)
{
wdata->partition.push_back(get_element_text(element).c_str());
}
else if (key == LIVELINESS_QOS)
{
const char* kind = element->Attribute(KIND);
std::string auxstring(kind ? kind : LIVELINESS_KIND_NOT_PRESENT);
if (auxstring == _AUTOMATIC_LIVELINESS_QOS)
{
wdata->liveliness.kind = dds::AUTOMATIC_LIVELINESS_QOS;
}
else if (auxstring == _MANUAL_BY_PARTICIPANT_LIVELINESS_QOS)
{
wdata->liveliness.kind = dds::MANUAL_BY_PARTICIPANT_LIVELINESS_QOS;
}
else if (auxstring == _MANUAL_BY_TOPIC_LIVELINESS_QOS)
{
wdata->liveliness.kind = dds::MANUAL_BY_TOPIC_LIVELINESS_QOS;
}
else
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Bad XML file, liveliness of kind: " << auxstring << " is not valid");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
const char* leaseDuration_ms = element->Attribute(LEASE_DURATION_MS);
auxstring = std::string(leaseDuration_ms ? leaseDuration_ms : _INF);
if (auxstring == _INF)
{
wdata->liveliness.lease_duration = dds::c_TimeInfinite;
}
else
{
uint32_t milliseclease = std::strtoul(auxstring.c_str(), nullptr, 10);
wdata->liveliness.lease_duration =
fastdds::rtps::TimeConv::MilliSeconds2Time_t((double)milliseclease).to_duration_t();
if (milliseclease == 0)
{
EPROSIMA_LOG_WARNING(RTPS_EDP, "BAD XML:livelinessQos leaseDuration is 0");
}
}
}
else if (key == DISABLE_POSITIVE_ACKS)
{
// Disable positive acks
if (XMLP_ret::XML_OK !=
XMLParser::getXMLDisablePositiveAcksQos(element, wdata->disable_positive_acks, 0))
{
return XMLP_ret::XML_ERROR;
}
}
else
{
EPROSIMA_LOG_WARNING(RTPS_EDP, "Unkown Endpoint-XML tag, ignoring " << key);
}
element = element->NextSiblingElement();
}
if (wdata->user_defined_id() == 0)
{
EPROSIMA_LOG_ERROR(RTPS_EDP, "Writer XML endpoint with NO ID defined");
delete(wdata);
return XMLP_ret::XML_ERROR;
}
for (const Locator_t& loc : unicast_locators)
{
wdata->add_unicast_locator(loc);
}
for (const Locator_t& loc : multicast_locators)
{
wdata->add_multicast_locator(loc);
}
pdata->m_writers.push_back(wdata);
return XMLP_ret::XML_OK;
}
XMLP_ret XMLEndpointParser::lookforReader(
const char* partname,
uint16_t id,
ReaderProxyData** rdataptr,
uint32_t& position)
{
for (std::vector<StaticRTPSParticipantInfo*>::iterator pit = m_RTPSParticipants.begin();
pit != m_RTPSParticipants.end(); ++pit)
{
if ((*pit)->m_RTPSParticipantName == partname || true) //it doenst matter the name fo the RTPSParticipant, only for organizational purposes
{
position = 0;
for (std::vector<ReaderProxyData*>::iterator rit = (*pit)->m_readers.begin();
rit != (*pit)->m_readers.end(); ++rit)
{
if ((*rit)->user_defined_id() == id)
{
if (nullptr != rdataptr)
{
*rdataptr = *rit;
}
return XMLP_ret::XML_OK;
}
++position;
}
}
}
return XMLP_ret::XML_ERROR;
}
XMLP_ret XMLEndpointParser::lookforWriter(
const char* partname,
uint16_t id,
WriterProxyData** wdataptr,
uint32_t& position)
{
for (std::vector<StaticRTPSParticipantInfo*>::iterator pit = m_RTPSParticipants.begin();
pit != m_RTPSParticipants.end(); ++pit)
{
if ((*pit)->m_RTPSParticipantName == partname || true) //it doenst matter the name fo the RTPSParticipant, only for organizational purposes
{
position = 0;
for (std::vector<WriterProxyData*>::iterator wit = (*pit)->m_writers.begin();
wit != (*pit)->m_writers.end(); ++wit)
{
if ((*wit)->user_defined_id() == id)
{
if (nullptr != wdataptr)
{
*wdataptr = *wit;
}
return XMLP_ret::XML_OK;
}
++position;
}
}
}
return XMLP_ret::XML_ERROR;
}
XMLP_ret XMLEndpointParser::get_reader_from_position(
const std::string& participant_name,
size_t pos,
rtps::ReaderProxyData** rdataptr)
{
XMLP_ret ret_value {XMLP_ret::XML_ERROR};
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
[&participant_name](StaticRTPSParticipantInfo* participant_info)
{
if (participant_info->m_RTPSParticipantName ==
participant_name.substr(0, participant_name.find_first_of('#')))
{
return true;
}
return false;
});
if (m_RTPSParticipants.end() != participant_it && (*participant_it)->m_readers.size() > pos && nullptr != rdataptr)
{
*rdataptr = (*participant_it)->m_readers.at(pos);
ret_value = XMLP_ret::XML_OK;
}
return ret_value;
}
XMLP_ret XMLEndpointParser::get_writer_from_position(
const std::string& participant_name,
size_t pos,
rtps::WriterProxyData** wdataptr)
{
XMLP_ret ret_value {XMLP_ret::XML_ERROR};
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
[&participant_name](StaticRTPSParticipantInfo* participant_info)
{
if (participant_info->m_RTPSParticipantName ==
participant_name.substr(0, participant_name.find_first_of('#')))
{
return true;
}
return false;
});
if (m_RTPSParticipants.end() != participant_it && (*participant_it)->m_writers.size() > pos && nullptr != wdataptr)
{
*wdataptr = (*participant_it)->m_writers.at(pos);
ret_value = XMLP_ret::XML_OK;
}
return ret_value;
}
size_t XMLEndpointParser::get_number_of_readers(
const std::string& participant_name)
{
size_t ret_value {0};
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
[&participant_name](StaticRTPSParticipantInfo* participant_info)
{
if (participant_info->m_RTPSParticipantName ==
participant_name.substr(0, participant_name.find_first_of('#')))
{
return true;
}
return false;
});
if (m_RTPSParticipants.end() != participant_it)
{
ret_value = (*participant_it)->m_readers.size();
}
return ret_value;
}
size_t XMLEndpointParser::get_number_of_writers(
const std::string& participant_name)
{
size_t ret_value {0};
auto participant_it = std::find_if(m_RTPSParticipants.begin(), m_RTPSParticipants.end(),
[&participant_name](StaticRTPSParticipantInfo* participant_info)
{
if (participant_info->m_RTPSParticipantName ==
participant_name.substr(0, participant_name.find_first_of('#')))
{
return true;
}
return false;
});
if (m_RTPSParticipants.end() != participant_it)
{
ret_value = (*participant_it)->m_writers.size();
}
return ret_value;
}
} // namespace xmlparser
} // namespace fastdds
} // namespace eprosima
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

https://github.com/eProsima/Fast-DDS
Cancel

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/OpenCodeShare/Fast-DDS.git
git@gitee.com:OpenCodeShare/Fast-DDS.git
OpenCodeShare
Fast-DDS
Fast-DDS
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /