hal/libhal libhal.c,1.25,1.26 libhal.h,1.17,1.18
Joe Shaw
joe at freedesktop.org
Fri Sep 17 10:05:50 PDT 2004
Update of /cvs/hal/hal/libhal
In directory gabe:/tmp/cvs-serv18110/libhal
Modified Files:
libhal.c libhal.h
Log Message:
2004-09-17 Joe Shaw <joeshaw at novell.com>
* doc/spec/hal-spec.xml.in: Add the Lock and Unlock methods to the
spec.
* hald/hald_dbus.c (raise_device_not_locked,
raise_device_already_locked): New errors for the locking methods.
(device_query_capability): Change the parsing to split up caps on
spaces rather than doing a substring match.
(device_lock): Implements the Lock dbus method, which grabs an
advisory lock on a device.
(device_unlock): Implements the Unlock dbus method.
(service_deleted): Callback which releases locks when the locking
service quits.
(filter_function): Add a ServiceDeleted handler, check for Lock
and Unlock methods.
(hald_dbus_init): Add a match for the ServiceDeleted signal so we
can see when things disconnect from the bus.
* libhal/libhal.c (hal_device_lock): Added. Takes an advisory
lock for a device.
(hal_device_unlock): Releases the lock.
Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- libhal.c 1 Sep 2004 17:38:58 -0000 1.25
+++ libhal.c 17 Sep 2004 17:05:48 -0000 1.26
@@ -1377,6 +1377,131 @@
NULL, 0, 0, 0.0f, FALSE);
}
+/** Take an advisory lock on the device.
+ *
+ * @param ctx The context for the connection to hald
+ * @param udi Unique Device Id
+ * @param reason_to_lock A user-presentable reason why the device
+ * is locked.l
+ * @param reason_why_locked A pointer to store the reason why the
+ * device cannot be locked on failure, or
+ * NULL
+ * @return TRUE if the lock was obtained, FALSE
+ * otherwise
+ *
+ */
+dbus_bool_t
+hal_device_lock (LibHalContext *ctx,
+ const char *udi,
+ const char *reason_to_lock,
+ char **reason_why_locked)
+{
+ DBusMessage *message;
+ DBusMessageIter iter;
+ DBusError error;
+ DBusMessage *reply;
+
+ if (reason_why_locked != NULL)
+ *reason_why_locked = NULL;
+
+ message = dbus_message_new_method_call ("org.freedesktop.Hal",
+ udi,
+ "org.freedesktop.Hal.Device",
+ "Lock");
+
+ if (message == NULL) {
+ fprintf (stderr,
+ "%s %d : Couldn't allocate D-BUS message\n",
+ __FILE__, __LINE__);
+ return FALSE;
+ }
+
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_append_string (&iter, reason_to_lock);
+
+ dbus_error_init (&error);
+ reply = dbus_connection_send_with_reply_and_block (ctx->connection,
+ message, -1,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ if (strcmp (error.name,
+ "org.freedesktop.Hal.DeviceAlreadyLocked") == 0) {
+ if (reason_why_locked != NULL) {
+ *reason_why_locked =
+ dbus_malloc0 (strlen (error.message) + 1);
+ strcpy (*reason_why_locked, error.message);
+ }
+ } else {
+ fprintf (stderr, "%s %d: %s raised\n\"%s\"\n\n",
+ __FILE__, __LINE__, error.name,
+ error.message);
+ }
+
+ dbus_message_unref (message);
+ return FALSE;
+ }
+
+ dbus_message_unref (message);
+
+ if (reply == NULL)
+ return FALSE;
+
+ dbus_message_unref (reply);
+
+ return TRUE;
+}
+
+/** Release an advisory lock on the device.
+ *
+ * @param ctx The context for the connection to hald
+ * @param udi Unique Device Id
+ * @return TRUE if the device was successfully unlocked,
+ * FALSE otherwise
+ *
+ */
+dbus_bool_t
+hal_device_unlock (LibHalContext *ctx,
+ const char *udi)
+{
+ DBusMessage *message;
+ DBusError error;
+ DBusMessage *reply;
+
+ message = dbus_message_new_method_call ("org.freedesktop.Hal",
+ udi,
+ "org.freedesktop.Hal.Device",
+ "Unlock");
+
+ if (message == NULL) {
+ fprintf (stderr,
+ "%s %d : Couldn't allocate D-BUS message\n",
+ __FILE__, __LINE__);
+ return FALSE;
+ }
+
+ 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: %s raised\n\"%s\"\n\n", __FILE__,
+ __LINE__, error.name, error.message);
+ dbus_message_unref (message);
+ return FALSE;
+ }
+
+ dbus_message_unref (message);
+
+ if (reply == NULL)
+ return FALSE;
+
+ dbus_message_unref (reply);
+
+ return TRUE;
+}
+
/** Create a new device object which will be hidden from applications
* until the CommitToGdl(), ie. hal_agent_commit_to_gdl(), method is called.
Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- libhal.h 1 Sep 2004 17:38:58 -0000 1.17
+++ libhal.h 17 Sep 2004 17:05:48 -0000 1.18
@@ -297,6 +297,14 @@
int hal_device_remove_property_watch (LibHalContext *ctx,
const char *udi);
+dbus_bool_t hal_device_lock (LibHalContext *ctx,
+ const char *udi,
+ const char *reason_to_lock,
+ char **reason_why_locked);
+
+dbus_bool_t hal_device_unlock (LibHalContext *ctx,
+ const char *udi);
+
/** @} */
#if defined(__cplusplus)
More information about the hal-commit
mailing list