Reformat Code

This commit is contained in:
Simon Dean 2024-11-27 09:53:07 +00:00
parent 7f38e16983
commit 478526b953
27 changed files with 2598 additions and 2717 deletions

View File

@ -18,17 +18,10 @@
#pragma once #pragma once
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace configuration
{
enum class BluetoothAdapterType namespace f1x::openauto::autoapp::configuration {
{
enum class BluetoothAdapterType {
NONE, NONE,
LOCAL, LOCAL,
REMOTE REMOTE
@ -37,4 +30,6 @@ enum class BluetoothAdapterType
} }
} }
} }
}

View File

@ -23,13 +23,7 @@
#pragma once #pragma once
namespace f1x namespace f1x::openauto::autoapp::projection
{
namespace openauto
{
namespace autoapp
{
namespace projection
{ {
class LocalBluetoothDevice: public QObject, public IBluetoothDevice class LocalBluetoothDevice: public QObject, public IBluetoothDevice
@ -37,7 +31,7 @@ class LocalBluetoothDevice: public QObject, public IBluetoothDevice
Q_OBJECT Q_OBJECT
public: public:
LocalBluetoothDevice(); LocalBluetoothDevice(const QString &adapterAddress = QString(), QObject *parent = nullptr);
void stop() override; void stop() override;
bool isPaired(const std::string& address) const override; bool isPaired(const std::string& address) const override;
@ -68,6 +62,6 @@ private:
}; };
} }
}
}
}

View File

@ -24,32 +24,29 @@
#include <aap_protobuf/service/control/message/ServiceDiscoveryResponse.pb.h> #include <aap_protobuf/service/control/message/ServiceDiscoveryResponse.pb.h>
#include <aap_protobuf/shared/MessageStatus.pb.h> #include <aap_protobuf/shared/MessageStatus.pb.h>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace service
{
class IService namespace f1x::openauto::autoapp::service {
{
public: class IService {
public:
typedef std::shared_ptr<IService> Pointer; typedef std::shared_ptr<IService> Pointer;
virtual ~IService() = default; virtual ~IService() = default;
virtual void start() = 0; virtual void start() = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual void pause() = 0; virtual void pause() = 0;
virtual void resume() = 0; virtual void resume() = 0;
virtual void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse& response) = 0;
};
typedef std::vector<IService::Pointer> ServiceList; virtual void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) = 0;
};
typedef std::vector<IService::Pointer> ServiceList;
} }
}
}
}

View File

@ -26,60 +26,60 @@
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <aasdk/Messenger/IMessenger.hpp> #include <aasdk/Messenger/IMessenger.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace sensor {
class SensorService :
public aasdk::channel::sensorsource::ISensorSourceServiceEventHandler,
public IService,
public std::enable_shared_from_this<SensorService> {
public:
SensorService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger);
bool isNight = false; namespace f1x::openauto::autoapp::service::sensor {
bool previous = false; class SensorService :
bool stopPolling = false; public aasdk::channel::sensorsource::ISensorSourceServiceEventHandler,
public IService,
public std::enable_shared_from_this<SensorService> {
public:
SensorService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger);
void start() override; bool isNight = false;
void stop() override; bool previous = false;
void pause() override; bool stopPolling = false;
void resume() override;
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override; void start() override;
void onSensorStartRequest( void stop() override;
const aap_protobuf::service::sensorsource::message::SensorRequest &request) override;
void onChannelError(const aasdk::error::Error &e) override; void pause() override;
private: void resume() override;
using std::enable_shared_from_this<SensorService>::shared_from_this;
void sendDrivingStatusUnrestricted(); void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
void sendNightData(); void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
void sendGPSLocationData(); void onSensorStartRequest(
const aap_protobuf::service::sensorsource::message::SensorRequest &request) override;
bool is_file_exist(const char *filename); void onChannelError(const aasdk::error::Error &e) override;
void sensorPolling(); private:
using std::enable_shared_from_this<SensorService>::shared_from_this;
void sendDrivingStatusUnrestricted();
void sendNightData();
void sendGPSLocationData();
bool is_file_exist(const char *filename);
void sensorPolling();
bool firstRun = true;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::sensorsource::SensorSourceService::Pointer channel_;
struct gps_data_t gpsData_;
bool gpsEnabled_ = false;
};
}
bool firstRun = true;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::sensorsource::SensorSourceService::Pointer channel_;
struct gps_data_t gpsData_;
bool gpsEnabled_ = false;
};
}
}
}
}
}

View File

@ -22,33 +22,26 @@
#include <f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp> #include <f1x/openauto/autoapp/Projection/IBluetoothDevice.hpp>
#include <f1x/openauto/autoapp/Service/IService.hpp> #include <f1x/openauto/autoapp/Service/IService.hpp>
namespace f1x { namespace f1x::openauto::autoapp::service {
namespace openauto {
namespace autoapp {
namespace service {
class Service class Service
: public IService { : public IService {
public: public:
Service(boost::asio::io_service &ioService); Service(boost::asio::io_service &ioService);
void start() override; void start() override;
void stop() override; void stop() override;
void pause() override; void pause() override;
void resume() override; void resume() override;
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override; void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
private: private:
boost::asio::io_service::strand strand_; boost::asio::io_service::strand strand_;
}; };
} }
}
}
}
}

View File

@ -23,39 +23,39 @@
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <aasdk/Messenger/IMessenger.hpp> #include <aasdk/Messenger/IMessenger.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace vendorextension {
class VendorExtensionService : namespace f1x::openauto::autoapp::service::vendorextension {
public aasdk::channel::vendorextension::IVendorExtensionServiceEventHandler,
public IService,
public std::enable_shared_from_this<VendorExtensionService> {
public:
VendorExtensionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
void start() override; class VendorExtensionService :
void stop() override; public aasdk::channel::vendorextension::IVendorExtensionServiceEventHandler,
void pause() override; public IService,
void resume() override; public std::enable_shared_from_this<VendorExtensionService> {
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override; public:
VendorExtensionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override; void start() override;
void onChannelError(const aasdk::error::Error &e) override; void stop() override;
void pause() override;
void resume() override;
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
void onChannelError(const aasdk::error::Error &e) override;
private:
using std::enable_shared_from_this<VendorExtensionService>::shared_from_this;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::vendorextension::VendorExtensionService::Pointer channel_;
};
}
private:
using std::enable_shared_from_this<VendorExtensionService>::shared_from_this;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::vendorextension::VendorExtensionService::Pointer channel_;
};
}
}
}
}
}

View File

@ -23,41 +23,42 @@
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <aasdk/Messenger/IMessenger.hpp> #include <aasdk/Messenger/IMessenger.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace wifiprojection {
class WifiProjectionService : namespace f1x::openauto::autoapp::service::wifiprojection {
public aasdk::channel::wifiprojection::IWifiProjectionServiceEventHandler,
public IService,
public std::enable_shared_from_this<WifiProjectionService> {
public:
WifiProjectionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
void start() override; class WifiProjectionService :
void stop() override; public aasdk::channel::wifiprojection::IWifiProjectionServiceEventHandler,
void pause() override; public IService,
void resume() override; public std::enable_shared_from_this<WifiProjectionService> {
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override; public:
WifiProjectionService(boost::asio::io_service &ioService, aasdk::messenger::IMessenger::Pointer messenger);
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override; void start() override;
void onChannelError(const aasdk::error::Error &e) override; void stop() override;
void pause() override;
void resume() override;
void fillFeatures(aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) override;
void onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) override;
void onChannelError(const aasdk::error::Error &e) override;
void
onWifiCredentialsRequest(
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) override;
private:
using std::enable_shared_from_this<WifiProjectionService>::shared_from_this;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::wifiprojection::WifiProjectionService::Pointer channel_;
};
}
void
onWifiCredentialsRequest(const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) override;
private:
using std::enable_shared_from_this<WifiProjectionService>::shared_from_this;
boost::asio::deadline_timer timer_;
boost::asio::io_service::strand strand_;
aasdk::channel::wifiprojection::WifiProjectionService::Pointer channel_;
};
}
}
}
}
}

View File

@ -35,13 +35,7 @@ namespace Ui
class SettingsWindow; class SettingsWindow;
} }
namespace f1x namespace f1x::openauto::autoapp::ui
{
namespace openauto
{
namespace autoapp
{
namespace ui
{ {
class SettingsWindow : public QWidget class SettingsWindow : public QWidget
@ -112,6 +106,6 @@ private:
}; };
} }
}
}
}

View File

