Skip to content
This repository
Browse code

Merge pull request #1794 from opdenkamp/cecdevscan

[cec] get the CEC devices that are connected to the system from libCEC
  • Loading branch information...
commit 5731da5a7eb0ce6e40d9b2ed6ca0642142b39bb3 2 parents f65e61c + 1bcf7ba
Lars Op den Kamp authored March 01, 2013

Showing 39 changed files with 363 additions and 326 deletions. Show diff stats Hide diff stats

  1. 14  XBMC.xcodeproj/project.pbxproj
  2. 40  configure.in
  3. 2  project/BuildDependencies/scripts/libcec_d.txt
  4. 2  project/VS2010Express/XBMC.vcxproj
  5. 6  project/VS2010Express/XBMC.vcxproj.filters
  6. 25  system/peripherals.xml
  7. 4  tools/android/depends/libcec/Makefile
  8. 2  tools/darwin/depends/libcec/Makefile
  9. 76  xbmc/peripherals/PeripheralTypes.h
  10. 62  xbmc/peripherals/Peripherals.cpp
  11. 7  xbmc/peripherals/Peripherals.h
  12. 4  xbmc/peripherals/bus/Makefile.in
  13. 81  xbmc/peripherals/bus/PeripheralBus.cpp
  14. 23  xbmc/peripherals/bus/PeripheralBus.h
  15. 69  xbmc/peripherals/bus/linux/PeripheralBusRPi.cpp
  16. 3  xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp
  17. 4  xbmc/peripherals/bus/linux/PeripheralBusUSBLibUdev.cpp
  18. 1  xbmc/peripherals/bus/osx/PeripheralBusUSB.cpp
  19. 116  xbmc/peripherals/bus/virtual/PeripheralBusCEC.cpp
  20. 25  xbmc/peripherals/bus/{linux/PeripheralBusRPi.h → virtual/PeripheralBusCEC.h}
  21. 5  xbmc/peripherals/bus/win32/PeripheralBusUSB.cpp
  22. 54  xbmc/peripherals/devices/Peripheral.cpp
  23. 6  xbmc/peripherals/devices/Peripheral.h
  24. 4  xbmc/peripherals/devices/PeripheralBluetooth.cpp
  25. 2  xbmc/peripherals/devices/PeripheralBluetooth.h
  26. 11  xbmc/peripherals/devices/PeripheralCecAdapter.cpp
  27. 2  xbmc/peripherals/devices/PeripheralCecAdapter.h
  28. 5  xbmc/peripherals/devices/PeripheralDisk.cpp
  29. 2  xbmc/peripherals/devices/PeripheralDisk.h
  30. 5  xbmc/peripherals/devices/PeripheralHID.cpp
  31. 2  xbmc/peripherals/devices/PeripheralHID.h
  32. 4  xbmc/peripherals/devices/PeripheralImon.cpp
  33. 2  xbmc/peripherals/devices/PeripheralImon.h
  34. 5  xbmc/peripherals/devices/PeripheralNIC.cpp
  35. 2  xbmc/peripherals/devices/PeripheralNIC.h
  36. 4  xbmc/peripherals/devices/PeripheralNyxboard.cpp
  37. 2  xbmc/peripherals/devices/PeripheralNyxboard.h
  38. 4  xbmc/peripherals/devices/PeripheralTuner.cpp
  39. 2  xbmc/peripherals/devices/PeripheralTuner.h
14  XBMC.xcodeproj/project.pbxproj
@@ -173,6 +173,7 @@
173 173
 		18E7CACB1578C26D001D4554 /* CDDARipJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18E7CAC91578C26D001D4554 /* CDDARipJob.cpp */; };
174 174
 		18ECC96213CF178D00A9ED6C /* StreamUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18ECC96013CF178D00A9ED6C /* StreamUtils.cpp */; };
175 175
 		1D638128161E211E003603ED /* PeripheralImon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1D638126161E211E003603ED /* PeripheralImon.cpp */; };
  176
+		1DAFDB7C16DFDCA7007F8C68 /* PeripheralBusCEC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1DAFDB7A16DFDCA7007F8C68 /* PeripheralBusCEC.cpp */; };
176 177
 		1DE0443515828F4B005DDB4D /* Exception.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1DE0443315828F4B005DDB4D /* Exception.cpp */; };
177 178
 		32C631281423A90F00F18420 /* JpegIO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32C631261423A90F00F18420 /* JpegIO.cpp */; };
178 179
 		36A9443D15821E2800727135 /* DatabaseUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36A9443B15821E2800727135 /* DatabaseUtils.cpp */; };
@@ -1384,6 +1385,8 @@
1384 1385
 		18ECC96113CF178D00A9ED6C /* StreamUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamUtils.h; sourceTree = "<group>"; };
1385 1386
 		1D638126161E211E003603ED /* PeripheralImon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PeripheralImon.cpp; sourceTree = "<group>"; };
1386 1387
 		1D638127161E211E003603ED /* PeripheralImon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeripheralImon.h; sourceTree = "<group>"; };
  1388
+		1DAFDB7A16DFDCA7007F8C68 /* PeripheralBusCEC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PeripheralBusCEC.cpp; sourceTree = "<group>"; };
  1389
+		1DAFDB7B16DFDCA7007F8C68 /* PeripheralBusCEC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeripheralBusCEC.h; sourceTree = "<group>"; };
1387 1390
 		1DE0443315828F4B005DDB4D /* Exception.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Exception.cpp; path = commons/Exception.cpp; sourceTree = "<group>"; };
1388 1391
 		1DE0443415828F4B005DDB4D /* Exception.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Exception.h; path = commons/Exception.h; sourceTree = "<group>"; };
1389 1392
 		32C631261423A90F00F18420 /* JpegIO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JpegIO.cpp; sourceTree = "<group>"; };
@@ -3743,6 +3746,15 @@
3743 3746
 			name = Products;
3744 3747
 			sourceTree = "<group>";
3745 3748
 		};
  3749
+		1DAFDB7916DFDCA7007F8C68 /* virtual */ = {
  3750
+			isa = PBXGroup;
  3751
+			children = (
  3752
+				1DAFDB7A16DFDCA7007F8C68 /* PeripheralBusCEC.cpp */,
  3753
+				1DAFDB7B16DFDCA7007F8C68 /* PeripheralBusCEC.h */,
  3754
+			);
  3755
+			path = virtual;
  3756
+			sourceTree = "<group>";
  3757
+		};
3746 3758
 		38F4E56013CCCB3B00664821 /* platform */ = {
3747 3759
 			isa = PBXGroup;
3748 3760
 			children = (
@@ -6391,6 +6403,7 @@
6391 6403
 		F5E1050D140AA38000175026 /* bus */ = {
6392 6404
 			isa = PBXGroup;
6393 6405
 			children = (
  6406
+				1DAFDB7916DFDCA7007F8C68 /* virtual */,
6394 6407
 				F5E10512140AA38000175026 /* osx */,
6395 6408
 				F5E10515140AA38000175026 /* PeripheralBus.cpp */,
6396 6409
 				F5E10516140AA38000175026 /* PeripheralBus.h */,
@@ -7746,6 +7759,7 @@
7746 7759
 				DF404A3A16B9896C00D8023E /* imagefactory.cpp in Sources */,
7747 7760
 				DFD5812516C828500008EEA0 /* DAVCommon.cpp in Sources */,
7748 7761
 				DFD5812616C828500008EEA0 /* DAVFile.cpp in Sources */,
  7762
+				1DAFDB7C16DFDCA7007F8C68 /* PeripheralBusCEC.cpp in Sources */,
7749 7763
 			);
7750 7764
 			runOnlyForDeploymentPostprocessing = 0;
7751 7765
 		};
40  configure.in
@@ -159,8 +159,6 @@ libusb_disabled="== libusb disabled. Plug and play USB device support will not b
159 159
 libusb_disabled_udev_found="== libusb disabled. =="
160 160
 libcec_enabled="== libcec enabled. =="
161 161
 libcec_disabled="== libcec disabled. CEC adapter support will not be available. =="
162  
-libcec_disabled_missing_libs="== libcec disabled because it either needs libudev, or libusb a compatible version of the RPi API. CEC adapter support will not be available. =="
163  
-cec_rpi_api_missing="== no compatible RPi API found =="
164 162
 
165 163
 # External library message strings
166 164
 external_libraries_enabled="== Use of all supported external libraries enabled. =="
@@ -1497,46 +1495,18 @@ fi
1497 1495
 
1498 1496
 # libcec
1499 1497
 USE_LIBCEC=0
1500  
-USE_CEC_RPI_API=0
1501  
-use_rpi_cec_api="auto"
1502 1498
 if test "x$use_libcec" != "xno"; then
1503  
-  case "${host_cpu}" in
1504  
-    arm*)
1505  
-      echo "will check for RPi support"
1506  
-      AC_CHECK_HEADER(interface/vmcs_host/vc_cec.h,,use_rpi_cec_api="no")
1507  
-      ;;
1508  
-    *)
1509  
-      echo "will not check for RPi support (unsupported cpu: ${host_cpu})"
1510  
-      use_rpi_cec_api="no"
1511  
-      ;;
1512  
-  esac
1513  
-
1514  
-  # libcec needs libudev, libusb or the RPi API under linux, or the device will never be detected.
1515  
-  if test "$host_vendor" != "apple" && test "$use_libusb" = "no" && test "$use_libudev" = "no" && test "$use_rpi_cec_api" = "no"; then
1516  
-    if test "x$use_libcec" != "xauto"; then
1517  
-      AC_MSG_ERROR($libcec_disabled_missing_libs)
1518  
-    else
1519  
-      use_libcec="no"
1520  
-      AC_MSG_NOTICE($libcec_disabled_missing_libs)
1521  
-    fi
1522  
-  fi
1523  
-
1524 1499
   # libcec is dyloaded, so we need to check for its headers and link any depends.
1525 1500
   if test "x$use_libcec" != "xno"; then
1526 1501
     if test "x$use_libcec" != "xauto"; then
1527  
-      PKG_CHECK_MODULES([CEC],[libcec >= 2.0.0],,[use_libcec="no";AC_MSG_ERROR($libcec_disabled)])
  1502
+      PKG_CHECK_MODULES([CEC],[libcec >= 2.1.0],,[use_libcec="no";AC_MSG_ERROR($libcec_disabled)])
1528 1503
     else
1529  
-      PKG_CHECK_MODULES([CEC],[libcec >= 2.0.0],,[use_libcec="no";AC_MSG_RESULT($libcec_disabled)])
  1504
+      PKG_CHECK_MODULES([CEC],[libcec >= 2.1.0],,[use_libcec="no";AC_MSG_RESULT($libcec_disabled)])
1530 1505
     fi
1531 1506
 
1532 1507
     if test "x$use_libcec" != "xno"; then
1533 1508
       INCLUDES="$INCLUDES $CEC_CFLAGS"
1534 1509
       USE_LIBCEC=1;AC_DEFINE([HAVE_LIBCEC],[1],["Define to 1 if libcec is installed"])
1535  
-      if test "x$use_rpi_cec_api" != "xno"; then
1536  
-        LIBS+=" -lvcos -lvchiq_arm"
1537  
-        AC_DEFINE([HAVE_CEC_RPI_API],[1],["Define to 1 if the CEC RPi API is installed"])
1538  
-        USE_CEC_RPI_API=1
1539  
-      fi
1540 1510
       XB_FIND_SONAME([LIBCEC],[cec],[use_libcec])
1541 1511
       AC_MSG_NOTICE($libcec_enabled)
1542 1512
     else
@@ -2289,11 +2259,6 @@ fi
2289 2259
 
2290 2260
 if test "x$use_libcec" != "xno"; then
2291 2261
   final_message="$final_message\n  libcec support:\tYes"
2292  
-  if test "x$use_rpi_cec_api" != "xno"; then
2293  
-    final_message="$final_message\n  libcec RPi support:\tYes"
2294  
-  else
2295  
-    final_message="$final_message\n  libcec RPi support:\tNo"
2296  
-  fi
2297 2262
 else
2298 2263
   final_message="$final_message\n  libcec support:\tNo"
2299 2264
 fi
@@ -2487,7 +2452,6 @@ AC_SUBST(USE_AIRTUNES)
2487 2452
 AC_SUBST(USE_LIBUDEV)
2488 2453
 AC_SUBST(USE_LIBUSB)
2489 2454
 AC_SUBST(USE_LIBCEC)
2490  
-AC_SUBST(USE_CEC_RPI_API)
2491 2455
 AC_SUBST(USE_MYSQL)
2492 2456
 AC_SUBST(USE_WEB_SERVER)
2493 2457
 AC_SUBST(USE_UPNP)
2  project/BuildDependencies/scripts/libcec_d.txt
... ...
@@ -1,3 +1,3 @@
1 1
 ; filename                        source of the file
2 2
 
3  
-libcec-2.0.5.zip                  http://mirrors.xbmc.org/build-deps/win32/
  3
+libcec-2.1.0.zip                  http://mirrors.xbmc.org/build-deps/win32/
2  project/VS2010Express/XBMC.vcxproj
@@ -860,6 +860,7 @@
860 860
     <ClCompile Include="..\..\xbmc\PartyModeManager.cpp" />
861 861
     <ClCompile Include="..\..\xbmc\PasswordManager.cpp" />
862 862
     <ClCompile Include="..\..\xbmc\peripherals\bus\PeripheralBus.cpp" />
  863
+    <ClCompile Include="..\..\xbmc\peripherals\bus\virtual\PeripheralBusCEC.cpp" />
863 864
     <ClCompile Include="..\..\xbmc\peripherals\bus\win32\PeripheralBusUSB.cpp" />
864 865
     <ClCompile Include="..\..\xbmc\peripherals\devices\Peripheral.cpp" />
865 866
     <ClCompile Include="..\..\xbmc\peripherals\devices\PeripheralBluetooth.cpp" />
@@ -1090,6 +1091,7 @@
1090 1091
     <ClInclude Include="..\..\xbmc\interfaces\python\PyContext.h" />
1091 1092
     <ClInclude Include="..\..\xbmc\interfaces\python\pythreadstate.h" />
1092 1093
     <ClInclude Include="..\..\xbmc\music\karaoke\karaokevideobackground.h" />
  1094
+    <ClInclude Include="..\..\xbmc\peripherals\bus\virtual\PeripheralBusCEC.h" />
1093 1095
     <ClInclude Include="..\..\xbmc\video\FFmpegVideoDecoder.h" />
1094 1096
     <ClInclude Include="..\..\xbmc\interfaces\python\swig.h" />
1095 1097
     <ClInclude Include="..\..\xbmc\interfaces\python\XBPython.h" />
6  project/VS2010Express/XBMC.vcxproj.filters
@@ -2981,6 +2981,9 @@
2981 2981
     <ClCompile Include="..\..\xbmc\filesystem\DAVCommon.cpp">
2982 2982
       <Filter>filesystem</Filter>
2983 2983
     </ClCompile>
  2984
+    <ClCompile Include="..\..\xbmc\peripherals\bus\virtual\PeripheralBusCEC.cpp">
  2985
+      <Filter>peripherals\bus</Filter>
  2986
+    </ClCompile>
2984 2987
   </ItemGroup>
2985 2988
   <ItemGroup>
2986 2989
     <ClInclude Include="..\..\xbmc\win32\pch.h">
