Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / hypertext.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 "accessible.h"
26
27 static AtkHypertext *
28 get_hypertext (DBusMessage * message)
29 {
30   AtkObject *obj = spi_dbus_get_object (dbus_message_get_path (message));
31   if (!obj)
32     return NULL;
33   return ATK_HYPERTEXT (obj);
34 }
35
36 static AtkHypertext *
37 get_hypertext_from_path (const char *path, void *user_data)
38 {
39   AtkObject *obj = spi_dbus_get_object (path);
40   if (!obj || !ATK_IS_HYPERTEXT(obj))
41     return NULL;
42   return ATK_HYPERTEXT (obj);
43 }
44
45 static DBusMessage *
46 impl_getNLinks (DBusConnection * bus, DBusMessage * message, void *user_data)
47 {
48   AtkHypertext *hypertext = get_hypertext (message);
49   gint rv;
50   DBusMessage *reply;
51
52   if (!hypertext)
53     return spi_dbus_general_error (message);
54   rv = atk_hypertext_get_n_links (hypertext);
55   reply = dbus_message_new_method_return (message);
56   if (reply)
57     {
58       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
59                                 DBUS_TYPE_INVALID);
60     }
61   return reply;
62 }
63
64 static DBusMessage *
65 impl_getLink (DBusConnection * bus, DBusMessage * message, void *user_data)
66 {
67   AtkHypertext *hypertext = get_hypertext (message);
68   DBusError error;
69   dbus_int32_t linkIndex;
70   AtkHyperlink *link;
71
72   if (!hypertext)
73     return spi_dbus_general_error (message);
74   dbus_error_init (&error);
75   if (!dbus_message_get_args
76       (message, &error, DBUS_TYPE_INT32, &linkIndex, DBUS_TYPE_INVALID))
77     {
78       return SPI_DBUS_RETURN_ERROR (message, &error);
79     }
80   link = atk_hypertext_get_link (hypertext, linkIndex);
81   return spi_dbus_return_object (message, ATK_OBJECT (link), FALSE);
82 }
83
84 static DBusMessage *
85 impl_getLinkIndex (DBusConnection * bus, DBusMessage * message,
86                    void *user_data)
87 {
88   AtkHypertext *hypertext = get_hypertext (message);
89   DBusError error;
90   dbus_int32_t characterIndex;
91   dbus_int32_t rv;
92   DBusMessage *reply;
93
94   if (!hypertext)
95     return spi_dbus_general_error (message);
96   dbus_error_init (&error);
97   if (!dbus_message_get_args
98       (message, &error, DBUS_TYPE_INT32, &characterIndex, DBUS_TYPE_INVALID))
99     {
100       return SPI_DBUS_RETURN_ERROR (message, &error);
101     }
102   rv = atk_hypertext_get_link_index (hypertext, characterIndex);
103   reply = dbus_message_new_method_return (message);
104   if (reply)
105     {
106       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
107                                 DBUS_TYPE_INVALID);
108     }
109   return reply;
110 }
111
112 static DRouteMethod methods[] = {
113   {impl_getNLinks, "getNLinks"},
114   {impl_getLink, "getLink"},
115   {impl_getLinkIndex, "getLinkIndex"},
116   {NULL, NULL}
117 };
118
119 void
120 spi_initialize_hypertext (DRouteData * data)
121 {
122   droute_add_interface (data, "org.freedesktop.atspi.Hypertext",
123                         methods, NULL,
124                         (DRouteGetDatumFunction) get_hypertext_from_path,
125                         NULL);
126 };