@ -22,171 +22,145 @@
#include <f1x/openauto/autoapp/App.hpp> #include <f1x/openauto/autoapp/App.hpp>
#include <f1x/openauto/Common/Log.hpp> #include <f1x/openauto/Common/Log.hpp>
namespace f1x namespace f1x::openauto::autoapp {
{
namespace openauto
{
namespace autoapp
{
App::App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, service::IAndroidAutoEntityFactory& androidAutoEntityFactory, App::App(boost::asio::io_service &ioService, aasdk::usb::USBWrapper &usbWrapper, aasdk::tcp::ITCPWrapper &tcpWrapper,
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator) service::IAndroidAutoEntityFactory &androidAutoEntityFactory,
: ioService_(ioService) aasdk::usb::IUSBHub::Pointer usbHub,
, usbWrapper_(usbWrapper) aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
, tcpWrapper_(tcpWrapper) : ioService_(ioService), usbWrapper_(usbWrapper), tcpWrapper_(tcpWrapper), strand_(ioService_),
, strand_(ioService_) androidAutoEntityFactory_(androidAutoEntityFactory), usbHub_(std::move(usbHub)),
, androidAutoEntityFactory_(androidAutoEntityFactory) connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator)),
, usbHub_(std::move(usbHub)) acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 5000)), isStopped_(false) {
, connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator))
, acceptor_(ioService, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 5000 ))
, isStopped_(false)
{
} }
void App::waitForUSBDevice() void App::waitForUSBDevice() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
try try {
{ this->waitForDevice();
this->waitForDevice(); }
} catch (...) {
catch(...) OPENAUTO_LOG(error) << "[App] waitForUSBDevice() -exception caused by this->waitForDevice();";
{ }
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() -exception caused by this->waitForDevice();"; try {
} this->enumerateDevices();
try }
{ catch (...) {
this->enumerateDevices(); OPENAUTO_LOG(error) << "[App] waitForUSBDevice() exception caused by this->enumerateDevices()";
} }
catch(...)
{
OPENAUTO_LOG(error) << "[App] waitForUSBDevice() exception caused by this->enumerateDevices()";
}
}); });
} }
void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket) void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket) {
{
strand_.dispatch([this, self = this->shared_from_this(), socket = std::move(socket)]() mutable { strand_.dispatch([this, self = this->shared_from_this(), socket = std::move(socket)]() mutable {
OPENAUTO_LOG(info) << "Start from socket"; OPENAUTO_LOG(info) << "Start from socket";
if(androidAutoEntity_ != nullptr) if (androidAutoEntity_ != nullptr) {
{
// tcpWrapper_.close(*socket); // tcpWrapper_.close(*socket);
// OPENAUTO_LOG(warning) << "[App] android auto entity is still running."; // OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
// return; // return;
try { try {
androidAutoEntity_->stop(); androidAutoEntity_->stop();
} catch (...) { } catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();"; OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
}
try {
androidAutoEntity_.reset();
} catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
}
} }
try {
androidAutoEntity_.reset();
} catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
}
}
try try {
{
// usbHub_->cancel(); // usbHub_->cancel();
// connectedAccessoriesEnumerator_->cancel(); // connectedAccessoriesEnumerator_->cancel();
auto tcpEndpoint(std::make_shared<aasdk::tcp::TCPEndpoint>(tcpWrapper_, std::move(socket))); auto tcpEndpoint(std::make_shared<aasdk::tcp::TCPEndpoint>(tcpWrapper_, std::move(socket)));
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint)); androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint));
androidAutoEntity_->start(*this); androidAutoEntity_->start(*this);
} }
catch(const aasdk::error::Error& error) catch (const aasdk::error::Error &error) {
{ OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what();
OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what();
//androidAutoEntity_.reset(); //androidAutoEntity_.reset();
this->waitForDevice(); this->waitForDevice();
} }
}); });
} }
void App::stop() void App::stop() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
isStopped_ = true; isStopped_ = true;
try { try {
connectedAccessoriesEnumerator_->cancel(); connectedAccessoriesEnumerator_->cancel();
} catch (...) { } catch (...) {
OPENAUTO_LOG(error) << "[App] stop: exception caused by connectedAccessoriesEnumerator_->cancel()"; OPENAUTO_LOG(error) << "[App] stop: exception caused by connectedAccessoriesEnumerator_->cancel()";
} }
try { try {
usbHub_->cancel(); usbHub_->cancel();
} catch (...) { } catch (...) {
OPENAUTO_LOG(error) << "[App] stop: exception caused by usbHub_->cancel();"; OPENAUTO_LOG(error) << "[App] stop: exception caused by usbHub_->cancel();";
} }
if(androidAutoEntity_ != nullptr) if (androidAutoEntity_ != nullptr) {
{ try {
try { androidAutoEntity_->stop();
androidAutoEntity_->stop(); } catch (...) {
} catch (...) { OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_->stop();";
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_->stop();";
}
try {
androidAutoEntity_.reset();
} catch (...) {
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_.reset();";
}
} }
try {
androidAutoEntity_.reset();
} catch (...) {
OPENAUTO_LOG(error) << "[App] stop: exception caused by androidAutoEntity_.reset();";
}
}
}); });
} }
void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle) void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle) {
{
OPENAUTO_LOG(info) << "[App] Device connected."; OPENAUTO_LOG(info) << "[App] Device connected.";
if(androidAutoEntity_ != nullptr) if (androidAutoEntity_ != nullptr) {
{ OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
OPENAUTO_LOG(warning) << "[App] android auto entity is still running."; return;
return;
} }
try try {
{ // ignore autostart if exit to csng was used
// ignore autostart if exit to csng was used if (!disableAutostartEntity) {
if (!disableAutostartEntity) { OPENAUTO_LOG(info) << "[App] Start Android Auto allowed - let's go.";
OPENAUTO_LOG(info) << "[App] Start Android Auto allowed - let's go."; connectedAccessoriesEnumerator_->cancel();
connectedAccessoriesEnumerator_->cancel();
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle)); auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice)); androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice));
androidAutoEntity_->start(*this); androidAutoEntity_->start(*this);
} else { } else {
OPENAUTO_LOG(info) << "[App] Start Android Auto not allowed - skip."; OPENAUTO_LOG(info) << "[App] Start Android Auto not allowed - skip.";
} }
} }
catch(const aasdk::error::Error& error) catch (const aasdk::error::Error &error) {
{ OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what();
OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what();
androidAutoEntity_.reset(); androidAutoEntity_.reset();
this->waitForDevice(); this->waitForDevice();
} }
} }
void App::enumerateDevices() void App::enumerateDevices() {
{
auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_); auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_);
promise->then([this, self = this->shared_from_this()](auto result) { promise->then([this, self = this->shared_from_this()](auto result) {
OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result; OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result;
}, },
[this, self = this->shared_from_this()](auto e) { [this, self = this->shared_from_this()](auto e) {
OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what(); OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what();
}); });
connectedAccessoriesEnumerator_->enumerate(std::move(promise)); connectedAccessoriesEnumerator_->enumerate(std::move(promise));
} }
void App::waitForDevice() void App::waitForDevice() {
{
OPENAUTO_LOG(info) << "[App] Waiting for device..."; OPENAUTO_LOG(info) << "[App] Waiting for device...";
auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_); auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_);
@ -194,80 +168,75 @@ void App::waitForDevice()
std::bind(&App::onUSBHubError, this->shared_from_this(), std::placeholders::_1)); std::bind(&App::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
usbHub_->start(std::move(promise)); usbHub_->start(std::move(promise));
startServerSocket(); startServerSocket();
} }
void App::startServerSocket() { void App::startServerSocket() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "startServerSocket() - Listening for WIFI Clients on Port 5000"; OPENAUTO_LOG(info) << "startServerSocket() - Listening for WIFI Clients on Port 5000";
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_); auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
acceptor_.async_accept( acceptor_.async_accept(
*socket, *socket,
std::bind(&App::handleNewClient, this, socket, std::placeholders::_1) std::bind(&App::handleNewClient, this, socket, std::placeholders::_1)
); );
}); });
} }
void App::handleNewClient(std::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code &err) { void
App::handleNewClient(std::shared_ptr<boost::asio::ip::tcp::socket> socket, const boost::system::error_code &err) {
OPENAUTO_LOG(info) << "handleNewClient() - Handle WIFI Client Connection"; OPENAUTO_LOG(info) << "handleNewClient() - Handle WIFI Client Connection";
if (!err) { if (!err) {
start(std::move(socket)); start(std::move(socket));
} }
} }
void App::pause() void App::pause() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[App] pause..."; OPENAUTO_LOG(info) << "[App] pause...";
androidAutoEntity_->pause(); androidAutoEntity_->pause();
}); });
} }
void App::resume() void App::resume() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
if(androidAutoEntity_ != nullptr) if (androidAutoEntity_ != nullptr) {
{ OPENAUTO_LOG(info) << "[App] resume...";
OPENAUTO_LOG(info) << "[App] resume..."; androidAutoEntity_->resume();
androidAutoEntity_->resume(); } else {
} else { OPENAUTO_LOG(info) << "[App] Ignore resume -> no androidAutoEntity_ ...";
OPENAUTO_LOG(info) << "[App] Ignore resume -> no androidAutoEntity_ ..."; }
}
}); });
} }
void App::onAndroidAutoQuit() void App::onAndroidAutoQuit() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[App] onAndroidAutoQuit()"; OPENAUTO_LOG(info) << "[App] onAndroidAutoQuit()";
//acceptor_.close(); //acceptor_.close();
if (androidAutoEntity_ != nullptr) { if (androidAutoEntity_ != nullptr) {
try { try {
androidAutoEntity_->stop(); androidAutoEntity_->stop();
} catch (...) { } catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();"; OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_->stop();";
}
try {
androidAutoEntity_.reset();
} catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
}
} }
try {
if(!isStopped_) androidAutoEntity_.reset();
{ } catch (...) {
try { OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by androidAutoEntity_.reset();";
this->waitForDevice();
} catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by this->waitForDevice();";
}
} }
}
if (!isStopped_) {
try {
this->waitForDevice();
} catch (...) {
OPENAUTO_LOG(error) << "[App] onAndroidAutoQuit: exception caused by this->waitForDevice();";
}
}
}); });
} }
void App::onUSBHubError(const aasdk::error::Error& error) void App::onUSBHubError(const aasdk::error::Error &error) {
{
OPENAUTO_LOG(error) << "[App] onUSBHubError(): " << error.what(); OPENAUTO_LOG(error) << "[App] onUSBHubError(): " << error.what();
// if(error != aasdk::error::ErrorCode::OPERATION_ABORTED && // if(error != aasdk::error::ErrorCode::OPERATION_ABORTED &&
@ -279,8 +248,8 @@ void App::onUSBHubError(const aasdk::error::Error& error)
// OPENAUTO_LOG(error) << "[App] onUSBHubError: exception caused by this->waitForDevice();"; // OPENAUTO_LOG(error) << "[App] onUSBHubError: exception caused by this->waitForDevice();";
// } // }
// } // }
} }
} }
}
}

View File

@ -20,13 +20,10 @@
#include <f1x/openauto/Common/Log.hpp> #include <f1x/openauto/Common/Log.hpp>
#include <QTouchDevice> #include <QTouchDevice>
namespace f1x
{
namespace openauto
{ namespace f1x::openauto::autoapp::configuration
namespace autoapp
{
namespace configuration
{ {
const std::string Configuration::cConfigFileName = "openauto.ini"; const std::string Configuration::cConfigFileName = "openauto.ini";
@ -766,6 +763,6 @@ void Configuration::writeButtonCodes(boost::property_tree::ptree& iniConfig)
} }
} }
}
}
}

View File

@ -18,13 +18,10 @@
#include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp> #include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp>
namespace f1x
{
namespace openauto
{ namespace f1x::openauto::autoapp::projection
namespace autoapp
{
namespace projection
{ {
void DummyBluetoothDevice::stop() void DummyBluetoothDevice::stop()
@ -53,6 +50,6 @@ bool DummyBluetoothDevice::isAvailable() const
} }
} }
}
}
}

View File

@ -22,14 +22,7 @@
#include <QBluetoothUuid> #include <QBluetoothUuid>
#include <QtBluetooth> #include <QtBluetooth>
namespace f1x namespace f1x::openauto::autoapp::projection {
{
namespace openauto
{
namespace autoapp
{
namespace projection
{
LocalBluetoothDevice::LocalBluetoothDevice() LocalBluetoothDevice::LocalBluetoothDevice()
{ {
@ -183,7 +176,3 @@ void LocalBluetoothDevice::onHostModeStateChanged(QBluetoothLocalDevice::HostMod
} }
} }
}
}
}
}

