mirror of https://github.com/f1xpl/openauto.git
Remove USB package from autoapp
parent
9e114226a9
commit
9cef110bc4
|
@ -29,15 +29,13 @@ namespace openauto
|
|||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace usb
|
||||
{
|
||||
|
||||
class USBApp: public projection::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this<USBApp>
|
||||
class App: public projection::IAndroidAutoEntityEventHandler, public std::enable_shared_from_this<App>
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<USBApp> Pointer;
|
||||
typedef std::shared_ptr<App> Pointer;
|
||||
|
||||
USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||
App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
|
||||
|
||||
void start();
|
||||
|
@ -45,7 +43,7 @@ public:
|
|||
void onAndroidAutoQuit() override;
|
||||
|
||||
private:
|
||||
using std::enable_shared_from_this<USBApp>::shared_from_this;
|
||||
using std::enable_shared_from_this<App>::shared_from_this;
|
||||
|
||||
void enumerateDevices();
|
||||
void waitForDevice();
|
||||
|
@ -64,4 +62,3 @@ private:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,26 +22,22 @@
|
|||
#include <f1x/aasdk/USB/AccessoryModeQueryChain.hpp>
|
||||
#include <f1x/aasdk/USB/AccessoryModeQueryChainFactory.hpp>
|
||||
#include <f1x/aasdk/USB/AccessoryModeQueryFactory.hpp>
|
||||
#include <f1x/openauto/autoapp/USB/USBApp.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>
|
||||
|
||||
class QApplication;
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace usb
|
||||
{
|
||||
|
||||
class USBMain
|
||||
class Main
|
||||
{
|
||||
public:
|
||||
USBMain(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration);
|
||||
Main(aasdk::usb::IUSBWrapper& usbWrapper, boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
@ -53,10 +49,9 @@ private:
|
|||
aasdk::usb::AccessoryModeQueryChainFactory queryChainFactory_;
|
||||
projection::ServiceFactory serviceFactory_;
|
||||
projection::AndroidAutoEntityFactory androidAutoEntityFactory_;
|
||||
autoapp::usb::USBApp::Pointer usbApp_;
|
||||
autoapp::App::Pointer app_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <thread>
|
||||
#include <f1x/openauto/autoapp/USB/USBApp.hpp>
|
||||
#include <f1x/openauto/autoapp/App.hpp>
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
|
||||
namespace f1x
|
||||
|
@ -26,10 +26,8 @@ namespace openauto
|
|||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace usb
|
||||
{
|
||||
|
||||
USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||
App::App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
||||
: ioService_(ioService)
|
||||
, strand_(ioService_)
|
||||
|
@ -41,7 +39,7 @@ USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntit
|
|||
|
||||
}
|
||||
|
||||
void USBApp::start()
|
||||
void App::start()
|
||||
{
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
this->waitForDevice();
|
||||
|
@ -49,7 +47,7 @@ void USBApp::start()
|
|||
});
|
||||
}
|
||||
|
||||
void USBApp::stop()
|
||||
void App::stop()
|
||||
{
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
isStopped_ = true;
|
||||
|
@ -63,9 +61,9 @@ void USBApp::stop()
|
|||
});
|
||||
}
|
||||
|
||||
void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||
void App::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
||||
{
|
||||
OPENAUTO_LOG(info) << "[USBApp] Device connected.";
|
||||
OPENAUTO_LOG(info) << "[App] Device connected.";
|
||||
|
||||
if(androidAutoEntity_ == nullptr)
|
||||
{
|
||||
|
@ -76,7 +74,7 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
|||
}
|
||||
catch(const aasdk::error::Error& error)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[USBApp] AndroidAutoEntity create error: " << error.what();
|
||||
OPENAUTO_LOG(error) << "[App] AndroidAutoEntity create error: " << error.what();
|
||||
|
||||
androidAutoEntity_.reset();
|
||||
this->waitForDevice();
|
||||
|
@ -84,37 +82,37 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
|||
}
|
||||
else
|
||||
{
|
||||
OPENAUTO_LOG(warning) << "[USBApp] android auto entity is still running.";
|
||||
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||
}
|
||||
}
|
||||
|
||||
void USBApp::enumerateDevices()
|
||||
void App::enumerateDevices()
|
||||
{
|
||||
auto promise = aasdk::usb::IConnectedAccessoriesEnumerator::Promise::defer(strand_);
|
||||
promise->then([this, self = this->shared_from_this()](auto result) {
|
||||
OPENAUTO_LOG(info) << "[USBApp] Devices enumeration result: " << result;
|
||||
OPENAUTO_LOG(info) << "[App] Devices enumeration result: " << result;
|
||||
},
|
||||
[this, self = this->shared_from_this()](auto e) {
|
||||
OPENAUTO_LOG(error) << "[USBApp] Devices enumeration failed: " << e.what();
|
||||
OPENAUTO_LOG(error) << "[App] Devices enumeration failed: " << e.what();
|
||||
});
|
||||
|
||||
connectedAccessoriesEnumerator_->enumerate(std::move(promise));
|
||||
}
|
||||
|
||||
void USBApp::waitForDevice()
|
||||
void App::waitForDevice()
|
||||
{
|
||||
OPENAUTO_LOG(info) << "[USBApp] Waiting for device...";
|
||||
OPENAUTO_LOG(info) << "[App] Waiting for device...";
|
||||
|
||||
auto promise = aasdk::usb::IUSBHub::Promise::defer(strand_);
|
||||
promise->then(std::bind(&USBApp::aoapDeviceHandler, this->shared_from_this(), std::placeholders::_1),
|
||||
std::bind(&USBApp::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
|
||||
promise->then(std::bind(&App::aoapDeviceHandler, this->shared_from_this(), std::placeholders::_1),
|
||||
std::bind(&App::onUSBHubError, this->shared_from_this(), std::placeholders::_1));
|
||||
usbHub_->start(std::move(promise));
|
||||
}
|
||||
|
||||
void USBApp::onAndroidAutoQuit()
|
||||
void App::onAndroidAutoQuit()
|
||||
{
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
OPENAUTO_LOG(info) << "[USBApp] quit.";
|
||||
OPENAUTO_LOG(info) << "[App] quit.";
|
||||
|
||||
androidAutoEntity_->stop();
|
||||
androidAutoEntity_.reset();
|
||||
|
@ -126,9 +124,9 @@ void USBApp::onAndroidAutoQuit()
|
|||
});
|
||||
}
|
||||
|
||||
void USBApp::onUSBHubError(const aasdk::error::Error& error)
|
||||
void App::onUSBHubError(const aasdk::error::Error& error)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[USBApp] usb hub error: " << error.what();
|
||||
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)
|
||||
|
@ -140,4 +138,3 @@ void USBApp::onUSBHubError(const aasdk::error::Error& error)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,89 +16,43 @@
|
|||
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <thread>
|
||||
#include <QApplication>
|
||||
#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/USB/USBMain.hpp>
|
||||
#include <f1x/openauto/Common/Log.hpp>
|
||||
#include <f1x/aasdk/USB/USBHub.hpp>
|
||||
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
|
||||
#include <f1x/openauto/autoapp/Main.hpp>
|
||||
|
||||
namespace aasdk = f1x::aasdk;
|
||||
namespace autoapp = f1x::openauto::autoapp;
|
||||
using ThreadPool = std::vector<std::thread>;
|
||||
|
||||
void startUSBWorkers(boost::asio::io_service& ioService, libusb_context* usbContext, ThreadPool& threadPool)
|
||||
namespace f1x
|
||||
{
|
||||
auto usbWorker = [&ioService, usbContext]() {
|
||||
timeval libusbEventTimeout{180, 0};
|
||||
|
||||
while(!ioService.stopped())
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
libusb_handle_events_timeout_completed(usbContext, &libusbEventTimeout, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
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 startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threadPool)
|
||||
void Main::start()
|
||||
{
|
||||
auto ioServiceWorker = [&ioService]() {
|
||||
ioService.run();
|
||||
};
|
||||
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
app_->start();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
void Main::stop()
|
||||
{
|
||||
libusb_context* usbContext;
|
||||
if(libusb_init(&usbContext) != 0)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
||||
return 1;
|
||||
app_->stop();
|
||||
}
|
||||
|
||||
QApplication qApplication(argc, argv);
|
||||
boost::asio::io_service ioService;
|
||||
boost::asio::io_service::work work(ioService);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
aasdk::usb::USBWrapper usbWrapper(usbContext);
|
||||
autoapp::usb::USBMain main(usbWrapper, ioService, configuration);
|
||||
|
||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
|
||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
|
||||
|
||||
std::vector<std::thread> threadPool;
|
||||
startUSBWorkers(ioService, usbContext, threadPool);
|
||||
startIOServiceWorkers(ioService, threadPool);
|
||||
main.start();
|
||||
|
||||
auto result = qApplication.exec();
|
||||
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
||||
|
||||
libusb_exit(usbContext);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +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/USB/USBMain.hpp>
|
||||
|
||||
namespace f1x
|
||||
{
|
||||
namespace openauto
|
||||
{
|
||||
namespace autoapp
|
||||
{
|
||||
namespace usb
|
||||
{
|
||||
|
||||
USBMain::USBMain(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_));
|
||||
|
||||
usbApp_ = std::make_shared<autoapp::usb::USBApp>(ioService_, androidAutoEntityFactory_,
|
||||
std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
|
||||
}
|
||||
|
||||
void USBMain::start()
|
||||
{
|
||||
usbApp_->start();
|
||||
}
|
||||
|
||||
void USBMain::stop()
|
||||
{
|
||||
usbApp_->stop();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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 <thread>
|
||||
#include <QApplication>
|
||||
#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/Common/Log.hpp>
|
||||
|
||||
namespace aasdk = f1x::aasdk;
|
||||
namespace autoapp = f1x::openauto::autoapp;
|
||||
using ThreadPool = std::vector<std::thread>;
|
||||
|
||||
void startUSBWorkers(boost::asio::io_service& ioService, libusb_context* usbContext, ThreadPool& threadPool)
|
||||
{
|
||||
auto usbWorker = [&ioService, usbContext]() {
|
||||
timeval libusbEventTimeout{180, 0};
|
||||
|
||||
while(!ioService.stopped())
|
||||
{
|
||||
libusb_handle_events_timeout_completed(usbContext, &libusbEventTimeout, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
threadPool.emplace_back(usbWorker);
|
||||
}
|
||||
|
||||
void startIOServiceWorkers(boost::asio::io_service& ioService, ThreadPool& threadPool)
|
||||
{
|
||||
auto ioServiceWorker = [&ioService]() {
|
||||
ioService.run();
|
||||
};
|
||||
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
threadPool.emplace_back(ioServiceWorker);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
libusb_context* usbContext;
|
||||
if(libusb_init(&usbContext) != 0)
|
||||
{
|
||||
OPENAUTO_LOG(error) << "[OpenAuto] libusb init failed.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
QApplication qApplication(argc, argv);
|
||||
boost::asio::io_service ioService;
|
||||
boost::asio::io_service::work work(ioService);
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
aasdk::usb::USBWrapper usbWrapper(usbContext);
|
||||
autoapp::Main main(usbWrapper, ioService, configuration);
|
||||
|
||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
|
||||
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::openSettings, &settingsWindow, &autoapp::ui::SettingsWindow::showFullScreen);
|
||||
|
||||
std::vector<std::thread> threadPool;
|
||||
startUSBWorkers(ioService, usbContext, threadPool);
|
||||
startIOServiceWorkers(ioService, threadPool);
|
||||
main.start();
|
||||
|
||||
auto result = qApplication.exec();
|
||||
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));
|
||||
|
||||
libusb_exit(usbContext);
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue