Skip to content

Commit

Permalink
Split ping method to send and schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Apr 6, 2018
1 parent 28fc6a3 commit 5059bba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr
private:
using std::enable_shared_from_this<AndroidAutoEntity>::shared_from_this;
void triggerQuit();
void ping();
void schedulePing();
void sendPing();

boost::asio::io_service::strand strand_;
aasdk::messenger::ICryptor::Pointer cryptor_;
Expand Down
21 changes: 13 additions & 8 deletions src/autoapp/Projection/AndroidAutoEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void AndroidAutoEntity::start(IAndroidAutoEntityEventHandler& eventHandler)

serviceList_ = serviceFactory_.create(messenger_);
std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::start, std::placeholders::_1));
this->ping();
this->schedulePing();

auto versionRequestPromise = aasdk::channel::SendPromise::defer(strand_);
versionRequestPromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));
Expand Down Expand Up @@ -253,16 +253,12 @@ void AndroidAutoEntity::triggerQuit()
}
}

void AndroidAutoEntity::ping()
void AndroidAutoEntity::schedulePing()
{
auto promise = IPinger::Promise::defer(strand_);
promise->then([this, self = this->shared_from_this()]() {
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));

aasdk::proto::messages::PingRequest request;
controlServiceChannel_->sendPingRequest(request, std::move(promise));
this->ping();
this->sendPing();
this->schedulePing();
},
[this, self = this->shared_from_this()](auto error) {
if(error != aasdk::error::ErrorCode::OPERATION_ABORTED &&
Expand All @@ -276,6 +272,15 @@ void AndroidAutoEntity::ping()
pinger_->ping(std::move(promise));
}

void AndroidAutoEntity::sendPing()
{
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));

aasdk::proto::messages::PingRequest request;
controlServiceChannel_->sendPingRequest(request, std::move(promise));
}

}
}
}
Expand Down

0 comments on commit 5059bba

Please sign in to comment.