View File

@ -19,50 +19,46 @@
#include <f1x/openauto/Common/Log.hpp> #include <f1x/openauto/Common/Log.hpp>
#include <f1x/openauto/autoapp/Service/Bluetooth/BluetoothService.hpp> #include <f1x/openauto/autoapp/Service/Bluetooth/BluetoothService.hpp>
namespace f1x { namespace f1x::openauto::autoapp::service::bluetooth {
namespace openauto {
namespace autoapp {
namespace service {
namespace bluetooth {
BluetoothService::BluetoothService(boost::asio::io_service &ioService, BluetoothService::BluetoothService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger, aasdk::messenger::IMessenger::Pointer messenger,
projection::IBluetoothDevice::Pointer bluetoothDevice) projection::IBluetoothDevice::Pointer bluetoothDevice)
: strand_(ioService), : strand_(ioService),
channel_(std::make_shared<aasdk::channel::bluetooth::BluetoothService>(strand_, std::move(messenger))), channel_(std::make_shared<aasdk::channel::bluetooth::BluetoothService>(strand_, std::move(messenger))),
bluetoothDevice_(std::move(bluetoothDevice)) { bluetoothDevice_(std::move(bluetoothDevice)) {
} }
void BluetoothService::start() { void BluetoothService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[BluetoothService] start()"; OPENAUTO_LOG(info) << "[BluetoothService] start()";
channel_->receive(this->shared_from_this()); channel_->receive(this->shared_from_this());
}); });
} }
void BluetoothService::stop() { void BluetoothService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[BluetoothService] stop()"; OPENAUTO_LOG(info) << "[BluetoothService] stop()";
bluetoothDevice_->stop(); bluetoothDevice_->stop();
}); });
} }
void BluetoothService::pause() { void BluetoothService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[BluetoothService] pause()"; OPENAUTO_LOG(info) << "[BluetoothService] pause()";
}); });
} }
void BluetoothService::resume() { void BluetoothService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[BluetoothService] resume()"; OPENAUTO_LOG(info) << "[BluetoothService] resume()";
}); });
} }
void BluetoothService::fillFeatures( void BluetoothService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) { aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[BluetoothService] fillFeatures()"; OPENAUTO_LOG(info) << "[BluetoothService] fillFeatures()";
if (bluetoothDevice_->isAvailable()) { if (bluetoothDevice_->isAvailable()) {
OPENAUTO_LOG(info) << "[BluetoothService] Local Address: " << bluetoothDevice_->getLocalAddress(); OPENAUTO_LOG(info) << "[BluetoothService] Local Address: " << bluetoothDevice_->getLocalAddress();
@ -82,76 +78,81 @@ namespace f1x {
} }
} }
void BluetoothService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) { void
OPENAUTO_LOG(info) << "[BluetoothService] onChannelOpenRequest()"; BluetoothService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(debug) << "[BluetoothService] Channel Id: " << request.service_id() << ", Priority: " << request.priority(); OPENAUTO_LOG(info) << "[BluetoothService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[BluetoothService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response; aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS; const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status); response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_); auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(), promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
std::placeholders::_1)); std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise)); channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
channel_->receive(this->shared_from_this());
}
void BluetoothService::onBluetoothPairingRequest(
const aap_protobuf::service::bluetooth::message::BluetoothPairingRequest &request) {
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothPairingRequest()";
OPENAUTO_LOG(info) << "[BluetoothService] Phone Address: " << request.phone_address();
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
const auto isPaired = bluetoothDevice_->isPaired(request.phone_address());
if (isPaired) {
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Already Paired";
} else {
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Not Paired";
}
/*
* The HU must always sent a STATUS_SUCCESS response,
* or STATUS_BLUETOOTH_PAIRING_DELAYED if:
* there's a delay in allowing bluetooth
* the HU is already engaged in a bluetooth call
*/
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
response.set_already_paired(isPaired);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then(std::bind(&BluetoothService::sendBluetoothAuthenticationData, this->shared_from_this()), std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendBluetoothPairingResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void BluetoothService::sendBluetoothAuthenticationData() {
aap_protobuf::service::bluetooth::message::BluetoothAuthenticationData data;
data.set_auth_data("123456");
data.set_pairing_method(aap_protobuf::service::bluetooth::message::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendBluetoothAuthenticationData(data, std::move(promise));
channel_->receive(this->shared_from_this());
}
void BluetoothService::onBluetoothAuthenticationResult(const aap_protobuf::service::bluetooth::message::BluetoothAuthenticationResult &request) {
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothAuthenticationResult()";
OPENAUTO_LOG(info) << "[BluetoothService] AuthData " << request.status();
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
channel_->receive(this->shared_from_this());
}
void BluetoothService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[BluetoothService] onChannelError(): " << e.what();
}
}
}
}
} }
}
void BluetoothService::onBluetoothPairingRequest(
const aap_protobuf::service::bluetooth::message::BluetoothPairingRequest &request) {
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothPairingRequest()";
OPENAUTO_LOG(info) << "[BluetoothService] Phone Address: " << request.phone_address();
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
const auto isPaired = bluetoothDevice_->isPaired(request.phone_address());
if (isPaired) {
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Already Paired";
} else {
OPENAUTO_LOG(info) << "[BluetoothService] Phone is Not Paired";
}
/*
* The HU must always sent a STATUS_SUCCESS response,
* or STATUS_BLUETOOTH_PAIRING_DELAYED if:
* there's a delay in allowing bluetooth
* the HU is already engaged in a bluetooth call
*/
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
response.set_already_paired(isPaired);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then(std::bind(&BluetoothService::sendBluetoothAuthenticationData, this->shared_from_this()),
std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendBluetoothPairingResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void BluetoothService::sendBluetoothAuthenticationData() {
OPENAUTO_LOG(info) << "[BluetoothService] sendBluetoothAuthenticationData()";
aap_protobuf::service::bluetooth::message::BluetoothAuthenticationData data;
// TODO: Bluetooth Authentication Data
data.set_auth_data("123456");
data.set_pairing_method(aap_protobuf::service::bluetooth::message::BluetoothPairingMethod::BLUETOOTH_PAIRING_PIN);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&BluetoothService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendBluetoothAuthenticationData(data, std::move(promise));
channel_->receive(this->shared_from_this());
}
void BluetoothService::onBluetoothAuthenticationResult(
const aap_protobuf::service::bluetooth::message::BluetoothAuthenticationResult &request) {
OPENAUTO_LOG(info) << "[BluetoothService] onBluetoothAuthenticationResult()";
OPENAUTO_LOG(info) << "[BluetoothService] AuthData " << request.status();
aap_protobuf::service::bluetooth::message::BluetoothPairingResponse response;
channel_->receive(this->shared_from_this());
}
void BluetoothService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[BluetoothService] onChannelError(): " << e.what();
}
}

View File

@ -21,75 +21,73 @@
#include <fstream> #include <fstream>
#include <QString> #include <QString>
namespace f1x { namespace f1x::openauto::autoapp::service::genericnotification {
namespace openauto {
namespace autoapp {
namespace service {
namespace genericnotification {
GenericNotificationService::GenericNotificationService(boost::asio::io_service &ioService, GenericNotificationService::GenericNotificationService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger) aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService), : strand_(ioService),
timer_(ioService), timer_(ioService),
channel_(std::make_shared<aasdk::channel::genericnotification::GenericNotificationService>(strand_, std::move(messenger))) { channel_(std::make_shared<aasdk::channel::genericnotification::GenericNotificationService>(strand_, std::move(
messenger))) {
}
void GenericNotificationService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] start()";
});
}
void GenericNotificationService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] stop()";
});
}
void GenericNotificationService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] pause()";
});
}
void GenericNotificationService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] resume()";
});
}
void GenericNotificationService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[GenericNotificationService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *genericNotification = service->mutable_wifi_projection_service();
}
void GenericNotificationService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[GenericNotificationService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[GenericNotificationService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&GenericNotificationService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void GenericNotificationService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[GenericNotificationService] onChannelError(): " << e.what();
}
}
}
}
} }
}
void GenericNotificationService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] start()";
});
}
void GenericNotificationService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] stop()";
});
}
void GenericNotificationService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] pause()";
});
}
void GenericNotificationService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[GenericNotificationService] resume()";
});
}
void GenericNotificationService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[GenericNotificationService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *genericNotification = service->mutable_wifi_projection_service();
}
void GenericNotificationService::onChannelOpenRequest(
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[GenericNotificationService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[GenericNotificationService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&GenericNotificationService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void GenericNotificationService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[GenericNotificationService] onChannelError(): " << e.what();
}
}

View File

@ -18,26 +18,22 @@
#include <f1x/openauto/autoapp/Service/MediaSink/GuidanceAudioService.hpp> #include <f1x/openauto/autoapp/Service/MediaSink/GuidanceAudioService.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace mediasink {
using f1x::openauto::autoapp::service::mediasink::GuidanceAudioService;
using f1x::openauto::autoapp::service::mediasink::AudioMediaSinkService;
using aasdk::channel::mediasink::audio::channel::GuidanceAudioChannel;
GuidanceAudioService::GuidanceAudioService(boost::asio::io_service &ioService, namespace f1x::openauto::autoapp::service::mediasink {
aasdk::messenger::IMessenger::Pointer messenger, using f1x::openauto::autoapp::service::mediasink::GuidanceAudioService;
projection::IAudioOutput::Pointer audioOutput) using f1x::openauto::autoapp::service::mediasink::AudioMediaSinkService;
: AudioMediaSinkService( using aasdk::channel::mediasink::audio::channel::GuidanceAudioChannel;
ioService,
std::make_shared<GuidanceAudioChannel>(strand_, std::move(messenger)), GuidanceAudioService::GuidanceAudioService(boost::asio::io_service &ioService,
std::move(audioOutput)) { aasdk::messenger::IMessenger::Pointer messenger,
projection::IAudioOutput::Pointer audioOutput)
: AudioMediaSinkService(
ioService,
std::make_shared<GuidanceAudioChannel>(strand_, std::move(messenger)),
std::move(audioOutput)) {
}
}
}
}
} }
} }

View File

@ -19,24 +19,18 @@
#include <f1x/openauto/autoapp/Service/MediaSink/MediaAudioService.hpp> #include <f1x/openauto/autoapp/Service/MediaSink/MediaAudioService.hpp>
namespace f1x::openauto::autoapp::service::mediasink {
MediaAudioService::MediaAudioService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger,
projection::IAudioOutput::Pointer audioOutput)
: AudioMediaSinkService(ioService,
std::make_shared<aasdk::channel::mediasink::audio::channel::MediaAudioChannel>(strand_,
std::move(
messenger)),
std::move(audioOutput)) {
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace mediasink {
MediaAudioService::MediaAudioService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger,
projection::IAudioOutput::Pointer audioOutput)
: AudioMediaSinkService(ioService,
std::make_shared<aasdk::channel::mediasink::audio::channel::MediaAudioChannel>(strand_,
std::move(
messenger)),
std::move(audioOutput)) {
}
}
}
}
} }
} }

