diff --git a/include/f1x/openauto/autoapp/App.hpp b/include/f1x/openauto/autoapp/App.hpp index f7741cc..e2f46fd 100644 --- a/include/f1x/openauto/autoapp/App.hpp +++ b/include/f1x/openauto/autoapp/App.hpp @@ -44,6 +44,8 @@ public: void waitForUSBDevice(); void start(aasdk::tcp::ITCPEndpoint::SocketPointer socket); void stop(); + void pause(); + void resume(); void onAndroidAutoQuit() override; bool disableAutostartEntity = false; diff --git a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp index 7f80039..0ae914c 100644 --- a/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp @@ -51,6 +51,8 @@ public: void start(IAndroidAutoEntityEventHandler& eventHandler) override; void stop() override; + void pause() override; + void resume() override; void onVersionResponse(uint16_t majorCode, uint16_t minorCode, aasdk::proto::enums::VersionResponseStatus::Enum status) override; void onHandshake(const aasdk::common::DataConstBuffer& payload) override; void onServiceDiscoveryRequest(const aasdk::proto::messages::ServiceDiscoveryRequest& request) override; diff --git a/include/f1x/openauto/autoapp/Service/AudioInputService.hpp b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp index a568b1d..c8e56c2 100644 --- a/include/f1x/openauto/autoapp/Service/AudioInputService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp @@ -40,6 +40,8 @@ public: void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onAVChannelSetupRequest(const aasdk::proto::messages::AVChannelSetupRequest& request) override; diff --git a/include/f1x/openauto/autoapp/Service/AudioService.hpp b/include/f1x/openauto/autoapp/Service/AudioService.hpp index 21a0785..034ddec 100644 --- a/include/f1x/openauto/autoapp/Service/AudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioService.hpp @@ -41,6 +41,8 @@ public: void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onAVChannelSetupRequest(const aasdk::proto::messages::AVChannelSetupRequest& request) override; diff --git a/include/f1x/openauto/autoapp/Service/BluetoothService.hpp b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp index 86e4dba..27b46d8 100644 --- a/include/f1x/openauto/autoapp/Service/BluetoothService.hpp +++ b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp @@ -37,6 +37,8 @@ public: BluetoothService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IBluetoothDevice::Pointer bluetoothDevice); void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onBluetoothPairingRequest(const aasdk::proto::messages::BluetoothPairingRequest& request) override; diff --git a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp index fc1cb38..e66da4a 100644 --- a/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp @@ -39,6 +39,8 @@ public: virtual void start(IAndroidAutoEntityEventHandler& eventHandler) = 0; virtual void stop() = 0; + virtual void pause() = 0; + virtual void resume() = 0; }; } diff --git a/include/f1x/openauto/autoapp/Service/IService.hpp b/include/f1x/openauto/autoapp/Service/IService.hpp index a676cb7..7c66f49 100644 --- a/include/f1x/openauto/autoapp/Service/IService.hpp +++ b/include/f1x/openauto/autoapp/Service/IService.hpp @@ -40,6 +40,8 @@ public: virtual void start() = 0; virtual void stop() = 0; + virtual void pause() = 0; + virtual void resume() = 0; virtual void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) = 0; }; diff --git a/include/f1x/openauto/autoapp/Service/InputService.hpp b/include/f1x/openauto/autoapp/Service/InputService.hpp index 6a64bc1..03ed01b 100644 --- a/include/f1x/openauto/autoapp/Service/InputService.hpp +++ b/include/f1x/openauto/autoapp/Service/InputService.hpp @@ -44,6 +44,8 @@ public: void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onBindingRequest(const aasdk::proto::messages::BindingRequest& request) override; diff --git a/include/f1x/openauto/autoapp/Service/SensorService.hpp b/include/f1x/openauto/autoapp/Service/SensorService.hpp index ee0e2b4..d5f59ea 100644 --- a/include/f1x/openauto/autoapp/Service/SensorService.hpp +++ b/include/f1x/openauto/autoapp/Service/SensorService.hpp @@ -40,6 +40,8 @@ public: void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onSensorStartRequest(const aasdk::proto::messages::SensorStartRequestMessage& request) override; diff --git a/include/f1x/openauto/autoapp/Service/VideoService.hpp b/include/f1x/openauto/autoapp/Service/VideoService.hpp index a7bc52d..4c67a05 100644 --- a/include/f1x/openauto/autoapp/Service/VideoService.hpp +++ b/include/f1x/openauto/autoapp/Service/VideoService.hpp @@ -42,6 +42,8 @@ public: void start() override; void stop() override; + void pause() override; + void resume() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onAVChannelSetupRequest(const aasdk::proto::messages::AVChannelSetupRequest& request) override; diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp index a765ee3..ca40401 100644 --- a/src/autoapp/App.cpp +++ b/src/autoapp/App.cpp @@ -84,13 +84,29 @@ void App::stop() { strand_.dispatch([this, self = this->shared_from_this()]() { isStopped_ = true; - connectedAccessoriesEnumerator_->cancel(); - usbHub_->cancel(); + try { + connectedAccessoriesEnumerator_->cancel(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] stop: exception caused by connectedAccessoriesEnumerator_->cancel()"; + } + try { + usbHub_->cancel(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] stop: exception caused by usbHub_->cancel();"; + } if(androidAutoEntity_ != nullptr) { - androidAutoEntity_->stop(); - androidAutoEntity_.reset(); + try { + androidAutoEntity_->stop(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_->stop();"; + } + try { + androidAutoEntity_.reset(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_.reset();"; + } } }); @@ -152,17 +168,51 @@ void App::waitForDevice() usbHub_->start(std::move(promise)); } +void App::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[App] pause..."; + androidAutoEntity_->pause(); + }); +} + +void App::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + if(androidAutoEntity_ != nullptr) + { + OPENAUTO_LOG(info) << "[App] resume..."; + androidAutoEntity_->resume(); + } else { + OPENAUTO_LOG(info) << "[App] Ignore resume -> no androidAutoEntity_ ..."; + } + }); +} + void App::onAndroidAutoQuit() { strand_.dispatch([this, self = this->shared_from_this()]() { OPENAUTO_LOG(info) << "[App] onAndroidAutoQuit."; - androidAutoEntity_->stop(); - androidAutoEntity_.reset(); + try { + androidAutoEntity_->stop(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();"; + } + try { + androidAutoEntity_.reset(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();"; + } if(!isStopped_) { - this->waitForDevice(); + try { + this->waitForDevice(); + } catch (...) { + OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by this->waitForDevice();"; + } + } }); } diff --git a/src/autoapp/Service/AndroidAutoEntity.cpp b/src/autoapp/Service/AndroidAutoEntity.cpp index fa37e34..4312e8d 100644 --- a/src/autoapp/Service/AndroidAutoEntity.cpp +++ b/src/autoapp/Service/AndroidAutoEntity.cpp @@ -87,6 +87,33 @@ void AndroidAutoEntity::stop() }); } +void AndroidAutoEntity::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] pause."; + + try { + std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::pause, std::placeholders::_1)); + messenger_->stop(); + } catch (...) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] exception in pause."; + } + }); +} + +void AndroidAutoEntity::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] resume."; + + try { + std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::resume, std::placeholders::_1)); + } catch (...) { + OPENAUTO_LOG(info) << "[AndroidAutoEntity] exception in resume."; + } + }); +} + void AndroidAutoEntity::onVersionResponse(uint16_t majorCode, uint16_t minorCode, aasdk::proto::enums::VersionResponseStatus::Enum status) { OPENAUTO_LOG(info) << "[AndroidAutoEntity] version response, version: " << majorCode diff --git a/src/autoapp/Service/AudioInputService.cpp b/src/autoapp/Service/AudioInputService.cpp index 78b2666..47e80da 100644 --- a/src/autoapp/Service/AudioInputService.cpp +++ b/src/autoapp/Service/AudioInputService.cpp @@ -54,6 +54,20 @@ void AudioInputService::stop() }); } +void AudioInputService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AudioInputService] pause."; + }); +} + +void AudioInputService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AudioInputService] resume."; + }); +} + void AudioInputService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) { OPENAUTO_LOG(info) << "[AudioInputService] fill features."; diff --git a/src/autoapp/Service/AudioService.cpp b/src/autoapp/Service/AudioService.cpp index 5ddafce..8db28a7 100644 --- a/src/autoapp/Service/AudioService.cpp +++ b/src/autoapp/Service/AudioService.cpp @@ -53,6 +53,20 @@ void AudioService::stop() }); } +void AudioService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AudioService] pause."; + }); +} + +void AudioService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[AudioService] resume."; + }); +} + void AudioService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) { OPENAUTO_LOG(info) << "[AudioService] fill features, channel: " << aasdk::messenger::channelIdToString(channel_->getId()); diff --git a/src/autoapp/Service/BluetoothService.cpp b/src/autoapp/Service/BluetoothService.cpp index b6ae545..043f1b5 100644 --- a/src/autoapp/Service/BluetoothService.cpp +++ b/src/autoapp/Service/BluetoothService.cpp @@ -52,6 +52,20 @@ void BluetoothService::stop() }); } +void BluetoothService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[BluetoothService] pause."; + }); +} + +void BluetoothService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[BluetoothService] resume."; + }); +} + void BluetoothService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) { OPENAUTO_LOG(info) << "[BluetoothService] fill features"; diff --git a/src/autoapp/Service/InputService.cpp b/src/autoapp/Service/InputService.cpp index b5e22fc..f038bb6 100644 --- a/src/autoapp/Service/InputService.cpp +++ b/src/autoapp/Service/InputService.cpp @@ -53,6 +53,20 @@ void InputService::stop() }); } +void InputService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[InputService] pause."; + }); +} + +void InputService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[InputService] resume."; + }); +} + void InputService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) { OPENAUTO_LOG(info) << "[InputService] fill features."; diff --git a/src/autoapp/Service/SensorService.cpp b/src/autoapp/Service/SensorService.cpp index c69b61a..24da391 100644 --- a/src/autoapp/Service/SensorService.cpp +++ b/src/autoapp/Service/SensorService.cpp @@ -58,6 +58,20 @@ void SensorService::stop() }); } +void SensorService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[SensorService] pause."; + }); +} + +void SensorService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[SensorService] resume."; + }); +} + void SensorService::fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) { OPENAUTO_LOG(info) << "[SensorService] fill features."; diff --git a/src/autoapp/Service/VideoService.cpp b/src/autoapp/Service/VideoService.cpp index 2f5ed2e..4abdc29 100644 --- a/src/autoapp/Service/VideoService.cpp +++ b/src/autoapp/Service/VideoService.cpp @@ -54,6 +54,20 @@ void VideoService::stop() }); } +void VideoService::pause() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[VideoService] pause."; + }); +} + +void VideoService::resume() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + OPENAUTO_LOG(info) << "[VideoService] resume."; + }); +} + void VideoService::onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) { OPENAUTO_LOG(info) << "[VideoService] open request, priority: " << request.priority(); diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index e482f76..acf58cf 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -221,29 +221,39 @@ int main(int argc, char* argv[]) }); QObject::connect(&mainWindow, &autoapp::ui::MainWindow::TriggerAppStart, [&app]() { - OPENAUTO_LOG(info) << "[Autoapp] Manual start android auto."; + OPENAUTO_LOG(info) << "[Autoapp] TriggerAppStart: Manual start android auto."; try { - if (std::ifstream("/tmp/android_device")) { - app->disableAutostartEntity = false; - app->stop(); - app->waitForUSBDevice(); - } + app->disableAutostartEntity = false; + app->resume(); + app->waitForUSBDevice(); } catch (...) { - OPENAUTO_LOG(info) << "[Autoapp] Exception in Manual start android auto."; + OPENAUTO_LOG(error) << "[Autoapp] TriggerAppStart: app->waitForUSBDevice();"; } }); QObject::connect(&mainWindow, &autoapp::ui::MainWindow::TriggerAppStop, [&app]() { try { if (std::ifstream("/tmp/android_device")) { - OPENAUTO_LOG(info) << "[Autoapp] Manual stop usb android auto."; + OPENAUTO_LOG(info) << "[Autoapp] TriggerAppStop: Manual stop usb android auto."; app->disableAutostartEntity = true; system("/usr/local/bin/autoapp_helper usbreset"); - usleep(1000000); - app->stop(); + usleep(500000); + try { + app->stop(); + //app->pause(); + } catch (...) { + OPENAUTO_LOG(error) << "[Autoapp] TriggerAppStop: stop();"; + } + } else { - OPENAUTO_LOG(info) << "[Autoapp] Manual stop wifi android auto."; - app->stop(); + OPENAUTO_LOG(info) << "[Autoapp] TriggerAppStop: Manual stop wifi android auto."; + try { + app->stop(); + //app->pause(); + } catch (...) { + OPENAUTO_LOG(error) << "[Autoapp] TriggerAppStop: stop();"; + } + } } catch (...) { OPENAUTO_LOG(info) << "[Autoapp] Exception in manual stop android auto.";