Skip to content
This repository was archived by the owner on Jul 22, 2021. It is now read-only.

Commit 163d700

Browse files
authored
Alternative StubbornNegotiator that shares ownership of participant (#298)
1 parent 5b66316 commit 163d700

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

rmf_traffic/include/rmf_traffic/schedule/StubbornNegotiator.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ class StubbornNegotiator : public Negotiator
4545
/// The Participant who wants to be stubborn.
4646
StubbornNegotiator(const Participant& participant);
4747

48+
/// Owning Constructor
49+
///
50+
/// The StubbornNegotiator instance will now hold a shared reference to the
51+
/// participant to ensure it maintains its lifetime. This constructor should
52+
/// be used in cases where the StubbornNegotiator instance has a prolonged
53+
/// lifecycle.
54+
///
55+
/// \param[in] participant
56+
/// The Participant who wants to be stubborn.
57+
StubbornNegotiator(std::shared_ptr<const Participant> participant);
58+
4859
void respond(
4960
const schedule::Negotiation::Table::ViewerPtr& table_viewer,
5061
const ResponderPtr& responder) final;

rmf_traffic/src/rmf_traffic/schedule/StubbornNegotiator.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ class StubbornNegotiator::Implementation
2727
public:
2828

2929
const Participant* participant;
30+
std::shared_ptr<const Participant> shared_ref;
3031

3132
};
3233

3334
//==============================================================================
3435
StubbornNegotiator::StubbornNegotiator(const Participant& participant)
35-
: _pimpl(rmf_utils::make_impl<Implementation>(Implementation{&participant}))
36+
: _pimpl(rmf_utils::make_impl<Implementation>(
37+
Implementation{&participant, nullptr}))
38+
{
39+
// Do nothing
40+
}
41+
42+
//==============================================================================
43+
StubbornNegotiator::StubbornNegotiator(
44+
std::shared_ptr<const Participant> participant)
45+
: _pimpl(rmf_utils::make_impl<Implementation>(
46+
Implementation{participant.get(), participant}))
3647
{
3748
// Do nothing
3849
}

0 commit comments

Comments
 (0)