hal/libhal libhal.c,1.58,1.59 libhal.h,1.34,1.35

David Zeuthen david at kemper.freedesktop.org
Thu Jun 8 19:19:34 PDT 2006


Update of /cvs/hal/hal/libhal
In directory kemper:/tmp/cvs-serv22208/libhal

Modified Files:
	libhal.c libhal.h 
Log Message:
2006-06-08  David Zeuthen  <davidz at redhat.com>

	Adds code so addons can claim interfaces and handle the methods on
	them in the addon daemon code. The example here is setting the LCD
	backlight on a Macbook Pro. Actual code for setting the backlight
	is based on code from Nicolas Boichat found on the mactel-linux
	mailing list.

	* hald/linux2/addons/addon-macbookpro-backlight.c: New file.

	* tools/hal-system-power-set-power-save: Bugfix so the right
	backend script is invoked.

	* libhal/libhal.h: Add prototype for libhal_device_claim_interface().

	* libhal/libhal.c (libhal_device_claim_interface): New function.

	* hald/linux2/addons/Makefile.am: Add rules for
	hald-addon-macbookpro-backlight. 

	* hald/hald_dbus.c (device_emit_condition): Only allow helpers,
	e.g.  only messages from direct connections.
	(device_claim_interface): New function to handle the
	ClaimInterface() method
	(do_introspect): Include introspection XML for ClaimInterface()
	and the introspection XML returned by ClaimInterface()
	invocations.
	(reply_from_fwd_message): New function
	(hald_dbus_filter_handle_methods): Handle ClaimInterface() and
	forward messages to the claimed interfaces on the appropriate
	objects.
	(local_server_message_handler): Forward signals from helpers onto
	the system message bus and DTRT when a helper disconnects.

	* hald/device_info.c (handle_spawn): New function. One can now do
	a <spawn udi="foo"> to spawn a child device. See the fdi file below
	for usage.
	(start, spawned_device_callouts_add_done, end):  Handle spawning
	device objects in response to <spawn>.

	* fdi/policy/10osvendor/10-laptop-panel-mgmt-policy.fdi: Add rules
	for matching the Macbook Pro in order to spawn a new device object
	with an addon for handing methods on the org.fd.H.D.LaptopPanel
	interface.

	* hal.conf.in: Allow some interfaces to also emit signals.

	* configure.in: Check for libpci so we can use it as an optional
	dependency. 



Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- libhal.c	25 Feb 2006 20:38:23 -0000	1.58
+++ libhal.c	9 Jun 2006 02:19:32 -0000	1.59
@@ -3303,7 +3303,7 @@
  * @condition_details: user-readable details of condition
  * @error: pointer to an initialized dbus error object for returning errors or NULL
  *
- * Emit a condition from a device.
+ * Emit a condition from a device. Can only be used from hald helpers.
  *
  * Returns: TRUE if condition successfully emitted,
  *                              FALSE otherwise
@@ -3365,3 +3365,76 @@
 
 	return result;	
 }
+
+/** 
+ * libhal_device_claim_interface:
+ * @ctx: the context for the connection to hald
+ * @udi: the Unique Device Id
+ * @interface_name: Name of interface to claim, e.g. org.freedesktop.Hal.Device.FoobarKindOfThing
+ * @introspection_xml: Introspection XML containing what would be inside the interface XML tag
+ * @error: pointer to an initialized dbus error object for returning errors or NULL
+ *
+ * Claim an interface for a device. All messages to this interface
+ * will be forwarded to the helper. Can only be used from hald
+ * helpers.
+ *
+ * Returns: TRUE if interface was claimed, FALSE otherwise
+ */
+dbus_bool_t
+libhal_device_claim_interface (LibHalContext *ctx,
+			       const char *udi,
+			       const char *interface_name,
+			       const char *introspection_xml,
+			       DBusError *error)
+{
+	LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+	
+	DBusMessage *message;
+	DBusMessageIter iter;
+	DBusMessageIter reply_iter;
+	DBusMessage *reply;
+	dbus_bool_t result;
+
+	message = dbus_message_new_method_call ("org.freedesktop.Hal",
+						udi,
+						"org.freedesktop.Hal.Device",
+						"ClaimInterface");
+
+	if (message == NULL) {
+		fprintf (stderr,
+			 "%s %d : Couldn't allocate D-BUS message\n",
+			 __FILE__, __LINE__);
+		return FALSE;
+	}
+
+	dbus_message_iter_init_append (message, &iter);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &interface_name);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &introspection_xml);
+	
+	reply = dbus_connection_send_with_reply_and_block (ctx->connection,
+							   message, -1,
+							   error);
+
+	if (dbus_error_is_set (error)) {
+		dbus_message_unref (message);
+		return FALSE;
+	}
+
+	dbus_message_unref (message);
+
+	if (reply == NULL)
+		return FALSE;
+
+	dbus_message_iter_init (reply, &reply_iter);
+	if (dbus_message_iter_get_arg_type (&reply_iter) !=
+		   DBUS_TYPE_BOOLEAN) {
+		dbus_message_unref (message);
+		dbus_message_unref (reply);
+		return FALSE;
+	}
+	dbus_message_iter_get_basic (&reply_iter, &result);
+
+	dbus_message_unref (reply);
+
+	return result;	
+}

Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- libhal.h	25 Feb 2006 20:54:16 -0000	1.34
+++ libhal.h	9 Jun 2006 02:19:32 -0000	1.35
@@ -526,13 +526,20 @@
 				   const char *udi,
 				   DBusError *error);
 
-/* Emit a condition from a device */
+/* Emit a condition from a device (for hald helpers only) */
 dbus_bool_t libhal_device_emit_condition (LibHalContext *ctx,
 					  const char *udi,
 					  const char *condition_name,
 					  const char *condition_details,
 					  DBusError *error);
 
+/* Claim an interface for a device (for hald helpers only) */
+dbus_bool_t libhal_device_claim_interface (LibHalContext *ctx,
+					   const char *udi,
+					   const char *interface_name,
+					   const char *introspection_xml,
+					   DBusError *error);
+
 
 #if defined(__cplusplus)
 }




More information about the hal-commit mailing list