hal/libhal libhal.c,1.24,1.25 libhal.h,1.16,1.17

David Zeuthen david at freedesktop.org
Wed Sep 1 10:39:02 PDT 2004


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

Modified Files:
	libhal.c libhal.h 
Log Message:
2004-09-01  David Zeuthen  <david at fubar.dk>

	Patch from Jon Lech Johansen <jon at nanocrew.net>. Add support for
	properties of 64-bit unsigned integers. Right now this is not used
	as the D-BUS python bindings needs a patch.

	* hald/device.c: (hal_device_merge_with_rewrite),
	(hal_device_merge), (hal_device_matches),
	(hal_device_property_get_uint64), (hal_device_property_set_uint64),
	(hal_device_print):
	* hald/device.h:
	* hald/device_info.c: (handle_match), (handle_merge), (end):
	* hald/hald_dbus.c: (foreach_property_append),
	(device_get_property), (device_set_property):
	* hald/linux/common.c: (parse_hex_uint64):
	* hald/linux/common.h:
	* hald/linux/ieee1394_node_class_device.c:
	(ieee1394_node_class_pre_process):
	* hald/linux/net_class_device.c: (net_class_pre_process):
	* hald/property.c: (hal_property_new_uint64),
	(hal_property_get_uint64), (hal_property_to_string),
	(hal_property_set_uint64):
	* hald/property.h:
	* hald/pstore.c: (hal_pstore_save_property),
	(hal_pstore_load_property):
	* libhal/libhal.c: (hal_device_get_all_properties),
	(hal_psi_get_uint64), (hal_device_get_property_uint64),
	(hal_device_set_property_helper), (hal_device_set_property_string),
	(hal_device_set_property_int), (hal_device_set_property_uint64),
	(hal_device_set_property_double), (hal_device_set_property_bool),
	(hal_device_remove_property), (hal_device_print):
	* libhal/libhal.h:
	* tools/device-manager/DeviceManager.py:
	* tools/hal_get_property.c: (main):
	* tools/hal_set_property.c: (usage), (main):
	* tools/lshal.c: (dump_devices), (print_property):



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- libhal.c	4 Aug 2004 15:35:17 -0000	1.24
+++ libhal.c	1 Sep 2004 17:38:58 -0000	1.25
@@ -89,6 +89,8 @@
 		char *str_value;     /**< UTF-8 zero-terminated string */
 		dbus_int32_t int_value;
 				     /**< 32-bit signed integer */
+		dbus_uint64_t uint64_value;
+				     /**< 64-bit unsigned integer */
 		double double_value; /**< IEEE754 double precision float */
 		dbus_bool_t bool_value;
 				     /**< Truth value */
@@ -253,6 +255,10 @@
 			p->int_value =
 			    dbus_message_iter_get_int32 (&dict_iter);
 			break;
+		case DBUS_TYPE_UINT64:
+			p->uint64_value =
+			    dbus_message_iter_get_uint64 (&dict_iter);
+			break;
 		case DBUS_TYPE_DOUBLE:
 			p->double_value =
 			    dbus_message_iter_get_double (&dict_iter);
@@ -336,7 +342,7 @@
  *
  *  @param  iter		Iterator object
  *  @return			One of DBUS_TYPE_STRING, DBUS_TYPE_INT32,
- *				DBUS_TYPE_BOOL, DBUS_TYPE_DOUBLE
+ *				DBUS_TYPE_UINT64, DBUS_TYPE_BOOL, DBUS_TYPE_DOUBLE
  */
 int
 hal_psi_get_type (LibHalPropertySetIterator * iter)
@@ -383,6 +389,17 @@
 	return iter->cur_prop->int_value;
 }
 
