Add GetAtspiVersion
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / adaptors / value-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 <math.h>
26
27 #include <atk/atk.h>
28 #include <droute/droute.h>
29
30 #include "common/spi-dbus.h"
31 #include "introspection.h"
32
33 static dbus_bool_t
34 impl_get_MinimumValue (DBusMessageIter * iter, void *user_data)
35 {
36   AtkValue *value = (AtkValue *) user_data;
37   GValue src = { 0 };
38   GValue dest = { 0 };
39   gdouble dub;
40
41   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
42
43   atk_value_get_minimum_value (value, &src);
44   g_value_init (&dest, G_TYPE_DOUBLE);
45
46   if (g_value_transform (&src, &dest))
47     {
48       dub = g_value_get_double (&dest);
49       return droute_return_v_double (iter, dub);
50     }
51   else
52     {
53       return FALSE;
54     }
55 }
56
57 static dbus_bool_t
58 impl_get_MaximumValue (DBusMessageIter * iter, void *user_data)
59 {
60   AtkValue *value = (AtkValue *) user_data;
61   GValue src = { 0 };
62   GValue dest = { 0 };
63   gdouble dub = 0;
64
65   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
66
67   atk_value_get_maximum_value (value, &src);
68   g_value_init (&dest, G_TYPE_DOUBLE);
69
70   if (g_value_transform (&src, &dest))
71     {
72       dub = g_value_get_double (&dest);
73     }
74   return droute_return_v_double (iter, dub);
75 }
76
77 static dbus_bool_t
78 impl_get_MinimumIncrement (DBusMessageIter * iter, void *user_data)
79 {
80   AtkValue *value = (AtkValue *) user_data;
81   GValue src = { 0 };
82   GValue dest = { 0 };
83   gdouble dub = 0;
84
85   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
86
87   atk_value_get_minimum_increment (value, &src);
88   g_value_init (&dest, G_TYPE_DOUBLE);
89
90   if (g_value_transform (&src, &dest))
91     {
92       dub = g_value_get_double (&dest);
93     }
94   return droute_return_v_double (iter, dub);
95 }
96
97 static dbus_bool_t
98 impl_get_CurrentValue (DBusMessageIter * iter, void *user_data)
99 {
100   AtkValue *value = (AtkValue *) user_data;
101   GValue src = { 0 };
102   GValue dest = { 0 };
103   gdouble dub = 0;
104
105   g_return_val_if_fail (ATK_IS_VALUE (user_data), FALSE);
106
107   atk_value_get_current_value (value, &src);
108   g_value_init (&dest, G_TYPE_DOUBLE);
109
110   if (g_value_transform (&src, &dest))
111     {
112       dub = g_value_get_double (&dest);
113     }
114   return droute_return_v_double (iter, dub);
115 }
116
117 static DBusMessage *
118 impl_set_CurrentValue (DBusConnection * bus, DBusMessage * message,
119                        void *user_data)
120 {
121   AtkValue *value = (AtkValue *) user_data;
122   dbus_bool_t rv;
123   DBusError error;
124   DBusMessage *reply;
125   gdouble dub = 0;
126   GValue new_value = { 0 };
127
128   g_return_val_if_fail (ATK_IS_VALUE (value),
129                         droute_not_yet_handled_error (message));
130
131   dbus_error_init (&error);
132   if (!dbus_message_get_args
133       (message, &error, DBUS_TYPE_DOUBLE, &dub, DBUS_TYPE_INVALID))
134     {
135       return droute_invalid_arguments_error (message);
136     }
137
138   g_value_init (&new_value, G_TYPE_DOUBLE);
139   g_value_set_double (&new_value, dub);
140   rv = atk_value_set_current_value (value, &new_value);
141
142   reply = dbus_message_new_method_return (message);
143   if (reply)
144     {
145       dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &rv,
146                                 DBUS_TYPE_INVALID);
147     }
148   return reply;
149 }
150
151 static DRouteMethod methods[] = {
152   {impl_set_CurrentValue, "SetCurrentValue"},
153   {NULL, NULL}
154 };
155
156 static DRouteProperty properties[] = {
157   {impl_get_MinimumValue, NULL, "MinimumValue"},
158   {impl_get_MaximumValue, NULL, "MaximumValue"},
159   {impl_get_MinimumIncrement, NULL, "MinimumIncrement"},
160   {impl_get_CurrentValue, NULL, "CurrentValue"},
161   {NULL, NULL, NULL}
162 };
163
164 void
165 spi_initialize_value (DRoutePath * path)
166 {
167   droute_path_add_interface (path,
168                              SPI_DBUS_INTERFACE_VALUE, spi_org_a11y_atspi_Value, methods, properties);
169 };