docs: Improve documentation for AtkPlug and AtkSocket
[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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atk.h"
21 #include "atksocket.h"
22
23 /**
24  * SECTION:atksocket
25  * @Short_description: Container for AtkPlug objects from other processes
26  * @Title: AtkSocket
27  * @See_also: #AtkPlug
28  *
29  * Together with #AtkPlug, #AtkSocket provides the ability to embed
30  * accessibles from one process into another in a fashion that is
31  * transparent to assistive technologies. #AtkSocket works as the
32  * container of #AtkPlug, embedding it using the method
33  * atk_socket_embed(). Any accessible contained in the #AtkPlug will
34  * appear to the assistive technologies as being inside the
35  * application that created the #AtkSocket.
36  *
37  * The communication between a #AtkSocket and a #AtkPlug is done by
38  * the IPC layer of the accessibility framework, normally implemented
39  * by the D-Bus based implementation of AT-SPI (at-spi2). If that is
40  * the case, at-spi-atk2 is the responsible to implement the abstract
41  * methods atk_plug_get_id() and atk_socket_embed(), so an ATK
42  * implementor shouldn't reimplement them. The process that contains
43  * the #AtkPlug is responsible to send the ID returned by
44  * atk_plug_id() to the process that contains the #AtkSocket, so it
45  * could call the method atk_socket_embed() in order to embed it.
46  *
47  */
48
49 static void atk_socket_class_init (AtkSocketClass *klass);
50 static void atk_socket_finalize   (GObject *obj);
51
52 static void atk_component_interface_init (AtkComponentIface *iface);
53
54 G_DEFINE_TYPE_WITH_CODE (AtkSocket, atk_socket, ATK_TYPE_OBJECT,
55                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
56
57 static void
58 atk_socket_init (AtkSocket* obj)
59 {
60   obj->embedded_plug_id = NULL;
61 }
62
63 static void
64 atk_socket_class_init (AtkSocketClass* klass)
65 {
66   GObjectClass *obj_class = G_OBJECT_CLASS (klass);
67
68   obj_class->finalize = atk_socket_finalize;
69
70   klass->embed = NULL;
71 }
72
73 static void
74 atk_socket_finalize (GObject *_obj)
75 {
76   AtkSocket *obj = ATK_SOCKET (_obj);
77
78   g_free (obj->embedded_plug_id);
79   obj->embedded_plug_id = NULL;
80
81   G_OBJECT_CLASS (atk_socket_parent_class)->finalize (_obj);
82 }
83
84 static void atk_component_interface_init (AtkComponentIface *iface)
85 {
86 }
87
88 AtkObject*
89 atk_socket_new (void)
90 {
91   AtkObject* accessible;
92   
93   accessible = g_object_new (ATK_TYPE_SOCKET, NULL);
94   g_return_val_if_fail (accessible != NULL, NULL);
95
96   accessible->role = ATK_ROLE_FILLER;
97   accessible->layer = ATK_LAYER_WIDGET;
98   
99   return accessible;
100 }
101
102 /**
103  * atk_socket_embed:
104  * @obj: an #AtkSocket
105  * @plug_id: the ID of an #AtkPlug
106  *
107  * Embeds the children of an #AtkPlug as the children of the
108  * #AtkSocket. The plug may be in the same process or in a different
109  * process.
110  *
111  * The class item used by this function should be filled in by the IPC
112  * layer (usually at-spi2-atk). The implementor of the AtkSocket
113  * should call this function and pass the id for the plug as returned
114  * by atk_plug_get_id().  It is the responsibility of the application
115  * to pass the plug id on to the process implementing the #AtkSocket
116  * as needed.
117  *
118  * Since: 1.30
119  **/
120 void
121 atk_socket_embed (AtkSocket* obj, gchar* plug_id)
122 {
123   AtkSocketClass *klass;
124
125   g_return_if_fail (plug_id != NULL);
126   g_return_if_fail (ATK_IS_SOCKET (obj));
127
128   klass = g_type_class_peek (ATK_TYPE_SOCKET);
129   if (klass && klass->embed)
130     {
131       if (obj->embedded_plug_id)
132         g_free (obj->embedded_plug_id);
133       obj->embedded_plug_id = g_strdup (plug_id);
134       (klass->embed) (obj, plug_id);
135     }
136 }
137
138 /**
139  * atk_socket_is_occupied:
140  * @obj: an #AtkSocket
141  *
142  * Determines whether or not the socket has an embedded plug.
143  *
144  * Returns: TRUE if a plug is embedded in the socket
145  *
146  * Since: 1.30
147  **/
148 gboolean
149 atk_socket_is_occupied (AtkSocket* obj)
150 {
151   g_return_val_if_fail (ATK_IS_SOCKET (obj), FALSE);
152
153   return (obj->embedded_plug_id != NULL);
154 }