hal: Branch 'master'
Danny Kukawka
dkukawka at kemper.freedesktop.org
Tue Aug 28 10:02:59 PDT 2007
hald/device.c | 66 +++++++++++++++++++++++++++++++----------
hald/device.h | 9 ++++-
hald/device_info.c | 6 +--
hald/freebsd/hf-usb.c | 2 -
hald/hald_dbus.c | 34 ++++++++++++++++-----
hald/hald_test.c | 4 +-
hald/linux/osspec.c | 2 -
hald/solaris/devinfo_storage.c | 4 +-
8 files changed, 93 insertions(+), 34 deletions(-)
New commits:
diff-tree 2948fca27b08642a03d9bee4c1659f72a79ae2f0 (from a55046077f803bb37121362cc506ed530b79283b)
Author: Danny Kukawka <danny.kukawka at web.de>
Date: Tue Aug 28 19:02:51 2007 +0200
fixed changeset handling for HAL_PROPERTY_TYPE_STRLIST
This patch fixes some problems with the workflow and signal handling in
changesets via libhal for HAL_PROPERTY_TYPE_STRLIST:
* If libhal_changeset_set_property_strlist() get currently used to add a
stringlist to HAL after call libhal_device_commit_changeset() for each
new entry of the list a 'PROPERTY_CHANGED' signal get emitted.
This seems to be wrong and make also no sence because you can't find
out what in the list was changed/added, since the signals get emitted
after the commit call where the list is already complete changed.
I changed this to commit the signal only one for each call of
libhal_changeset_set_property_strlist().
* If libhal_changeset_set_property_strlist() get currently used in the
code HAL use hal_device_property_strlist_clear() to clear the list for
the new list. This function also call hal_property_strlist_clear() which
doesn't work (which we already detected in March 2007) and cause some
times later a crash in HAL. I fixed this by remove the strlist property
from the hashtable and add an new empty property instead with the same
key.
diff --git a/hald/device.c b/hald/device.c
index d163078..9514c9d 100644
--- a/hald/device.c
+++ b/hald/device.c
@@ -355,7 +355,7 @@ hal_property_strlist_clear (HalProperty
}
g_slist_free (prop->v.strlist_value);
- return FALSE;
+ return TRUE;
}
@@ -598,9 +598,9 @@ merge_device_rewrite_cb (HalDevice *sour
{
GSList *l;
- hal_device_property_strlist_clear (ud->target, target_key);
+ hal_device_property_strlist_clear (ud->target, target_key, FALSE);
for (l = hal_property_get_strlist (p); l != NULL; l = l->next)
- hal_device_property_strlist_append (ud->target, target_key, l->data);
+ hal_device_property_strlist_append (ud->target, target_key, l->data, FALSE);
}
break;
@@ -1409,7 +1409,8 @@ hal_device_property_get_strlist_elem (Ha
gboolean
hal_device_property_strlist_append (HalDevice *device,
const char *key,
- const char *value)
+ const char *value,
+ gboolean changeset)
{
HalProperty *prop;
@@ -1421,9 +1422,10 @@ hal_device_property_strlist_append (HalD
return FALSE;
hal_property_strlist_append (prop, value);
-
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, FALSE);
+
+ if (!changeset)
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, FALSE);
} else {
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
@@ -1431,13 +1433,39 @@ hal_device_property_strlist_append (HalD
g_hash_table_insert (device->private->props, g_strdup (key), prop);
+ if (!changeset)
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
+ }
+
+ return TRUE;
+}
+
+gboolean
+hal_device_property_strlist_append_finish_changeset (HalDevice *device,
+ const char *key,
+ gboolean is_added){
+
+ HalProperty *prop;
+
+ /* check if property already exists */
+ prop = hal_device_property_find (device, key);
+
+ if (prop != NULL) {
+ if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
+ return FALSE;
+
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ key, FALSE, is_added);
+
+ } else {
+ return FALSE;
}
return TRUE;
}
+
gboolean
hal_device_property_strlist_prepend (HalDevice *device,
const char *key,
@@ -1497,7 +1525,8 @@ hal_device_property_strlist_remove_elem
gboolean
hal_device_property_strlist_clear (HalDevice *device,
- const char *key)
+ const char *key,
+ gboolean changeset)
{
HalProperty *prop;
@@ -1508,21 +1537,26 @@ hal_device_property_strlist_clear (HalDe
prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
g_hash_table_insert (device->private->props, g_strdup (key), prop);
- g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
- key, FALSE, TRUE);
+ if (!changeset)
+ g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
+ key, FALSE, TRUE);
return TRUE;
}
if (hal_property_get_type (prop) != HAL_PROPERTY_TYPE_STRLIST)
return FALSE;
- if (hal_property_strlist_clear (prop)) {
+ /* TODO: check why hal_property_strlist_clear (prop) not work */
+ g_hash_table_remove (device->private->props, key);
+ prop = hal_property_new (HAL_PROPERTY_TYPE_STRLIST);
+ g_hash_table_insert (device->private->props, g_strdup (key), prop);
+
+ if (!changeset) {
g_signal_emit (device, signals[PROPERTY_CHANGED], 0,
key, FALSE, FALSE);
- return TRUE;
}
-
- return FALSE;
+
+ return TRUE;
}
@@ -1672,7 +1706,7 @@ hal_device_acquire_lock (HalDevice *devi
goto out;
}
- hal_device_property_strlist_append (device, buf, sender);
+ hal_device_property_strlist_append (device, buf, sender, FALSE);
g_snprintf (buf, sizeof (buf), "info.named_locks.%s.locked", lock_name);
hal_device_property_set_bool (device, buf, TRUE);
diff --git a/hald/device.h b/hald/device.h
index 4141c63..a135d82 100644
--- a/hald/device.h
+++ b/hald/device.h
@@ -183,7 +183,11 @@ gboolean hal_device_property_set_st
GSList *value);
gboolean hal_device_property_strlist_append (HalDevice *device,
const char *key,
- const char *value);
+ const char *value,
+ gboolean changeset);
+gboolean hal_device_property_strlist_append_finish_changeset (HalDevice *device,
+ const char *key,
+ gboolean is_added);
gboolean hal_device_property_strlist_prepend (HalDevice *device,
const char *key,
const char *value);
@@ -191,7 +195,8 @@ gboolean hal_device_property_strlis
const char *key,
guint index);
gboolean hal_device_property_strlist_clear (HalDevice *device,
- const char *key);
+ const char *key,
+ gboolean changeset);
gboolean hal_device_property_strlist_add (HalDevice *device,
const char *key,
const char *value);
diff --git a/hald/device_info.c b/hald/device_info.c
index 194257c..8b28c1a 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -751,7 +751,7 @@ handle_merge (struct rule *rule, HalDevi
if (type == HAL_PROPERTY_TYPE_STRLIST || type == HAL_PROPERTY_TYPE_INVALID) {
hal_device_property_remove (d, key);
- hal_device_property_strlist_append (d, key, value);
+ hal_device_property_strlist_append (d, key, value, FALSE);
}
} else if (rule->type_merge == MERGE_INT32) {
@@ -811,7 +811,7 @@ handle_merge (struct rule *rule, HalDevi
}
if (rule->type_merge == MERGE_STRLIST) {
- hal_device_property_strlist_append (d, key, value);
+ hal_device_property_strlist_append (d, key, value, FALSE);
} else {
const char *existing_string;
@@ -881,7 +881,7 @@ handle_merge (struct rule *rule, HalDevi
if (!hal_device_has_property (d, key) ||
!hal_device_property_strlist_contains (d, key, value)) {
- hal_device_property_strlist_append (d, key, value);
+ hal_device_property_strlist_append (d, key, value, FALSE);
}
} else if (rule->rtype == RULE_REMOVE) {
diff --git a/hald/freebsd/hf-usb.c b/hald/freebsd/hf-usb.c
index b7991b5..48b8186 100644
--- a/hald/freebsd/hf-usb.c
+++ b/hald/freebsd/hf-usb.c
@@ -394,7 +394,7 @@ hf_usb_device_new (HalDevice *parent,
char *port;
port = g_strdup_printf("%i", di->udi_ports[i]);
- hal_device_property_strlist_append(device, "usb_device.freebsd.ports", port);
+ hal_device_property_strlist_append(device, "usb_device.freebsd.ports", port, FALSE);
g_free(port);
}
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 764da50..ddae65c 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -1212,22 +1212,40 @@ device_set_multiple_properties (DBusConn
switch (change_type) {
case DBUS_TYPE_ARRAY:
+ {
+ gboolean _error;
+ gboolean _added;
+
+ _error = FALSE;
+ _added = TRUE;
+
if (dbus_message_iter_get_element_type (&var_iter) != DBUS_TYPE_STRING) {
/* TODO: error */
}
dbus_message_iter_recurse (&var_iter, &array_iter);
- hal_device_property_strlist_clear (d, key);
+ if (hal_device_has_property(d, key)) {
+ if (hal_device_property_get_type(d, key) != HAL_PROPERTY_TYPE_STRLIST) {
+ _error = TRUE;
+ }
+ _added = FALSE;
+ }
+
+ hal_device_property_strlist_clear (d, key, TRUE);
while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) {
const char *v;
dbus_message_iter_get_basic (&array_iter, &v);
HAL_INFO ((" strlist elem %s -> %s", key, v));
- rc = hal_device_property_strlist_append (d, key, v);
+ rc = hal_device_property_strlist_append (d, key, v, TRUE);
dbus_message_iter_next (&array_iter);
}
+
+ if (!_error)
+ hal_device_property_strlist_append_finish_changeset(d, key, _added);
break;
+ }
case DBUS_TYPE_STRING:
{
const char *v;
@@ -1741,7 +1759,7 @@ device_string_list_append_prepend (DBusC
if (do_prepend)
ret = hal_device_property_strlist_prepend (d, key, value);
else
- ret = hal_device_property_strlist_append (d, key, value);
+ ret = hal_device_property_strlist_append (d, key, value, FALSE);
if (!ret) {
raise_property_type_error (connection, message, udi, key);
return DBUS_HANDLER_RESULT_HANDLED;
@@ -4667,12 +4685,14 @@ reply_from_fwd_message (DBusPendingCall
reply_from_addon = dbus_pending_call_steal_reply (pending_call);
reply = dbus_message_copy (reply_from_addon);
- dbus_message_set_destination (reply, dbus_message_get_sender (method_from_caller));
- dbus_message_set_reply_serial (reply, dbus_message_get_serial (method_from_caller));
+ if (reply != NULL) {
+ dbus_message_set_destination (reply, dbus_message_get_sender (method_from_caller));
+ dbus_message_set_reply_serial (reply, dbus_message_get_serial (method_from_caller));
- if (dbus_connection != NULL)
- dbus_connection_send (dbus_connection, reply, NULL);
+ if (dbus_connection != NULL)
+ dbus_connection_send (dbus_connection, reply, NULL);
+ }
dbus_message_unref (reply_from_addon);
dbus_message_unref (reply);
dbus_message_unref (method_from_caller);
diff --git a/hald/hald_test.c b/hald/hald_test.c
index 1929429..d3a3774 100644
--- a/hald/hald_test.c
+++ b/hald/hald_test.c
@@ -167,7 +167,7 @@ check_properties (void)
printf ("PASSED\n");
printf ("strlist: ");
- if (!hal_device_property_strlist_append (d, "test.strlist", "foostrlist0")) {
+ if (!hal_device_property_strlist_append (d, "test.strlist", "foostrlist0", FALSE)) {
printf ("FAILED00\n");
goto out;
}
@@ -184,7 +184,7 @@ check_properties (void)
goto out;
}
- if (!hal_device_property_strlist_append (d, "test.strlist", "foostrlist1")) {
+ if (!hal_device_property_strlist_append (d, "test.strlist", "foostrlist1", FALSE)) {
printf ("FAILED10\n");
goto out;
}
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 39ba0c0..b3bb44d 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -588,7 +588,7 @@ get_openfirmware_entry(HalDevice *d, cha
if (multivalue) {
gsize offset = 0;
while (offset < length) {
- hal_device_property_strlist_append(d, property, contents + offset);
+ hal_device_property_strlist_append(d, property, contents + offset, FALSE);
for (; offset < length - 1 && contents[offset] != '\0'; offset++)
;
offset++;
diff --git a/hald/solaris/devinfo_storage.c b/hald/solaris/devinfo_storage.c
index f7d6512..9181572 100644
--- a/hald/solaris/devinfo_storage.c
+++ b/hald/solaris/devinfo_storage.c
@@ -1619,10 +1619,10 @@ devinfo_storage_append_nickname (HalDevi
char buf[64];
if (media_num == 0) {
- hal_device_property_strlist_append (d, "storage.solaris.nicknames", media_type);
+ hal_device_property_strlist_append (d, "storage.solaris.nicknames", media_type, FALSE);
}
snprintf(buf, sizeof (buf), "%s%d", media_type, media_num);
- hal_device_property_strlist_append (d, "storage.solaris.nicknames", buf);
+ hal_device_property_strlist_append (d, "storage.solaris.nicknames", buf, FALSE);
}
static void
More information about the hal-commit
mailing list