Merge remote-tracking branch 'remotes/origin/development' into feature/audio_enhancements

pull/53/head
michal.szwaj 2018-03-25 04:21:40 +02:00
commit ef53aa4399
18 changed files with 698 additions and 174 deletions

View File

@ -20,6 +20,9 @@
#include <f1x/aasdk/USB/IUSBHub.hpp>
#include <f1x/aasdk/USB/IConnectedAccessoriesEnumerator.hpp>
#include <f1x/aasdk/USB/USBWrapper.hpp>
#include <f1x/aasdk/TCP/ITCPWrapper.hpp>
#include <f1x/aasdk/TCP/ITCPEndpoint.hpp>
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp>
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp>
@ -35,10 +38,11 @@ class App: public projection::IAndroidAutoEntityEventHandler, public std::enable
public:
typedef std::shared_ptr<App> Pointer;
App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
void start();
void waitForUSBDevice();
void start(aasdk::tcp::ITCPEndpoint::SocketPointer socket);
void stop();
void onAndroidAutoQuit() override;
@ -51,6 +55,8 @@ private:
void onUSBHubError(const aasdk::error::Error& error);
boost::asio::io_service& ioService_;
aasdk::usb::USBWrapper& usbWrapper_;
aasdk::tcp::ITCPWrapper& tcpWrapper_;
boost::asio::io_service::strand strand_;
projection::IAndroidAutoEntityFactory& androidAutoEntityFactory_;
aasdk::usb::IUSBHub::Pointer usbHub_;

View File

@ -0,0 +1,46 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <deque>
#include <string>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace configuration
{
class IRecentAddressesList
{
public:
typedef std::deque<std::string> RecentAddresses;
virtual void read() = 0;
virtual void insertAddress(const std::string& address) = 0;
virtual RecentAddresses getList() const = 0;
};
}
}
}
}

View File

@ -0,0 +1,57 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <deque>
#include <f1x/openauto/autoapp/Configuration/IRecentAddressesList.hpp>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace configuration
{
class RecentAddressesList: public IRecentAddressesList
{
public:
RecentAddressesList(size_t maxListSize);
void read() override;
void insertAddress(const std::string& address) override;
RecentAddresses getList() const override;
private:
void load();
void save();
size_t maxListSize_;
RecentAddresses list_;
static const std::string cConfigFileName;
static const std::string cRecentEntiresCount;
static const std::string cRecentEntryPrefix;
};
}
}
}
}

View File

@ -1,57 +0,0 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <f1x/aasdk/USB/USBWrapper.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryChain.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryChainFactory.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryFactory.hpp>
#include <f1x/openauto/autoapp/App.hpp>
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
#include <f1x/openauto/autoapp/Projection/ServiceFactory.hpp>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
class Main
{
public:
Main(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration);
void start();
void stop();
private:
aasdk::usb::IUSBWrapper& usbWrapper_;
boost::asio::io_service& ioService_;
aasdk::usb::AccessoryModeQueryFactory queryFactory_;
aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory_;
projection::ServiceFactory serviceFactory_;
projection::AndroidAutoEntityFactory androidAutoEntityFactory_;
autoapp::App::Pointer app_;
};
}
}
}

View File

@ -36,18 +36,16 @@ namespace projection
class AndroidAutoEntityFactory: public IAndroidAutoEntityFactory
{
public:
AndroidAutoEntityFactory(aasdk::usb::IUSBWrapper& usbWrapper,
boost::asio::io_service& ioService,
AndroidAutoEntityFactory(boost::asio::io_service& ioService,
configuration::IConfiguration::Pointer configuration,
IServiceFactory& serviceFactory);
IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) override;
IAndroidAutoEntity::Pointer create(aasdk::usb::IAOAPDevice::Pointer aoapDevice) override;
IAndroidAutoEntity::Pointer create(aasdk::tcp::ITCPEndpoint::Pointer tcpEndpoint) override;
private:
IAndroidAutoEntity::Pointer create(aasdk::transport::ITransport::Pointer transport);
aasdk::usb::IUSBWrapper& usbWrapper_;
boost::asio::io_service& ioService_;
configuration::IConfiguration::Pointer configuration_;
IServiceFactory& serviceFactory_;

View File

@ -19,7 +19,7 @@
#pragma once
#include <f1x/aasdk/TCP/ITCPEndpoint.hpp>
#include <f1x/aasdk/USB/USBWrapper.hpp>
#include <f1x/aasdk/USB/IAOAPDevice.hpp>
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntity.hpp>
namespace f1x
@ -36,7 +36,7 @@ class IAndroidAutoEntityFactory
public:
virtual ~IAndroidAutoEntityFactory() = default;
virtual IAndroidAutoEntity::Pointer create(aasdk::usb::DeviceHandle deviceHandle) = 0;
virtual IAndroidAutoEntity::Pointer create(aasdk::usb::IAOAPDevice::Pointer aoapDevice) = 0;
virtual IAndroidAutoEntity::Pointer create(aasdk::tcp::ITCPEndpoint::Pointer tcpEndpoint) = 0;
};

View File

@ -0,0 +1,57 @@
#pragma once
#include <QDialog>
#include <QStringListModel>
#include <f1x/aasdk/TCP/ITCPEndpoint.hpp>
#include <f1x/aasdk/TCP/ITCPWrapper.hpp>
#include <f1x/openauto/autoapp/Configuration/IRecentAddressesList.hpp>
namespace Ui {
class ConnectDialog;
}
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace ui
{
class ConnectDialog : public QDialog
{
Q_OBJECT
public:
explicit ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITCPWrapper& tcpWrapper, openauto::autoapp::configuration::IRecentAddressesList& recentAddressesList, QWidget *parent = nullptr);
~ConnectDialog() override;
signals:
void connectToDevice(const QString& ipAddress);
void connectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress);
void connectionFailed(const QString& message);
private slots:
void onConnectButtonClicked();
void onConnectionFailed(const QString& message);
void onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress);
void onRecentAddressClicked(const QModelIndex& index);
private:
void insertIpAddress(const std::string& ipAddress);
void loadRecentList();
void setControlsEnabledStatus(bool status);
void connectHandler(const boost::system::error_code& ec, const std::string& ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket);
boost::asio::io_service& ioService_;
aasdk::tcp::ITCPWrapper& tcpWrapper_;
openauto::autoapp::configuration::IRecentAddressesList& recentAddressesList_;
Ui::ConnectDialog *ui_;
QStringListModel recentAddressesModel_;
};
}
}
}
}

View File

@ -46,6 +46,7 @@ signals:
void exit();
void openSettings();
void toggleCursor();
void openConnectDialog();
private:
Ui::MainWindow* ui_;

View File

