diff --git a/include/f1x/openauto/autoapp/App.hpp b/include/f1x/openauto/autoapp/App.hpp
index f31e2d5..461743d 100644
--- a/include/f1x/openauto/autoapp/App.hpp
+++ b/include/f1x/openauto/autoapp/App.hpp
@@ -38,7 +38,7 @@ public:
App(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
- void start();
+ void waitForUSBDevice();
void stop();
void onAndroidAutoQuit() override;
diff --git a/include/f1x/openauto/autoapp/Main.hpp b/include/f1x/openauto/autoapp/Main.hpp
deleted file mode 100644
index 4cb6746..0000000
--- a/include/f1x/openauto/autoapp/Main.hpp
+++ /dev/null
@@ -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 .
-*/
-
-#pragma once
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-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_;
-};
-
-}
-}
-}
diff --git a/src/autoapp/App.cpp b/src/autoapp/App.cpp
index 73a7b3d..7b00e07 100644
--- a/src/autoapp/App.cpp
+++ b/src/autoapp/App.cpp
@@ -39,7 +39,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();
diff --git a/src/autoapp/Main.cpp b/src/autoapp/Main.cpp
deleted file mode 100644
index 84ea91e..0000000
--- a/src/autoapp/Main.cpp
+++ /dev/null
@@ -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 .
-*/
-
-#include
-#include
-#include
-#include
-
-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(usbWrapper_, ioService_, queryChainFactory_));
- auto ConnectedAccessoriesEnumerator(std::make_shared(usbWrapper_, ioService_, queryChainFactory_));
-
- app_ = std::make_shared(ioService_, androidAutoEntityFactory_,
- std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
-}
-
-void Main::start()
-{
- app_->start();
-}
-
-void Main::stop()
-{
- app_->stop();
-}
-
-}
-}
-}
diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp
index 4b4b4b5..6a2e3e9 100644
--- a/src/autoapp/autoapp.cpp
+++ b/src/autoapp/autoapp.cpp
@@ -18,10 +18,18 @@
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
-#include
#include
namespace aasdk = f1x::aasdk;
@@ -66,35 +74,41 @@ 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 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::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 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(usbWrapper, ioService, configuration, serviceFactory);
+
+ auto usbHub(std::make_shared(usbWrapper, ioService, queryChainFactory));
+ auto ConnectedAccessoriesEnumerator(std::make_shared(usbWrapper, ioService, queryChainFactory));
+ auto app = std::make_shared(ioService, androidAutoEntityFactory, std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
+ app->waitForUSBDevice();
auto result = qApplication.exec();
std::for_each(threadPool.begin(), threadPool.end(), std::bind(&std::thread::join, std::placeholders::_1));