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_PASSIVE + 1];
26 static location_method_e __convert_location_method_e(LocationMethod method)
28 location_method_e _method = LOCATIONS_METHOD_NONE; //LCOV_EXCL_LINE
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_PASSIVE:
60 _method = LOCATION_METHOD_PASSIVE;
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 location_manager_s *handle = (location_manager_s *) userdata;
74 if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
75 LocationSatellite *sat = (LocationSatellite *)data;
76 LOCATIONS_LOGD("callback invoked[TYPE_SATELLITE] timestamp : %d, number of active : %d, number of inview : %d",
77 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
78 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
79 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
80 } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
81 LocationPosition *pos = (LocationPosition *) data;
82 LocationVelocity *vel = (LocationVelocity *) velocity;
83 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
84 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(pos->latitude, pos->longitude, pos->altitude,
85 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
86 LOCATIONS_LOGD("callback invoked[TYPE_DISTANCE] timestamp : %d", pos->timestamp);
89 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
90 LocationPosition *pos = (LocationPosition *) data;
91 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude,
92 pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
93 LOCATIONS_LOGD("callback invoked[TYPE_POSITION] timestamp : %d", pos->timestamp);
96 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
97 LocationVelocity *vel = (LocationVelocity *) velocity;
98 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb,
99 vel->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
102 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
103 LocationPosition *pos = (LocationPosition *) data;
104 LocationVelocity *vel = (LocationVelocity *) velocity;
105 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
106 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
107 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
108 LOCATIONS_LOGD("callback invoked[TYPE_POS_VEL] timestamp : %d", pos->timestamp);
113 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
115 int converted_err = __convert_error_code(error);
116 location_manager_s *handle = (location_manager_s *) userdata;
117 LocationPosition *pos = (LocationPosition *) position;
118 LocationVelocity *vel = (LocationVelocity *) velocity;
120 LOCATIONS_LOGD("Callback function[TYPE_LOCATION: single] timestamp : %d, error : %d", pos->timestamp, error);
121 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
122 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
123 pos->timestamp, vel->speed, vel->direction, vel->climb, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
126 if (error != LOCATION_ERROR_NONE) {
128 location_position_free(pos);
129 location_velocity_free(vel);
135 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
137 LOCATIONS_LOGD("Batch callback function has been invoked.");
138 location_manager_s *handle = (location_manager_s *) userdata;
140 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
141 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
145 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
147 LOCATIONS_LOGD("Invoked[service_enabled]. status = %d", status);
148 location_manager_s *handle = (location_manager_s *) userdata;
149 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
150 ((location_service_state_changed_cb)
151 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
155 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
157 LOCATIONS_LOGD("Invoked[service_disabled]. status = %d", status);
158 location_manager_s *handle = (location_manager_s *) userdata;
159 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
160 ((location_service_state_changed_cb)
161 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, 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)
170 return -1; //LCOV_EXCL_LINE
173 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
177 if (bound1->type == bound2->type) {
178 switch (bound1->type) {
179 case LOCATION_BOUNDARY_CIRCLE:
180 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius)
184 case LOCATION_BOUNDARY_RECT:
185 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom))
189 case LOCATION_BOUNDARY_POLYGON: {
190 GList *boundary1_next = NULL;
191 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
192 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list))
195 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
196 if (boundary2_start == NULL) return -1;
198 boundary2_prev = g_list_previous(boundary2_start);
199 boundary2_next = g_list_next(boundary2_start);
201 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
202 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
204 boundary1_next = g_list_next(bound1->polygon.position_list);
205 if (boundary1_next != NULL && boundary2_prev != NULL &&
206 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
207 boundary1_next = g_list_next(boundary1_next);
208 while (boundary1_next) {
209 boundary2_prev = g_list_previous(boundary2_prev);
210 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
211 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
214 boundary1_next = g_list_next(boundary1_next);
217 } else if (boundary1_next != NULL && boundary2_next != NULL &&
218 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
219 boundary1_next = g_list_next(boundary1_next);
220 while (boundary1_next) {
221 boundary2_next = g_list_next(boundary2_next);
222 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
223 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
226 boundary1_next = g_list_next(boundary1_next);
241 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
243 LOCATIONS_LOGD("ENTER >>>");
244 location_manager_s *handle = (location_manager_s *) userdata;
245 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
246 LocationPosition *pos = (LocationPosition *) position;
247 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
248 pos->latitude, pos->longitude, pos->altitude, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
251 location_bounds_s *bounds;
252 GList *bounds_list = g_list_first(handle->bounds_list);
253 while (bounds_list) {
254 bounds = (location_bounds_s *)bounds_list->data;
255 if (__boundary_compare(boundary, bounds->boundary) == 0) {
256 LOCATIONS_LOGD("Find zone in boundary");
258 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
262 bounds_list = g_list_next(bounds_list);
264 LOCATIONS_LOGD("EXIT <<<");
267 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
269 LOCATIONS_LOGD("ENTER >>>");
270 location_manager_s *handle = (location_manager_s *) userdata;
271 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
272 LocationPosition *pos = (LocationPosition *) position;
273 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
274 pos->latitude, pos->longitude, pos->altitude, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_BOUNDARY]);
277 location_bounds_s *bounds;
278 GList *bounds_list = g_list_first(handle->bounds_list);
279 while (bounds_list) {
280 bounds = (location_bounds_s *)bounds_list->data;
281 if (__boundary_compare(boundary, bounds->boundary) == 0) {
282 LOCATIONS_LOGD("Find zone out boundary");
284 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
288 bounds_list = g_list_next(bounds_list);
290 LOCATIONS_LOGD("EXIT <<<");
293 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
295 location_manager_s *handle = (location_manager_s *) user_data;
297 if (handle != NULL && boundary != NULL) {
299 location_bounds_h bounds;
300 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
301 location_coords_s center;
302 center.latitude = boundary->circle.center->latitude;
303 center.longitude = boundary->circle.center->longitude;
304 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
305 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
306 location_coords_s left_top;
307 location_coords_s right_bottom;
308 left_top.latitude = boundary->rect.left_top->latitude;
309 left_top.longitude = boundary->rect.left_top->longitude;
310 right_bottom.latitude = boundary->rect.right_bottom->latitude;
311 right_bottom.longitude = boundary->rect.right_bottom->longitude;
312 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
313 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
314 GList *list = boundary->polygon.position_list;
315 int size = g_list_length(list);
317 location_coords_s coords[size];
320 LocationPosition *pos = list->data;
321 coords[cnt].latitude = pos->latitude;
322 coords[cnt].longitude = pos->longitude;
323 list = g_list_next(list);
326 ret = location_bounds_create_polygon(coords, size, &bounds);
329 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
332 if (ret != LOCATIONS_ERROR_NONE) {
333 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret); //LCOV_EXCL_LINE
335 if (handle->is_continue_foreach_bounds) {
336 handle->is_continue_foreach_bounds =
337 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
340 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
342 location_bounds_destroy(bounds);
345 LOCATIONS_LOGD("__foreach_boundary() has been failed"); //LCOV_EXCL_LINE
350 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
352 LOCATIONS_LOGD("method: [%d]", method);
353 location_method_e _method = __convert_location_method_e(method);
354 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
355 if (_setting_changed == NULL) {
356 LOCATIONS_LOGE("Invaild userdata\n");
360 if (_setting_changed[_method].callback != NULL)
361 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
365 /*/////////////////////////////////////// */
366 /* Location Manager */
367 /*////////////////////////////////////// */
369 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
371 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
372 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
373 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED); //LCOV_EXCL_LINE
374 return false; //LCOV_EXCL_LINE
377 if (method == LOCATIONS_METHOD_GPS) {
378 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
379 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED); //LCOV_EXCL_LINE
380 return false; //LCOV_EXCL_LINE
382 } else if (method == LOCATIONS_METHOD_WPS) {
383 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
384 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
389 LocationMethod _method = __convert_LocationMethod(method);
390 if (_method == LOCATION_METHOD_NONE) {
391 LOCATIONS_LOGE("Not supported method [%d]", method);
392 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
396 gboolean ret = location_is_supported_method(_method);
398 set_last_result(LOCATIONS_ERROR_NONE);
401 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
406 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
408 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
410 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
411 LOCATIONS_LOGE("Not supported method [%d]", method);
412 return LOCATIONS_ERROR_INCORRECT_METHOD;
415 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
416 LOCATIONS_NULL_ARG_CHECK(enable);
417 int is_enabled_val = -1;
418 LocationMethod _method = __convert_LocationMethod(method);
419 int ret = location_is_enabled_method(_method, &is_enabled_val);
420 if (ret != LOCATION_ERROR_NONE) {
422 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
423 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
424 return LOCATIONS_ERROR_INCORRECT_METHOD;
426 return __convert_error_code(ret);
430 if (is_enabled_val == -1)
431 return TIZEN_ERROR_PERMISSION_DENIED;
433 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
434 return LOCATIONS_ERROR_NONE;
438 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
440 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
442 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
443 LOCATIONS_LOGE("Not supported method [%d]", method);
444 return LOCATIONS_ERROR_INCORRECT_METHOD;
447 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
450 if (LOCATIONS_METHOD_HYBRID == method) {
451 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
452 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
453 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
455 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
456 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
457 return __convert_error_code(ret);
459 return LOCATIONS_ERROR_NONE;
462 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
463 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
464 return LOCATIONS_ERROR_NOT_SUPPORTED;
465 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
466 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
467 return LOCATIONS_ERROR_NOT_SUPPORTED;
470 LocationMethod _method = __convert_LocationMethod(method);
472 int ret = location_enable_method(_method, enable);
474 return __convert_error_code(ret);
479 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
481 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
483 if (method == LOCATIONS_METHOD_HYBRID)
484 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
485 else if (method == LOCATIONS_METHOD_GPS)
486 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
487 else if (method == LOCATIONS_METHOD_WPS)
488 LOCATIONS_NOT_SUPPORTED_CHECK(__is_wps_supported());
489 else if (method == LOCATIONS_METHOD_PASSIVE)
490 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
492 LocationMethod _method = __convert_LocationMethod(method);
493 if (_method == LOCATION_METHOD_NONE) {
494 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
495 return LOCATIONS_ERROR_NOT_SUPPORTED;
498 if (!location_is_supported_method(_method)) {
499 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
500 return LOCATIONS_ERROR_NOT_SUPPORTED;
503 /*It is moved here becasue of TCS. */
504 LOCATIONS_NULL_ARG_CHECK(manager);
506 if (location_init() != LOCATION_ERROR_NONE) {
507 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); //LCOV_EXCL_LINE
508 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; //LCOV_EXCL_LINE
511 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
512 if (handle == NULL) {
513 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY); //LCOV_EXCL_LINE
514 return LOCATIONS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
517 memset(handle, 0, sizeof(location_manager_s));
519 handle->object = location_new(_method, FALSE);
520 if (handle->object == NULL) {
522 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
524 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
527 handle->method = method;
528 handle->is_continue_foreach_bounds = TRUE;
529 handle->bounds_list = NULL;
531 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
532 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
534 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
535 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
537 *manager = (location_manager_h) handle;
538 return LOCATIONS_ERROR_NONE;
541 EXPORT_API int location_manager_destroy(location_manager_h manager)
543 LOCATIONS_LOGD("location_manager_destroy");
544 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
545 LOCATIONS_NULL_ARG_CHECK(manager);
546 location_manager_s *handle = (location_manager_s *) manager;
548 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
549 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
550 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
553 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
554 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
555 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
558 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
559 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]); //LCOV_EXCL_LINE
560 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0; //LCOV_EXCL_LINE
563 int ret = location_free(handle->object, FALSE);
564 if (ret != LOCATIONS_ERROR_NONE)
565 return __convert_error_code(ret); //LCOV_EXCL_LINE
568 return LOCATIONS_ERROR_NONE;
571 EXPORT_API int location_manager_start(location_manager_h manager)
573 LOCATIONS_LOGD("location_manager_start");
574 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
575 LOCATIONS_NULL_ARG_CHECK(manager);
576 location_manager_s *handle = (location_manager_s *) manager;
578 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
579 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
581 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
582 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
583 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
585 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
586 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
588 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method); //LCOV_EXCL_LINE
591 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
592 LOCATIONS_LOGI("Satellite update_cb is set");
593 location_set_option(handle->object, "USE_SV");
596 int ret = location_start(handle->object);
597 if (ret != LOCATION_ERROR_NONE)
598 return __convert_error_code(ret); //LCOV_EXCL_LINE
600 return LOCATIONS_ERROR_NONE;
603 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
605 LOCATIONS_LOGD("location_manager_request_single_location");
606 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
607 LOCATIONS_NULL_ARG_CHECK(manager);
608 LOCATIONS_NULL_ARG_CHECK(callback);
609 if (timeout <= 0 || timeout > 120) {
610 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
611 return LOCATIONS_ERROR_INVALID_PARAMETER;
614 location_manager_s *handle = (location_manager_s *) manager;
615 int ret = LOCATIONS_ERROR_NONE;
617 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
618 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
620 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
621 if (ret != LOCATIONS_ERROR_NONE)
624 ret = location_request_single_location(handle->object, timeout);
625 if (ret != LOCATION_ERROR_NONE) {
627 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
628 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
629 return LOCATIONS_ERROR_INCORRECT_METHOD;
631 return __convert_error_code(ret);
635 return LOCATIONS_ERROR_NONE;
638 EXPORT_API int location_manager_stop(location_manager_h manager)
640 LOCATIONS_LOGD("location_manager_stop");
641 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
642 LOCATIONS_NULL_ARG_CHECK(manager);
644 location_manager_s *handle = (location_manager_s *) manager;
646 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
647 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
648 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
651 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
652 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
653 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
654 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
657 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
658 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
659 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
663 int ret = location_stop(handle->object);
664 if (ret != LOCATION_ERROR_NONE)
665 return __convert_error_code(ret); //LCOV_EXCL_LINE
667 return LOCATIONS_ERROR_NONE;
670 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
672 LOCATIONS_LOGD("location_manager_add_boundary");
673 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
674 LOCATIONS_NULL_ARG_CHECK(manager);
675 LOCATIONS_NULL_ARG_CHECK(bounds);
677 location_manager_s *handle = (location_manager_s *) manager;
678 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
679 int ret = location_boundary_add(handle->object, bound_handle->boundary);
680 if (ret != LOCATION_ERROR_NONE)
681 return __convert_error_code(ret); //LCOV_EXCL_LINE
683 bound_handle->is_added = TRUE;
684 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
685 return LOCATIONS_ERROR_NONE;
688 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
690 LOCATIONS_LOGD("location_manager_remove_boundary");
691 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
692 LOCATIONS_NULL_ARG_CHECK(manager);
693 LOCATIONS_NULL_ARG_CHECK(bounds);
695 location_manager_s *handle = (location_manager_s *) manager;
696 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
697 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
698 if (ret != LOCATION_ERROR_NONE)
699 return __convert_error_code(ret); //LCOV_EXCL_LINE
701 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
702 bound_handle->is_added = FALSE;
703 return LOCATIONS_ERROR_NONE;
706 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
708 LOCATIONS_LOGD("location_manager_foreach_boundary");
709 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
710 LOCATIONS_NULL_ARG_CHECK(manager);
711 LOCATIONS_NULL_ARG_CHECK(callback);
713 location_manager_s *handle = (location_manager_s *) manager;
714 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
715 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
716 handle->is_continue_foreach_bounds = TRUE;
717 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
718 if (ret != LOCATION_ERROR_NONE)
719 return __convert_error_code(ret); //LCOV_EXCL_LINE
721 return LOCATIONS_ERROR_NONE;
724 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
726 LOCATIONS_LOGD("location_manager_get_method");
727 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
728 LOCATIONS_NULL_ARG_CHECK(manager);
729 LOCATIONS_NULL_ARG_CHECK(method);
731 location_manager_s *handle = (location_manager_s *) manager;
732 LocationMethod _method = LOCATION_METHOD_NONE;
733 g_object_get(handle->object, "method", &_method, NULL);
735 case LOCATION_METHOD_NONE:
736 *method = LOCATIONS_METHOD_NONE;
738 case LOCATION_METHOD_HYBRID:
739 *method = LOCATIONS_METHOD_HYBRID;
741 case LOCATION_METHOD_GPS:
742 *method = LOCATIONS_METHOD_GPS;
744 case LOCATION_METHOD_WPS:
745 *method = LOCATIONS_METHOD_WPS; //LCOV_EXCL_LINE
746 break; //LCOV_EXCL_LINE
747 case LOCATION_METHOD_PASSIVE:
748 *method = LOCATIONS_METHOD_PASSIVE;
751 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] invalid method"); //LCOV_EXCL_LINE
752 return LOCATIONS_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
755 return LOCATIONS_ERROR_NONE;
758 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
761 LOCATIONS_LOGD("location_manager_get_position");
762 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
763 LOCATIONS_NULL_ARG_CHECK(manager);
764 LOCATIONS_NULL_ARG_CHECK(altitude);
765 LOCATIONS_NULL_ARG_CHECK(latitude);
766 LOCATIONS_NULL_ARG_CHECK(longitude);
767 LOCATIONS_NULL_ARG_CHECK(timestamp);
769 location_manager_s *handle = (location_manager_s *) manager;
770 LocationPosition *pos = NULL;
771 LocationAccuracy *acc = NULL;
772 int ret = location_get_position(handle->object, &pos, &acc);
773 if (ret != LOCATION_ERROR_NONE)
774 return __convert_error_code(ret); //LCOV_EXCL_LINE
776 if (pos->status == LOCATION_STATUS_NO_FIX) {
777 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; //LCOV_EXCL_LINE
779 *latitude = pos->latitude;
780 *longitude = pos->longitude;
781 *altitude = pos->altitude;
783 *timestamp = pos->timestamp;
784 location_position_free(pos);
785 location_accuracy_free(acc);
786 return LOCATIONS_ERROR_NONE;
789 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)
791 LOCATIONS_LOGD("location_manager_get_location");
792 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
793 LOCATIONS_NULL_ARG_CHECK(manager);
794 LOCATIONS_NULL_ARG_CHECK(altitude);
795 LOCATIONS_NULL_ARG_CHECK(latitude);
796 LOCATIONS_NULL_ARG_CHECK(longitude);
797 LOCATIONS_NULL_ARG_CHECK(climb);
798 LOCATIONS_NULL_ARG_CHECK(direction);
799 LOCATIONS_NULL_ARG_CHECK(speed);
800 LOCATIONS_NULL_ARG_CHECK(level);
801 LOCATIONS_NULL_ARG_CHECK(horizontal);
802 LOCATIONS_NULL_ARG_CHECK(vertical);
803 LOCATIONS_NULL_ARG_CHECK(timestamp);
805 location_manager_s *handle = (location_manager_s *) manager;
806 LocationPosition *pos = NULL;
807 LocationVelocity *vel = NULL;
808 LocationAccuracy *acc = NULL;
809 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
810 if (ret != LOCATION_ERROR_NONE)
811 return __convert_error_code(ret); //LCOV_EXCL_LINE
813 if (pos->status == LOCATION_STATUS_NO_FIX) {
814 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE); //LCOV_EXCL_LINE
816 *latitude = pos->latitude;
817 *longitude = pos->longitude;
818 *altitude = pos->altitude;
820 *timestamp = pos->timestamp;
822 *direction = vel->direction;
825 *horizontal = acc->horizontal_accuracy;
826 *vertical = acc->vertical_accuracy;
828 location_position_free(pos);
829 location_velocity_free(vel);
830 location_accuracy_free(acc);
831 return LOCATIONS_ERROR_NONE;
834 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
836 LOCATIONS_LOGD("location_manager_get_velocity");
837 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
838 LOCATIONS_NULL_ARG_CHECK(manager);
839 LOCATIONS_NULL_ARG_CHECK(climb);
840 LOCATIONS_NULL_ARG_CHECK(direction);
841 LOCATIONS_NULL_ARG_CHECK(speed);
842 LOCATIONS_NULL_ARG_CHECK(timestamp);
844 location_manager_s *handle = (location_manager_s *) manager;
845 LocationVelocity *vel = NULL;
846 LocationAccuracy *acc = NULL;
848 int ret = location_get_velocity(handle->object, &vel, &acc);
849 if (ret != LOCATION_ERROR_NONE)
850 return __convert_error_code(ret); //LCOV_EXCL_LINE
853 *direction = vel->direction;
855 *timestamp = vel->timestamp;
856 location_velocity_free(vel);
857 location_accuracy_free(acc);
858 return LOCATIONS_ERROR_NONE;
861 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
864 LOCATIONS_LOGD("location_manager_get_accuracy");
865 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
866 LOCATIONS_NULL_ARG_CHECK(manager);
867 LOCATIONS_NULL_ARG_CHECK(level);
868 LOCATIONS_NULL_ARG_CHECK(horizontal);
869 LOCATIONS_NULL_ARG_CHECK(vertical);
870 location_manager_s *handle = (location_manager_s *) manager;
873 LocationPosition *pos = NULL;
874 LocationAccuracy *acc = NULL;
875 ret = location_get_position(handle->object, &pos, &acc);
876 if (ret != LOCATION_ERROR_NONE)
877 return __convert_error_code(ret); //LCOV_EXCL_LINE
880 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE); //LCOV_EXCL_LINE
883 *horizontal = acc->horizontal_accuracy;
884 *vertical = acc->vertical_accuracy;
885 location_position_free(pos);
886 location_accuracy_free(acc);
887 return LOCATIONS_ERROR_NONE;
890 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
892 LOCATIONS_LOGD("location_manager_get_last_position");
893 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
894 LOCATIONS_NULL_ARG_CHECK(manager);
895 LOCATIONS_NULL_ARG_CHECK(altitude);
896 LOCATIONS_NULL_ARG_CHECK(latitude);
897 LOCATIONS_NULL_ARG_CHECK(longitude);
898 LOCATIONS_NULL_ARG_CHECK(timestamp);
900 location_manager_s *handle = (location_manager_s *) manager;
903 LocationPosition *last_pos = NULL;
904 LocationAccuracy *last_acc = NULL;
905 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
906 if (ret != LOCATION_ERROR_NONE)
907 return __convert_error_code(ret); //LCOV_EXCL_LINE
909 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
910 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
912 *latitude = last_pos->latitude;
913 *longitude = last_pos->longitude;
914 *altitude = last_pos->altitude;
916 *timestamp = last_pos->timestamp;
917 location_position_free(last_pos);
918 location_accuracy_free(last_acc);
919 return LOCATIONS_ERROR_NONE;
922 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)
924 LOCATIONS_LOGD("location_manager_get_last_location");
925 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
926 LOCATIONS_NULL_ARG_CHECK(manager);
927 LOCATIONS_NULL_ARG_CHECK(altitude);
928 LOCATIONS_NULL_ARG_CHECK(latitude);
929 LOCATIONS_NULL_ARG_CHECK(longitude);
930 LOCATIONS_NULL_ARG_CHECK(climb);
931 LOCATIONS_NULL_ARG_CHECK(direction);
932 LOCATIONS_NULL_ARG_CHECK(speed);
933 LOCATIONS_NULL_ARG_CHECK(level);
934 LOCATIONS_NULL_ARG_CHECK(horizontal);
935 LOCATIONS_NULL_ARG_CHECK(vertical);
936 LOCATIONS_NULL_ARG_CHECK(timestamp);
938 location_manager_s *handle = (location_manager_s *) manager;
941 LocationPosition *last_pos = NULL;
942 LocationVelocity *last_vel = NULL;
943 LocationAccuracy *last_acc = NULL;
944 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
945 if (ret != LOCATION_ERROR_NONE)
946 return __convert_error_code(ret); //LCOV_EXCL_LINE
948 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
949 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
951 *latitude = last_pos->latitude;
952 *longitude = last_pos->longitude;
953 *altitude = last_pos->altitude;
955 *timestamp = last_pos->timestamp;
956 *climb = last_vel->climb;
957 *direction = last_vel->direction;
958 *speed = last_vel->speed;
959 *level = last_acc->level;
960 *horizontal = last_acc->horizontal_accuracy;
961 *vertical = last_acc->vertical_accuracy;
962 location_position_free(last_pos);
963 location_velocity_free(last_vel);
964 location_accuracy_free(last_acc);
965 return LOCATIONS_ERROR_NONE;
968 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
970 LOCATIONS_LOGD("location_manager_get_last_velocity");
971 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
972 LOCATIONS_NULL_ARG_CHECK(manager);
973 LOCATIONS_NULL_ARG_CHECK(climb);
974 LOCATIONS_NULL_ARG_CHECK(direction);
975 LOCATIONS_NULL_ARG_CHECK(speed);
976 LOCATIONS_NULL_ARG_CHECK(timestamp);
978 location_manager_s *handle = (location_manager_s *) manager;
981 LocationVelocity *last_vel = NULL;
982 LocationAccuracy *last_acc = NULL;
983 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
984 if (ret != LOCATION_ERROR_NONE)
985 return __convert_error_code(ret); //LCOV_EXCL_LINE
987 *climb = last_vel->climb;
988 *direction = last_vel->direction;
989 *speed = last_vel->speed;
990 *timestamp = last_vel->timestamp;
991 location_velocity_free(last_vel);
992 location_accuracy_free(last_acc);
993 return LOCATIONS_ERROR_NONE;
996 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
998 LOCATIONS_LOGD("location_manager_get_last_accuracy");
999 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1000 LOCATIONS_NULL_ARG_CHECK(manager);
1001 LOCATIONS_NULL_ARG_CHECK(level);
1002 LOCATIONS_NULL_ARG_CHECK(horizontal);
1003 LOCATIONS_NULL_ARG_CHECK(vertical);
1004 location_manager_s *handle = (location_manager_s *) manager;
1007 LocationPosition *last_pos = NULL;
1008 LocationAccuracy *last_acc = NULL;
1009 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1010 if (ret != LOCATION_ERROR_NONE)
1011 return __convert_error_code(ret); //LCOV_EXCL_LINE
1013 *level = last_acc->level;
1014 *horizontal = last_acc->horizontal_accuracy;
1015 *vertical = last_acc->vertical_accuracy;
1016 location_position_free(last_pos);
1017 location_accuracy_free(last_acc);
1018 return LOCATIONS_ERROR_NONE;
1021 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1023 dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1024 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1025 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1026 LOCATIONS_NULL_ARG_CHECK(state);
1028 int ret = LOCATION_ERROR_NONE;
1029 LocationAccessState auth = LOCATION_ACCESS_NONE;
1030 ret = location_get_accessibility_state(&auth);
1031 if (ret != LOCATION_ERROR_NONE) {
1032 *state = LOCATIONS_ACCESS_STATE_NONE; //LCOV_EXCL_LINE
1033 return __convert_error_code(ret); //LCOV_EXCL_LINE
1038 case LOCATION_ACCESS_DENIED:
1039 *state = LOCATIONS_ACCESS_STATE_DENIED;
1041 case LOCATION_ACCESS_ALLOWED:
1042 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1044 case LOCATION_ACCESS_NONE:
1046 *state = LOCATIONS_ACCESS_STATE_NONE;
1051 return LOCATIONS_ERROR_NONE;
1054 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)
1056 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1057 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1058 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1059 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1060 LOCATIONS_NULL_ARG_CHECK(manager);
1061 location_manager_s *handle = (location_manager_s *) manager;
1062 g_object_set(handle->object, "min-interval", interval, NULL);
1063 g_object_set(handle->object, "min-distance", distance, NULL);
1064 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1067 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1069 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1070 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1071 LOCATIONS_NULL_ARG_CHECK(manager);
1072 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1075 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1077 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1078 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1079 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1080 LOCATIONS_NULL_ARG_CHECK(manager);
1081 location_manager_s *handle = (location_manager_s *) manager;
1082 g_object_set(handle->object, "loc-interval", interval, NULL);
1083 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1086 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1088 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1089 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1090 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1093 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1095 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1096 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1097 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1098 LOCATIONS_NULL_ARG_CHECK(manager);
1099 location_manager_s *handle = (location_manager_s *) manager;
1100 g_object_set(handle->object, "pos-interval", interval, NULL);
1101 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1104 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1106 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1107 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1108 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1111 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1113 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1114 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1115 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1116 LOCATIONS_NULL_ARG_CHECK(manager);
1117 location_manager_s *handle = (location_manager_s *) manager;
1118 g_object_set(handle->object, "vel-interval", interval, NULL);
1119 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1122 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1124 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1125 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1126 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1129 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1132 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1133 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1134 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1137 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1139 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1140 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1141 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1144 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1146 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1147 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1148 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1151 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1153 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1154 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1155 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1158 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1160 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1161 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1162 LOCATIONS_NULL_ARG_CHECK(callback);
1164 LocationMethod _method = __convert_LocationMethod(method);
1165 int ret = LOCATION_ERROR_NONE;
1167 if (_method == LOCATION_METHOD_NONE) {
1168 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1169 } else if (_method == LOCATION_METHOD_PASSIVE) {
1170 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD"); //LCOV_EXCL_LINE
1171 return LOCATIONS_ERROR_INCORRECT_METHOD; //LCOV_EXCL_LINE
1174 g_location_setting[_method].callback = callback;
1175 g_location_setting[_method].user_data = user_data;
1177 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1178 if (ret != LOCATION_ERROR_NONE)
1179 return __convert_error_code(ret); //LCOV_EXCL_LINE
1181 return LOCATIONS_ERROR_NONE;
1184 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1186 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1187 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1188 LocationMethod _method = __convert_LocationMethod(method);
1189 int ret = LOCATION_ERROR_NONE;
1191 if (_method == LOCATION_METHOD_NONE) {
1192 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1193 } else if (_method == LOCATION_METHOD_PASSIVE) {
1194 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD"); //LCOV_EXCL_LINE
1195 return LOCATIONS_ERROR_INCORRECT_METHOD; //LCOV_EXCL_LINE
1198 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1199 if (ret != LOCATION_ERROR_NONE) {
1200 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret); //LCOV_EXCL_LINE
1201 ret = __convert_error_code(ret); //LCOV_EXCL_LINE
1204 g_location_setting[method].callback = NULL;
1205 g_location_setting[method].user_data = NULL;
1207 return LOCATIONS_ERROR_NONE;
1210 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1212 LOCATIONS_LOGD("location_manager_get_distance");
1213 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1214 LOCATIONS_NULL_ARG_CHECK(distance);
1215 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1216 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1217 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1218 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1220 int ret = LOCATION_ERROR_NONE;
1223 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1224 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1226 ret = location_get_distance(start, end, &u_distance);
1227 if (ret != LOCATION_ERROR_NONE)
1228 return __convert_error_code(ret); //LCOV_EXCL_LINE
1230 *distance = (double)u_distance;
1232 return LOCATIONS_ERROR_NONE;
1235 /*/////////////////////////////////////// */
1236 /* GPS Status & Satellites */
1237 /*////////////////////////////////////// */
1239 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1241 LOCATIONS_LOGD("gps_status_get_nmea");
1242 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1243 LOCATIONS_NULL_ARG_CHECK(manager);
1244 LOCATIONS_NULL_ARG_CHECK(nmea);
1245 location_manager_s *handle = (location_manager_s *) manager;
1248 int ret = location_get_nmea(handle->object, &nmea_data);
1249 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1251 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1252 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1253 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1256 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1257 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1261 *nmea = g_strdup(nmea_data);
1264 return LOCATIONS_ERROR_NONE;
1267 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1269 LOCATIONS_LOGD("gps_status_get_satellite");
1270 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1271 LOCATIONS_NULL_ARG_CHECK(manager);
1272 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1273 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1274 LOCATIONS_NULL_ARG_CHECK(timestamp);
1275 location_manager_s *handle = (location_manager_s *) manager;
1276 LocationSatellite *sat = NULL;
1277 int ret = location_get_satellite(handle->object, &sat);
1278 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1280 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1281 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1282 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1285 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1286 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1290 *num_of_active = sat->num_of_sat_used;
1291 *num_of_inview = sat->num_of_sat_inview;
1292 *timestamp = sat->timestamp;
1293 location_satellite_free(sat);
1295 return LOCATIONS_ERROR_NONE;
1298 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1300 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1301 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1302 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1303 LOCATIONS_NULL_ARG_CHECK(manager);
1304 LOCATIONS_NULL_ARG_CHECK(callback);
1306 location_manager_s *handle = (location_manager_s *) manager;
1307 int ret = location_set_option(handle->object, "USE_SV");
1308 if (ret != LOCATION_ERROR_NONE) {
1310 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1311 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1312 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1317 g_object_set(handle->object, "sat-interval", interval, NULL);
1318 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1321 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1323 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1324 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1325 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1328 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1330 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1331 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1332 LOCATIONS_NULL_ARG_CHECK(manager);
1333 LOCATIONS_NULL_ARG_CHECK(callback);
1335 location_manager_s *handle = (location_manager_s *) manager;
1336 LocationSatellite *sat = NULL;
1337 int ret = location_get_satellite(handle->object, &sat);
1339 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1340 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1341 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1342 return LOCATIONS_ERROR_INCORRECT_METHOD;
1343 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1344 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1345 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1348 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1349 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1354 for (i = 0; i < sat->num_of_sat_inview; i++) {
1360 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1361 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1364 location_satellite_free(sat);
1366 return LOCATIONS_ERROR_NONE;
1369 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1371 LOCATIONS_LOGD("gps_status_get_last_satellite");
1372 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1373 LOCATIONS_NULL_ARG_CHECK(manager);
1374 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1375 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1376 LOCATIONS_NULL_ARG_CHECK(timestamp);
1378 location_manager_s *handle = (location_manager_s *) manager;
1379 int ret = LOCATION_ERROR_NONE;
1380 LocationSatellite *last_sat = NULL;
1381 ret = location_get_last_satellite(handle->object, &last_sat);
1382 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;
1397 *num_of_active = last_sat->num_of_sat_used;
1398 *num_of_inview = last_sat->num_of_sat_inview;
1399 *timestamp = last_sat->timestamp;
1400 location_satellite_free(last_sat);
1401 return LOCATIONS_ERROR_NONE;
1404 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1406 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1407 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1408 LOCATIONS_NULL_ARG_CHECK(manager);
1409 LOCATIONS_NULL_ARG_CHECK(callback);
1410 location_manager_s *handle = (location_manager_s *) manager;
1411 int ret = LOCATION_ERROR_NONE;
1412 LocationSatellite *last_sat = NULL;
1414 ret = location_get_last_satellite(handle->object, &last_sat);
1415 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1417 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1418 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1419 return LOCATIONS_ERROR_INCORRECT_METHOD;
1422 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1423 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1428 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1434 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1435 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1438 location_satellite_free(last_sat);
1439 return LOCATIONS_ERROR_NONE;
1446 EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager, location_batch_cb callback, int batch_interval, int batch_period, void *user_data)
1448 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1449 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1452 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1453 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1454 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1455 LOCATIONS_NULL_ARG_CHECK(manager);
1456 LOCATIONS_NULL_ARG_CHECK(callback);
1457 location_manager_s *handle = (location_manager_s *) manager;
1458 g_object_set(handle->object, "batch-period", batch_period, NULL);
1459 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1460 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1464 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1466 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1467 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1468 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager); //LCOV_EXCL_LINE
1471 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1473 LOCATIONS_LOGD("location_manager_start_batch");
1474 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1477 LOCATIONS_NULL_ARG_CHECK(manager);
1478 location_manager_s *handle = (location_manager_s *) manager;
1480 if (LOCATIONS_METHOD_GPS == handle->method) {
1481 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1482 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1484 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1485 return LOCATIONS_ERROR_INCORRECT_METHOD;
1488 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1489 LOCATIONS_LOGD("batch status set : Start");
1491 int ret = location_start_batch(handle->object);
1492 if (ret != LOCATION_ERROR_NONE)
1493 return __convert_error_code(ret);
1495 return LOCATIONS_ERROR_NONE;
1499 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1501 LOCATIONS_LOGD("location_manager_stop_batch");
1502 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1505 LOCATIONS_NULL_ARG_CHECK(manager);
1506 location_manager_s *handle = (location_manager_s *) manager;
1508 if (LOCATIONS_METHOD_GPS == handle->method) {
1509 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1510 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1511 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1515 int ret = location_stop_batch(handle->object);
1516 if (ret != LOCATION_ERROR_NONE)
1517 return __convert_error_code(ret);
1519 return LOCATIONS_ERROR_NONE;
1523 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1525 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1526 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1528 LOCATIONS_NULL_ARG_CHECK(manager);
1529 LOCATIONS_NULL_ARG_CHECK(callback);
1530 location_manager_s *handle = (location_manager_s *) manager;
1531 LocationBatch *batch = NULL;
1533 int ret = location_get_batch(handle->object, &batch);
1534 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1535 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1536 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1537 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1540 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1541 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1545 for (i = 0; i < batch->num_of_location; i++) {
1555 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1556 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1559 location_batch_free(batch);
1561 return LOCATIONS_ERROR_NONE;
1565 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1567 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1568 LOCATIONS_NULL_ARG_CHECK(enabled);
1569 int is_enabled_val = -1;
1570 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1571 if (ret != LOCATION_ERROR_NONE)
1572 return __convert_error_code(ret); //LCOV_EXCL_LINE
1574 if (is_enabled_val == -1)
1575 return TIZEN_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
1577 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1578 return LOCATIONS_ERROR_NONE;
1581 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1583 LOCATIONS_LOGD("enable: %d", enable);
1584 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1585 int ret = LOCATION_ERROR_NONE;
1587 ret = location_enable_mock(enable);
1588 return __convert_error_code(ret);
1591 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1592 const double speed, const double direction, const double accuracy)
1594 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1595 LOCATIONS_NULL_ARG_CHECK(manager);
1597 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1598 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1599 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1601 location_manager_s *handle = (location_manager_s *) manager;
1602 int ret = LOCATION_ERROR_NONE;
1604 LocationPosition *pos = NULL;
1605 LocationVelocity *vel = NULL;
1606 LocationAccuracy *acc = NULL;
1608 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1609 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1610 if (ret == LOCATIONS_ERROR_NONE) {
1612 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1614 return __convert_error_code(ret); //LCOV_EXCL_LINE
1617 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1619 LOCATIONS_LOGE("Failed to create position"); //LCOV_EXCL_LINE
1620 return LOCATIONS_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
1622 vel = location_velocity_new(0, speed, direction, 0);
1625 LOCATIONS_LOGE("Failed to create velocity");
1626 location_position_free(pos);
1627 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1631 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1634 LOCATIONS_LOGE("Failed to create accuracy");
1635 location_position_free(pos);
1636 location_velocity_free(vel);
1637 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1641 ret = location_set_mock_location(handle->object, pos, vel, acc);
1642 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1643 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1644 return LOCATIONS_ERROR_INCORRECT_METHOD;
1647 location_position_free(pos);
1648 location_velocity_free(vel);
1649 location_accuracy_free(acc);
1651 return __convert_error_code(ret);
1654 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1656 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1657 LOCATIONS_NULL_ARG_CHECK(manager);
1659 location_manager_s *handle = (location_manager_s *) manager;
1662 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1663 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1664 if (ret == LOCATIONS_ERROR_NONE) {
1666 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1668 return __convert_error_code(ret); //LCOV_EXCL_LINE
1671 ret = location_clear_mock_location(handle->object);
1672 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1673 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1674 return LOCATIONS_ERROR_INCORRECT_METHOD;
1677 return __convert_error_code(ret);