View File

@ -19,23 +19,20 @@
#include <aasdk/Channel/MediaSink/Audio/Channel/SystemAudioChannel.hpp> #include <aasdk/Channel/MediaSink/Audio/Channel/SystemAudioChannel.hpp>
#include <f1x/openauto/autoapp/Service/MediaSink/SystemAudioService.hpp> #include <f1x/openauto/autoapp/Service/MediaSink/SystemAudioService.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace mediasink {
SystemAudioService::SystemAudioService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger,
projection::IAudioOutput::Pointer audioOutput)
: AudioMediaSinkService(ioService,
std::make_shared<aasdk::channel::mediasink::audio::channel::SystemAudioChannel>(strand_,
std::move(messenger)),
std::move(audioOutput)) {
} namespace f1x::openauto::autoapp::service::mediasink {
SystemAudioService::SystemAudioService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger,
projection::IAudioOutput::Pointer audioOutput)
: AudioMediaSinkService(ioService,
std::make_shared<aasdk::channel::mediasink::audio::channel::SystemAudioChannel>(strand_,
std::move(
messenger)),
std::move(audioOutput)) {
}
}
}
} }
}
}

View File

@ -16,256 +16,258 @@
* along with openauto. If not, see <http://www.gnu.org/licenses/>. * along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <time.h>
#include <f1x/openauto/Common/Log.hpp> #include <f1x/openauto/Common/Log.hpp>
#include <f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp> #include <f1x/openauto/autoapp/Service/MediaSource/MediaSourceService.hpp>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace mediasource {
MediaSourceService::MediaSourceService(boost::asio::io_service &ioService, namespace f1x::openauto::autoapp::service::mediasource {
aasdk::channel::mediasource::IMediaSourceService::Pointer channel,
projection::IAudioInput::Pointer audioInput)
: strand_(ioService), channel_(std::move(channel)), audioInput_(std::move(audioInput)), session_(-1) {
} MediaSourceService::MediaSourceService(boost::asio::io_service &ioService,
aasdk::channel::mediasource::IMediaSourceService::Pointer channel,
projection::IAudioInput::Pointer audioInput)
: strand_(ioService), channel_(std::move(channel)), audioInput_(std::move(audioInput)), session_(-1) {
void MediaSourceService::start() { }
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[MediaSourceService] start()";
channel_->receive(this->shared_from_this());
});
}
void MediaSourceService::stop() { void MediaSourceService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[MediaSourceService] stop()"; OPENAUTO_LOG(info) << "[MediaSourceService] start()";
audioInput_->stop(); channel_->receive(this->shared_from_this());
}); });
} }
void MediaSourceService::pause() { void MediaSourceService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[MediaSourceService] pause()"; OPENAUTO_LOG(info) << "[MediaSourceService] stop()";
}); audioInput_->stop();
} });
}
void MediaSourceService::resume() { void MediaSourceService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[MediaSourceService] resume()"; OPENAUTO_LOG(info) << "[MediaSourceService] pause()";
}); });
} }
/* void MediaSourceService::resume() {
* Service Discovery strand_.dispatch([this, self = this->shared_from_this()]() {
*/ OPENAUTO_LOG(info) << "[MediaSourceService] resume()";
});
}
/** /*
* Fill Features of Service * Service Discovery
* @param response */
*/
void MediaSourceService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[MediaSourceService] fillFeatures()";
auto *service = response.add_channels(); /**
service->set_id(static_cast<uint32_t>(channel_->getId())); * Fill Features of Service
* @param response
*/
void MediaSourceService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[MediaSourceService] fillFeatures()";
auto *avInputChannel = service->mutable_media_source_service(); auto *service = response.add_channels();
avInputChannel->set_available_type( service->set_id(static_cast<uint32_t>(channel_->getId()));
aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM);
auto audioConfig = avInputChannel->mutable_audio_config(); auto *avInputChannel = service->mutable_media_source_service();
audioConfig->set_sampling_rate(audioInput_->getSampleRate()); avInputChannel->set_available_type(
audioConfig->set_number_of_bits(audioInput_->getSampleSize()); aap_protobuf::service::media::shared::message::MediaCodecType::MEDIA_CODEC_AUDIO_PCM);
audioConfig->set_number_of_channels(audioInput_->getChannelCount());
}
/* auto audioConfig = avInputChannel->mutable_audio_config();
* Base Channel Handling audioConfig->set_sampling_rate(audioInput_->getSampleRate());
*/ audioConfig->set_number_of_bits(audioInput_->getSampleSize());
audioConfig->set_number_of_channels(audioInput_->getChannelCount());
}
/** /*
* Open Service Channel Request * Base Channel Handling
* @param request */
*/
void MediaSourceService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[MediaSourceService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
const aap_protobuf::shared::MessageStatus status = audioInput_->open() /**
? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS * Open Service Channel Request
: aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR; * @param request
*/
void
MediaSourceService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[MediaSourceService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
OPENAUTO_LOG(info) << "[MediaSourceService] Status determined: " << aap_protobuf::shared::MessageStatus_Name(status); const aap_protobuf::shared::MessageStatus status = audioInput_->open()
? aap_protobuf::shared::MessageStatus::STATUS_SUCCESS
: aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR;
aap_protobuf::service::control::message::ChannelOpenResponse response; OPENAUTO_LOG(info) << "[MediaSourceService] Status determined: "
response.set_status(status); << aap_protobuf::shared::MessageStatus_Name(status);
auto promise = aasdk::channel::SendPromise::defer(strand_); aap_protobuf::service::control::message::ChannelOpenResponse response;
promise->then([]() {}, response.set_status(status);
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise)); auto promise = aasdk::channel::SendPromise::defer(strand_);
channel_->receive(this->shared_from_this()); promise->then([]() {},
} std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
/** channel_->sendChannelOpenResponse(response, std::move(promise));
* Generic Channel Error channel_->receive(this->shared_from_this());
* @param e }
*/
void MediaSourceService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[MediaSourceService] onChannelError(): " << e.what();
}
/* /**
* Media Channel Handling * Generic Channel Error
*/ * @param e
*/
void MediaSourceService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[MediaSourceService] onChannelError(): " << e.what();
}
/** /*
* Generic Media Channel Setup Request * Media Channel Handling
* @param request */
*/
void
MediaSourceService::onMediaChannelSetupRequest(const aap_protobuf::service::media::shared::message::Setup &request) {
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelSetupRequest()"; /**
OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId()) << ", Codec: " << MediaCodecType_Name(request.type()); * Generic Media Channel Setup Request
* @param request
*/
void
MediaSourceService::onMediaChannelSetupRequest(const aap_protobuf::service::media::shared::message::Setup &request) {
aap_protobuf::service::media::shared::message::Config response; OPENAUTO_LOG(info) << "[MediaSourceService] onMediaChannelSetupRequest()";
auto status = aap_protobuf::service::media::shared::message::Config::STATUS_READY; OPENAUTO_LOG(info) << "[MediaSourceService] Channel Id: " << aasdk::messenger::channelIdToString(channel_->getId())
response.set_status(status); << ", Codec: " << MediaCodecType_Name(request.type());
response.set_max_unacked(1);
response.add_configuration_indices(0);
auto promise = aasdk::channel::SendPromise::defer(strand_); aap_protobuf::service::media::shared::message::Config response;
auto status = aap_protobuf::service::media::shared::message::Config::STATUS_READY;
response.set_status(status);
response.set_max_unacked(1);
response.add_configuration_indices(0);
promise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(), auto promise = aasdk::channel::SendPromise::defer(strand_);
std::placeholders::_1));
channel_->sendChannelSetupResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
/** promise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
* Generic Media Ack std::placeholders::_1));
*/ channel_->sendChannelSetupResponse(response, std::move(promise));
void MediaSourceService::onMediaChannelAckIndication( channel_->receive(this->shared_from_this());
const aap_protobuf::service::media::source::message::Ack &) { }
OPENAUTO_LOG(debug) << "[MediaSourceService] onMediaChannelAckIndication()";
channel_->receive(this->shared_from_this());
}
/* /**
* Source Media Channel Handling * Generic Media Ack
*/ */
void MediaSourceService::onMediaChannelAckIndication(
const aap_protobuf::service::media::source::message::Ack &) {
OPENAUTO_LOG(debug) << "[MediaSourceService] onMediaChannelAckIndication()";
channel_->receive(this->shared_from_this());
}
/** /*
* Handle request to Open or Close Microphone Source Channel * Source Media Channel Handling
* @param request */
*/
void MediaSourceService::onMediaSourceOpenRequest(
const aap_protobuf::service::media::source::message::MicrophoneRequest &request) {
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaSourceOpenRequest()";
OPENAUTO_LOG(info) << "[MediaSourceService] Request to Open?: " << request.open() << ", anc: " << request.anc_enabled() << ", ec: " << request.ec_enabled() << ", max unacked: " << request.max_unacked();
if (request.open()) { /**
// Request for Channel Open * Handle request to Open or Close Microphone Source Channel
auto startPromise = projection::IAudioInput::StartPromise::defer(strand_); * @param request
startPromise->then(std::bind(&MediaSourceService::onMediaSourceOpenSuccess, this->shared_from_this()), */
[this, self = this->shared_from_this()]() { void MediaSourceService::onMediaSourceOpenRequest(
OPENAUTO_LOG(error) << "[MediaSourceService] Media Source Open Failed"; const aap_protobuf::service::media::source::message::MicrophoneRequest &request) {
OPENAUTO_LOG(info) << "[MediaSourceService] onMediaSourceOpenRequest()";
OPENAUTO_LOG(info) << "[MediaSourceService] Request to Open?: " << request.open() << ", anc: "
<< request.anc_enabled() << ", ec: " << request.ec_enabled() << ", max unacked: "
<< request.max_unacked();
aap_protobuf::service::media::source::message::MicrophoneResponse response; if (request.open()) {
response.set_session_id(session_); // Request for Channel Open
auto startPromise = projection::IAudioInput::StartPromise::defer(strand_);
startPromise->then(std::bind(&MediaSourceService::onMediaSourceOpenSuccess, this->shared_from_this()),
[this, self = this->shared_from_this()]() {
OPENAUTO_LOG(error) << "[MediaSourceService] Media Source Open Failed";
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR); aap_protobuf::service::media::source::message::MicrophoneResponse response;
response.set_session_id(session_);
auto sendPromise = aasdk::channel::SendPromise::defer(strand_); response.set_status(aap_protobuf::shared::MessageStatus::STATUS_INTERNAL_ERROR);
sendPromise->then([]() {},
std::bind(&MediaSourceService::onChannelError,
this->shared_from_this(),
std::placeholders::_1));
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
});
audioInput_->start(std::move(startPromise)); auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
} else { sendPromise->then([]() {},
// Request for Channel Close std::bind(&MediaSourceService::onChannelError,
audioInput_->stop(); this->shared_from_this(),
std::placeholders::_1));
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
});
aap_protobuf::service::media::source::message::MicrophoneResponse response; audioInput_->start(std::move(startPromise));
response.set_session_id(session_); } else {
// Request for Channel Close
audioInput_->stop();
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); aap_protobuf::service::media::source::message::MicrophoneResponse response;
response.set_session_id(session_);
auto sendPromise = aasdk::channel::SendPromise::defer(strand_); response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
}
channel_->receive(this->shared_from_this()); auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
} sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
}
channel_->receive(this->shared_from_this());
}
/** /**
* Sends response to advise Microphone is Open * Sends response to advise Microphone is Open
*/ */
void MediaSourceService::onMediaSourceOpenSuccess() { void MediaSourceService::onMediaSourceOpenSuccess() {
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceOpenSuccess()"; OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceOpenSuccess()";
aap_protobuf::service::media::source::message::MicrophoneResponse response; aap_protobuf::service::media::source::message::MicrophoneResponse response;
response.set_session_id(session_); response.set_session_id(session_);
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS); response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
auto sendPromise = aasdk::channel::SendPromise::defer(strand_); auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(), sendPromise->then([]() {}, std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1)); std::placeholders::_1));
channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise)); channel_->sendMicrophoneOpenResponse(response, std::move(sendPromise));
this->readMediaSource(); this->readMediaSource();
} }
/** /**
* Resolves promise from readMediaSource. Sends Media with Timestamp Indication to channel. * Resolves promise from readMediaSource. Sends Media with Timestamp Indication to channel.
* @param data * @param data
*/ */
void MediaSourceService::onMediaSourceDataReady(aasdk::common::Data data) { void MediaSourceService::onMediaSourceDataReady(aasdk::common::Data data) {
OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceDataReady()"; OPENAUTO_LOG(error) << "[MediaSourceService] onMediaSourceDataReady()";
auto sendPromise = aasdk::channel::SendPromise::defer(strand_); auto sendPromise = aasdk::channel::SendPromise::defer(strand_);
sendPromise->then(std::bind(&MediaSourceService::readMediaSource, this->shared_from_this()), sendPromise->then(std::bind(&MediaSourceService::readMediaSource, this->shared_from_this()),
std::bind(&MediaSourceService::onChannelError, this->shared_from_this(), std::bind(&MediaSourceService::onChannelError, this->shared_from_this(),
std::placeholders::_1)); std::placeholders::_1));
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>( auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()); std::chrono::high_resolution_clock::now().time_since_epoch());
channel_->sendMediaSourceWithTimestampIndication(timestamp.count(), std::move(data), std::move(sendPromise)); channel_->sendMediaSourceWithTimestampIndication(timestamp.count(), std::move(data), std::move(sendPromise));
} }
/** /**
* Reads audio from a MediaSource (eg Microphone). Promise resolves to onMediaSourceDataReady. * Reads audio from a MediaSource (eg Microphone). Promise resolves to onMediaSourceDataReady.
*/ */
void MediaSourceService::readMediaSource() { void MediaSourceService::readMediaSource() {
OPENAUTO_LOG(debug) << "[MediaSourceService] readMediaSource()"; OPENAUTO_LOG(debug) << "[MediaSourceService] readMediaSource()";
if (audioInput_->isActive()) { if (audioInput_->isActive()) {
auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_); auto readPromise = projection::IAudioInput::ReadPromise::defer(strand_);
readPromise->then( readPromise->then(
std::bind(&MediaSourceService::onMediaSourceDataReady, this->shared_from_this(), std::bind(&MediaSourceService::onMediaSourceDataReady, this->shared_from_this(),
std::placeholders::_1), std::placeholders::_1),
[this, self = this->shared_from_this()]() { [this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[MediaSourceService] audio input read rejected."; OPENAUTO_LOG(debug) << "[MediaSourceService] audio input read rejected.";
}); });
audioInput_->read(std::move(readPromise)); audioInput_->read(std::move(readPromise));
}
}
}
}
} }
} }
} }

