[PATCH] remote: allow for no devices & missing devices; constness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patches attached.

-- 
| Darren Salt    | linux or ds at              | nr. Ashington, | Toon
| RISC OS, Linux | youmustbejoking,demon,co,uk | Northumberland | Army
|   Say NO to UK ID cards. http://www.no2id.net/

Multics is security spelled sideways.
-------------- next part --------------
diff -urNad vdr-plugin-remote-0.3.4~/remote.c vdr-plugin-remote-0.3.4/remote.c
--- vdr-plugin-remote-0.3.4~/remote.c	2006-01-09 20:04:36.000000000 +0000
+++ vdr-plugin-remote-0.3.4/remote.c	2006-01-09 20:04:36.670699823 +0000
@@ -786,9 +786,9 @@
     } // for
     
     if (!ok)
-        esyslog("%s: fatal error - unable to open input device", Name());
+        esyslog("%s: warning: unable to open input device", Name());
 
-    return ok;
+    return true;
 }
 
 
-------------- next part --------------
diff -urNad vdr-plugin-remote-0.3.4~/remote.c vdr-plugin-remote-0.3.4/remote.c
--- vdr-plugin-remote-0.3.4~/remote.c	2006-01-09 20:04:41.000000000 +0000
+++ vdr-plugin-remote-0.3.4/remote.c	2006-01-09 20:04:41.158402951 +0000
@@ -174,7 +174,7 @@
 //          -1 - error
 //
 // ---------------------------------------------------------------------------
-int identifyInputDevice(const int fh, char *name)
+int identifyInputDevice(const int fh, const char *name)
 // ---------------------------------------------------------------------------
 {
     char description[256];
@@ -654,6 +654,23 @@
 }
 
 
+class cListString : public cListObject
+{
+private:
+  cString *content;
+public:
+  cListString (const char *obj) { content = new cString (obj); }
+  ~cListString () { delete content; }
+  int Compare (const cListObject &obj) const;
+  const cString& Get () { return *content; }
+};
+
+int cListString::Compare (const cListObject &obj) const
+{
+  return strcmp (**content, **((const cListString &)obj).content);
+}
+
+
 // ---------------------------------------------------------------------------
 bool cPluginRemote::Start(void)
 // ---------------------------------------------------------------------------
@@ -671,17 +688,59 @@
         devcnt = 1;
     }
 
+    cList<cListString> devices;
+
+    DIR *dir = opendir ("/dev/input");
+    if (!dir)
+    {
+        esyslog ("%s: unable to open '%s': %s",
+                 Name (), "/dev/input", strerror (errno));
+        return false;
+    }
+
+    long devmin = INT_MAX;
+    for (;;)
+    {
+        dirent obj, *ret;
+        int err = readdir_r (dir, &obj, &ret);
+        if (err)
+        {
+            esyslog ("%s: unable to read '%s': %s",
+                     Name (), "/dev/input", strerror (errno));
+            closedir (dir);
+            return false;
+        }
+        if (!ret)
+            break;
+
+        if (strncmp (obj.d_name, "event", 5))
+            continue;
+
+        long j;
+        char *end;
+        j = strtol (obj.d_name + 5, &end, 10);
+        if (j < 0 || end == obj.d_name || *end)
+            continue;
+
+        // keep track of the lowest device number (in case it's not 0)
+        if (j < devmin)
+            devmin = j;
+
+        devices.Add (new cListString (cString::sprintf ("/dev/input/%s", obj.d_name)));
+    }
+    closedir (dir);
+
+    devices.Sort ();
+
     /* probe eventX devices */
     for (int i = 0; i < devcnt; i++)
     {
         if (devtyp[i] == 'i' && strcmp(devnam[i], "autodetect") == 0)
         {
-            char nam[80];
 
-            for (int j = 0; ; j++)
+            for (cListString *dev = devices.First (); dev; dev = devices.Next (dev))
             {
-                sprintf(nam, "/dev/input/event%d", j);
-                fh[i] = open(nam, O_RDONLY);
+                fh[i] = open(dev->Get (), O_RDONLY);
                 if (fh[i] < 0)
                 {
                     switch (errno)
@@ -694,22 +753,23 @@
                     break;
                 }
 		
-                if (identifyInputDevice(fh[i], nam) >= 1)
+                if (identifyInputDevice(fh[i], dev->Get ()) >= 1)
                 {
                     // found DVB card receiver
-                    devnam[i] = strdup(nam);
+                    devnam[i] = strdup(dev->Get ());
                     close(fh[i]);
+                    devices.Del (dev);
                     break;
                 }
 
                 // unknown device, try next one
                 close(fh[i]);
-            } // for j
+            } // for each (remaining) eventX
         } // if autodetect
 
         // use default device if nothing could be identified
         if (devtyp[i] == 'i' && strcmp(devnam[i], "autodetect") == 0)
-            devnam[i] = "/dev/input/event0";
+            asprintf (&devnam[i], "/dev/input/event%ld", devmin);
     } // for i
 
     for (int i = 0; i < devcnt; i++)
-------------- next part --------------
diff -urNad vdr-plugin-remote-0.3.5~/remote.c vdr-plugin-remote-0.3.5/remote.c
--- vdr-plugin-remote-0.3.5~/remote.c	2006-01-25 14:35:49.000000000 +0000
+++ vdr-plugin-remote-0.3.5/remote.c	2006-01-25 14:38:21.525298825 +0000
@@ -26,10 +26,8 @@
 
 #define NUMREMOTES      10        // maximum number of remote control devices
  
-#define KEYMAP_DEVICE_AV7110   "/proc/av7110_ir"
-
-static const char *VERSION        = "0.3.5";
-static const char *DESCRIPTION    = "Remote control";
+static const char VERSION[]     = "0.3.5";
+static const char DESCRIPTION[] = "Remote control";
 
 
 
@@ -616,7 +614,7 @@
 bool cPluginRemote::ProcessArgs(int argc, char *argv[])
 // ---------------------------------------------------------------------------
 {
-    static struct option long_options[] =
+    static const struct option long_options[] =
             { { "input", required_argument, NULL, 'i' },
               { "lirc",  required_argument, NULL, 'l' },
               { "port",  required_argument, NULL, 'p' },

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux