2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <system_info.h>
21 #include "locations.h"
22 #include "location_internal.h"
24 static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_WPS + 1];
26 static location_method_e __convert_location_method_e(LocationMethod method)
28 location_method_e _method = LOCATIONS_METHOD_NONE;
30 case LOCATION_METHOD_HYBRID:
31 _method = LOCATIONS_METHOD_HYBRID;
33 case LOCATION_METHOD_GPS:
34 _method = LOCATIONS_METHOD_GPS;
36 case LOCATION_METHOD_WPS:
37 _method = LOCATIONS_METHOD_WPS;
39 case LOCATION_METHOD_NONE:
46 static LocationMethod __convert_LocationMethod(location_method_e method)
48 LocationMethod _method = LOCATION_METHOD_NONE;
50 case LOCATIONS_METHOD_HYBRID:
51 _method = LOCATION_METHOD_HYBRID;
53 case LOCATIONS_METHOD_GPS:
54 _method = LOCATION_METHOD_GPS;
56 case LOCATIONS_METHOD_WPS:
57 _method = LOCATION_METHOD_WPS;
59 case LOCATIONS_METHOD_NONE:
61 _method = LOCATION_METHOD_NONE;
67 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
69 LOCATIONS_LOGD("Callback function has been invoked. ");
70 location_manager_s *handle = (location_manager_s *) userdata;
72 if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
73 LocationSatellite *sat = (LocationSatellite *)data;
74 LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
75 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
76 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
77 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
78 } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
79 LocationPosition *pos = (LocationPosition *) data;
80 LocationVelocity *vel = (LocationVelocity *) velocity; /* current velocity */
81 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
82 vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
85 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
86 LocationPosition *pos = (LocationPosition *) data;
87 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude, pos->timestamp,
88 handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
91 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
92 LocationVelocity *vel = (LocationVelocity *) velocity;
93 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb, vel->timestamp,
94 handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
97 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
98 LocationPosition *pos = (LocationPosition *) data;
99 LocationVelocity *vel = (LocationVelocity *) velocity;
100 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
101 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
102 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
107 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
109 LOCATIONS_LOGD("Callback function has been invoked. ");
110 int converted_err = __convert_error_code(error);
111 location_manager_s *handle = (location_manager_s *) userdata;
112 LocationPosition *pos = (LocationPosition *) position;
113 LocationVelocity *vel = (LocationVelocity *) velocity;
115 LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
116 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
117 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
118 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
122 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
124 LOCATIONS_LOGD("Callback function has been invoked. ");
125 location_manager_s *handle = (location_manager_s *) userdata;
126 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
127 ((location_service_state_changed_cb)
128 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
132 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
134 LOCATIONS_LOGD("Callback function has been invoked. ");
135 location_manager_s *handle = (location_manager_s *) userdata;
136 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
137 ((location_service_state_changed_cb)
138 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
141 static int __compare_position(gconstpointer a, gconstpointer b)
143 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
150 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
154 if (bound1->type == bound2->type) {
155 switch (bound1->type) {
156 case LOCATION_BOUNDARY_CIRCLE:
157 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
161 case LOCATION_BOUNDARY_RECT:
162 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
166 case LOCATION_BOUNDARY_POLYGON: {
167 GList *boundary1_next = NULL;
168 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
169 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
173 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
174 if (boundary2_start == NULL) return -1;
176 boundary2_prev = g_list_previous(boundary2_start);
177 boundary2_next = g_list_next(boundary2_start);
179 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
180 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
182 boundary1_next = g_list_next(bound1->polygon.position_list);
183 if (boundary1_next != NULL && boundary2_prev != NULL &&
184 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
185 boundary1_next = g_list_next(boundary1_next);
186 while (boundary1_next) {
187 boundary2_prev = g_list_previous(boundary2_prev);
188 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
189 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
192 boundary1_next = g_list_next(boundary1_next);
195 } else if (boundary1_next != NULL && boundary2_next != NULL &&
196 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
197 boundary1_next = g_list_next(boundary1_next);
198 while (boundary1_next) {
199 boundary2_next = g_list_next(boundary2_next);
200 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
201 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
204 boundary1_next = g_list_next(boundary1_next);
219 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
221 LOCATIONS_LOGD("ENTER >>>");
222 location_manager_s *handle = (location_manager_s *) userdata;
223 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
224 LocationPosition *pos = (LocationPosition *) position;
225 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
226 pos->latitude, pos->longitude,
227 pos->altitude, pos->timestamp,
229 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
232 location_bounds_s *bounds;
233 GList *bounds_list = g_list_first(handle->bounds_list);
234 while (bounds_list) {
235 bounds = (location_bounds_s *)bounds_list->data;
236 if (__boundary_compare(boundary, bounds->boundary) == 0) {
237 LOCATIONS_LOGD("Find zone in boundary");
238 if (bounds->user_cb) {
239 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
243 bounds_list = g_list_next(bounds_list);
245 LOCATIONS_LOGD("EXIT <<<");
248 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
250 LOCATIONS_LOGD("ENTER >>>");
251 location_manager_s *handle = (location_manager_s *) userdata;
252 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
253 LocationPosition *pos = (LocationPosition *) position;
254 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
255 pos->latitude, pos->longitude,
256 pos->altitude, pos->timestamp,
258 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
261 location_bounds_s *bounds;
262 GList *bounds_list = g_list_first(handle->bounds_list);
263 while (bounds_list) {
264 bounds = (location_bounds_s *)bounds_list->data;
265 if (__boundary_compare(boundary, bounds->boundary) == 0) {
266 LOCATIONS_LOGD("Find zone out boundary");
267 if (bounds->user_cb) {
268 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
272 bounds_list = g_list_next(bounds_list);
274 LOCATIONS_LOGD("EXIT <<<");
277 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
279 location_manager_s *handle = (location_manager_s *) user_data;
281 if (handle != NULL && boundary != NULL) {
283 location_bounds_h bounds;
284 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
285 location_coords_s center;
286 center.latitude = boundary->circle.center->latitude;
287 center.longitude = boundary->circle.center->longitude;
288 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
289 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
290 location_coords_s left_top;
291 location_coords_s right_bottom;
292 left_top.latitude = boundary->rect.left_top->latitude;
293 left_top.longitude = boundary->rect.left_top->longitude;
294 right_bottom.latitude = boundary->rect.right_bottom->latitude;
295 right_bottom.longitude = boundary->rect.right_bottom->longitude;
296 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
297 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
298 GList *list = boundary->polygon.position_list;
299 int size = g_list_length(list);
301 location_coords_s coords[size];
304 LocationPosition *pos = list->data;
305 coords[cnt].latitude = pos->latitude;
306 coords[cnt].longitude = pos->longitude;
307 list = g_list_next(list);
310 ret = location_bounds_create_polygon(coords, size, &bounds);
313 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
316 if (ret != LOCATIONS_ERROR_NONE) {
317 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
319 if (handle->is_continue_foreach_bounds) {
320 handle->is_continue_foreach_bounds =
321 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
324 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
326 location_bounds_destroy(bounds);
329 LOCATIONS_LOGD("__foreach_boundary() has been failed");
333 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
335 LOCATIONS_LOGD("method: [%d]", method);
336 location_method_e _method = __convert_location_method_e(method);
337 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
338 if (_setting_changed == NULL) {
339 LOCATIONS_LOGE("Invaild userdata\n");
343 if (_setting_changed[_method].callback != NULL) {
344 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
348 /*/////////////////////////////////////// */
349 /* Location Manager */
350 /*////////////////////////////////////// */
352 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
354 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
355 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
356 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
360 if (method == LOCATIONS_METHOD_GPS) {
361 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
362 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
365 } else if (method == LOCATIONS_METHOD_WPS) {
366 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
367 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
372 LocationMethod _method = __convert_LocationMethod(method);
373 if (_method == LOCATION_METHOD_NONE) {
374 LOCATIONS_LOGE("Not supported method [%d]", method);
375 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
379 set_last_result(LOCATIONS_ERROR_NONE);
380 return location_is_supported_method(_method);
383 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
385 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
387 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
388 LOCATIONS_LOGE("Not supported method [%d]", method);
389 return LOCATIONS_ERROR_INCORRECT_METHOD;
392 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
393 LOCATIONS_NULL_ARG_CHECK(enable);
394 int is_enabled_val = -1;
395 LocationMethod _method = __convert_LocationMethod(method);
396 int ret = location_is_enabled_method(_method, &is_enabled_val);
397 if (ret != LOCATION_ERROR_NONE) {
398 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
399 return LOCATIONS_ERROR_INCORRECT_METHOD;
400 return __convert_error_code(ret);
402 if (is_enabled_val == -1) {
403 return TIZEN_ERROR_PERMISSION_DENIED;
406 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
407 return LOCATIONS_ERROR_NONE;
410 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
412 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
414 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
415 LOCATIONS_LOGE("Not supported method [%d]", method);
416 return LOCATIONS_ERROR_INCORRECT_METHOD;
419 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
422 if (LOCATIONS_METHOD_HYBRID == method) {
423 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
424 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
425 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
427 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
428 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
429 return __convert_error_code(ret);
431 return LOCATIONS_ERROR_NONE;
434 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
435 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
436 return LOCATIONS_ERROR_NOT_SUPPORTED;
437 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
438 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
439 return LOCATIONS_ERROR_NOT_SUPPORTED;
442 LocationMethod _method = __convert_LocationMethod(method);
444 int ret = location_enable_method(_method, enable);
446 return __convert_error_code(ret);
451 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
453 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
455 if (method == LOCATIONS_METHOD_HYBRID) {
456 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
457 } else if (method == LOCATIONS_METHOD_GPS) {
458 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
459 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
460 return LOCATIONS_ERROR_NOT_SUPPORTED;
462 } else if (method == LOCATIONS_METHOD_WPS) {
463 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
464 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
465 return LOCATIONS_ERROR_NOT_SUPPORTED;
469 LocationMethod _method = __convert_LocationMethod(method);
470 if (_method == LOCATION_METHOD_NONE) {
471 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
472 return LOCATIONS_ERROR_NOT_SUPPORTED;
474 if (!location_is_supported_method(_method)) {
475 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
476 return LOCATIONS_ERROR_NOT_SUPPORTED;
479 /*It is moved here becasue of TCS. */
480 LOCATIONS_NULL_ARG_CHECK(manager);
482 if (location_init() != LOCATION_ERROR_NONE) {
483 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
484 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
487 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
488 if (handle == NULL) {
489 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
490 return LOCATIONS_ERROR_OUT_OF_MEMORY;
493 memset(handle, 0, sizeof(location_manager_s));
495 handle->object = location_new(_method);
496 if (handle->object == NULL) {
497 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
499 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
501 handle->method = method;
502 handle->is_continue_foreach_bounds = TRUE;
503 handle->bounds_list = NULL;
505 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
506 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
508 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
509 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
511 *manager = (location_manager_h) handle;
512 return LOCATIONS_ERROR_NONE;
515 EXPORT_API int location_manager_destroy(location_manager_h manager)
517 LOCATIONS_LOGD("location_manager_destroy");
518 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
519 LOCATIONS_NULL_ARG_CHECK(manager);
520 location_manager_s *handle = (location_manager_s *) manager;
522 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
523 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
524 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
527 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
528 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
529 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
532 int ret = location_free(handle->object);
533 if (ret != LOCATIONS_ERROR_NONE) {
534 return __convert_error_code(ret);
537 return LOCATIONS_ERROR_NONE;
540 EXPORT_API int location_manager_start(location_manager_h manager)
542 LOCATIONS_LOGD("location_manager_start");
543 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
544 LOCATIONS_NULL_ARG_CHECK(manager);
545 location_manager_s *handle = (location_manager_s *) manager;
547 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
548 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
550 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
551 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
552 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
554 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
555 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
557 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
560 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
561 LOCATIONS_LOGI("Satellite update_cb is set");
562 location_set_option(handle->object, "USE_SV");
565 int ret = location_start(handle->object);
566 if (ret != LOCATION_ERROR_NONE) {
567 return __convert_error_code(ret);
569 return LOCATIONS_ERROR_NONE;
572 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
574 LOCATIONS_LOGD("location_manager_request_single_location");
575 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
576 LOCATIONS_NULL_ARG_CHECK(manager);
577 LOCATIONS_NULL_ARG_CHECK(callback);
578 if (timeout <= 0 || timeout > 120) {
579 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
580 return LOCATIONS_ERROR_INVALID_PARAMETER;
583 location_manager_s *handle = (location_manager_s *) manager;
584 int ret = LOCATIONS_ERROR_NONE;
586 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
587 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
589 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
590 if (ret != LOCATIONS_ERROR_NONE) {
594 ret = location_request_single_location(handle->object, timeout);
595 if (ret != LOCATION_ERROR_NONE) {
596 return __convert_error_code(ret);
598 return LOCATIONS_ERROR_NONE;
601 EXPORT_API int location_manager_stop(location_manager_h manager)
603 LOCATIONS_LOGD("location_manager_stop");
604 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
605 LOCATIONS_NULL_ARG_CHECK(manager);
607 location_manager_s *handle = (location_manager_s *) manager;
609 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
610 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
611 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
614 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
615 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
616 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
617 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
620 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
621 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
622 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
626 int ret = location_stop(handle->object);
627 if (ret != LOCATION_ERROR_NONE) {
628 return __convert_error_code(ret);
630 return LOCATIONS_ERROR_NONE;
633 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
635 LOCATIONS_LOGD("location_manager_add_boundary");
636 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
637 LOCATIONS_NULL_ARG_CHECK(manager);
638 LOCATIONS_NULL_ARG_CHECK(bounds);
640 location_manager_s *handle = (location_manager_s *) manager;
641 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
642 int ret = location_boundary_add(handle->object, bound_handle->boundary);
643 if (ret != LOCATION_ERROR_NONE) {
644 return __convert_error_code(ret);
646 bound_handle->is_added = TRUE;
647 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
648 return LOCATIONS_ERROR_NONE;
651 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
653 LOCATIONS_LOGD("location_manager_remove_boundary");
654 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
655 LOCATIONS_NULL_ARG_CHECK(manager);
656 LOCATIONS_NULL_ARG_CHECK(bounds);
658 location_manager_s *handle = (location_manager_s *) manager;
659 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
660 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
661 if (ret != LOCATION_ERROR_NONE) {
662 return __convert_error_code(ret);
664 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
665 bound_handle->is_added = FALSE;
666 return LOCATIONS_ERROR_NONE;
669 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
671 LOCATIONS_LOGD("location_manager_foreach_boundary");
672 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
673 LOCATIONS_NULL_ARG_CHECK(manager);
674 LOCATIONS_NULL_ARG_CHECK(callback);
676 location_manager_s *handle = (location_manager_s *) manager;
677 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
678 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
679 handle->is_continue_foreach_bounds = TRUE;
680 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
681 if (ret != LOCATION_ERROR_NONE) {
682 return __convert_error_code(ret);
684 return LOCATIONS_ERROR_NONE;
687 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
689 LOCATIONS_LOGD("location_manager_get_method %d", method);
690 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
691 LOCATIONS_NULL_ARG_CHECK(manager);
692 LOCATIONS_NULL_ARG_CHECK(method);
694 location_manager_s *handle = (location_manager_s *) manager;
695 LocationMethod _method = LOCATION_METHOD_NONE;
696 g_object_get(handle->object, "method", &_method, NULL);
698 case LOCATION_METHOD_NONE:
699 *method = LOCATIONS_METHOD_NONE;
701 case LOCATION_METHOD_HYBRID:
702 *method = LOCATIONS_METHOD_HYBRID;
704 case LOCATION_METHOD_GPS:
705 *method = LOCATIONS_METHOD_GPS;
707 case LOCATION_METHOD_WPS:
708 *method = LOCATIONS_METHOD_WPS;
711 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
712 LOCATIONS_ERROR_INVALID_PARAMETER, method);
713 return LOCATIONS_ERROR_INVALID_PARAMETER;
716 /**method = handle->method; */
717 return LOCATIONS_ERROR_NONE;
720 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
723 LOCATIONS_LOGD("location_manager_get_position");
724 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
725 LOCATIONS_NULL_ARG_CHECK(manager);
726 LOCATIONS_NULL_ARG_CHECK(altitude);
727 LOCATIONS_NULL_ARG_CHECK(latitude);
728 LOCATIONS_NULL_ARG_CHECK(longitude);
729 LOCATIONS_NULL_ARG_CHECK(timestamp);
731 location_manager_s *handle = (location_manager_s *) manager;
733 LocationPosition *pos = NULL;
734 LocationAccuracy *acc = NULL;
735 ret = location_get_position(handle->object, &pos, &acc);
736 if (ret != LOCATION_ERROR_NONE) {
737 return __convert_error_code(ret);
740 if (pos->status == LOCATION_STATUS_NO_FIX) {
741 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
743 *latitude = pos->latitude;
744 *longitude = pos->longitude;
745 *altitude = pos->altitude;
747 *timestamp = pos->timestamp;
748 location_position_free(pos);
749 location_accuracy_free(acc);
750 return LOCATIONS_ERROR_NONE;
753 EXPORT_API int location_manager_get_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e *level, double *horizontal, double *vertical, time_t *timestamp)
755 LOCATIONS_LOGD("location_manager_get_location");
756 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
757 LOCATIONS_NULL_ARG_CHECK(manager);
758 LOCATIONS_NULL_ARG_CHECK(altitude);
759 LOCATIONS_NULL_ARG_CHECK(latitude);
760 LOCATIONS_NULL_ARG_CHECK(longitude);
761 LOCATIONS_NULL_ARG_CHECK(climb);
762 LOCATIONS_NULL_ARG_CHECK(direction);
763 LOCATIONS_NULL_ARG_CHECK(speed);
764 LOCATIONS_NULL_ARG_CHECK(level);
765 LOCATIONS_NULL_ARG_CHECK(horizontal);
766 LOCATIONS_NULL_ARG_CHECK(vertical);
767 LOCATIONS_NULL_ARG_CHECK(timestamp);
769 location_manager_s *handle = (location_manager_s *) manager;
771 LocationPosition *pos = NULL;
772 LocationVelocity *vel = NULL;
773 LocationAccuracy *acc = NULL;
774 ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
775 if (ret != LOCATION_ERROR_NONE) {
776 return __convert_error_code(ret);
779 if (pos->status == LOCATION_STATUS_NO_FIX) {
780 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
782 *latitude = pos->latitude;
783 *longitude = pos->longitude;
784 *altitude = pos->altitude;
786 *timestamp = pos->timestamp;
788 *direction = vel->direction;
791 *horizontal = acc->horizontal_accuracy;
792 *vertical = acc->vertical_accuracy;
794 location_position_free(pos);
795 location_velocity_free(vel);
796 location_accuracy_free(acc);
797 return LOCATIONS_ERROR_NONE;
800 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
802 LOCATIONS_LOGD("location_manager_get_velocity");
803 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
804 LOCATIONS_NULL_ARG_CHECK(manager);
805 LOCATIONS_NULL_ARG_CHECK(climb);
806 LOCATIONS_NULL_ARG_CHECK(direction);
807 LOCATIONS_NULL_ARG_CHECK(speed);
808 LOCATIONS_NULL_ARG_CHECK(timestamp);
810 location_manager_s *handle = (location_manager_s *) manager;
812 LocationVelocity *vel = NULL;
813 LocationAccuracy *acc = NULL;
814 ret = location_get_velocity(handle->object, &vel, &acc);
815 if (ret != LOCATION_ERROR_NONE) {
816 return __convert_error_code(ret);
820 *direction = vel->direction;
822 *timestamp = vel->timestamp;
823 location_velocity_free(vel);
824 location_accuracy_free(acc);
825 return LOCATIONS_ERROR_NONE;
828 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
831 LOCATIONS_LOGD("location_manager_get_accuracy");
832 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
833 LOCATIONS_NULL_ARG_CHECK(manager);
834 LOCATIONS_NULL_ARG_CHECK(level);
835 LOCATIONS_NULL_ARG_CHECK(horizontal);
836 LOCATIONS_NULL_ARG_CHECK(vertical);
837 location_manager_s *handle = (location_manager_s *) manager;
840 LocationPosition *pos = NULL;
841 LocationAccuracy *acc = NULL;
842 ret = location_get_position(handle->object, &pos, &acc);
843 if (ret != LOCATION_ERROR_NONE) {
844 return __convert_error_code(ret);
848 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
852 *horizontal = acc->horizontal_accuracy;
853 *vertical = acc->vertical_accuracy;
854 location_position_free(pos);
855 location_accuracy_free(acc);
856 return LOCATIONS_ERROR_NONE;
859 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
861 LOCATIONS_LOGD("location_manager_get_last_position");
862 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
863 LOCATIONS_NULL_ARG_CHECK(manager);
864 LOCATIONS_NULL_ARG_CHECK(altitude);
865 LOCATIONS_NULL_ARG_CHECK(latitude);
866 LOCATIONS_NULL_ARG_CHECK(longitude);
867 LOCATIONS_NULL_ARG_CHECK(timestamp);
869 location_manager_s *handle = (location_manager_s *) manager;
872 LocationPosition *last_pos = NULL;
873 LocationAccuracy *last_acc = NULL;
874 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
875 if (ret != LOCATION_ERROR_NONE) {
876 return __convert_error_code(ret);
879 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
880 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
882 *latitude = last_pos->latitude;
883 *longitude = last_pos->longitude;
884 *altitude = last_pos->altitude;
886 *timestamp = last_pos->timestamp;
887 location_position_free(last_pos);
888 location_accuracy_free(last_acc);
889 return LOCATIONS_ERROR_NONE;
892 EXPORT_API int location_manager_get_last_location(location_manager_h manager, double *altitude, double *latitude, double *longitude, double *climb, double *direction, double *speed, location_accuracy_level_e *level, double *horizontal, double *vertical, time_t *timestamp)
894 LOCATIONS_LOGD("location_manager_get_last_location");
895 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
896 LOCATIONS_NULL_ARG_CHECK(manager);
897 LOCATIONS_NULL_ARG_CHECK(altitude);
898 LOCATIONS_NULL_ARG_CHECK(latitude);
899 LOCATIONS_NULL_ARG_CHECK(longitude);
900 LOCATIONS_NULL_ARG_CHECK(climb);
901 LOCATIONS_NULL_ARG_CHECK(direction);
902 LOCATIONS_NULL_ARG_CHECK(speed);
903 LOCATIONS_NULL_ARG_CHECK(level);
904 LOCATIONS_NULL_ARG_CHECK(horizontal);
905 LOCATIONS_NULL_ARG_CHECK(vertical);
906 LOCATIONS_NULL_ARG_CHECK(timestamp);
908 location_manager_s *handle = (location_manager_s *) manager;
911 LocationPosition *last_pos = NULL;
912 LocationVelocity *last_vel = NULL;
913 LocationAccuracy *last_acc = NULL;
914 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
915 if (ret != LOCATION_ERROR_NONE) {
916 return __convert_error_code(ret);
919 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
920 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
922 *latitude = last_pos->latitude;
923 *longitude = last_pos->longitude;
924 *altitude = last_pos->altitude;
926 *timestamp = last_pos->timestamp;
927 *climb = last_vel->climb;
928 *direction = last_vel->direction;
929 *speed = last_vel->speed;
930 *level = last_acc->level;
931 *horizontal = last_acc->horizontal_accuracy;
932 *vertical = last_acc->vertical_accuracy;
933 location_position_free(last_pos);
934 location_velocity_free(last_vel);
935 location_accuracy_free(last_acc);
936 return LOCATIONS_ERROR_NONE;
939 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
941 LOCATIONS_LOGD("location_manager_get_last_velocity");
942 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
943 LOCATIONS_NULL_ARG_CHECK(manager);
944 LOCATIONS_NULL_ARG_CHECK(climb);
945 LOCATIONS_NULL_ARG_CHECK(direction);
946 LOCATIONS_NULL_ARG_CHECK(speed);
947 LOCATIONS_NULL_ARG_CHECK(timestamp);
949 location_manager_s *handle = (location_manager_s *) manager;
952 LocationVelocity *last_vel = NULL;
953 LocationAccuracy *last_acc = NULL;
954 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
955 if (ret != LOCATION_ERROR_NONE) {
956 return __convert_error_code(ret);
959 *climb = last_vel->climb;
960 *direction = last_vel->direction;
961 *speed = last_vel->speed;
962 *timestamp = last_vel->timestamp;
963 location_velocity_free(last_vel);
964 location_accuracy_free(last_acc);
965 return LOCATIONS_ERROR_NONE;
968 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
970 LOCATIONS_LOGD("location_manager_get_last_accuracy");
971 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
972 LOCATIONS_NULL_ARG_CHECK(manager);
973 LOCATIONS_NULL_ARG_CHECK(level);
974 LOCATIONS_NULL_ARG_CHECK(horizontal);
975 LOCATIONS_NULL_ARG_CHECK(vertical);
976 location_manager_s *handle = (location_manager_s *) manager;
979 LocationPosition *last_pos = NULL;
980 LocationAccuracy *last_acc = NULL;
981 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
982 if (ret != LOCATION_ERROR_NONE) {
983 return __convert_error_code(ret);
986 *level = last_acc->level;
987 *horizontal = last_acc->horizontal_accuracy;
988 *vertical = last_acc->vertical_accuracy;
989 location_position_free(last_pos);
990 location_accuracy_free(last_acc);
991 return LOCATIONS_ERROR_NONE;
994 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
996 LOCATIONS_LOGD("location_manager_get_accessibility_state");
997 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
998 LOCATIONS_NULL_ARG_CHECK(state);
1000 int ret = LOCATION_ERROR_NONE;
1001 LocationAccessState auth = LOCATION_ACCESS_NONE;
1002 ret = location_get_accessibility_state(&auth);
1003 if (ret != LOCATION_ERROR_NONE) {
1004 *state = LOCATIONS_ACCESS_STATE_NONE;
1005 return __convert_error_code(ret);
1009 case LOCATION_ACCESS_DENIED:
1010 *state = LOCATIONS_ACCESS_STATE_DENIED;
1012 case LOCATION_ACCESS_ALLOWED:
1013 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1015 case LOCATION_ACCESS_NONE:
1017 *state = LOCATIONS_ACCESS_STATE_NONE;
1021 return LOCATIONS_ERROR_NONE;
1024 EXPORT_API int location_manager_set_distance_based_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, double distance, void *user_data)
1026 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1027 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1028 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1029 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1030 LOCATIONS_NULL_ARG_CHECK(manager);
1031 location_manager_s *handle = (location_manager_s *) manager;
1032 g_object_set(handle->object, "min-interval", interval, NULL);
1033 g_object_set(handle->object, "min-distance", distance, NULL);
1034 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1037 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1039 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1040 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1041 LOCATIONS_NULL_ARG_CHECK(manager);
1042 location_manager_s *handle = (location_manager_s *) manager;
1043 g_object_set(handle->object, "min-interval", 0, NULL);
1044 g_object_set(handle->object, "min-distance", 0, NULL);
1045 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1048 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1050 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1051 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1052 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1053 LOCATIONS_NULL_ARG_CHECK(manager);
1054 location_manager_s *handle = (location_manager_s *) manager;
1055 g_object_set(handle->object, "loc-interval", interval, NULL);
1056 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1059 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1061 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1062 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1063 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1066 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1068 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1069 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1070 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1071 LOCATIONS_NULL_ARG_CHECK(manager);
1072 location_manager_s *handle = (location_manager_s *) manager;
1073 g_object_set(handle->object, "pos-interval", interval, NULL);
1074 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1077 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1079 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1080 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1081 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1084 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1086 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1087 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1088 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1089 LOCATIONS_NULL_ARG_CHECK(manager);
1090 location_manager_s *handle = (location_manager_s *) manager;
1091 g_object_set(handle->object, "vel-interval", interval, NULL);
1092 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1095 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1097 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1098 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1099 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1102 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1105 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1106 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1107 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1110 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1112 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1113 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1114 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1117 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1119 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1120 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1121 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1124 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1126 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1127 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1128 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1131 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1133 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1134 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1135 LOCATIONS_NULL_ARG_CHECK(callback);
1137 LocationMethod _method = __convert_LocationMethod(method);
1138 int ret = LOCATION_ERROR_NONE;
1140 if (_method == LOCATION_METHOD_NONE) {
1141 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1144 g_location_setting[_method].callback = callback;
1145 g_location_setting[_method].user_data = user_data;
1147 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1148 if (ret != LOCATION_ERROR_NONE) {
1149 return __convert_error_code(ret);
1152 return LOCATIONS_ERROR_NONE;
1155 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1157 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1158 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1159 LocationMethod _method = __convert_LocationMethod(method);
1160 int ret = LOCATION_ERROR_NONE;
1162 if (_method == LOCATION_METHOD_NONE) {
1163 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1166 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1167 if (ret != LOCATION_ERROR_NONE) {
1168 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1169 ret = __convert_error_code(ret);
1172 g_location_setting[method].callback = NULL;
1173 g_location_setting[method].user_data = NULL;
1175 return LOCATIONS_ERROR_NONE;
1178 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1180 LOCATIONS_LOGD("location_manager_get_distance");
1181 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1182 LOCATIONS_NULL_ARG_CHECK(distance);
1183 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1184 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1185 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1186 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1188 int ret = LOCATION_ERROR_NONE;
1191 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1192 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1194 ret = location_get_distance(start, end, &u_distance);
1195 if (ret != LOCATION_ERROR_NONE) {
1196 return __convert_error_code(ret);
1199 *distance = (double)u_distance;
1201 return LOCATIONS_ERROR_NONE;
1204 /*/////////////////////////////////////// */
1205 /* GPS Status & Satellites */
1206 /*////////////////////////////////////// */
1208 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1210 LOCATIONS_LOGD("gps_status_get_nmea");
1211 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1212 LOCATIONS_NULL_ARG_CHECK(manager);
1213 LOCATIONS_NULL_ARG_CHECK(nmea);
1214 location_manager_s *handle = (location_manager_s *) manager;
1217 int ret = location_get_nmea(handle->object, &nmea_data);
1218 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1219 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1220 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1221 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1224 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1225 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1228 *nmea = g_strdup(nmea_data);
1231 return LOCATIONS_ERROR_NONE;
1234 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1236 LOCATIONS_LOGD("gps_status_get_satellite");
1237 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1238 LOCATIONS_NULL_ARG_CHECK(manager);
1239 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1240 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1241 LOCATIONS_NULL_ARG_CHECK(timestamp);
1242 location_manager_s *handle = (location_manager_s *) manager;
1243 LocationSatellite *sat = NULL;
1244 int ret = location_get_satellite(handle->object, &sat);
1245 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1246 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1247 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1248 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1251 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1252 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1255 *num_of_active = sat->num_of_sat_used;
1256 *num_of_inview = sat->num_of_sat_inview;
1257 *timestamp = sat->timestamp;
1258 location_satellite_free(sat);
1260 return LOCATIONS_ERROR_NONE;
1263 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1265 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1266 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1267 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1268 LOCATIONS_NULL_ARG_CHECK(manager);
1269 LOCATIONS_NULL_ARG_CHECK(callback);
1271 location_manager_s *handle = (location_manager_s *) manager;
1272 location_set_option(handle->object, "USE_SV");
1273 g_object_set(handle->object, "sat-interval", interval, NULL);
1274 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1277 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1279 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1280 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1281 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1284 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1286 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1287 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1288 LOCATIONS_NULL_ARG_CHECK(manager);
1289 LOCATIONS_NULL_ARG_CHECK(callback);
1291 location_manager_s *handle = (location_manager_s *) manager;
1292 LocationSatellite *sat = NULL;
1293 int ret = location_get_satellite(handle->object, &sat);
1294 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1295 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1296 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1297 return LOCATIONS_ERROR_INCORRECT_METHOD;
1298 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1299 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1300 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1303 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1304 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1308 for (i = 0; i < sat->num_of_sat_inview; i++) {
1314 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1315 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1318 location_satellite_free(sat);
1320 return LOCATIONS_ERROR_NONE;
1323 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1325 LOCATIONS_LOGD("gps_status_get_last_satellite");
1326 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1327 LOCATIONS_NULL_ARG_CHECK(manager);
1328 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1329 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1330 LOCATIONS_NULL_ARG_CHECK(timestamp);
1332 location_manager_s *handle = (location_manager_s *) manager;
1333 int ret = LOCATION_ERROR_NONE;
1334 LocationSatellite *last_sat = NULL;
1335 ret = location_get_last_satellite(handle->object, &last_sat);
1336 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1337 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1338 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1339 return LOCATIONS_ERROR_INCORRECT_METHOD;
1340 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1341 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1342 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1345 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1346 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1349 *num_of_active = last_sat->num_of_sat_used;
1350 *num_of_inview = last_sat->num_of_sat_inview;
1351 *timestamp = last_sat->timestamp;
1352 location_satellite_free(last_sat);
1353 return LOCATIONS_ERROR_NONE;
1356 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1358 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1359 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1360 LOCATIONS_NULL_ARG_CHECK(manager);
1361 LOCATIONS_NULL_ARG_CHECK(callback);
1362 location_manager_s *handle = (location_manager_s *) manager;
1364 LocationSatellite *last_sat = NULL;
1365 ret = location_get_last_satellite(handle->object, &last_sat);
1366 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1367 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1368 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1369 return LOCATIONS_ERROR_INCORRECT_METHOD;
1372 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1373 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1377 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1383 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1384 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1388 location_satellite_free(last_sat);
1389 return LOCATIONS_ERROR_NONE;