@@ -5827,6 +5830,9 @@
5827 5830
     <ClInclude Include="..\..\xbmc\filesystem\DAVCommon.h">
5828 5831
       <Filter>filesystem</Filter>
5829 5832
     </ClInclude>
  5833
+    <ClInclude Include="..\..\xbmc\peripherals\bus\virtual\PeripheralBusCEC.h">
  5834
+      <Filter>peripherals\bus</Filter>
  5835
+    </ClInclude>
5830 5836
   </ItemGroup>
5831 5837
   <ItemGroup>
5832 5838
     <ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
25  system/peripherals.xml
@@ -7,30 +7,7 @@
7 7
     <setting key="flip_remote" value="Dialog.Close(virtualkeyboard)" label="36003" order="4" />
8 8
   </peripheral>
9 9
 
10  
-  <peripheral vendor_product="2708:1001" bus="rpi" name="Raspberry Pi CEC Adapter" mapTo="cec">
11  
-    <setting key="enabled" type="bool" value="1" label="305" order="1" />
12  
-    <setting key="activate_source" type="bool" value="1" label="36020" order="2" />
13  
-    <setting key="wake_devices" type="enum" value="36037" label="36007" lvalues="36037|36038|36039|231" order="3" />
14  
-    <setting key="standby_devices" type="enum" value="36037" label="36008" lvalues="36037|36038|36039|231" order="4" />
15  
-    <setting key="send_inactive_source" type="bool" value="1" label="36025" order="5" />
16  
-    <setting key="cec_standby_screensaver" type="bool" value="0" label="36009" order="7" />
17  
-    <setting key="standby_pc_on_tv_standby" type="enum" value="13011" label="36029" order="7" lvalues="36028|13005|13011" />
18  
-    <setting key="standby_tv_on_pc_standby" type="bool" value="1" label="36026" order="8" />
19  
-    <setting key="use_tv_menu_language" type="bool" value="1" label="36018" order="9" />
20  
-    <setting key="physical_address" type="string" label="36021" value="0" order="10" />
21  
-
22  
-    <setting key="tv_vendor" type="int" value="0" configurable="0" />
23  
-    <setting key="device_name" type="string" value="XBMC" configurable="0" />
24  
-    <setting key="device_type" type="int" value="1" configurable="0" />
25  
-    <setting key="cec_hdmi_port" type="int" value="1" label="36015" configurable="0" />
26  
-    <setting key="connected_device" type="int" label="36019" value="0" configurable="0" />
27  
-    <setting key="port" type="string" value="" label="36022" configurable="0" />
28  
-    <setting key="wake_devices_advanced" type="string" value="" configurable="0" />
29  
-    <setting key="standby_devices_advanced" type="string" value="" configurable="0" />
30  
-    <setting key="double_tap_timeout_ms" type="int" min="0" value="2000" configurable="0" />
31  
-  </peripheral>
32  
-
33  
-  <peripheral vendor_product="2548:1001,2548:1002" bus="usb" name="Pulse-Eight CEC Adapter" mapTo="cec">
  10
+  <peripheral bus="cec" name="CEC Adapter" mapTo="cec">
34 11
     <setting key="enabled" type="bool" value="1" label="305" order="1" />
35 12
     <setting key="activate_source" type="bool" value="1" label="36020" order="2" />
36 13
     <setting key="wake_devices" type="enum" value="36037" label="36007" lvalues="36037|36038|36039|231" order="3" />
4  tools/android/depends/libcec/Makefile
@@ -3,7 +3,7 @@ DEPS= ../Makefile.include Makefile
3 3
 
4 4
 # lib name, version
5 5
 LIBNAME=libcec
6  
-VERSION=2.0.5-3
  6
+VERSION=2.1.0
7 7
 SOURCE=$(LIBNAME)-$(VERSION)
8 8
 ARCHIVE=$(SOURCE).tar.gz
9 9
 
@@ -11,7 +11,7 @@ ARCHIVE=$(SOURCE).tar.gz
11 11
 CONFIGURE=./configure --prefix=$(PREFIX) --host=$(HOST) \
12 12
           ac_cv_search_dlopen=yes
13 13
 
14  
-LIBDYLIB=$(PLATFORM)/src/lib/.libs/libcec.so.2.0.0
  14
+LIBDYLIB=$(PLATFORM)/src/lib/.libs/libcec.so.2.0.1
15 15
 
16 16
 all: .installed-$(PLATFORM)
17 17
 
2  tools/darwin/depends/libcec/Makefile
@@ -3,7 +3,7 @@ include ../config.site.mk
3 3
 
4 4
 # lib name, version
5 5
 LIBNAME=libcec
6  
-VERSION=2.0.5-3
  6
+VERSION=2.1.0
7 7
 SOURCE=$(LIBNAME)-$(VERSION)
8 8
 ARCHIVE=$(SOURCE).tar.gz
9 9
 
76  xbmc/peripherals/PeripheralTypes.h
@@ -35,7 +35,8 @@ namespace PERIPHERALS
35 35
     PERIPHERAL_BUS_UNKNOWN = 0,
36 36
     PERIPHERAL_BUS_USB,
37 37
     PERIPHERAL_BUS_PCI,
38  
-    PERIPHERAL_BUS_RPI
  38
+    PERIPHERAL_BUS_RPI,
  39
+    PERIPHERAL_BUS_CEC
39 40
   };
40 41
 
41 42
   enum PeripheralFeature
@@ -143,6 +144,8 @@ namespace PERIPHERALS
143 144
         return "pci";
144 145
       case PERIPHERAL_BUS_RPI:
145 146
         return "rpi";
  147
+      case PERIPHERAL_BUS_CEC:
  148
+        return "cec";
146 149
       default:
147 150
         return "unknown";
148 151
       }
@@ -159,6 +162,8 @@ namespace PERIPHERALS
159 162
         return PERIPHERAL_BUS_PCI;
160 163
       else if (strTypeLowerCase.Equals("rpi"))
161 164
         return PERIPHERAL_BUS_RPI;
  165
+      else if (strTypeLowerCase.Equals("cec"))
  166
+        return PERIPHERAL_BUS_CEC;
162 167
 
163 168
       return PERIPHERAL_BUS_UNKNOWN;
164 169
     };
@@ -180,4 +185,73 @@ namespace PERIPHERALS
180 185
       strHexString.Format("%04X", iVal);
181 186
     };
182 187
   };
  188
+
  189
+  class PeripheralScanResult
  190
+  {
  191
+  public:
  192
+    PeripheralScanResult(const PeripheralBusType busType) :
  193
+      m_type(PERIPHERAL_UNKNOWN),
  194
+      m_iVendorId(0),
  195
+      m_iProductId(0),
  196
+      m_mappedType(PERIPHERAL_UNKNOWN),
  197
+      m_busType(busType),
  198
+      m_mappedBusType(busType),
  199
+      m_iSequence(0) {}
  200
+
  201
+    PeripheralScanResult(void) :
  202
+      m_type(PERIPHERAL_UNKNOWN),
  203
+      m_iVendorId(0),
  204
+      m_iProductId(0),
  205
+      m_mappedType(PERIPHERAL_UNKNOWN),
  206
+      m_busType(PERIPHERAL_BUS_UNKNOWN),
  207
+      m_mappedBusType(PERIPHERAL_BUS_UNKNOWN),
  208
+      m_iSequence(0) {}
  209
+
  210
+    bool operator ==(const PeripheralScanResult& right) const
  211
+    {
  212
+      return m_iVendorId  == right.m_iVendorId &&
  213
+             m_iProductId == right.m_iProductId &&
  214
+             m_type       == right.m_type &&
  215
+             m_busType    == right.m_busType &&
  216
+             m_strLocation.Equals(right.m_strLocation);
  217
+    }
  218
+
  219
+    bool operator !=(const PeripheralScanResult& right) const
  220
+    {
  221
+      return !(*this == right);
  222
+    }
  223
+
  224
+    PeripheralType    m_type;
  225
+    CStdString        m_strLocation;
  226
+    int               m_iVendorId;
  227
+    int               m_iProductId;
  228
+    PeripheralType    m_mappedType;
  229
+    CStdString        m_strDeviceName;
  230
+    PeripheralBusType m_busType;
  231
+    PeripheralBusType m_mappedBusType;
  232
+    unsigned int      m_iSequence; // when more than one adapter of the same type is found
  233
+  };
  234
+
  235
+  struct PeripheralScanResults
  236
+  {
  237
+    bool GetDeviceOnLocation(const CStdString& strLocation, PeripheralScanResult* result) const
  238
+    {
  239
+      for (std::vector<PeripheralScanResult>::const_iterator it = m_results.begin(); it != m_results.end(); it++)
  240
+      {
  241
+        if ((*it).m_strLocation == strLocation)
  242
+        {
  243
+          *result = *it;
  244
+          return true;
  245
+        }
  246
+      }
  247
+      return false;
  248
+    }
  249
+
  250
+    bool ContainsResult(const PeripheralScanResult& result) const
  251
+    {
  252
+      return std::find(m_results.begin(), m_results.end(), result) != m_results.end();
  253
+    }
  254
+
  255
+    std::vector<PeripheralScanResult> m_results;
  256
+  };
183 257
 }
62  xbmc/peripherals/Peripherals.cpp
@@ -31,8 +31,8 @@
31 31
 #include "bus/PeripheralBusUSB.h"
32 32
 #include "dialogs/GUIDialogPeripheralManager.h"
33 33
 
34  
-#ifdef HAVE_CEC_RPI_API
35  
-#include "bus/linux/PeripheralBusRPi.h"
  34
+#if defined(HAVE_LIBCEC)
  35
+#include "bus/virtual/PeripheralBusCEC.h"
36 36
 #endif
37 37
 
38 38
 #include "threads/SingleLock.h"
@@ -84,8 +84,8 @@ void CPeripherals::Initialise(void)
84 84
 #if defined(HAVE_PERIPHERAL_BUS_USB)
85 85
     m_busses.push_back(new CPeripheralBusUSB(this));
86 86
 #endif
87  
-#ifdef HAVE_CEC_RPI_API
88  
-    m_busses.push_back(new CPeripheralBusRPi(this));
  87
+#if defined(HAVE_LIBCEC)
  88
+    m_busses.push_back(new CPeripheralBusCEC(this));
89 89
 #endif
90 90
 
91 91
     /* initialise all known busses */
@@ -229,54 +229,50 @@ bool CPeripherals::HasPeripheralWithFeature(const PeripheralFeature feature, Per
229 229
   return (GetPeripheralsWithFeature(dummy, feature, busType) > 0);
230 230
 }
231 231
 
232  
-CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralType type, const CStdString &strLocation, int iVendorId /* = 0 */, int iProductId /* = 0 */)
  232
+CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result)
233 233
 {
234 234
   CPeripheral *peripheral = NULL;
  235
+  PeripheralScanResult mappedResult = result;
  236
+  if (mappedResult.m_busType == PERIPHERAL_BUS_UNKNOWN)
  237
+    mappedResult.m_busType = bus.Type();
  238
+
235 239
   /* check whether there's something mapped in peripherals.xml */
236  
-  PeripheralType mappedType = type;
237  
-  CStdString strDeviceName;
238  
-  int iMappingPtr = GetMappingForDevice(bus, type, iVendorId, iProductId);
239  
-  bool bHasMapping(iMappingPtr >= 0);
240  
-  if (bHasMapping)
241  
-  {
242  
-    mappedType    = m_mappings[iMappingPtr].m_mappedTo;
243  
-    strDeviceName = m_mappings[iMappingPtr].m_strDeviceName;
244  
-  }
245  
-  else
  240
+  if (!GetMappingForDevice(bus, mappedResult))
246 241
   {
247 242
     /* don't create instances for devices that aren't mapped in peripherals.xml */
248 243
     return NULL;
249 244
   }
250 245
 
251  
-  switch(mappedType)
  246
+  switch(mappedResult.m_mappedType)
252 247
   {
253 248
   case PERIPHERAL_HID:
254  
-    peripheral = new CPeripheralHID(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  249
+    peripheral = new CPeripheralHID(mappedResult);
255 250
     break;
256 251
 
257 252
   case PERIPHERAL_NIC:
258  
-    peripheral = new CPeripheralNIC(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  253
+    peripheral = new CPeripheralNIC(mappedResult);
259 254
     break;
260 255
 
261 256
   case PERIPHERAL_DISK:
262  
-    peripheral = new CPeripheralDisk(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  257
+    peripheral = new CPeripheralDisk(mappedResult);
263 258
     break;
264 259
 
265 260
   case PERIPHERAL_NYXBOARD:
266  
-    peripheral = new CPeripheralNyxboard(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  261
+    peripheral = new CPeripheralNyxboard(mappedResult);
267 262
     break;
268 263
 
269 264
   case PERIPHERAL_TUNER:
270  
-    peripheral = new CPeripheralTuner(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  265
+    peripheral = new CPeripheralTuner(mappedResult);
271 266
     break;
272 267
 
273 268
   case PERIPHERAL_BLUETOOTH:
274  
-    peripheral = new CPeripheralBluetooth(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  269
+    peripheral = new CPeripheralBluetooth(mappedResult);
275 270
     break;
276 271
 
277 272
   case PERIPHERAL_CEC:
278 273
 #if defined(HAVE_LIBCEC)
279  
-    peripheral = new CPeripheralCecAdapter(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  274
+    if (bus.Type() == PERIPHERAL_BUS_CEC)
  275
+      peripheral = new CPeripheralCecAdapter(mappedResult);
280 276
 #else
281 277
     if (!m_bMissingLibCecWarningDisplayed)
282 278
     {
@@ -288,7 +284,7 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
288 284
     break;
289 285
 
290 286
   case PERIPHERAL_IMON:
291  
-    peripheral = new CPeripheralImon(type, bus.Type(), strLocation, strDeviceName, iVendorId, iProductId);
  287
+    peripheral = new CPeripheralImon(mappedResult);
292 288
     break;
293 289
 
294 290
   default:
@@ -305,7 +301,7 @@ CPeripheral *CPeripherals::CreatePeripheral(CPeripheralBus &bus, const Periphera
305 301
     }
306 302
     else
307 303
     {
308  
-      CLog::Log(LOGDEBUG, "%s - failed to initialise peripheral on '%s'", __FUNCTION__, strLocation.c_str());
  304
+      CLog::Log(LOGDEBUG, "%s - failed to initialise peripheral on '%s'", __FUNCTION__, mappedResult.m_strLocation.c_str());
309 305
       delete peripheral;
310 306
       peripheral = NULL;
311 307
     }
@@ -340,7 +336,7 @@ void CPeripherals::OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral
340 336
   CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Info, g_localizeStrings.Get(35006), peripheral.DeviceName());
341 337
 }
342 338
 
343  
-int CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, const PeripheralType classType, int iVendorId, int iProductId) const
  339
+bool CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const
344 340
 {
345 341
   /* check all mappings in the order in which they are defined in peripherals.xml */
346 342
   for (unsigned int iMappingPtr = 0; iMappingPtr < m_mappings.size(); iMappingPtr++)
@@ -355,24 +351,26 @@ int CPeripherals::GetMappingForDevice(const CPeripheralBus &bus, const Periphera
355 351
     else
356 352
     {
357 353
       for (unsigned int i = 0; i < mapping.m_PeripheralID.size(); i++)
358  
-        if (mapping.m_PeripheralID[i].m_iVendorId == iVendorId && mapping.m_PeripheralID[i].m_iProductId == iProductId)
  354
+        if (mapping.m_PeripheralID[i].m_iVendorId == result.m_iVendorId && mapping.m_PeripheralID[i].m_iProductId == result.m_iProductId)
359 355
           bProductMatch = true;
360 356
     }
361 357
 
362 358
     bool bBusMatch = (mapping.m_busType == PERIPHERAL_BUS_UNKNOWN || mapping.m_busType == bus.Type());
363  
-    bool bClassMatch = (mapping.m_class == PERIPHERAL_UNKNOWN || mapping.m_class == classType);
  359
+    bool bClassMatch = (mapping.m_class == PERIPHERAL_UNKNOWN || mapping.m_class == result.m_type);
364 360
 
365 361
     if (bProductMatch && bBusMatch && bClassMatch)
366 362
     {
367 363
       CStdString strVendorId, strProductId;
368  
-      PeripheralTypeTranslator::FormatHexString(iVendorId, strVendorId);
369  
-      PeripheralTypeTranslator::FormatHexString(iProductId, strProductId);
  364
+      PeripheralTypeTranslator::FormatHexString(result.m_iVendorId, strVendorId);
  365
+      PeripheralTypeTranslator::FormatHexString(result.m_iProductId, strProductId);
370 366
       CLog::Log(LOGDEBUG, "%s - device (%s:%s) mapped to %s (type = %s)", __FUNCTION__, strVendorId.c_str(), strProductId.c_str(), mapping.m_strDeviceName.c_str(), PeripheralTypeTranslator::TypeToString(mapping.m_mappedTo));
371  
-      return iMappingPtr;
  367
+      result.m_mappedType    = m_mappings[iMappingPtr].m_mappedTo;
  368
+      result.m_strDeviceName = m_mappings[iMappingPtr].m_strDeviceName;
  369
+      return true;
372 370
     }
373 371
   }
374 372
 
375  
-  return -1;
  373
+  return false;
376 374
 }
377 375
 
378 376
 void CPeripherals::GetSettingsFromMapping(CPeripheral &peripheral) const
7  xbmc/peripherals/Peripherals.h
@@ -111,11 +111,10 @@ namespace PERIPHERALS
111 111
     /*!
112 112
      * @brief Creates a new instance of a peripheral.
113 113
      * @param bus The bus on which this peripheral is present.
114  
-     * @param type The type of the new peripheral.
115  
-     * @param strLocation The location on the bus.
  114
+     * @param result The scan result from the device scanning code.
116 115
      * @return The new peripheral or NULL if it could not be created.
117 116
      */
118  
-    CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralType type, const CStdString &strLocation, int iVendorId = 0, int iProductId = 0);
  117
+    CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result);
119 118
 
120 119
     /*!
121 120
      * @brief Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).
@@ -200,7 +199,7 @@ namespace PERIPHERALS
200 199
   private:
201 200
     CPeripherals(void);
202 201
     bool LoadMappings(void);
203  
-    int GetMappingForDevice(const CPeripheralBus &bus, const PeripheralType classType, int iVendorId, int iProductId) const;
  202
+    bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const;
204 203
     static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<CStdString, CSetting *> &m_settings);
205 204
 
206 205
     bool                                 m_bInitialised;
4  xbmc/peripherals/bus/Makefile.in
@@ -12,8 +12,8 @@ ifeq ($(findstring osx,@ARCH@),osx)
12 12
 SRCS += osx/PeripheralBusUSB.cpp
13 13
 endif
14 14
 
15  
-ifeq (@USE_CEC_RPI_API@,1)
16  
-SRCS += linux/PeripheralBusRPi.cpp
  15
+ifeq (@USE_LIBCEC@,1)
  16
+SRCS += virtual/PeripheralBusCEC.cpp
17 17
 endif
18 18
 
19 19
 LIB = peripheral-bus.a
81  xbmc/peripherals/bus/PeripheralBus.cpp
@@ -29,65 +29,6 @@ using namespace PERIPHERALS;
29 29
 
30 30
 #define PERIPHERAL_DEFAULT_RESCAN_INTERVAL 1000
31 31
 
32  
-bool PeripheralScanResult::operator ==(const PeripheralScanResult &right) const
33  
-{
34  
-  return m_iVendorId == right.m_iVendorId &&
35  
-      m_iProductId == right.m_iProductId &&
36  
-      m_type == right.m_type &&
37  
-      m_strLocation.Equals(right.m_strLocation);
38  
-}
39  
-
40  
-bool PeripheralScanResult::operator !=(const PeripheralScanResult &right) const
41  
-{
42  
-  return !(*this == right);
43  
-}
44  
-
45  
-bool PeripheralScanResult::operator ==(const CPeripheral &right) const
46  
-{
47  
-  return m_iVendorId == right.VendorId() &&
48  
-      m_iProductId == right.ProductId() &&
49  
-      m_type == right.Type() &&
50  
-      m_strLocation.Equals(right.Location());
51  
-}
52  
-
53  
-bool PeripheralScanResult::operator !=(const CPeripheral &right) const
54  
-{
55  
-  return !(*this == right);
56  
-}
57  
-
58  
-bool PeripheralScanResults::GetDeviceOnLocation(const CStdString &strLocation, PeripheralScanResult *result) const
59  
-{
60  
-  bool bReturn(false);
61  
-
62  
-  for (unsigned int iDevicePtr = 0; iDevicePtr < m_results.size(); iDevicePtr++)
63  
-  {
64  
-    if (m_results.at(iDevicePtr).m_strLocation == strLocation)
65  
-    {
66  
-      *result = m_results.at(iDevicePtr);
67  
-      bReturn = true;
68  
-      break;
69  
-    }
70  
-  }
71  
-
72  
-  return bReturn;
73  
-}
74  
-
75  
-bool PeripheralScanResults::ContainsResult(const PeripheralScanResult &result) const
76  
-{
77  
-  bool bReturn(false);
78  
-
79  
-  for (unsigned int iDevicePtr = 0; iDevicePtr < m_results.size(); iDevicePtr++)
80  
-  {
81  
-    if (m_results.at(iDevicePtr) == result)
82  
-    {
83  
-      bReturn = true;
84  
-      break;
85  
-    }
86  
-  }
87  
-
88  
-  return bReturn;
89  
-}
90  
-
91 32
 CPeripheralBus::CPeripheralBus(CPeripherals *manager, PeripheralBusType type) :
92 33
     CThread("XBMC Peripherals"),
93 34
     m_iRescanTime(PERIPHERAL_DEFAULT_RESCAN_INTERVAL),
@@ -137,9 +78,9 @@ void CPeripheralBus::UnregisterRemovedDevices(const PeripheralScanResults &resul
137 78
   for (int iDevicePtr = (int) m_peripherals.size() - 1; iDevicePtr >= 0; iDevicePtr--)
138 79
   {
139 80
     CPeripheral *peripheral = m_peripherals.at(iDevicePtr);
140  
-    PeripheralScanResult updatedDevice;
  81
+    PeripheralScanResult updatedDevice(m_type);
141 82
     if (!results.GetDeviceOnLocation(peripheral->Location(), &updatedDevice) ||
142  
-        updatedDevice != *peripheral)
  83
+        *peripheral != updatedDevice)
143 84
     {
144 85
       /* device removed */
145 86
       removedPeripherals.push_back(peripheral);
@@ -170,9 +111,9 @@ void CPeripheralBus::RegisterNewDevices(const PeripheralScanResults &results)
170 111
   CSingleLock lock(m_critSection);
171 112
   for (unsigned int iResultPtr = 0; iResultPtr < results.m_results.size(); iResultPtr++)
172 113
   {
173  
-    PeripheralScanResult result = results.m_results.at(iResultPtr);
  114
+    const PeripheralScanResult& result = results.m_results.at(iResultPtr);
174 115
     if (!HasPeripheral(result.m_strLocation))
175  
-      g_peripherals.CreatePeripheral(*this, result.m_type, result.m_strLocation, result.m_iVendorId, result.m_iProductId);
  116
+      g_peripherals.CreatePeripheral(*this, result);
176 117
   }
177 118
 }
178 119
 
@@ -246,6 +187,20 @@ int CPeripheralBus::GetPeripheralsWithFeature(vector<CPeripheral *> &results, co
246 187
   return iReturn;
247 188
 }
248 189
 
  190
+size_t CPeripheralBus::GetNumberOfPeripheralsWithId(const int iVendorId, const int iProductId) const
  191
+{
  192
+  int iReturn(0);
  193
+  CSingleLock lock(m_critSection);
  194
+  for (unsigned int iPeripheralPtr = 0; iPeripheralPtr < m_peripherals.size(); iPeripheralPtr++)
  195
+  {
  196
+    if (m_peripherals.at(iPeripheralPtr)->VendorId() == iVendorId &&
  197
+        m_peripherals.at(iPeripheralPtr)->ProductId() == iProductId)
  198
+      iReturn++;
  199
+  }
  200
+
  201
+  return iReturn;
  202
+}
  203
+
249 204
 void CPeripheralBus::Process(void)
250 205
 {
251 206
   while (!m_bStop)
23  xbmc/peripherals/bus/PeripheralBus.h
@@ -31,28 +31,6 @@ namespace PERIPHERALS
31 31
 {
32 32
   class CPeripherals;
33 33
 
34  
-  struct PeripheralScanResult
35  
-  {
36  
-    bool operator ==(const PeripheralScanResult &right) const;
37  
-    bool operator !=(const PeripheralScanResult &right) const;
38  
-
39  
-    bool operator ==(const CPeripheral &right) const;
40  
-    bool operator !=(const CPeripheral &right) const;
41  
-
42  
-    PeripheralType m_type;
43  
-    CStdString     m_strLocation;
44  
-    int            m_iVendorId;
45  
-    int            m_iProductId;
46  
-  };
47  
-
48  
-  struct PeripheralScanResults
49  
-  {
50  
-    bool GetDeviceOnLocation(const CStdString &strLocation, PeripheralScanResult *result) const;
51  
-    bool ContainsResult(const PeripheralScanResult &result) const;
52  
-
53  
-    std::vector<PeripheralScanResult> m_results;
54  
-  };
55  
-
56 34
   /*!
57 35
    * @class CPeripheralBus
58 36
    * This represents a bus on the system. By default, this bus instance will scan for changes every second.
@@ -100,6 +78,7 @@ namespace PERIPHERALS
100 78
     virtual int GetPeripheralsWithFeature(std::vector<CPeripheral *> &results, const PeripheralFeature feature) const;
101 79
 
102 80
     virtual size_t GetNumberOfPeripherals() const;
  81
+    virtual size_t GetNumberOfPeripheralsWithId(const int iVendorId, const int iProductId) const;
103 82
 
104 83
     /*!
105 84
      * @brief Get all features that are supported by devices on this bus.
69  xbmc/peripherals/bus/linux/PeripheralBusRPi.cpp
... ...
@@ -1,69 +0,0 @@
1  
-/*
2  
- *      Copyright (C) 2005-2013 Team XBMC
3  
- *      http://xbmc.org
4  
- *
5  
- *  This Program is free software; you can redistribute it and/or modify
6  
- *  it under the terms of the GNU General Public License as published by
7  
- *  the Free Software Foundation; either version 2, or (at your option)
8  
- *  any later version.
9  
- *
10  
- *  This Program is distributed in the hope that it will be useful,
11  
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  
- *  GNU General Public License for more details.
14  
- *
15  
- *  You should have received a copy of the GNU General Public License
16  
- *  along with XBMC; see the file COPYING.  If not, see
17  
- *  <http://www.gnu.org/licenses/>.
18  
- *
19  
- */
20  
-
21  
-#include "PeripheralBusRPi.h"
22  
-#include <libcec/cectypes.h>
23  
-
24  
-extern "C" {
25  
-#include <interface/vmcs_host/vc_cecservice.h>
26  
-#include <interface/vchiq_arm/vchiq_if.h>
27  
-}
28  
-
29  
-using namespace PERIPHERALS;
30  
-
31  
-#define RPI_PERIPHERAL_BUS_VID 0x2708
32  
-#define RPI_PERIPHERAL_CEC_PID 0x1001
33  
-
34  
-CPeripheralBusRPi::CPeripheralBusRPi(CPeripherals *manager) :
35  
-    CPeripheralBus(manager, PERIPHERAL_BUS_RPI)
36  
-{
37  
-  m_bNeedsPolling = false;
38  
-}
39  
-
40  
-bool CPeripheralBusRPi::PerformDeviceScan(PeripheralScanResults &results)
41  
-{
42  
-  if (FindAdapter())
43  
-  {
44  
-    PeripheralScanResult result;
45  
-    result.m_iVendorId   = RPI_PERIPHERAL_BUS_VID;
46  
-    result.m_iProductId  = RPI_PERIPHERAL_CEC_PID;
47  
-    result.m_type        = PERIPHERAL_CEC;
48  
-    result.m_strLocation = CEC_RPI_VIRTUAL_COM;
49  
-
50  
-    if (!results.ContainsResult(result))
51  
-      results.m_results.push_back(result);
52  
-  }
53  
-
54  
-  return true;
55  
-}
56  
-
57  
-bool CPeripheralBusRPi::FindAdapter(void)
58  
-{
59  
-  uint8_t iResult;
60  
-
61  
-  VCHI_INSTANCE_T vchiq_instance;
62  
-  if ((iResult = vchi_initialise(&vchiq_instance)) != VCHIQ_SUCCESS)
63  
-    return false;
64  
-
65  
-  if ((iResult = vchi_connect(NULL, 0, vchiq_instance)) != VCHIQ_SUCCESS)
66  
-    return false;
67  
-
68  
-  return true;
69  
-}
3  xbmc/peripherals/bus/linux/PeripheralBusUSBLibUSB.cpp
@@ -43,7 +43,7 @@ bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results)
43 43
     struct usb_device *dev;
44 44
     for (dev = bus->devices; dev; dev = dev->next)
45 45
     {
46  
-      PeripheralScanResult result;
  46
+      PeripheralScanResult result(m_type);
47 47
       result.m_iVendorId  = dev->descriptor.idVendor;
48 48
       result.m_iProductId = dev->descriptor.idProduct;
49 49
       result.m_type       = (dev->descriptor.bDeviceClass == USB_CLASS_PER_INTERFACE && dev->descriptor.bNumConfigurations > 0 &&
@@ -55,6 +55,7 @@ bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results)
55 55
 #else
56 56
       result.m_strLocation.Format("/bus%s/dev%s", bus->dirname, dev->filename);
57 57
 #endif
  58
+      result.m_iSequence   = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId);
58 59
       if (!results.ContainsResult(result))
59 60
         results.m_results.push_back(result);
60 61
     }
4  xbmc/peripherals/bus/linux/PeripheralBusUSBLibUdev.cpp
@@ -152,12 +152,12 @@ bool CPeripheralBusUSB::PerformDeviceScan(PeripheralScanResults &results)
152 152
         iClass = USB_CLASS_HID;
153 153
       }
154 154
 
155  
-      PeripheralScanResult result;
  155
+      PeripheralScanResult result(m_type);
156 156
       result.m_iVendorId   = PeripheralTypeTranslator::HexStringToInt(udev_device_get_sysattr_value(dev, "idVendor"));
157 157
       result.m_iProductId  = PeripheralTypeTranslator::HexStringToInt(udev_device_get_sysattr_value(dev, "idProduct"));
158 158
       result.m_type        = GetType(iClass);
159 159
       result.m_strLocation = udev_device_get_syspath(dev);
160  
-
  160
+      result.m_iSequence   = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId);
161 161
       if (!results.ContainsResult(result))
162 162
         results.m_results.push_back(result);
163 163
     }
1  xbmc/peripherals/bus/osx/PeripheralBusUSB.cpp
@@ -267,6 +267,7 @@ void CPeripheralBusUSB::DeviceAttachCallback(CPeripheralBusUSB* refCon, io_itera
267 267
         else
268 268
           privateDataRef->result.m_type = refCon->GetType(bDeviceClass);
269 269
 
  270
+        privateDataRef->result.m_iSequence = refCon->GetNumberOfPeripheralsWithId(privateDataRef->result.m_iVendorId, privateDataRef->result.m_iProductId);
270 271
         if (!refCon->m_scan_results.ContainsResult(privateDataRef->result))
271 272
         {
272 273
           // register this usb device for an interest notification callback. 
116  xbmc/peripherals/bus/virtual/PeripheralBusCEC.cpp
... ...
@@ -0,0 +1,116 @@
  1
+/*
  2
+ *      Copyright (C) 2005-2012 Team XBMC
  3
+ *      http://xbmc.org
  4
+ *
  5
+ *  This Program is free software; you can redistribute it and/or modify
  6
+ *  it under the terms of the GNU General Public License as published by
  7
+ *  the Free Software Foundation; either version 2, or (at your option)
  8
+ *  any later version.
  9
+ *
  10
+ *  This Program is distributed in the hope that it will be useful,
  11
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13
+ *  GNU General Public License for more details.
  14
+ *
  15
+ *  You should have received a copy of the GNU General Public License
  16
+ *  along with XBMC; see the file COPYING.  If not, see
  17
+ *  <http://www.gnu.org/licenses/>.
  18
+ *
  19
+ */
  20
+
  21
+#include "system.h"
  22
+#if defined(HAVE_LIBCEC)
  23
+#include "PeripheralBusCEC.h"
  24
+#include "peripherals/Peripherals.h"
  25
+#include "utils/log.h"
  26
+#include "DynamicDll.h"
  27
+
  28
+#include <libcec/cec.h>
  29
+
  30
+using namespace PERIPHERALS;
  31
+using namespace CEC;
  32
+using namespace std;
  33
+
  34
+class DllLibCECInterface
  35
+{
  36
+public:
  37
+  virtual ~DllLibCECInterface() {}
  38
+  virtual ICECAdapter* CECInitialise(libcec_configuration *configuration)=0;
  39
+  virtual void*        CECDestroy(ICECAdapter *adapter)=0;
  40
+};
  41
+
  42
+class PERIPHERALS::DllLibCEC : public DllDynamic, DllLibCECInterface
  43
+{
  44
+  DECLARE_DLL_WRAPPER(DllLibCEC, DLL_PATH_LIBCEC)
  45
+
  46
+  DEFINE_METHOD1(ICECAdapter*, CECInitialise, (libcec_configuration *p1))
  47
+  DEFINE_METHOD1(void*       , CECDestroy,    (ICECAdapter *p1))
  48
+
  49
+  BEGIN_METHOD_RESOLVE()
  50
+    RESOLVE_METHOD_RENAME(CECInitialise,  CECInitialise)
  51
+    RESOLVE_METHOD_RENAME(CECDestroy, CECDestroy)
  52
+  END_METHOD_RESOLVE()
  53
+};
  54
+
  55
+CPeripheralBusCEC::CPeripheralBusCEC(CPeripherals *manager) :
  56
+    CPeripheralBus(manager, PERIPHERAL_BUS_CEC),
  57
+    m_dll(new DllLibCEC),
  58
+    m_cecAdapter(NULL)
  59
+{
  60
+  m_iRescanTime = 1000;
  61
+  if (!m_dll->Load() || !m_dll->IsLoaded())
  62
+  {
  63
+    delete m_dll;
  64
+    m_dll = NULL;
  65
+  }
  66
+  else
  67
+  {
  68
+    m_cecAdapter = m_dll->CECInitialise(&m_configuration);
  69
+  }
  70
+}
  71
+
  72
+CPeripheralBusCEC::~CPeripheralBusCEC(void)
  73
+{
  74
+  if (m_dll && m_cecAdapter)
  75
+    m_dll->CECDestroy(m_cecAdapter);
  76
+  delete m_dll;
  77
+}
  78
+
  79
+bool CPeripheralBusCEC::PerformDeviceScan(PeripheralScanResults &results)
  80
+{
  81
+  if (!m_dll || !m_cecAdapter)
  82
+    return false;
  83
+
  84
+  cec_adapter_descriptor deviceList[10];
  85
+  int8_t iFound = m_cecAdapter->DetectAdapters(deviceList, 10, NULL, true);
  86
+
  87
+  for (uint8_t iDevicePtr = 0; iDevicePtr < iFound; iDevicePtr++)
  88
+  {
  89
+    PeripheralScanResult result(m_type);
  90
+    result.m_iVendorId   = deviceList[iDevicePtr].iVendorId;
  91
+    result.m_iProductId  = deviceList[iDevicePtr].iProductId;
  92
+    result.m_strLocation = deviceList[iDevicePtr].strComPath;
  93
+    result.m_type        = PERIPHERAL_CEC;
  94
+
  95
+    // override the bus type, so users don't have to reconfigure their adapters
  96
+    switch(deviceList[iDevicePtr].adapterType)
  97
+    {
  98
+    case ADAPTERTYPE_P8_EXTERNAL:
  99
+    case ADAPTERTYPE_P8_DAUGHTERBOARD:
  100
+      result.m_mappedBusType = PERIPHERAL_BUS_USB;
  101
+      break;
  102
+    case ADAPTERTYPE_RPI:
  103
+      result.m_mappedBusType = PERIPHERAL_BUS_RPI;
  104
+      break;
  105
+    default:
  106
+      break;
  107
+    }
  108
+
  109
+    result.m_iSequence = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId);
  110
+    if (!results.ContainsResult(result))
  111
+      results.m_results.push_back(result);
  112
+  }
  113
+  return true;
  114
+}
  115
+
  116
+#endif
25  xbmc/peripherals/bus/linux/PeripheralBusRPi.h → xbmc/peripherals/bus/virtual/PeripheralBusCEC.h
@@ -22,19 +22,36 @@
22 22
 #include "peripherals/bus/PeripheralBus.h"
23 23
 #include "peripherals/devices/Peripheral.h"
24 24
 
  25
+// undefine macro isset, it collides with function in cectypes.h
  26
+#ifdef isset
  27
+#undef isset
  28
+#endif
  29
+#include <libcec/cectypes.h>
  30
+
  31
+namespace CEC
  32
+{
  33
+  class ICECAdapter;
  34
+}
  35
+
25 36
 namespace PERIPHERALS
26 37
 {
27 38
   class CPeripherals;
  39
+  class DllLibCEC;
28 40
 
29  
-  class CPeripheralBusRPi : public CPeripheralBus
  41
+  class CPeripheralBusCEC : public CPeripheralBus
30 42
   {
31 43
   public:
32  
-    CPeripheralBusRPi(CPeripherals *manager);
33  
-    virtual ~CPeripheralBusRPi(void) {};
  44
+    CPeripheralBusCEC(CPeripherals *manager);
  45
+    virtual ~CPeripheralBusCEC(void);
34 46
 
  47
+    /*!
  48
+     * @see PeripheralBus::PerformDeviceScan()
  49
+     */
35 50
     bool PerformDeviceScan(PeripheralScanResults &results);
36 51
 
37 52
   private:
38  
-    bool FindAdapter(void);
  53
+    DllLibCEC*                m_dll;
  54
+    CEC::ICECAdapter*         m_cecAdapter;
  55
+    CEC::libcec_configuration m_configuration;
39 56
   };
40 57
 }
5  xbmc/peripherals/bus/win32/PeripheralBusUSB.cpp
@@ -104,14 +104,15 @@ bool CPeripheralBusUSB::PerformDeviceScan(const GUID *guid, const PeripheralType
104 104
 
105 105
         if ((strTmp.Find("&mi_") < 0) || (strTmp.Find("&mi_00") >= 0))
106 106
         {
107  
-          PeripheralScanResult prevDevice;
  107
+          PeripheralScanResult prevDevice(m_type);
108 108
           if (!results.GetDeviceOnLocation(devicedetailData->DevicePath, &prevDevice))
109 109
           {
110  
-            PeripheralScanResult result;
  110
+            PeripheralScanResult result(m_type);
111 111
             result.m_strLocation  = devicedetailData->DevicePath;
112 112
             result.m_type         = type;
113 113
             result.m_iVendorId    = PeripheralTypeTranslator::HexStringToInt(strVendorId.c_str());
114 114
             result.m_iProductId   = PeripheralTypeTranslator::HexStringToInt(strProductId.c_str());
  115
+            result.m_iSequence    = GetNumberOfPeripheralsWithId(result.m_iVendorId, result.m_iProductId);
115 116
 
116 117
             if (!results.ContainsResult(result))
117 118
               results.m_results.push_back(result);
54  xbmc/peripherals/devices/Peripheral.cpp
@@ -38,39 +38,23 @@ struct SortBySettingsOrder
38 38
   }
39 39
 };
40 40
 
41  
-CPeripheral::CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId) :
42  
-  m_type(type),
43  
-  m_busType(busType),
44  
-  m_strLocation(strLocation),
45  
-  m_strDeviceName(strDeviceName),
  41
+CPeripheral::CPeripheral(const PeripheralScanResult& scanResult) :
  42
+  m_type(scanResult.m_mappedType),
  43
+  m_busType(scanResult.m_busType),
  44
+  m_mappedBusType(scanResult.m_mappedBusType),
  45
+  m_strLocation(scanResult.m_strLocation),
  46
+  m_strDeviceName(scanResult.m_strDeviceName),
46 47
   m_strFileLocation(StringUtils::EmptyString),
47  
-  m_iVendorId(iVendorId),
48  
-  m_iProductId(iProductId),
49  
-  m_strVersionInfo(g_localizeStrings.Get(13205)), // "unknown"
50  
-  m_bInitialised(false),
51  
-  m_bHidden(false),
52  
-  m_bError(false)
53  
-{
54  
-  PeripheralTypeTranslator::FormatHexString(iVendorId, m_strVendorId);
55  
-  PeripheralTypeTranslator::FormatHexString(iProductId, m_strProductId);
56  
-  m_strFileLocation.Format("peripherals://%s/%s.dev", PeripheralTypeTranslator::BusTypeToString(busType), strLocation.c_str());
57  
-}
58  
-
59  
-CPeripheral::CPeripheral(void) :
60  
-  m_type(PERIPHERAL_UNKNOWN),
61  
-  m_busType(PERIPHERAL_BUS_UNKNOWN),
62  
-  m_strLocation(StringUtils::EmptyString),
63  
-  m_strDeviceName(StringUtils::EmptyString),
64  
-  m_strFileLocation(StringUtils::EmptyString),
65  
-  m_iVendorId(0),
66  
-  m_strVendorId("0000"),
67  
-  m_iProductId(0),
68  
-  m_strProductId("0000"),
  48
+  m_iVendorId(scanResult.m_iVendorId),
  49
+  m_iProductId(scanResult.m_iProductId),
69 50
   m_strVersionInfo(g_localizeStrings.Get(13205)), // "unknown"
70 51
   m_bInitialised(false),
71 52
   m_bHidden(false),
72 53
   m_bError(false)
73 54
 {
  55
+  PeripheralTypeTranslator::FormatHexString(scanResult.m_iVendorId, m_strVendorId);
  56
+  PeripheralTypeTranslator::FormatHexString(scanResult.m_iProductId, m_strProductId);
  57
+  m_strFileLocation.Format(scanResult.m_iSequence > 0 ? "peripherals://%s/%s_%d.dev" : "peripherals://%s/%s.dev", PeripheralTypeTranslator::BusTypeToString(scanResult.m_busType), scanResult.m_strLocation.c_str(), scanResult.m_iSequence);
74 58
 }
75 59
 
76 60
 CPeripheral::~CPeripheral(void)
@@ -146,7 +130,7 @@ bool CPeripheral::Initialise(void)
146 130
     return bReturn;
147 131
 
148 132
   g_peripherals.GetSettingsFromMapping(*this);
149  
-  m_strSettingsFile.Format("special://profile/peripheral_data/%s_%s_%s.xml", PeripheralTypeTranslator::BusTypeToString(m_busType), m_strVendorId.c_str(), m_strProductId.c_str());
  133
+  m_strSettingsFile.Format("special://profile/peripheral_data/%s_%s_%s.xml", PeripheralTypeTranslator::BusTypeToString(m_mappedBusType), m_strVendorId.c_str(), m_strProductId.c_str());
150 134
   LoadPersistedSettings();
151 135
 
152 136
   for (unsigned int iFeaturePtr = 0; iFeaturePtr < m_features.size(); iFeaturePtr++)
@@ -535,3 +519,17 @@ void CPeripheral::ClearSettings(void)
535 519
   }
536 520
   m_settings.clear();
537 521
 }
  522
