*/
#include "atspi-private.h"
+#include "atspi-accessible-private.h"
#include <string.h>
#include <ctype.h>
AtspiEventListenerCB callback;
void *user_data;
GDestroyNotify callback_destroyed;
+ char *event_type;
char *category;
char *name;
char *detail;
+ GArray *properties;
} EventListenerEntry;
G_DEFINE_TYPE (AtspiEventListener, atspi_event_listener, G_TYPE_OBJECT)
}
static void
-remove_datum (const AtspiEvent *event, void *user_data)
+remove_datum (AtspiEvent *event, void *user_data)
{
AtspiEventListenerSimpleCB cb = user_data;
cb (event);
/**
* atspi_event_listener_new:
- * @callback: (scope notified): An #AtspiEventListenerSimpleCB to be called
+ * @callback: (scope notified): An #AtspiEventListenerCB to be called
* when an event is fired.
* @user_data: (closure): data to pass to the callback.
* @callback_destroyed: A #GDestroyNotify called when the listener is freed
}
/**
- * atspi_event_listener_new_simple:
+ * atspi_event_listener_new_simple: (skip)
* @callback: (scope notified): An #AtspiEventListenerSimpleCB to be called
* when an event is fired.
* @callback_destroyed: A #GDestroyNotify called when the listener is freed
return;
child = g_value_get_object (&event->any_data);
+ if (child)
+ return;
if (!strncmp (event->type, "object:children-changed:add", 27))
{
- if (g_list_find (event->source->children, child))
+ g_ptr_array_remove (event->source->children, child); /* just to be safe */
+ if (event->detail1 < 0 || event->detail1 > event->source->children->len)
+ {
+ event->source->cached_properties &= ~ATSPI_CACHE_CHILDREN;
return;
- GList *new_list = g_list_insert (event->source->children, g_object_ref (child), event->detail1);
- if (new_list)
- event->source->children = new_list;
+ }
+ /* Unfortunately, there's no g_ptr_array_insert or similar */
+ g_ptr_array_add (event->source->children, NULL);
+ memmove (event->source->children->pdata + event->detail1 + 1,
+ event->source->children->pdata + event->detail1,
+ (event->source->children->len - event->detail1 - 1) * sizeof (gpointer));
+ g_ptr_array_index (event->source->children, event->detail1) = g_object_ref (child);
}
- else if (g_list_find (event->source->children, child))
+ else
{
- event->source->children = g_list_remove (event->source->children, child);
+ g_ptr_array_remove (event->source->children, child);
if (child == child->parent.app->root)
g_object_run_dispose (G_OBJECT (child->parent.app));
- g_object_unref (child);
}
}
event->source->cached_properties &= ~ATSPI_CACHE_DESCRIPTION;
}
}
+ else if (!strcmp (event->type, "object:property-change:accessible-role"))
+ {
+ if (G_VALUE_HOLDS_INT (&event->any_data))
+ {
+ event->source->role = g_value_get_int (&event->any_data);
+ _atspi_accessible_add_cache (event->source, ATSPI_CACHE_ROLE);
+ }
+ else
+ {
+ event->source->cached_properties &= ~ATSPI_CACHE_ROLE;
+ }
+ }
}
static void
if (tmp == NULL) return FALSE;
category = strtok_r (tmp, ":", &saveptr);
if (category) category = g_strdup (category);
- if (!category) goto oom;
name = strtok_r (NULL, ":", &saveptr);
if (name)
{
name = g_strdup (name);
- if (!name) goto oom;
detail = strtok_r (NULL, ":", &saveptr);
if (detail) detail = g_strdup (detail);
}
else if (detail) g_free (detail);
g_free (tmp);
return TRUE;
-oom:
- if (tmp) g_free (tmp);
- if (category) g_free (category);
- if (name) g_free (name);
- if (detail) g_free (detail);
- return FALSE;
}
static void
listener_entry_free (EventListenerEntry *e)
{
gpointer callback = (e->callback == remove_datum ? (gpointer)e->user_data : (gpointer)e->callback);
+ g_free (e->event_type);
g_free (e->category);
g_free (e->name);
if (e->detail) g_free (e->detail);
}
/**
+ * atspi_event_listener_register_full:
+ * @listener: The #AtspiEventListener to register against an event type.
+ * @event_type: a character string indicating the type of events for which
+ * notification is requested. See #atspi_event_listener_register
+ * for a description of the format and legal event types.
+* @properties: (element-type gchar*) (transfer none) (allow-none): a list of
+ * properties that should be sent along with the event. The
+ * properties are valued for the duration of the event callback.k
+ * TODO: Document.
+ *
+ * Adds an in-process callback function to an existing #AtspiEventListener.
+ *
+ * Returns: #TRUE if successful, otherwise #FALSE.
+ **/
+gboolean
+atspi_event_listener_register_full (AtspiEventListener *listener,
+ const gchar *event_type,
+ GArray *properties,
+ GError **error)
+{
+ /* TODO: Keep track of which events have been registered, so that we
+ * deregister all of them when the event listener is destroyed */
+
+ return atspi_event_listener_register_from_callback_full (listener->callback,
+ listener->user_data,
+ listener->cb_destroyed,
+ event_type,
+ properties,
+ error);
+}
+
+static gboolean
+notify_event_registered (EventListenerEntry *e)
+{
+
+ if (e->properties)
+ dbind_method_call_reentrant (_atspi_bus (), atspi_bus_registry,
+ atspi_path_registry,
+ atspi_interface_registry,
+ "RegisterEvent",
+ NULL, "sas", e->event_type,
+ e->properties);
+ else
+ dbind_method_call_reentrant (_atspi_bus (), atspi_bus_registry,
+ atspi_path_registry,
+ atspi_interface_registry,
+ "RegisterEvent",
+ NULL, "s", e->event_type);
+
+ return TRUE;
+}
+
+/**
* atspi_event_listener_register_from_callback:
* @callback: (scope notified): the #AtspiEventListenerCB to be registered
* against an event type.
const gchar *event_type,
GError **error)
{
+ return atspi_event_listener_register_from_callback_full (callback,
+ user_data,
+ callback_destroyed,
+ event_type, NULL,
+ error);
+}
+
+static GArray *
+copy_event_properties (GArray *src)
+{
+ gint i;
+
+ GArray *dst = g_array_new (FALSE, FALSE, sizeof (char *));
+
+ if (!src)
+ return dst;
+ for (i = 0; i < src->len; i++)
+ {
+ gchar *dup = g_strdup (g_array_index (src, char *, i));
+ g_array_append_val (dst, dup);
+ }
+ return dst;
+}
+
+gboolean
+atspi_event_listener_register_from_callback_full (AtspiEventListenerCB callback,
+ void *user_data,
+ GDestroyNotify callback_destroyed,
+ const gchar *event_type,
+ GArray *properties,
+ GError **error)
+{
EventListenerEntry *e;
DBusError d_error;
- GList *new_list;
- DBusMessage *message, *reply;
GPtrArray *matchrule_array;
gint i;
}
e = g_new (EventListenerEntry, 1);
+ e->event_type = g_strdup (event_type);
e->callback = callback;
e->user_data = user_data;
e->callback_destroyed = callback_destroyed;
g_free (e);
return FALSE;
}
- new_list = g_list_prepend (event_listeners, e);
- if (!new_list)
- {
- listener_entry_free (e);
- return FALSE;
- }
- event_listeners = new_list;
- dbus_error_init (&d_error);
+ e->properties = copy_event_properties (properties);
+ event_listeners = g_list_prepend (event_listeners, e);
for (i = 0; i < matchrule_array->len; i++)
{
char *matchrule = g_ptr_array_index (matchrule_array, i);
+ dbus_error_init (&d_error);
dbus_bus_add_match (_atspi_bus(), matchrule, &d_error);
+ if (dbus_error_is_set (&d_error))
+ {
+ g_warning ("Atspi: Adding match: %s", d_error.message);
+ dbus_error_free (&d_error);
+ /* TODO: Set error */
+ }
+
g_free (matchrule);
}
g_ptr_array_free (matchrule_array, TRUE);
- if (d_error.message)
- {
- g_warning ("Atspi: Adding match: %s", d_error.message);
- /* TODO: Set error */
- }
-
- dbus_error_init (&d_error);
- message = dbus_message_new_method_call (atspi_bus_registry,
- atspi_path_registry,
- atspi_interface_registry,
- "RegisterEvent");
- if (!message)
- return FALSE;
- dbus_message_append_args (message, DBUS_TYPE_STRING, &event_type, DBUS_TYPE_INVALID);
- reply = _atspi_dbus_send_with_reply_and_block (message, error);
- if (reply)
- dbus_message_unref (reply);
+ notify_event_registered (e);
return TRUE;
}
+void
+_atspi_reregister_event_listeners ()
+{
+ GList *l;
+ EventListenerEntry *e;
+
+ for (l = event_listeners; l; l = l->next)
+ {
+ e = l->data;
+ notify_event_registered (e);
+ }
+}
+
/**
- * atspi_event_listener_register_no_data:
+ * atspi_event_listener_register_no_data: (skip)
* @callback: (scope notified): the #AtspiEventListenerSimpleCB to be
* registered against an event type.
* @callback_destroyed: A #GDestroyNotify called when the callback is destroyed.
is_superset (detail, e->detail))
{
gboolean need_replace;
- DBusError d_error;
DBusMessage *message, *reply;
need_replace = (l == event_listeners);
l = g_list_remove (l, e);
if (need_replace)
event_listeners = l;
- dbus_error_init (&d_error);
- for (i = 0; i < matchrule_array->len; i++)
- {
- char *matchrule = g_ptr_array_index (matchrule_array, i);
- dbus_bus_remove_match (_atspi_bus(), matchrule, &d_error);
- }
- dbus_error_init (&d_error);
+ for (i = 0; i < matchrule_array->len; i++)
+ {
+ char *matchrule = g_ptr_array_index (matchrule_array, i);
+ dbus_bus_remove_match (_atspi_bus(), matchrule, NULL);
+ }
message = dbus_message_new_method_call (atspi_bus_registry,
atspi_path_registry,
atspi_interface_registry,
}
/**
- * atspi_event_listener_deregister_no_data:
+ * atspi_event_listener_deregister_no_data: (skip)
* @callback: (scope call): the #AtspiEventListenerSimpleCB registered against
* an event type.
* @event_type: a string specifying the event type for which this
if (!listener_detail)
return TRUE;
+ if (!event_detail)
+ return (listener_detail ? FALSE : TRUE);
+
return !(listener_detail [strcspn (listener_detail, ":")] == '\0'
? strncmp (listener_detail, event_detail,
strcspn (event_detail, ":"))
{
char *category, *name, *detail;
GList *l;
+ GList *called_listeners = NULL;
/* Ensure that the value is set to avoid a Python exception */
/* TODO: Figure out how to do this without using a private field */
(entry->name == NULL || !strcmp (name, entry->name)) &&
detail_matches_listener (detail, entry->detail))
{
+ GList *l2;
+ for (l2 = called_listeners; l2; l2 = l2->next)
+ {
+ EventListenerEntry *e2 = l2->data;
+ if (entry->callback == e2->callback && entry->user_data == e2->user_data)
+ break;
+ }
+ if (!l2)
+ {
entry->callback (atspi_event_copy (e), entry->user_data);
+ called_listeners = g_list_prepend (called_listeners, entry);
+ }
}
}
if (detail) g_free (detail);
g_free (name);
g_free (category);
+ g_list_free (called_listeners);
}
DBusHandlerResult
AtspiEvent e;
dbus_int32_t detail1, detail2;
char *p;
+ GHashTable *cache = NULL;
- if (strcmp (signature, "siiv(so)") != 0)
+ if (strcmp (signature, "siiv(so)") != 0 &&
+ strcmp (signature, "siiva{sv}") != 0)
{
g_warning ("Got invalid signature %s for signal %s from interface %s\n", signature, member, category);
return DBUS_HANDLER_RESULT_HANDLED;
}
e.type = converted_type;
e.source = _atspi_ref_accessible (dbus_message_get_sender(message), dbus_message_get_path(message));
+ if (e.source == NULL)
+ {
+ g_warning ("Got no valid source accessible for signal for signal %s from interface %s\n", member, category);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
dbus_message_iter_recurse (&iter, &iter_variant);
switch (dbus_message_iter_get_arg_type (&iter_variant))
accessible = _atspi_dbus_return_accessible_from_iter (&iter_variant);
g_value_init (&e.any_data, ATSPI_TYPE_ACCESSIBLE);
g_value_set_instance (&e.any_data, accessible);
- g_object_unref (accessible); /* value now owns it */
+ if (accessible)
+ g_object_unref (accessible); /* value now owns it */
}
break;
}
break;
}
+ dbus_message_iter_next (&iter);
+ if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY)
+ {
+ /* new form -- parse properties sent with event */
+ cache = _atspi_dbus_update_cache_from_dict (e.source, &iter);
+ }
+
if (!strncmp (e.type, "object:children-changed", 23))
{
cache_process_children_changed (&e);
{
cache_process_state_changed (&e);
}
+ else if (!strncmp (e.type, "focus", 5))
+ {
+ /* BGO#663992 - TODO: figure out the real problem */
+ e.source->cached_properties &= ~(ATSPI_CACHE_STATES);
+ }
_atspi_send_event (&e);
+ if (cache)
+ _atspi_accessible_unref_cache (e.source);
+
g_free (converted_type);
g_free (name);
g_free (detail);