diff options
author | David Zeuthen <david@fubar.dk> | 2006-06-09 02:19:32 +0000 |
---|---|---|
committer | David Zeuthen <david@fubar.dk> | 2006-06-09 02:19:32 +0000 |
commit | 5234473b96de6e1c2961ac061cb6c2cd19a293f4 (patch) | |
tree | 3290fe91200485a5fde983d08447520a408b38f6 /libhal | |
parent | 97eacd2fa6f57369c5a6bf924dc3ac6a836e02c8 (diff) |
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.
New file.
Bugfix so the right backend script is invoked.
Add prototype for libhal_device_claim_interface().
New function.
Add rules for hald-addon-macbookpro-backlight.
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.
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>.
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.
Allow some interfaces to also emit signals.
Check for libpci so we can use it as an optional dependency.
Diffstat (limited to 'libhal')
-rw-r--r-- | libhal/libhal.c | 75 | ||||
-rw-r--r-- | libhal/libhal.h | 9 |
2 files changed, 82 insertions, 2 deletions
diff --git a/libhal/libhal.c b/libhal/libhal.c index 3205387b..7c315867 100644 --- a/libhal/libhal.c +++ b/libhal/libhal.c @@ -3303,7 +3303,7 @@ libhal_device_reprobe (LibHalContext *ctx, const char *udi, DBusError *error) * @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 @@ dbus_bool_t libhal_device_emit_condition (LibHalContext *ctx, 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; +} diff --git a/libhal/libhal.h b/libhal/libhal.h index 70cac795..7e227ab1 100644 --- a/libhal/libhal.h +++ b/libhal/libhal.h @@ -526,13 +526,20 @@ dbus_bool_t libhal_device_reprobe (LibHalContext *ctx, 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) } |