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;
493 } else if (method == LOCATIONS_METHOD_MOCK) {
494 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
495 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
496 return LOCATIONS_ERROR_NOT_SUPPORTED;
500 LocationMethod _method = __convert_LocationMethod(method);
501 if (_method == LOCATION_METHOD_NONE) {
502 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
503 return LOCATIONS_ERROR_NOT_SUPPORTED;
506 if (!location_is_supported_method(_method)) {
507 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
508 return LOCATIONS_ERROR_NOT_SUPPORTED;
511 /*It is moved here becasue of TCS. */
512 LOCATIONS_NULL_ARG_CHECK(manager);
514 if (location_init() != LOCATION_ERROR_NONE) {
515 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
516 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
519 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
520 if (handle == NULL) {
521 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
522 return LOCATIONS_ERROR_OUT_OF_MEMORY;
525 memset(handle, 0, sizeof(location_manager_s));
527 handle->object = location_new(_method);
528 if (handle->object == NULL) {
529 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
531 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
533 handle->method = method;
534 handle->is_continue_foreach_bounds = TRUE;
535 handle->bounds_list = NULL;
537 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
538 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
540 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
541 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
544 if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED])
545 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle);
548 *manager = (location_manager_h) handle;
549 return LOCATIONS_ERROR_NONE;
552 EXPORT_API int location_manager_destroy(location_manager_h manager)
554 LOCATIONS_LOGD("location_manager_destroy");
555 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
556 LOCATIONS_NULL_ARG_CHECK(manager);
557 location_manager_s *handle = (location_manager_s *) manager;
560 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
561 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
562 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
565 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
566 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
567 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
571 if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) {
572 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]);
573 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0;
577 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
578 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
579 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
582 int ret = location_free(handle->object);
583 if (ret != LOCATIONS_ERROR_NONE) {
584 return __convert_error_code(ret);
587 return LOCATIONS_ERROR_NONE;
590 EXPORT_API int location_manager_start(location_manager_h manager)
592 LOCATIONS_LOGD("location_manager_start");
593 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
594 LOCATIONS_NULL_ARG_CHECK(manager);
595 location_manager_s *handle = (location_manager_s *) manager;
597 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
598 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
600 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
601 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
602 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
604 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
605 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
607 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
610 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
611 LOCATIONS_LOGI("Satellite update_cb is set");
612 location_set_option(handle->object, "USE_SV");
615 int ret = location_start(handle->object);
616 if (ret != LOCATION_ERROR_NONE) {
617 return __convert_error_code(ret);
619 return LOCATIONS_ERROR_NONE;
622 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
624 LOCATIONS_LOGD("location_manager_request_single_location");
625 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
626 LOCATIONS_NULL_ARG_CHECK(manager);
627 LOCATIONS_NULL_ARG_CHECK(callback);
628 if (timeout <= 0 || timeout > 120) {
629 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
630 return LOCATIONS_ERROR_INVALID_PARAMETER;
633 location_manager_s *handle = (location_manager_s *) manager;
634 int ret = LOCATIONS_ERROR_NONE;
636 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
637 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
639 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
640 if (ret != LOCATIONS_ERROR_NONE) {
644 ret = location_request_single_location(handle->object, timeout);
645 if (ret != LOCATION_ERROR_NONE) {
646 return __convert_error_code(ret);
648 return LOCATIONS_ERROR_NONE;
651 EXPORT_API int location_manager_stop(location_manager_h manager)
653 LOCATIONS_LOGD("location_manager_stop");
654 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
655 LOCATIONS_NULL_ARG_CHECK(manager);
657 location_manager_s *handle = (location_manager_s *) manager;
659 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
660 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
661 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
664 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_MOCK >= handle->method) {
665 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
666 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
667 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
670 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
671 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
672 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
676 int ret = location_stop(handle->object);
677 if (ret != LOCATION_ERROR_NONE) {
678 return __convert_error_code(ret);
680 return LOCATIONS_ERROR_NONE;
683 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
685 LOCATIONS_LOGD("location_manager_add_boundary");
686 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
687 LOCATIONS_NULL_ARG_CHECK(manager);
688 LOCATIONS_NULL_ARG_CHECK(bounds);
690 location_manager_s *handle = (location_manager_s *) manager;
691 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
692 int ret = location_boundary_add(handle->object, bound_handle->boundary);
693 if (ret != LOCATION_ERROR_NONE) {
694 return __convert_error_code(ret);
696 bound_handle->is_added = TRUE;
697 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
698 return LOCATIONS_ERROR_NONE;
701 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
703 LOCATIONS_LOGD("location_manager_remove_boundary");
704 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
705 LOCATIONS_NULL_ARG_CHECK(manager);
706 LOCATIONS_NULL_ARG_CHECK(bounds);
708 location_manager_s *handle = (location_manager_s *) manager;
709 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
710 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
711 if (ret != LOCATION_ERROR_NONE) {
712 return __convert_error_code(ret);
714 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
715 bound_handle->is_added = FALSE;
716 return LOCATIONS_ERROR_NONE;
719 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
721 LOCATIONS_LOGD("location_manager_foreach_boundary");
722 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
723 LOCATIONS_NULL_ARG_CHECK(manager);
724 LOCATIONS_NULL_ARG_CHECK(callback);
726 location_manager_s *handle = (location_manager_s *) manager;
727 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
728 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
729 handle->is_continue_foreach_bounds = TRUE;
730 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
731 if (ret != LOCATION_ERROR_NONE) {
732 return __convert_error_code(ret);
734 return LOCATIONS_ERROR_NONE;
737 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
739 LOCATIONS_LOGD("location_manager_get_method %d", method);
740 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
741 LOCATIONS_NULL_ARG_CHECK(manager);
742 LOCATIONS_NULL_ARG_CHECK(method);
744 location_manager_s *handle = (location_manager_s *) manager;
745 LocationMethod _method = LOCATION_METHOD_NONE;
746 g_object_get(handle->object, "method", &_method, NULL);
748 case LOCATION_METHOD_NONE:
749 *method = LOCATIONS_METHOD_NONE;
751 case LOCATION_METHOD_HYBRID:
752 *method = LOCATIONS_METHOD_HYBRID;
754 case LOCATION_METHOD_GPS:
755 *method = LOCATIONS_METHOD_GPS;
757 case LOCATION_METHOD_WPS:
758 *method = LOCATIONS_METHOD_WPS;
760 case LOCATION_METHOD_MOCK:
761 *method = LOCATIONS_METHOD_MOCK;
764 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
765 LOCATIONS_ERROR_INVALID_PARAMETER, method);
766 return LOCATIONS_ERROR_INVALID_PARAMETER;
769 return LOCATIONS_ERROR_NONE;
772 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
775 LOCATIONS_LOGD("location_manager_get_position");
776 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
777 LOCATIONS_NULL_ARG_CHECK(manager);
778 LOCATIONS_NULL_ARG_CHECK(altitude);
779 LOCATIONS_NULL_ARG_CHECK(latitude);
780 LOCATIONS_NULL_ARG_CHECK(longitude);
781 LOCATIONS_NULL_ARG_CHECK(timestamp);
783 location_manager_s *handle = (location_manager_s *) manager;
785 LocationPosition *pos = NULL;
786 LocationAccuracy *acc = NULL;
787 ret = location_get_position(handle->object, &pos, &acc);
788 if (ret != LOCATION_ERROR_NONE) {
789 return __convert_error_code(ret);
792 if (pos->status == LOCATION_STATUS_NO_FIX) {
793 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
795 *latitude = pos->latitude;
796 *longitude = pos->longitude;
797 *altitude = pos->altitude;
799 *timestamp = pos->timestamp;
800 location_position_free(pos);
801 location_accuracy_free(acc);
802 return LOCATIONS_ERROR_NONE;
805 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)
807 LOCATIONS_LOGD("location_manager_get_location");
808 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
809 LOCATIONS_NULL_ARG_CHECK(manager);
810 LOCATIONS_NULL_ARG_CHECK(altitude);
811 LOCATIONS_NULL_ARG_CHECK(latitude);
812 LOCATIONS_NULL_ARG_CHECK(longitude);
813 LOCATIONS_NULL_ARG_CHECK(climb);
814 LOCATIONS_NULL_ARG_CHECK(direction);
815 LOCATIONS_NULL_ARG_CHECK(speed);
816 LOCATIONS_NULL_ARG_CHECK(level);
817 LOCATIONS_NULL_ARG_CHECK(horizontal);
818 LOCATIONS_NULL_ARG_CHECK(vertical);
819 LOCATIONS_NULL_ARG_CHECK(timestamp);
821 location_manager_s *handle = (location_manager_s *) manager;
823 LocationPosition *pos = NULL;
824 LocationVelocity *vel = NULL;
825 LocationAccuracy *acc = NULL;
826 ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
827 if (ret != LOCATION_ERROR_NONE) {
828 return __convert_error_code(ret);
831 if (pos->status == LOCATION_STATUS_NO_FIX) {
832 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
834 *latitude = pos->latitude;
835 *longitude = pos->longitude;
836 *altitude = pos->altitude;
838 *timestamp = pos->timestamp;
840 *direction = vel->direction;
843 *horizontal = acc->horizontal_accuracy;
844 *vertical = acc->vertical_accuracy;
846 location_position_free(pos);
847 location_velocity_free(vel);
848 location_accuracy_free(acc);
849 return LOCATIONS_ERROR_NONE;
852 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
854 LOCATIONS_LOGD("location_manager_get_velocity");
855 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
856 LOCATIONS_NULL_ARG_CHECK(manager);
857 LOCATIONS_NULL_ARG_CHECK(climb);
858 LOCATIONS_NULL_ARG_CHECK(direction);
859 LOCATIONS_NULL_ARG_CHECK(speed);
860 LOCATIONS_NULL_ARG_CHECK(timestamp);
862 location_manager_s *handle = (location_manager_s *) manager;
864 LocationVelocity *vel = NULL;
865 LocationAccuracy *acc = NULL;
866 ret = location_get_velocity(handle->object, &vel, &acc);
867 if (ret != LOCATION_ERROR_NONE) {
868 return __convert_error_code(ret);
872 *direction = vel->direction;
874 *timestamp = vel->timestamp;
875 location_velocity_free(vel);
876 location_accuracy_free(acc);
877 return LOCATIONS_ERROR_NONE;
880 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
883 LOCATIONS_LOGD("location_manager_get_accuracy");
884 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
885 LOCATIONS_NULL_ARG_CHECK(manager);
886 LOCATIONS_NULL_ARG_CHECK(level);
887 LOCATIONS_NULL_ARG_CHECK(horizontal);
888 LOCATIONS_NULL_ARG_CHECK(vertical);
889 location_manager_s *handle = (location_manager_s *) manager;
892 LocationPosition *pos = NULL;
893 LocationAccuracy *acc = NULL;
894 ret = location_get_position(handle->object, &pos, &acc);
895 if (ret != LOCATION_ERROR_NONE) {
896 return __convert_error_code(ret);
900 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
904 *horizontal = acc->horizontal_accuracy;
905 *vertical = acc->vertical_accuracy;
906 location_position_free(pos);
907 location_accuracy_free(acc);
908 return LOCATIONS_ERROR_NONE;
911 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
913 LOCATIONS_LOGD("location_manager_get_last_position");
914 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
915 LOCATIONS_NULL_ARG_CHECK(manager);
916 LOCATIONS_NULL_ARG_CHECK(altitude);
917 LOCATIONS_NULL_ARG_CHECK(latitude);
918 LOCATIONS_NULL_ARG_CHECK(longitude);
919 LOCATIONS_NULL_ARG_CHECK(timestamp);
921 location_manager_s *handle = (location_manager_s *) manager;
924 LocationPosition *last_pos = NULL;
925 LocationAccuracy *last_acc = NULL;
926 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
927 if (ret != LOCATION_ERROR_NONE) {
928 return __convert_error_code(ret);
931 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
932 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
934 *latitude = last_pos->latitude;
935 *longitude = last_pos->longitude;
936 *altitude = last_pos->altitude;
938 *timestamp = last_pos->timestamp;
939 location_position_free(last_pos);
940 location_accuracy_free(last_acc);
941 return LOCATIONS_ERROR_NONE;
944 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)
946 LOCATIONS_LOGD("location_manager_get_last_location");
947 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
948 LOCATIONS_NULL_ARG_CHECK(manager);
949 LOCATIONS_NULL_ARG_CHECK(altitude);
950 LOCATIONS_NULL_ARG_CHECK(latitude);
951 LOCATIONS_NULL_ARG_CHECK(longitude);
952 LOCATIONS_NULL_ARG_CHECK(climb);
953 LOCATIONS_NULL_ARG_CHECK(direction);
954 LOCATIONS_NULL_ARG_CHECK(speed);
955 LOCATIONS_NULL_ARG_CHECK(level);
956 LOCATIONS_NULL_ARG_CHECK(horizontal);
957 LOCATIONS_NULL_ARG_CHECK(vertical);
958 LOCATIONS_NULL_ARG_CHECK(timestamp);
960 location_manager_s *handle = (location_manager_s *) manager;
963 LocationPosition *last_pos = NULL;
964 LocationVelocity *last_vel = NULL;
965 LocationAccuracy *last_acc = NULL;
966 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
967 if (ret != LOCATION_ERROR_NONE) {
968 return __convert_error_code(ret);
971 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
972 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
974 *latitude = last_pos->latitude;
975 *longitude = last_pos->longitude;
976 *altitude = last_pos->altitude;
978 *timestamp = last_pos->timestamp;
979 *climb = last_vel->climb;
980 *direction = last_vel->direction;
981 *speed = last_vel->speed;
982 *level = last_acc->level;
983 *horizontal = last_acc->horizontal_accuracy;
984 *vertical = last_acc->vertical_accuracy;
985 location_position_free(last_pos);
986 location_velocity_free(last_vel);
987 location_accuracy_free(last_acc);
988 return LOCATIONS_ERROR_NONE;
991 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
993 LOCATIONS_LOGD("location_manager_get_last_velocity");
994 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
995 LOCATIONS_NULL_ARG_CHECK(manager);
996 LOCATIONS_NULL_ARG_CHECK(climb);
997 LOCATIONS_NULL_ARG_CHECK(direction);
998 LOCATIONS_NULL_ARG_CHECK(speed);
999 LOCATIONS_NULL_ARG_CHECK(timestamp);
1001 location_manager_s *handle = (location_manager_s *) manager;
1004 LocationVelocity *last_vel = NULL;
1005 LocationAccuracy *last_acc = NULL;
1006 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
1007 if (ret != LOCATION_ERROR_NONE) {
1008 return __convert_error_code(ret);
1011 *climb = last_vel->climb;
1012 *direction = last_vel->direction;
1013 *speed = last_vel->speed;
1014 *timestamp = last_vel->timestamp;
1015 location_velocity_free(last_vel);
1016 location_accuracy_free(last_acc);
1017 return LOCATIONS_ERROR_NONE;
1020 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
1022 LOCATIONS_LOGD("location_manager_get_last_accuracy");
1023 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1024 LOCATIONS_NULL_ARG_CHECK(manager);
1025 LOCATIONS_NULL_ARG_CHECK(level);
1026 LOCATIONS_NULL_ARG_CHECK(horizontal);
1027 LOCATIONS_NULL_ARG_CHECK(vertical);
1028 location_manager_s *handle = (location_manager_s *) manager;
1031 LocationPosition *last_pos = NULL;
1032 LocationAccuracy *last_acc = NULL;
1033 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1034 if (ret != LOCATION_ERROR_NONE) {
1035 return __convert_error_code(ret);
1038 *level = last_acc->level;
1039 *horizontal = last_acc->horizontal_accuracy;
1040 *vertical = last_acc->vertical_accuracy;
1041 location_position_free(last_pos);
1042 location_accuracy_free(last_acc);
1043 return LOCATIONS_ERROR_NONE;
1046 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1048 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1049 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1050 LOCATIONS_NULL_ARG_CHECK(state);
1052 int ret = LOCATION_ERROR_NONE;
1053 LocationAccessState auth = LOCATION_ACCESS_NONE;
1054 ret = location_get_accessibility_state(&auth);
1055 if (ret != LOCATION_ERROR_NONE) {
1056 *state = LOCATIONS_ACCESS_STATE_NONE;
1057 return __convert_error_code(ret);
1061 case LOCATION_ACCESS_DENIED:
1062 *state = LOCATIONS_ACCESS_STATE_DENIED;
1064 case LOCATION_ACCESS_ALLOWED:
1065 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1067 case LOCATION_ACCESS_NONE:
1069 *state = LOCATIONS_ACCESS_STATE_NONE;
1073 return LOCATIONS_ERROR_NONE;
1076 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)
1078 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1079 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1080 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1081 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1082 LOCATIONS_NULL_ARG_CHECK(manager);
1083 location_manager_s *handle = (location_manager_s *) manager;
1084 g_object_set(handle->object, "min-interval", interval, NULL);
1085 g_object_set(handle->object, "min-distance", distance, NULL);
1086 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1089 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1091 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1092 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1093 LOCATIONS_NULL_ARG_CHECK(manager);
1094 location_manager_s *handle = (location_manager_s *) manager;
1095 g_object_set(handle->object, "min-interval", 0, NULL);
1096 g_object_set(handle->object, "min-distance", 0, NULL);
1097 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1100 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1102 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1103 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1104 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1105 LOCATIONS_NULL_ARG_CHECK(manager);
1106 location_manager_s *handle = (location_manager_s *) manager;
1107 g_object_set(handle->object, "loc-interval", interval, NULL);
1108 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1111 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1113 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1114 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1115 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1118 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1120 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1121 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1122 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1123 LOCATIONS_NULL_ARG_CHECK(manager);
1124 location_manager_s *handle = (location_manager_s *) manager;
1125 g_object_set(handle->object, "pos-interval", interval, NULL);
1126 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1129 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1131 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1132 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1133 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1136 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1138 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1139 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1140 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1141 LOCATIONS_NULL_ARG_CHECK(manager);
1142 location_manager_s *handle = (location_manager_s *) manager;
1143 g_object_set(handle->object, "vel-interval", interval, NULL);
1144 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1147 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1149 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1150 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1151 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1154 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1157 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1158 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1159 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1162 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1164 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1165 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1166 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1169 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1171 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1172 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1173 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1176 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1178 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1179 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1180 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1183 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1185 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1186 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1187 LOCATIONS_NULL_ARG_CHECK(callback);
1189 LocationMethod _method = __convert_LocationMethod(method);
1190 int ret = LOCATION_ERROR_NONE;
1192 if (_method == LOCATION_METHOD_NONE) {
1193 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1196 g_location_setting[_method].callback = callback;
1197 g_location_setting[_method].user_data = user_data;
1199 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1200 if (ret != LOCATION_ERROR_NONE) {
1201 return __convert_error_code(ret);
1204 return LOCATIONS_ERROR_NONE;
1207 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1209 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1210 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1211 LocationMethod _method = __convert_LocationMethod(method);
1212 int ret = LOCATION_ERROR_NONE;
1214 if (_method == LOCATION_METHOD_NONE) {
1215 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1218 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1219 if (ret != LOCATION_ERROR_NONE) {
1220 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1221 ret = __convert_error_code(ret);
1224 g_location_setting[method].callback = NULL;
1225 g_location_setting[method].user_data = NULL;
1227 return LOCATIONS_ERROR_NONE;
1230 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1232 LOCATIONS_LOGD("location_manager_get_distance");
1233 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1234 LOCATIONS_NULL_ARG_CHECK(distance);
1235 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1236 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1237 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1238 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1240 int ret = LOCATION_ERROR_NONE;
1243 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1244 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1246 ret = location_get_distance(start, end, &u_distance);
1247 if (ret != LOCATION_ERROR_NONE) {
1248 return __convert_error_code(ret);
1251 *distance = (double)u_distance;
1253 return LOCATIONS_ERROR_NONE;
1256 /*/////////////////////////////////////// */
1257 /* GPS Status & Satellites */
1258 /*////////////////////////////////////// */
1260 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1262 LOCATIONS_LOGD("gps_status_get_nmea");
1263 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1264 LOCATIONS_NULL_ARG_CHECK(manager);
1265 LOCATIONS_NULL_ARG_CHECK(nmea);
1266 location_manager_s *handle = (location_manager_s *) manager;
1269 int ret = location_get_nmea(handle->object, &nmea_data);
1270 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1271 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1272 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1273 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1276 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1277 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1280 *nmea = g_strdup(nmea_data);
1283 return LOCATIONS_ERROR_NONE;
1286 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1288 LOCATIONS_LOGD("gps_status_get_satellite");
1289 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1290 LOCATIONS_NULL_ARG_CHECK(manager);
1291 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1292 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1293 LOCATIONS_NULL_ARG_CHECK(timestamp);
1294 location_manager_s *handle = (location_manager_s *) manager;
1295 LocationSatellite *sat = NULL;
1296 int ret = location_get_satellite(handle->object, &sat);
1297 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1298 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;
1307 *num_of_active = sat->num_of_sat_used;
1308 *num_of_inview = sat->num_of_sat_inview;
1309 *timestamp = sat->timestamp;
1310 location_satellite_free(sat);
1312 return LOCATIONS_ERROR_NONE;
1315 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1317 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1318 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1319 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1320 LOCATIONS_NULL_ARG_CHECK(manager);
1321 LOCATIONS_NULL_ARG_CHECK(callback);
1323 location_manager_s *handle = (location_manager_s *) manager;
1324 location_set_option(handle->object, "USE_SV");
1325 g_object_set(handle->object, "sat-interval", interval, NULL);
1326 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1329 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1331 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1332 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1333 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1336 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1338 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1339 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1340 LOCATIONS_NULL_ARG_CHECK(manager);
1341 LOCATIONS_NULL_ARG_CHECK(callback);
1343 location_manager_s *handle = (location_manager_s *) manager;
1344 LocationSatellite *sat = NULL;
1345 int ret = location_get_satellite(handle->object, &sat);
1346 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1347 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1348 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1349 return LOCATIONS_ERROR_INCORRECT_METHOD;
1350 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1351 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1352 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1355 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1356 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1360 for (i = 0; i < sat->num_of_sat_inview; i++) {
1366 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1367 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1370 location_satellite_free(sat);
1372 return LOCATIONS_ERROR_NONE;
1375 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1377 LOCATIONS_LOGD("gps_status_get_last_satellite");
1378 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1379 LOCATIONS_NULL_ARG_CHECK(manager);
1380 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1381 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1382 LOCATIONS_NULL_ARG_CHECK(timestamp);
1384 location_manager_s *handle = (location_manager_s *) manager;
1385 int ret = LOCATION_ERROR_NONE;
1386 LocationSatellite *last_sat = NULL;
1387 ret = location_get_last_satellite(handle->object, &last_sat);
1388 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1389 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1390 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1391 return LOCATIONS_ERROR_INCORRECT_METHOD;
1392 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1393 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1394 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1397 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1398 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1401 *num_of_active = last_sat->num_of_sat_used;
1402 *num_of_inview = last_sat->num_of_sat_inview;
1403 *timestamp = last_sat->timestamp;
1404 location_satellite_free(last_sat);
1405 return LOCATIONS_ERROR_NONE;
1408 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1410 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1411 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1412 LOCATIONS_NULL_ARG_CHECK(manager);
1413 LOCATIONS_NULL_ARG_CHECK(callback);
1414 location_manager_s *handle = (location_manager_s *) manager;
1415 int ret = LOCATION_ERROR_NONE;
1416 LocationSatellite *last_sat = NULL;
1418 ret = location_get_last_satellite(handle->object, &last_sat);
1419 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1420 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1421 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1422 return LOCATIONS_ERROR_INCORRECT_METHOD;
1425 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1426 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1430 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1436 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1437 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1441 location_satellite_free(last_sat);
1442 return LOCATIONS_ERROR_NONE;
1449 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1451 LOCATIONS_LOGD("enable: %d", enable);
1452 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1453 int ret = LOCATION_ERROR_NONE;
1455 ret = location_enable_mock(LOCATION_METHOD_MOCK, enable);
1456 return __convert_error_code(ret);
1459 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1460 const double speed, const double direction, const double accuracy)
1462 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1463 LOCATIONS_NULL_ARG_CHECK(manager);
1465 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1466 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1467 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1469 location_manager_s *handle = (location_manager_s *) manager;
1470 int ret = LOCATION_ERROR_NONE;
1472 LocationPosition *pos = NULL;
1473 LocationVelocity *vel = NULL;
1474 LocationAccuracy *acc = NULL;
1476 ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
1477 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1478 if (ret == LOCATIONS_ERROR_NONE) {
1480 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1484 return __convert_error_code(ret);
1487 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1489 LOCATIONS_LOGE("Failed to create position");
1490 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1492 vel = location_velocity_new(0, speed, direction, 0);
1494 LOCATIONS_LOGE("Failed to create volocity");
1495 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1498 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1500 LOCATIONS_LOGE("Failed to create accuracy");
1501 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1504 ret = location_set_mock_location(handle->object, pos, vel, acc);
1505 return __convert_error_code(ret);
1509 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1511 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1512 LOCATIONS_NULL_ARG_CHECK(manager);
1514 location_manager_s *handle = (location_manager_s *) manager;
1515 int ret = LOCATION_ERROR_NONE;
1518 ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled);
1519 if (ret == LOCATIONS_ERROR_NONE) {
1521 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1524 return __convert_error_code(ret);
1527 ret = location_clear_mock_location(handle->object);
1528 return __convert_error_code(ret);
1534 * @brief Gets the state of location service.
1536 * @param[in] manager The location manager handle
1537 * @param[out] state The current state of location service
1538 * @return 0 on success, otherwise a negative error value
1539 * @retval #LOCATIONS_ERROR_NONE Successful
1540 * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter
1541 * @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported
1542 * @see location_manager_create()
1543 * @see location_manager_set_setting_changed_cb()
1544 * @see location_manager_unset_setting_changed_cb()
1546 int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state);
1548 EXPORT_API int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state)
1550 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1551 LOCATIONS_NULL_ARG_CHECK(manager);
1552 LOCATIONS_NULL_ARG_CHECK(state);
1554 location_manager_s *handle = (location_manager_s *) manager;
1556 int service_state = -1;
1558 int ret = location_get_service_state(handle->object, &service_state);
1559 if (ret != LOCATION_ERROR_NONE) {
1560 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
1561 return LOCATIONS_ERROR_INCORRECT_METHOD;
1562 return __convert_error_code(ret);
1565 switch (service_state) {
1567 ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1568 *state = LOCATIONS_SERVICE_DISABLED;
1571 *state = LOCATIONS_SERVICE_DISABLED;
1574 *state = LOCATIONS_SERVICE_ENABLED;
1577 *state = LOCATIONS_SERVICE_ERROR;
1585 EXPORT_API int location_add_test_provider(const LocationMethod method, const int enable)
1590 #ifndef TIZEN_PROFILE_TV
1591 ret = location_check_privilege(LOCATION_ENABLE_PRIVILEGE);
1592 if (ret != LOCATION_ERROR_NONE) {
1593 LOCATION_LOGE("Cannot use location service for privacy[%d]", ret);
1594 return LOCATION_ERROR_NOT_ALLOWED;
1598 if (method == LOCATION_METHOD_MOCK) {
1599 _key = __convert_setting_key(method);
1601 LOCATION_LOGE("Invalid method[%d]", method);
1602 return LOCATION_ERROR_NOT_SUPPORTED;
1604 ret = vconf_set_int(_key, enable);
1605 if (ret != VCONF_OK) {
1606 LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret);
1608 return LOCATION_ERROR_NOT_ALLOWED;