[hack] UMS camera detected as libgphoto2 supported

Sjoerd Simons sjoerd at luon.net
Sat Nov 6 12:24:14 PST 2004


Hi,

  It seems that various olympus share the same usb id's. Some of which are PtP
  and others are UMS. 

  When using an UMS camera, hal-hotplug-map will set the libgphoto2 properties
  because it recognizes the usb id's. Which causes g-v-m to pop up the photo
  dialog twice, once for the usb_device with camera capability and once for the
  volume with a dcim dir.

  Attached is a hack to not set the gphoto properties when the camera is UMS.
  It's hackish, because at the moment the callout is run the child device
  aren't known yet. 

  A better solution is probably to let libgphoto itself decide instead of just
  judging by the USB id's.. But that would make hal (or atleast the callout)
  dependent on libgphoto..

  Sjoerd
-- 
Murphy was an optimist.
-------------- next part --------------
Index: tools/linux/hal_hotplug_map.c
===================================================================
RCS file: /cvs/hal/hal/tools/linux/hal_hotplug_map.c,v
retrieving revision 1.3
diff -u -r1.3 hal_hotplug_map.c
--- tools/linux/hal_hotplug_map.c	27 Sep 2004 14:52:11 -0000	1.3
+++ tools/linux/hal_hotplug_map.c	6 Nov 2004 18:48:59 -0000
@@ -3,6 +3,9 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <dirent.h>
+#include <sys/types.h>
+
 #define DBUS_API_SUBJECT_TO_CHANGE
 #include "libhal/libhal.h"
 
@@ -21,6 +24,45 @@
 /* @todo FIXME HACK: it's a hack to hardcode this */
 static const char *usbmapfiles[] = {"/etc/hotplug/usb.usermap", "/etc/hotplug/usb/libsane.usermap", "/etc/hotplug/usb/libgphoto2.usermap",  NULL};
 
+#define BUFSIZE 256
+static int 
+check_usb_masstorage() {
+  char *sysfspath = getenv("HAL_PROP_LINUX_SYSFS_PATH");
+  DIR *sysfsdir;
+  struct dirent *direntry;
+  FILE *f;
+  char buf[BUFSIZE];
+  char path[PATH_MAX];
+
+  if (sysfspath == NULL) { 
+    return FALSE;
+  }
+  sysfsdir = opendir(sysfspath);
+  if (sysfsdir == NULL) {
+    return FALSE;
+  }
+  while ((direntry = readdir(sysfsdir)) != NULL)  {
+    if (direntry->d_type == DT_DIR) {
+      snprintf(path, PATH_MAX, "%s/%s/bInterfaceClass", 
+               sysfspath, direntry->d_name);
+      f = fopen(path, "r");
+      if (f == NULL)
+        continue;
+      if (fgets(buf, BUFSIZE, f) == NULL) {
+        fclose(f);
+        continue;
+      }
+      fclose(f);
+      if (atoi(buf) == 8) {
+        /* usb mass storage endpoint */
+        dbg("Found USB Mass Storage endpoint!\n");
+        return TRUE;
+      }
+    }
+  }
+  return FALSE;
+}
+
 static int
 handle_usb_found (const char *module)
 {
@@ -35,7 +77,8 @@
 	if (hal_context == NULL)
 		return FALSE;
 
-	if (strcmp (module, "usbcam") == 0 || strcmp(module, "libgphoto2") == 0) {
+	if ((strcmp (module, "usbcam") == 0 || strcmp(module, "libgphoto2") == 0) 
+       && !check_usb_masstorage()) {
 		hal_device_add_capability (hal_context, udi, "camera");
 		hal_device_set_property_string (hal_context, udi, "info.category", "camera");
 		hal_device_set_property_string (hal_context, udi, "camera.access_method", "user");
-------------- next part --------------
_______________________________________________
hal mailing list
hal at freedesktop.org
http://freedesktop.org/mailman/listinfo/hal


More information about the Hal mailing list