3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
25 #include "PlatformDefs.h"
27 #include "utils/StdString.h"
28 #include "utils/StringUtils.h"
34 enum PeripheralBusType
36 PERIPHERAL_BUS_UNKNOWN = 0,
43 enum PeripheralFeature
58 PERIPHERAL_UNKNOWN = 0,
75 struct PeripheralDeviceSetting
81 struct PeripheralDeviceMapping
83 std::vector<PeripheralID> m_PeripheralID;
84 PeripheralBusType m_busType;
85 PeripheralType m_class;
86 CStdString m_strDeviceName;
87 PeripheralType m_mappedTo;
88 std::map<CStdString, PeripheralDeviceSetting> m_settings;
91 class PeripheralTypeTranslator
94 static const char *TypeToString(const PeripheralType type)
98 case PERIPHERAL_BLUETOOTH:
102 case PERIPHERAL_DISK:
108 case PERIPHERAL_NYXBOARD:
110 case PERIPHERAL_TUNER:
112 case PERIPHERAL_IMON:
119 static PeripheralType GetTypeFromString(const CStdString &strType)
121 CStdString strTypeLowerCase(strType);
122 StringUtils::ToLower(strTypeLowerCase);
124 if (strTypeLowerCase.Equals("bluetooth"))
125 return PERIPHERAL_BLUETOOTH;
126 else if (strTypeLowerCase.Equals("cec"))
127 return PERIPHERAL_CEC;
128 else if (strTypeLowerCase.Equals("disk"))
129 return PERIPHERAL_DISK;
130 else if (strTypeLowerCase.Equals("hid"))
131 return PERIPHERAL_HID;
132 else if (strTypeLowerCase.Equals("nic"))
133 return PERIPHERAL_NIC;
134 else if (strTypeLowerCase.Equals("nyxboard"))
135 return PERIPHERAL_NYXBOARD;
136 else if (strTypeLowerCase.Equals("tuner"))
137 return PERIPHERAL_TUNER;
138 else if (strTypeLowerCase.Equals("imon"))
139 return PERIPHERAL_IMON;
141 return PERIPHERAL_UNKNOWN;
144 static const char *BusTypeToString(const PeripheralBusType type)
148 case PERIPHERAL_BUS_USB:
150 case PERIPHERAL_BUS_PCI:
152 case PERIPHERAL_BUS_RPI:
154 case PERIPHERAL_BUS_CEC:
161 static PeripheralBusType GetBusTypeFromString(const CStdString &strType)
163 CStdString strTypeLowerCase(strType);
164 StringUtils::ToLower(strTypeLowerCase);
166 if (strTypeLowerCase.Equals("usb"))
167 return PERIPHERAL_BUS_USB;
168 else if (strTypeLowerCase.Equals("pci"))
169 return PERIPHERAL_BUS_PCI;
170 else if (strTypeLowerCase.Equals("rpi"))
171 return PERIPHERAL_BUS_RPI;
172 else if (strTypeLowerCase.Equals("cec"))
173 return PERIPHERAL_BUS_CEC;
175 return PERIPHERAL_BUS_UNKNOWN;
178 static int HexStringToInt(const char *strHex)
181 sscanf(strHex, "%x", &iVal);
185 static void FormatHexString(int iVal, CStdString &strHexString)
192 strHexString = StringUtils::Format("%04X", iVal);
196 class PeripheralScanResult
199 PeripheralScanResult(const PeripheralBusType busType) :
200 m_type(PERIPHERAL_UNKNOWN),
203 m_mappedType(PERIPHERAL_UNKNOWN),
205 m_mappedBusType(busType),
208 PeripheralScanResult(void) :
209 m_type(PERIPHERAL_UNKNOWN),
212 m_mappedType(PERIPHERAL_UNKNOWN),
213 m_busType(PERIPHERAL_BUS_UNKNOWN),
214 m_mappedBusType(PERIPHERAL_BUS_UNKNOWN),
217 bool operator ==(const PeripheralScanResult& right) const
219 return m_iVendorId == right.m_iVendorId &&
220 m_iProductId == right.m_iProductId &&
221 m_type == right.m_type &&
222 m_busType == right.m_busType &&
223 m_strLocation.Equals(right.m_strLocation);
226 bool operator !=(const PeripheralScanResult& right) const
228 return !(*this == right);
231 PeripheralType m_type;
232 CStdString m_strLocation;
235 PeripheralType m_mappedType;
236 CStdString m_strDeviceName;
237 PeripheralBusType m_busType;
238 PeripheralBusType m_mappedBusType;
239 unsigned int m_iSequence; // when more than one adapter of the same type is found
242 struct PeripheralScanResults
244 bool GetDeviceOnLocation(const CStdString& strLocation, PeripheralScanResult* result) const
246 for (std::vector<PeripheralScanResult>::const_iterator it = m_results.begin(); it != m_results.end(); it++)
248 if ((*it).m_strLocation == strLocation)
257 bool ContainsResult(const PeripheralScanResult& result) const
259 return std::find(m_results.begin(), m_results.end(), result) != m_results.end();
262 std::vector<PeripheralScanResult> m_results;