Updated FSF's address
[platform/upstream/atk.git] / atk / atksocket.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright (C) 2009 Novell, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "atk.h"
19 #include "atksocket.h"
20
21 /**
22  * SECTION:atksocket
23  * @Short_description: Container for AtkPlug objects from other processes
24  * @Title: AtkSocket
25  * @See_also: #AtkPlug
26  *
27  * Together with #AtkPlug, #AtkSocket provides the ability to embed
28  * accessibles from one process into another in a fashion that is
29  * transparent to assistive technologies. #AtkSocket works as the
30  * container of #AtkPlug, embedding it using the method
31  * atk_socket_embed(). Any accessible contained in the #AtkPlug will
32  * appear to the assistive technologies as being inside the
33  * application that created the #AtkSocket.
34  *
35  * The communication between a #AtkSocket and a #AtkPlug is done by
36  * the IPC layer of the accessibility framework, normally implemented
37  * by the D-Bus based implementation of AT-SPI (at-spi2). If that is
38  * the case, at-spi-atk2 is the responsible to implement the abstract
39  * methods atk_plug_get_id() and atk_socket_embed(), so an ATK
40  * implementor shouldn't reimplement them. The process that contains
41  * the #AtkPlug is responsible to send the ID returned by
42  * atk_plug_id() to the process that contains the #AtkSocket, so it
43  * could call the method atk_socket_embed() in order to embed it.
44  *
45  * For the same reasons, an implementor doesn't need to implement
46  * atk_object_get_n_accessible_children() and
47  * atk_object_ref_accessible_child(). All the logic related to those
48  * functions will be implemented by the IPC layer.
49  */
50
51 static void atk_socket_class_init (AtkSocketClass *klass);
52 static void atk_socket_finalize   (GObject *obj);
53
54 static void atk_component_interface_init (AtkComponentIface *iface);
55
56 G_DEFINE_TYPE_WITH_CODE (AtkSocket, atk_socket, ATK_TYPE_OBJECT,
57                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
58
59 static void
60 atk_socket_init (AtkSocket* obj)
61 {
62   obj->embedded_plug_id = NULL;
63 }
64
65 static void
66 atk_socket_class_init (AtkSocketClass* klass)
67 {
68   GObjectClass *obj_class = G_OBJECT_CLASS (klass);
69
70   obj_class->finalize = atk_socket_finalize;
71
72   klass->embed = NULL;
73 }
74
75 static void
76 atk_socket_finalize (GObject *_obj)
77 {
78   AtkSocket *obj = ATK_SOCKET (_obj);
79
80   g_free (obj->embedded_plug_id);
81   obj->embedded_plug_id = NULL;
82
83   G_OBJECT_CLASS (atk_socket_parent_class)->finalize (_obj);
84 }
85
86 static void atk_component_interface_init (AtkComponentIface *iface)
87 {
88 }
89
90 AtkObject*
91 atk_socket_new (void)
92 {
93   AtkObject* accessible;
94   
95   accessible = g_object_new (ATK_TYPE_SOCKET, NULL);
96   g_return_val_if_fail (accessible != NULL, NULL);
97
98   accessible->role = ATK_ROLE_FILLER;
99   accessible->layer = ATK_LAYER_WIDGET;
100   
101   return accessible;
102 }
103
104 /**
105  * atk_socket_embed:
106  * @obj: an #AtkSocket
107  * @plug_id: the ID of an #AtkPlug
108  *
109  * Embeds the children of an #AtkPlug as the children of the
110  * #AtkSocket. The plug may be in the same process or in a different
111  * process.
112  *
113  * The class item used by this function should be filled in by the IPC
114  * layer (usually at-spi2-atk). The implementor of the AtkSocket
115  * should call this function and pass the id for the plug as returned
116  * by atk_plug_get_id().  It is the responsibility of the application
117  * to pass the plug id on to the process implementing the #AtkSocket
118  * as needed.
119  *
120  * Since: 1.30
121  **/
122 void
123 atk_socket_embed (AtkSocket* obj, gchar* plug_id)
124 {
125   AtkSocketClass *klass;
126
127   g_return_if_fail (plug_id != NULL);
128   g_return_if_fail (ATK_IS_SOCKET (obj));
129
130   klass = g_type_class_peek (ATK_TYPE_SOCKET);
131   if (klass && klass->embed)
132     {
133       if (obj->embedded_plug_id)
134         g_free (obj->embedded_plug_id);
135       obj->embedded_plug_id = g_strdup (plug_id);
136       (klass->embed) (obj, plug_id);
137     }
138 }
139
140 /**
141  * atk_socket_is_occupied:
142  * @obj: an #AtkSocket
143  *
144  * Determines whether or not the socket has an embedded plug.
145  *
146  * Returns: TRUE if a plug is embedded in the socket
147  *
148  * Since: 1.30
149  **/
150 gboolean
151 atk_socket_is_occupied (AtkSocket* obj)
152 {
153   g_return_val_if_fail (ATK_IS_SOCKET (obj), FALSE);
154
155   return (obj->embedded_plug_id != NULL);
156 }