wok-6.x annotate xorg-server-tinyX/stuff/xorg-server-tinyX-1.5.3-hal_parallel.u @ rev 3531

scim: Update to version 1.4.9
author Liu Peng <rocky@slitaz.org>
date Mon Jun 22 13:37:35 2009 +0800 (2009-06-22)
parents
children
rev   line source
jozee@3327 1 diff --git xorg-server-1.5.3/config/hal.c xorg-server-1.5.3/config/hal.c
jozee@3327 2 index 8dfbb07..36fa839 100644
jozee@3327 3 --- xorg-server-1.5.3/config/hal.c
jozee@3327 4 +++ xorg-server-1.5.3/config/hal.c
jozee@3327 5 @@ -467,11 +467,10 @@ disconnect_hook(void *data)
jozee@3327 6 info->system_bus = NULL;
jozee@3327 7 }
jozee@3327 8 -static void
jozee@3327 9 -connect_hook(DBusConnection *connection, void *data)
jozee@3327 10 +static BOOL
jozee@3327 11 +connect_and_register(DBusConnection *connection, struct config_hal_info *info)
jozee@3327 12 {
jozee@3327 13 DBusError error;
jozee@3327 14 - struct config_hal_info *info = data;
jozee@3327 15 char **devices;
jozee@3327 16 int num_devices, i;
jozee@3327 17 @@ -479,8 +478,10 @@ connect_hook(DBusConnection *connection, void *data)
jozee@3327 18 dbus_error_init(&error);
jozee@3327 19 - if (!info->hal_ctx)
jozee@3327 20 - info->hal_ctx = libhal_ctx_new();
jozee@3327 21 + if (info->hal_ctx)
jozee@3327 22 + return TRUE; /* already registered, pretend we did something */
jozee@3327 23 +
jozee@3327 24 + info->hal_ctx = libhal_ctx_new();
jozee@3327 25 if (!info->hal_ctx) {
jozee@3327 26 LogMessage(X_ERROR, "config/hal: couldn't create HAL context\n");
jozee@3327 27 goto out_err;
jozee@3327 28 @@ -512,7 +513,7 @@ connect_hook(DBusConnection *connection, void *data)
jozee@3327 29 dbus_error_free(&error);
jozee@3327 30 - return;
jozee@3327 31 + return TRUE;
jozee@3327 32 out_ctx2:
jozee@3327 33 if (!libhal_ctx_shutdown(info->hal_ctx, &error))
jozee@3327 34 @@ -525,6 +526,104 @@ out_err:
jozee@3327 35 info->hal_ctx = NULL;
jozee@3327 36 info->system_bus = NULL;
jozee@3327 37 + return FALSE;
jozee@3327 38 +}
jozee@3327 39 +
jozee@3327 40 +
jozee@3327 41 +/**
jozee@3327 42 + * Handle NewOwnerChanged signals to deal with HAL startup at X server runtime.
jozee@3327 43 + *
jozee@3327 44 + * NewOwnerChanged is send once when HAL shuts down, and once again when it
jozee@3327 45 + * comes back up. Message has three arguments, first is the name
jozee@3327 46 + * (org.freedesktop.Hal), the second one is the old owner, third one is new
jozee@3327 47 + * owner.
jozee@3327 48 + */
jozee@3327 49 +static DBusHandlerResult
jozee@3327 50 +ownerchanged_handler(DBusConnection *connection, DBusMessage *message, void *data)
jozee@3327 51 +{
jozee@3327 52 + int ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
jozee@3327 53 +
jozee@3327 54 + if (dbus_message_is_signal(message,
jozee@3327 55 + "org.freedesktop.DBus",
jozee@3327 56 + "NameOwnerChanged")) {
jozee@3327 57 + DBusError error;
jozee@3327 58 + char *name, *old_owner, *new_owner;
jozee@3327 59 +
jozee@3327 60 + dbus_error_init(&error);
jozee@3327 61 + dbus_message_get_args(message, &error,
jozee@3327 62 + DBUS_TYPE_STRING, &name,
jozee@3327 63 + DBUS_TYPE_STRING, &old_owner,
jozee@3327 64 + DBUS_TYPE_STRING, &new_owner,
jozee@3327 65 + DBUS_TYPE_INVALID);
jozee@3327 66 +
jozee@3327 67 + if (dbus_error_is_set(&error)) {
jozee@3327 68 + ErrorF("[config/hal] failed to get NameOwnerChanged args: %s (%s)\n",
jozee@3327 69 + error.name, error.message);
jozee@3327 70 + } else if (name && strcmp(name, "org.freedesktop.Hal") == 0) {
jozee@3327 71 +
jozee@3327 72 + if (!old_owner || !strlen(old_owner)) {
jozee@3327 73 + DebugF("[config/hal] HAL startup detected.\n");
jozee@3327 74 + if (connect_and_register(connection, (struct config_hal_info*)data))
jozee@3327 75 + dbus_connection_unregister_object_path(connection,
jozee@3327 76 + "/org/freedesktop/DBus");
jozee@3327 77 + else
jozee@3327 78 + ErrorF("[config/hal] Failed to connect to HAL bus.\n");
jozee@3327 79 + }
jozee@3327 80 +
jozee@3327 81 + ret = DBUS_HANDLER_RESULT_HANDLED;
jozee@3327 82 + }
jozee@3327 83 + dbus_error_free(&error);
jozee@3327 84 + }
jozee@3327 85 +
jozee@3327 86 + return ret;
jozee@3327 87 +}
jozee@3327 88 +
jozee@3327 89 +/**
jozee@3327 90 + * Register a handler for the NameOwnerChanged signal.
jozee@3327 91 + */
jozee@3327 92 +static BOOL
jozee@3327 93 +listen_for_startup(DBusConnection *connection, void *data)
jozee@3327 94 +{
jozee@3327 95 + DBusObjectPathVTable vtable = { .message_function = ownerchanged_handler, };
jozee@3327 96 + DBusError error;
jozee@3327 97 + const char MATCH_RULE[] = "sender='org.freedesktop.DBus',"
jozee@3327 98 + "interface='org.freedesktop.DBus',"
jozee@3327 99 + "type='signal',"
jozee@3327 100 + "path='/org/freedesktop/DBus',"
jozee@3327 101 + "member='NameOwnerChanged'";
jozee@3327 102 + int rc = FALSE;
jozee@3327 103 +
jozee@3327 104 + dbus_error_init(&error);
jozee@3327 105 + dbus_bus_add_match(connection, MATCH_RULE, &error);
jozee@3327 106 + if (!dbus_error_is_set(&error)) {
jozee@3327 107 + if (dbus_connection_register_object_path(connection,
jozee@3327 108 + "/org/freedesktop/DBus",
jozee@3327 109 + &vtable,
jozee@3327 110 + data))
jozee@3327 111 + rc = TRUE;
jozee@3327 112 + else
jozee@3327 113 + ErrorF("[config/hal] cannot register object path.\n");
jozee@3327 114 + } else {
jozee@3327 115 + ErrorF("[config/hal] couldn't add match rule: %s (%s)\n", error.name,
jozee@3327 116 + error.message);
jozee@3327 117 + ErrorF("[config/hal] cannot detect a HAL startup.\n");
jozee@3327 118 + }
jozee@3327 119 +
jozee@3327 120 + dbus_error_free(&error);
jozee@3327 121 +
jozee@3327 122 + return rc;
jozee@3327 123 +}
jozee@3327 124 +
jozee@3327 125 +static void
jozee@3327 126 +connect_hook(DBusConnection *connection, void *data)
jozee@3327 127 +{
jozee@3327 128 + struct config_hal_info *info = data;
jozee@3327 129 +
jozee@3327 130 + if (listen_for_startup(connection, data) &&
jozee@3327 131 + connect_and_register(connection, info))
jozee@3327 132 + dbus_connection_unregister_object_path(connection,
jozee@3327 133 + "/org/freedesktop/DBus");
jozee@3327 134 +
jozee@3327 135 return;
jozee@3327 136 }