View File

@ -19,22 +19,18 @@
#include <aasdk/Channel/MediaSource/Audio/MicrophoneAudioChannel.hpp> #include <aasdk/Channel/MediaSource/Audio/MicrophoneAudioChannel.hpp>
#include <f1x/openauto/autoapp/Service/MediaSource/MicrophoneMediaSourceService.hpp> #include <f1x/openauto/autoapp/Service/MediaSource/MicrophoneMediaSourceService.hpp>
namespace f1x { namespace f1x::openauto::autoapp::service::mediasource {
namespace openauto { MicrophoneMediaSourceService::MicrophoneMediaSourceService(boost::asio::io_service &ioService,
namespace autoapp { aasdk::messenger::IMessenger::Pointer messenger,
namespace service { projection::IAudioInput::Pointer audioOutput)
namespace mediasource { : MediaSourceService(ioService,
MicrophoneMediaSourceService::MicrophoneMediaSourceService(boost::asio::io_service &ioService, std::make_shared<aasdk::channel::mediasource::audio::MicrophoneAudioChannel>(strand_,
aasdk::messenger::IMessenger::Pointer messenger, std::move(
projection::IAudioInput::Pointer audioOutput) messenger)),
: MediaSourceService(ioService, std::make_shared<aasdk::channel::mediasource::audio::MicrophoneAudioChannel>(strand_, std::move(audioOutput)) {
std::move(
messenger)),
std::move(audioOutput)) {
}
}
}
}
} }
} }

View File

@ -21,89 +21,90 @@
#include <fstream> #include <fstream>
#include <QString> #include <QString>
namespace f1x { namespace f1x::openauto::autoapp::service::navigationstatus {
namespace openauto {
namespace autoapp {
namespace service {
namespace navigationstatus {
NavigationStatusService::NavigationStatusService(boost::asio::io_service &ioService, NavigationStatusService::NavigationStatusService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger) aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService), : strand_(ioService),
timer_(ioService), timer_(ioService),
channel_(std::make_shared<aasdk::channel::navigationstatus::NavigationStatusService>(strand_, std::move(messenger))) { channel_(std::make_shared<aasdk::channel::navigationstatus::NavigationStatusService>(strand_,
std::move(messenger))) {
}
void NavigationStatusService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] start()";
});
}
void NavigationStatusService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] stop()";
});
}
void NavigationStatusService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] pause()";
});
}
void NavigationStatusService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] resume()";
});
}
void NavigationStatusService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[NavigationStatusService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *navigationStatus = service->mutable_navigation_status_service();
}
void NavigationStatusService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[NavigationStatusService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[NavigationStatusService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&NavigationStatusService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onStatusUpdate(const aap_protobuf::service::navigationstatus::message::NavigationStatus &navStatus) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onTurnEvent(const aap_protobuf::service::navigationstatus::message::NavigationNextTurnEvent &turnEvent) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onDistanceEvent(const aap_protobuf::service::navigationstatus::message::NavigationNextTurnDistanceEvent &distanceEvent) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[NavigationStatusService] onChannelError(): " << e.what();
}
}
}
}
} }
}
void NavigationStatusService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] start()";
});
}
void NavigationStatusService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] stop()";
});
}
void NavigationStatusService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] pause()";
});
}
void NavigationStatusService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[NavigationStatusService] resume()";
});
}
void NavigationStatusService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[NavigationStatusService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *navigationStatus = service->mutable_navigation_status_service();
}
void NavigationStatusService::onChannelOpenRequest(
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[NavigationStatusService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[NavigationStatusService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&NavigationStatusService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onStatusUpdate(
const aap_protobuf::service::navigationstatus::message::NavigationStatus &navStatus) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onTurnEvent(
const aap_protobuf::service::navigationstatus::message::NavigationNextTurnEvent &turnEvent) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onDistanceEvent(
const aap_protobuf::service::navigationstatus::message::NavigationNextTurnDistanceEvent &distanceEvent) {
channel_->receive(this->shared_from_this());
}
void NavigationStatusService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[NavigationStatusService] onChannelError(): " << e.what();
}
}

View File

@ -19,86 +19,60 @@
#include <f1x/openauto/autoapp/Service/Pinger.hpp> #include <f1x/openauto/autoapp/Service/Pinger.hpp>
#include <f1x/openauto/Common/Log.hpp> #include <f1x/openauto/Common/Log.hpp>
namespace f1x namespace f1x::openauto::autoapp::service {
{
namespace openauto
{
namespace autoapp
{
namespace service
{
Pinger::Pinger(boost::asio::io_service& ioService, time_t duration) Pinger::Pinger(boost::asio::io_service &ioService, time_t duration)
: strand_(ioService) : strand_(ioService), timer_(ioService), duration_(duration), cancelled_(false), pingsCount_(0), pongsCount_(0) {
, timer_(ioService)
, duration_(duration)
, cancelled_(false)
, pingsCount_(0)
, pongsCount_(0)
{
} }
void Pinger::ping(Promise::Pointer promise) void Pinger::ping(Promise::Pointer promise) {
{
strand_.dispatch([this, self = this->shared_from_this(), promise = std::move(promise)]() mutable { strand_.dispatch([this, self = this->shared_from_this(), promise = std::move(promise)]() mutable {
cancelled_ = false; cancelled_ = false;
if(promise_ != nullptr) if (promise_ != nullptr) {
{ promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_IN_PROGRESS));
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)); } else {
} ++pingsCount_;
else OPENAUTO_LOG(debug) << "[Pinger] Ping counter: " << pingsCount_;
{
++pingsCount_;
OPENAUTO_LOG(debug) << "[Pinger] Ping counter: " << pingsCount_;
promise_ = std::move(promise); promise_ = std::move(promise);
timer_.expires_from_now(boost::posix_time::milliseconds(duration_)); 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))); timer_.async_wait(
} strand_.wrap(std::bind(&Pinger::onTimerExceeded, this->shared_from_this(), std::placeholders::_1)));
}
}); });
} }
void Pinger::pong() void Pinger::pong() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
++pongsCount_; ++pongsCount_;
OPENAUTO_LOG(debug) << "[Pinger] Pong counter: " << pongsCount_; OPENAUTO_LOG(debug) << "[Pinger] Pong counter: " << pongsCount_;
}); });
} }
void Pinger::onTimerExceeded(const boost::system::error_code& error) void Pinger::onTimerExceeded(const boost::system::error_code &error) {
{ if (promise_ == nullptr) {
if(promise_ == nullptr) return;
{ } else if (error == boost::asio::error::operation_aborted || cancelled_) {
return; promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_ABORTED));
} } else if (pingsCount_ - pongsCount_ > 4) {
else if(error == boost::asio::error::operation_aborted || cancelled_) promise_->reject(aasdk::error::Error());
{ } else {
promise_->reject(aasdk::error::Error(aasdk::error::ErrorCode::OPERATION_ABORTED)); promise_->resolve();
}
else if(pingsCount_ - pongsCount_ > 4)
{
promise_->reject(aasdk::error::Error());
}
else
{
promise_->resolve();
} }
promise_.reset(); promise_.reset();
} }
void Pinger::cancel() void Pinger::cancel() {
{
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
cancelled_ = true; cancelled_ = true;
timer_.cancel(); timer_.cancel();
}); });
} }
} }
}
}
}

