Skip to content

Commit b936603

Browse files
Fix PubSubParticipant rtps deprecated
Signed-off-by: Eugenio Collado <[email protected]>
1 parent 3a48940 commit b936603

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

test/blackbox/api/dds-pim/PubSubParticipant.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,13 @@ class PubSubParticipant
671671
return *this;
672672
}
673673

674+
PubSubParticipant& wire_protocol_builtin(
675+
const eprosima::fastrtps::rtps::BuiltinAttributes& wire_protocol_builtin)
676+
{
677+
participant_qos_.wire_protocol().builtin = wire_protocol_builtin;
678+
return *this;
679+
}
680+
674681
bool update_wire_protocol(
675682
const eprosima::fastdds::dds::WireProtocolConfigQos& wire_protocol)
676683
{

test/blackbox/api/fastrtps_deprecated/PubSubParticipant.hpp

+111
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,39 @@ namespace fastrtps {
4747
template<class TypeSupport>
4848
class PubSubParticipant
4949
{
50+
class PrtListener : public ParticipantListener
51+
{
52+
friend class PubSubParticipant;
53+
54+
public:
55+
56+
PrtListener(
57+
PubSubParticipant* participant)
58+
: participant_(participant)
59+
{
60+
}
61+
62+
~PrtListener()
63+
{
64+
}
65+
66+
void onParticipantDiscovery(
67+
Participant* part,
68+
rtps::ParticipantDiscoveryInfo&& info) override
69+
{
70+
(void)part;
71+
(void)info;
72+
participant_->prt_matched();
73+
}
74+
75+
private:
76+
77+
PrtListener& operator =(
78+
const PrtListener&) = delete;
79+
//! A pointer to the participant
80+
PubSubParticipant* participant_;
81+
};
82+
5083
class PubListener : public PublisherListener
5184
{
5285
friend class PubSubParticipant;
@@ -151,6 +184,7 @@ class PubSubParticipant
151184
, publisher_attr_()
152185
, pub_listener_(this)
153186
, sub_listener_(this)
187+
, prt_matched_(0)
154188
, pub_matched_(0)
155189
, sub_matched_(0)
156190
, pub_times_liveliness_lost_(0)
@@ -269,6 +303,59 @@ class PubSubParticipant
269303
publishers_[index]->assert_liveliness();
270304
}
271305

306+
bool wait_discovery(
307+
std::chrono::seconds timeout = std::chrono::seconds::zero(),
308+
uint8_t matched = 0,
309+
bool exact = false)
310+
{
311+
// No need to wait in this case
312+
if (exact && matched == prt_matched_)
313+
{
314+
return true;
315+
}
316+
317+
std::unique_lock<std::mutex> lock(prt_mutex_);
318+
bool ret_value = true;
319+
std::cout << "Participant is waiting discovery..." << std::endl;
320+
321+
if (timeout == std::chrono::seconds::zero())
322+
{
323+
prt_cv_.wait(lock, [&]()
324+
{
325+
if (exact)
326+
{
327+
return prt_matched_ == matched;
328+
}
329+
return prt_matched_ >= matched;
330+
});
331+
}
332+
else
333+
{
334+
if (!prt_cv_.wait_for(lock, timeout, [&]()
335+
{
336+
if (exact)
337+
{
338+
return prt_matched_ == matched;
339+
}
340+
return prt_matched_ >= matched;
341+
}))
342+
{
343+
ret_value = false;
344+
}
345+
}
346+
347+
if (ret_value)
348+
{
349+
std::cout << "Participant discovery finished successfully..." << std::endl;
350+
}
351+
else
352+
{
353+
std::cout << "Participant discovery finished unsuccessfully..." << std::endl;
354+
}
355+
356+
return ret_value;
357+
}
358+
272359
void pub_wait_discovery(
273360
std::chrono::seconds timeout = std::chrono::seconds::zero())
274361
{
@@ -437,6 +524,13 @@ class PubSubParticipant
437524
return *this;
438525
}
439526

527+
PubSubParticipant& wire_protocol_builtin(
528+
const eprosima::fastrtps::rtps::BuiltinAttributes& wire_protocol_builtin)
529+
{
530+
participant_attr_.rtps = wire_protocol.builtin;
531+
return *this;
532+
}
533+
440534
PubSubParticipant& initial_peers(
441535
const eprosima::fastrtps::rtps::LocatorList_t& initial_peers)
442536
{
@@ -601,6 +695,20 @@ class PubSubParticipant
601695
PubSubParticipant& operator =(
602696
const PubSubParticipant&) = delete;
603697

698+
void prt_matched()
699+
{
700+
std::unique_lock<std::mutex> lock(prt_mutex);
701+
++prt_matched_;
702+
prt_cv_.notify_one();
703+
}
704+
705+
void prt_unmatched()
706+
{
707+
std::unique_lock<std::mutex> lock(prt_mutex);
708+
--prt_matched_;
709+
prt_cv_.notify_one();
710+
}
711+
604712
void pub_matched()
605713
{
606714
std::unique_lock<std::mutex> lock(pub_mutex_);
@@ -654,10 +762,13 @@ class PubSubParticipant
654762
//! A listener for subscribers
655763
SubListener sub_listener_;
656764

765+
std::mutex prt_mutex;
657766
std::mutex pub_mutex_;
658767
std::mutex sub_mutex_;
768+
std::condition_variable prt_cv_;
659769
std::condition_variable pub_cv_;
660770
std::condition_variable sub_cv_;
771+
std::atomic<unsigned int> prt_matched_;
661772
std::atomic<unsigned int> pub_matched_;
662773
std::atomic<unsigned int> sub_matched_;
663774

test/blackbox/common/BlackboxTestsDiscovery.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ TEST_P(Discovery, single_unicast_pdp_response)
14171417

14181418
// The main participant will use the test transport and a specific announcments configuration
14191419
main_participant->disable_builtin_transport().add_user_transport_to_pparams(test_transport)
1420-
.wire_protocol(main_wire_protocol);
1420+
.wire_protocol_builtin(main_wire_protocol.builtin);
14211421

14221422
// Start the main participant
14231423
ASSERT_TRUE(main_participant->init_participant());
@@ -1446,7 +1446,7 @@ TEST_P(Discovery, single_unicast_pdp_response)
14461446
auto participant = std::make_shared<PubSubParticipant<HelloWorldPubSubType>>(0, 0, 0, 0);
14471447
// All participants use the same transport
14481448
participant->disable_builtin_transport().add_user_transport_to_pparams(udp_localhost_transport)
1449-
.wire_protocol(wire_protocol);
1449+
.wire_protocol_builtin(wire_protocol.builtin);
14501450
participants.push_back(participant);
14511451
}
14521452

0 commit comments

Comments
 (0)