+
  523
+bool CPeripheral::operator ==(const PeripheralScanResult& right) const
  524
+{
  525
+  return m_iVendorId  == right.m_iVendorId &&
  526
+         m_iProductId == right.m_iProductId &&
  527
+         m_type       == right.m_type &&
  528
+         m_busType    == right.m_busType &&
  529
+         m_strLocation.Equals(right.m_strLocation);
  530
+}
  531
+
  532
+bool CPeripheral::operator !=(const PeripheralScanResult& right) const
  533
+{
  534
+  return !(*this == right);
  535
+}
6  xbmc/peripherals/devices/Peripheral.h
@@ -34,12 +34,13 @@ namespace PERIPHERALS
34 34
     friend class CGUIDialogPeripheralSettings;
35 35
 
36 36
   public:
37  
-    CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
38  
-    CPeripheral(void);
  37
+    CPeripheral(const PeripheralScanResult& scanResult);
39 38
     virtual ~CPeripheral(void);
40 39
 
41 40
     bool operator ==(const CPeripheral &right) const;
42 41
     bool operator !=(const CPeripheral &right) const;
  42
+    bool operator ==(const PeripheralScanResult& right) const;
  43
+    bool operator !=(const PeripheralScanResult& right) const;
43 44
 
44 45
     const CStdString &FileLocation(void) const     { return m_strFileLocation; }
45 46
     const CStdString &Location(void) const         { return m_strLocation; }
@@ -158,6 +159,7 @@ namespace PERIPHERALS
158 159
 
159 160
     PeripheralType                   m_type;
160 161
     PeripheralBusType                m_busType;
  162
+    PeripheralBusType                m_mappedBusType;
161 163
     CStdString                       m_strLocation;
162 164
     CStdString                       m_strDeviceName;
163 165
     CStdString                       m_strSettingsFile;
4  xbmc/peripherals/devices/PeripheralBluetooth.cpp
@@ -23,8 +23,8 @@
23 23
 
24 24
 using namespace PERIPHERALS;
25