View File

@ -21,78 +21,74 @@
#include <fstream> #include <fstream>
#include <QString> #include <QString>
namespace f1x { namespace f1x::openauto::autoapp::service::radio {
namespace openauto {
namespace autoapp {
namespace service {
namespace radio {
RadioService::RadioService(boost::asio::io_service &ioService, RadioService::RadioService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger) aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService), : strand_(ioService),
timer_(ioService), timer_(ioService),
channel_(std::make_shared<aasdk::channel::radio::RadioService>(strand_, std::move(messenger))) { channel_(std::make_shared<aasdk::channel::radio::RadioService>(strand_, std::move(messenger))) {
}
void RadioService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] start()";
});
}
void RadioService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] stop()";
});
}
void RadioService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] pause()";
});
}
void RadioService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] resume()";
});
}
void RadioService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[RadioService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *radio = service->mutable_radio_service();
}
void RadioService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[RadioService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[RadioService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&RadioService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void RadioService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[RadioService] onChannelError(): " << e.what();
}
}
}
}
} }
}
void RadioService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] start()";
});
}
void RadioService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] stop()";
});
}
void RadioService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] pause()";
});
}
void RadioService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(debug) << "[RadioService] resume()";
});
}
void RadioService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[RadioService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *radio = service->mutable_radio_service();
}
void RadioService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[RadioService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[RadioService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&RadioService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void RadioService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[RadioService] onChannelError(): " << e.what();
}
}

View File

