ce15850d6106ccf8cfe9672d56cc364c229fc590
[framework/location/libslp-location.git] / location / location-geocode.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "location/location-log.h"
27
28 #include "location/location-module-internal.h"
29
30 #include "location/location-geocode.h"
31 #include "location/location-marshal.h"
32 #include "location/location-ielement.h"
33
34 typedef struct _LocationGeocodePrivate {
35         LocationGeoMod* mod;
36 } LocationGeocodePrivate;
37
38 enum {
39         PROP_0,
40         PROP_SERVICE_NAME
41 };
42
43 #define DEFAULT_SERVICE "decarta"
44
45 #define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LOCATION_TYPE_GEOCODE, LocationGeocodePrivate))
46
47 static void location_ielement_interface_init (LocationIElementInterface *iface);
48
49 G_DEFINE_TYPE_WITH_CODE (LocationGeocode, location_geocode, G_TYPE_OBJECT,
50         G_IMPLEMENT_INTERFACE (LOCATION_TYPE_IELEMENT, location_ielement_interface_init));
51
52
53 static void
54 location_geocode_dispose (GObject *gobject)
55 {
56         LOCATION_LOGD("location_geocode_dispose");
57
58         G_OBJECT_CLASS (location_geocode_parent_class)->dispose (gobject);
59 }
60
61 static void
62 location_geocode_finalize (GObject *gobject)
63 {
64         LOCATION_LOGD("location_geocode_finalize");
65         LocationGeocodePrivate* priv = GET_PRIVATE(gobject);
66         module_free(priv->mod, "geocode");
67         priv->mod = NULL;
68         G_OBJECT_CLASS (location_geocode_parent_class)->finalize (gobject);
69 }
70
71 static void
72 location_geocode_get_property (GObject *object,
73         guint property_id,
74         GValue *value,
75         GParamSpec *pspec)
76 {
77         LocationGeocodePrivate *priv = GET_PRIVATE (object);
78
79         g_return_if_fail(priv->mod);
80         g_return_if_fail(priv->mod->handler);
81         switch (property_id){
82         case PROP_SERVICE_NAME:{
83                 char* service_name = NULL;
84                 if(priv->mod->ops.get_service_name){
85                         if( LOCATION_ERROR_NONE != priv->mod->ops.get_service_name(priv->mod->handler, &service_name) ){
86                                 service_name = NULL;
87                         }
88                 }
89                 LOCATION_LOGD("Get prop>> Service name: %s", service_name);
90                 g_value_set_string(value, service_name);
91                 g_free(service_name);
92                 break;
93         }
94         default:
95                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
96                 break;
97         }
98 }
99
100 static int
101 location_geocode_get_geocode (LocationGeocode *self,
102         const LocationAddress *address,
103         GList **position_list,
104         GList **accuracy_list)
105 {
106         LOCATION_LOGD("location_geocode_get_geocode");
107         LocationGeocodePrivate* priv = GET_PRIVATE(self);
108         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
109         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
110         g_return_val_if_fail (priv->mod->ops.get_geocode, LOCATION_ERROR_NOT_AVAILABLE);
111         return (priv->mod->ops.get_geocode)(priv->mod->handler, address, position_list, accuracy_list);
112 }
113
114 static int
115 location_geocode_get_geocode_freeform (LocationGeocode *self,
116         const gchar  *address,
117         GList **position_list,
118         GList **accuracy_list)
119 {
120         LOCATION_LOGD("location_geocode_get_geocode_freeform");
121         LocationGeocodePrivate* priv = GET_PRIVATE(self);
122         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
123         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
124         g_return_val_if_fail (priv->mod->ops.get_geocode_freetext, LOCATION_ERROR_NOT_AVAILABLE);
125         return (priv->mod->ops.get_geocode_freetext)(priv->mod->handler, address, position_list, accuracy_list);
126 }
127
128 static int
129 location_geocode_get_reversegeocode (LocationGeocode *self,
130         const LocationPosition *position,
131         LocationAddress **address,
132         LocationAccuracy **accuracy)
133 {
134         LOCATION_LOGD("location_geocode_get_reversegeocode");
135         LocationGeocodePrivate* priv = GET_PRIVATE(self);
136         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
137         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
138         g_return_val_if_fail (priv->mod->ops.get_reverse_geocode, LOCATION_ERROR_NOT_AVAILABLE);
139         return (priv->mod->ops.get_reverse_geocode)(priv->mod->handler, position, address, accuracy);
140 }
141
142 static int
143 location_geocode_get_geocode_async (LocationGeocode *self,
144         LocationAddress *address,
145         LocationPositionCB callback,
146         gpointer userdata)
147 {
148         LOCATION_LOGD("location_geocode_get_geocode_async");
149         LocationGeocodePrivate* priv = GET_PRIVATE(self);
150         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
151         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
152         g_return_val_if_fail (priv->mod->ops.get_geocode_async, LOCATION_ERROR_NOT_AVAILABLE);
153         return (priv->mod->ops.get_geocode_async)(priv->mod->handler, address, callback, userdata);
154 }
155
156 static int
157 location_geocode_get_geocode_freeform_async (LocationGeocode *self,
158         const gchar *address,
159         LocationPositionCB callback,
160         gpointer userdata)
161 {
162         LOCATION_LOGD("location_geocode_get_geocode_freeform_async");
163         LocationGeocodePrivate* priv = GET_PRIVATE(self);
164         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
165         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
166         g_return_val_if_fail (priv->mod->ops.get_geocode_freetext_async, LOCATION_ERROR_NOT_AVAILABLE);
167         return (priv->mod->ops.get_geocode_freetext_async)(priv->mod->handler, address, callback, userdata);
168 }
169
170 static int
171 location_geocode_get_reversegeocode_async (LocationGeocode *self,
172         const LocationPosition *position,
173         LocationAddressCB callback,
174         gpointer userdata)
175 {
176         LOCATION_LOGD("location_geocode_get_reversegeocode_async");
177         LocationGeocodePrivate* priv = GET_PRIVATE(self);
178         g_return_val_if_fail (priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
179         g_return_val_if_fail (priv->mod->handler, LOCATION_ERROR_NOT_AVAILABLE);
180         g_return_val_if_fail (priv->mod->ops.get_reverse_geocode_async, LOCATION_ERROR_NOT_AVAILABLE);
181         return (priv->mod->ops.get_reverse_geocode_async)(priv->mod->handler, position, callback, userdata);
182 }
183
184 static void
185 location_ielement_interface_init (LocationIElementInterface *iface)
186 {
187         iface->get_geocode = (TYPE_GET_GEOCODE)location_geocode_get_geocode;
188         iface->get_geocode_freeform = (TYPE_GET_GEOCODE_FREEFORM)location_geocode_get_geocode_freeform;
189         iface->get_reversegeocode = (TYPE_GET_REVERSEGEOCODE)location_geocode_get_reversegeocode;
190         iface->get_geocode_async = (TYPE_GET_GEOCODE_ASYNC)location_geocode_get_geocode_async;
191         iface->get_geocode_freeform_async = (TYPE_GET_GEOCODE_FREEFORM_ASYNC)location_geocode_get_geocode_freeform_async;
192         iface->get_reversegeocode_async = (TYPE_GET_REVERSEGEOCODE_ASYNC)location_geocode_get_reversegeocode_async;
193 }
194
195 static void
196 location_geocode_init (LocationGeocode *self)
197 {
198         LOCATION_LOGD("location_geocode_init");
199         LocationGeocodePrivate* priv = GET_PRIVATE(self);
200
201         priv->mod = (LocationGeoMod*)module_new("geocode");
202         if(!priv->mod) LOCATION_LOGW("module loading failed");
203 }
204
205 static void
206 location_geocode_class_init (LocationGeocodeClass *klass)
207 {
208         LOCATION_LOGD("location_geocode_class_init");
209         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
210         GParamSpec *pspec;
211
212         gobject_class->get_property = location_geocode_get_property;
213
214         gobject_class->dispose = location_geocode_dispose;
215         gobject_class->finalize = location_geocode_finalize;
216
217         g_type_class_add_private (klass, sizeof (LocationGeocodePrivate));
218
219         pspec = g_param_spec_string ("service provider",
220                                 "geocode service provider name prop",
221                                 "geocode service provider name",
222                                 DEFAULT_SERVICE,
223                                 G_PARAM_READABLE);
224         g_object_class_install_property (gobject_class,
225                                    PROP_SERVICE_NAME,
226                                    pspec);
227 }