Enumerate connected devices with AOAP capabilities
This commit is contained in:
parent
3c1e65792f
commit
28cff9c53b
@ -19,6 +19,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <f1x/aasdk/USB/IUSBHub.hpp>
|
#include <f1x/aasdk/USB/IUSBHub.hpp>
|
||||||
|
#include <f1x/aasdk/USB/IConnectedAccessoriesEnumerator.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp>
|
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityEventHandler.hpp>
|
||||||
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp>
|
#include <f1x/openauto/autoapp/Projection/IAndroidAutoEntityFactory.hpp>
|
||||||
|
|
||||||
@ -36,7 +37,8 @@ class USBApp: public projection::IAndroidAutoEntityEventHandler, public std::ena
|
|||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<USBApp> Pointer;
|
typedef std::shared_ptr<USBApp> Pointer;
|
||||||
|
|
||||||
USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub);
|
USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||||
|
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
@ -45,6 +47,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
using std::enable_shared_from_this<USBApp>::shared_from_this;
|
using std::enable_shared_from_this<USBApp>::shared_from_this;
|
||||||
|
|
||||||
|
void enumerateDevices();
|
||||||
void waitForDevice();
|
void waitForDevice();
|
||||||
void aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle);
|
void aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle);
|
||||||
void onUSBHubError(const aasdk::error::Error& error);
|
void onUSBHubError(const aasdk::error::Error& error);
|
||||||
@ -53,6 +56,7 @@ private:
|
|||||||
boost::asio::io_service::strand strand_;
|
boost::asio::io_service::strand strand_;
|
||||||
projection::IAndroidAutoEntityFactory& androidAutoEntityFactory_;
|
projection::IAndroidAutoEntityFactory& androidAutoEntityFactory_;
|
||||||
aasdk::usb::IUSBHub::Pointer usbHub_;
|
aasdk::usb::IUSBHub::Pointer usbHub_;
|
||||||
|
aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator_;
|
||||||
projection::IAndroidAutoEntity::Pointer androidAutoEntity_;
|
projection::IAndroidAutoEntity::Pointer androidAutoEntity_;
|
||||||
bool isStopped_;
|
bool isStopped_;
|
||||||
};
|
};
|
||||||
|
@ -29,11 +29,13 @@ namespace autoapp
|
|||||||
namespace usb
|
namespace usb
|
||||||
{
|
{
|
||||||
|
|
||||||
USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory, aasdk::usb::IUSBHub::Pointer usbHub)
|
USBApp::USBApp(boost::asio::io_service& ioService, projection::IAndroidAutoEntityFactory& androidAutoEntityFactory,
|
||||||
|
aasdk::usb::IUSBHub::Pointer usbHub, aasdk::usb::IConnectedAccessoriesEnumerator::Pointer connectedAccessoriesEnumerator)
|
||||||
: ioService_(ioService)
|
: ioService_(ioService)
|
||||||
, strand_(ioService_)
|
, strand_(ioService_)
|
||||||
, androidAutoEntityFactory_(androidAutoEntityFactory)
|
, androidAutoEntityFactory_(androidAutoEntityFactory)
|
||||||
, usbHub_(std::move(usbHub))
|
, usbHub_(std::move(usbHub))
|
||||||
|
, connectedAccessoriesEnumerator_(std::move(connectedAccessoriesEnumerator))
|
||||||
, isStopped_(false)
|
, isStopped_(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -43,6 +45,7 @@ void USBApp::start()
|
|||||||
{
|
{
|
||||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||||
this->waitForDevice();
|
this->waitForDevice();
|
||||||
|
this->enumerateDevices();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +87,19 @@ void USBApp::aoapDeviceHandler(aasdk::usb::DeviceHandle deviceHandle)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USBApp::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;
|
||||||
|
},
|
||||||
|
[this, self = this->shared_from_this()](auto e) {
|
||||||
|
OPENAUTO_LOG(error) << "[USBApp] Devices enumeration failed: " << e.what();
|
||||||
|
});
|
||||||
|
|
||||||
|
connectedAccessoriesEnumerator_->enumerate(std::move(promise));
|
||||||
|
}
|
||||||
|
|
||||||
void USBApp::waitForDevice()
|
void USBApp::waitForDevice()
|
||||||
{
|
{
|
||||||
OPENAUTO_LOG(info) << "[USBApp] Waiting for device...";
|
OPENAUTO_LOG(info) << "[USBApp] Waiting for device...";
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <f1x/aasdk/USB/USBHub.hpp>
|
#include <f1x/aasdk/USB/USBHub.hpp>
|
||||||
|
#include <f1x/aasdk/USB/ConnectedAccessoriesEnumerator.hpp>
|
||||||
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
|
||||||
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
|
#include <f1x/openauto/autoapp/UI/MainWindow.hpp>
|
||||||
#include <f1x/openauto/autoapp/UI/SettingsWindow.hpp>
|
#include <f1x/openauto/autoapp/UI/SettingsWindow.hpp>
|
||||||
@ -42,8 +43,11 @@ USBMain::USBMain(libusb_context* context)
|
|||||||
, serviceFactory_(ioService_, configuration_)
|
, serviceFactory_(ioService_, configuration_)
|
||||||
, androidAutoEntityFactory_(usbWrapper_, ioService_, configuration_, serviceFactory_)
|
, androidAutoEntityFactory_(usbWrapper_, ioService_, configuration_, serviceFactory_)
|
||||||
{
|
{
|
||||||
aasdk::usb::IUSBHub::Pointer usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper_, ioService_, queryChainFactory_));
|
auto usbHub(std::make_shared<aasdk::usb::USBHub>(usbWrapper_, ioService_, queryChainFactory_));
|
||||||
usbApp_ = std::make_shared<autoapp::usb::USBApp>(ioService_, androidAutoEntityFactory_, std::move(usbHub));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
int USBMain::exec(int argc, char* argv[])
|
int USBMain::exec(int argc, char* argv[])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user