@ -23,230 +23,224 @@
#include <cmath> #include <cmath>
#include <gps.h> #include <gps.h>
namespace f1x { namespace f1x::openauto::autoapp::service::sensor {
namespace openauto { SensorService::SensorService(boost::asio::io_service &ioService,
namespace autoapp { aasdk::messenger::IMessenger::Pointer messenger)
namespace service { : strand_(ioService),
namespace sensor { timer_(ioService),
SensorService::SensorService(boost::asio::io_service &ioService, channel_(std::make_shared<aasdk::channel::sensorsource::SensorSourceService>(strand_, std::move(messenger))) {
aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService),
timer_(ioService),
channel_(std::make_shared<aasdk::channel::sensorsource::SensorSourceService>(strand_, std::move(messenger))) {
} }
void SensorService::start() { void SensorService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() { strand_.dispatch([this, self = this->shared_from_this()]() {
if (gps_open("127.0.0.1", "2947", &this->gpsData_)) { if (gps_open("127.0.0.1", "2947", &this->gpsData_)) {
OPENAUTO_LOG(warning) << "[SensorService] can't connect to GPSD."; OPENAUTO_LOG(warning) << "[SensorService] can't connect to GPSD.";
} else { } else {
OPENAUTO_LOG(info) << "[SensorService] Connected to GPSD."; OPENAUTO_LOG(info) << "[SensorService] Connected to GPSD.";
gps_stream(&this->gpsData_, WATCH_ENABLE | WATCH_JSON, NULL); gps_stream(&this->gpsData_, WATCH_ENABLE | WATCH_JSON, NULL);
this->gpsEnabled_ = true; this->gpsEnabled_ = true;
}
if (is_file_exist("/tmp/night_mode_enabled")) {
this->isNight = true;
}
this->sensorPolling();
OPENAUTO_LOG(info) << "[SensorService] start()";
channel_->receive(this->shared_from_this());
});
}
void SensorService::stop() {
this->stopPolling = true;
strand_.dispatch([this, self = this->shared_from_this()]() {
if (this->gpsEnabled_) {
gps_stream(&this->gpsData_, WATCH_DISABLE, NULL);
gps_close(&this->gpsData_);
this->gpsEnabled_ = false;
}
OPENAUTO_LOG(info) << "[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(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[SensorService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *sensorChannel = service->mutable_sensor_source_service();
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_DRIVING_STATUS_DATA);
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_LOCATION);
sensorChannel->add_sensors()->set_sensor_type(aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE);
}
void SensorService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[SensorService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[SensorService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void SensorService::onSensorStartRequest(
const aap_protobuf::service::sensorsource::message::SensorRequest &request) {
OPENAUTO_LOG(info) << "[SensorService] onSensorStartRequest()";
OPENAUTO_LOG(debug) << "[SensorService] Request Type: "<< request.type();
aap_protobuf::service::sensorsource::message::SensorStartResponseMessage response;
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
auto promise = aasdk::channel::SendPromise::defer(strand_);
if (request.type() == aap_protobuf::service::sensorsource::message::SENSOR_DRIVING_STATUS_DATA)
{
promise->then(std::bind(&SensorService::sendDrivingStatusUnrestricted, this->shared_from_this()),
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
}
else if (request.type() == aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE)
{
promise->then(std::bind(&SensorService::sendNightData, this->shared_from_this()),
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
}
else
{
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
}
channel_->sendSensorStartResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void SensorService::sendDrivingStatusUnrestricted() {
OPENAUTO_LOG(info) << "[SensorService] sendDrivingStatusUnrestricted()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
indication.add_driving_status_data()->set_status(aap_protobuf::service::sensorsource::message::DrivingStatus::DRIVE_STATUS_UNRESTRICTED);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() { },
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
}
void SensorService::sendNightData() {
OPENAUTO_LOG(info) << "[SensorService] sendNightData()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
if (SensorService::isNight) {
OPENAUTO_LOG(info) << "[SensorService] Night Mode Triggered";
indication.add_night_mode_data()->set_night_mode(true);
} else {
OPENAUTO_LOG(info) << "[SensorService] Day Mode Triggered";
indication.add_night_mode_data()->set_night_mode(false);
}
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
if (this->firstRun) {
this->firstRun = false;
this->previous = this->isNight;
}
}
void SensorService::sendGPSLocationData() {
OPENAUTO_LOG(info) << "[SensorService] sendGPSLocationData()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
auto *locInd = indication.add_location_data();
// epoch seconds
// locInd->set_timestamp(this->gpsData_.fix.time * 1e3);
// degrees
locInd->set_latitude_e7(this->gpsData_.fix.latitude * 1e7);
locInd->set_longitude_e7(this->gpsData_.fix.longitude * 1e7);
// meters
auto accuracy = sqrt(pow(this->gpsData_.fix.epx, 2) + pow(this->gpsData_.fix.epy, 2));
locInd->set_accuracy_e3(accuracy * 1e3);
if (this->gpsData_.set & ALTITUDE_SET) {
// meters above ellipsoid
locInd->set_altitude_e2(this->gpsData_.fix.altitude * 1e2);
}
if (this->gpsData_.set & SPEED_SET) {
// meters per second to knots
locInd->set_speed_e3(this->gpsData_.fix.speed * 1.94384 * 1e3);
}
if (this->gpsData_.set & TRACK_SET) {
// degrees
locInd->set_bearing_e6(this->gpsData_.fix.track * 1e6);
}
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
}
void SensorService::sensorPolling() {
OPENAUTO_LOG(info) << "[SensorService] sensorPolling()";
if (!this->stopPolling) {
strand_.dispatch([this, self = this->shared_from_this()]() {
this->isNight = is_file_exist("/tmp/night_mode_enabled");
if (this->previous != this->isNight && !this->firstRun) {
this->previous = this->isNight;
this->sendNightData();
}
if ((this->gpsEnabled_) &&
(gps_waiting(&this->gpsData_, 0)) &&
(gps_read(&this->gpsData_) > 0) &&
(this->gpsData_.status != STATUS_NO_FIX) &&
(this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) &&
(this->gpsData_.set & TIME_SET) &&
(this->gpsData_.set & LATLON_SET))
{
this->sendGPSLocationData();
}
timer_.expires_from_now(boost::posix_time::milliseconds(250));
timer_.async_wait(strand_.wrap(std::bind(&SensorService::sensorPolling, this->shared_from_this())));
});
}
}
bool SensorService::is_file_exist(const char *fileName) {
OPENAUTO_LOG(info) << "[SensorService] is_file_exist()";
std::ifstream ifile(fileName, std::ios::in);
return ifile.good();
}
void SensorService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[SensorService] onChannelError(): " << e.what();
}
}
} }
if (is_file_exist("/tmp/night_mode_enabled")) {
this->isNight = true;
}
this->sensorPolling();
OPENAUTO_LOG(info) << "[SensorService] start()";
channel_->receive(this->shared_from_this());
});
}
void SensorService::stop() {
this->stopPolling = true;
strand_.dispatch([this, self = this->shared_from_this()]() {
if (this->gpsEnabled_) {
gps_stream(&this->gpsData_, WATCH_DISABLE, NULL);
gps_close(&this->gpsData_);
this->gpsEnabled_ = false;
}
OPENAUTO_LOG(info) << "[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(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[SensorService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *sensorChannel = service->mutable_sensor_source_service();
sensorChannel->add_sensors()->set_sensor_type(
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_DRIVING_STATUS_DATA);
sensorChannel->add_sensors()->set_sensor_type(
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_LOCATION);
sensorChannel->add_sensors()->set_sensor_type(
aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE);
}
void SensorService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[SensorService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[SensorService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void SensorService::onSensorStartRequest(
const aap_protobuf::service::sensorsource::message::SensorRequest &request) {
OPENAUTO_LOG(info) << "[SensorService] onSensorStartRequest()";
OPENAUTO_LOG(debug) << "[SensorService] Request Type: " << request.type();
aap_protobuf::service::sensorsource::message::SensorStartResponseMessage response;
response.set_status(aap_protobuf::shared::MessageStatus::STATUS_SUCCESS);
auto promise = aasdk::channel::SendPromise::defer(strand_);
if (request.type() == aap_protobuf::service::sensorsource::message::SENSOR_DRIVING_STATUS_DATA) {
promise->then(std::bind(&SensorService::sendDrivingStatusUnrestricted, this->shared_from_this()),
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
} else if (request.type() == aap_protobuf::service::sensorsource::message::SensorType::SENSOR_NIGHT_MODE) {
promise->then(std::bind(&SensorService::sendNightData, this->shared_from_this()),
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
} else {
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
}
channel_->sendSensorStartResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void SensorService::sendDrivingStatusUnrestricted() {
OPENAUTO_LOG(info) << "[SensorService] sendDrivingStatusUnrestricted()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
indication.add_driving_status_data()->set_status(
aap_protobuf::service::sensorsource::message::DrivingStatus::DRIVE_STATUS_UNRESTRICTED);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
}
void SensorService::sendNightData() {
OPENAUTO_LOG(info) << "[SensorService] sendNightData()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
if (SensorService::isNight) {
OPENAUTO_LOG(info) << "[SensorService] Night Mode Triggered";
indication.add_night_mode_data()->set_night_mode(true);
} else {
OPENAUTO_LOG(info) << "[SensorService] Day Mode Triggered";
indication.add_night_mode_data()->set_night_mode(false);
}
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
if (this->firstRun) {
this->firstRun = false;
this->previous = this->isNight;
} }
} }
}
void SensorService::sendGPSLocationData() {
OPENAUTO_LOG(info) << "[SensorService] sendGPSLocationData()";
aap_protobuf::service::sensorsource::message::SensorBatch indication;
auto *locInd = indication.add_location_data();
// epoch seconds
// locInd->set_timestamp(this->gpsData_.fix.time * 1e3);
// degrees
locInd->set_latitude_e7(this->gpsData_.fix.latitude * 1e7);
locInd->set_longitude_e7(this->gpsData_.fix.longitude * 1e7);
// meters
auto accuracy = sqrt(pow(this->gpsData_.fix.epx, 2) + pow(this->gpsData_.fix.epy, 2));
locInd->set_accuracy_e3(accuracy * 1e3);
if (this->gpsData_.set & ALTITUDE_SET) {
// meters above ellipsoid
locInd->set_altitude_e2(this->gpsData_.fix.altitude * 1e2);
}
if (this->gpsData_.set & SPEED_SET) {
// meters per second to knots
locInd->set_speed_e3(this->gpsData_.fix.speed * 1.94384 * 1e3);
}
if (this->gpsData_.set & TRACK_SET) {
// degrees
locInd->set_bearing_e6(this->gpsData_.fix.track * 1e6);
}
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {},
std::bind(&SensorService::onChannelError, this->shared_from_this(), std::placeholders::_1));
channel_->sendSensorEventIndication(indication, std::move(promise));
}
void SensorService::sensorPolling() {
OPENAUTO_LOG(info) << "[SensorService] sensorPolling()";
if (!this->stopPolling) {
strand_.dispatch([this, self = this->shared_from_this()]() {
this->isNight = is_file_exist("/tmp/night_mode_enabled");
if (this->previous != this->isNight && !this->firstRun) {
this->previous = this->isNight;
this->sendNightData();
}
if ((this->gpsEnabled_) &&
(gps_waiting(&this->gpsData_, 0)) &&
(gps_read(&this->gpsData_) > 0) &&
(this->gpsData_.status != STATUS_NO_FIX) &&
(this->gpsData_.fix.mode == MODE_2D || this->gpsData_.fix.mode == MODE_3D) &&
(this->gpsData_.set & TIME_SET) &&
(this->gpsData_.set & LATLON_SET)) {
this->sendGPSLocationData();
}
timer_.expires_from_now(boost::posix_time::milliseconds(250));
timer_.async_wait(strand_.wrap(std::bind(&SensorService::sensorPolling, this->shared_from_this())));
});
}
}
bool SensorService::is_file_exist(const char *fileName) {
OPENAUTO_LOG(info) << "[SensorService] is_file_exist()";
std::ifstream ifile(fileName, std::ios::in);
return ifile.good();
}
void SensorService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[SensorService] onChannelError(): " << e.what();
}
}

View File

@ -49,30 +49,28 @@
#include <f1x/openauto/autoapp/Projection/RemoteBluetoothDevice.hpp> #include <f1x/openauto/autoapp/Projection/RemoteBluetoothDevice.hpp>
#include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp> #include <f1x/openauto/autoapp/Projection/DummyBluetoothDevice.hpp>
namespace f1x { namespace f1x::openauto::autoapp::service {
namespace openauto {
namespace autoapp {
namespace service {
ServiceFactory::ServiceFactory(boost::asio::io_service &ioService, ServiceFactory::ServiceFactory(boost::asio::io_service &ioService,
configuration::IConfiguration::Pointer configuration) configuration::IConfiguration::Pointer configuration)
: ioService_(ioService), configuration_(std::move(configuration)) { : ioService_(ioService), configuration_(std::move(configuration)) {
} }
ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messenger) { ServiceList ServiceFactory::create(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] create()"; OPENAUTO_LOG(info) << "[ServiceFactory] create()";
ServiceList serviceList; ServiceList serviceList;
this->createMediaSinkServices(serviceList, messenger); this->createMediaSinkServices(serviceList, messenger);
this->createMediaSourceServices(serviceList, messenger); this->createMediaSourceServices(serviceList, messenger);
serviceList.emplace_back(this->createSensorService(messenger)); serviceList.emplace_back(this->createSensorService(messenger));
serviceList.emplace_back(this->createBluetoothService(messenger)); serviceList.emplace_back(this->createBluetoothService(messenger));
serviceList.emplace_back(this->createInputService(messenger)); serviceList.emplace_back(this->createInputService(messenger));
//serviceList.emplace_back(this->createWifiProjectionService(messenger)); // TODO: What is WiFi Projection Service?
//serviceList.emplace_back(this->createWifiProjectionService(messenger));
return serviceList; return serviceList;
} }
IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger) { IService::Pointer ServiceFactory::createBluetoothService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createBluetoothService()"; OPENAUTO_LOG(info) << "[ServiceFactory] createBluetoothService()";
@ -97,123 +95,123 @@ namespace f1x {
break; break;
} }
return std::make_shared<bluetooth::BluetoothService>(ioService_, messenger, std::move(bluetoothDevice)); return std::make_shared<bluetooth::BluetoothService>(ioService_, messenger, std::move(bluetoothDevice));
} }
IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) { IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createInputService()"; OPENAUTO_LOG(info) << "[ServiceFactory] createInputService()";
QRect videoGeometry; QRect videoGeometry;
switch (configuration_->getVideoResolution()) { switch (configuration_->getVideoResolution()) {
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1280x720: case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1280x720:
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1280x720"; OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1280x720";
videoGeometry = QRect(0, 0, 1280, 720); videoGeometry = QRect(0, 0, 1280, 720);
break; break;
case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1920x1080: case aap_protobuf::service::media::sink::message::VideoCodecResolutionType::VIDEO_1920x1080:
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1920x1080"; OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 1920x1080";
videoGeometry = QRect(0, 0, 1920, 1080); videoGeometry = QRect(0, 0, 1920, 1080);
break; break;
default: default:
OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 800x480"; OPENAUTO_LOG(info) << "[ServiceFactory] Resolution 800x480";
videoGeometry = QRect(0, 0, 800, 480); videoGeometry = QRect(0, 0, 800, 480);
break; break;
} }
QScreen *screen = QGuiApplication::primaryScreen(); QScreen *screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen == nullptr ? QRect(0, 0, 1, 1) : screen->geometry(); QRect screenGeometry = screen == nullptr ? QRect(0, 0, 1, 1) : screen->geometry();
projection::IInputDevice::Pointer inputDevice( projection::IInputDevice::Pointer inputDevice(
std::make_shared<projection::InputDevice>(*QApplication::instance(), configuration_, std::make_shared<projection::InputDevice>(*QApplication::instance(), configuration_,
std::move(screenGeometry), std::move(videoGeometry))); std::move(screenGeometry), std::move(videoGeometry)));
return std::make_shared<inputsource::InputSourceService>(ioService_, messenger, std::move(inputDevice)); return std::make_shared<inputsource::InputSourceService>(ioService_, messenger, std::move(inputDevice));
} }
void ServiceFactory::createMediaSinkServices(ServiceList &serviceList, void ServiceFactory::createMediaSinkServices(ServiceList &serviceList,
aasdk::messenger::IMessenger::Pointer messenger) { aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSinkServices()"; OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSinkServices()";
if (configuration_->musicAudioChannelEnabled()) { if (configuration_->musicAudioChannelEnabled()) {
OPENAUTO_LOG(info) << "[ServiceFactory] Media Audio Channel enabled"; OPENAUTO_LOG(info) << "[ServiceFactory] Media Audio Channel enabled";
auto mediaAudioOutput = auto mediaAudioOutput =
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<projection::RtAudioOutput>(2, 16, 48000) : std::make_shared<projection::RtAudioOutput>(2, 16, 48000) :
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(2, 16, 48000), projection::IAudioOutput::Pointer(new projection::QtAudioOutput(2, 16, 48000),
std::bind(&QObject::deleteLater, std::placeholders::_1)); std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back( serviceList.emplace_back(
std::make_shared<mediasink::MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput))); std::make_shared<mediasink::MediaAudioService>(ioService_, messenger, std::move(mediaAudioOutput)));
} }
if (configuration_->guidanceAudioChannelEnabled()) { if (configuration_->guidanceAudioChannelEnabled()) {
OPENAUTO_LOG(info) << "[ServiceFactory] Guidance Audio Channel enabled"; OPENAUTO_LOG(info) << "[ServiceFactory] Guidance Audio Channel enabled";
auto guidanceAudioOutput = auto guidanceAudioOutput =
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) : std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000), projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
std::bind(&QObject::deleteLater, std::placeholders::_1)); std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back( serviceList.emplace_back(
std::make_shared<mediasink::GuidanceAudioService>(ioService_, messenger, std::make_shared<mediasink::GuidanceAudioService>(ioService_, messenger,
std::move(guidanceAudioOutput))); std::move(guidanceAudioOutput)));
} }
if (configuration_->telephonyAudioChannelEnabled()) { if (configuration_->telephonyAudioChannelEnabled()) {
OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled"; OPENAUTO_LOG(info) << "[ServiceFactory] Telephony Audio Channel enabled";
auto telephonyAudioOutput = auto telephonyAudioOutput =
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) : std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000), projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
std::bind(&QObject::deleteLater, std::placeholders::_1)); std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back( serviceList.emplace_back(
std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger, std::make_shared<mediasink::TelephonyAudioService>(ioService_, messenger,
std::move(telephonyAudioOutput))); std::move(telephonyAudioOutput)));
} }
/* /*
* No Need to Check for systemAudioChannelEnabled - MUST be enabled by default. * No Need to Check for systemAudioChannelEnabled - MUST be enabled by default.
*/ */
OPENAUTO_LOG(info) << "[ServiceFactory] System Audio Channel enabled"; OPENAUTO_LOG(info) << "[ServiceFactory] System Audio Channel enabled";
auto systemAudioOutput = auto systemAudioOutput =
configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ? configuration_->getAudioOutputBackendType() == configuration::AudioOutputBackendType::RTAUDIO ?
std::make_shared<projection::RtAudioOutput>(1, 16, 16000) : std::make_shared<projection::RtAudioOutput>(1, 16, 16000) :
projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000), projection::IAudioOutput::Pointer(new projection::QtAudioOutput(1, 16, 16000),
std::bind(&QObject::deleteLater, std::placeholders::_1)); std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back( serviceList.emplace_back(
std::make_shared<mediasink::SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput))); std::make_shared<mediasink::SystemAudioService>(ioService_, messenger, std::move(systemAudioOutput)));
#ifdef USE_OMX #ifdef USE_OMX
auto videoOutput(std::make_shared<projection::OMXVideoOutput>(configuration_)); auto videoOutput(std::make_shared<projection::OMXVideoOutput>(configuration_));
#else #else
projection::IVideoOutput::Pointer videoOutput(new projection::QtVideoOutput(configuration_), projection::IVideoOutput::Pointer videoOutput(new projection::QtVideoOutput(configuration_),
std::bind(&QObject::deleteLater, std::placeholders::_1)); std::bind(&QObject::deleteLater, std::placeholders::_1));
#endif #endif
OPENAUTO_LOG(info) << "[ServiceFactory] Video Channel enabled"; OPENAUTO_LOG(info) << "[ServiceFactory] Video Channel enabled";
serviceList.emplace_back( serviceList.emplace_back(
std::make_shared<mediasink::VideoService>(ioService_, messenger, std::move(videoOutput))); std::make_shared<mediasink::VideoService>(ioService_, messenger, std::move(videoOutput)));
}
void ServiceFactory::createMediaSourceServices(f1x::openauto::autoapp::service::ServiceList &serviceList,
aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSourceServices()";
projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000),
std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back(std::make_shared<mediasource::MicrophoneMediaSourceService>(ioService_, messenger,
std::move(audioInput)));
}
IService::Pointer ServiceFactory::createSensorService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createSensorService()";
return std::make_shared<sensor::SensorService>(ioService_, messenger);
}
IService::Pointer ServiceFactory::createWifiProjectionService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createWifiProjectionService()";
return std::make_shared<wifiprojection::WifiProjectionService>(ioService_, messenger);
}
}
}
} }
void ServiceFactory::createMediaSourceServices(f1x::openauto::autoapp::service::ServiceList &serviceList,
aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createMediaSourceServices()";
projection::IAudioInput::Pointer audioInput(new projection::QtAudioInput(1, 16, 16000),
std::bind(&QObject::deleteLater, std::placeholders::_1));
serviceList.emplace_back(std::make_shared<mediasource::MicrophoneMediaSourceService>(ioService_, messenger,
std::move(audioInput)));
}
IService::Pointer ServiceFactory::createSensorService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createSensorService()";
return std::make_shared<sensor::SensorService>(ioService_, messenger);
}
IService::Pointer ServiceFactory::createWifiProjectionService(aasdk::messenger::IMessenger::Pointer messenger) {
OPENAUTO_LOG(info) << "[ServiceFactory] createWifiProjectionService()";
return std::make_shared<wifiprojection::WifiProjectionService>(ioService_, messenger);
}
} }