+/** Get the value of a property of type integer. 
+ *
+ *  @param  iter		Iterator object
+ *  @return			64-bit unsigned integer
+ */
+dbus_uint64_t
+hal_psi_get_uint64 (LibHalPropertySetIterator * iter)
+{
+	return iter->cur_prop->uint64_value;
+}
+
 /** Get the value of a property of type double. 
  *
  *  @param  iter		Iterator object
@@ -731,7 +748,7 @@
  *  @param  udi			Unique Device Id
  *  @param  key			Name of the property
  *  @return			One of DBUS_TYPE_STRING, DBUS_TYPE_INT32,
- *				DBUS_TYPE_BOOL, DBUS_TYPE_DOUBLE or 
+ *				DBUS_TYPE_UINT64, DBUS_TYPE_BOOL, DBUS_TYPE_DOUBLE or 
  *				DBUS_TYPE_NIL if the property didn't exist.
  */
 int
@@ -936,6 +953,78 @@
 	return value;
 }
 
+/** Get the value of a property of type integer. 
+ *
+ *  @param  ctx                 The context for the connection to hald
+ *  @param  udi			Unique Device Id
+ *  @param  key			Name of the property
+ *  @return			64-bit unsigned integer
+ */
+dbus_uint64_t
+hal_device_get_property_uint64 (LibHalContext *ctx, 
+			     const char *udi, const char *key)
+{
+	DBusError error;
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	dbus_uint64_t value;
+
+	message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
+						"org.freedesktop.Hal.Device",
+						"GetPropertyInteger");
+	if (message == NULL) {
+		fprintf (stderr,
+			 "%s %d : Couldn't allocate D-BUS message\n",
+			 __FILE__, __LINE__);
+		return -1;
+	}
+
+	dbus_message_iter_init (message, &iter);
+	dbus_message_iter_append_string (&iter, key);
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (ctx->connection,
+							   message, -1,
+							   &error);
+	if (dbus_error_is_set (&error)) {
+		fprintf (stderr, "%s %d : Error sending msg: %s\n",
+			 __FILE__, __LINE__, error.message);
+		dbus_message_unref (message);
+		return -1;
+	}
+	if (reply == NULL) {
+		dbus_message_unref (message);
+		return -1;
+	}
+
+	dbus_message_iter_init (reply, &iter);
+
+	/* now analyze reply */
+	if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_NIL) {
+		/* property didn't exist */
+		fprintf (stderr,
+			 "%s %d : property '%s' for device '%s' does not "
+			 "exist\n", __FILE__, __LINE__, key, udi);
+		dbus_message_unref (message);
+		dbus_message_unref (reply);
+		return -1;
+	} else if (dbus_message_iter_get_arg_type (&iter) !=
+		   DBUS_TYPE_UINT64) {
+		fprintf (stderr,
+			 "%s %d : property '%s' for device '%s' is not "
+			 "of type integer\n", __FILE__, __LINE__, key,
+			 udi);
+		dbus_message_unref (message);
+		dbus_message_unref (reply);
+		return -1;
+	}
+	value = dbus_message_iter_get_uint64 (&iter);
+
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+	return value;
+}
+
 /** Get the value of a property of type double. 
  *
  *  @param  ctx                 The context for the connection to hald
@@ -1087,6 +1176,7 @@
 				int type,
 				const char *str_value,
 				dbus_int32_t int_value,
+				dbus_uint64_t uint64_value,
 				double double_value,
 				dbus_bool_t bool_value)
 {
@@ -1106,6 +1196,7 @@
 		method_name = "SetPropertyString";
 		break;
 	case DBUS_TYPE_INT32:
+	case DBUS_TYPE_UINT64:
 		method_name = "SetPropertyInteger";
 		break;
 	case DBUS_TYPE_DOUBLE:
@@ -1142,6 +1233,9 @@
 	case DBUS_TYPE_INT32:
 		dbus_message_iter_append_int32 (&iter, int_value);
 		break;
+	case DBUS_TYPE_UINT64:
+		dbus_message_iter_append_uint64 (&iter, uint64_value);
+		break;
 	case DBUS_TYPE_DOUBLE:
 		dbus_message_iter_append_double (&iter, double_value);
 		break;
@@ -1186,7 +1280,7 @@
 {
 	return hal_device_set_property_helper (ctx, udi, key,
 					       DBUS_TYPE_STRING,
-					       value, 0, 0.0f, FALSE);
+					       value, 0, 0, 0.0f, FALSE);
 }
 
 /** Set a property of type integer.
@@ -1205,7 +1299,26 @@
 {
 	return hal_device_set_property_helper (ctx, udi, key,
 					       DBUS_TYPE_INT32,
-					       NULL, value, 0.0f, FALSE);
+					       NULL, value, 0, 0.0f, FALSE);
+}
+
+/** Set a property of type integer.
+ *
+ *  @param  ctx                 The context for the connection to hald
+ *  @param  udi			Unique Device Id
+ *  @param  key			Name of the property
+ *  @param  value		Value of the property
+ *  @return			TRUE if the property was set, FALSE if
+ *				the device didn't exist or the property
+ *				had a different type.
+ */
+dbus_bool_t
+hal_device_set_property_uint64 (LibHalContext *ctx, const char *udi,
+			     const char *key, dbus_uint64_t value)
+{
+	return hal_device_set_property_helper (ctx, udi, key,
+					       DBUS_TYPE_UINT64,
+					       NULL, 0, value, 0.0f, FALSE);
 }
 
 /** Set a property of type double.
@@ -1224,7 +1337,7 @@
 {
 	return hal_device_set_property_helper (ctx, udi, key,
 					       DBUS_TYPE_DOUBLE,
-					       NULL, 0, value, FALSE);
+					       NULL, 0, 0, value, FALSE);
 }
 
 /** Set a property of type bool.
@@ -1243,7 +1356,7 @@
 {
 	return hal_device_set_property_helper (ctx, udi, key,
 					       DBUS_TYPE_BOOLEAN,
-					       NULL, 0, 0.0f, value);
+					       NULL, 0, 0, 0.0f, value);
 }
 
 
@@ -1261,7 +1374,7 @@
 {
 	return hal_device_set_property_helper (ctx, udi, key, DBUS_TYPE_NIL,	
 					       /* DBUS_TYPE_NIL means remove */