@ -17,6 +17,8 @@
*/
#include <thread>
#include <f1x/aasdk/USB/AOAPDevice.hpp>
#include <f1x/aasdk/TCP/TCPEndpoint.hpp>
#include <f1x/openauto/autoapp/App.hpp>
#include <f1x/openauto/Common/Log.hpp>
@ -27,9 +29,11 @@ namespace openauto
namespace autoapp
{
App::App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
App::App(boost::asio::io_service& ioService, aasdk::usb::USBWrapper& usbWrapper, aasdk::tcp::ITCPWrapper& tcpWrapper, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
: ioService_(ioService)
, usbWrapper_(usbWrapper)
, tcpWrapper_(tcpWrapper)
, strand_(ioService_)
, androidAutoEntityFactory_(androidAutoEntityFactory)
, usbHub_(std::move(usbHub))
@ -39,7 +43,7 @@ App::App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFacto
}
void App::start()
void App::waitForUSBDevice()
{
strand_.dispatch([this, self = this->shared_from_this()]() {
this->waitForDevice();
@ -47,6 +51,36 @@ void App::start()
});
}
void App::start(aasdk::tcp::ITCPEndpoint::SocketPointer socket)
{
strand_.dispatch([this, self = this->shared_from_this(), socket = std::move(socket)]() mutable {
if(androidAutoEntity_ == nullptr)
{
try
{
usbHub_->cancel();
connectedAccessoriesEnumerator_->cancel();
auto tcpEndpoint(std::make_shared<aasdk::tcp::TCPEndpoint>(tcpWrapper_, std::move(socket)));
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(tcpEndpoint));
androidAutoEntity_->start(*this);
}
catch(const aasdk::error::Error& error)
{
OPENAUTO_LOG(error) << "[App] TCP AndroidAutoEntity create error: " << error.what();
androidAutoEntity_.reset();
this->waitForDevice();
}
}
else
{
tcpWrapper_.close(*socket);
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
}
});
}
void App::stop()
{
strand_.dispatch([this, self = this->shared_from_this()]() {
@ -69,12 +103,15 @@ void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
{
try
{
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(deviceHandle));
connectedAccessoriesEnumerator_->cancel();
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
androidAutoEntity_ = androidAutoEntityFactory_.create(std::move(aoapDevice));
androidAutoEntity_->start(*this);
}
catch(const aasdk::error::Error& error)
{
OPENAUTO_LOG(error) << "[App] AndroidAutoEntity create error: " << error.what();
OPENAUTO_LOG(error) << "[App] USB AndroidAutoEntity create error: " << error.what();
androidAutoEntity_.reset();
this->waitForDevice();
@ -128,8 +165,8 @@ void App::onUSBHubError(const aasdk::error::Error& error)
{
OPENAUTO_LOG(error) << "[App] usb hub error: " << error.what();
if(error.getCode() == aasdk::error::ErrorCode::OPERATION_ABORTED ||
error.getCode() == aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)
if(error.getCode() != aasdk::error::ErrorCode::OPERATION_ABORTED &&
error.getCode() != aasdk::error::ErrorCode::OPERATION_IN_PROGRESS)
{
this->waitForDevice();
}

View File

@ -0,0 +1,116 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/property_tree/ini_parser.hpp>
#include <f1x/openauto/Common/Log.hpp>
#include <f1x/openauto/autoapp/Configuration/RecentAddressesList.hpp>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace configuration
{
const std::string RecentAddressesList::cConfigFileName = "openauto_wifi_recent.ini";
const std::string RecentAddressesList::cRecentEntiresCount = "Recent.EntiresCount";
const std::string RecentAddressesList::cRecentEntryPrefix = "Recent.Entry_";
RecentAddressesList::RecentAddressesList(size_t maxListSize)
: maxListSize_(maxListSize)
{
}
void RecentAddressesList::read()
{
this->load();
}
void RecentAddressesList::insertAddress(const std::string& address)
{
if(std::find(list_.begin(), list_.end(), address) != list_.end())
{
return;
}
if(list_.size() >= maxListSize_)
{
list_.pop_back();
}
list_.push_front(address);
this->save();
}
RecentAddressesList::RecentAddresses RecentAddressesList::getList() const
{
return list_;
}
void RecentAddressesList::load()
{
boost::property_tree::ptree iniConfig;
try
{
boost::property_tree::ini_parser::read_ini(cConfigFileName, iniConfig);
const auto listSize = std::min(maxListSize_, iniConfig.get<size_t>(cRecentEntiresCount, 0));
for(size_t i = 0; i < listSize; ++i)
{
const auto key = cRecentEntryPrefix + std::to_string(i);
const auto address = iniConfig.get<RecentAddresses::value_type>(key, RecentAddresses::value_type());
if(!address.empty())
{
list_.push_back(address);
}
}
}
catch(const boost::property_tree::ini_parser_error& e)
{
OPENAUTO_LOG(warning) << "[RecentAddressesList] failed to read configuration file: " << cConfigFileName
<< ", error: " << e.what()
<< ". Empty list will be used.";
}
}
void RecentAddressesList::save()
{
boost::property_tree::ptree iniConfig;
const auto entiresCount = std::min(maxListSize_, list_.size());
iniConfig.put<size_t>(cRecentEntiresCount, entiresCount);
for(size_t i = 0; i < entiresCount; ++i)
{
const auto key = cRecentEntryPrefix + std::to_string(i);
iniConfig.put<RecentAddresses::value_type>(key, list_.at(i));
}
boost::property_tree::ini_parser::write_ini(cConfigFileName, iniConfig);
}
}
}
}
}

View File

@ -1,58 +0,0 @@
/*
* This file is part of openauto project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* openauto is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* openauto is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <f1x/aasdk/USB/USBHub.hpp>
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
#include <f1x/openauto/autoapp/Main.hpp>
namespace f1x
{
namespace openauto
{
namespace autoapp
{
Main::Main(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration)
: usbWrapper_(usbWrapper)
, ioService_(ioService)
, queryFactory_(usbWrapper_, ioService_)
, queryChainFactory_(usbWrapper_, ioService_, queryFactory_)
, serviceFactory_(ioService_, configuration)
, androidAutoEntityFactory_(usbWrapper_, ioService_, configuration, serviceFactory_)
{
auto usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper_, ioService_, queryChainFactory_));
auto ConnectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper_, ioService_, queryChainFactory_));
app_ = std::make_shared<autoapp::App>(ioService_, androidAutoEntityFactory_,
std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
}
void Main::start()
{
app_->start();
}
void Main::stop()
{
app_->stop();
}
}
}
}

View File

@ -33,23 +33,19 @@ namespace autoapp
namespace projection
{
AndroidAutoEntityFactory::AndroidAutoEntityFactory(aasdk::usb::IUSBWrapper& usbWrapper,
boost::asio::io_service& ioService,
AndroidAutoEntityFactory::AndroidAutoEntityFactory(boost::asio::io_service& ioService,
configuration::IConfiguration::Pointer configuration,
IServiceFactory& serviceFactory)
: usbWrapper_(usbWrapper)
, ioService_(ioService)
: ioService_(ioService)
, configuration_(std::move(configuration))
, serviceFactory_(serviceFactory)
{
}
IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::usb::DeviceHandle deviceHandle)
IAndroidAutoEntity::Pointer AndroidAutoEntityFactory::create(aasdk::usb::IAOAPDevice::Pointer aoapDevice)
{
auto aoapDevice(aasdk::usb::AOAPDevice::create(usbWrapper_, ioService_, deviceHandle));
auto transport(std::make_shared<aasdk::transport::USBTransport>(ioService_, aoapDevice));
auto transport(std::make_shared<aasdk::transport::USBTransport>(ioService_, std::move(aoapDevice)));
return create(std::move(transport));
}

View File

@ -0,0 +1,125 @@
#include <QMessageBox>
#include <f1x/openauto/autoapp/UI/ConnectDialog.hpp>
#include "ui_connectdialog.h"
namespace f1x
{
namespace openauto
{
namespace autoapp
{
namespace ui
{
ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITCPWrapper& tcpWrapper, openauto::autoapp::configuration::IRecentAddressesList& recentAddressesList, QWidget *parent)
: QDialog(parent)
, ioService_(ioService)
, tcpWrapper_(tcpWrapper)
, recentAddressesList_(recentAddressesList)
, ui_(new Ui::ConnectDialog)
{
qRegisterMetaType<aasdk::tcp::ITCPEndpoint::SocketPointer>("aasdk::tcp::ITCPEndpoint::SocketPointer");
qRegisterMetaType<std::string>("std::string");
ui_->setupUi(this);
connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &ConnectDialog::close);
connect(ui_->pushButtonConnect, &QPushButton::clicked, this, &ConnectDialog::onConnectButtonClicked);
connect(ui_->listViewRecent, &QListView::clicked, this, &ConnectDialog::onRecentAddressClicked);
connect(this, &ConnectDialog::connectionSucceed, this, &ConnectDialog::onConnectionSucceed);
connect(this, &ConnectDialog::connectionFailed, this, &ConnectDialog::onConnectionFailed);
ui_->listViewRecent->setModel(&recentAddressesModel_);
this->loadRecentList();
}
ConnectDialog::~ConnectDialog()
{
delete ui_;
}
void ConnectDialog::onConnectButtonClicked()
{
this->setControlsEnabledStatus(false);
const auto& ipAddress = ui_->lineEditIPAddress->text().toStdString();
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
try
{
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, std::bind(&ConnectDialog::connectHandler, this, std::placeholders::_1, ipAddress, socket));
}
catch(const boost::system::system_error& se)
{
emit connectionFailed(QString(se.what()));
}
}
void ConnectDialog::connectHandler(const boost::system::error_code& ec, const std::string& ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
{
if(!ec)
{
emit connectionSucceed(std::move(socket), ipAddress);
this->close();
}
else
{
emit connectionFailed(QString::fromStdString(ec.message()));
}
}
void ConnectDialog::onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer, const std::string& ipAddress)
{
this->insertIpAddress(ipAddress);
this->setControlsEnabledStatus(true);
}
void ConnectDialog::onConnectionFailed(const QString& message)
{
this->setControlsEnabledStatus(true);
QMessageBox errorMessage(QMessageBox::Critical, "Connect error", message, QMessageBox::Ok);
errorMessage.setWindowFlags(Qt::WindowStaysOnTopHint);
errorMessage.exec();
}
void ConnectDialog::onRecentAddressClicked(const QModelIndex& index)
{
const auto& recentAddressesList = recentAddressesList_.getList();
if(static_cast<size_t>(index.row()) <= recentAddressesList.size())
{
ui_->lineEditIPAddress->setText(QString::fromStdString(recentAddressesList.at(index.row())));
}
}
void ConnectDialog::setControlsEnabledStatus(bool status)
{
ui_->pushButtonConnect->setVisible(status);
ui_->pushButtonCancel->setEnabled(status);
ui_->lineEditIPAddress->setEnabled(status);
ui_->listViewRecent->setEnabled(status);
}
void ConnectDialog::loadRecentList()
{
QStringList stringList;
const auto& configList = recentAddressesList_.getList();
for(const auto& element : configList)
{
stringList.append(QString::fromStdString(element));
}
recentAddressesModel_.setStringList(stringList);
}
void ConnectDialog::insertIpAddress(const std::string& ipAddress)
{
recentAddressesList_.insertAddress(ipAddress);
this->loadRecentList();
}
}
}
}
}

View File

@ -37,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::openSettings);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit);
connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor);
connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog);
}
MainWindow::~MainWindow()

View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ConnectDialog</class>
<widget class="QDialog" name="ConnectDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>301</width>
<height>389</height>
</rect>
</property>
<property name="windowTitle">
<string>Connect to device</string>
</property>
<widget class="QGroupBox" name="groupBoxIPAddress">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>281</width>
<height>61</height>
</rect>
</property>
<property name="title">
<string>IP Address</string>
</property>
<widget class="QLineEdit" name="lineEditIPAddress">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>261</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBoxRecent">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>281</width>
<height>181</height>
</rect>
</property>
<property name="title">
<string>Recent</string>
</property>
<widget class="QListView" name="listViewRecent">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>261</width>
<height>141</height>
</rect>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</widget>
<widget class="QLabel" name="labelHeadUnitServerInfo">
<property name="geometry">
<rect>
<x>60</x>
<y>260</y>
<width>221</width>
<height>81</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;In order to use wireless mode you must enable head unit server in developer settings.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="labelCopyrightsInfoIcon">
<property name="geometry">
<rect>
<x>20</x>
<y>290</y>
<width>21</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_info.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonCancel">
<property name="geometry">
<rect>
<x>40</x>
<y>340</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonConnect">
<property name="geometry">
<rect>
<x>170</x>
<y>340</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Connect</string>
</property>
</widget>
<widget class="QProgressBar" name="progressBarConnect">
<property name="geometry">
<rect>
<x>170</x>
<y>340</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
<widget class="QLabel" name="labelConnecting">
<property name="geometry">
<rect>
<x>188</x>
<y>350</y>
<width>91</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Connecting...</string>
</property>
</widget>
<zorder>groupBoxIPAddress</zorder>
<zorder>groupBoxRecent</zorder>
<zorder>labelHeadUnitServerInfo</zorder>
<zorder>labelCopyrightsInfoIcon</zorder>
<zorder>pushButtonCancel</zorder>
<zorder>progressBarConnect</zorder>
<zorder>labelConnecting</zorder>
<zorder>pushButtonConnect</zorder>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -48,7 +48,7 @@ color: rgb(238, 238, 236);</string>
<property name="geometry">
<rect>
<x>630</x>
<y>340</y>
<y>370</y>
<width>161</width>
<height>41</height>
</rect>
@ -67,7 +67,7 @@ color: rgb(238, 238, 236);</string>
<property name="geometry">
<rect>
<x>630</x>
<y>390</y>
<y>420</y>
<width>161</width>
<height>41</height>
</rect>
@ -79,7 +79,7 @@ color: rgb(238, 238, 236);</string>
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="labelPluginDeviceText">
<property name="geometry">
<rect>
<x>340</x>
@ -92,11 +92,11 @@ color: rgb(238, 238, 236);</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic; color:#eeeeec;&quot;&gt;Plug in your device to start AndroidAuto (tm).&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="labelProjectHomePage">
<property name="geometry">
<rect>
<x>10</x>
<y>410</y>
<y>440</y>
<width>271</width>
<height>21</height>
</rect>
@ -167,20 +167,20 @@ color: rgb(238, 238, 236);</string>
<property name="geometry">
<rect>
<x>220</x>
<y>376</y>
<y>400</y>
<width>21</width>
<height>21</height>
<height>31</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;img src=&quot;:/ico_info.png&quot;/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="labelTrademark">
<property name="geometry">
<rect>
<x>250</x>
<y>370</y>
<y>400</y>
<width>361</width>
<height>31</height>
</rect>
@ -193,7 +193,7 @@ color: rgb(238, 238, 236);</string>
<property name="geometry">
<rect>
<x>630</x>
<y>290</y>
<y>270</y>
<width>161</width>
<height>41</height>
</rect>
@ -208,21 +208,30 @@ color: rgb(238, 238, 236);</string>
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonWirelessConnection">
<property name="geometry">
<rect>
<x>630</x>
<y>320</y>
<width>161</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Wireless connection</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<tabstops>
<tabstop>pushButtonToggleCursor</tabstop>
<tabstop>pushButtonWirelessConnection</tabstop>
<tabstop>pushButtonSettings</tabstop>
<tabstop>pushButtonExit</tabstop>
</tabstops>

View File

@ -23,7 +23,7 @@
</size>
</property>
<property name="windowTitle">
<string>Form</string>
<string>Settings</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(46, 52, 54);

View File

@ -18,10 +18,21 @@
#include <thread>
#include <QApplication>
#include <f1x/aasdk/USB/USBHub.hpp>
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryChain.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryChainFactory.hpp>
#include <f1x/aasdk/USB/AccessoryModeQueryFactory.hpp>
#include <f1x/aasdk/TCP/TCPWrapper.hpp>
#include <f1x/openauto/autoapp/App.hpp>
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
#include <f1x/openauto/autoapp/Configuration/RecentAddressesList.hpp>
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
#include <f1x/openauto/autoapp/Projection/ServiceFactory.hpp>
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
#include <f1x/openauto/autoapp/UI/SettingsWindow.hpp>
#include <f1x/openauto/autoapp/Main.hpp>
#include <f1x/openauto/autoapp/UI/ConnectDialog.hpp>
#include <f1x/openauto/Common/Log.hpp>
namespace aasdk = f1x::aasdk;
@ -66,35 +77,54 @@ int main(int argc, char* argv[])
return 1;
}
QApplication qApplication(argc, argv);
boost::asio::io_service ioService;
boost::asio::io_service::work work(ioService);
std::vector<std::thread> threadPool;
startUSBWorkers(ioService, usbContext, threadPool);
startIOServiceWorkers(ioService, threadPool);
QApplication qApplication(argc, argv);
autoapp::ui::MainWindow mainWindow;
mainWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
mainWindow.showFullScreen();
auto configuration = std::make_shared<autoapp::configuration::Configuration>();
autoapp::ui::SettingsWindow settingsWindow(configuration);
settingsWindow.setWindowFlags(Qt::WindowStaysOnTopHint);
qApplication.setOverrideCursor(Qt::BlankCursor);
bool cursorVisible = false;
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&cursorVisible, &qApplication]() {
cursorVisible = !cursorVisible;
qApplication.setOverrideCursor(cursorVisible ? Qt::ArrowCursor : Qt::BlankCursor);
});
autoapp::configuration::RecentAddressesList recentAddressesList(7);
recentAddressesList.read();
aasdk::usb::USBWrapper usbWrapper(usbContext);
autoapp::Main main(usbWrapper, ioService, configuration);
aasdk::tcp::TCPWrapper tcpWrapper;
autoapp::ui::ConnectDialog connectDialog(ioService, tcpWrapper, recentAddressesList);
connectDialog.setWindowFlags(Qt::WindowStaysOnTopHint);
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openConnectDialog, &connectDialog, &autoapp::ui::ConnectDialog::exec);
std::vector<std::thread> threadPool;
startUSBWorkers(ioService, usbContext, threadPool);
startIOServiceWorkers(ioService, threadPool);
main.start();
qApplication.setOverrideCursor(Qt::BlankCursor);
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::toggleCursor, [&qApplication]() {
const auto cursor = qApplication.overrideCursor()->shape() == Qt::BlankCursor ? Qt::ArrowCursor : Qt::BlankCursor;
qApplication.setOverrideCursor(cursor);
});
mainWindow.showFullScreen();
aasdk::usb::USBWrapper usbWrapper(usbContext);
aasdk::usb::AccessoryModeQueryFactory queryFactory(usbWrapper, ioService);
aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory(usbWrapper, ioService, queryFactory);
autoapp::projection::ServiceFactory serviceFactory(ioService, configuration);
autoapp::projection::AndroidAutoEntityFactory androidAutoEntityFactory(ioService, configuration, serviceFactory);
auto usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper, ioService, queryChainFactory));
auto connectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper, ioService, queryChainFactory));
auto app = std::make_shared<autoapp::App>(ioService, usbWrapper, tcpWrapper, androidAutoEntityFactory, std::move(usbHub), std::move(connectedAccessoriesEnumerator));
QObject::connect(&connectDialog, &autoapp::ui::ConnectDialog::connectionSucceed, [&app](auto socket) {
app->start(std::move(socket));
});
app->waitForUSBDevice();
auto result = qApplication.exec();
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));