Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
keep fake peer pointer in subscribers
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Boldyrev <[email protected]>
  • Loading branch information
MBoldyrev committed Mar 18, 2019
1 parent 2f7f0e8 commit 7417957
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,32 @@ namespace integration_framework {
// This code feels like part of constructor, but the use of `this'
// to call virtual functions from base class constructor seems wrong.
// Hint: such calls would precede the derived class construction.
fake_peer_wptr_ = fake_peer;
fake_peer_ = fake_peer;
log_ = std::move(log);
// subscribe for all messages
subscriptions_.emplace_back(
getFakePeer().getMstStatesObservable().subscribe(
[this](const auto &message) {
[this, alive = fake_peer](const auto &message) {
this->processMstMessage(message);
}));
subscriptions_.emplace_back(
getFakePeer().getYacStatesObservable().subscribe(
[this](const auto &message) {
[this, alive = fake_peer](const auto &message) {
this->processYacMessage(message);
}));
subscriptions_.emplace_back(
getFakePeer().getOsBatchesObservable().subscribe(
[this](const auto &batch) { this->processOsBatch(batch); }));
[this, alive = fake_peer](const auto &batch) {
this->processOsBatch(batch);
}));
subscriptions_.emplace_back(
getFakePeer().getOgProposalsObservable().subscribe(
[this](const auto &proposal) {
[this, alive = fake_peer](const auto &proposal) {
this->processOgProposal(proposal);
}));
subscriptions_.emplace_back(
getFakePeer().getBatchesObservable().subscribe(
[this](const auto &batches) {
[this, alive = fake_peer](const auto &batches) {
this->processOrderingBatches(*batches);
}));
}
Expand All @@ -51,14 +53,11 @@ namespace integration_framework {
for (auto &subscription : subscriptions_) {
subscription.unsubscribe();
}
fake_peer_wptr_.reset();
fake_peer_.reset();
}

FakePeer &Behaviour::getFakePeer() {
auto fake_peer = fake_peer_wptr_.lock();
assert(fake_peer && "Fake peer shared pointer is not set!"
" Probably the fake peer has gone before the associated behaviour.");
return *fake_peer;
return *fake_peer_;
}

logger::LoggerPtr &Behaviour::getLogger() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace integration_framework {
logger::LoggerPtr &getLogger();

private:
std::weak_ptr<FakePeer> fake_peer_wptr_;
std::shared_ptr<FakePeer> fake_peer_;
std::vector<rxcpp::subscription> subscriptions_;
logger::LoggerPtr log_;
};
Expand Down

0 comments on commit 7417957

Please sign in to comment.