From 124dfa18c1a25c753c2205e65897be84e8773088 Mon Sep 17 00:00:00 2001 From: jose_morato Date: Thu, 27 Jun 2024 17:29:11 +0200 Subject: [PATCH] return string empty if not found address --- Native/OpenDDSWrapper/MulticastInst.cpp | 20 ++++++++++--------- Native/OpenDDSWrapper/RtpsDiscovery.cpp | 9 ++++----- Native/OpenDDSWrapper/RtpsUdpInst.cpp | 11 +++++++--- .../OpenDDSharp.UnitTest/MulticastInstTest.cs | 12 ++++++++++- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Native/OpenDDSWrapper/MulticastInst.cpp b/Native/OpenDDSWrapper/MulticastInst.cpp index 2a2cd9a2..19d91cec 100644 --- a/Native/OpenDDSWrapper/MulticastInst.cpp +++ b/Native/OpenDDSWrapper/MulticastInst.cpp @@ -58,13 +58,15 @@ void MulticastInst_SetPortOffset(::OpenDDS::DCPS::MulticastInst *mi, CORBA::USho char *MulticastInst_GetGroupAddress(::OpenDDS::DCPS::MulticastInst *mi) { const char* addr_str = ::OpenDDS::DCPS::LogAddr(mi->group_address_.get()).c_str(); - + if (addr_str == NULL) { + return CORBA::string_dup(""); + } return CORBA::string_dup(addr_str); } void MulticastInst_SetGroupAddress(::OpenDDS::DCPS::MulticastInst *mi, char *value) { - const ::OpenDDS::DCPS::NetworkAddress * addr_obj = new ::OpenDDS::DCPS::NetworkAddress(value); - mi->group_address(*addr_obj); + const ::OpenDDS::DCPS::NetworkAddress addr_obj(value); + mi->group_address(addr_obj); } char *MulticastInst_GetLocalAddress(::OpenDDS::DCPS::MulticastInst *mi) { @@ -77,7 +79,7 @@ void MulticastInst_SetLocalAddress(::OpenDDS::DCPS::MulticastInst *mi, char *val } CORBA::Double MulticastInst_GetSynBackoff(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->syn_backoff_; + return mi->syn_backoff_.get(); } void MulticastInst_SetSynBackoff(::OpenDDS::DCPS::MulticastInst *mi, CORBA::Double value) { @@ -101,7 +103,7 @@ void MulticastInst_SetSynTimeout(::OpenDDS::DCPS::MulticastInst *mi, TimeValueWr } size_t MulticastInst_GetNakDepth(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->nak_depth_; + return mi->nak_depth_.get(); } void MulticastInst_SetNakDepth(::OpenDDS::DCPS::MulticastInst *mi, size_t value) { @@ -117,7 +119,7 @@ void MulticastInst_SetNakInterval(::OpenDDS::DCPS::MulticastInst *mi, TimeValueW } size_t MulticastInst_GetNakDelayIntervals(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->nak_delay_intervals_; + return mi->nak_delay_intervals_.get(); } void MulticastInst_SetNakDelayIntervals(::OpenDDS::DCPS::MulticastInst *mi, size_t value) { @@ -125,7 +127,7 @@ void MulticastInst_SetNakDelayIntervals(::OpenDDS::DCPS::MulticastInst *mi, size } size_t MulticastInst_GetNakMax(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->nak_max_; + return mi->nak_max_.get(); } void MulticastInst_SetNakMax(::OpenDDS::DCPS::MulticastInst *mi, size_t value) { @@ -141,7 +143,7 @@ void MulticastInst_SetNakTimeout(::OpenDDS::DCPS::MulticastInst *mi, TimeValueWr } CORBA::Octet MulticastInst_GetTtl(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->ttl_; + return mi->ttl_.get(); } void MulticastInst_SetTtl(::OpenDDS::DCPS::MulticastInst *mi, CORBA::Octet value) { @@ -149,7 +151,7 @@ void MulticastInst_SetTtl(::OpenDDS::DCPS::MulticastInst *mi, CORBA::Octet value } size_t MulticastInst_GetRcvBufferSize(::OpenDDS::DCPS::MulticastInst *mi) { - return mi->rcv_buffer_size_; + return mi->rcv_buffer_size_.get(); } void MulticastInst_SetRcvBufferSize(::OpenDDS::DCPS::MulticastInst *mi, size_t value) { diff --git a/Native/OpenDDSWrapper/RtpsDiscovery.cpp b/Native/OpenDDSWrapper/RtpsDiscovery.cpp index d50157e0..815cdb1f 100644 --- a/Native/OpenDDSWrapper/RtpsDiscovery.cpp +++ b/Native/OpenDDSWrapper/RtpsDiscovery.cpp @@ -28,8 +28,7 @@ ::OpenDDS::RTPS::RtpsDiscovery *RtpsDiscovery_new(const char *key) { } TimeValueWrapper RtpsDiscovery_GetResendPeriod(::OpenDDS::RTPS::RtpsDiscovery *d) { - ::OpenDDS::DCPS::TimeDuration td = d->resend_period(); - return td; + return d->resend_period(); } void RtpsDiscovery_SetResendPeriod(::OpenDDS::RTPS::RtpsDiscovery *d, TimeValueWrapper value) { @@ -102,7 +101,7 @@ char *RtpsDiscovery_GetSedpLocalAddress(::OpenDDS::RTPS::RtpsDiscovery *d) { } void RtpsDiscovery_SetSedpLocalAddress(::OpenDDS::RTPS::RtpsDiscovery *d, char *value) { - const ::OpenDDS::DCPS::NetworkAddress addr = static_cast(value); + const ::OpenDDS::DCPS::NetworkAddress addr(value); d->sedp_local_address(addr); } @@ -116,7 +115,7 @@ char *RtpsDiscovery_GetSpdpLocalAddress(::OpenDDS::RTPS::RtpsDiscovery *d) { } void RtpsDiscovery_SetSpdpLocalAddress(::OpenDDS::RTPS::RtpsDiscovery *d, char *value) { - const ::OpenDDS::DCPS::NetworkAddress addr = static_cast(value); + const ::OpenDDS::DCPS::NetworkAddress addr(value); d->spdp_local_address(addr); } @@ -146,7 +145,7 @@ char *RtpsDiscovery_GetDefaultMulticastGroup(::OpenDDS::RTPS::RtpsDiscovery *d, } void RtpsDiscovery_SetDefaultMulticastGroup(::OpenDDS::RTPS::RtpsDiscovery *d, char *value) { - const ::OpenDDS::DCPS::NetworkAddress addr = static_cast(value); + const ::OpenDDS::DCPS::NetworkAddress addr(value); d->default_multicast_group(addr); } diff --git a/Native/OpenDDSWrapper/RtpsUdpInst.cpp b/Native/OpenDDSWrapper/RtpsUdpInst.cpp index a576e315..8c9b03c3 100644 --- a/Native/OpenDDSWrapper/RtpsUdpInst.cpp +++ b/Native/OpenDDSWrapper/RtpsUdpInst.cpp @@ -78,12 +78,15 @@ void RtpsUdpInst_SetTtl(::OpenDDS::DCPS::RtpsUdpInst *ri, CORBA::Octet value) { char *RtpsUdpInst_GetMulticastGroupAddress(::OpenDDS::DCPS::RtpsUdpInst *ri, int domain_id) { const char* addr_str = ::OpenDDS::DCPS::LogAddr(ri->multicast_group_address(domain_id)).c_str(); + if (addr_str == NULL) { + return CORBA::string_dup(""); + } return CORBA::string_dup(addr_str); } void RtpsUdpInst_SetMulticastGroupAddress(::OpenDDS::DCPS::RtpsUdpInst *ri, char *value) { - const OpenDDS::DCPS::NetworkAddress addr = static_cast(value); + const OpenDDS::DCPS::NetworkAddress addr(value); ri->multicast_group_address(addr); } @@ -97,12 +100,14 @@ void RtpsUdpInst_SetMulticastInterface(::OpenDDS::DCPS::RtpsUdpInst *ri, char *v char *RtpsUdpInst_GetLocalAddress(::OpenDDS::DCPS::RtpsUdpInst *ri) { const char* addr_str = ::OpenDDS::DCPS::LogAddr(ri->local_address()).c_str(); - + if (addr_str == NULL) { + return CORBA::string_dup(""); + } return CORBA::string_dup(addr_str); } void RtpsUdpInst_SetLocalAddress(::OpenDDS::DCPS::RtpsUdpInst *ri, char *value) { - const OpenDDS::DCPS::NetworkAddress addr = static_cast(value); + const OpenDDS::DCPS::NetworkAddress addr(value); ri->local_address(addr); } diff --git a/Tests/OpenDDSharp.UnitTest/MulticastInstTest.cs b/Tests/OpenDDSharp.UnitTest/MulticastInstTest.cs index 777864eb..c4ffc30d 100644 --- a/Tests/OpenDDSharp.UnitTest/MulticastInstTest.cs +++ b/Tests/OpenDDSharp.UnitTest/MulticastInstTest.cs @@ -162,7 +162,17 @@ public void TestNonDefaultValues() Assert.IsNotNull(mi.SynTimeout); Assert.AreEqual(10, mi.SynTimeout.Seconds); Assert.AreEqual(500000, mi.SynTimeout.MicroSeconds); - Assert.IsTrue(mi.AsyncSend); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Assert.IsTrue(mi.AsyncSend); + } + else + { + // AsyncSend is not supported on Unix platforms and should always be false. + Assert.IsFalse(mi.AsyncSend); + } + Assert.AreEqual(2, mi.Ttl); Assert.AreEqual(64U, mi.DatalinkControlChunks); Assert.AreEqual(20000, mi.DatalinkReleaseDelay);