+static void
+handle_addition (CSpiApplication*app, CACHE_ADDITION *ca)
+{
+ gint i;
+ GList *new_list;
+
+ Accessible *a = ref_accessible (app, ca->path);
+ /* Note: children don't hold refs for their parents or vice versa */
+ a->parent = ref_accessible (app, ca->parent);
+ if (a->parent) cspi_object_unref (a->parent);
+ if (a->children)
+ {
+ g_list_free (a->children);
+ a->children = NULL;
+ }
+ for (i = 0; i < ca->children->len; i++)
+ {
+ const char *child_path = g_array_index (ca->children, const char *, i);
+ Accessible *child = ref_accessible (app, child_path);
+ new_list = g_list_append (a->children, child);
+ if (new_list) a->children = new_list;
+ cspi_object_unref (child);
+ }
+ a->interfaces = 0;
+ for (i = 0; i < ca->interfaces->len; i++)
+ {
+ const char *iface = g_array_index (ca->interfaces, const char *, i);
+ if (!strcmp (iface, "org.freedesktop.DBus.Introspectable")) continue;
+ gint n = get_iface_num (iface);
+ if (n == -1)
+ {
+ g_warning ("Unknown interface %s", iface);
+ }
+ else a->interfaces |= (1 << n);
+ g_free (iface);
+ }
+ if (a->name) g_free (a->name);
+ a->name = ca->name;
+ a->role = ca->role;
+ if (a->description) g_free (a->description);
+ a->description = ca->description;
+ a->states = spi_state_set_cache_new (ca->state_bitflags);
+ g_array_free (ca->interfaces, TRUE);
+ g_array_free (ca->children, TRUE);
+ /* spi_state_set_cache_new frees state_bitflags */
+ /* This is a bit of a hack since ref_accessible sets ref_count to 2
+ * for a new object, one of the refs being for the cache */
+ cspi_object_unref (a);
+}
+