4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include "location/location.h"
29 #include "location/location-log.h"
30 #include "location/location-setting.h"
31 #include "location/location-module-internal.h"
32 #include "location/location-ielement.h"
33 #include "location/location-hybrid.h"
34 #include "location/location-gps.h"
35 #include "location/location-wps.h"
36 #include "location/location-ips.h"
37 #include "location/location-cps.h"
38 #include "location/location-sps.h"
39 #include "location/location-geocode.h"
40 #include "location/location-poi.h"
41 #include "location/location-position.h"
43 static LocationObject *geocode = NULL;
44 static LocationObject *poi = NULL;
47 is_connected_network()
49 gboolean is_connected = TRUE;
52 net_state = location_setting_get_int(VCONFKEY_NETWORK_STATUS);
54 LOCATION_LOGW("net_state[%d]", net_state);
55 if(net_state == VCONFKEY_NETWORK_OFF) {
63 EXPORT_API int location_init (void)
65 LOCATION_LOGD("location_init");
67 if( FALSE == module_init() )
68 return LOCATION_ERROR_NOT_AVAILABLE;
70 return LOCATION_ERROR_NONE;
73 EXPORT_API LocationObject*
74 location_new (LocationMethod method)
76 LocationObject *self = NULL;
79 geocode = g_object_new (LOCATION_TYPE_GEOCODE, NULL);
82 poi = g_object_new (LOCATION_TYPE_POI, NULL);*/
85 case LOCATION_METHOD_HYBRID:
86 self = g_object_new (LOCATION_TYPE_HYBRID, NULL);
88 case LOCATION_METHOD_GPS:
89 self = g_object_new (LOCATION_TYPE_GPS, NULL);
91 case LOCATION_METHOD_WPS:
92 self = g_object_new (LOCATION_TYPE_WPS, NULL);
94 case LOCATION_METHOD_CPS:
95 self = g_object_new (LOCATION_TYPE_CPS, NULL);
97 case LOCATION_METHOD_IPS:
98 self = g_object_new (LOCATION_TYPE_IPS, NULL);
100 case LOCATION_METHOD_SPS:
101 self = g_object_new (LOCATION_TYPE_SPS, NULL);
110 location_free (LocationObject *obj)
112 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
114 //location_ielement_stop(LOCATION_IELEMENT(obj));
116 g_object_unref (geocode);
120 g_object_unref (poi);
123 g_object_unref (obj);
124 return LOCATION_ERROR_NONE;
128 location_start (LocationObject *obj)
130 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
131 return location_ielement_start (LOCATION_IELEMENT(obj));
135 location_stop (LocationObject *obj)
137 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
138 return location_ielement_stop (LOCATION_IELEMENT(obj));
142 location_is_supported_method(LocationMethod method)
144 gboolean is_supported = FALSE;
147 case LOCATION_METHOD_HYBRID:
148 if(module_is_supported("gps") || module_is_supported("wps") || module_is_supported("sps"))
151 case LOCATION_METHOD_GPS:
152 is_supported = module_is_supported("gps");
154 case LOCATION_METHOD_WPS:
155 is_supported = module_is_supported("wps");
157 case LOCATION_METHOD_SPS:
158 is_supported = module_is_supported("sps");
160 case LOCATION_METHOD_CPS:
161 case LOCATION_METHOD_IPS:
170 location_is_enabled_gps(LocationObject *obj)
172 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
174 return (gboolean) location_setting_get_int(GPS_ENABLED);
178 location_get_position (LocationObject *obj,
179 LocationPosition **position,
180 LocationAccuracy **accuracy)
182 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
183 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
184 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
185 return location_ielement_get_position (LOCATION_IELEMENT(obj), position, accuracy);
189 location_get_last_position (LocationObject *obj, LocationMethod method,
190 LocationPosition **position,
191 LocationAccuracy **accuracy)
193 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
194 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
196 return LOCATION_ERROR_NONE;
200 location_get_last_known_position (LocationObject *obj, LocationMethod method,
201 LocationLastPosition *last_position)
203 g_return_val_if_fail (last_position, LOCATION_ERROR_PARAMETER);
205 LocationMethod redefined_method = method;
207 if (!obj) redefined_method = LOCATION_METHOD_HYBRID;
209 if (redefined_method == LOCATION_METHOD_HYBRID) {
210 int gps_timestamp = 0, wps_timestamp = 0, sps_timestamp = 0;
211 int latest_timestamp = 0;
213 redefined_method = LOCATION_METHOD_SPS;
214 vconf_get_int(GPS_LAST_TIMESTAMP, &gps_timestamp);
215 vconf_get_int(WPS_LAST_TIMESTAMP, &wps_timestamp);
216 vconf_get_int(SPS_LAST_TIMESTAMP, &sps_timestamp);
218 redefined_method = LOCATION_METHOD_SPS;
219 latest_timestamp = sps_timestamp;
220 if (gps_timestamp > sps_timestamp) {
221 redefined_method = LOCATION_METHOD_GPS;
222 latest_timestamp = gps_timestamp;
225 if (wps_timestamp > latest_timestamp) {
226 redefined_method = LOCATION_METHOD_WPS;
231 if (get_last_known_position (redefined_method, last_position)) {
232 return LOCATION_ERROR_UNKNOWN;
235 return LOCATION_ERROR_NONE;
239 location_get_satellite (LocationObject *obj, LocationSatellite **satellite)
241 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
242 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
244 return LOCATION_ERROR_NONE;;
248 location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite)
250 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
251 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
253 return LOCATION_ERROR_NONE;;
257 location_get_position_from_address (LocationObject *obj,
258 const LocationAddress *address,
259 GList **position_list,
260 GList **accuracy_list)
262 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
263 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
264 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
265 return location_ielement_get_geocode (LOCATION_IELEMENT(geocode), address, position_list, accuracy_list);
269 location_get_position_from_freeformed_address (LocationObject *obj,
270 const gchar *address,
271 GList **position_list,
272 GList **accuracy_list)
274 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
275 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
276 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
277 return location_ielement_get_geocode_freeform (LOCATION_IELEMENT(geocode), address, position_list, accuracy_list);
281 location_get_velocity (LocationObject *obj,
282 LocationVelocity **velocity,
283 LocationAccuracy **accuracy)
285 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
286 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
287 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
289 return location_ielement_get_velocity (LOCATION_IELEMENT(obj), velocity, accuracy);
293 location_get_last_velocity (LocationObject *obj,
294 LocationVelocity **velocity,
295 LocationAccuracy **accuracy)
297 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
298 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
299 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
300 return LOCATION_ERROR_NONE;
304 location_get_address (LocationObject *obj,
305 LocationAddress **address,
306 LocationAccuracy **accuracy)
308 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
309 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
310 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
312 LocationPosition *position = NULL;
313 int ret = location_ielement_get_position(LOCATION_IELEMENT (obj), &position, accuracy);
314 if (LOCATION_ERROR_NONE != ret) return ret;
315 ret = location_ielement_get_reversegeocode (LOCATION_IELEMENT(geocode), position, address, accuracy);
316 location_position_free (position);
321 location_get_address_from_position (LocationObject *obj,
322 const LocationPosition *position,
323 LocationAddress **address,
324 LocationAccuracy **accuracy)
326 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
327 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
328 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
329 return location_ielement_get_reversegeocode (LOCATION_IELEMENT(geocode), position, address, accuracy);
333 location_get_position_from_address_async (LocationObject *obj,
334 const LocationAddress *address,
335 LocationPositionCB callback,
338 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
339 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
340 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
341 return location_ielement_get_geocode_async (LOCATION_IELEMENT(geocode), address, callback, userdata);
346 location_get_position_from_freeformed_address_async (LocationObject *obj,
347 const gchar *address,
348 LocationPositionCB callback,
351 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
352 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
353 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
354 return location_ielement_get_geocode_freeform_async (LOCATION_IELEMENT(geocode), address, callback, userdata);
358 location_get_address_async (LocationObject *obj,
359 LocationAddressCB callback,
362 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
363 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
364 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
366 LocationPosition *position = NULL;
367 LocationAccuracy *acc = NULL;
368 int ret = location_ielement_get_position(LOCATION_IELEMENT(obj), &position, &acc);
369 if (LOCATION_ERROR_NONE != ret) return ret;
370 ret = location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(geocode), position, callback, userdata);
371 location_position_free (position);
376 location_get_address_from_position_async (LocationObject *obj,
377 const LocationPosition *position,
378 LocationAddressCB callback,
381 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
382 g_return_val_if_fail (geocode, LOCATION_ERROR_NOT_AVAILABLE);
383 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
384 return location_ielement_get_reversegeocode_async (LOCATION_IELEMENT(geocode), position, callback, userdata);
388 location_get_poi (LocationObject *obj,
390 const gchar *keyword,
391 LocationPOIInfo **poi_info)
393 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
394 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
395 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
396 return location_ielement_get_poi(LOCATION_IELEMENT(poi), radius, keyword, poi_info);
400 location_get_poi_from_address(LocationObject *obj,
401 const LocationAddress *address,
403 const gchar *keyword,
404 LocationPOIInfo **poi_info)
406 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
407 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
408 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
409 return location_ielement_get_poi_from_address(LOCATION_IELEMENT(poi), address, radius, keyword, poi_info);
413 location_get_poi_from_position(LocationObject *obj,
414 const LocationPosition *position,
416 const gchar *keyword,
417 LocationPOIInfo **poi_info)
419 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
420 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
421 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
422 return location_ielement_get_poi_from_position(LOCATION_IELEMENT(poi), position, radius, keyword, poi_info);
426 location_get_poi_async (LocationObject *obj,
428 const gchar *keyword,
429 LocationPOICB callback,
432 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
433 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
434 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
435 return location_ielement_get_poi_async(LOCATION_IELEMENT(poi), radius, keyword, callback, userdata);
439 location_get_poi_from_address_async (LocationObject *obj,
440 const LocationAddress *address,
442 const gchar *keyword,
443 LocationPOICB callback,
446 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
447 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
448 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
449 return location_ielement_get_poi_from_address_async(LOCATION_IELEMENT(poi), address, radius, keyword, callback, userdata);
453 location_get_poi_from_position_async (LocationObject *obj,
454 const LocationPosition *position,
457 LocationPOICB callback,
460 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
461 g_return_val_if_fail (poi, LOCATION_ERROR_NOT_AVAILABLE);
462 g_return_val_if_fail (is_connected_network(), LOCATION_ERROR_NETWORK_NOT_CONNECTED);
463 return location_ielement_get_poi_from_position_async(LOCATION_IELEMENT(poi), position, radius, keyword, callback, userdata);
467 location_send_command(const char *cmd)
469 g_return_val_if_fail (cmd, LOCATION_ERROR_PARAMETER);
471 return LOCATION_ERROR_NONE;