hal/libhal libhal.c,1.42,1.43 libhal.h,1.23,1.24

David Zeuthen david at freedesktop.org
Sat Feb 26 14:31:44 PST 2005


Update of /cvs/hal/hal/libhal
In directory gabe:/tmp/cvs-serv9653/libhal

Modified Files:
	libhal.c libhal.h 
Log Message:
2005-02-26  David Zeuthen  <davidz at redhat.com>

	* libhal-storage/libhal-storage.h: Add new LibHalDriveType entries
	for ZIP, JAZ and FLASH_KEY - the latter represents a USB memory stick.

	* libhal-storage/libhal-storage.c (my_strvdup): New function
	(libhal_drive_from_udi): Fixup new detection of cameras and 
	musicplayers. Also handle storage.drive_type zip, jaz and flash_key
	and convert to LibHalDriveType as appropriate

	* libhal/libhal.h: Fixup type for LibHalDeviceCondition

	* libhal/libhal.c (filter_func): Fix up condition handling now that
	it's a name and details string rather than a whole DBusMessage trailing
	off. Fix up a bunch of free's due to new memory ownership semantics
	in the new D-BUS
	(libhal_device_query_capability): Handle this now that capabilities
	is a strlist

	* hald/device.c (hal_device_merge): info.capabilities is now a strlist
	(hal_device_add_capability): -do-
	(hal_device_has_capability): -do-
	(hal_device_property_strlist_add): Return whether element was actually
	added

	* fdi/information/10freedesktop/10-usb-zip-drives.fdi: New file

	* fdi/information/10freedesktop/10-usb-music-players.fdi: New file

	* fdi/information/10freedesktop/10-usb-card-readers.fdi: New file



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- libhal.c	23 Feb 2005 17:55:23 -0000	1.42
+++ libhal.c	26 Feb 2005 22:31:42 -0000	1.43
@@ -648,7 +648,7 @@
 
 	object_path = dbus_message_get_path (message);
 
-	/*printf("*** in filter_func, object_path=%s\n", object_path); */
+	/*printf("*** in filter_func, object_path=%s\n", object_path);*/
 
 	if (dbus_message_is_signal (message, "org.freedesktop.Hal.Manager",
 				    "DeviceAdded")) {
@@ -659,13 +659,9 @@
 			if (ctx->device_added != NULL) {
 				ctx->device_added (ctx, udi);
 			}
-			dbus_free (udi);
 		}
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	} else
-	    if (dbus_message_is_signal
-		(message, "org.freedesktop.Hal.Manager",
-		 "DeviceRemoved")) {
+	} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Manager", "DeviceRemoved")) {
 		char *udi;
 		if (dbus_message_get_args (message, &error,
 					   DBUS_TYPE_STRING, &udi,
@@ -673,13 +669,9 @@
 			if (ctx->device_removed != NULL) {
 				ctx->device_removed (ctx, udi);
 			}
-			dbus_free (udi);
 		}
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	} else
-	    if (dbus_message_is_signal
-		(message, "org.freedesktop.Hal.Manager",
-		 "NewCapability")) {
+	} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Manager","NewCapability")) {
 		char *udi;
 		char *capability;
 		if (dbus_message_get_args (message, &error,
@@ -687,36 +679,25 @@
 					   DBUS_TYPE_STRING, &capability,
 					   DBUS_TYPE_INVALID)) {
 			if (ctx->device_new_capability != NULL) {
-				ctx->device_new_capability (ctx, 
-								       udi,
-								  capability);
+				ctx->device_new_capability (ctx, udi, capability);
 			}
-			dbus_free (udi);
-			dbus_free (capability);
 		}
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	} else
-	    if (dbus_message_is_signal
-		(message, "org.freedesktop.Hal.Device", "Condition")) {
-		if (ctx->device_condition != NULL) {
-			DBusMessageIter iter;
-			char *condition_name;
-
-			dbus_message_iter_init (message, &iter);
-			dbus_message_iter_get_basic (&iter, &condition_name);
-
-			ctx->device_condition (ctx, 
-							  object_path,
-							  condition_name,
-							  message);
-
-			dbus_free (condition_name);
+	} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Device", "Condition")) {
+		char *udi;
+		char *condition_name;
+		char *condition_detail;
+		if (dbus_message_get_args (message, &error,
+					   DBUS_TYPE_STRING, &udi,
+					   DBUS_TYPE_STRING, &condition_name,
+					   DBUS_TYPE_STRING, &condition_detail,
+					   DBUS_TYPE_INVALID)) {
+			if (ctx->device_new_capability != NULL) {
+				ctx->device_condition (ctx, udi, condition_name, condition_detail);
+			}
 		}
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-	} else
-	    if (dbus_message_is_signal
-		(message, "org.freedesktop.Hal.Device",
-		 "PropertyModified")) {
+	} else if (dbus_message_is_signal (message, "org.freedesktop.Hal.Device", "PropertyModified")) {
 		if (ctx->device_property_modified != NULL) {
 			int i;
 			char *key;
@@ -742,19 +723,19 @@
 				dbus_message_iter_get_basic (&iter_struct, &removed);
 				dbus_message_iter_next (&iter_struct);
 				dbus_message_iter_get_basic (&iter_struct, &added);
-
+				
 				ctx->device_property_modified (ctx, 
 							       object_path,
 							       key, removed,
 							       added);
-
+				
 				dbus_message_iter_next (&iter_array);
 			}
-
+			
 		}
 		return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 	}
-
+	
 	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
@@ -2550,15 +2531,25 @@
  *				otherwise FALSE
  */
 dbus_bool_t
-libhal_device_query_capability (LibHalContext *ctx, 
-				const char *udi, const char *capability, DBusError *error)
+libhal_device_query_capability (LibHalContext *ctx, const char *udi, const char *capability, DBusError *error)
 {
+	char **caps;
+	unsigned int i;
 	dbus_bool_t ret;
-	char *caps;
 
-	caps = libhal_device_get_property_string (ctx, udi, "info.capabilities", error);
-	ret = (caps != NULL && strstr (caps, capability) != NULL);
-	libhal_free_string (caps);
+	ret = FALSE;
+
+	caps = libhal_device_get_property_strlist (ctx, udi, "info.capabilities", error);
+	if (caps != NULL) {
+		for (i = 0; caps[i] != NULL; i++) {
+			if (strcmp (caps[i], capability) == 0) {
+				ret = TRUE;
+				break;
+			}
+		}
+		libhal_free_string_array (caps);
+	}
+
 	return ret;
 }
 

Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- libhal.h	16 Feb 2005 18:39:56 -0000	1.23
+++ libhal.h	26 Feb 2005 22:31:42 -0000	1.24
@@ -134,7 +134,7 @@
 typedef void (*LibHalDeviceCondition) (LibHalContext *ctx,
 				       const char *udi,
 				       const char *condition_name,
-				       DBusMessage *message);
+				       const char *condition_detail);
 
 
 LibHalContext *libhal_ctx_new                          (void);




More information about the hal-commit mailing list