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 return LOCATIONS_ERROR_INCORRECT_METHOD;
419 return __convert_error_code(ret);
422 if (is_enabled_val == -1)
423 return TIZEN_ERROR_PERMISSION_DENIED;
425 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
426 return LOCATIONS_ERROR_NONE;
429 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
431 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
433 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
434 LOCATIONS_LOGE("Not supported method [%d]", method);
435 return LOCATIONS_ERROR_INCORRECT_METHOD;
438 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
441 if (LOCATIONS_METHOD_HYBRID == method) {
442 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
443 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
444 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
446 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
447 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
448 return __convert_error_code(ret);
450 return LOCATIONS_ERROR_NONE;
453 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
454 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
455 return LOCATIONS_ERROR_NOT_SUPPORTED;
456 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
457 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
458 return LOCATIONS_ERROR_NOT_SUPPORTED;
461 LocationMethod _method = __convert_LocationMethod(method);
463 int ret = location_enable_method(_method, enable);
465 return __convert_error_code(ret);
469 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
471 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
473 if (method == LOCATIONS_METHOD_HYBRID)
474 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
475 else if (method == LOCATIONS_METHOD_GPS)
476 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
477 else if (method == LOCATIONS_METHOD_WPS)
478 LOCATIONS_NOT_SUPPORTED_CHECK(__is_wps_supported());
479 else if (method == LOCATIONS_METHOD_PASSIVE)
480 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
482 LocationMethod _method = __convert_LocationMethod(method);
483 if (_method == LOCATION_METHOD_NONE) {
484 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
485 return LOCATIONS_ERROR_NOT_SUPPORTED;
488 if (!location_is_supported_method(_method)) {
489 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
490 return LOCATIONS_ERROR_NOT_SUPPORTED;
493 /*It is moved here becasue of TCS. */
494 LOCATIONS_NULL_ARG_CHECK(manager);
496 if (location_init() != LOCATION_ERROR_NONE) {
497 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
498 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
501 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
502 if (handle == NULL) {
503 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
504 return LOCATIONS_ERROR_OUT_OF_MEMORY;
507 memset(handle, 0, sizeof(location_manager_s));
509 handle->object = location_new(_method, FALSE);
510 if (handle->object == NULL) {
511 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
513 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
515 handle->method = method;
516 handle->is_continue_foreach_bounds = TRUE;
517 handle->bounds_list = NULL;
519 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
520 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
522 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
523 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
525 *manager = (location_manager_h) handle;
526 return LOCATIONS_ERROR_NONE;
529 EXPORT_API int location_manager_destroy(location_manager_h manager)
531 LOCATIONS_LOGD("location_manager_destroy");
532 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
533 LOCATIONS_NULL_ARG_CHECK(manager);
534 location_manager_s *handle = (location_manager_s *) manager;
536 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
537 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
538 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
541 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
542 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
543 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
546 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
547 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
548 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
551 int ret = location_free(handle->object, FALSE);
552 if (ret != LOCATIONS_ERROR_NONE)
553 return __convert_error_code(ret);
556 return LOCATIONS_ERROR_NONE;
559 EXPORT_API int location_manager_start(location_manager_h manager)
561 LOCATIONS_LOGD("location_manager_start");
562 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
563 LOCATIONS_NULL_ARG_CHECK(manager);
564 location_manager_s *handle = (location_manager_s *) manager;
566 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
567 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
569 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
570 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
571 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
573 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
574 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
576 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
579 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
580 LOCATIONS_LOGI("Satellite update_cb is set");
581 location_set_option(handle->object, "USE_SV");
584 int ret = location_start(handle->object);
585 if (ret != LOCATION_ERROR_NONE)
586 return __convert_error_code(ret);
588 return LOCATIONS_ERROR_NONE;
591 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
593 LOCATIONS_LOGD("location_manager_request_single_location");
594 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
595 LOCATIONS_NULL_ARG_CHECK(manager);
596 LOCATIONS_NULL_ARG_CHECK(callback);
597 if (timeout <= 0 || timeout > 120) {
598 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
599 return LOCATIONS_ERROR_INVALID_PARAMETER;
602 location_manager_s *handle = (location_manager_s *) manager;
603 int ret = LOCATIONS_ERROR_NONE;
605 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
606 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
608 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
609 if (ret != LOCATIONS_ERROR_NONE)
612 ret = location_request_single_location(handle->object, timeout);
613 if (ret != LOCATION_ERROR_NONE) {
614 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
615 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
616 return LOCATIONS_ERROR_INCORRECT_METHOD;
618 return __convert_error_code(ret);
621 return LOCATIONS_ERROR_NONE;
624 EXPORT_API int location_manager_stop(location_manager_h manager)
626 LOCATIONS_LOGD("location_manager_stop");
627 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
628 LOCATIONS_NULL_ARG_CHECK(manager);
630 location_manager_s *handle = (location_manager_s *) manager;
632 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
633 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
634 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
637 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
638 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
639 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
640 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
643 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
644 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
645 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
649 int ret = location_stop(handle->object);
650 if (ret != LOCATION_ERROR_NONE)
651 return __convert_error_code(ret);
653 return LOCATIONS_ERROR_NONE;
656 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
658 LOCATIONS_LOGD("location_manager_add_boundary");
659 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
660 LOCATIONS_NULL_ARG_CHECK(manager);
661 LOCATIONS_NULL_ARG_CHECK(bounds);
663 location_manager_s *handle = (location_manager_s *) manager;
664 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
665 int ret = location_boundary_add(handle->object, bound_handle->boundary);
666 if (ret != LOCATION_ERROR_NONE)
667 return __convert_error_code(ret);
669 bound_handle->is_added = TRUE;
670 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
671 return LOCATIONS_ERROR_NONE;
674 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
676 LOCATIONS_LOGD("location_manager_remove_boundary");
677 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
678 LOCATIONS_NULL_ARG_CHECK(manager);
679 LOCATIONS_NULL_ARG_CHECK(bounds);
681 location_manager_s *handle = (location_manager_s *) manager;
682 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
683 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
684 if (ret != LOCATION_ERROR_NONE)
685 return __convert_error_code(ret);
687 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
688 bound_handle->is_added = FALSE;
689 return LOCATIONS_ERROR_NONE;
692 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
694 LOCATIONS_LOGD("location_manager_foreach_boundary");
695 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
696 LOCATIONS_NULL_ARG_CHECK(manager);
697 LOCATIONS_NULL_ARG_CHECK(callback);
699 location_manager_s *handle = (location_manager_s *) manager;
700 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
701 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
702 handle->is_continue_foreach_bounds = TRUE;
703 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
704 if (ret != LOCATION_ERROR_NONE)
705 return __convert_error_code(ret);
707 return LOCATIONS_ERROR_NONE;
710 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
712 LOCATIONS_LOGD("location_manager_get_method %d", method);
713 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
714 LOCATIONS_NULL_ARG_CHECK(manager);
715 LOCATIONS_NULL_ARG_CHECK(method);
717 location_manager_s *handle = (location_manager_s *) manager;
718 LocationMethod _method = LOCATION_METHOD_NONE;
719 g_object_get(handle->object, "method", &_method, NULL);
721 case LOCATION_METHOD_NONE:
722 *method = LOCATIONS_METHOD_NONE;
724 case LOCATION_METHOD_HYBRID:
725 *method = LOCATIONS_METHOD_HYBRID;
727 case LOCATION_METHOD_GPS:
728 *method = LOCATIONS_METHOD_GPS;
730 case LOCATION_METHOD_WPS:
731 *method = LOCATIONS_METHOD_WPS;
733 case LOCATION_METHOD_PASSIVE:
734 *method = LOCATIONS_METHOD_PASSIVE;
737 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
738 return LOCATIONS_ERROR_INVALID_PARAMETER;
741 return LOCATIONS_ERROR_NONE;
744 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
747 LOCATIONS_LOGD("location_manager_get_position");
748 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
749 LOCATIONS_NULL_ARG_CHECK(manager);
750 LOCATIONS_NULL_ARG_CHECK(altitude);
751 LOCATIONS_NULL_ARG_CHECK(latitude);
752 LOCATIONS_NULL_ARG_CHECK(longitude);
753 LOCATIONS_NULL_ARG_CHECK(timestamp);
755 location_manager_s *handle = (location_manager_s *) manager;
756 LocationPosition *pos = NULL;
757 LocationAccuracy *acc = NULL;
758 int ret = location_get_position(handle->object, &pos, &acc);
759 if (ret != LOCATION_ERROR_NONE)
760 return __convert_error_code(ret);
762 if (pos->status == LOCATION_STATUS_NO_FIX) {
763 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
765 *latitude = pos->latitude;
766 *longitude = pos->longitude;
767 *altitude = pos->altitude;
769 *timestamp = pos->timestamp;
770 location_position_free(pos);
771 location_accuracy_free(acc);
772 return LOCATIONS_ERROR_NONE;
775 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)
777 LOCATIONS_LOGD("location_manager_get_location");
778 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
779 LOCATIONS_NULL_ARG_CHECK(manager);
780 LOCATIONS_NULL_ARG_CHECK(altitude);
781 LOCATIONS_NULL_ARG_CHECK(latitude);
782 LOCATIONS_NULL_ARG_CHECK(longitude);
783 LOCATIONS_NULL_ARG_CHECK(climb);
784 LOCATIONS_NULL_ARG_CHECK(direction);
785 LOCATIONS_NULL_ARG_CHECK(speed);
786 LOCATIONS_NULL_ARG_CHECK(level);
787 LOCATIONS_NULL_ARG_CHECK(horizontal);
788 LOCATIONS_NULL_ARG_CHECK(vertical);
789 LOCATIONS_NULL_ARG_CHECK(timestamp);
791 location_manager_s *handle = (location_manager_s *) manager;
792 LocationPosition *pos = NULL;
793 LocationVelocity *vel = NULL;
794 LocationAccuracy *acc = NULL;
795 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
796 if (ret != LOCATION_ERROR_NONE)
797 return __convert_error_code(ret);
799 if (pos->status == LOCATION_STATUS_NO_FIX) {
800 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
802 *latitude = pos->latitude;
803 *longitude = pos->longitude;
804 *altitude = pos->altitude;
806 *timestamp = pos->timestamp;
808 *direction = vel->direction;
811 *horizontal = acc->horizontal_accuracy;
812 *vertical = acc->vertical_accuracy;
814 location_position_free(pos);
815 location_velocity_free(vel);
816 location_accuracy_free(acc);
817 return LOCATIONS_ERROR_NONE;
820 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
822 LOCATIONS_LOGD("location_manager_get_velocity");
823 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
824 LOCATIONS_NULL_ARG_CHECK(manager);
825 LOCATIONS_NULL_ARG_CHECK(climb);
826 LOCATIONS_NULL_ARG_CHECK(direction);
827 LOCATIONS_NULL_ARG_CHECK(speed);
828 LOCATIONS_NULL_ARG_CHECK(timestamp);
830 location_manager_s *handle = (location_manager_s *) manager;
831 LocationVelocity *vel = NULL;
832 LocationAccuracy *acc = NULL;
834 int ret = location_get_velocity(handle->object, &vel, &acc);
835 if (ret != LOCATION_ERROR_NONE)
836 return __convert_error_code(ret);
839 *direction = vel->direction;
841 *timestamp = vel->timestamp;
842 location_velocity_free(vel);
843 location_accuracy_free(acc);
844 return LOCATIONS_ERROR_NONE;
847 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
850 LOCATIONS_LOGD("location_manager_get_accuracy");
851 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
852 LOCATIONS_NULL_ARG_CHECK(manager);
853 LOCATIONS_NULL_ARG_CHECK(level);
854 LOCATIONS_NULL_ARG_CHECK(horizontal);
855 LOCATIONS_NULL_ARG_CHECK(vertical);
856 location_manager_s *handle = (location_manager_s *) manager;
859 LocationPosition *pos = NULL;
860 LocationAccuracy *acc = NULL;
861 ret = location_get_position(handle->object, &pos, &acc);
862 if (ret != LOCATION_ERROR_NONE)
863 return __convert_error_code(ret);
866 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
869 *horizontal = acc->horizontal_accuracy;
870 *vertical = acc->vertical_accuracy;
871 location_position_free(pos);
872 location_accuracy_free(acc);
873 return LOCATIONS_ERROR_NONE;
876 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
878 LOCATIONS_LOGD("location_manager_get_last_position");
879 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
880 LOCATIONS_NULL_ARG_CHECK(manager);
881 LOCATIONS_NULL_ARG_CHECK(altitude);
882 LOCATIONS_NULL_ARG_CHECK(latitude);
883 LOCATIONS_NULL_ARG_CHECK(longitude);
884 LOCATIONS_NULL_ARG_CHECK(timestamp);
886 location_manager_s *handle = (location_manager_s *) manager;
889 LocationPosition *last_pos = NULL;
890 LocationAccuracy *last_acc = NULL;
891 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
892 if (ret != LOCATION_ERROR_NONE)
893 return __convert_error_code(ret);
895 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
896 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
898 *latitude = last_pos->latitude;
899 *longitude = last_pos->longitude;
900 *altitude = last_pos->altitude;
902 *timestamp = last_pos->timestamp;
903 location_position_free(last_pos);
904 location_accuracy_free(last_acc);
905 return LOCATIONS_ERROR_NONE;
908 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)
910 LOCATIONS_LOGD("location_manager_get_last_location");
911 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
912 LOCATIONS_NULL_ARG_CHECK(manager);
913 LOCATIONS_NULL_ARG_CHECK(altitude);
914 LOCATIONS_NULL_ARG_CHECK(latitude);
915 LOCATIONS_NULL_ARG_CHECK(longitude);
916 LOCATIONS_NULL_ARG_CHECK(climb);
917 LOCATIONS_NULL_ARG_CHECK(direction);
918 LOCATIONS_NULL_ARG_CHECK(speed);
919 LOCATIONS_NULL_ARG_CHECK(level);
920 LOCATIONS_NULL_ARG_CHECK(horizontal);
921 LOCATIONS_NULL_ARG_CHECK(vertical);
922 LOCATIONS_NULL_ARG_CHECK(timestamp);
924 location_manager_s *handle = (location_manager_s *) manager;
927 LocationPosition *last_pos = NULL;
928 LocationVelocity *last_vel = NULL;
929 LocationAccuracy *last_acc = NULL;
930 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
931 if (ret != LOCATION_ERROR_NONE)
932 return __convert_error_code(ret);
934 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
935 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
937 *latitude = last_pos->latitude;
938 *longitude = last_pos->longitude;
939 *altitude = last_pos->altitude;
941 *timestamp = last_pos->timestamp;
942 *climb = last_vel->climb;
943 *direction = last_vel->direction;
944 *speed = last_vel->speed;
945 *level = last_acc->level;
946 *horizontal = last_acc->horizontal_accuracy;
947 *vertical = last_acc->vertical_accuracy;
948 location_position_free(last_pos);
949 location_velocity_free(last_vel);
950 location_accuracy_free(last_acc);
951 return LOCATIONS_ERROR_NONE;
954 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
956 LOCATIONS_LOGD("location_manager_get_last_velocity");
957 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
958 LOCATIONS_NULL_ARG_CHECK(manager);
959 LOCATIONS_NULL_ARG_CHECK(climb);
960 LOCATIONS_NULL_ARG_CHECK(direction);
961 LOCATIONS_NULL_ARG_CHECK(speed);
962 LOCATIONS_NULL_ARG_CHECK(timestamp);
964 location_manager_s *handle = (location_manager_s *) manager;
967 LocationVelocity *last_vel = NULL;
968 LocationAccuracy *last_acc = NULL;
969 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
970 if (ret != LOCATION_ERROR_NONE)
971 return __convert_error_code(ret);
973 *climb = last_vel->climb;
974 *direction = last_vel->direction;
975 *speed = last_vel->speed;
976 *timestamp = last_vel->timestamp;
977 location_velocity_free(last_vel);
978 location_accuracy_free(last_acc);
979 return LOCATIONS_ERROR_NONE;
982 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
984 LOCATIONS_LOGD("location_manager_get_last_accuracy");
985 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
986 LOCATIONS_NULL_ARG_CHECK(manager);
987 LOCATIONS_NULL_ARG_CHECK(level);
988 LOCATIONS_NULL_ARG_CHECK(horizontal);
989 LOCATIONS_NULL_ARG_CHECK(vertical);
990 location_manager_s *handle = (location_manager_s *) manager;
993 LocationPosition *last_pos = NULL;
994 LocationAccuracy *last_acc = NULL;
995 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
996 if (ret != LOCATION_ERROR_NONE)
997 return __convert_error_code(ret);
999 *level = last_acc->level;
1000 *horizontal = last_acc->horizontal_accuracy;
1001 *vertical = last_acc->vertical_accuracy;
1002 location_position_free(last_pos);
1003 location_accuracy_free(last_acc);
1004 return LOCATIONS_ERROR_NONE;
1007 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1009 dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1010 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1011 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1012 LOCATIONS_NULL_ARG_CHECK(state);
1014 int ret = LOCATION_ERROR_NONE;
1015 LocationAccessState auth = LOCATION_ACCESS_NONE;
1016 ret = location_get_accessibility_state(&auth);
1017 if (ret != LOCATION_ERROR_NONE) {
1018 *state = LOCATIONS_ACCESS_STATE_NONE;
1019 return __convert_error_code(ret);
1023 case LOCATION_ACCESS_DENIED:
1024 *state = LOCATIONS_ACCESS_STATE_DENIED;
1026 case LOCATION_ACCESS_ALLOWED:
1027 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1029 case LOCATION_ACCESS_NONE:
1031 *state = LOCATIONS_ACCESS_STATE_NONE;
1035 return LOCATIONS_ERROR_NONE;
1038 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)
1040 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1041 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1042 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1043 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1044 LOCATIONS_NULL_ARG_CHECK(manager);
1045 location_manager_s *handle = (location_manager_s *) manager;
1046 g_object_set(handle->object, "min-interval", interval, NULL);
1047 g_object_set(handle->object, "min-distance", distance, NULL);
1048 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1051 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1053 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1054 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1055 LOCATIONS_NULL_ARG_CHECK(manager);
1056 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1059 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1061 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1062 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1063 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1064 LOCATIONS_NULL_ARG_CHECK(manager);
1065 location_manager_s *handle = (location_manager_s *) manager;
1066 g_object_set(handle->object, "loc-interval", interval, NULL);
1067 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1070 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1072 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1073 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1074 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1077 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1079 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1080 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1081 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1082 LOCATIONS_NULL_ARG_CHECK(manager);
1083 location_manager_s *handle = (location_manager_s *) manager;
1084 g_object_set(handle->object, "pos-interval", interval, NULL);
1085 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1088 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1090 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1091 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1092 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1095 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1097 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1098 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1099 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1100 LOCATIONS_NULL_ARG_CHECK(manager);
1101 location_manager_s *handle = (location_manager_s *) manager;
1102 g_object_set(handle->object, "vel-interval", interval, NULL);
1103 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1106 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1108 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1109 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1110 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1113 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1116 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1117 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1118 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1121 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1123 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1124 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1125 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1128 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1130 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1131 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1132 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1135 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1137 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1138 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1139 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1142 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1144 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1145 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1146 LOCATIONS_NULL_ARG_CHECK(callback);
1148 LocationMethod _method = __convert_LocationMethod(method);
1149 int ret = LOCATION_ERROR_NONE;
1151 if (_method == LOCATION_METHOD_NONE) {
1152 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1153 } else if (_method == LOCATION_METHOD_PASSIVE) {
1154 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1155 return LOCATIONS_ERROR_INCORRECT_METHOD;
1158 g_location_setting[_method].callback = callback;
1159 g_location_setting[_method].user_data = user_data;
1161 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1162 if (ret != LOCATION_ERROR_NONE)
1163 return __convert_error_code(ret);
1165 return LOCATIONS_ERROR_NONE;
1168 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1170 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1171 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1172 LocationMethod _method = __convert_LocationMethod(method);
1173 int ret = LOCATION_ERROR_NONE;
1175 if (_method == LOCATION_METHOD_NONE) {
1176 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1177 } else if (_method == LOCATION_METHOD_PASSIVE) {
1178 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1179 return LOCATIONS_ERROR_INCORRECT_METHOD;
1182 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1183 if (ret != LOCATION_ERROR_NONE) {
1184 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1185 ret = __convert_error_code(ret);
1188 g_location_setting[method].callback = NULL;
1189 g_location_setting[method].user_data = NULL;
1191 return LOCATIONS_ERROR_NONE;
1194 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1196 LOCATIONS_LOGD("location_manager_get_distance");
1197 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1198 LOCATIONS_NULL_ARG_CHECK(distance);
1199 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1200 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1201 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1202 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1204 int ret = LOCATION_ERROR_NONE;
1207 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1208 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1210 ret = location_get_distance(start, end, &u_distance);
1211 if (ret != LOCATION_ERROR_NONE)
1212 return __convert_error_code(ret);
1214 *distance = (double)u_distance;
1216 return LOCATIONS_ERROR_NONE;
1219 /*/////////////////////////////////////// */
1220 /* GPS Status & Satellites */
1221 /*////////////////////////////////////// */
1223 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1225 LOCATIONS_LOGD("gps_status_get_nmea");
1226 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1227 LOCATIONS_NULL_ARG_CHECK(manager);
1228 LOCATIONS_NULL_ARG_CHECK(nmea);
1229 location_manager_s *handle = (location_manager_s *) manager;
1232 int ret = location_get_nmea(handle->object, &nmea_data);
1233 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1234 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1235 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1236 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1239 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1240 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1243 *nmea = g_strdup(nmea_data);
1246 return LOCATIONS_ERROR_NONE;
1249 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1251 LOCATIONS_LOGD("gps_status_get_satellite");
1252 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1253 LOCATIONS_NULL_ARG_CHECK(manager);
1254 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1255 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1256 LOCATIONS_NULL_ARG_CHECK(timestamp);
1257 location_manager_s *handle = (location_manager_s *) manager;
1258 LocationSatellite *sat = NULL;
1259 int ret = location_get_satellite(handle->object, &sat);
1260 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1261 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1262 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1263 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1266 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1267 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1270 *num_of_active = sat->num_of_sat_used;
1271 *num_of_inview = sat->num_of_sat_inview;
1272 *timestamp = sat->timestamp;
1273 location_satellite_free(sat);
1275 return LOCATIONS_ERROR_NONE;
1278 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1280 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1281 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1282 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1283 LOCATIONS_NULL_ARG_CHECK(manager);
1284 LOCATIONS_NULL_ARG_CHECK(callback);
1286 location_manager_s *handle = (location_manager_s *) manager;
1287 int ret = location_set_option(handle->object, "USE_SV");
1288 if (ret != LOCATION_ERROR_NONE) {
1289 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1290 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1291 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1295 g_object_set(handle->object, "sat-interval", interval, NULL);
1296 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1299 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1301 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1302 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1303 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1306 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1308 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1309 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1310 LOCATIONS_NULL_ARG_CHECK(manager);
1311 LOCATIONS_NULL_ARG_CHECK(callback);
1313 location_manager_s *handle = (location_manager_s *) manager;
1314 LocationSatellite *sat = NULL;
1315 int ret = location_get_satellite(handle->object, &sat);
1316 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1317 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1318 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1319 return LOCATIONS_ERROR_INCORRECT_METHOD;
1320 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1321 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1322 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1325 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1326 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1330 for (i = 0; i < sat->num_of_sat_inview; i++) {
1336 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1337 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1340 location_satellite_free(sat);
1342 return LOCATIONS_ERROR_NONE;
1345 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1347 LOCATIONS_LOGD("gps_status_get_last_satellite");
1348 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1349 LOCATIONS_NULL_ARG_CHECK(manager);
1350 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1351 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1352 LOCATIONS_NULL_ARG_CHECK(timestamp);
1354 location_manager_s *handle = (location_manager_s *) manager;
1355 int ret = LOCATION_ERROR_NONE;
1356 LocationSatellite *last_sat = NULL;
1357 ret = location_get_last_satellite(handle->object, &last_sat);
1358 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1359 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1360 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1361 return LOCATIONS_ERROR_INCORRECT_METHOD;
1362 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1363 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1364 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1367 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1368 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1371 *num_of_active = last_sat->num_of_sat_used;
1372 *num_of_inview = last_sat->num_of_sat_inview;
1373 *timestamp = last_sat->timestamp;
1374 location_satellite_free(last_sat);
1375 return LOCATIONS_ERROR_NONE;
1378 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1380 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1381 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1382 LOCATIONS_NULL_ARG_CHECK(manager);
1383 LOCATIONS_NULL_ARG_CHECK(callback);
1384 location_manager_s *handle = (location_manager_s *) manager;
1385 int ret = LOCATION_ERROR_NONE;
1386 LocationSatellite *last_sat = NULL;
1388 ret = location_get_last_satellite(handle->object, &last_sat);
1389 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1390 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1391 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1392 return LOCATIONS_ERROR_INCORRECT_METHOD;
1395 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1396 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1400 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1406 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1407 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1410 location_satellite_free(last_sat);
1411 return LOCATIONS_ERROR_NONE;
1418 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)
1420 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1421 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1423 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1424 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1425 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1426 LOCATIONS_NULL_ARG_CHECK(manager);
1427 LOCATIONS_NULL_ARG_CHECK(callback);
1428 location_manager_s *handle = (location_manager_s *) manager;
1429 g_object_set(handle->object, "batch-period", batch_period, NULL);
1430 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1431 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1434 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1436 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1437 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1438 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
1441 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1443 LOCATIONS_LOGD("location_manager_start_batch");
1444 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1445 LOCATIONS_NULL_ARG_CHECK(manager);
1446 location_manager_s *handle = (location_manager_s *) manager;
1448 if (LOCATIONS_METHOD_GPS == handle->method) {
1449 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1450 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1452 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1453 return LOCATIONS_ERROR_INCORRECT_METHOD;
1456 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1457 LOCATIONS_LOGD("batch status set : Start");
1459 int ret = location_start_batch(handle->object);
1460 if (ret != LOCATION_ERROR_NONE)
1461 return __convert_error_code(ret);
1463 return LOCATIONS_ERROR_NONE;
1466 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1468 LOCATIONS_LOGD("location_manager_stop_batch");
1469 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1470 LOCATIONS_NULL_ARG_CHECK(manager);
1471 location_manager_s *handle = (location_manager_s *) manager;
1473 if (LOCATIONS_METHOD_GPS == handle->method) {
1474 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1475 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1476 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1480 int ret = location_stop_batch(handle->object);
1481 if (ret != LOCATION_ERROR_NONE)
1482 return __convert_error_code(ret);
1484 return LOCATIONS_ERROR_NONE;
1487 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1489 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1490 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1491 LOCATIONS_NULL_ARG_CHECK(manager);
1492 LOCATIONS_NULL_ARG_CHECK(callback);
1493 location_manager_s *handle = (location_manager_s *) manager;
1494 LocationBatch *batch = NULL;
1496 int ret = location_get_batch(handle->object, &batch);
1497 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1498 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1499 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1500 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1503 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1504 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1508 for (i = 0; i < batch->num_of_location; i++) {
1518 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1519 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1522 location_batch_free(batch);
1524 return LOCATIONS_ERROR_NONE;
1527 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1529 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1530 LOCATIONS_NULL_ARG_CHECK(enabled);
1531 int is_enabled_val = -1;
1532 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1533 if (ret != LOCATION_ERROR_NONE)
1534 return __convert_error_code(ret);
1536 if (is_enabled_val == -1)
1537 return TIZEN_ERROR_PERMISSION_DENIED;
1539 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1540 return LOCATIONS_ERROR_NONE;
1543 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1545 LOCATIONS_LOGD("enable: %d", enable);
1546 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1547 int ret = LOCATION_ERROR_NONE;
1549 ret = location_enable_mock(enable);
1550 return __convert_error_code(ret);
1553 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1554 const double speed, const double direction, const double accuracy)
1556 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1557 LOCATIONS_NULL_ARG_CHECK(manager);
1559 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1560 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1561 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1563 location_manager_s *handle = (location_manager_s *) manager;
1564 int ret = LOCATION_ERROR_NONE;
1566 LocationPosition *pos = NULL;
1567 LocationVelocity *vel = NULL;
1568 LocationAccuracy *acc = NULL;
1570 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1571 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1572 if (ret == LOCATIONS_ERROR_NONE) {
1574 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1576 return __convert_error_code(ret);
1579 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1581 LOCATIONS_LOGE("Failed to create position");
1582 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1584 vel = location_velocity_new(0, speed, direction, 0);
1586 LOCATIONS_LOGE("Failed to create velocity");
1587 location_position_free(pos);
1588 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1591 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1593 LOCATIONS_LOGE("Failed to create accuracy");
1594 location_position_free(pos);
1595 location_velocity_free(vel);
1596 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1599 ret = location_set_mock_location(handle->object, pos, vel, acc);
1601 location_position_free(pos);
1602 location_velocity_free(vel);
1603 location_accuracy_free(acc);
1605 return __convert_error_code(ret);
1608 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1610 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1611 LOCATIONS_NULL_ARG_CHECK(manager);
1613 location_manager_s *handle = (location_manager_s *) manager;
1616 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1617 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1618 if (ret == LOCATIONS_ERROR_NONE) {
1620 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1622 return __convert_error_code(ret);
1625 ret = location_clear_mock_location(handle->object);
1626 return __convert_error_code(ret);