mirror of https://github.com/f1xpl/openauto.git
Implement creating of tcp AA entity
parent
21ff97fe8a
commit
2ecdd83e76
|
@ -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 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_;
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
@ -47,6 +51,35 @@ void App::waitForUSBDevice()
|
|||
});
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
OPENAUTO_LOG(warning) << "[App] android auto entity is still running.";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void App::stop()
|
||||
{
|
||||
strand_.dispatch([this, self = this->shared_from_this()]() {
|
||||
|
@ -69,12 +102,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 +164,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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#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/Projection/AndroidAutoEntityFactory.hpp>
|
||||
|
@ -99,15 +100,16 @@ int main(int argc, char* argv[])
|
|||
|
||||
mainWindow.showFullScreen();
|
||||
|
||||
aasdk::tcp::TCPWrapper tcpWrapper;
|
||||
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);
|
||||
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, androidAutoEntityFactory, std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
|
||||
auto app = std::make_shared<autoapp::App>(ioService, usbWrapper, tcpWrapper, androidAutoEntityFactory, std::move(usbHub), std::move(ConnectedAccessoriesEnumerator));
|
||||
app->waitForUSBDevice();
|
||||
|
||||
auto result = qApplication.exec();
|
||||
|
|
Loading…
Reference in New Issue