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;
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 LOCATIONS_LOGD("Callback function has been invoked. ");
116 int converted_err = __convert_error_code(error);
117 location_manager_s *handle = (location_manager_s *) userdata;
118 LocationPosition *pos = (LocationPosition *) position;
119 LocationVelocity *vel = (LocationVelocity *) velocity;
121 LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
122 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
123 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
124 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
128 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
130 LOCATIONS_LOGD("Batch callback function has been invoked.");
131 location_manager_s *handle = (location_manager_s *) userdata;
133 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
134 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
137 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
139 LOCATIONS_LOGD("Invoked[service_enabled]. status = %d", status);
140 location_manager_s *handle = (location_manager_s *) userdata;
141 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
142 ((location_service_state_changed_cb)
143 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
147 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
149 LOCATIONS_LOGD("Invoked[service_disabled]. status = %d", status);
150 location_manager_s *handle = (location_manager_s *) userdata;
151 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
152 ((location_service_state_changed_cb)
153 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
157 static int __compare_position(gconstpointer a, gconstpointer b)
159 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
165 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
169 if (bound1->type == bound2->type) {
170 switch (bound1->type) {
171 case LOCATION_BOUNDARY_CIRCLE:
172 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius)
176 case LOCATION_BOUNDARY_RECT:
177 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom))
181 case LOCATION_BOUNDARY_POLYGON: {
182 GList *boundary1_next = NULL;
183 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
184 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list))
187 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
188 if (boundary2_start == NULL) return -1;
190 boundary2_prev = g_list_previous(boundary2_start);
191 boundary2_next = g_list_next(boundary2_start);
193 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
194 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
196 boundary1_next = g_list_next(bound1->polygon.position_list);
197 if (boundary1_next != NULL && boundary2_prev != NULL &&
198 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
199 boundary1_next = g_list_next(boundary1_next);
200 while (boundary1_next) {
201 boundary2_prev = g_list_previous(boundary2_prev);
202 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
203 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
206 boundary1_next = g_list_next(boundary1_next);
209 } else if (boundary1_next != NULL && boundary2_next != NULL &&
210 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
211 boundary1_next = g_list_next(boundary1_next);
212 while (boundary1_next) {
213 boundary2_next = g_list_next(boundary2_next);
214 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
215 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
218 boundary1_next = g_list_next(boundary1_next);
233 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
235 LOCATIONS_LOGD("ENTER >>>");
236 location_manager_s *handle = (location_manager_s *) userdata;
237 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
238 LocationPosition *pos = (LocationPosition *) position;
239 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
240 pos->latitude, pos->longitude,
241 pos->altitude, pos->timestamp,
243 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
246 location_bounds_s *bounds;
247 GList *bounds_list = g_list_first(handle->bounds_list);
248 while (bounds_list) {
249 bounds = (location_bounds_s *)bounds_list->data;
250 if (__boundary_compare(boundary, bounds->boundary) == 0) {
251 LOCATIONS_LOGD("Find zone in boundary");
253 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
257 bounds_list = g_list_next(bounds_list);
259 LOCATIONS_LOGD("EXIT <<<");
262 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
264 LOCATIONS_LOGD("ENTER >>>");
265 location_manager_s *handle = (location_manager_s *) userdata;
266 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
267 LocationPosition *pos = (LocationPosition *) position;
268 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
269 pos->latitude, pos->longitude,
270 pos->altitude, pos->timestamp,
272 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
275 location_bounds_s *bounds;
276 GList *bounds_list = g_list_first(handle->bounds_list);
277 while (bounds_list) {
278 bounds = (location_bounds_s *)bounds_list->data;
279 if (__boundary_compare(boundary, bounds->boundary) == 0) {
280 LOCATIONS_LOGD("Find zone out boundary");
282 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
286 bounds_list = g_list_next(bounds_list);
288 LOCATIONS_LOGD("EXIT <<<");
291 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
293 location_manager_s *handle = (location_manager_s *) user_data;
295 if (handle != NULL && boundary != NULL) {
297 location_bounds_h bounds;
298 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
299 location_coords_s center;
300 center.latitude = boundary->circle.center->latitude;
301 center.longitude = boundary->circle.center->longitude;
302 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
303 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
304 location_coords_s left_top;
305 location_coords_s right_bottom;
306 left_top.latitude = boundary->rect.left_top->latitude;
307 left_top.longitude = boundary->rect.left_top->longitude;
308 right_bottom.latitude = boundary->rect.right_bottom->latitude;
309 right_bottom.longitude = boundary->rect.right_bottom->longitude;
310 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
311 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
312 GList *list = boundary->polygon.position_list;
313 int size = g_list_length(list);
315 location_coords_s coords[size];
318 LocationPosition *pos = list->data;
319 coords[cnt].latitude = pos->latitude;
320 coords[cnt].longitude = pos->longitude;
321 list = g_list_next(list);
324 ret = location_bounds_create_polygon(coords, size, &bounds);
327 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
330 if (ret != LOCATIONS_ERROR_NONE) {
331 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
333 if (handle->is_continue_foreach_bounds) {
334 handle->is_continue_foreach_bounds =
335 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
338 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
340 location_bounds_destroy(bounds);
343 LOCATIONS_LOGD("__foreach_boundary() has been failed");
347 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
349 LOCATIONS_LOGD("method: [%d]", method);
350 location_method_e _method = __convert_location_method_e(method);
351 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
352 if (_setting_changed == NULL) {
353 LOCATIONS_LOGE("Invaild userdata\n");
357 if (_setting_changed[_method].callback != NULL)
358 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
361 /*/////////////////////////////////////// */
362 /* Location Manager */
363 /*////////////////////////////////////// */
365 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
367 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
368 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
369 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
373 if (method == LOCATIONS_METHOD_GPS) {
374 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
375 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
378 } else if (method == LOCATIONS_METHOD_WPS) {
379 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
380 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
385 LocationMethod _method = __convert_LocationMethod(method);
386 if (_method == LOCATION_METHOD_NONE) {
387 LOCATIONS_LOGE("Not supported method [%d]", method);
388 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
392 gboolean ret = location_is_supported_method(_method);
394 set_last_result(LOCATIONS_ERROR_NONE);
397 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
402 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
404 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
406 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
407 LOCATIONS_LOGE("Not supported method [%d]", method);
408 return LOCATIONS_ERROR_INCORRECT_METHOD;
411 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
412 LOCATIONS_NULL_ARG_CHECK(enable);
413 int is_enabled_val = -1;
414 LocationMethod _method = __convert_LocationMethod(method);
415 int ret = location_is_enabled_method(_method, &is_enabled_val);
416 if (ret != LOCATION_ERROR_NONE) {
417 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
418 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
419 return LOCATIONS_ERROR_INCORRECT_METHOD;
421 return __convert_error_code(ret);
424 if (is_enabled_val == -1)
425 return TIZEN_ERROR_PERMISSION_DENIED;
427 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
428 return LOCATIONS_ERROR_NONE;
431 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
433 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
435 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
436 LOCATIONS_LOGE("Not supported method [%d]", method);
437 return LOCATIONS_ERROR_INCORRECT_METHOD;
440 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
443 if (LOCATIONS_METHOD_HYBRID == method) {
444 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
445 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
446 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
448 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
449 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
450 return __convert_error_code(ret);
452 return LOCATIONS_ERROR_NONE;
455 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
456 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
457 return LOCATIONS_ERROR_NOT_SUPPORTED;
458 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
459 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
460 return LOCATIONS_ERROR_NOT_SUPPORTED;
463 LocationMethod _method = __convert_LocationMethod(method);
465 int ret = location_enable_method(_method, enable);
467 return __convert_error_code(ret);
471 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
473 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
475 if (method == LOCATIONS_METHOD_HYBRID)
476 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
477 else if (method == LOCATIONS_METHOD_GPS)
478 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
479 else if (method == LOCATIONS_METHOD_WPS)
480 LOCATIONS_NOT_SUPPORTED_CHECK(__is_wps_supported());
481 else if (method == LOCATIONS_METHOD_PASSIVE)
482 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
484 LocationMethod _method = __convert_LocationMethod(method);
485 if (_method == LOCATION_METHOD_NONE) {
486 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
487 return LOCATIONS_ERROR_NOT_SUPPORTED;
490 if (!location_is_supported_method(_method)) {
491 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
492 return LOCATIONS_ERROR_NOT_SUPPORTED;
495 /*It is moved here becasue of TCS. */
496 LOCATIONS_NULL_ARG_CHECK(manager);
498 if (location_init() != LOCATION_ERROR_NONE) {
499 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
500 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
503 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
504 if (handle == NULL) {
505 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
506 return LOCATIONS_ERROR_OUT_OF_MEMORY;
509 memset(handle, 0, sizeof(location_manager_s));
511 handle->object = location_new(_method, FALSE);
512 if (handle->object == NULL) {
513 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
515 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
517 handle->method = method;
518 handle->is_continue_foreach_bounds = TRUE;
519 handle->bounds_list = NULL;
521 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
522 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
524 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
525 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
527 *manager = (location_manager_h) handle;
528 return LOCATIONS_ERROR_NONE;
531 EXPORT_API int location_manager_destroy(location_manager_h manager)
533 LOCATIONS_LOGD("location_manager_destroy");
534 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
535 LOCATIONS_NULL_ARG_CHECK(manager);
536 location_manager_s *handle = (location_manager_s *) manager;
538 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
539 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
540 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
543 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
544 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
545 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
548 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
549 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
550 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
553 int ret = location_free(handle->object, FALSE);
554 if (ret != LOCATIONS_ERROR_NONE)
555 return __convert_error_code(ret);
558 return LOCATIONS_ERROR_NONE;
561 EXPORT_API int location_manager_start(location_manager_h manager)
563 LOCATIONS_LOGD("location_manager_start");
564 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
565 LOCATIONS_NULL_ARG_CHECK(manager);
566 location_manager_s *handle = (location_manager_s *) manager;
568 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
569 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
571 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
572 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
573 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
575 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
576 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
578 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
581 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
582 LOCATIONS_LOGI("Satellite update_cb is set");
583 location_set_option(handle->object, "USE_SV");
586 int ret = location_start(handle->object);
587 if (ret != LOCATION_ERROR_NONE)
588 return __convert_error_code(ret);
590 return LOCATIONS_ERROR_NONE;
593 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
595 LOCATIONS_LOGD("location_manager_request_single_location");
596 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
597 LOCATIONS_NULL_ARG_CHECK(manager);
598 LOCATIONS_NULL_ARG_CHECK(callback);
599 if (timeout <= 0 || timeout > 120) {
600 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
601 return LOCATIONS_ERROR_INVALID_PARAMETER;
604 location_manager_s *handle = (location_manager_s *) manager;
605 int ret = LOCATIONS_ERROR_NONE;
607 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
608 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
610 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
611 if (ret != LOCATIONS_ERROR_NONE)
614 ret = location_request_single_location(handle->object, timeout);
615 if (ret != LOCATION_ERROR_NONE) {
616 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
617 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
618 return LOCATIONS_ERROR_INCORRECT_METHOD;
620 return __convert_error_code(ret);
623 return LOCATIONS_ERROR_NONE;
626 EXPORT_API int location_manager_stop(location_manager_h manager)
628 LOCATIONS_LOGD("location_manager_stop");
629 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
630 LOCATIONS_NULL_ARG_CHECK(manager);
632 location_manager_s *handle = (location_manager_s *) manager;
634 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
635 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
636 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
639 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
640 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
641 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
642 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
645 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
646 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
647 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
651 int ret = location_stop(handle->object);
652 if (ret != LOCATION_ERROR_NONE)
653 return __convert_error_code(ret);
655 return LOCATIONS_ERROR_NONE;
658 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
660 LOCATIONS_LOGD("location_manager_add_boundary");
661 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
662 LOCATIONS_NULL_ARG_CHECK(manager);
663 LOCATIONS_NULL_ARG_CHECK(bounds);
665 location_manager_s *handle = (location_manager_s *) manager;
666 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
667 int ret = location_boundary_add(handle->object, bound_handle->boundary);
668 if (ret != LOCATION_ERROR_NONE)
669 return __convert_error_code(ret);
671 bound_handle->is_added = TRUE;
672 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
673 return LOCATIONS_ERROR_NONE;
676 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
678 LOCATIONS_LOGD("location_manager_remove_boundary");
679 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
680 LOCATIONS_NULL_ARG_CHECK(manager);
681 LOCATIONS_NULL_ARG_CHECK(bounds);
683 location_manager_s *handle = (location_manager_s *) manager;
684 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
685 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
686 if (ret != LOCATION_ERROR_NONE)
687 return __convert_error_code(ret);
689 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
690 bound_handle->is_added = FALSE;
691 return LOCATIONS_ERROR_NONE;
694 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
696 LOCATIONS_LOGD("location_manager_foreach_boundary");
697 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
698 LOCATIONS_NULL_ARG_CHECK(manager);
699 LOCATIONS_NULL_ARG_CHECK(callback);
701 location_manager_s *handle = (location_manager_s *) manager;
702 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
703 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
704 handle->is_continue_foreach_bounds = TRUE;
705 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
706 if (ret != LOCATION_ERROR_NONE)
707 return __convert_error_code(ret);
709 return LOCATIONS_ERROR_NONE;
712 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
714 LOCATIONS_LOGD("location_manager_get_method %d", method);
715 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
716 LOCATIONS_NULL_ARG_CHECK(manager);
717 LOCATIONS_NULL_ARG_CHECK(method);
719 location_manager_s *handle = (location_manager_s *) manager;
720 LocationMethod _method = LOCATION_METHOD_NONE;
721 g_object_get(handle->object, "method", &_method, NULL);
723 case LOCATION_METHOD_NONE:
724 *method = LOCATIONS_METHOD_NONE;
726 case LOCATION_METHOD_HYBRID:
727 *method = LOCATIONS_METHOD_HYBRID;
729 case LOCATION_METHOD_GPS:
730 *method = LOCATIONS_METHOD_GPS;
732 case LOCATION_METHOD_WPS:
733 *method = LOCATIONS_METHOD_WPS;
735 case LOCATION_METHOD_PASSIVE:
736 *method = LOCATIONS_METHOD_PASSIVE;
739 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
740 return LOCATIONS_ERROR_INVALID_PARAMETER;
743 return LOCATIONS_ERROR_NONE;
746 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
749 LOCATIONS_LOGD("location_manager_get_position");
750 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
751 LOCATIONS_NULL_ARG_CHECK(manager);
752 LOCATIONS_NULL_ARG_CHECK(altitude);
753 LOCATIONS_NULL_ARG_CHECK(latitude);
754 LOCATIONS_NULL_ARG_CHECK(longitude);
755 LOCATIONS_NULL_ARG_CHECK(timestamp);
757 location_manager_s *handle = (location_manager_s *) manager;
758 LocationPosition *pos = NULL;
759 LocationAccuracy *acc = NULL;
760 int ret = location_get_position(handle->object, &pos, &acc);
761 if (ret != LOCATION_ERROR_NONE)
762 return __convert_error_code(ret);
764 if (pos->status == LOCATION_STATUS_NO_FIX) {
765 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
767 *latitude = pos->latitude;
768 *longitude = pos->longitude;
769 *altitude = pos->altitude;
771 *timestamp = pos->timestamp;
772 location_position_free(pos);
773 location_accuracy_free(acc);
774 return LOCATIONS_ERROR_NONE;
777 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)
779 LOCATIONS_LOGD("location_manager_get_location");
780 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
781 LOCATIONS_NULL_ARG_CHECK(manager);
782 LOCATIONS_NULL_ARG_CHECK(altitude);
783 LOCATIONS_NULL_ARG_CHECK(latitude);
784 LOCATIONS_NULL_ARG_CHECK(longitude);
785 LOCATIONS_NULL_ARG_CHECK(climb);
786 LOCATIONS_NULL_ARG_CHECK(direction);
787 LOCATIONS_NULL_ARG_CHECK(speed);
788 LOCATIONS_NULL_ARG_CHECK(level);
789 LOCATIONS_NULL_ARG_CHECK(horizontal);
790 LOCATIONS_NULL_ARG_CHECK(vertical);
791 LOCATIONS_NULL_ARG_CHECK(timestamp);
793 location_manager_s *handle = (location_manager_s *) manager;
794 LocationPosition *pos = NULL;
795 LocationVelocity *vel = NULL;
796 LocationAccuracy *acc = NULL;
797 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
798 if (ret != LOCATION_ERROR_NONE)
799 return __convert_error_code(ret);
801 if (pos->status == LOCATION_STATUS_NO_FIX) {
802 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
804 *latitude = pos->latitude;
805 *longitude = pos->longitude;
806 *altitude = pos->altitude;
808 *timestamp = pos->timestamp;
810 *direction = vel->direction;
813 *horizontal = acc->horizontal_accuracy;
814 *vertical = acc->vertical_accuracy;
816 location_position_free(pos);
817 location_velocity_free(vel);
818 location_accuracy_free(acc);
819 return LOCATIONS_ERROR_NONE;
822 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
824 LOCATIONS_LOGD("location_manager_get_velocity");
825 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
826 LOCATIONS_NULL_ARG_CHECK(manager);
827 LOCATIONS_NULL_ARG_CHECK(climb);
828 LOCATIONS_NULL_ARG_CHECK(direction);
829 LOCATIONS_NULL_ARG_CHECK(speed);
830 LOCATIONS_NULL_ARG_CHECK(timestamp);
832 location_manager_s *handle = (location_manager_s *) manager;
833 LocationVelocity *vel = NULL;
834 LocationAccuracy *acc = NULL;
836 int ret = location_get_velocity(handle->object, &vel, &acc);
837 if (ret != LOCATION_ERROR_NONE)
838 return __convert_error_code(ret);
841 *direction = vel->direction;
843 *timestamp = vel->timestamp;
844 location_velocity_free(vel);
845 location_accuracy_free(acc);
846 return LOCATIONS_ERROR_NONE;
849 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
852 LOCATIONS_LOGD("location_manager_get_accuracy");
853 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
854 LOCATIONS_NULL_ARG_CHECK(manager);
855 LOCATIONS_NULL_ARG_CHECK(level);
856 LOCATIONS_NULL_ARG_CHECK(horizontal);
857 LOCATIONS_NULL_ARG_CHECK(vertical);
858 location_manager_s *handle = (location_manager_s *) manager;
861 LocationPosition *pos = NULL;
862 LocationAccuracy *acc = NULL;
863 ret = location_get_position(handle->object, &pos, &acc);
864 if (ret != LOCATION_ERROR_NONE)
865 return __convert_error_code(ret);
868 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
871 *horizontal = acc->horizontal_accuracy;
872 *vertical = acc->vertical_accuracy;
873 location_position_free(pos);
874 location_accuracy_free(acc);
875 return LOCATIONS_ERROR_NONE;
878 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
880 LOCATIONS_LOGD("location_manager_get_last_position");
881 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
882 LOCATIONS_NULL_ARG_CHECK(manager);
883 LOCATIONS_NULL_ARG_CHECK(altitude);
884 LOCATIONS_NULL_ARG_CHECK(latitude);
885 LOCATIONS_NULL_ARG_CHECK(longitude);
886 LOCATIONS_NULL_ARG_CHECK(timestamp);
888 location_manager_s *handle = (location_manager_s *) manager;
891 LocationPosition *last_pos = NULL;
892 LocationAccuracy *last_acc = NULL;
893 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
894 if (ret != LOCATION_ERROR_NONE)
895 return __convert_error_code(ret);
897 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
898 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
900 *latitude = last_pos->latitude;
901 *longitude = last_pos->longitude;
902 *altitude = last_pos->altitude;
904 *timestamp = last_pos->timestamp;
905 location_position_free(last_pos);
906 location_accuracy_free(last_acc);
907 return LOCATIONS_ERROR_NONE;
910 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)
912 LOCATIONS_LOGD("location_manager_get_last_location");
913 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
914 LOCATIONS_NULL_ARG_CHECK(manager);
915 LOCATIONS_NULL_ARG_CHECK(altitude);
916 LOCATIONS_NULL_ARG_CHECK(latitude);
917 LOCATIONS_NULL_ARG_CHECK(longitude);
918 LOCATIONS_NULL_ARG_CHECK(climb);
919 LOCATIONS_NULL_ARG_CHECK(direction);
920 LOCATIONS_NULL_ARG_CHECK(speed);
921 LOCATIONS_NULL_ARG_CHECK(level);
922 LOCATIONS_NULL_ARG_CHECK(horizontal);
923 LOCATIONS_NULL_ARG_CHECK(vertical);
924 LOCATIONS_NULL_ARG_CHECK(timestamp);
926 location_manager_s *handle = (location_manager_s *) manager;
929 LocationPosition *last_pos = NULL;
930 LocationVelocity *last_vel = NULL;
931 LocationAccuracy *last_acc = NULL;
932 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
933 if (ret != LOCATION_ERROR_NONE)
934 return __convert_error_code(ret);
936 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
937 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
939 *latitude = last_pos->latitude;
940 *longitude = last_pos->longitude;
941 *altitude = last_pos->altitude;
943 *timestamp = last_pos->timestamp;
944 *climb = last_vel->climb;
945 *direction = last_vel->direction;
946 *speed = last_vel->speed;
947 *level = last_acc->level;
948 *horizontal = last_acc->horizontal_accuracy;
949 *vertical = last_acc->vertical_accuracy;
950 location_position_free(last_pos);
951 location_velocity_free(last_vel);
952 location_accuracy_free(last_acc);
953 return LOCATIONS_ERROR_NONE;
956 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
958 LOCATIONS_LOGD("location_manager_get_last_velocity");
959 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
960 LOCATIONS_NULL_ARG_CHECK(manager);
961 LOCATIONS_NULL_ARG_CHECK(climb);
962 LOCATIONS_NULL_ARG_CHECK(direction);
963 LOCATIONS_NULL_ARG_CHECK(speed);
964 LOCATIONS_NULL_ARG_CHECK(timestamp);
966 location_manager_s *handle = (location_manager_s *) manager;
969 LocationVelocity *last_vel = NULL;
970 LocationAccuracy *last_acc = NULL;
971 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
972 if (ret != LOCATION_ERROR_NONE)
973 return __convert_error_code(ret);
975 *climb = last_vel->climb;
976 *direction = last_vel->direction;
977 *speed = last_vel->speed;
978 *timestamp = last_vel->timestamp;
979 location_velocity_free(last_vel);
980 location_accuracy_free(last_acc);
981 return LOCATIONS_ERROR_NONE;
984 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
986 LOCATIONS_LOGD("location_manager_get_last_accuracy");
987 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
988 LOCATIONS_NULL_ARG_CHECK(manager);
989 LOCATIONS_NULL_ARG_CHECK(level);
990 LOCATIONS_NULL_ARG_CHECK(horizontal);
991 LOCATIONS_NULL_ARG_CHECK(vertical);
992 location_manager_s *handle = (location_manager_s *) manager;
995 LocationPosition *last_pos = NULL;
996 LocationAccuracy *last_acc = NULL;
997 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
998 if (ret != LOCATION_ERROR_NONE)
999 return __convert_error_code(ret);
1001 *level = last_acc->level;
1002 *horizontal = last_acc->horizontal_accuracy;
1003 *vertical = last_acc->vertical_accuracy;
1004 location_position_free(last_pos);
1005 location_accuracy_free(last_acc);
1006 return LOCATIONS_ERROR_NONE;
1009 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1011 dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1012 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1013 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1014 LOCATIONS_NULL_ARG_CHECK(state);
1016 int ret = LOCATION_ERROR_NONE;
1017 LocationAccessState auth = LOCATION_ACCESS_NONE;
1018 ret = location_get_accessibility_state(&auth);
1019 if (ret != LOCATION_ERROR_NONE) {
1020 *state = LOCATIONS_ACCESS_STATE_NONE;
1021 return __convert_error_code(ret);
1025 case LOCATION_ACCESS_DENIED:
1026 *state = LOCATIONS_ACCESS_STATE_DENIED;
1028 case LOCATION_ACCESS_ALLOWED:
1029 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1031 case LOCATION_ACCESS_NONE:
1033 *state = LOCATIONS_ACCESS_STATE_NONE;
1037 return LOCATIONS_ERROR_NONE;
1040 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)
1042 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1043 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1044 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1045 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1046 LOCATIONS_NULL_ARG_CHECK(manager);
1047 location_manager_s *handle = (location_manager_s *) manager;
1048 g_object_set(handle->object, "min-interval", interval, NULL);
1049 g_object_set(handle->object, "min-distance", distance, NULL);
1050 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1053 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1055 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1056 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1057 LOCATIONS_NULL_ARG_CHECK(manager);
1058 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1061 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1063 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1064 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1065 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1066 LOCATIONS_NULL_ARG_CHECK(manager);
1067 location_manager_s *handle = (location_manager_s *) manager;
1068 g_object_set(handle->object, "loc-interval", interval, NULL);
1069 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1072 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1074 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1075 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1076 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1079 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1081 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1082 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1083 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1084 LOCATIONS_NULL_ARG_CHECK(manager);
1085 location_manager_s *handle = (location_manager_s *) manager;
1086 g_object_set(handle->object, "pos-interval", interval, NULL);
1087 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1090 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1092 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1093 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1094 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1097 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1099 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1100 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1101 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1102 LOCATIONS_NULL_ARG_CHECK(manager);
1103 location_manager_s *handle = (location_manager_s *) manager;
1104 g_object_set(handle->object, "vel-interval", interval, NULL);
1105 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1108 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1110 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1111 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1112 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1115 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1118 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1119 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1120 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1123 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1125 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1126 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1127 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1130 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1132 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1133 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1134 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1137 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1139 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1140 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1141 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1144 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1146 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1147 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1148 LOCATIONS_NULL_ARG_CHECK(callback);
1150 LocationMethod _method = __convert_LocationMethod(method);
1151 int ret = LOCATION_ERROR_NONE;
1153 if (_method == LOCATION_METHOD_NONE) {
1154 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1155 } else if (_method == LOCATION_METHOD_PASSIVE) {
1156 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1157 return LOCATIONS_ERROR_INCORRECT_METHOD;
1160 g_location_setting[_method].callback = callback;
1161 g_location_setting[_method].user_data = user_data;
1163 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1164 if (ret != LOCATION_ERROR_NONE)
1165 return __convert_error_code(ret);
1167 return LOCATIONS_ERROR_NONE;
1170 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1172 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1173 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1174 LocationMethod _method = __convert_LocationMethod(method);
1175 int ret = LOCATION_ERROR_NONE;
1177 if (_method == LOCATION_METHOD_NONE) {
1178 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1179 } else if (_method == LOCATION_METHOD_PASSIVE) {
1180 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1181 return LOCATIONS_ERROR_INCORRECT_METHOD;
1184 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1185 if (ret != LOCATION_ERROR_NONE) {
1186 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1187 ret = __convert_error_code(ret);
1190 g_location_setting[method].callback = NULL;
1191 g_location_setting[method].user_data = NULL;
1193 return LOCATIONS_ERROR_NONE;
1196 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1198 LOCATIONS_LOGD("location_manager_get_distance");
1199 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1200 LOCATIONS_NULL_ARG_CHECK(distance);
1201 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1202 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1203 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1204 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1206 int ret = LOCATION_ERROR_NONE;
1209 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1210 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1212 ret = location_get_distance(start, end, &u_distance);
1213 if (ret != LOCATION_ERROR_NONE)
1214 return __convert_error_code(ret);
1216 *distance = (double)u_distance;
1218 return LOCATIONS_ERROR_NONE;
1221 /*/////////////////////////////////////// */
1222 /* GPS Status & Satellites */
1223 /*////////////////////////////////////// */
1225 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1227 LOCATIONS_LOGD("gps_status_get_nmea");
1228 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1229 LOCATIONS_NULL_ARG_CHECK(manager);
1230 LOCATIONS_NULL_ARG_CHECK(nmea);
1231 location_manager_s *handle = (location_manager_s *) manager;
1234 int ret = location_get_nmea(handle->object, &nmea_data);
1235 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1236 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1237 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1238 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1241 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1242 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1245 *nmea = g_strdup(nmea_data);
1248 return LOCATIONS_ERROR_NONE;
1251 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1253 LOCATIONS_LOGD("gps_status_get_satellite");
1254 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1255 LOCATIONS_NULL_ARG_CHECK(manager);
1256 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1257 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1258 LOCATIONS_NULL_ARG_CHECK(timestamp);
1259 location_manager_s *handle = (location_manager_s *) manager;
1260 LocationSatellite *sat = NULL;
1261 int ret = location_get_satellite(handle->object, &sat);
1262 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1263 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1264 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1265 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1268 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1269 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1272 *num_of_active = sat->num_of_sat_used;
1273 *num_of_inview = sat->num_of_sat_inview;
1274 *timestamp = sat->timestamp;
1275 location_satellite_free(sat);
1277 return LOCATIONS_ERROR_NONE;
1280 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1282 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1283 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1284 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1285 LOCATIONS_NULL_ARG_CHECK(manager);
1286 LOCATIONS_NULL_ARG_CHECK(callback);
1288 location_manager_s *handle = (location_manager_s *) manager;
1289 int ret = location_set_option(handle->object, "USE_SV");
1290 if (ret != LOCATION_ERROR_NONE) {
1291 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1292 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1293 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1297 g_object_set(handle->object, "sat-interval", interval, NULL);
1298 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1301 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1303 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1304 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1305 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1308 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1310 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1311 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1312 LOCATIONS_NULL_ARG_CHECK(manager);
1313 LOCATIONS_NULL_ARG_CHECK(callback);
1315 location_manager_s *handle = (location_manager_s *) manager;
1316 LocationSatellite *sat = NULL;
1317 int ret = location_get_satellite(handle->object, &sat);
1318 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1319 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1320 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1321 return LOCATIONS_ERROR_INCORRECT_METHOD;
1322 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1323 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1324 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1327 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1328 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1332 for (i = 0; i < sat->num_of_sat_inview; i++) {
1338 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1339 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1342 location_satellite_free(sat);
1344 return LOCATIONS_ERROR_NONE;
1347 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1349 LOCATIONS_LOGD("gps_status_get_last_satellite");
1350 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1351 LOCATIONS_NULL_ARG_CHECK(manager);
1352 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1353 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1354 LOCATIONS_NULL_ARG_CHECK(timestamp);
1356 location_manager_s *handle = (location_manager_s *) manager;
1357 int ret = LOCATION_ERROR_NONE;
1358 LocationSatellite *last_sat = NULL;
1359 ret = location_get_last_satellite(handle->object, &last_sat);
1360 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1361 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1362 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1363 return LOCATIONS_ERROR_INCORRECT_METHOD;
1364 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1365 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1366 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1369 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1370 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1373 *num_of_active = last_sat->num_of_sat_used;
1374 *num_of_inview = last_sat->num_of_sat_inview;
1375 *timestamp = last_sat->timestamp;
1376 location_satellite_free(last_sat);
1377 return LOCATIONS_ERROR_NONE;
1380 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1382 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1383 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1384 LOCATIONS_NULL_ARG_CHECK(manager);
1385 LOCATIONS_NULL_ARG_CHECK(callback);
1386 location_manager_s *handle = (location_manager_s *) manager;
1387 int ret = LOCATION_ERROR_NONE;
1388 LocationSatellite *last_sat = NULL;
1390 ret = location_get_last_satellite(handle->object, &last_sat);
1391 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1392 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1393 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1394 return LOCATIONS_ERROR_INCORRECT_METHOD;
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;
1402 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1408 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1409 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1412 location_satellite_free(last_sat);
1413 return LOCATIONS_ERROR_NONE;
1420 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)
1422 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1423 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1425 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1426 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1427 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1428 LOCATIONS_NULL_ARG_CHECK(manager);
1429 LOCATIONS_NULL_ARG_CHECK(callback);
1430 location_manager_s *handle = (location_manager_s *) manager;
1431 g_object_set(handle->object, "batch-period", batch_period, NULL);
1432 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1433 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1436 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1438 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1439 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1440 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
1443 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1445 LOCATIONS_LOGD("location_manager_start_batch");
1446 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1447 LOCATIONS_NULL_ARG_CHECK(manager);
1448 location_manager_s *handle = (location_manager_s *) manager;
1450 if (LOCATIONS_METHOD_GPS == handle->method) {
1451 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1452 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1454 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1455 return LOCATIONS_ERROR_INCORRECT_METHOD;
1458 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1459 LOCATIONS_LOGD("batch status set : Start");
1461 int ret = location_start_batch(handle->object);
1462 if (ret != LOCATION_ERROR_NONE)
1463 return __convert_error_code(ret);
1465 return LOCATIONS_ERROR_NONE;
1468 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1470 LOCATIONS_LOGD("location_manager_stop_batch");
1471 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1472 LOCATIONS_NULL_ARG_CHECK(manager);
1473 location_manager_s *handle = (location_manager_s *) manager;
1475 if (LOCATIONS_METHOD_GPS == handle->method) {
1476 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1477 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1478 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1482 int ret = location_stop_batch(handle->object);
1483 if (ret != LOCATION_ERROR_NONE)
1484 return __convert_error_code(ret);
1486 return LOCATIONS_ERROR_NONE;
1489 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1491 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1492 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1493 LOCATIONS_NULL_ARG_CHECK(manager);
1494 LOCATIONS_NULL_ARG_CHECK(callback);
1495 location_manager_s *handle = (location_manager_s *) manager;
1496 LocationBatch *batch = NULL;
1498 int ret = location_get_batch(handle->object, &batch);
1499 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1500 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1501 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1502 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1505 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1506 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1510 for (i = 0; i < batch->num_of_location; i++) {
1520 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1521 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1524 location_batch_free(batch);
1526 return LOCATIONS_ERROR_NONE;
1529 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1531 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1532 LOCATIONS_NULL_ARG_CHECK(enabled);
1533 int is_enabled_val = -1;
1534 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1535 if (ret != LOCATION_ERROR_NONE)
1536 return __convert_error_code(ret);
1538 if (is_enabled_val == -1)
1539 return TIZEN_ERROR_PERMISSION_DENIED;
1541 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1542 return LOCATIONS_ERROR_NONE;
1545 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1547 LOCATIONS_LOGD("enable: %d", enable);
1548 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1549 int ret = LOCATION_ERROR_NONE;
1551 ret = location_enable_mock(enable);
1552 return __convert_error_code(ret);
1555 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1556 const double speed, const double direction, const double accuracy)
1558 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1559 LOCATIONS_NULL_ARG_CHECK(manager);
1561 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1562 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1563 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1565 location_manager_s *handle = (location_manager_s *) manager;
1566 int ret = LOCATION_ERROR_NONE;
1568 LocationPosition *pos = NULL;
1569 LocationVelocity *vel = NULL;
1570 LocationAccuracy *acc = NULL;
1572 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1573 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1574 if (ret == LOCATIONS_ERROR_NONE) {
1576 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1578 return __convert_error_code(ret);
1581 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1583 LOCATIONS_LOGE("Failed to create position");
1584 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1586 vel = location_velocity_new(0, speed, direction, 0);
1588 LOCATIONS_LOGE("Failed to create velocity");
1589 location_position_free(pos);
1590 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1593 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1595 LOCATIONS_LOGE("Failed to create accuracy");
1596 location_position_free(pos);
1597 location_velocity_free(vel);
1598 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1601 ret = location_set_mock_location(handle->object, pos, vel, acc);
1602 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1603 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1604 return LOCATIONS_ERROR_INCORRECT_METHOD;
1607 location_position_free(pos);
1608 location_velocity_free(vel);
1609 location_accuracy_free(acc);
1611 return __convert_error_code(ret);
1614 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1616 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1617 LOCATIONS_NULL_ARG_CHECK(manager);
1619 location_manager_s *handle = (location_manager_s *) manager;
1622 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1623 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1624 if (ret == LOCATIONS_ERROR_NONE) {
1626 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1628 return __convert_error_code(ret);
1631 ret = location_clear_mock_location(handle->object);
1632 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1633 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1634 return LOCATIONS_ERROR_INCORRECT_METHOD;
1637 return __convert_error_code(ret);