USB implementation changes
authorJustin Dickow <jjdickow@gmail.com>
Tue, 15 Jul 2014 20:05:17 +0000 (16:05 -0400)
committerJustin Dickow <jjdickow@gmail.com>
Tue, 15 Jul 2014 20:05:17 +0000 (16:05 -0400)
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
src/components/transport_manager/src/usb/libusb/platform_usb_device.cc
src/components/transport_manager/src/usb/libusb/usb_connection.cc
src/components/transport_manager/src/usb/libusb/usb_handler.cc
src/components/transport_manager/src/usb/qnx/platform_usb_device.cc
src/components/transport_manager/src/usb/qnx/usb_connection.cc
src/components/transport_manager/src/usb/qnx/usb_handler.cc
src/components/transport_manager/src/usb/usb_aoa_adapter.cc [new file with mode: 0644]
src/components/transport_manager/src/usb/usb_connection_factory.cc
src/components/transport_manager/src/usb/usb_device_scanner.cc

index 2110ac3..cb61126 100644 (file)
 #include "transport_manager/usb/libusb/platform_usb_device.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
+
 PlatformUsbDevice::PlatformUsbDevice(
     uint8_t bus_number, uint8_t address,
     const libusb_device_descriptor& device_descriptor,
index 9a1b4c8..7e98d98 100644 (file)
 
 #include <libusb/libusb.h>
 
+#include <sstream>
+
 #include "transport_manager/usb/libusb/usb_connection.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
+
 UsbConnection::UsbConnection(const DeviceUID& device_uid,
                              const ApplicationHandle& app_handle,
                              TransportAdapterController* controller,
index 88c4ee1..40c8220 100644 (file)
 #include "transport_manager/usb/common.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 class UsbHandler::ControlTransferSequenceState {
  public:
   ControlTransferSequenceState(class UsbHandler* usb_handler,
index c17c2aa..0f35a16 100644 (file)
 #include "transport_manager/usb/qnx/platform_usb_device.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 PlatformUsbDevice::PlatformUsbDevice(
     usbd_device_instance_t* instance, usbd_device* device,
     const usbd_device_descriptor_t& device_descriptor)
index dec5267..0ece01c 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <errno.h>
 #include <sched.h>
 #include <cstring>
 
 #include "transport_manager/usb/qnx/usb_connection.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 UsbConnection::UsbConnection(const DeviceUID& device_uid,
                              const ApplicationHandle& app_handle,
                              TransportAdapterController* controller,
index ccb9cd0..7ab3616 100644 (file)
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <errno.h>
+
 #include <cstring>
 #include <cstdlib>
 
 #include "transport_manager/usb/common.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 namespace {
 UsbHandler* usb_handler;
 }
diff --git a/src/components/transport_manager/src/usb/usb_aoa_adapter.cc b/src/components/transport_manager/src/usb/usb_aoa_adapter.cc
new file mode 100644 (file)
index 0000000..88487bc
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * \file usb_aoa_adapter.cpp
+ * \brief UsbAoaAdapter class source file.
+ *
+ * Copyright (c) 2013, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "transport_manager/usb/usb_aoa_adapter.h"
+#include "transport_manager/usb/usb_device_scanner.h"
+#include "transport_manager/usb/usb_connection_factory.h"
+#include "transport_manager/usb/common.h"
+
+namespace transport_manager {
+namespace transport_adapter {
+
+UsbAoaAdapter::UsbAoaAdapter()
+    : TransportAdapterImpl(new UsbDeviceScanner(this),
+                           new UsbConnectionFactory(this), 0),
+      is_initialised_(false),
+      usb_handler_(new UsbHandler()) {
+  static_cast<UsbDeviceScanner*>(device_scanner_)->SetUsbHandler(usb_handler_);
+  static_cast<UsbConnectionFactory*>(server_connection_factory_)
+      ->SetUsbHandler(usb_handler_);
+}
+
+UsbAoaAdapter::~UsbAoaAdapter() {}
+
+DeviceType UsbAoaAdapter::GetDeviceType() const { return "sdl-usb-aoa"; }
+
+bool UsbAoaAdapter::IsInitialised() const {
+  return is_initialised_ && TransportAdapterImpl::IsInitialised();
+}
+
+TransportAdapter::Error UsbAoaAdapter::Init() {
+  TransportAdapter::Error error = usb_handler_->Init();
+  if (error != TransportAdapter::OK) {
+    return error;
+  }
+  error = TransportAdapterImpl::Init();
+  if (error != TransportAdapter::OK) {
+    return error;
+  }
+  is_initialised_ = true;
+  return TransportAdapter::OK;
+}
+
+bool UsbAoaAdapter::ToBeAutoConnected(DeviceSptr device) const {
+  return true;
+}
+
+}  // namespace transport_adapter
+}  // namespace transport_manager
index 4081ac4..e382e3b 100644 (file)
@@ -1,8 +1,5 @@
-/**
- * \file usb_connection_factory.cc
- * \brief UsbConnectionFactory class source file.
- *
- * Copyright (c) 2013, Ford Motor Company
+/*
+ * Copyright (c) 2014, Ford Motor Company
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "transport_manager/usb/usb_device.h"
 #include "transport_manager/transport_adapter/transport_adapter_impl.h"
 
-#if defined(__QNX__) || defined(__QNXNTO__)
+#if defined(__QNXNTO__)
 #include "transport_manager/usb/qnx/usb_connection.h"
 #else
 #include "transport_manager/usb/libusb/usb_connection.h"
 #endif
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 UsbConnectionFactory::UsbConnectionFactory(
     TransportAdapterController* controller)
     : controller_(controller), usb_handler_() {}
@@ -68,17 +69,19 @@ TransportAdapter::Error UsbConnectionFactory::CreateConnection(
 
   UsbDevice* usb_device = static_cast<UsbDevice*>(device.get());
   UsbConnection* usb_connection =
-      new UsbConnection(device_uid, app_handle, controller_, usb_handler_,
-                        usb_device->usb_device());
+    new UsbConnection(device_uid, app_handle, controller_, usb_handler_,
+      usb_device->usb_device());
   ConnectionSptr connection(usb_connection);
 
   controller_->ConnectionCreated(connection, device_uid, app_handle);
-  if (!usb_connection->Init()) {
+
+  if (usb_connection->Init()) {
+    LOG4CXX_INFO(logger_, "USB connection initialised");
+    return TransportAdapter::OK;
+  }
+  else {
     return TransportAdapter::FAIL;
   }
-  LOG4CXX_INFO(logger_, "Usb connection initialised");
-
-  return TransportAdapter::OK;
 }
 
 void UsbConnectionFactory::Terminate() {}
index 78358d4..da25928 100644 (file)
@@ -1,8 +1,5 @@
-/**
- * \file usb_device_scanner.cc
- * \brief UsbDeviceScanner class source file.
- *
- * Copyright (c) 2013, Ford Motor Company
+/*
+ * Copyright (c) 2014, Ford Motor Company
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "transport_manager/usb/usb_device.h"
 #include "transport_manager/usb/common.h"
 
+#include "utils/logger.h"
+
 namespace transport_manager {
 namespace transport_adapter {
 
+CREATE_LOGGERPTR_GLOBAL(logger_, "TransportManager")
+
 class AoaInitSequence : public UsbControlTransferSequence {
  public:
   AoaInitSequence();
@@ -54,15 +55,16 @@ class AoaInitSequence : public UsbControlTransferSequence {
   class AoaTurnIntoAccessoryMode;
 };
 
-bool IsGoogleAccessory(uint16_t vid, uint16_t pid) {
-  return (vid == kAoaVid) && (pid == kAoaPid1 || pid == kAoaPid2);
-}
-
 void UsbDeviceScanner::OnDeviceArrived(PlatformUsbDevice* device) {
-  if (IsGoogleAccessory(device->vendor_id(), device->product_id())) {
-    GoogleAccessoryFound(device);
-  } else {
-    TurnIntoAccessoryMode(device);
+  if (IsAppleDevice(device)) {
+    SupportedDeviceFound(device);
+  }
+  else {
+    if (IsGoogleAccessory(device)) {
+      SupportedDeviceFound(device);
+    } else {
+      TurnIntoAccessoryMode(device);
+    }
   }
 }
 
@@ -160,13 +162,13 @@ void UsbDeviceScanner::TurnIntoAccessoryMode(PlatformUsbDevice* device) {
   GetUsbHandler()->StartControlTransferSequence(new AoaInitSequence, device);
 }
 
-void UsbDeviceScanner::GoogleAccessoryFound(PlatformUsbDevice* device) {
-  LOG4CXX_INFO(logger_, "Google accessory found");
+void UsbDeviceScanner::SupportedDeviceFound(PlatformUsbDevice* device) {
+  LOG4CXX_INFO(logger_, "Supported device found");
 
   pthread_mutex_lock(&devices_mutex_);
   devices_.push_back(device);
   pthread_mutex_unlock(&devices_mutex_);
-  LOG4CXX_INFO(logger_, "Google accessory (bus number "
+  LOG4CXX_INFO(logger_, "USB device (bus number "
                             << static_cast<int>(device->bus_number())
                             << ", address "
                             << static_cast<int>(device->address())