atksocket: Fix typo - parameter is _obj not obj. Set freed to NULL.
[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 static void atk_socket_class_init (AtkSocketClass *klass);
24 static void atk_socket_finalize   (GObject *obj);
25
26 static void atk_component_interface_init (AtkComponentIface *iface);
27
28 G_DEFINE_TYPE_WITH_CODE (AtkSocket, atk_socket, ATK_TYPE_OBJECT,
29                          G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT, atk_component_interface_init))
30
31 static void
32 atk_socket_init (AtkSocket* obj)
33 {
34   obj->embedded_plug_id = NULL;
35 }
36
37 static void
38 atk_socket_class_init (AtkSocketClass* klass)
39 {
40   GObjectClass *obj_class = G_OBJECT_CLASS (klass);
41
42   obj_class->finalize = atk_socket_finalize;
43
44   klass->embed = NULL;
45 }
46
47 static void
48 atk_socket_finalize (GObject *_obj)
49 {
50   AtkSocket *obj = ATK_SOCKET (_obj);
51
52   g_free (obj->embedded_plug_id);
53   obj->embedded_plug_id = NULL;
54
55   G_OBJECT_CLASS (atk_socket_parent_class)->finalize (_obj);
56 }
57
58 static void atk_component_interface_init (AtkComponentIface *iface)
59 {
60 }
61
62 AtkObject*
63 atk_socket_new (void)
64 {
65   AtkObject* accessible;
66   
67   accessible = g_object_new (ATK_TYPE_SOCKET, NULL);
68   g_return_val_if_fail (accessible != NULL, NULL);
69
70   accessible->role = ATK_ROLE_FILLER;
71   accessible->layer = ATK_LAYER_WIDGET;
72   
73   return accessible;
74 }
75
76 /**
77  * atk_socket_embed:
78  * @obj: an #AtkSocket
79  * @plug_id: the ID of an #AtkPlug
80  *
81  * Embeds the children of an #AtkPlug as the children of the #AtkSocket.  The
82  * plug may be in the same process or in a different process.
83  * THe class item used by this function should be filled in by the IPC layer
84  * (ie, at-spi2-atk).  The implementor of the AtkSocket should call this
85  * function and pass the id for the plug as returned by atk_plug_get_id.
86  * It is the responsibility of the application to pass the plug id on to
87  * the process implementing the AtkSocket as needed.
88  *
89  * Since: 1.30
90  **/
91 void
92 atk_socket_embed (AtkSocket* obj, gchar* plug_id)
93 {
94   AtkSocketClass *klass;
95
96   g_return_if_fail (plug_id != NULL);
97   g_return_if_fail (ATK_IS_SOCKET (obj));
98
99   klass = g_type_class_peek (ATK_TYPE_SOCKET);
100   if (klass && klass->embed)
101     {
102       if (obj->embedded_plug_id)
103         g_free (obj->embedded_plug_id);
104       obj->embedded_plug_id = g_strdup (plug_id);
105       (klass->embed) (obj, plug_id);
106     }
107 }
108
109 /**
110  * atk_socket_is_occupied:
111  * @obj: an #AtkSocket
112  *
113  * Determines whether or not the socket has an embedded plug.
114  *
115  * Returns: TRUE if a plug is embedded in the socket
116  *
117  * Since: 1.30
118  **/
119 gboolean
120 atk_socket_is_occupied (AtkSocket* obj)
121 {
122   g_return_val_if_fail (ATK_IS_SOCKET (obj), FALSE);
123
124   return (obj->embedded_plug_id != NULL);
125 }