Permalink
Browse files

Merge pull request #198 from malard/USB_HID

USB HID fixes
  • Loading branch information...
2 parents 2ce5189 + 3ec87dd commit 34de506b468eff4bb0ea864976752a1879e39a82 @malard malard committed Jun 28, 2011
View
3 xbmc/input/ButtonTranslator.cpp
@@ -865,9 +865,8 @@ void CButtonTranslator::MapWindowActions(TiXmlNode *pWindow, int windowID)
{
pDevice = pWindow->FirstChild(type);
TiXmlElement *pDeviceElement = pDevice->ToElement();
- CStdString deviceName;
//check if exists, if not use "default"
- deviceName = pDeviceElement->Attribute("name");
+ CStdString deviceName = pDeviceElement->Attribute("name");
if (deviceName.empty())
deviceName = "default";
View
62 xbmc/input/KeymapLoader.cpp
@@ -28,26 +28,23 @@
using namespace std;
using namespace XFILE;
-CKeymapLoader::CKeymapLoader()
-{
- if (!parsedMappings)
- {
- ParseDeviceMappings();
- }
-}
+static std::map<CStdString, CStdString> deviceMappings;
+bool CKeymapLoader::parsedMappings = false;
-void CKeymapLoader::DeviceAdded(CStdString deviceId)
+void CKeymapLoader::DeviceAdded(const CStdString& deviceId)
{
+ ParseDeviceMappings();
CStdString keymapName;
- if (FindMappedDevice(deviceId, keymapName))
+ if (CKeymapLoader::FindMappedDevice(deviceId, keymapName))
{
CLog::Log(LOGDEBUG, "Switching Active Keymapping to: %s", keymapName.c_str());
g_settings.m_activeKeyboardMapping = keymapName;
}
}
-void CKeymapLoader::DeviceRemoved(CStdString deviceId)
+void CKeymapLoader::DeviceRemoved(const CStdString& deviceId)
{
+ ParseDeviceMappings();
CStdString keymapName;
if (FindMappedDevice(deviceId, keymapName))
{
@@ -58,33 +55,42 @@ void CKeymapLoader::DeviceRemoved(CStdString deviceId)
void CKeymapLoader::ParseDeviceMappings()
{
- parsedMappings = true;
- CStdString file("special://xbmc/system/deviceidmappings.xml");
- TiXmlDocument deviceXML;
- if (!CFile::Exists(file) || !deviceXML.LoadFile(file))
- return;
+ if (!parsedMappings)
+ {
+ parsedMappings = true;
+ CStdString file("special://xbmc/system/deviceidmappings.xml");
+ TiXmlDocument deviceXML;
+ if (!CFile::Exists(file) || !deviceXML.LoadFile(file))
+ return;
- TiXmlElement *pRootElement = deviceXML.RootElement();
- if (!pRootElement || strcmpi(pRootElement->Value(), "devicemappings") != 0)
- return;
+ TiXmlElement *pRootElement = deviceXML.RootElement();
+ if (!pRootElement || strcmpi(pRootElement->Value(), "devicemappings") != 0)
+ return;
- TiXmlElement *pDevice = pRootElement->FirstChildElement("device");
- while (pDevice)
- {
- CStdString deviceId(pDevice->Attribute("id"));
- CStdString keymap(pDevice->Attribute("keymap"));
- if (!deviceId.empty() && !keymap.empty())
- deviceMappings.insert(pair<CStdString, CStdString>(deviceId.ToUpper(), keymap));
- pDevice = pDevice->NextSiblingElement("device");
+ TiXmlElement *pDevice = pRootElement->FirstChildElement("device");
+ while (pDevice)
+ {
+ CStdString deviceId(pDevice->Attribute("id"));
+ CStdString keymap(pDevice->Attribute("keymap"));
+ if (!deviceId.empty() && !keymap.empty())
+ deviceMappings.insert(pair<CStdString, CStdString>(deviceId.ToUpper(), keymap));
+ pDevice = pDevice->NextSiblingElement("device");
+ }
}
}
-bool CKeymapLoader::FindMappedDevice(CStdString deviceId, CStdString& keymapName)
+bool CKeymapLoader::FindMappedDevice(const CStdString& deviceId, CStdString& keymapName)
{
- std::map<CStdString, CStdString>::iterator deviceIdIt = deviceMappings.find(deviceId.ToUpper());
+ CStdString deviceIdTemp = deviceId;
+ std::map<CStdString, CStdString>::iterator deviceIdIt = deviceMappings.find(deviceIdTemp.ToUpper());
if (deviceIdIt == deviceMappings.end())
return false;
keymapName = deviceIdIt->second;
return true;
+}
+
+CStdString CKeymapLoader::ParseWin32HIDName(const CStdString& deviceLongName)
+{
+ return deviceLongName.Mid(deviceLongName.find_last_of('\\')+1, deviceLongName.find_last_of('#') - deviceLongName.find_last_of('\\'));
}
View
15 xbmc/input/KeymapLoader.h
@@ -1,3 +1,4 @@
+#pragma once
/*
* Copyright (C) 2005-2011 Team XBMC
* http://xbmc.org
@@ -22,16 +23,14 @@
#include <map>
#include "utils/StdString.h"
-static std::map<CStdString, CStdString> deviceMappings;
-static bool parsedMappings;
-
class CKeymapLoader
{
public:
- CKeymapLoader();
- void DeviceRemoved(CStdString deviceID);
- void DeviceAdded(CStdString deviceID);
+ static void DeviceRemoved(const CStdString& deviceID);
+ static void DeviceAdded(const CStdString& deviceID);
+ static CStdString ParseWin32HIDName(const CStdString& deviceLongName);
private:
- void ParseDeviceMappings();
- bool FindMappedDevice(CStdString deviceId, CStdString& keymapName);
+ static void ParseDeviceMappings();
+ static bool FindMappedDevice(const CStdString& deviceId, CStdString& keymapName);
+ static bool parsedMappings;
};
View
5 xbmc/win32/WIN32USBScan.cpp
@@ -65,10 +65,7 @@ CWIN32USBScan::CWIN32USBScan()
detailResult = SetupDiGetDeviceInterfaceDetail(hDevHandle, &deviceInterfaceData, devicedetailData, nBufferSize , &required, NULL);
- CStdString dbcc_name(devicedetailData->DevicePath);
- dbcc_name = dbcc_name.Mid(dbcc_name.find_last_of('\\')+1, dbcc_name.find_last_of('#') - dbcc_name.find_last_of('\\'));
-
- CKeymapLoader().DeviceAdded(dbcc_name);
+ CKeymapLoader::DeviceAdded(CKeymapLoader::ParseWin32HIDName(devicedetailData->DevicePath));
if(!detailResult)
continue;
View
3 xbmc/windowing/windows/WinEventsWin32.cpp
@@ -32,6 +32,7 @@
#include "windowing/WindowingFactory.h"
#include <dbt.h>
#include "guilib/LocalizeStrings.h"
+#include "input/KeymapLoader.h"
#include "input/KeyboardStat.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/GUIControl.h" // for EVENT_RESULT
@@ -653,7 +654,7 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
{
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
CStdString dbcc_name(b->dbcc_name);
- dbcc_name = dbcc_name.Mid(dbcc_name.find_last_of('\\')+1, dbcc_name.find_last_of('#') - dbcc_name.find_last_of('\\'));
+ dbcc_name = CKeymapLoader::ParseWin32HIDName(b->dbcc_name);
switch (wParam)
{
case DBT_DEVICEARRIVAL:

0 comments on commit 34de506

Please sign in to comment.