Merge branch 'master' into mgorse
[platform/core/uifw/at-spi2-atk.git] / droute / droute-variant.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  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "droute-variant.h"
27
28 /*---------------------------------------------------------------------------*/
29
30 dbus_bool_t
31 droute_return_v_int32 (DBusMessageIter *iter, dbus_int32_t val)
32 {
33     DBusMessageIter sub;
34
35     if (!dbus_message_iter_open_container
36         (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &sub))
37       {
38         return FALSE;
39       }
40     dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &val);
41     dbus_message_iter_close_container (iter, &sub);
42     return TRUE;
43 }
44
45 dbus_bool_t
46 droute_return_v_double (DBusMessageIter *iter, double val)
47 {
48     DBusMessageIter sub;
49
50     if (!dbus_message_iter_open_container
51         (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_DOUBLE_AS_STRING, &sub))
52       {
53         return FALSE;
54       }
55     dbus_message_iter_append_basic (&sub, DBUS_TYPE_DOUBLE, &val);
56     dbus_message_iter_close_container (iter, &sub);
57     return TRUE;
58 }
59
60 dbus_bool_t
61 droute_return_v_string (DBusMessageIter *iter, const char *val)
62 {
63     DBusMessageIter sub;
64
65     if (!val)
66       val = "";
67     if (!dbus_message_iter_open_container
68         (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &sub))
69       {
70         return FALSE;
71       }
72     dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING, &val);
73     dbus_message_iter_close_container (iter, &sub);
74     return TRUE;
75 }
76
77 dbus_bool_t
78 droute_return_v_object (DBusMessageIter *iter, const char *path)
79 {
80     DBusMessageIter sub;
81
82     if (!dbus_message_iter_open_container
83         (iter, DBUS_TYPE_VARIANT, DBUS_TYPE_OBJECT_PATH_AS_STRING, &sub))
84       {
85         return FALSE;
86       }
87     dbus_message_iter_append_basic (&sub, DBUS_TYPE_OBJECT_PATH, &path);
88     dbus_message_iter_close_container (iter, &sub);
89     return TRUE;
90 }
91
92 /*---------------------------------------------------------------------------*/
93
94 dbus_int32_t
95 droute_get_v_int32 (DBusMessageIter *iter)
96 {
97     DBusMessageIter sub;
98     dbus_int32_t rv;
99
100     // TODO- ensure we have the correct type
101     dbus_message_iter_recurse (iter, &sub);
102     dbus_message_iter_get_basic (&sub, &rv);
103     return rv;
104 }
105
106 const char *
107 droute_get_v_string (DBusMessageIter *iter)
108 {
109     DBusMessageIter sub;
110     char *rv;
111
112     // TODO- ensure we have the correct type
113     dbus_message_iter_recurse (iter, &sub);
114     dbus_message_iter_get_basic (&sub, &rv);
115     return rv;
116 }
117
118 /*END------------------------------------------------------------------------*/