Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/development' into featur…
Browse files Browse the repository at this point in the history
…e/audio_enhancements
  • Loading branch information
f1xpl committed Mar 25, 2018
2 parents 8900c18 + 4b8861f commit ef53aa4
Show file tree
Hide file tree
Showing 18 changed files with 697 additions and 173 deletions.
10 changes: 8 additions & 2 deletions include/f1x/openauto/autoapp/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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;

Expand All @@ -51,6 +55,8 @@ class App: public projection::IAndroidAutoEntityEventHandler, public std::enable
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_;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};

}
}
}
}
57 changes: 57 additions & 0 deletions include/f1x/openauto/autoapp/Configuration/RecentAddressesList.hpp
Original file line number Diff line number Diff line change
@@ -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;
};

}
}
}
}
57 changes: 0 additions & 57 deletions include/f1x/openauto/autoapp/Main.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
};

Expand Down
57 changes: 57 additions & 0 deletions include/f1x/openauto/autoapp/UI/ConnectDialog.hpp
Original file line number Diff line number Diff line change
@@ -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_;
};

}
}
}
}
1 change: 1 addition & 0 deletions include/f1x/openauto/autoapp/UI/MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MainWindow : public QMainWindow
void exit();
void openSettings();
void toggleCursor();
void openConnectDialog();

private:
Ui::MainWindow* ui_;
Expand Down
49 changes: 43 additions & 6 deletions src/autoapp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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))
Expand All @@ -39,14 +43,44 @@ 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();
this->enumerateDevices();
});
}

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()]() {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit ef53aa4

Please sign in to comment.