6569eaaac210e9bcf49fc113c59580a36ea76c18
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / hypertext-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include <atk/atk.h>
26 #include <droute/droute.h>
27
28 #include "spi-dbus.h"
29 #include "object.h"
30
31 #include "introspection.h"
32
33 static DBusMessage *
34 impl_GetNLinks (DBusConnection * bus, DBusMessage * message, void *user_data)
35 {
36   AtkHypertext *hypertext = (AtkHypertext *) user_data;
37   gint rv;
38   DBusMessage *reply;
39
40   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
41                         droute_not_yet_handled_error (message));
42   rv = atk_hypertext_get_n_links (hypertext);
43   reply = dbus_message_new_method_return (message);
44   if (reply)
45     {
46       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
47                                 DBUS_TYPE_INVALID);
48     }
49   return reply;
50 }
51
52 static DBusMessage *
53 impl_GetLink (DBusConnection * bus, DBusMessage * message, void *user_data)
54 {
55   AtkHypertext *hypertext = (AtkHypertext *) user_data;
56   DBusError error;
57   dbus_int32_t linkIndex;
58   AtkHyperlink *link;
59
60   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
61                         droute_not_yet_handled_error (message));
62   dbus_error_init (&error);
63   if (!dbus_message_get_args
64       (message, &error, DBUS_TYPE_INT32, &linkIndex, DBUS_TYPE_INVALID))
65     {
66       return droute_invalid_arguments_error (message);
67     }
68   link = atk_hypertext_get_link (hypertext, linkIndex);
69   /*The above line doesn't ref the link, and the next call is going to unref*/
70   if (link)
71     g_object_ref (link);
72   return spi_hyperlink_return_reference (message, link);
73 }
74
75 static DBusMessage *
76 impl_GetLinkIndex (DBusConnection * bus, DBusMessage * message,
77                    void *user_data)
78 {
79   AtkHypertext *hypertext = (AtkHypertext *) user_data;
80   DBusError error;
81   dbus_int32_t characterIndex;
82   dbus_int32_t rv;
83   DBusMessage *reply;
84
85   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
86                         droute_not_yet_handled_error (message));
87   dbus_error_init (&error);
88   if (!dbus_message_get_args
89       (message, &error, DBUS_TYPE_INT32, &characterIndex, DBUS_TYPE_INVALID))
90     {
91       return droute_invalid_arguments_error (message);
92     }
93   rv = atk_hypertext_get_link_index (hypertext, characterIndex);
94   reply = dbus_message_new_method_return (message);
95   if (reply)
96     {
97       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
98                                 DBUS_TYPE_INVALID);
99     }
100   return reply;
101 }
102
103 static DRouteMethod methods[] = {
104   {impl_GetNLinks, "GetNLinks"},
105   {impl_GetLink, "GetLink"},
106   {impl_GetLinkIndex, "GetLinkIndex"},
107   {NULL, NULL}
108 };
109
110 void
111 spi_initialize_hypertext (DRoutePath * path)
112 {
113   droute_path_add_interface (path,
114                              ATSPI_DBUS_INTERFACE_HYPERTEXT, spi_org_a11y_atspi_Hypertext, methods, NULL);
115 };