1
/*
2
 * AT-SPI - Assistive Technology Service Provider Interface
3
 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the
17
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20

            
21
/*
22
 * Simple test application for AT-SPI.
23
 *
24
 * The only thing this application does, is registering itself to the AT-SPI
25
 * registry and then waiting to get killed by some external force.
26
 */
27

            
28
#include <atspi/atspi.h>
29
#include <dbus/dbus.h>
30
#include <glib.h>
31
#include <stdio.h>
32

            
33
static GMainLoop *mainloop;
34

            
35
int
36
register_app ()
37
{
38
  DBusConnection *connection = NULL;
39
  DBusMessage *message;
40
  DBusMessageIter iter;
41
  DBusMessageIter subiter;
42
  DBusError error;
43
  DBusMessage *reply;
44
  const gchar *name;
45
  gchar *path;
46

            
47
  /* Set up D-Bus connection and register bus name */
48
  dbus_error_init (&error);
49
  connection = atspi_get_a11y_bus ();
50
  if (!connection)
51
    {
52
      printf ("Couldn't get a11y bus!\n");
53
      return -1;
54
    }
55

            
56
  /* Register this app by sending a signal out to AT-SPI registry daemon */
57
  message = dbus_message_new_method_call (ATSPI_DBUS_NAME_REGISTRY,
58
                                          ATSPI_DBUS_PATH_ROOT,
59
                                          ATSPI_DBUS_INTERFACE_SOCKET,
60
                                          "Embed");
61

            
62
  dbus_message_iter_init_append (message, &iter);
63

            
64
  name = dbus_bus_get_unique_name (connection);
65
  path = g_strdup (ATSPI_DBUS_PATH_NULL);
66

            
67
  dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
68
                                    &subiter);
69
  dbus_message_iter_append_basic (&subiter, DBUS_TYPE_STRING, &name);
70
  dbus_message_iter_append_basic (&subiter, DBUS_TYPE_OBJECT_PATH, &path);
71
  dbus_message_iter_close_container (&iter, &subiter);
72

            
73
  g_free (path);
74

            
75
  reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
76
  if (!reply)
77
    {
78
      printf ("Did not get a reply from the registry.\n");
79
      dbus_message_unref (message);
80
      dbus_error_free (&error);
81
      return -1;
82
    }
83

            
84
  dbus_message_unref (message);
85
  dbus_message_unref (reply);
86
  dbus_error_free (&error);
87
  return 0;
88
}
89

            
90
int
91
main (int argc, char *argv[])
92
{
93
  int ret = register_app ();
94
  if (ret)
95
    {
96
      printf ("Failed to send dbus signals. Aborting.\n");
97
      return ret;
98
    }
99

            
100
  // This keeps the test-application runnig indefinitely, i.e.
101
  // until killed by an external signal.
102
  mainloop = g_main_loop_new (NULL, FALSE);
103
  g_main_loop_run (mainloop);
104

            
105
  return 0;
106
}