View File

@ -21,74 +21,72 @@
#include <fstream> #include <fstream>
#include <QString> #include <QString>
namespace f1x { namespace f1x::openauto::autoapp::service::vendorextension {
namespace openauto {
namespace autoapp {
namespace service {
namespace vendorextension {
VendorExtensionService::VendorExtensionService(boost::asio::io_service &ioService, VendorExtensionService::VendorExtensionService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger) aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService), : strand_(ioService),
timer_(ioService), timer_(ioService),
channel_(std::make_shared<aasdk::channel::vendorextension::VendorExtensionService>(strand_, std::move(messenger))) { channel_(
std::make_shared<aasdk::channel::vendorextension::VendorExtensionService>(strand_, std::move(messenger))) {
}
void VendorExtensionService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] start()";
});
}
void VendorExtensionService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] stop()";
});
}
void VendorExtensionService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] pause()";
});
}
void VendorExtensionService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] resume()";
});
}
void VendorExtensionService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[VendorExtensionService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *vendorExtension = service->mutable_vendor_extension_service();
}
void VendorExtensionService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[VendorExtensionService] onChannelError(): " << e.what();
}
void VendorExtensionService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[VendorExtensionService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[VendorExtensionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&VendorExtensionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
}
}
}
} }
}
void VendorExtensionService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] start()";
});
}
void VendorExtensionService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] stop()";
});
}
void VendorExtensionService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] pause()";
});
}
void VendorExtensionService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[VendorExtensionService] resume()";
});
}
void VendorExtensionService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[VendorExtensionService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *vendorExtension = service->mutable_vendor_extension_service();
}
void VendorExtensionService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[VendorExtensionService] onChannelError(): " << e.what();
}
void VendorExtensionService::onChannelOpenRequest(
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[VendorExtensionService] onChannelOpenRequest()";
OPENAUTO_LOG(info) << "[VendorExtensionService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&VendorExtensionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
}

View File

@ -22,97 +22,97 @@
#include <QString> #include <QString>
#include <QNetworkInterface> #include <QNetworkInterface>
namespace f1x {
namespace openauto {
namespace autoapp {
namespace service {
namespace wifiprojection {
WifiProjectionService::WifiProjectionService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService),
timer_(ioService),
channel_(std::make_shared<aasdk::channel::wifiprojection::WifiProjectionService>(strand_, std::move(messenger))) {
} namespace f1x::openauto::autoapp::service::wifiprojection {
WifiProjectionService::WifiProjectionService(boost::asio::io_service &ioService,
aasdk::messenger::IMessenger::Pointer messenger)
: strand_(ioService),
timer_(ioService),
channel_(
std::make_shared<aasdk::channel::wifiprojection::WifiProjectionService>(strand_, std::move(messenger))) {
void WifiProjectionService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] start()";
});
}
void WifiProjectionService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] stop()";
});
}
void WifiProjectionService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] pause()";
});
}
void WifiProjectionService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] resume()";
});
}
void WifiProjectionService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[WifiProjectionService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *wifiChannel = service->mutable_wifi_projection_service();
wifiChannel->set_car_wifi_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
}
void WifiProjectionService::onWifiCredentialsRequest(
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) {
OPENAUTO_LOG(info) << "[WifiProjectionService] onWifiCredentialsRequest()";
aap_protobuf::service::wifiprojection::message::WifiCredentialsResponse response;
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
response.set_car_wifi_ssid("CRANKSHAFT-NG");
response.set_car_wifi_password("1234567890");
response.set_car_wifi_security_mode(aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_PERSONAL);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendWifiCredentialsResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void WifiProjectionService::onChannelOpenRequest(const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[WifiProjectionService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[WifiProjectionService] Channel Id: " << request.service_id() << ", Priority: " << request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void WifiProjectionService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[WifiProjectionService] onChannelError(): " << e.what();
}
}
}
}
} }
}
void WifiProjectionService::start() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] start()";
});
}
void WifiProjectionService::stop() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] stop()";
});
}
void WifiProjectionService::pause() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] pause()";
});
}
void WifiProjectionService::resume() {
strand_.dispatch([this, self = this->shared_from_this()]() {
OPENAUTO_LOG(info) << "[WifiProjectionService] resume()";
});
}
void WifiProjectionService::fillFeatures(
aap_protobuf::service::control::message::ServiceDiscoveryResponse &response) {
OPENAUTO_LOG(info) << "[WifiProjectionService] fillFeatures()";
auto *service = response.add_channels();
service->set_id(static_cast<uint32_t>(channel_->getId()));
auto *wifiChannel = service->mutable_wifi_projection_service();
wifiChannel->set_car_wifi_bssid(QNetworkInterface::interfaceFromName("wlan0").hardwareAddress().toStdString());
}
void WifiProjectionService::onWifiCredentialsRequest(
const aap_protobuf::service::wifiprojection::message::WifiCredentialsRequest &request) {
OPENAUTO_LOG(info) << "[WifiProjectionService] onWifiCredentialsRequest()";
aap_protobuf::service::wifiprojection::message::WifiCredentialsResponse response;
response.set_access_point_type(aap_protobuf::service::wifiprojection::message::AccessPointType::STATIC);
response.set_car_wifi_ssid("CRANKSHAFT-NG");
response.set_car_wifi_password("1234567890");
response.set_car_wifi_security_mode(
aap_protobuf::service::wifiprojection::message::WifiSecurityMode::WPA2_PERSONAL);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendWifiCredentialsResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void WifiProjectionService::onChannelOpenRequest(
const aap_protobuf::service::control::message::ChannelOpenRequest &request) {
OPENAUTO_LOG(info) << "[WifiProjectionService] onChannelOpenRequest()";
OPENAUTO_LOG(debug) << "[WifiProjectionService] Channel Id: " << request.service_id() << ", Priority: "
<< request.priority();
aap_protobuf::service::control::message::ChannelOpenResponse response;
const aap_protobuf::shared::MessageStatus status = aap_protobuf::shared::MessageStatus::STATUS_SUCCESS;
response.set_status(status);
auto promise = aasdk::channel::SendPromise::defer(strand_);
promise->then([]() {}, std::bind(&WifiProjectionService::onChannelError, this->shared_from_this(),
std::placeholders::_1));
channel_->sendChannelOpenResponse(response, std::move(promise));
channel_->receive(this->shared_from_this());
}
void WifiProjectionService::onChannelError(const aasdk::error::Error &e) {
OPENAUTO_LOG(error) << "[WifiProjectionService] onChannelError(): " << e.what();
}
}

File diff suppressed because it is too large Load Diff