From 4c01c5cc55e5840ab91d6d51248b080b869f8c17 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Wed, 4 Apr 2018 18:26:20 +0200 Subject: [PATCH 1/9] Set socket options to detect broken connection --- src/autoapp/UI/ConnectDialog.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/autoapp/UI/ConnectDialog.cpp b/src/autoapp/UI/ConnectDialog.cpp index 127e2165..08b4f560 100644 --- a/src/autoapp/UI/ConnectDialog.cpp +++ b/src/autoapp/UI/ConnectDialog.cpp @@ -46,6 +46,8 @@ void ConnectDialog::onConnectButtonClicked() try { + tcpWrapper_.setKeepAliveOption(*socket, true); + tcpWrapper_.setNoDelayOption(*socket, true); tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket)); } catch(const boost::system::system_error& se) From cf3a5e51d7ec45a02b3a8854657cc270c3893c5a Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Thu, 5 Apr 2018 18:09:15 +0200 Subject: [PATCH 2/9] Draft of ping implementation --- .../autoapp/Projection/AndroidAutoEntity.hpp | 7 +- .../openauto/autoapp/Projection/IPinger.hpp | 47 ++++++++++ .../openauto/autoapp/Projection/Pinger.hpp | 57 ++++++++++++ src/autoapp/Projection/AndroidAutoEntity.cpp | 40 +++++++-- .../Projection/AndroidAutoEntityFactory.cpp | 4 +- src/autoapp/Projection/Pinger.cpp | 86 +++++++++++++++++++ src/autoapp/UI/ConnectDialog.cpp | 2 - 7 files changed, 234 insertions(+), 9 deletions(-) create mode 100644 include/f1x/openauto/autoapp/Projection/IPinger.hpp create mode 100644 include/f1x/openauto/autoapp/Projection/Pinger.hpp create mode 100644 src/autoapp/Projection/Pinger.cpp diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp index b085d5e7..786ee77d 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace f1x { @@ -43,7 +44,8 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr aasdk::messenger::ICryptor::Pointer cryptor, aasdk::transport::ITransport::Pointer transport, configuration::IConfiguration::Pointer configuration, - IServiceFactory& serviceFactory); + IServiceFactory& serviceFactory, + IPinger::Pointer pinger); ~AndroidAutoEntity() override; void start(IAndroidAutoEntityEventHandler& eventHandler) override; @@ -55,17 +57,20 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr void onShutdownRequest(const aasdk::proto::messages::ShutdownRequest& request) override; void onShutdownResponse(const aasdk::proto::messages::ShutdownResponse& response) override; void onNavigationFocusRequest(const aasdk::proto::messages::NavigationFocusRequest& request) override; + void onPingResponse(const aasdk::proto::messages::PingResponse& response) override; void onChannelError(const aasdk::error::Error& e) override; private: using std::enable_shared_from_this::shared_from_this; void triggerQuit(); + void ping(); boost::asio::io_service::strand strand_; aasdk::messenger::ICryptor::Pointer cryptor_; aasdk::transport::ITransport::Pointer transport_; configuration::IConfiguration::Pointer configuration_; IServiceFactory& serviceFactory_; + IPinger::Pointer pinger_; aasdk::messenger::IMessenger::Pointer messenger_; aasdk::channel::control::ControlServiceChannel::Pointer controlServiceChannel_; ServiceList serviceList_; diff --git a/include/f1x/openauto/autoapp/Projection/IPinger.hpp b/include/f1x/openauto/autoapp/Projection/IPinger.hpp new file mode 100644 index 00000000..63def2b2 --- /dev/null +++ b/include/f1x/openauto/autoapp/Projection/IPinger.hpp @@ -0,0 +1,47 @@ +/* +* This file is part of openauto project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* openauto is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* openauto is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with openauto. If not, see . +*/ + +#pragma once + +#include + +namespace f1x +{ +namespace openauto +{ +namespace autoapp +{ +namespace projection +{ + +class IPinger +{ +public: + typedef std::shared_ptr Pointer; + typedef aasdk::io::Promise Promise; + + virtual ~IPinger() = default; + virtual void ping(Promise::Pointer promise) = 0; + virtual void pong() = 0; + virtual void cancel() = 0; +}; + +} +} +} +} diff --git a/include/f1x/openauto/autoapp/Projection/Pinger.hpp b/include/f1x/openauto/autoapp/Projection/Pinger.hpp new file mode 100644 index 00000000..8ddaafc1 --- /dev/null +++ b/include/f1x/openauto/autoapp/Projection/Pinger.hpp @@ -0,0 +1,57 @@ +/* +* This file is part of openauto project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* openauto is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* openauto is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with openauto. If not, see . +*/ + +#pragma once + +#include + +namespace f1x +{ +namespace openauto +{ +namespace autoapp +{ +namespace projection +{ + +class Pinger: public IPinger, std::enable_shared_from_this +{ +public: + Pinger(boost::asio::io_service& ioService, time_t duration); + + void ping(Promise::Pointer promise) override; + void pong() override; + void cancel() override; + +private: + using std::enable_shared_from_this::shared_from_this; + + void onTimerExceeded(const boost::system::error_code& error); + + boost::asio::io_service::strand strand_; + boost::asio::deadline_timer timer_; + time_t duration_; + Promise::Pointer promise_; + int64_t pingsCount_; + int64_t pongsCount_; +}; + +} +} +} +} diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index a0c690c1..5e77ba0b 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -35,12 +35,14 @@ AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, aasdk::messenger::ICryptor::Pointer cryptor, aasdk::transport::ITransport::Pointer transport, configuration::IConfiguration::Pointer configuration, - IServiceFactory& serviceFactory) + IServiceFactory& serviceFactory, + IPinger::Pointer pinger) : strand_(ioService) , cryptor_(std::move(cryptor)) , transport_(std::move(transport)) , configuration_(std::move(configuration)) , serviceFactory_(serviceFactory) + , pinger_(std::move(pinger)) , messenger_(std::make_shared(ioService, std::make_shared(ioService, transport_, cryptor_), std::make_shared(ioService, transport_, cryptor_))) @@ -178,6 +180,8 @@ void AndroidAutoEntity::onServiceDiscoveryRequest(const aasdk::proto::messages:: promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendServiceDiscoveryResponse(serviceDiscoveryResponse, std::move(promise)); controlServiceChannel_->receive(this->shared_from_this()); + + this->ping(); } void AndroidAutoEntity::onAudioFocusRequest(const aasdk::proto::messages::AudioFocusRequest& request) @@ -205,10 +209,8 @@ void AndroidAutoEntity::onShutdownRequest(const aasdk::proto::messages::Shutdown aasdk::proto::messages::ShutdownResponse response; auto promise = aasdk::channel::SendPromise::defer(strand_); - promise->then([this, self = this->shared_from_this()]() { - this->triggerQuit(); - }, - std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); + promise->then(std::bind(&AndroidAutoEntity::triggerQuit, this->shared_from_this()), + std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendShutdownResponse(response, std::move(promise)); controlServiceChannel_->receive(this->shared_from_this()); @@ -233,6 +235,14 @@ void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::N controlServiceChannel_->receive(this->shared_from_this()); } +void AndroidAutoEntity::onPingResponse(const aasdk::proto::messages::PingResponse&) +{ + OPENAUTO_LOG(info) << "[AndroidAutoEntity] ping response"; + + pinger_->pong(); + controlServiceChannel_->receive(this->shared_from_this()); +} + void AndroidAutoEntity::onChannelError(const aasdk::error::Error& e) { OPENAUTO_LOG(error) << "[AndroidAutoEntity] channel error: " << e.what(); @@ -247,6 +257,26 @@ void AndroidAutoEntity::triggerQuit() } } +void AndroidAutoEntity::ping() +{ + 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, self = this->shared_from_this()]() { + OPENAUTO_LOG(error) << "[AndroidAutoEntity] ping timer exceeded."; + this->triggerQuit(); + }); + + pinger_->ping(std::move(promise)); +} + } } } diff --git a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp index 0eb69428..a704d039 100644 --- a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp +++ b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace f1x { @@ -59,8 +60,9 @@ IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::transport::I { auto sslWrapper(std::make_shared()); auto cryptor(std::make_shared(std::move(sslWrapper))); + auto pinger(std::make_shared(ioService_, 5000)); - return std::make_shared(ioService_, std::move(cryptor), std::move(transport), configuration_, serviceFactory_); + return std::make_shared(ioService_, std::move(cryptor), std::move(transport), configuration_, serviceFactory_, std::move(pinger)); } } diff --git a/src/autoapp/Projection/Pinger.cpp b/src/autoapp/Projection/Pinger.cpp new file mode 100644 index 00000000..7dd52842 --- /dev/null +++ b/src/autoapp/Projection/Pinger.cpp @@ -0,0 +1,86 @@ +/* +* This file is part of openauto project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* openauto is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* openauto is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with openauto. If not, see . +*/ + +#include + +namespace f1x +{ +namespace openauto +{ +namespace autoapp +{ +namespace projection +{ + +Pinger::Pinger(boost::asio::io_service& ioService, time_t duration) + : strand_(ioService) + , timer_(ioService) + , duration_(duration) + , pingsCount_(0) + , pongsCount_(0) +{ + +} + +void Pinger::ping(Promise::Pointer promise) +{ + strand_.dispatch([this, self = this->shared_from_this(), promise = std::move(promise)]() mutable { + ++pingsCount_; + + promise_ = std::move(promise); + timer_.expires_from_now(boost::posix_time::milliseconds(duration_)); + timer_.async_wait(strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1))); + }); +} + +void Pinger::pong() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + ++pongsCount_; + }); +} + +void Pinger::onTimerExceeded(const boost::system::error_code& error) +{ + if(!error && promise_ != nullptr) + { + if(std::abs(pingsCount_ - pongsCount_) > 1) + { + promise_->reject(); + } + else + { + promise_->resolve(); + } + + promise_.reset(); + } +} + +void Pinger::cancel() +{ + strand_.dispatch([this, self = this->shared_from_this()]() { + promise_.reset(); + timer_.cancel(); + }); +} + +} +} +} +} diff --git a/src/autoapp/UI/ConnectDialog.cpp b/src/autoapp/UI/ConnectDialog.cpp index 08b4f560..127e2165 100644 --- a/src/autoapp/UI/ConnectDialog.cpp +++ b/src/autoapp/UI/ConnectDialog.cpp @@ -46,8 +46,6 @@ void ConnectDialog::onConnectButtonClicked() try { - tcpWrapper_.setKeepAliveOption(*socket, true); - tcpWrapper_.setNoDelayOption(*socket, true); tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket)); } catch(const boost::system::system_error& se) From a0b241802219288c694f5ac0d2c72958f00adf45 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Thu, 5 Apr 2018 18:27:31 +0200 Subject: [PATCH 3/9] Fix invalid inheritance of enable_shared_from_this --- include/f1x/openauto/autoapp/Projection/Pinger.hpp | 2 +- src/autoapp/Projection/AndroidAutoEntity.cpp | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/Pinger.hpp b/include/f1x/openauto/autoapp/Projection/Pinger.hpp index 8ddaafc1..5c111eb4 100644 --- a/include/f1x/openauto/autoapp/Projection/Pinger.hpp +++ b/include/f1x/openauto/autoapp/Projection/Pinger.hpp @@ -29,7 +29,7 @@ namespace autoapp namespace projection { -class Pinger: public IPinger, std::enable_shared_from_this +class Pinger: public IPinger, public std::enable_shared_from_this { public: Pinger(boost::asio::io_service& ioService, time_t duration); diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index 5e77ba0b..7e9c0d13 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -79,8 +79,8 @@ void AndroidAutoEntity::stop() strand_.dispatch([this, self = this->shared_from_this()]() { OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop."; + pinger_->cancel(); std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1)); - messenger_->stop(); cryptor_->deinit(); transport_->stop(); @@ -145,6 +145,7 @@ void AndroidAutoEntity::onHandshake(const aasdk::common::DataConstBuffer& payloa auto authCompletePromise = aasdk::channel::SendPromise::defer(strand_); authCompletePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendAuthComplete(authCompleteIndication, std::move(authCompletePromise)); + this->ping(); } controlServiceChannel_->receive(this->shared_from_this()); @@ -180,8 +181,6 @@ void AndroidAutoEntity::onServiceDiscoveryRequest(const aasdk::proto::messages:: promise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendServiceDiscoveryResponse(serviceDiscoveryResponse, std::move(promise)); controlServiceChannel_->receive(this->shared_from_this()); - - this->ping(); } void AndroidAutoEntity::onAudioFocusRequest(const aasdk::proto::messages::AudioFocusRequest& request) @@ -237,8 +236,6 @@ void AndroidAutoEntity::onNavigationFocusRequest(const aasdk::proto::messages::N void AndroidAutoEntity::onPingResponse(const aasdk::proto::messages::PingResponse&) { - OPENAUTO_LOG(info) << "[AndroidAutoEntity] ping response"; - pinger_->pong(); controlServiceChannel_->receive(this->shared_from_this()); } @@ -266,7 +263,6 @@ void AndroidAutoEntity::ping() aasdk::proto::messages::PingRequest request; controlServiceChannel_->sendPingRequest(request, std::move(promise)); - this->ping(); }, [this, self = this->shared_from_this()]() { From 28fc6a32e947231a29249b5de2fe3c595edfcfe5 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Thu, 5 Apr 2018 23:33:38 +0200 Subject: [PATCH 4/9] Standarize behavior of pinger cancel --- .../openauto/autoapp/Projection/IPinger.hpp | 2 +- .../openauto/autoapp/Projection/Pinger.hpp | 1 + src/autoapp/App.cpp | 4 +- src/autoapp/Projection/AndroidAutoEntity.cpp | 19 ++++---- src/autoapp/Projection/Pinger.cpp | 47 ++++++++++++------- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/IPinger.hpp b/include/f1x/openauto/autoapp/Projection/IPinger.hpp index 63def2b2..379462f8 100644 --- a/include/f1x/openauto/autoapp/Projection/IPinger.hpp +++ b/include/f1x/openauto/autoapp/Projection/IPinger.hpp @@ -33,7 +33,7 @@ class IPinger { public: typedef std::shared_ptr Pointer; - typedef aasdk::io::Promise Promise; + typedef aasdk::io::Promise Promise; virtual ~IPinger() = default; virtual void ping(Promise::Pointer promise) = 0; diff --git a/include/f1x/openauto/autoapp/Projection/Pinger.hpp b/include/f1x/openauto/autoapp/Projection/Pinger.hpp index 5c111eb4..bc7884f6 100644 --- a/include/f1x/openauto/autoapp/Projection/Pinger.hpp +++ b/include/f1x/openauto/autoapp/Projection/Pinger.hpp @@ -46,6 +46,7 @@ class Pinger: public IPinger, public std::enable_shared_from_this boost::asio::io_service::strand strand_; boost::asio::deadline_timer timer_; time_t duration_; + bool cancelled_; Promise::Pointer promise_; int64_t pingsCount_; int64_t pongsCount_; diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp index b3f92a00..26274c7c 100644 --- a/src/autoapp/App.cpp +++ b/src/autoapp/App.cpp @@ -165,8 +165,8 @@ void App::onUSBHubError(const aasdk::error::Error& error) { OPENAUTO_LOG(error) << "[App] usb hub error: " << error.what(); - if(error.getCode() != aasdk::error::ErrorCode::OPERATION_ABORTED && - error.getCode() != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS) + if(error != aasdk::error::ErrorCode::OPERATION_ABORTED && + error != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS) { this->waitForDevice(); } diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index 7e9c0d13..b36bb291 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -60,17 +60,18 @@ void AndroidAutoEntity::start(IAndroidAutoEntityEventHandler& eventHandler) { strand_.dispatch([this, self = this->shared_from_this(), eventHandler = &eventHandler]() { OPENAUTO_LOG(info) << "[AndroidAutoEntity] start."; - eventHandler_ = eventHandler; cryptor_->init(); serviceList_ = serviceFactory_.create(messenger_); std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::start, std::placeholders::_1)); + this->ping(); - controlServiceChannel_->receive(this->shared_from_this()); auto versionRequestPromise = aasdk::channel::SendPromise::defer(strand_); versionRequestPromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendVersionRequest(std::move(versionRequestPromise)); + eventHandler_ = eventHandler; + controlServiceChannel_->receive(this->shared_from_this()); }); } @@ -79,12 +80,12 @@ void AndroidAutoEntity::stop() strand_.dispatch([this, self = this->shared_from_this()]() { OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop."; + eventHandler_ = nullptr; pinger_->cancel(); std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1)); messenger_->stop(); cryptor_->deinit(); transport_->stop(); - eventHandler_ = nullptr; }); } @@ -145,7 +146,6 @@ void AndroidAutoEntity::onHandshake(const aasdk::common::DataConstBuffer& payloa auto authCompletePromise = aasdk::channel::SendPromise::defer(strand_); authCompletePromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendAuthComplete(authCompleteIndication, std::move(authCompletePromise)); - this->ping(); } controlServiceChannel_->receive(this->shared_from_this()); @@ -212,7 +212,6 @@ void AndroidAutoEntity::onShutdownRequest(const aasdk::proto::messages::Shutdown std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendShutdownResponse(response, std::move(promise)); - controlServiceChannel_->receive(this->shared_from_this()); } void AndroidAutoEntity::onShutdownResponse(const aasdk::proto::messages::ShutdownResponse&) @@ -265,9 +264,13 @@ void AndroidAutoEntity::ping() controlServiceChannel_->sendPingRequest(request, std::move(promise)); this->ping(); }, - [this, self = this->shared_from_this()]() { - OPENAUTO_LOG(error) << "[AndroidAutoEntity] ping timer exceeded."; - this->triggerQuit(); + [this, self = this->shared_from_this()](auto error) { + if(error != aasdk::error::ErrorCode::OPERATION_ABORTED && + error != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS) + { + OPENAUTO_LOG(error) << "[AndroidAutoEntity] ping timer exceeded."; + this->triggerQuit(); + } }); pinger_->ping(std::move(promise)); diff --git a/src/autoapp/Projection/Pinger.cpp b/src/autoapp/Projection/Pinger.cpp index 7dd52842..8be0cdee 100644 --- a/src/autoapp/Projection/Pinger.cpp +++ b/src/autoapp/Projection/Pinger.cpp @@ -31,6 +31,7 @@ Pinger::Pinger(boost::asio::io_service& ioService, time_t duration) : strand_(ioService) , timer_(ioService) , duration_(duration) + , cancelled_(false) , pingsCount_(0) , pongsCount_(0) { @@ -40,11 +41,20 @@ Pinger::Pinger(boost::asio::io_service& ioService, time_t duration) void Pinger::ping(Promise::Pointer promise) { strand_.dispatch([this, self = this->shared_from_this(), promise = std::move(promise)]() mutable { - ++pingsCount_; + cancelled_ = false; - promise_ = std::move(promise); - timer_.expires_from_now(boost::posix_time::milliseconds(duration_)); - timer_.async_wait(strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1))); + if(promise_ != nullptr) + { + promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)); + } + else + { + ++pingsCount_; + + promise_ = std::move(promise); + timer_.expires_from_now(boost::posix_time::milliseconds(duration_)); + timer_.async_wait(strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1))); + } }); } @@ -57,25 +67,30 @@ void Pinger::pong() void Pinger::onTimerExceeded(const boost::system::error_code& error) { - if(!error && promise_ != nullptr) + if(promise_ == nullptr) { - if(std::abs(pingsCount_ - pongsCount_) > 1) - { - promise_->reject(); - } - else - { - promise_->resolve(); - } - - promise_.reset(); + return; } + else if(error == boost::asio::error::operation_aborted || cancelled_) + { + promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_ABORTED)); + } + else if(pingsCount_ - pongsCount_ > 1) + { + promise_->reject(aasdk::error::Error()); + } + else + { + promise_->resolve(); + } + + promise_.reset(); } void Pinger::cancel() { strand_.dispatch([this, self = this->shared_from_this()]() { - promise_.reset(); + cancelled_ = true; timer_.cancel(); }); } From 5059bba795cd2da05410ffb33fb10c720a78263b Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Fri, 6 Apr 2018 19:50:34 +0200 Subject: [PATCH 5/9] Split ping method to send and schedule --- .../autoapp/Projection/AndroidAutoEntity.hpp | 3 ++- src/autoapp/Projection/AndroidAutoEntity.cpp | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp index 786ee77d..ab73a6c7 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp @@ -63,7 +63,8 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr private: using std::enable_shared_from_this::shared_from_this; void triggerQuit(); - void ping(); + void schedulePing(); + void sendPing(); boost::asio::io_service::strand strand_; aasdk::messenger::ICryptor::Pointer cryptor_; diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index b36bb291..9e20a482 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -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)); @@ -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 && @@ -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)); +} + } } } From dfd3cb7b0cca9231a34032d101e06cbf9fde5f40 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Fri, 6 Apr 2018 20:14:47 +0200 Subject: [PATCH 6/9] Inject messenger to the entity --- .../openauto/autoapp/Projection/AndroidAutoEntity.hpp | 7 ++++--- src/autoapp/Projection/AndroidAutoEntity.cpp | 11 ++++------- src/autoapp/Projection/AndroidAutoEntityFactory.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp index ab73a6c7..4101c95b 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include @@ -43,6 +43,7 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr AndroidAutoEntity(boost::asio::io_service& ioService, aasdk::messenger::ICryptor::Pointer cryptor, aasdk::transport::ITransport::Pointer transport, + aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration, IServiceFactory& serviceFactory, IPinger::Pointer pinger); @@ -69,11 +70,11 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr boost::asio::io_service::strand strand_; aasdk::messenger::ICryptor::Pointer cryptor_; aasdk::transport::ITransport::Pointer transport_; + aasdk::messenger::IMessenger::Pointer messenger_; + aasdk::channel::control::IControlServiceChannel::Pointer controlServiceChannel_; configuration::IConfiguration::Pointer configuration_; IServiceFactory& serviceFactory_; IPinger::Pointer pinger_; - aasdk::messenger::IMessenger::Pointer messenger_; - aasdk::channel::control::ControlServiceChannel::Pointer controlServiceChannel_; ServiceList serviceList_; IAndroidAutoEntityEventHandler* eventHandler_; }; diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index 9e20a482..94cbd7cb 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -16,9 +16,7 @@ * along with openauto. If not, see . */ -#include -#include -#include +#include #include #include @@ -34,19 +32,18 @@ namespace projection AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, aasdk::messenger::ICryptor::Pointer cryptor, aasdk::transport::ITransport::Pointer transport, + aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration, IServiceFactory& serviceFactory, IPinger::Pointer pinger) : strand_(ioService) , cryptor_(std::move(cryptor)) , transport_(std::move(transport)) + , messenger_(std::move(messenger)) + , controlServiceChannel_(std::make_shared(strand_, messenger_)) , configuration_(std::move(configuration)) , serviceFactory_(serviceFactory) , pinger_(std::move(pinger)) - , messenger_(std::make_shared(ioService, - std::make_shared(ioService, transport_, cryptor_), - std::make_shared(ioService, transport_, cryptor_))) - , controlServiceChannel_(std::make_shared(strand_, messenger_)) , eventHandler_(nullptr) { } diff --git a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp index a704d039..b9651fc8 100644 --- a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp +++ b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -60,9 +63,11 @@ IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::transport::I { auto sslWrapper(std::make_shared()); auto cryptor(std::make_shared(std::move(sslWrapper))); + auto messenger(std::make_shared(ioService_, + std::make_shared(ioService_, transport, cryptor), + std::make_shared(ioService_, transport, cryptor))); auto pinger(std::make_shared(ioService_, 5000)); - - return std::make_shared(ioService_, std::move(cryptor), std::move(transport), configuration_, serviceFactory_, std::move(pinger)); + return std::make_shared(ioService_, std::move(cryptor), std::move(transport), std::move(messenger), configuration_, serviceFactory_, std::move(pinger)); } } From 24bbe66954043c20ae3d790da2d24931513fd3aa Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Fri, 6 Apr 2018 20:24:08 +0200 Subject: [PATCH 7/9] Inject list of services instead of service factory --- .../autoapp/Projection/AndroidAutoEntity.hpp | 7 +++---- src/autoapp/Projection/AndroidAutoEntity.cpp | 13 +++++-------- src/autoapp/Projection/AndroidAutoEntityFactory.cpp | 6 +++++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp index 4101c95b..c33eab57 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include namespace f1x @@ -45,7 +45,7 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr aasdk::transport::ITransport::Pointer transport, aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration, - IServiceFactory& serviceFactory, + ServiceList serviceList, IPinger::Pointer pinger); ~AndroidAutoEntity() override; @@ -73,9 +73,8 @@ class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::contr aasdk::messenger::IMessenger::Pointer messenger_; aasdk::channel::control::IControlServiceChannel::Pointer controlServiceChannel_; configuration::IConfiguration::Pointer configuration_; - IServiceFactory& serviceFactory_; - IPinger::Pointer pinger_; ServiceList serviceList_; + IPinger::Pointer pinger_; IAndroidAutoEntityEventHandler* eventHandler_; }; diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Projection/AndroidAutoEntity.cpp index 94cbd7cb..fbd9a7ee 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Projection/AndroidAutoEntity.cpp @@ -34,7 +34,7 @@ AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, aasdk::transport::ITransport::Pointer transport, aasdk::messenger::IMessenger::Pointer messenger, configuration::IConfiguration::Pointer configuration, - IServiceFactory& serviceFactory, + ServiceList serviceList, IPinger::Pointer pinger) : strand_(ioService) , cryptor_(std::move(cryptor)) @@ -42,7 +42,7 @@ AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, , messenger_(std::move(messenger)) , controlServiceChannel_(std::make_shared(strand_, messenger_)) , configuration_(std::move(configuration)) - , serviceFactory_(serviceFactory) + , serviceList_(std::move(serviceList)) , pinger_(std::move(pinger)) , eventHandler_(nullptr) { @@ -58,16 +58,13 @@ void AndroidAutoEntity::start(IAndroidAutoEntityEventHandler& eventHandler) strand_.dispatch([this, self = this->shared_from_this(), eventHandler = &eventHandler]() { OPENAUTO_LOG(info) << "[AndroidAutoEntity] start."; - cryptor_->init(); - - serviceList_ = serviceFactory_.create(messenger_); + eventHandler_ = eventHandler; std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::start, std::placeholders::_1)); this->schedulePing(); auto versionRequestPromise = aasdk::channel::SendPromise::defer(strand_); versionRequestPromise->then([]() {}, std::bind(&AndroidAutoEntity::onChannelError, this->shared_from_this(), std::placeholders::_1)); controlServiceChannel_->sendVersionRequest(std::move(versionRequestPromise)); - eventHandler_ = eventHandler; controlServiceChannel_->receive(this->shared_from_this()); }); } @@ -78,11 +75,11 @@ void AndroidAutoEntity::stop() OPENAUTO_LOG(info) << "[AndroidAutoEntity] stop."; eventHandler_ = nullptr; - pinger_->cancel(); std::for_each(serviceList_.begin(), serviceList_.end(), std::bind(&IService::stop, std::placeholders::_1)); + pinger_->cancel(); messenger_->stop(); - cryptor_->deinit(); transport_->stop(); + cryptor_->deinit(); }); } diff --git a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp index b9651fc8..c111f286 100644 --- a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp +++ b/src/autoapp/Projection/AndroidAutoEntityFactory.cpp @@ -63,11 +63,15 @@ IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::transport::I { auto sslWrapper(std::make_shared()); auto cryptor(std::make_shared(std::move(sslWrapper))); + cryptor->init(); + auto messenger(std::make_shared(ioService_, std::make_shared(ioService_, transport, cryptor), std::make_shared(ioService_, transport, cryptor))); + + auto serviceList = serviceFactory_.create(messenger); auto pinger(std::make_shared(ioService_, 5000)); - return std::make_shared(ioService_, std::move(cryptor), std::move(transport), std::move(messenger), configuration_, serviceFactory_, std::move(pinger)); + return std::make_shared(ioService_, std::move(cryptor), std::move(transport), std::move(messenger), configuration_, std::move(serviceList), std::move(pinger)); } } From 675e6cfcf6c05de35cb8a30f4c0f23eb596e293e Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Fri, 6 Apr 2018 20:33:27 +0200 Subject: [PATCH 8/9] Cleanup entity creation --- include/f1x/openauto/autoapp/App.hpp | 1 - src/autoapp/App.cpp | 71 ++++++++++++++-------------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/f1x/openauto/autoapp/App.hpp b/include/f1x/openauto/autoapp/App.hpp index 5bbdbe2c..81c3f39b 100644 --- a/include/f1x/openauto/autoapp/App.hpp +++ b/include/f1x/openauto/autoapp/App.hpp @@ -48,7 +48,6 @@ class App: public projection::IAndroidAutoEntityEventHandler, public std::enable private: using std::enable_shared_from_this::shared_from_this; - void enumerateDevices(); void waitForDevice(); void aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle); diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp index 26274c7c..a58aad30 100644 --- a/src/autoapp/App.cpp +++ b/src/autoapp/App.cpp @@ -54,29 +54,28 @@ void App::waitForUSBDevice() void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket) { strand_.dispatch([this, self = this->shared_from_this(), socket = std::move(socket)]() mutable { - if(androidAutoEntity_ == nullptr) - { - try - { - usbHub_->cancel(); - connectedAccessoriesEnumerator_->cancel(); - - auto tcpEndpoint(std::make_shared(tcpWrapper_, std::move(socket))); - androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint)); - androidAutoEntity_->start(*this); - } - catch(const aasdk::error::Error& error) - { - OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what(); - - androidAutoEntity_.reset(); - this->waitForDevice(); - } - } - else + if(androidAutoEntity_ != nullptr) { tcpWrapper_.close(*socket); OPENAUTO_LOG(warning) << "[App] android auto entity is still running."; + return; + } + + try + { + usbHub_->cancel(); + connectedAccessoriesEnumerator_->cancel(); + + auto tcpEndpoint(std::make_shared(tcpWrapper_, std::move(socket))); + androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint)); + androidAutoEntity_->start(*this); + } + catch(const aasdk::error::Error& error) + { + OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what(); + + androidAutoEntity_.reset(); + this->waitForDevice(); } }); } @@ -91,6 +90,7 @@ void App::stop() if(androidAutoEntity_ != nullptr) { androidAutoEntity_->stop(); + androidAutoEntity_.reset(); } }); } @@ -99,27 +99,26 @@ void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle) { OPENAUTO_LOG(info) << "[App] Device connected."; - if(androidAutoEntity_ == nullptr) + if(androidAutoEntity_ != nullptr) { - try - { - connectedAccessoriesEnumerator_->cancel(); + OPENAUTO_LOG(warning) << "[App] android auto entity is still running."; + return; + } - auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle)); - androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice)); - androidAutoEntity_->start(*this); - } - catch(const aasdk::error::Error& error) - { - OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what(); + try + { + connectedAccessoriesEnumerator_->cancel(); - androidAutoEntity_.reset(); - this->waitForDevice(); - } + auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle)); + androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice)); + androidAutoEntity_->start(*this); } - else + catch(const aasdk::error::Error& error) { - OPENAUTO_LOG(warning) << "[App] android auto entity is still running."; + OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what(); + + androidAutoEntity_.reset(); + this->waitForDevice(); } } From 478caf07675b813302708acf020d0355cb161a72 Mon Sep 17 00:00:00 2001 From: "michal.szwaj" Date: Sat, 7 Apr 2018 00:38:43 +0200 Subject: [PATCH 9/9] Create service package --- include/f1x/openauto/autoapp/App.hpp | 12 ++--- .../Projection/ServiceFinishPromise.hpp | 37 -------------- .../AndroidAutoEntity.hpp | 8 ++-- .../AndroidAutoEntityFactory.hpp | 6 +-- .../AudioInputService.hpp | 8 ++-- .../{Projection => Service}/AudioService.hpp | 8 ++-- .../BluetoothService.hpp | 8 ++-- .../IAndroidAutoEntity.hpp | 4 +- .../IAndroidAutoEntityEventHandler.hpp | 2 +- .../IAndroidAutoEntityFactory.hpp | 4 +- .../{Projection => Service}/IPinger.hpp | 2 +- .../{Projection => Service}/IService.hpp | 2 +- .../IServiceFactory.hpp | 4 +- .../{Projection => Service}/InputService.hpp | 14 +++--- .../MediaAudioService.hpp | 6 +-- .../{Projection => Service}/Pinger.hpp | 4 +- .../{Projection => Service}/SensorService.hpp | 4 +- .../ServiceFactory.hpp | 4 +- .../SpeechAudioService.hpp | 6 +-- .../SystemAudioService.hpp | 6 +-- .../{Projection => Service}/VideoService.hpp | 9 ++-- src/autoapp/App.cpp | 2 +- .../AndroidAutoEntity.cpp | 4 +- .../AndroidAutoEntityFactory.cpp | 8 ++-- .../AudioInputService.cpp | 10 ++-- .../{Projection => Service}/AudioService.cpp | 6 +-- .../BluetoothService.cpp | 6 +-- .../{Projection => Service}/InputService.cpp | 14 +++--- .../MediaAudioService.cpp | 6 +-- .../{Projection => Service}/Pinger.cpp | 4 +- .../{Projection => Service}/SensorService.cpp | 4 +- .../ServiceFactory.cpp | 48 +++++++++---------- .../SpeechAudioService.cpp | 6 +-- .../SystemAudioService.cpp | 6 +-- .../{Projection => Service}/VideoService.cpp | 6 +-- src/autoapp/autoapp.cpp | 8 ++-- 36 files changed, 129 insertions(+), 167 deletions(-) delete mode 100644 include/f1x/openauto/autoapp/Projection/ServiceFinishPromise.hpp rename include/f1x/openauto/autoapp/{Projection => Service}/AndroidAutoEntity.hpp (94%) rename include/f1x/openauto/autoapp/{Projection => Service}/AndroidAutoEntityFactory.hpp (91%) rename include/f1x/openauto/autoapp/{Projection => Service}/AudioInputService.hpp (91%) rename include/f1x/openauto/autoapp/{Projection => Service}/AudioService.hpp (91%) rename include/f1x/openauto/autoapp/{Projection => Service}/BluetoothService.hpp (88%) rename include/f1x/openauto/autoapp/{Projection => Service}/IAndroidAutoEntity.hpp (91%) rename include/f1x/openauto/autoapp/{Projection => Service}/IAndroidAutoEntityEventHandler.hpp (97%) rename include/f1x/openauto/autoapp/{Projection => Service}/IAndroidAutoEntityFactory.hpp (93%) rename include/f1x/openauto/autoapp/{Projection => Service}/IPinger.hpp (98%) rename include/f1x/openauto/autoapp/{Projection => Service}/IService.hpp (98%) rename include/f1x/openauto/autoapp/{Projection => Service}/IServiceFactory.hpp (92%) rename include/f1x/openauto/autoapp/{Projection => Service}/InputService.hpp (82%) rename include/f1x/openauto/autoapp/{Projection => Service}/MediaAudioService.hpp (85%) rename include/f1x/openauto/autoapp/{Projection => Service}/Pinger.hpp (94%) rename include/f1x/openauto/autoapp/{Projection => Service}/SensorService.hpp (95%) rename include/f1x/openauto/autoapp/{Projection => Service}/ServiceFactory.hpp (95%) rename include/f1x/openauto/autoapp/{Projection => Service}/SpeechAudioService.hpp (85%) rename include/f1x/openauto/autoapp/{Projection => Service}/SystemAudioService.hpp (85%) rename include/f1x/openauto/autoapp/{Projection => Service}/VideoService.hpp (90%) rename src/autoapp/{Projection => Service}/AndroidAutoEntity.cpp (99%) rename src/autoapp/{Projection => Service}/AndroidAutoEntityFactory.cpp (93%) rename src/autoapp/{Projection => Service}/AudioInputService.cpp (95%) rename src/autoapp/{Projection => Service}/AudioService.cpp (97%) rename src/autoapp/{Projection => Service}/BluetoothService.cpp (95%) rename src/autoapp/{Projection => Service}/InputService.cpp (93%) rename src/autoapp/{Projection => Service}/MediaAudioService.cpp (85%) rename src/autoapp/{Projection => Service}/Pinger.cpp (97%) rename src/autoapp/{Projection => Service}/SensorService.cpp (98%) rename src/autoapp/{Projection => Service}/ServiceFactory.cpp (67%) rename src/autoapp/{Projection => Service}/SpeechAudioService.cpp (85%) rename src/autoapp/{Projection => Service}/SystemAudioService.cpp (85%) rename src/autoapp/{Projection => Service}/VideoService.cpp (97%) diff --git a/include/f1x/openauto/autoapp/App.hpp b/include/f1x/openauto/autoapp/App.hpp index 81c3f39b..3dbcab2f 100644 --- a/include/f1x/openauto/autoapp/App.hpp +++ b/include/f1x/openauto/autoapp/App.hpp @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include namespace f1x { @@ -33,12 +33,12 @@ namespace openauto namespace autoapp { -class App: public projection::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this +class App: public service::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this { public: typedef std::shared_ptr Pointer; - App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, + App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, service::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator); void waitForUSBDevice(); @@ -57,10 +57,10 @@ class App: public projection::IAndroidAutoEntityEventHandler, public std::enable aasdk::usb::USBWrapper& usbWrapper_; aasdk::tcp::ITCPWrapper& tcpWrapper_; boost::asio::io_service::strand strand_; - projection::IAndroidAutoEntityFactory& androidAutoEntityFactory_; + service::IAndroidAutoEntityFactory& androidAutoEntityFactory_; aasdk::usb::IUSBHub::Pointer usbHub_; aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator_; - projection::IAndroidAutoEntity::Pointer androidAutoEntity_; + service::IAndroidAutoEntity::Pointer androidAutoEntity_; bool isStopped_; }; diff --git a/include/f1x/openauto/autoapp/Projection/ServiceFinishPromise.hpp b/include/f1x/openauto/autoapp/Projection/ServiceFinishPromise.hpp deleted file mode 100644 index 6b098357..00000000 --- a/include/f1x/openauto/autoapp/Projection/ServiceFinishPromise.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* -* This file is part of openauto project. -* Copyright (C) 2018 f1x.studio (Michal Szwaj) -* -* openauto is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 3 of the License, or -* (at your option) any later version. - -* openauto is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with openauto. If not, see . -*/ - -#pragma once - -#include - -namespace f1x -{ -namespace openauto -{ -namespace autoapp -{ -namespace projection -{ - -typedef aasdk::io::Promise ServiceFinishPromise; - -} -} -} -} diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp similarity index 94% rename from include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp rename to include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp index c33eab57..7f800391 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntity.hpp @@ -24,9 +24,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace f1x { @@ -34,7 +34,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class AndroidAutoEntity: public IAndroidAutoEntity, public aasdk::channel::control::IControlServiceChannelEventHandler, public std::enable_shared_from_this diff --git a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp b/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp similarity index 91% rename from include/f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp rename to include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp index 73b8696b..b9fed4ff 100644 --- a/include/f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/AndroidAutoEntityFactory.hpp @@ -21,8 +21,8 @@ #include #include #include -#include -#include +#include +#include namespace f1x { @@ -30,7 +30,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class AndroidAutoEntityFactory: public IAndroidAutoEntityFactory diff --git a/include/f1x/openauto/autoapp/Projection/AudioInputService.hpp b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp similarity index 91% rename from include/f1x/openauto/autoapp/Projection/AudioInputService.hpp rename to include/f1x/openauto/autoapp/Service/AudioInputService.hpp index 6fea2930..a568b1da 100644 --- a/include/f1x/openauto/autoapp/Projection/AudioInputService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioInputService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include #include namespace f1x @@ -28,7 +28,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class AudioInputService: public aasdk::channel::av::IAVInputServiceChannelEventHandler, public IService, public std::enable_shared_from_this @@ -36,7 +36,7 @@ class AudioInputService: public aasdk::channel::av::IAVInputServiceChannelEventH public: typedef std::shared_ptr Pointer; - AudioInputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioInput::Pointer audioInput); + AudioInputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioInput::Pointer audioInput); void start() override; void stop() override; @@ -55,7 +55,7 @@ class AudioInputService: public aasdk::channel::av::IAVInputServiceChannelEventH boost::asio::io_service::strand strand_; aasdk::channel::av::AVInputServiceChannel::Pointer channel_; - IAudioInput::Pointer audioInput_; + projection::IAudioInput::Pointer audioInput_; int32_t session_; }; diff --git a/include/f1x/openauto/autoapp/Projection/AudioService.hpp b/include/f1x/openauto/autoapp/Service/AudioService.hpp similarity index 91% rename from include/f1x/openauto/autoapp/Projection/AudioService.hpp rename to include/f1x/openauto/autoapp/Service/AudioService.hpp index 82e1d5d1..21a07852 100644 --- a/include/f1x/openauto/autoapp/Projection/AudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/AudioService.hpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include namespace f1x { @@ -29,7 +29,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class AudioService: public aasdk::channel::av::IAudioServiceChannelEventHandler, public IService, public std::enable_shared_from_this @@ -37,7 +37,7 @@ class AudioService: public aasdk::channel::av::IAudioServiceChannelEventHandler, public: typedef std::shared_ptr Pointer; - AudioService(boost::asio::io_service& ioService, aasdk::channel::av::IAudioServiceChannel::Pointer channel, IAudioOutput::Pointer audioOutput); + AudioService(boost::asio::io_service& ioService, aasdk::channel::av::IAudioServiceChannel::Pointer channel, projection::IAudioOutput::Pointer audioOutput); void start() override; void stop() override; @@ -55,7 +55,7 @@ class AudioService: public aasdk::channel::av::IAudioServiceChannelEventHandler, boost::asio::io_service::strand strand_; aasdk::channel::av::IAudioServiceChannel::Pointer channel_; - IAudioOutput::Pointer audioOutput_; + projection::IAudioOutput::Pointer audioOutput_; int32_t session_; }; diff --git a/include/f1x/openauto/autoapp/Projection/BluetoothService.hpp b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp similarity index 88% rename from include/f1x/openauto/autoapp/Projection/BluetoothService.hpp rename to include/f1x/openauto/autoapp/Service/BluetoothService.hpp index ddb17308..86e4dbaa 100644 --- a/include/f1x/openauto/autoapp/Projection/BluetoothService.hpp +++ b/include/f1x/openauto/autoapp/Service/BluetoothService.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace f1x { @@ -28,13 +28,13 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class BluetoothService: public aasdk::channel::bluetooth::IBluetoothServiceChannelEventHandler, public IService, public std::enable_shared_from_this { public: - BluetoothService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IBluetoothDevice::Pointer bluetoothDevice); + BluetoothService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IBluetoothDevice::Pointer bluetoothDevice); void start() override; void stop() override; void fillFeatures(aasdk::proto::messages::ServiceDiscoveryResponse& response) override; @@ -47,7 +47,7 @@ class BluetoothService: public aasdk::channel::bluetooth::IBluetoothServiceChann boost::asio::io_service::strand strand_; aasdk::channel::bluetooth::BluetoothServiceChannel::Pointer channel_; - IBluetoothDevice::Pointer bluetoothDevice_; + projection::IBluetoothDevice::Pointer bluetoothDevice_; }; } diff --git a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp similarity index 91% rename from include/f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp rename to include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp index 1d249e7e..fc1cb38e 100644 --- a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntity.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,7 +27,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IAndroidAutoEntity diff --git a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp similarity index 97% rename from include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp rename to include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp index 2a244c1c..648d125f 100644 --- a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityEventHandler.hpp @@ -26,7 +26,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IAndroidAutoEntityEventHandler diff --git a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp similarity index 93% rename from include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp rename to include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp index f9f37c34..97b958b5 100644 --- a/include/f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/IAndroidAutoEntityFactory.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include namespace f1x { @@ -28,7 +28,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IAndroidAutoEntityFactory diff --git a/include/f1x/openauto/autoapp/Projection/IPinger.hpp b/include/f1x/openauto/autoapp/Service/IPinger.hpp similarity index 98% rename from include/f1x/openauto/autoapp/Projection/IPinger.hpp rename to include/f1x/openauto/autoapp/Service/IPinger.hpp index 379462f8..d345ed38 100644 --- a/include/f1x/openauto/autoapp/Projection/IPinger.hpp +++ b/include/f1x/openauto/autoapp/Service/IPinger.hpp @@ -26,7 +26,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IPinger diff --git a/include/f1x/openauto/autoapp/Projection/IService.hpp b/include/f1x/openauto/autoapp/Service/IService.hpp similarity index 98% rename from include/f1x/openauto/autoapp/Projection/IService.hpp rename to include/f1x/openauto/autoapp/Service/IService.hpp index cd7c7620..a676cb76 100644 --- a/include/f1x/openauto/autoapp/Projection/IService.hpp +++ b/include/f1x/openauto/autoapp/Service/IService.hpp @@ -28,7 +28,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IService diff --git a/include/f1x/openauto/autoapp/Projection/IServiceFactory.hpp b/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp similarity index 92% rename from include/f1x/openauto/autoapp/Projection/IServiceFactory.hpp rename to include/f1x/openauto/autoapp/Service/IServiceFactory.hpp index 4d1563c3..6049d9d9 100644 --- a/include/f1x/openauto/autoapp/Projection/IServiceFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/IServiceFactory.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,7 +27,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class IServiceFactory diff --git a/include/f1x/openauto/autoapp/Projection/InputService.hpp b/include/f1x/openauto/autoapp/Service/InputService.hpp similarity index 82% rename from include/f1x/openauto/autoapp/Projection/InputService.hpp rename to include/f1x/openauto/autoapp/Service/InputService.hpp index cb6c5e42..6a64bc15 100644 --- a/include/f1x/openauto/autoapp/Projection/InputService.hpp +++ b/include/f1x/openauto/autoapp/Service/InputService.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -30,17 +30,17 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class InputService: public aasdk::channel::input::IInputServiceChannelEventHandler, public IService, - public IInputDeviceEventHandler, + public projection::IInputDeviceEventHandler, public std::enable_shared_from_this { public: - InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IInputDevice::Pointer inputDevice); + InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IInputDevice::Pointer inputDevice); void start() override; void stop() override; @@ -48,15 +48,15 @@ class InputService: void onChannelOpenRequest(const aasdk::proto::messages::ChannelOpenRequest& request) override; void onBindingRequest(const aasdk::proto::messages::BindingRequest& request) override; void onChannelError(const aasdk::error::Error& e) override; - void onButtonEvent(const ButtonEvent& event) override; - void onTouchEvent(const TouchEvent& event) override; + void onButtonEvent(const projection::ButtonEvent& event) override; + void onTouchEvent(const projection::TouchEvent& event) override; private: using std::enable_shared_from_this::shared_from_this; boost::asio::io_service::strand strand_; aasdk::channel::input::InputServiceChannel::Pointer channel_; - IInputDevice::Pointer inputDevice_; + projection::IInputDevice::Pointer inputDevice_; }; } diff --git a/include/f1x/openauto/autoapp/Projection/MediaAudioService.hpp b/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp similarity index 85% rename from include/f1x/openauto/autoapp/Projection/MediaAudioService.hpp rename to include/f1x/openauto/autoapp/Service/MediaAudioService.hpp index 447952f5..bbd14140 100644 --- a/include/f1x/openauto/autoapp/Projection/MediaAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/MediaAudioService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,13 +27,13 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class MediaAudioService: public AudioService { public: - MediaAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput); + MediaAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput); }; } diff --git a/include/f1x/openauto/autoapp/Projection/Pinger.hpp b/include/f1x/openauto/autoapp/Service/Pinger.hpp similarity index 94% rename from include/f1x/openauto/autoapp/Projection/Pinger.hpp rename to include/f1x/openauto/autoapp/Service/Pinger.hpp index bc7884f6..2c226cae 100644 --- a/include/f1x/openauto/autoapp/Projection/Pinger.hpp +++ b/include/f1x/openauto/autoapp/Service/Pinger.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include namespace f1x { @@ -26,7 +26,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class Pinger: public IPinger, public std::enable_shared_from_this diff --git a/include/f1x/openauto/autoapp/Projection/SensorService.hpp b/include/f1x/openauto/autoapp/Service/SensorService.hpp similarity index 95% rename from include/f1x/openauto/autoapp/Projection/SensorService.hpp rename to include/f1x/openauto/autoapp/Service/SensorService.hpp index a5b348d4..5dfd8e51 100644 --- a/include/f1x/openauto/autoapp/Projection/SensorService.hpp +++ b/include/f1x/openauto/autoapp/Service/SensorService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,7 +27,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class SensorService: public aasdk::channel::sensor::ISensorServiceChannelEventHandler, public IService, public std::enable_shared_from_this diff --git a/include/f1x/openauto/autoapp/Projection/ServiceFactory.hpp b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp similarity index 95% rename from include/f1x/openauto/autoapp/Projection/ServiceFactory.hpp rename to include/f1x/openauto/autoapp/Service/ServiceFactory.hpp index f7fdbd20..2ee9c6b8 100644 --- a/include/f1x/openauto/autoapp/Projection/ServiceFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp @@ -18,7 +18,7 @@ #pragma once -#include +#include #include namespace f1x @@ -27,7 +27,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class ServiceFactory: public IServiceFactory diff --git a/include/f1x/openauto/autoapp/Projection/SpeechAudioService.hpp b/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp similarity index 85% rename from include/f1x/openauto/autoapp/Projection/SpeechAudioService.hpp rename to include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp index 6d3cf0b0..d71f1a95 100644 --- a/include/f1x/openauto/autoapp/Projection/SpeechAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/SpeechAudioService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,13 +27,13 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class SpeechAudioService: public AudioService { public: - SpeechAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput); + SpeechAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput); }; } diff --git a/include/f1x/openauto/autoapp/Projection/SystemAudioService.hpp b/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp similarity index 85% rename from include/f1x/openauto/autoapp/Projection/SystemAudioService.hpp rename to include/f1x/openauto/autoapp/Service/SystemAudioService.hpp index e33fdffa..af775b2d 100644 --- a/include/f1x/openauto/autoapp/Projection/SystemAudioService.hpp +++ b/include/f1x/openauto/autoapp/Service/SystemAudioService.hpp @@ -19,7 +19,7 @@ #pragma once #include -#include +#include namespace f1x { @@ -27,13 +27,13 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class SystemAudioService: public AudioService { public: - SystemAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput); + SystemAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput); }; } diff --git a/include/f1x/openauto/autoapp/Projection/VideoService.hpp b/include/f1x/openauto/autoapp/Service/VideoService.hpp similarity index 90% rename from include/f1x/openauto/autoapp/Projection/VideoService.hpp rename to include/f1x/openauto/autoapp/Service/VideoService.hpp index 7896bebc..a7bc52d8 100644 --- a/include/f1x/openauto/autoapp/Projection/VideoService.hpp +++ b/include/f1x/openauto/autoapp/Service/VideoService.hpp @@ -21,9 +21,8 @@ #include #include #include -#include #include -#include +#include namespace f1x { @@ -31,7 +30,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { class VideoService: public aasdk::channel::av::IVideoServiceChannelEventHandler, public IService, public std::enable_shared_from_this @@ -39,7 +38,7 @@ class VideoService: public aasdk::channel::av::IVideoServiceChannelEventHandler, public: typedef std::shared_ptr Pointer; - VideoService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IVideoOutput::Pointer videoOutput); + VideoService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IVideoOutput::Pointer videoOutput); void start() override; void stop() override; @@ -58,7 +57,7 @@ class VideoService: public aasdk::channel::av::IVideoServiceChannelEventHandler, boost::asio::io_service::strand strand_; aasdk::channel::av::VideoServiceChannel::Pointer channel_; - IVideoOutput::Pointer videoOutput_; + projection::IVideoOutput::Pointer videoOutput_; int32_t session_; }; diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp index a58aad30..a49c3d8d 100644 --- a/src/autoapp/App.cpp +++ b/src/autoapp/App.cpp @@ -29,7 +29,7 @@ namespace openauto namespace autoapp { -App::App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, +App::App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, service::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator) : ioService_(ioService) , usbWrapper_(usbWrapper) diff --git a/src/autoapp/Projection/AndroidAutoEntity.cpp b/src/autoapp/Service/AndroidAutoEntity.cpp similarity index 99% rename from src/autoapp/Projection/AndroidAutoEntity.cpp rename to src/autoapp/Service/AndroidAutoEntity.cpp index fbd9a7ee..50aabf87 100644 --- a/src/autoapp/Projection/AndroidAutoEntity.cpp +++ b/src/autoapp/Service/AndroidAutoEntity.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include namespace f1x @@ -26,7 +26,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { AndroidAutoEntity::AndroidAutoEntity(boost::asio::io_service& ioService, diff --git a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp b/src/autoapp/Service/AndroidAutoEntityFactory.cpp similarity index 93% rename from src/autoapp/Projection/AndroidAutoEntityFactory.cpp rename to src/autoapp/Service/AndroidAutoEntityFactory.cpp index c111f286..d833250d 100644 --- a/src/autoapp/Projection/AndroidAutoEntityFactory.cpp +++ b/src/autoapp/Service/AndroidAutoEntityFactory.cpp @@ -24,9 +24,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace f1x { @@ -34,7 +34,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { AndroidAutoEntityFactory::AndroidAutoEntityFactory(boost::asio::io_service& ioService, diff --git a/src/autoapp/Projection/AudioInputService.cpp b/src/autoapp/Service/AudioInputService.cpp similarity index 95% rename from src/autoapp/Projection/AudioInputService.cpp rename to src/autoapp/Service/AudioInputService.cpp index 755ddbac..78b2666a 100644 --- a/src/autoapp/Projection/AudioInputService.cpp +++ b/src/autoapp/Service/AudioInputService.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace f1x { @@ -26,10 +26,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -AudioInputService::AudioInputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioInput::Pointer audioInput) +AudioInputService::AudioInputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioInput::Pointer audioInput) : strand_(ioService) , channel_(std::make_shared(strand_, std::move(messenger))) , audioInput_(std::move(audioInput)) @@ -114,7 +114,7 @@ void AudioInputService::onAVInputOpenRequest(const aasdk::proto::messages::AVInp if(request.open()) { - auto startPromise = IAudioInput::StartPromise::defer(strand_); + auto startPromise = projection::IAudioInput::StartPromise::defer(strand_); startPromise->then(std::bind(&AudioInputService::onAudioInputOpenSucceed, this->shared_from_this()), [this, self = this->shared_from_this()]() { OPENAUTO_LOG(error) << "[AudioInputService] audio input open failed."; @@ -185,7 +185,7 @@ void AudioInputService::readAudioInput() { if(audioInput_->isActive()) { - auto readPromise = IAudioInput::ReadPromise::defer(strand_); + auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_); readPromise->then(std::bind(&AudioInputService::onAudioInputDataReady, this->shared_from_this(), std::placeholders::_1), [this, self = this->shared_from_this()]() { OPENAUTO_LOG(info) << "[AudioInputService] audio input read rejected."; diff --git a/src/autoapp/Projection/AudioService.cpp b/src/autoapp/Service/AudioService.cpp similarity index 97% rename from src/autoapp/Projection/AudioService.cpp rename to src/autoapp/Service/AudioService.cpp index d09001fe..5ddafce3 100644 --- a/src/autoapp/Projection/AudioService.cpp +++ b/src/autoapp/Service/AudioService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -AudioService::AudioService(boost::asio::io_service& ioService, aasdk::channel::av::IAudioServiceChannel::Pointer channel, IAudioOutput::Pointer audioOutput) +AudioService::AudioService(boost::asio::io_service& ioService, aasdk::channel::av::IAudioServiceChannel::Pointer channel, projection::IAudioOutput::Pointer audioOutput) : strand_(ioService) , channel_(std::move(channel)) , audioOutput_(std::move(audioOutput)) diff --git a/src/autoapp/Projection/BluetoothService.cpp b/src/autoapp/Service/BluetoothService.cpp similarity index 95% rename from src/autoapp/Projection/BluetoothService.cpp rename to src/autoapp/Service/BluetoothService.cpp index c8712a57..b6ae5456 100644 --- a/src/autoapp/Projection/BluetoothService.cpp +++ b/src/autoapp/Service/BluetoothService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -BluetoothService::BluetoothService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IBluetoothDevice::Pointer bluetoothDevice) +BluetoothService::BluetoothService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IBluetoothDevice::Pointer bluetoothDevice) : strand_(ioService) , channel_(std::make_shared(strand_, std::move(messenger))) , bluetoothDevice_(std::move(bluetoothDevice)) diff --git a/src/autoapp/Projection/InputService.cpp b/src/autoapp/Service/InputService.cpp similarity index 93% rename from src/autoapp/Projection/InputService.cpp rename to src/autoapp/Service/InputService.cpp index 7bc611c3..b5e22fc3 100644 --- a/src/autoapp/Projection/InputService.cpp +++ b/src/autoapp/Service/InputService.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace f1x { @@ -26,10 +26,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -InputService::InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IInputDevice::Pointer inputDevice) +InputService::InputService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IInputDevice::Pointer inputDevice) : strand_(ioService) , channel_(std::make_shared(strand_, std::move(messenger))) , inputDevice_(std::move(inputDevice)) @@ -135,7 +135,7 @@ void InputService::onChannelError(const aasdk::error::Error& e) OPENAUTO_LOG(error) << "[SensorService] channel error: " << e.what(); } -void InputService::onButtonEvent(const ButtonEvent& event) +void InputService::onButtonEvent(const projection::ButtonEvent& event) { auto timestamp = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); @@ -146,14 +146,14 @@ void InputService::onButtonEvent(const ButtonEvent& event) if(event.code == aasdk::proto::enums::ButtonCode::SCROLL_WHEEL) { auto relativeEvent = inputEventIndication.mutable_relative_input_event()->add_relative_input_events(); - relativeEvent->set_delta(event.wheelDirection == WheelDirection::LEFT ? -1 : 1); + relativeEvent->set_delta(event.wheelDirection == projection::WheelDirection::LEFT ? -1 : 1); relativeEvent->set_scan_code(event.code); } else { auto buttonEvent = inputEventIndication.mutable_button_event()->add_button_events(); buttonEvent->set_meta(0); - buttonEvent->set_is_pressed(event.type == ButtonEventType::PRESS); + buttonEvent->set_is_pressed(event.type == projection::ButtonEventType::PRESS); buttonEvent->set_long_press(false); buttonEvent->set_scan_code(event.code); } @@ -164,7 +164,7 @@ void InputService::onButtonEvent(const ButtonEvent& event) }); } -void InputService::onTouchEvent(const TouchEvent& event) +void InputService::onTouchEvent(const projection::TouchEvent& event) { auto timestamp = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()); diff --git a/src/autoapp/Projection/MediaAudioService.cpp b/src/autoapp/Service/MediaAudioService.cpp similarity index 85% rename from src/autoapp/Projection/MediaAudioService.cpp rename to src/autoapp/Service/MediaAudioService.cpp index be7e9f73..b754d216 100644 --- a/src/autoapp/Projection/MediaAudioService.cpp +++ b/src/autoapp/Service/MediaAudioService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -MediaAudioService::MediaAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput) +MediaAudioService::MediaAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput) : AudioService(ioService, std::make_shared(strand_, std::move(messenger)), std::move(audioOutput)) { diff --git a/src/autoapp/Projection/Pinger.cpp b/src/autoapp/Service/Pinger.cpp similarity index 97% rename from src/autoapp/Projection/Pinger.cpp rename to src/autoapp/Service/Pinger.cpp index 8be0cdee..fd0b45dc 100644 --- a/src/autoapp/Projection/Pinger.cpp +++ b/src/autoapp/Service/Pinger.cpp @@ -16,7 +16,7 @@ * along with openauto. If not, see . */ -#include +#include namespace f1x { @@ -24,7 +24,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { Pinger::Pinger(boost::asio::io_service& ioService, time_t duration) diff --git a/src/autoapp/Projection/SensorService.cpp b/src/autoapp/Service/SensorService.cpp similarity index 98% rename from src/autoapp/Projection/SensorService.cpp rename to src/autoapp/Service/SensorService.cpp index 59a8bd0d..f6c05efa 100644 --- a/src/autoapp/Projection/SensorService.cpp +++ b/src/autoapp/Service/SensorService.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include namespace f1x { @@ -26,7 +26,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { SensorService::SensorService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger) diff --git a/src/autoapp/Projection/ServiceFactory.cpp b/src/autoapp/Service/ServiceFactory.cpp similarity index 67% rename from src/autoapp/Projection/ServiceFactory.cpp rename to src/autoapp/Service/ServiceFactory.cpp index d10ddff6..5f9d60ec 100644 --- a/src/autoapp/Projection/ServiceFactory.cpp +++ b/src/autoapp/Service/ServiceFactory.cpp @@ -21,15 +21,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -46,7 +46,7 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { ServiceFactory::ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration) @@ -60,7 +60,7 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng { ServiceList serviceList; - IAudioInput::Pointer audioInput(new QtAudioInput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(audioInput))); this->createAudioServices(serviceList, messenger); serviceList.emplace_back(std::make_shared(ioService_, messenger)); @@ -74,28 +74,28 @@ ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messeng IService::Pointer ServiceFactory::createVideoService(aasdk::messenger::IMessenger::Pointer messenger) { #ifdef USE_OMX - IVideoOutput::Pointer videoOutput(std::make_shared(configuration_)); + auto videoOutput(std::make_shared(configuration_)); #else - IVideoOutput::Pointer videoOutput(new QtVideoOutput(configuration_), std::bind(&QObject::deleteLater, std::placeholders::_1)); + projection::IVideoOutput::Pointer videoOutput(new projection::QtVideoOutput(configuration_), std::bind(&QObject::deleteLater, std::placeholders::_1)); #endif return std::make_shared(ioService_, messenger, std::move(videoOutput)); } IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger) { - IBluetoothDevice::Pointer bluetoothDevice; + projection::IBluetoothDevice::Pointer bluetoothDevice; switch(configuration_->getBluetoothAdapterType()) { case configuration::BluetoothAdapterType::LOCAL: - bluetoothDevice = IBluetoothDevice::Pointer(new LocalBluetoothDevice(), std::bind(&QObject::deleteLater, std::placeholders::_1)); + bluetoothDevice = projection::IBluetoothDevice::Pointer(new projection::LocalBluetoothDevice(), std::bind(&QObject::deleteLater, std::placeholders::_1)); break; case configuration::BluetoothAdapterType::REMOTE: - bluetoothDevice = std::make_shared(configuration_->getBluetoothRemoteAdapterAddress()); + bluetoothDevice = std::make_shared(configuration_->getBluetoothRemoteAdapterAddress()); break; default: - bluetoothDevice = std::make_shared(); + bluetoothDevice = std::make_shared(); break; } @@ -122,7 +122,7 @@ IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenge QScreen* screen = QGuiApplication::primaryScreen(); QRect screenGeometry = screen == nullptr ? QRect(0, 0, 1, 1) : screen->geometry(); - IInputDevice::Pointer inputDevice(std::make_shared(*QApplication::instance(), configuration_, std::move(screenGeometry), std::move(videoGeometry))); + projection::IInputDevice::Pointer inputDevice(std::make_shared(*QApplication::instance(), configuration_, std::move(screenGeometry), std::move(videoGeometry))); return std::make_shared(ioService_, messenger, std::move(inputDevice)); } @@ -132,8 +132,8 @@ void ServiceFactory::createAudioServices(ServiceList& serviceList, aasdk::messen if(configuration_->musicAudioChannelEnabled()) { auto mediaAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? - std::make_shared(2, 16, 48000) : - IAudioOutput::Pointer(new QtAudioOutput(2, 16, 48000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + std::make_shared(2, 16, 48000) : + projection::IAudioOutput::Pointer(new projection::QtAudioOutput(2, 16, 48000), std::bind(&QObject::deleteLater, std::placeholders::_1)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(mediaAudioOutput))); } @@ -141,15 +141,15 @@ void ServiceFactory::createAudioServices(ServiceList& serviceList, aasdk::messen if(configuration_->speechAudioChannelEnabled()) { auto speechAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? - std::make_shared(1, 16, 16000) : - IAudioOutput::Pointer(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + std::make_shared(1, 16, 16000) : + projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(speechAudioOutput))); } auto systemAudioOutput = configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? - std::make_shared(1, 16, 16000) : - IAudioOutput::Pointer(new QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); + std::make_shared(1, 16, 16000) : + projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000), std::bind(&QObject::deleteLater, std::placeholders::_1)); serviceList.emplace_back(std::make_shared(ioService_, messenger, std::move(systemAudioOutput))); } diff --git a/src/autoapp/Projection/SpeechAudioService.cpp b/src/autoapp/Service/SpeechAudioService.cpp similarity index 85% rename from src/autoapp/Projection/SpeechAudioService.cpp rename to src/autoapp/Service/SpeechAudioService.cpp index f1703467..59300950 100644 --- a/src/autoapp/Projection/SpeechAudioService.cpp +++ b/src/autoapp/Service/SpeechAudioService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -SpeechAudioService::SpeechAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput) +SpeechAudioService::SpeechAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput) : AudioService(ioService, std::make_shared(strand_, std::move(messenger)), std::move(audioOutput)) { diff --git a/src/autoapp/Projection/SystemAudioService.cpp b/src/autoapp/Service/SystemAudioService.cpp similarity index 85% rename from src/autoapp/Projection/SystemAudioService.cpp rename to src/autoapp/Service/SystemAudioService.cpp index 1acedf6e..09986159 100644 --- a/src/autoapp/Projection/SystemAudioService.cpp +++ b/src/autoapp/Service/SystemAudioService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -SystemAudioService::SystemAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IAudioOutput::Pointer audioOutput) +SystemAudioService::SystemAudioService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IAudioOutput::Pointer audioOutput) : AudioService(ioService, std::make_shared(strand_, std::move(messenger)), std::move(audioOutput)) { diff --git a/src/autoapp/Projection/VideoService.cpp b/src/autoapp/Service/VideoService.cpp similarity index 97% rename from src/autoapp/Projection/VideoService.cpp rename to src/autoapp/Service/VideoService.cpp index b419d4a4..1bb0aa12 100644 --- a/src/autoapp/Projection/VideoService.cpp +++ b/src/autoapp/Service/VideoService.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include namespace f1x { @@ -25,10 +25,10 @@ namespace openauto { namespace autoapp { -namespace projection +namespace service { -VideoService::VideoService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, IVideoOutput::Pointer videoOutput) +VideoService::VideoService(boost::asio::io_service& ioService, aasdk::messenger::IMessenger::Pointer messenger, projection::IVideoOutput::Pointer videoOutput) : strand_(ioService) , channel_(std::make_shared(strand_, std::move(messenger))) , videoOutput_(std::move(videoOutput)) diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index 8c2565c0..2aa9dcb8 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -113,8 +113,8 @@ int main(int argc, char* argv[]) aasdk::usb::USBWrapper usbWrapper(usbContext); aasdk::usb::AccessoryModeQueryFactory queryFactory(usbWrapper, ioService); aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory(usbWrapper, ioService, queryFactory); - autoapp::projection::ServiceFactory serviceFactory(ioService, configuration); - autoapp::projection::AndroidAutoEntityFactory androidAutoEntityFactory(ioService, configuration, serviceFactory); + autoapp::service::ServiceFactory serviceFactory(ioService, configuration); + autoapp::service::AndroidAutoEntityFactory androidAutoEntityFactory(ioService, configuration, serviceFactory); auto usbHub(std::make_shared(usbWrapper, ioService, queryChainFactory)); auto connectedAccessoriesEnumerator(std::make_shared(usbWrapper, ioService, queryChainFactory));