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_MOCK + 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_MOCK:
60 _method = LOCATION_METHOD_MOCK;
62 case LOCATIONS_METHOD_NONE:
64 _method = LOCATION_METHOD_NONE;
70 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
72 LOCATIONS_LOGD("Callback function has been invoked. ");
73 location_manager_s *handle = (location_manager_s *) userdata;
75 if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
76 LocationSatellite *sat = (LocationSatellite *)data;
77 LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
78 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
79 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
80 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
81 } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
82 LocationPosition *pos = (LocationPosition *) data;
83 LocationVelocity *vel = (LocationVelocity *) velocity; /* current velocity */
84 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
85 vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
88 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
89 LocationPosition *pos = (LocationPosition *) data;
90 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude, pos->timestamp,
91 handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
94 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
95 LocationVelocity *vel = (LocationVelocity *) velocity;
96 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb, vel->timestamp,
97 handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
100 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
101 LocationPosition *pos = (LocationPosition *) data;
102 LocationVelocity *vel = (LocationVelocity *) velocity;
103 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
104 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
105 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
110 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
112 LOCATIONS_LOGD("Callback function has been invoked. ");
113 int converted_err = __convert_error_code(error);
114 location_manager_s *handle = (location_manager_s *) userdata;
115 LocationPosition *pos = (LocationPosition *) position;
116 LocationVelocity *vel = (LocationVelocity *) velocity;
118 LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
119 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
120 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
121 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
125 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
127 LOCATIONS_LOGD("Invoked. status = %d", status);
128 location_manager_s *handle = (location_manager_s *) userdata;
129 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
130 ((location_service_state_changed_cb)
131 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
135 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
137 LOCATIONS_LOGD("Invoked. status = %d", status);
138 location_manager_s *handle = (location_manager_s *) userdata;
139 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
140 ((location_service_state_changed_cb)
141 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
146 static void __cb_service_status_changed(GObject *self, guint status, gpointer userdata)
148 LOCATIONS_LOGD("Invoked. status = %u", status);
149 location_manager_s *handle = (location_manager_s *) userdata;
151 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
152 if (status == LOCATION_STATUS_2D_FIX || status == LOCATION_STATUS_3D_FIX)
153 ((location_service_state_changed_cb)
154 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
155 else if (status == LOCATION_STATUS_NO_FIX)
156 ((location_service_state_changed_cb)
157 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
158 else if (status == LOCATION_STATUS_MOCK_FAIL)
159 ((location_service_state_changed_cb)
160 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ERROR, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
165 static int __compare_position(gconstpointer a, gconstpointer b)
167 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
174 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
178 if (bound1->type == bound2->type) {
179 switch (bound1->type) {
180 case LOCATION_BOUNDARY_CIRCLE:
181 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
185 case LOCATION_BOUNDARY_RECT:
186 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
190 case LOCATION_BOUNDARY_POLYGON: {
191 GList *boundary1_next = NULL;
192 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
193 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
197 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
198 if (boundary2_start == NULL) return -1;
200 boundary2_prev = g_list_previous(boundary2_start);
201 boundary2_next = g_list_next(boundary2_start);
203 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
204 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
206 boundary1_next = g_list_next(bound1->polygon.position_list);
207 if (boundary1_next != NULL && boundary2_prev != NULL &&
208 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
209 boundary1_next = g_list_next(boundary1_next);
210 while (boundary1_next) {
211 boundary2_prev = g_list_previous(boundary2_prev);
212 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
213 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
216 boundary1_next = g_list_next(boundary1_next);
219 } else if (boundary1_next != NULL && boundary2_next != NULL &&
220 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
221 boundary1_next = g_list_next(boundary1_next);
222 while (boundary1_next) {
223 boundary2_next = g_list_next(boundary2_next);
224 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
225 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
228 boundary1_next = g_list_next(boundary1_next);
243 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
245 LOCATIONS_LOGD("ENTER >>>");
246 location_manager_s *handle = (location_manager_s *) userdata;
247 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
248 LocationPosition *pos = (LocationPosition *) position;
249 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
250 pos->latitude, pos->longitude,
251 pos->altitude, pos->timestamp,
253 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
256 location_bounds_s *bounds;
257 GList *bounds_list = g_list_first(handle->bounds_list);
258 while (bounds_list) {
259 bounds = (location_bounds_s *)bounds_list->data;
260 if (__boundary_compare(boundary, bounds->boundary) == 0) {
261 LOCATIONS_LOGD("Find zone in boundary");
262 if (bounds->user_cb) {
263 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
267 bounds_list = g_list_next(bounds_list);
269 LOCATIONS_LOGD("EXIT <<<");
272 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
274 LOCATIONS_LOGD("ENTER >>>");
275 location_manager_s *handle = (location_manager_s *) userdata;
276 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
277 LocationPosition *pos = (LocationPosition *) position;
278 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
279 pos->latitude, pos->longitude,
280 pos->altitude, pos->timestamp,
282 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
285 location_bounds_s *bounds;
286 GList *bounds_list = g_list_first(handle->bounds_list);
287 while (bounds_list) {
288 bounds = (location_bounds_s *)bounds_list->data;
289 if (__boundary_compare(boundary, bounds->boundary) == 0) {
290 LOCATIONS_LOGD("Find zone out boundary");
291 if (bounds->user_cb) {
292 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
296 bounds_list = g_list_next(bounds_list);
298 LOCATIONS_LOGD("EXIT <<<");
301 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
303 location_manager_s *handle = (location_manager_s *) user_data;
305 if (handle != NULL && boundary != NULL) {
307 location_bounds_h bounds;
308 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
309 location_coords_s center;
310 center.latitude = boundary->circle.center->latitude;
311 center.longitude = boundary->circle.center->longitude;
312 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
313 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
314 location_coords_s left_top;
315 location_coords_s right_bottom;
316 left_top.latitude = boundary->rect.left_top->latitude;
317 left_top.longitude = boundary->rect.left_top->longitude;
318 right_bottom.latitude = boundary->rect.right_bottom->latitude;
319 right_bottom.longitude = boundary->rect.right_bottom->longitude;
320 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
321 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
322 GList *list = boundary->polygon.position_list;
323 int size = g_list_length(list);
325 location_coords_s coords[size];
328 LocationPosition *pos = list->data;
329 coords[cnt].latitude = pos->latitude;
330 coords[cnt].longitude = pos->longitude;
331 list = g_list_next(list);
334 ret = location_bounds_create_polygon(coords, size, &bounds);
337 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
340 if (ret != LOCATIONS_ERROR_NONE) {
341 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
343 if (handle->is_continue_foreach_bounds) {
344 handle->is_continue_foreach_bounds =
345 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
348 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
350 location_bounds_destroy(bounds);
353 LOCATIONS_LOGD("__foreach_boundary() has been failed");
357 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
359 LOCATIONS_LOGD("method: [%d]", method);
360 location_method_e _method = __convert_location_method_e(method);
361 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
362 if (_setting_changed == NULL) {
363 LOCATIONS_LOGE("Invaild userdata\n");
367 if (_setting_changed[_method].callback != NULL) {
368 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
372 /*/////////////////////////////////////// */
373 /* Location Manager */
374 /*////////////////////////////////////// */
376 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
378 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
379 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
380 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
384 if (method == LOCATIONS_METHOD_GPS) {
385 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
386 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
389 } else if (method == LOCATIONS_METHOD_WPS) {
390 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
391 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
396 LocationMethod _method = __convert_LocationMethod(method);
397 if (_method == LOCATION_METHOD_NONE) {
398 LOCATIONS_LOGE("Not supported method [%d]", method);
399 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
403 set_last_result(LOCATIONS_ERROR_NONE);
404 return location_is_supported_method(_method);
407 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
409 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
411 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) {
412 LOCATIONS_LOGE("Not supported method [%d]", method);
413 return LOCATIONS_ERROR_INCORRECT_METHOD;
416 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
417 LOCATIONS_NULL_ARG_CHECK(enable);
418 int is_enabled_val = -1;
419 LocationMethod _method = __convert_LocationMethod(method);
420 int ret = location_is_enabled_method(_method, &is_enabled_val);
421 if (ret != LOCATION_ERROR_NONE) {
422 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
423 return LOCATIONS_ERROR_INCORRECT_METHOD;
424 return __convert_error_code(ret);
426 if (is_enabled_val == -1) {
427 return TIZEN_ERROR_PERMISSION_DENIED;
430 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
431 return LOCATIONS_ERROR_NONE;
434 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
436 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
438 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_MOCK < method) {
439 LOCATIONS_LOGE("Not supported method [%d]", method);
440 return LOCATIONS_ERROR_INCORRECT_METHOD;
443 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
446 if (LOCATIONS_METHOD_HYBRID == method) {
447 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
448 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
449 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
451 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
452 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
453 return __convert_error_code(ret);
455 return LOCATIONS_ERROR_NONE;
457 } else if (LOCATIONS_METHOD_MOCK == method) {
458 ret = location_enable_mock(LOCATION_METHOD_MOCK, enable);
459 return __convert_error_code(ret);
461 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
462 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
463 return LOCATIONS_ERROR_NOT_SUPPORTED;
464 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
465 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
466 return LOCATIONS_ERROR_NOT_SUPPORTED;
469 LocationMethod _method = __convert_LocationMethod(method);
471 int ret = location_enable_method(_method, enable);
473 return __convert_error_code(ret);
477 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
479 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
481 if (method == LOCATIONS_METHOD_HYBRID) {
482 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
483 } else if (method == LOCATIONS_METHOD_GPS) {
484 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
485 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
486 return LOCATIONS_ERROR_NOT_SUPPORTED;
488 } else if (method == LOCATIONS_METHOD_WPS) {
489 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
490 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
491 return LOCATIONS_ERROR_NOT_SUPPORTED;
495 LocationMethod _method = __convert_LocationMethod(method);
496 if (_method == LOCATION_METHOD_NONE) {
497 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
498 return LOCATIONS_ERROR_NOT_SUPPORTED;
501 if (!location_is_supported_method(_method)) {
502 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
503 return LOCATIONS_ERROR_NOT_SUPPORTED;
506 /*It is moved here becasue of TCS. */
507 LOCATIONS_NULL_ARG_CHECK(manager);
509 if (location_init() != LOCATION_ERROR_NONE) {
510 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
511 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
514 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
515 if (handle == NULL) {
516 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
517 return LOCATIONS_ERROR_OUT_OF_MEMORY;
520 memset(handle, 0, sizeof(location_manager_s));
522 handle->object = location_new(_method);
523 if (handle->object == NULL) {
524 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
526 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
528 handle->method = method;
529 handle->is_continue_foreach_bounds = TRUE;
530 handle->bounds_list = NULL;
532 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
533 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
535 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
536 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
539 if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED])
540 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle);
543 *manager = (location_manager_h) handle;
544 return LOCATIONS_ERROR_NONE;
547 EXPORT_API int location_manager_destroy(location_manager_h manager)
549 LOCATIONS_LOGD("location_manager_destroy");
550 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
551 LOCATIONS_NULL_ARG_CHECK(manager);
552 location_manager_s *handle = (location_manager_s *) manager;
555 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
556 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
557 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
560 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
561 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
562 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
566 if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) {
567 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]);
568 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0;
572 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
573 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
574 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
577 int ret = location_free(handle->object);
578 if (ret != LOCATIONS_ERROR_NONE) {
579 return __convert_error_code(ret);
582 return LOCATIONS_ERROR_NONE;
585 EXPORT_API int location_manager_start(location_manager_h manager)
587 LOCATIONS_LOGD("location_manager_start");
588 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
589 LOCATIONS_NULL_ARG_CHECK(manager);
590 location_manager_s *handle = (location_manager_s *) manager;
592 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
593 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
595 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
596 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
597 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
599 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
600 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
602 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
605 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
606 LOCATIONS_LOGI("Satellite update_cb is set");
607 location_set_option(handle->object, "USE_SV");
610 int ret = location_start(handle->object);
611 if (ret != LOCATION_ERROR_NONE) {
612 return __convert_error_code(ret);
614 return LOCATIONS_ERROR_NONE;
617 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
619 LOCATIONS_LOGD("location_manager_request_single_location");
620 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
621 LOCATIONS_NULL_ARG_CHECK(manager);
622 LOCATIONS_NULL_ARG_CHECK(callback);
623 if (timeout <= 0 || timeout > 120) {
624 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
625 return LOCATIONS_ERROR_INVALID_PARAMETER;
628 location_manager_s *handle = (location_manager_s *) manager;
629 int ret = LOCATIONS_ERROR_NONE;
631 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
632 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
634 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
635 if (ret != LOCATIONS_ERROR_NONE) {
639 ret = location_request_single_location(handle->object, timeout);
640 if (ret != LOCATION_ERROR_NONE) {
641 return __convert_error_code(ret);
643 return LOCATIONS_ERROR_NONE;
646 EXPORT_API int location_manager_stop(location_manager_h manager)
648 LOCATIONS_LOGD("location_manager_stop");
649 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
650 LOCATIONS_NULL_ARG_CHECK(manager);
652 location_manager_s *handle = (location_manager_s *) manager;
654 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
655 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
656 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
659 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
660 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
661 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
662 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
665 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
666 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
667 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
671 int ret = location_stop(handle->object);
672 if (ret != LOCATION_ERROR_NONE) {
673 return __convert_error_code(ret);
675 return LOCATIONS_ERROR_NONE;
678 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
680 LOCATIONS_LOGD("location_manager_add_boundary");
681 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
682 LOCATIONS_NULL_ARG_CHECK(manager);
683 LOCATIONS_NULL_ARG_CHECK(bounds);
685 location_manager_s *handle = (location_manager_s *) manager;
686 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
687 int ret = location_boundary_add(handle->object, bound_handle->boundary);
688 if (ret != LOCATION_ERROR_NONE) {
689 return __convert_error_code(ret);
691 bound_handle->is_added = TRUE;
692 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
693 return LOCATIONS_ERROR_NONE;
696 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
698 LOCATIONS_LOGD("location_manager_remove_boundary");
699 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
700 LOCATIONS_NULL_ARG_CHECK(manager);
701 LOCATIONS_NULL_ARG_CHECK(bounds);
703 location_manager_s *handle = (location_manager_s *) manager;
704 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
705 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
706 if (ret != LOCATION_ERROR_NONE) {
707 return __convert_error_code(ret);
709 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
710 bound_handle->is_added = FALSE;
711 return LOCATIONS_ERROR_NONE;
714 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
716 LOCATIONS_LOGD("location_manager_foreach_boundary");
717 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
718 LOCATIONS_NULL_ARG_CHECK(manager);
719 LOCATIONS_NULL_ARG_CHECK(callback);
721 location_manager_s *handle = (location_manager_s *) manager;
722 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
723 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
724 handle->is_continue_foreach_bounds = TRUE;
725 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
726 if (ret != LOCATION_ERROR_NONE) {
727 return __convert_error_code(ret);
729 return LOCATIONS_ERROR_NONE;
732 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
734 LOCATIONS_LOGD("location_manager_get_method %d", method);
735 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
736 LOCATIONS_NULL_ARG_CHECK(manager);
737 LOCATIONS_NULL_ARG_CHECK(method);
739 location_manager_s *handle = (location_manager_s *) manager;
740 LocationMethod _method = LOCATION_METHOD_NONE;
741 g_object_get(handle->object, "method", &_method, NULL);
743 case LOCATION_METHOD_NONE:
744 *method = LOCATIONS_METHOD_NONE;
746 case LOCATION_METHOD_HYBRID:
747 *method = LOCATIONS_METHOD_HYBRID;
749 case LOCATION_METHOD_GPS:
750 *method = LOCATIONS_METHOD_GPS;
752 case LOCATION_METHOD_WPS:
753 *method = LOCATIONS_METHOD_WPS;
755 case LOCATION_METHOD_MOCK:
756 *method = LOCATIONS_METHOD_MOCK;
759 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
760 LOCATIONS_ERROR_INVALID_PARAMETER, method);
761 return LOCATIONS_ERROR_INVALID_PARAMETER;
764 return LOCATIONS_ERROR_NONE;
767 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
770 LOCATIONS_LOGD("location_manager_get_position");
771 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
772 LOCATIONS_NULL_ARG_CHECK(manager);
773 LOCATIONS_NULL_ARG_CHECK(altitude);
774 LOCATIONS_NULL_ARG_CHECK(latitude);
775 LOCATIONS_NULL_ARG_CHECK(longitude);
776 LOCATIONS_NULL_ARG_CHECK(timestamp);
778 location_manager_s *handle = (location_manager_s *) manager;
780 LocationPosition *pos = NULL;
781 LocationAccuracy *acc = NULL;
782 ret = location_get_position(handle->object, &pos, &acc);
783 if (ret != LOCATION_ERROR_NONE) {
784 return __convert_error_code(ret);
787 if (pos->status == LOCATION_STATUS_NO_FIX) {
788 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
790 *latitude = pos->latitude;
791 *longitude = pos->longitude;
792 *altitude = pos->altitude;
794 *timestamp = pos->timestamp;
795 location_position_free(pos);
796 location_accuracy_free(acc);
797 return LOCATIONS_ERROR_NONE;
800 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)
802 LOCATIONS_LOGD("location_manager_get_location");
803 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
804 LOCATIONS_NULL_ARG_CHECK(manager);
805 LOCATIONS_NULL_ARG_CHECK(altitude);
806 LOCATIONS_NULL_ARG_CHECK(latitude);
807 LOCATIONS_NULL_ARG_CHECK(longitude);
808 LOCATIONS_NULL_ARG_CHECK(climb);
809 LOCATIONS_NULL_ARG_CHECK(direction);
810 LOCATIONS_NULL_ARG_CHECK(speed);
811 LOCATIONS_NULL_ARG_CHECK(level);
812 LOCATIONS_NULL_ARG_CHECK(horizontal);
813 LOCATIONS_NULL_ARG_CHECK(vertical);
814 LOCATIONS_NULL_ARG_CHECK(timestamp);
816 location_manager_s *handle = (location_manager_s *) manager;
818 LocationPosition *pos = NULL;
819 LocationVelocity *vel = NULL;
820 LocationAccuracy *acc = NULL;
821 ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
822 if (ret != LOCATION_ERROR_NONE) {
823 return __convert_error_code(ret);
826 if (pos->status == LOCATION_STATUS_NO_FIX) {
827 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
829 *latitude = pos->latitude;
830 *longitude = pos->longitude;
831 *altitude = pos->altitude;
833 *timestamp = pos->timestamp;
835 *direction = vel->direction;
838 *horizontal = acc->horizontal_accuracy;
839 *vertical = acc->vertical_accuracy;
841 location_position_free(pos);
842 location_velocity_free(vel);
843 location_accuracy_free(acc);
844 return LOCATIONS_ERROR_NONE;
847 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
849 LOCATIONS_LOGD("location_manager_get_velocity");
850 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
851 LOCATIONS_NULL_ARG_CHECK(manager);
852 LOCATIONS_NULL_ARG_CHECK(climb);
853 LOCATIONS_NULL_ARG_CHECK(direction);
854 LOCATIONS_NULL_ARG_CHECK(speed);
855 LOCATIONS_NULL_ARG_CHECK(timestamp);
857 location_manager_s *handle = (location_manager_s *) manager;
859 LocationVelocity *vel = NULL;
860 LocationAccuracy *acc = NULL;
861 ret = location_get_velocity(handle->object, &vel, &acc);
862 if (ret != LOCATION_ERROR_NONE) {
863 return __convert_error_code(ret);
867 *direction = vel->direction;
869 *timestamp = vel->timestamp;
870 location_velocity_free(vel);
871 location_accuracy_free(acc);
872 return LOCATIONS_ERROR_NONE;
875 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
878 LOCATIONS_LOGD("location_manager_get_accuracy");
879 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
880 LOCATIONS_NULL_ARG_CHECK(manager);
881 LOCATIONS_NULL_ARG_CHECK(level);
882 LOCATIONS_NULL_ARG_CHECK(horizontal);
883 LOCATIONS_NULL_ARG_CHECK(vertical);
884 location_manager_s *handle = (location_manager_s *) manager;
887 LocationPosition *pos = NULL;
888 LocationAccuracy *acc = NULL;
889 ret = location_get_position(handle->object, &pos, &acc);
890 if (ret != LOCATION_ERROR_NONE) {
891 return __convert_error_code(ret);
895 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
899 *horizontal = acc->horizontal_accuracy;
900 *vertical = acc->vertical_accuracy;
901 location_position_free(pos);
902 location_accuracy_free(acc);
903 return LOCATIONS_ERROR_NONE;
906 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
908 LOCATIONS_LOGD("location_manager_get_last_position");
909 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
910 LOCATIONS_NULL_ARG_CHECK(manager);
911 LOCATIONS_NULL_ARG_CHECK(altitude);
912 LOCATIONS_NULL_ARG_CHECK(latitude);
913 LOCATIONS_NULL_ARG_CHECK(longitude);
914 LOCATIONS_NULL_ARG_CHECK(timestamp);
916 location_manager_s *handle = (location_manager_s *) manager;
919 LocationPosition *last_pos = NULL;
920 LocationAccuracy *last_acc = NULL;
921 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
922 if (ret != LOCATION_ERROR_NONE) {
923 return __convert_error_code(ret);
926 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
927 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
929 *latitude = last_pos->latitude;
930 *longitude = last_pos->longitude;
931 *altitude = last_pos->altitude;
933 *timestamp = last_pos->timestamp;
934 location_position_free(last_pos);
935 location_accuracy_free(last_acc);
936 return LOCATIONS_ERROR_NONE;
939 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)
941 LOCATIONS_LOGD("location_manager_get_last_location");
942 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
943 LOCATIONS_NULL_ARG_CHECK(manager);
944 LOCATIONS_NULL_ARG_CHECK(altitude);
945 LOCATIONS_NULL_ARG_CHECK(latitude);
946 LOCATIONS_NULL_ARG_CHECK(longitude);
947 LOCATIONS_NULL_ARG_CHECK(climb);
948 LOCATIONS_NULL_ARG_CHECK(direction);
949 LOCATIONS_NULL_ARG_CHECK(speed);
950 LOCATIONS_NULL_ARG_CHECK(level);
951 LOCATIONS_NULL_ARG_CHECK(horizontal);
952 LOCATIONS_NULL_ARG_CHECK(vertical);
953 LOCATIONS_NULL_ARG_CHECK(timestamp);
955 location_manager_s *handle = (location_manager_s *) manager;
958 LocationPosition *last_pos = NULL;
959 LocationVelocity *last_vel = NULL;
960 LocationAccuracy *last_acc = NULL;
961 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
962 if (ret != LOCATION_ERROR_NONE) {
963 return __convert_error_code(ret);
966 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
967 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
969 *latitude = last_pos->latitude;
970 *longitude = last_pos->longitude;
971 *altitude = last_pos->altitude;
973 *timestamp = last_pos->timestamp;
974 *climb = last_vel->climb;
975 *direction = last_vel->direction;
976 *speed = last_vel->speed;
977 *level = last_acc->level;
978 *horizontal = last_acc->horizontal_accuracy;
979 *vertical = last_acc->vertical_accuracy;
980 location_position_free(last_pos);
981 location_velocity_free(last_vel);
982 location_accuracy_free(last_acc);
983 return LOCATIONS_ERROR_NONE;
986 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
988 LOCATIONS_LOGD("location_manager_get_last_velocity");
989 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
990 LOCATIONS_NULL_ARG_CHECK(manager);
991 LOCATIONS_NULL_ARG_CHECK(climb);
992 LOCATIONS_NULL_ARG_CHECK(direction);
993 LOCATIONS_NULL_ARG_CHECK(speed);
994 LOCATIONS_NULL_ARG_CHECK(timestamp);
996 location_manager_s *handle = (location_manager_s *) manager;
999 LocationVelocity *last_vel = NULL;
1000 LocationAccuracy *last_acc = NULL;
1001 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
1002 if (ret != LOCATION_ERROR_NONE) {
1003 return __convert_error_code(ret);
1006 *climb = last_vel->climb;
1007 *direction = last_vel->direction;
1008 *speed = last_vel->speed;
1009 *timestamp = last_vel->timestamp;
1010 location_velocity_free(last_vel);
1011 location_accuracy_free(last_acc);
1012 return LOCATIONS_ERROR_NONE;
1015 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
1017 LOCATIONS_LOGD("location_manager_get_last_accuracy");
1018 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1019 LOCATIONS_NULL_ARG_CHECK(manager);
1020 LOCATIONS_NULL_ARG_CHECK(level);
1021 LOCATIONS_NULL_ARG_CHECK(horizontal);
1022 LOCATIONS_NULL_ARG_CHECK(vertical);
1023 location_manager_s *handle = (location_manager_s *) manager;
1026 LocationPosition *last_pos = NULL;
1027 LocationAccuracy *last_acc = NULL;
1028 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1029 if (ret != LOCATION_ERROR_NONE) {
1030 return __convert_error_code(ret);
1033 *level = last_acc->level;
1034 *horizontal = last_acc->horizontal_accuracy;
1035 *vertical = last_acc->vertical_accuracy;
1036 location_position_free(last_pos);
1037 location_accuracy_free(last_acc);
1038 return LOCATIONS_ERROR_NONE;
1041 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1043 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1044 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1045 LOCATIONS_NULL_ARG_CHECK(state);
1047 int ret = LOCATION_ERROR_NONE;
1048 LocationAccessState auth = LOCATION_ACCESS_NONE;
1049 ret = location_get_accessibility_state(&auth);
1050 if (ret != LOCATION_ERROR_NONE) {
1051 *state = LOCATIONS_ACCESS_STATE_NONE;
1052 return __convert_error_code(ret);
1056 case LOCATION_ACCESS_DENIED:
1057 *state = LOCATIONS_ACCESS_STATE_DENIED;
1059 case LOCATION_ACCESS_ALLOWED:
1060 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1062 case LOCATION_ACCESS_NONE:
1064 *state = LOCATIONS_ACCESS_STATE_NONE;
1068 return LOCATIONS_ERROR_NONE;
1071 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)
1073 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1074 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1075 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1076 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1077 LOCATIONS_NULL_ARG_CHECK(manager);
1078 location_manager_s *handle = (location_manager_s *) manager;
1079 g_object_set(handle->object, "min-interval", interval, NULL);
1080 g_object_set(handle->object, "min-distance", distance, NULL);
1081 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1084 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1086 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1087 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1088 LOCATIONS_NULL_ARG_CHECK(manager);
1089 location_manager_s *handle = (location_manager_s *) manager;
1090 g_object_set(handle->object, "min-interval", 0, NULL);
1091 g_object_set(handle->object, "min-distance", 0, NULL);
1092 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1095 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1097 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1098 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1099 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1100 LOCATIONS_NULL_ARG_CHECK(manager);
1101 location_manager_s *handle = (location_manager_s *) manager;
1102 g_object_set(handle->object, "loc-interval", interval, NULL);
1103 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1106 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1108 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1109 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1110 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1113 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1115 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1116 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1117 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1118 LOCATIONS_NULL_ARG_CHECK(manager);
1119 location_manager_s *handle = (location_manager_s *) manager;
1120 g_object_set(handle->object, "pos-interval", interval, NULL);
1121 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1124 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1126 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1127 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1128 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1131 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1133 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1134 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1135 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1136 LOCATIONS_NULL_ARG_CHECK(manager);
1137 location_manager_s *handle = (location_manager_s *) manager;
1138 g_object_set(handle->object, "vel-interval", interval, NULL);
1139 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1142 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1144 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1145 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1146 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1149 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1152 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1153 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1154 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1157 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1159 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1160 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1161 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1164 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1166 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1167 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1168 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1171 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1173 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1174 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1175 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1178 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1180 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1181 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1182 LOCATIONS_NULL_ARG_CHECK(callback);
1184 LocationMethod _method = __convert_LocationMethod(method);
1185 int ret = LOCATION_ERROR_NONE;
1187 if (_method == LOCATION_METHOD_NONE) {
1188 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1191 g_location_setting[_method].callback = callback;
1192 g_location_setting[_method].user_data = user_data;
1194 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1195 if (ret != LOCATION_ERROR_NONE) {
1196 return __convert_error_code(ret);
1199 return LOCATIONS_ERROR_NONE;
1202 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1204 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1205 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1206 LocationMethod _method = __convert_LocationMethod(method);
1207 int ret = LOCATION_ERROR_NONE;
1209 if (_method == LOCATION_METHOD_NONE) {
1210 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1213 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1214 if (ret != LOCATION_ERROR_NONE) {
1215 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1216 ret = __convert_error_code(ret);
1219 g_location_setting[method].callback = NULL;
1220 g_location_setting[method].user_data = NULL;
1222 return LOCATIONS_ERROR_NONE;
1225 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1227 LOCATIONS_LOGD("location_manager_get_distance");
1228 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1229 LOCATIONS_NULL_ARG_CHECK(distance);
1230 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1231 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1232 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1233 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1235 int ret = LOCATION_ERROR_NONE;
1238 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1239 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1241 ret = location_get_distance(start, end, &u_distance);
1242 if (ret != LOCATION_ERROR_NONE) {
1243 return __convert_error_code(ret);
1246 *distance = (double)u_distance;
1248 return LOCATIONS_ERROR_NONE;
1251 /*/////////////////////////////////////// */
1252 /* GPS Status & Satellites */
1253 /*////////////////////////////////////// */
1255 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1257 LOCATIONS_LOGD("gps_status_get_nmea");
1258 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1259 LOCATIONS_NULL_ARG_CHECK(manager);
1260 LOCATIONS_NULL_ARG_CHECK(nmea);
1261 location_manager_s *handle = (location_manager_s *) manager;
1264 int ret = location_get_nmea(handle->object, &nmea_data);
1265 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1266 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1267 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1268 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1271 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1272 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1275 *nmea = g_strdup(nmea_data);
1278 return LOCATIONS_ERROR_NONE;
1281 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1283 LOCATIONS_LOGD("gps_status_get_satellite");
1284 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1285 LOCATIONS_NULL_ARG_CHECK(manager);
1286 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1287 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1288 LOCATIONS_NULL_ARG_CHECK(timestamp);
1289 location_manager_s *handle = (location_manager_s *) manager;
1290 LocationSatellite *sat = NULL;
1291 int ret = location_get_satellite(handle->object, &sat);
1292 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1293 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1294 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1295 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1298 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1299 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1302 *num_of_active = sat->num_of_sat_used;
1303 *num_of_inview = sat->num_of_sat_inview;
1304 *timestamp = sat->timestamp;
1305 location_satellite_free(sat);
1307 return LOCATIONS_ERROR_NONE;
1310 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1312 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1313 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1314 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1315 LOCATIONS_NULL_ARG_CHECK(manager);
1316 LOCATIONS_NULL_ARG_CHECK(callback);
1318 location_manager_s *handle = (location_manager_s *) manager;
1319 location_set_option(handle->object, "USE_SV");
1320 g_object_set(handle->object, "sat-interval", interval, NULL);
1321 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1324 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1326 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1327 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1328 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1331 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1333 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1334 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1335 LOCATIONS_NULL_ARG_CHECK(manager);
1336 LOCATIONS_NULL_ARG_CHECK(callback);
1338 location_manager_s *handle = (location_manager_s *) manager;
1339 LocationSatellite *sat = NULL;
1340 int ret = location_get_satellite(handle->object, &sat);
1341 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1342 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1343 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1344 return LOCATIONS_ERROR_INCORRECT_METHOD;
1345 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1346 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1347 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1350 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1351 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1355 for (i = 0; i < sat->num_of_sat_inview; i++) {
1361 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1362 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1365 location_satellite_free(sat);
1367 return LOCATIONS_ERROR_NONE;
1370 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1372 LOCATIONS_LOGD("gps_status_get_last_satellite");
1373 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1374 LOCATIONS_NULL_ARG_CHECK(manager);
1375 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1376 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1377 LOCATIONS_NULL_ARG_CHECK(timestamp);
1379 location_manager_s *handle = (location_manager_s *) manager;
1380 int ret = LOCATION_ERROR_NONE;
1381 LocationSatellite *last_sat = NULL;
1382 ret = location_get_last_satellite(handle->object, &last_sat);
1383 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1384 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1385 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1386 return LOCATIONS_ERROR_INCORRECT_METHOD;
1387 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1388 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1389 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1392 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1393 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1396 *num_of_active = last_sat->num_of_sat_used;
1397 *num_of_inview = last_sat->num_of_sat_inview;
1398 *timestamp = last_sat->timestamp;
1399 location_satellite_free(last_sat);
1400 return LOCATIONS_ERROR_NONE;
1403 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1405 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1406 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1407 LOCATIONS_NULL_ARG_CHECK(manager);
1408 LOCATIONS_NULL_ARG_CHECK(callback);
1409 location_manager_s *handle = (location_manager_s *) manager;
1410 int ret = LOCATION_ERROR_NONE;
1411 LocationSatellite *last_sat = NULL;
1413 ret = location_get_last_satellite(handle->object, &last_sat);
1414 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1415 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1416 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1417 return LOCATIONS_ERROR_INCORRECT_METHOD;
1420 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1421 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1425 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1431 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1432 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1436 location_satellite_free(last_sat);
1437 return LOCATIONS_ERROR_NONE;
1444 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1446 LOCATIONS_LOGD("enable: %d", enable);
1447 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1448 int ret = LOCATION_ERROR_NONE;
1450 ret = location_enable_mock(LOCATION_METHOD_MOCK, enable);
1451 return __convert_error_code(ret);
1454 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1455 const double speed, const double direction, const double accuracy)
1457 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1458 LOCATIONS_NULL_ARG_CHECK(manager);
1460 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1461 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1462 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1464 location_manager_s *handle = (location_manager_s *) manager;
1465 int ret = LOCATION_ERROR_NONE;
1467 LocationPosition *pos = NULL;
1468 LocationVelocity *vel = NULL;
1469 LocationAccuracy *acc = NULL;
1471 ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
1472 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1473 if (ret == LOCATIONS_ERROR_NONE) {
1475 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1479 return __convert_error_code(ret);
1482 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1484 LOCATIONS_LOGE("Failed to create position");
1485 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1487 vel = location_velocity_new(0, speed, direction, 0);
1489 LOCATIONS_LOGE("Failed to create volocity");
1490 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1493 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1495 LOCATIONS_LOGE("Failed to create accuracy");
1496 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1499 ret = location_set_mock_location(handle->object, pos, vel, acc);
1500 return __convert_error_code(ret);
1504 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1506 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1507 location_manager_s *handle = (location_manager_s *) manager;
1508 int ret = LOCATION_ERROR_NONE;
1511 ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
1512 if (ret == LOCATIONS_ERROR_NONE) {
1514 return __convert_error_code(LOCATIONS_ERROR_SETTING_OFF);
1517 return __convert_error_code(ret);
1520 ret = location_clear_mock_location(handle->object);
1521 return __convert_error_code(ret);
1527 * @brief Gets the state of location service.
1529 * @param[in] manager The location manager handle
1530 * @param[out] state The current state of location service
1531 * @return 0 on success, otherwise a negative error value
1532 * @retval #LOCATIONS_ERROR_NONE Successful
1533 * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
1534 * @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
1535 * @see location_manager_create()
1536 * @see location_manager_set_setting_changed_cb()
1537 * @see location_manager_unset_setting_changed_cb()
1539 int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state);
1541 EXPORT_API int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state)
1543 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1544 LOCATIONS_NULL_ARG_CHECK(manager);
1545 LOCATIONS_NULL_ARG_CHECK(state);
1547 location_manager_s *handle = (location_manager_s *) manager;
1549 int service_state = -1;
1551 int ret = location_get_service_state(handle->object, &service_state);
1552 if (ret != LOCATION_ERROR_NONE) {
1553 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
1554 return LOCATIONS_ERROR_INCORRECT_METHOD;
1555 return __convert_error_code(ret);
1558 switch (service_state) {
1560 ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1561 *state = LOCATIONS_SERVICE_DISABLED;
1564 *state = LOCATIONS_SERVICE_DISABLED;
1567 *state = LOCATIONS_SERVICE_ENABLED;
1570 *state = LOCATIONS_SERVICE_ERROR;
1578 EXPORT_API int location_add_test_provider(const LocationMethod method, const int enable)
1583 #ifndef TIZEN_PROFILE_TV
1584 ret = location_check_privilege(LOCATION_ENABLE_PRIVILEGE);
1585 if (ret != LOCATION_ERROR_NONE) {
1586 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
1587 return LOCATION_ERROR_NOT_ALLOWED;
1591 if (method == LOCATION_METHOD_MOCK) {
1592 _key = __convert_setting_key(method);
1594 LOCATION_LOGE("Invalid method[%d]", method);
1595 return LOCATION_ERROR_NOT_SUPPORTED;
1597 ret = vconf_set_int(_key, enable);
1598 if (ret != VCONF_OK) {
1599 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
1601 return LOCATION_ERROR_NOT_ALLOWED;