[peripherals] pass the full scan result to CPeripherals::CreatePeripheral()
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 26 Feb 2013 12:05:09 +0000 (13:05 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 28 Feb 2013 19:14:30 +0000 (20:14 +0100)
xbmc/peripherals/Peripherals.cpp
xbmc/peripherals/Peripherals.h
xbmc/peripherals/bus/PeripheralBus.cpp

index 51852ad..3130a9a 100644 (file)
@@ -229,13 +229,13 @@ bool CPeripherals::HasPeripheralWithFeature(const PeripheralFeature feature, Per
   return (GetPeripheralsWithFeature(dummy, feature, busType) > 0);
 }
 
-CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralType type, const CStdString &strLocation, int iVendorId /* = 0 */, int iProductId /* = 0 */)
+CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result)
 {
   CPeripheral *peripheral = NULL;
   /* check whether there's something mapped in peripherals.xml */
-  PeripheralType mappedType = type;
+  PeripheralType mappedType = result.m_type;
   CStdString strDeviceName;
-  int iMappingPtr = GetMappingForDevice(bus, type, iVendorId, iProductId);
+  int iMappingPtr = GetMappingForDevice(bus, result.m_type, result.m_iVendorId, result.m_iProductId);
   bool bHasMapping(iMappingPtr >= 0);
   if (bHasMapping)
   {
@@ -251,33 +251,33 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
   switch(mappedType)
   {
   case PERIPHERAL_HID:
-    peripheral = new CPeripheralHID(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralHID(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_NIC:
-    peripheral = new CPeripheralNIC(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralNIC(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_DISK:
-    peripheral = new CPeripheralDisk(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralDisk(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_NYXBOARD:
-    peripheral = new CPeripheralNyxboard(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralNyxboard(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_TUNER:
-    peripheral = new CPeripheralTuner(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralTuner(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_BLUETOOTH:
-    peripheral = new CPeripheralBluetooth(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralBluetooth(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   case PERIPHERAL_CEC:
 #if defined(HAVE_LIBCEC)
     if (bus.Type() == PERIPHERAL_BUS_CEC)
-      peripheral = new CPeripheralCecAdapter(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+      peripheral = new CPeripheralCecAdapter(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
 #else
     if (!m_bMissingLibCecWarningDisplayed)
     {
@@ -289,7 +289,7 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
     break;
 
   case PERIPHERAL_IMON:
-    peripheral = new CPeripheralImon(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
+    peripheral = new CPeripheralImon(mappedType, bus.Type(), result.m_strLocation, strDeviceName, result.m_iVendorId, result.m_iProductId);
     break;
 
   default:
@@ -306,7 +306,7 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
     }
     else
     {
-      CLog::Log(LOGDEBUG, "%s - failed to initialise peripheral on '%s'", __FUNCTION__, strLocation.c_str());
+      CLog::Log(LOGDEBUG, "%s - failed to initialise peripheral on '%s'", __FUNCTION__, result.m_strLocation.c_str());
       delete peripheral;
       peripheral = NULL;
     }
index ca41a3e..c229943 100644 (file)
@@ -111,11 +111,10 @@ namespace PERIPHERALS
     /*!
      * @brief Creates a new instance of a peripheral.
      * @param bus The bus on which this peripheral is present.
-     * @param type The type of the new peripheral.
-     * @param strLocation The location on the bus.
+     * @param result The scan result from the device scanning code.
      * @return The new peripheral or NULL if it could not be created.
      */
-    CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralType type, const CStdString &strLocation, int iVendorId = 0, int iProductId = 0);
+    CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result);
 
     /*!
      * @brief Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).
index b0d3790..d9459e3 100644 (file)
@@ -170,9 +170,9 @@ void CPeripheralBus::RegisterNewDevices(const PeripheralScanResults &results)
   CSingleLock lock(m_critSection);
   for (unsigned int iResultPtr = 0; iResultPtr < results.m_results.size(); iResultPtr++)
   {
-    PeripheralScanResult result = results.m_results.at(iResultPtr);
+    const PeripheralScanResult& result = results.m_results.at(iResultPtr);
     if (!HasPeripheral(result.m_strLocation))
-      g_peripherals.CreatePeripheral(*this, result.m_type, result.m_strLocation, result.m_iVendorId, result.m_iProductId);
+      g_peripherals.CreatePeripheral(*this, result);
   }
 }