Initialize Tizen 2.3
[external/gupnp.git] / libgupnp / gupnp-types.c
1 /*
2  * Copyright (C) 2007 Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
3  * Copyright (C) 2006, 2007 OpenedHand Ltd.
4  *
5  * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
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 /**
24  * SECTION:gupnp-types
25  * @short_description: Extra types for use when calling UPnP actions.
26  *
27  * These GTypes are used to marshal to and from string data to particular UPnP
28  * types when invoking actions on a #GUPnPServiceProxy.
29  */
30
31 #include <string.h>
32
33 #include "gupnp-types.h"
34 #include "gupnp-types-private.h"
35
36 static void
37 gupnp_string_type_to_string (const GValue *src_value,
38                              GValue       *dest_value)
39 {
40         const char *str;
41
42         str = gupnp_value_get_string (src_value);
43
44         g_value_set_string (dest_value, str);
45 }
46
47 static void
48 gupnp_string_to_string_type (const GValue *src_value,
49                              GValue       *dest_value)
50 {
51         const char *str;
52
53         str = g_value_get_string (src_value);
54
55         g_value_set_boxed (dest_value, str);
56 }
57
58 static GType
59 register_string_type (const char *name)
60 {
61         GType type;
62
63         type = g_boxed_type_register_static (
64                                 g_intern_static_string (name),
65                                 (GBoxedCopyFunc) g_strdup,
66                                 (GBoxedFreeFunc) g_free);
67         g_value_register_transform_func (
68                         type,
69                         G_TYPE_STRING,
70                         gupnp_string_type_to_string);
71         g_value_register_transform_func (
72                         G_TYPE_STRING,
73                         type,
74                         gupnp_string_to_string_type);
75
76         return type;
77 }
78
79 GType
80 gupnp_bin_base64_get_type (void)
81 {
82         static GType type = 0;
83
84         if (!type)
85                 type = register_string_type ("GUPnPBinBase64");
86
87         return type;
88 }
89
90 GType
91 gupnp_bin_hex_get_type (void)
92 {
93         static GType type = 0;
94
95         if (!type)
96                 type = register_string_type ("GUPnPBinHex");
97
98         return type;
99 }
100
101 GType
102 gupnp_date_get_type (void)
103 {
104         static GType type = 0;
105
106         if (!type)
107                 type = register_string_type ("GUPnPDate");
108
109         return type;
110 }
111
112 GType
113 gupnp_date_time_get_type (void)
114 {
115         static GType type = 0;
116
117         if (!type)
118                 type = register_string_type ("GUPnPDateTime");
119
120         return type;
121 }
122
123 GType
124 gupnp_date_time_tz_get_type (void)
125 {
126         static GType type = 0;
127
128         if (!type)
129                 type = register_string_type ("GUPnPDateTimeTZ");
130
131         return type;
132 }
133
134 GType
135 gupnp_time_get_type (void)
136 {
137         static GType type = 0;
138
139         if (!type)
140                 type = register_string_type ("GUPnPTime");
141
142         return type;
143 }
144
145 GType
146 gupnp_time_tz_get_type (void)
147 {
148         static GType type = 0;
149
150         if (!type)
151                 type = register_string_type ("GUPnPTimeTZ");
152
153         return type;
154 }
155
156 GType
157 gupnp_uri_get_type (void)
158 {
159         static GType type = 0;
160
161         if (!type)
162                 type = register_string_type ("GUPnPURI");
163
164         return type;
165 }
166
167 GType
168 gupnp_uuid_get_type (void)
169 {
170         static GType type = 0;
171
172         if (!type)
173                 type = register_string_type ("GUPnPUUID");
174
175         return type;
176 }
177
178 GType
179 gupnp_data_type_to_gtype (const char *data_type)
180 {
181         if (g_ascii_strcasecmp ("UUID", data_type) == 0)
182                 return GUPNP_TYPE_UUID;
183         else if (g_ascii_strcasecmp ("URI", data_type) == 0)
184                 return GUPNP_TYPE_URI;
185         else if (g_ascii_strcasecmp ("time.tz", data_type) == 0)
186                 return GUPNP_TYPE_TIME_TZ;
187         else if (g_ascii_strcasecmp ("dateTime.tz", data_type) == 0)
188                 return GUPNP_TYPE_DATE_TIME_TZ;
189         else if (g_ascii_strcasecmp ("dateTime", data_type) == 0)
190                 return GUPNP_TYPE_DATE_TIME;
191         else if (g_ascii_strcasecmp ("date", data_type) == 0)
192                 return GUPNP_TYPE_DATE;
193         else if (g_ascii_strcasecmp ("time", data_type) == 0)
194                 return GUPNP_TYPE_TIME;
195         else if (g_ascii_strcasecmp ("bin.base64", data_type) == 0)
196                 return GUPNP_TYPE_BIN_BASE64;
197         else if (g_ascii_strcasecmp ("bin.hex", data_type) == 0)
198                 return GUPNP_TYPE_BIN_BASE64;
199         else
200                 return G_TYPE_INVALID;
201 }