-					       NULL, 0, 0.0f, FALSE);
+					       NULL, 0, 0, 0.0f, FALSE);
 }
 
 
@@ -1747,6 +1860,11 @@
 				hal_psi_get_int (&i),
 				hal_psi_get_int (&i));
 			break;
+		case DBUS_TYPE_UINT64:
+			printf ("    %s = %lld = 0x%llx (uint64)\n", key,
+				hal_psi_get_uint64 (&i),
+				hal_psi_get_uint64 (&i));
+			break;
 		case DBUS_TYPE_BOOLEAN:
 			printf ("    %s = %s (bool)\n", key,
 				(hal_psi_get_bool (&i) ? "true" :

Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- libhal.h	29 Jul 2004 17:07:09 -0000	1.16
+++ libhal.h	1 Sep 2004 17:38:58 -0000	1.17
@@ -166,6 +166,10 @@
 					  const char *udi,
 					  const char *key);
 
+dbus_uint64_t hal_device_get_property_uint64 (LibHalContext *ctx, 
+					  const char *udi,
+					  const char *key);
+
 double hal_device_get_property_double (LibHalContext *ctx, 
 				       const char *udi,
 				       const char *key);
@@ -184,6 +188,11 @@
 					 const char *key,
 					 dbus_int32_t value);
 
+dbus_bool_t hal_device_set_property_uint64 (LibHalContext *ctx, 
+					 const char *udi,
+					 const char *key,
+					 dbus_uint64_t value);
+
 dbus_bool_t hal_device_set_property_double (LibHalContext *ctx, 
 					    const char *udi,
 					    const char *key,
@@ -242,6 +251,7 @@
 
 char *hal_psi_get_string (LibHalPropertySetIterator * iter);
 dbus_int32_t hal_psi_get_int (LibHalPropertySetIterator * iter);
+dbus_uint64_t hal_psi_get_uint64 (LibHalPropertySetIterator * iter);
 double hal_psi_get_double (LibHalPropertySetIterator * iter);
 dbus_bool_t hal_psi_get_bool (LibHalPropertySetIterator * iter);
 




More information about the hal-commit mailing list