Fix crash when phone is unplugged during entity startup
This commit is contained in:
parent
e76aee2da8
commit
648924d7be
@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
using std::enable_shared_from_this<AndroidAutoEntity>::shared_from_this;
|
using std::enable_shared_from_this<AndroidAutoEntity>::shared_from_this;
|
||||||
void handleStop();
|
void triggerQuit();
|
||||||
|
|
||||||
boost::asio::io_service::strand strand_;
|
boost::asio::io_service::strand strand_;
|
||||||
aasdk::messenger::ICryptor::Pointer cryptor_;
|
aasdk::messenger::ICryptor::Pointer cryptor_;
|
||||||
|
@ -76,7 +76,13 @@ void AndroidAutoEntity::stop()
|
|||||||
{
|
{
|
||||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop.";
|
OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop.";
|
||||||
this->handleStop();
|
|
||||||
|
std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1));
|
||||||
|
|
||||||
|
messenger_->stop();
|
||||||
|
cryptor_->deinit();
|
||||||
|
transport_->stop();
|
||||||
|
eventHandler_ = nullptr;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +95,7 @@ void AndroidAutoEntity::onVersionResponse(uint16_t majorCode, uint16_t minorCode
|
|||||||
if(status == aasdk::proto::enums::VersionResponseStatus::MISMATCH)
|
if(status == aasdk::proto::enums::VersionResponseStatus::MISMATCH)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[AndroidAutoEntity] version mismatch.";
|
OPENAUTO_LOG(error) << "[AndroidAutoEntity] version mismatch.";
|
||||||
eventHandler_->onAndroidAutoQuit();
|
this->triggerQuit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -200,7 +206,7 @@ void AndroidAutoEntity::onShutdownRequest(const aasdk::proto::messages::Shutdown
|
|||||||
aasdk::proto::messages::ShutdownResponse response;
|
aasdk::proto::messages::ShutdownResponse response;
|
||||||
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
auto promise = aasdk::channel::SendPromise::defer(strand_);
|
||||||
promise->then([this, self = this->shared_from_this()]() {
|
promise->then([this, self = this->shared_from_this()]() {
|
||||||
eventHandler_->onAndroidAutoQuit();
|
this->triggerQuit();
|
||||||
},
|
},
|
||||||
std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1));
|
||||||
|
|
||||||
@ -211,7 +217,7 @@ void AndroidAutoEntity::onShutdownRequest(const aasdk::proto::messages::Shutdown
|
|||||||
void AndroidAutoEntity::onShutdownResponse(const aasdk::proto::messages::ShutdownResponse&)
|
void AndroidAutoEntity::onShutdownResponse(const aasdk::proto::messages::ShutdownResponse&)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(info) << "[AndroidAutoEntity] Shutdown response ";
|
OPENAUTO_LOG(info) << "[AndroidAutoEntity] Shutdown response ";
|
||||||
eventHandler_->onAndroidAutoQuit();
|
this->triggerQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request)
|
void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request)
|
||||||
@ -230,17 +236,15 @@ void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::N
|
|||||||
void AndroidAutoEntity::onChannelError(const aasdk::error::Error& e)
|
void AndroidAutoEntity::onChannelError(const aasdk::error::Error& e)
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(error) << "[AndroidAutoEntity] channel error: " << e.what();
|
OPENAUTO_LOG(error) << "[AndroidAutoEntity] channel error: " << e.what();
|
||||||
eventHandler_->onAndroidAutoQuit();
|
this->triggerQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidAutoEntity::handleStop()
|
void AndroidAutoEntity::triggerQuit()
|
||||||
{
|
{
|
||||||
std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1));
|
if(eventHandler_ != nullptr)
|
||||||
|
{
|
||||||
messenger_->stop();
|
eventHandler_->onAndroidAutoQuit();
|
||||||
cryptor_->deinit();
|
}
|
||||||
transport_->stop();
|
|
||||||
eventHandler_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user