Merge pull request #4592 from koying/fixlinhotplug
authorjmarshallnz <jcmarsha@gmail.com>
Tue, 6 May 2014 23:46:52 +0000 (11:46 +1200)
committerJonathan Marshall <jmarshall@never.you.mind>
Tue, 6 May 2014 23:47:19 +0000 (11:47 +1200)
FIX: [linux] fix & optimize input device checking

xbmc/input/linux/LinuxInputDevices.cpp
xbmc/input/linux/LinuxInputDevices.h

index 4b642ae..ee21474 100644 (file)
@@ -931,9 +931,9 @@ void CLinuxInputDevice::GetInfo(int fd)
   //printf("pref: %d\n", m_devicePreferredId);
 }
 
-char* CLinuxInputDevice::GetDeviceName()
+const std::string& CLinuxInputDevice::GetFileName()
 {
-  return m_deviceName;
+  return m_fileName;
 }
 
 bool CLinuxInputDevice::IsUnplugged()
@@ -945,6 +945,11 @@ bool CLinuxInputDevices::CheckDevice(const char *device)
 {
   int fd;
 
+  // Does the device exists?
+  struct stat buffer;
+  if (stat(device, &buffer) != 0)
+    return false;
+
   /* Check if we are able to open the device */
   fd = open(device, O_RDWR);
   if (fd < 0)
@@ -1016,7 +1021,7 @@ void CLinuxInputDevices::CheckHotplugged()
 
     for (size_t j = 0; j < m_devices.size(); j++)
     {
-      if (strcmp(m_devices[j]->GetDeviceName(),buf) == 0)
+      if (m_devices[j]->GetFileName().compare(buf) == 0)
       {
         ispresent = true;
         break;
index c385ed7..384a83a 100644 (file)
@@ -41,7 +41,7 @@ public:
   CLinuxInputDevice(const std::string fileName, int index);
   ~CLinuxInputDevice();
   XBMC_Event ReadEvent();
-  char* GetDeviceName();
+  const std::string& GetFileName();
   bool IsUnplugged();
  
 private: