2.34.0
[platform/upstream/at-spi2-core.git] / atspi / atspi-device-listener.c
index 6f7d9cf..8e04c41 100644 (file)
@@ -7,19 +7,19 @@
  * Copyright 2010, 2011 Novell, Inc.
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #include "atspi-private.h"
@@ -115,7 +115,7 @@ id_is_free (guint id)
 }
 
 static AtspiDeviceEvent *
-atspi_device_event_copy (AtspiDeviceEvent *src)
+atspi_device_event_copy (const AtspiDeviceEvent *src)
 {
   AtspiDeviceEvent *dst = g_new0 (AtspiDeviceEvent, 1);
   dst->type = src->type;
@@ -164,14 +164,12 @@ atspi_device_event_dispatch (AtspiDeviceListener               *listener,
 static void
 atspi_device_listener_init (AtspiDeviceListener *listener)
 {
-  GList *new_list;
 
   do
   {
     listener->id = listener_id++;
   } while (!id_is_free (listener->id));
-  new_list = g_list_append (device_listeners, listener);
-  if (new_list) device_listeners = new_list;
+  device_listeners = g_list_append (device_listeners, listener);
 }
 
 static void
@@ -211,9 +209,9 @@ G_DEFINE_TYPE (AtspiDeviceListener, atspi_device_listener,
  * @user_data: (closure): a pointer to data which will be passed to the
  * callback when invoked.
  * @callback_destroyed: A #GDestroyNotify called when the listener is freed
- * and data associated with the callback should be freed.  Can be NULL.
+ * and data associated with the callback should be freed. It can be NULL.
  *
- * Create a new #AtspiDeviceListener with a specified callback function.
+ * Creates a new #AtspiDeviceListener with a specified callback function.
  *
  * Returns: (transfer full): a pointer to a newly-created #AtspiDeviceListener.
  *
@@ -232,14 +230,15 @@ atspi_device_listener_new (AtspiDeviceListenerCB callback,
 }
 
 /**
- * atspi_device_listener_new_simple: (skip):
+ * atspi_device_listener_new_simple: (skip)
  * @callback: (scope notified): an #AtspiDeviceListenerCB callback function,
  *            or NULL.
  * @callback_destroyed: A #GDestroyNotify called when the listener is freed
- * and data associated with the callback should be freed.  Can be NULL.
+ * and data associated with the callback should be freed.  It an be NULL.
  *
- * Create a new #AtspiDeviceListener with a specified callback function.
- * Like atspi_device_listener_new, but callback takes no user data.
+ * Creates a new #AtspiDeviceListener with a specified callback function.
+ * This method is similar to #atspi_device_listener_new, but callback
+ * takes no user data.
  *
  * Returns: a pointer to a newly-created #AtspiDeviceListener.
  *
@@ -248,21 +247,19 @@ AtspiDeviceListener *
 atspi_device_listener_new_simple (AtspiDeviceListenerSimpleCB callback,
                            GDestroyNotify callback_destroyed)
 {
-  return atspi_device_listener_new (device_remove_datum, callback_destroyed, callback);
+  return atspi_device_listener_new (device_remove_datum, callback, callback_destroyed);
 }
 
 /**
  * atspi_device_listener_add_callback:
  * @listener: the #AtspiDeviceListener instance to modify.
  * @callback: (scope notified): an #AtspiDeviceListenerCB function pointer.
- * @user_data: (closure): a pointer to data which will be passed to the
- *             callback when invoked.
  * @callback_destroyed: A #GDestroyNotify called when the listener is freed
- * and data associated with the callback should be freed.  Can be NULL.
- *
- * Add an in-process callback function to an existing #AtspiDeviceListener.
+ * and data associated with the callback should be freed. It can be NULL.
+ * @user_data: (closure): a pointer to data which will be passed to the
+ *             callback when invoked. 
  *
- * Returns: #TRUE if successful, otherwise #FALSE.
+ * Adds an in-process callback function to an existing #AtspiDeviceListener.
  *
  **/
 void
@@ -277,13 +274,7 @@ atspi_device_listener_add_callback (AtspiDeviceListener  *listener,
   new_handler = device_event_handler_new (callback,
                                           callback_destroyed, user_data);
 
-  if (new_handler)
-  {
-    GList *new_list;
-    new_list = g_list_prepend (listener->callbacks, new_handler);
-    if (new_list)
-      listener->callbacks = new_list;
-  }
+  listener->callbacks = g_list_prepend (listener->callbacks, new_handler);
 }
 
 /**
@@ -291,9 +282,8 @@ atspi_device_listener_add_callback (AtspiDeviceListener  *listener,
  * @listener: the #AtspiDeviceListener instance to modify.
  * @callback: (scope call): an #AtspiDeviceListenerCB function pointer.
  *
- * Remove an in-process callback function from an existing #AtspiDeviceListener.
- *
- * Returns: #TRUE if successful, otherwise #FALSE.
+ * Removes an in-process callback function from an existing 
+ * #AtspiDeviceListener.
  *
  **/
 void
@@ -346,11 +336,8 @@ read_device_event_from_iter (DBusMessageIter *iter, AtspiDeviceEvent *event)
   event->is_text = is_text;
 }
 
-/*
- * atspi_dbus_handle_DeviceEvent: (skip)
- */
 DBusHandlerResult
-atspi_dbus_handle_DeviceEvent (DBusConnection *bus, DBusMessage *message, void *data)
+_atspi_dbus_handle_DeviceEvent (DBusConnection *bus, DBusMessage *message, void *data)
 {
   const char *path = dbus_message_get_path (message);
   int id;
@@ -364,13 +351,13 @@ atspi_dbus_handle_DeviceEvent (DBusConnection *bus, DBusMessage *message, void *
 
   if (strcmp (dbus_message_get_signature (message), "(uiuuisb)") != 0)
   {
-    g_warning ("Atspi: Unknown signature for an event");
+    g_warning ("AT-SPI: Unknown signature for an event");
     goto done;
   }
 
   if (sscanf (path, "/org/a11y/atspi/listeners/%d", &id) != 1)
   {
-    g_warning ("Atspi: Bad listener path: %s\n", path);
+    g_warning ("AT-SPI: Bad listener path: %s\n", path);
     goto done;
   }
 
@@ -390,6 +377,11 @@ atspi_dbus_handle_DeviceEvent (DBusConnection *bus, DBusMessage *message, void *
   if (klass->device_event)
   {
     retval = (*klass->device_event) (listener, &event);
+    if (retval != 0 && retval != 1)
+    {
+      g_warning ("AT-SPI: device event handler returned %d; should be 0 or 1", retval);
+      retval = 0;
+    }
   }
 done:
   reply = dbus_message_new_method_return (message);
@@ -404,8 +396,7 @@ done:
 
 gchar *
 _atspi_device_listener_get_path (AtspiDeviceListener *listener)
-{
-  return g_strdup_printf ("/org/a11y/atspi/listeners/%d", listener->id);
+{  return g_strdup_printf ("/org/a11y/atspi/listeners/%d", listener->id);
 }
 
 G_DEFINE_BOXED_TYPE (AtspiDeviceEvent,