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 int converted_err = __convert_error_code(error);
116 location_manager_s *handle = (location_manager_s *) userdata;
117 LocationPosition *pos = (LocationPosition *) position;
118 LocationVelocity *vel = (LocationVelocity *) velocity;
120 LOCATIONS_LOGD("Callback function[TYPE_LOCATION: single] timestamp : %d, error : %d", pos->timestamp, error);
121 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
122 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
123 pos->timestamp, vel->speed, vel->direction, vel->climb, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
126 if (error != LOCATION_ERROR_NONE) {
127 location_position_free(pos);
128 location_velocity_free(vel);
132 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
134 LOCATIONS_LOGD("Batch callback function has been invoked.");
135 location_manager_s *handle = (location_manager_s *) userdata;
137 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
138 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
141 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
143 LOCATIONS_LOGD("Invoked[service_enabled]. status = %d", status);
144 location_manager_s *handle = (location_manager_s *) userdata;
145 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
146 ((location_service_state_changed_cb)
147 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
151 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
153 LOCATIONS_LOGD("Invoked[service_disabled]. status = %d", status);
154 location_manager_s *handle = (location_manager_s *) userdata;
155 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
156 ((location_service_state_changed_cb)
157 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
161 static int __compare_position(gconstpointer a, gconstpointer b)
163 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
169 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
173 if (bound1->type == bound2->type) {
174 switch (bound1->type) {
175 case LOCATION_BOUNDARY_CIRCLE:
176 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius)
180 case LOCATION_BOUNDARY_RECT:
181 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom))
185 case LOCATION_BOUNDARY_POLYGON: {
186 GList *boundary1_next = NULL;
187 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
188 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list))
191 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
192 if (boundary2_start == NULL) return -1;
194 boundary2_prev = g_list_previous(boundary2_start);
195 boundary2_next = g_list_next(boundary2_start);
197 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
198 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
200 boundary1_next = g_list_next(bound1->polygon.position_list);
201 if (boundary1_next != NULL && boundary2_prev != NULL &&
202 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
203 boundary1_next = g_list_next(boundary1_next);
204 while (boundary1_next) {
205 boundary2_prev = g_list_previous(boundary2_prev);
206 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
207 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
210 boundary1_next = g_list_next(boundary1_next);
213 } else if (boundary1_next != NULL && boundary2_next != NULL &&
214 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
215 boundary1_next = g_list_next(boundary1_next);
216 while (boundary1_next) {
217 boundary2_next = g_list_next(boundary2_next);
218 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
219 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
222 boundary1_next = g_list_next(boundary1_next);
237 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
239 LOCATIONS_LOGD("ENTER >>>");
240 location_manager_s *handle = (location_manager_s *) userdata;
241 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
242 LocationPosition *pos = (LocationPosition *) position;
243 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
244 pos->latitude, pos->longitude,
245 pos->altitude, pos->timestamp,
247 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
250 location_bounds_s *bounds;
251 GList *bounds_list = g_list_first(handle->bounds_list);
252 while (bounds_list) {
253 bounds = (location_bounds_s *)bounds_list->data;
254 if (__boundary_compare(boundary, bounds->boundary) == 0) {
255 LOCATIONS_LOGD("Find zone in boundary");
257 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
261 bounds_list = g_list_next(bounds_list);
263 LOCATIONS_LOGD("EXIT <<<");
266 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
268 LOCATIONS_LOGD("ENTER >>>");
269 location_manager_s *handle = (location_manager_s *) userdata;
270 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
271 LocationPosition *pos = (LocationPosition *) position;
272 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
273 pos->latitude, pos->longitude,
274 pos->altitude, pos->timestamp,
276 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
279 location_bounds_s *bounds;
280 GList *bounds_list = g_list_first(handle->bounds_list);
281 while (bounds_list) {
282 bounds = (location_bounds_s *)bounds_list->data;
283 if (__boundary_compare(boundary, bounds->boundary) == 0) {
284 LOCATIONS_LOGD("Find zone out boundary");
286 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
290 bounds_list = g_list_next(bounds_list);
292 LOCATIONS_LOGD("EXIT <<<");
295 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
297 location_manager_s *handle = (location_manager_s *) user_data;
299 if (handle != NULL && boundary != NULL) {
301 location_bounds_h bounds;
302 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
303 location_coords_s center;
304 center.latitude = boundary->circle.center->latitude;
305 center.longitude = boundary->circle.center->longitude;
306 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
307 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
308 location_coords_s left_top;
309 location_coords_s right_bottom;
310 left_top.latitude = boundary->rect.left_top->latitude;
311 left_top.longitude = boundary->rect.left_top->longitude;
312 right_bottom.latitude = boundary->rect.right_bottom->latitude;
313 right_bottom.longitude = boundary->rect.right_bottom->longitude;
314 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
315 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
316 GList *list = boundary->polygon.position_list;
317 int size = g_list_length(list);
319 location_coords_s coords[size];
322 LocationPosition *pos = list->data;
323 coords[cnt].latitude = pos->latitude;
324 coords[cnt].longitude = pos->longitude;
325 list = g_list_next(list);
328 ret = location_bounds_create_polygon(coords, size, &bounds);
331 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
334 if (ret != LOCATIONS_ERROR_NONE) {
335 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
337 if (handle->is_continue_foreach_bounds) {
338 handle->is_continue_foreach_bounds =
339 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
342 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
344 location_bounds_destroy(bounds);
347 LOCATIONS_LOGD("__foreach_boundary() has been failed");
351 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
353 LOCATIONS_LOGD("method: [%d]", method);
354 location_method_e _method = __convert_location_method_e(method);
355 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
356 if (_setting_changed == NULL) {
357 LOCATIONS_LOGE("Invaild userdata\n");
361 if (_setting_changed[_method].callback != NULL)
362 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
365 /*/////////////////////////////////////// */
366 /* Location Manager */
367 /*////////////////////////////////////// */
369 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
371 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
372 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
373 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
377 if (method == LOCATIONS_METHOD_GPS) {
378 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
379 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
382 } else if (method == LOCATIONS_METHOD_WPS) {
383 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
384 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
389 LocationMethod _method = __convert_LocationMethod(method);
390 if (_method == LOCATION_METHOD_NONE) {
391 LOCATIONS_LOGE("Not supported method [%d]", method);
392 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
396 gboolean ret = location_is_supported_method(_method);
398 set_last_result(LOCATIONS_ERROR_NONE);
401 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
406 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
408 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
410 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
411 LOCATIONS_LOGE("Not supported method [%d]", method);
412 return LOCATIONS_ERROR_INCORRECT_METHOD;
415 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
416 LOCATIONS_NULL_ARG_CHECK(enable);
417 int is_enabled_val = -1;
418 LocationMethod _method = __convert_LocationMethod(method);
419 int ret = location_is_enabled_method(_method, &is_enabled_val);
420 if (ret != LOCATION_ERROR_NONE) {
421 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
422 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
423 return LOCATIONS_ERROR_INCORRECT_METHOD;
425 return __convert_error_code(ret);
428 if (is_enabled_val == -1)
429 return TIZEN_ERROR_PERMISSION_DENIED;
431 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
432 return LOCATIONS_ERROR_NONE;
435 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
437 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
439 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
440 LOCATIONS_LOGE("Not supported method [%d]", method);
441 return LOCATIONS_ERROR_INCORRECT_METHOD;
444 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
447 if (LOCATIONS_METHOD_HYBRID == method) {
448 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
449 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
450 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
452 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
453 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
454 return __convert_error_code(ret);
456 return LOCATIONS_ERROR_NONE;
459 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
460 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
461 return LOCATIONS_ERROR_NOT_SUPPORTED;
462 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
463 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
464 return LOCATIONS_ERROR_NOT_SUPPORTED;
467 LocationMethod _method = __convert_LocationMethod(method);
469 int ret = location_enable_method(_method, enable);
471 return __convert_error_code(ret);
475 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
477 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
479 if (method == LOCATIONS_METHOD_HYBRID)
480 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
481 else if (method == LOCATIONS_METHOD_GPS)
482 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
483 else if (method == LOCATIONS_METHOD_WPS)
484 LOCATIONS_NOT_SUPPORTED_CHECK(__is_wps_supported());
485 else if (method == LOCATIONS_METHOD_PASSIVE)
486 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
488 LocationMethod _method = __convert_LocationMethod(method);
489 if (_method == LOCATION_METHOD_NONE) {
490 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
491 return LOCATIONS_ERROR_NOT_SUPPORTED;
494 if (!location_is_supported_method(_method)) {
495 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
496 return LOCATIONS_ERROR_NOT_SUPPORTED;
499 /*It is moved here becasue of TCS. */
500 LOCATIONS_NULL_ARG_CHECK(manager);
502 if (location_init() != LOCATION_ERROR_NONE) {
503 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
504 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
507 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
508 if (handle == NULL) {
509 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
510 return LOCATIONS_ERROR_OUT_OF_MEMORY;
513 memset(handle, 0, sizeof(location_manager_s));
515 handle->object = location_new(_method, FALSE);
516 if (handle->object == NULL) {
517 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
519 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
521 handle->method = method;
522 handle->is_continue_foreach_bounds = TRUE;
523 handle->bounds_list = NULL;
525 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
526 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
528 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
529 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
531 *manager = (location_manager_h) handle;
532 return LOCATIONS_ERROR_NONE;
535 EXPORT_API int location_manager_destroy(location_manager_h manager)
537 LOCATIONS_LOGD("location_manager_destroy");
538 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
539 LOCATIONS_NULL_ARG_CHECK(manager);
540 location_manager_s *handle = (location_manager_s *) manager;
542 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
543 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
544 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
547 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
548 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
549 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
552 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
553 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
554 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
557 int ret = location_free(handle->object, FALSE);
558 if (ret != LOCATIONS_ERROR_NONE)
559 return __convert_error_code(ret);
562 return LOCATIONS_ERROR_NONE;
565 EXPORT_API int location_manager_start(location_manager_h manager)
567 LOCATIONS_LOGD("location_manager_start");
568 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
569 LOCATIONS_NULL_ARG_CHECK(manager);
570 location_manager_s *handle = (location_manager_s *) manager;
572 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
573 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
575 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
576 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
577 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
579 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
580 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
582 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
585 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
586 LOCATIONS_LOGI("Satellite update_cb is set");
587 location_set_option(handle->object, "USE_SV");
590 int ret = location_start(handle->object);
591 if (ret != LOCATION_ERROR_NONE)
592 return __convert_error_code(ret);
594 return LOCATIONS_ERROR_NONE;
597 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
599 LOCATIONS_LOGD("location_manager_request_single_location");
600 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
601 LOCATIONS_NULL_ARG_CHECK(manager);
602 LOCATIONS_NULL_ARG_CHECK(callback);
603 if (timeout <= 0 || timeout > 120) {
604 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
605 return LOCATIONS_ERROR_INVALID_PARAMETER;
608 location_manager_s *handle = (location_manager_s *) manager;
609 int ret = LOCATIONS_ERROR_NONE;
611 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
612 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
614 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
615 if (ret != LOCATIONS_ERROR_NONE)
618 ret = location_request_single_location(handle->object, timeout);
619 if (ret != LOCATION_ERROR_NONE) {
620 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
621 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
622 return LOCATIONS_ERROR_INCORRECT_METHOD;
624 return __convert_error_code(ret);
627 return LOCATIONS_ERROR_NONE;
630 EXPORT_API int location_manager_stop(location_manager_h manager)
632 LOCATIONS_LOGD("location_manager_stop");
633 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
634 LOCATIONS_NULL_ARG_CHECK(manager);
636 location_manager_s *handle = (location_manager_s *) manager;
638 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
639 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
640 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
643 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
644 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
645 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
646 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
649 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
650 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
651 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
655 int ret = location_stop(handle->object);
656 if (ret != LOCATION_ERROR_NONE)
657 return __convert_error_code(ret);
659 return LOCATIONS_ERROR_NONE;
662 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
664 LOCATIONS_LOGD("location_manager_add_boundary");
665 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
666 LOCATIONS_NULL_ARG_CHECK(manager);
667 LOCATIONS_NULL_ARG_CHECK(bounds);
669 location_manager_s *handle = (location_manager_s *) manager;
670 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
671 int ret = location_boundary_add(handle->object, bound_handle->boundary);
672 if (ret != LOCATION_ERROR_NONE)
673 return __convert_error_code(ret);
675 bound_handle->is_added = TRUE;
676 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
677 return LOCATIONS_ERROR_NONE;
680 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
682 LOCATIONS_LOGD("location_manager_remove_boundary");
683 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
684 LOCATIONS_NULL_ARG_CHECK(manager);
685 LOCATIONS_NULL_ARG_CHECK(bounds);
687 location_manager_s *handle = (location_manager_s *) manager;
688 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
689 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
690 if (ret != LOCATION_ERROR_NONE)
691 return __convert_error_code(ret);
693 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
694 bound_handle->is_added = FALSE;
695 return LOCATIONS_ERROR_NONE;
698 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
700 LOCATIONS_LOGD("location_manager_foreach_boundary");
701 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
702 LOCATIONS_NULL_ARG_CHECK(manager);
703 LOCATIONS_NULL_ARG_CHECK(callback);
705 location_manager_s *handle = (location_manager_s *) manager;
706 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
707 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
708 handle->is_continue_foreach_bounds = TRUE;
709 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
710 if (ret != LOCATION_ERROR_NONE)
711 return __convert_error_code(ret);
713 return LOCATIONS_ERROR_NONE;
716 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
718 LOCATIONS_LOGD("location_manager_get_method %d", method);
719 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
720 LOCATIONS_NULL_ARG_CHECK(manager);
721 LOCATIONS_NULL_ARG_CHECK(method);
723 location_manager_s *handle = (location_manager_s *) manager;
724 LocationMethod _method = LOCATION_METHOD_NONE;
725 g_object_get(handle->object, "method", &_method, NULL);
727 case LOCATION_METHOD_NONE:
728 *method = LOCATIONS_METHOD_NONE;
730 case LOCATION_METHOD_HYBRID:
731 *method = LOCATIONS_METHOD_HYBRID;
733 case LOCATION_METHOD_GPS:
734 *method = LOCATIONS_METHOD_GPS;
736 case LOCATION_METHOD_WPS:
737 *method = LOCATIONS_METHOD_WPS;
739 case LOCATION_METHOD_PASSIVE:
740 *method = LOCATIONS_METHOD_PASSIVE;
743 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
744 return LOCATIONS_ERROR_INVALID_PARAMETER;
747 return LOCATIONS_ERROR_NONE;
750 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
753 LOCATIONS_LOGD("location_manager_get_position");
754 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
755 LOCATIONS_NULL_ARG_CHECK(manager);
756 LOCATIONS_NULL_ARG_CHECK(altitude);
757 LOCATIONS_NULL_ARG_CHECK(latitude);
758 LOCATIONS_NULL_ARG_CHECK(longitude);
759 LOCATIONS_NULL_ARG_CHECK(timestamp);
761 location_manager_s *handle = (location_manager_s *) manager;
762 LocationPosition *pos = NULL;
763 LocationAccuracy *acc = NULL;
764 int ret = location_get_position(handle->object, &pos, &acc);
765 if (ret != LOCATION_ERROR_NONE)
766 return __convert_error_code(ret);
768 if (pos->status == LOCATION_STATUS_NO_FIX) {
769 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
771 *latitude = pos->latitude;
772 *longitude = pos->longitude;
773 *altitude = pos->altitude;
775 *timestamp = pos->timestamp;
776 location_position_free(pos);
777 location_accuracy_free(acc);
778 return LOCATIONS_ERROR_NONE;
781 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)
783 LOCATIONS_LOGD("location_manager_get_location");
784 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
785 LOCATIONS_NULL_ARG_CHECK(manager);
786 LOCATIONS_NULL_ARG_CHECK(altitude);
787 LOCATIONS_NULL_ARG_CHECK(latitude);
788 LOCATIONS_NULL_ARG_CHECK(longitude);
789 LOCATIONS_NULL_ARG_CHECK(climb);
790 LOCATIONS_NULL_ARG_CHECK(direction);
791 LOCATIONS_NULL_ARG_CHECK(speed);
792 LOCATIONS_NULL_ARG_CHECK(level);
793 LOCATIONS_NULL_ARG_CHECK(horizontal);
794 LOCATIONS_NULL_ARG_CHECK(vertical);
795 LOCATIONS_NULL_ARG_CHECK(timestamp);
797 location_manager_s *handle = (location_manager_s *) manager;
798 LocationPosition *pos = NULL;
799 LocationVelocity *vel = NULL;
800 LocationAccuracy *acc = NULL;
801 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
802 if (ret != LOCATION_ERROR_NONE)
803 return __convert_error_code(ret);
805 if (pos->status == LOCATION_STATUS_NO_FIX) {
806 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
808 *latitude = pos->latitude;
809 *longitude = pos->longitude;
810 *altitude = pos->altitude;
812 *timestamp = pos->timestamp;
814 *direction = vel->direction;
817 *horizontal = acc->horizontal_accuracy;
818 *vertical = acc->vertical_accuracy;
820 location_position_free(pos);
821 location_velocity_free(vel);
822 location_accuracy_free(acc);
823 return LOCATIONS_ERROR_NONE;
826 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
828 LOCATIONS_LOGD("location_manager_get_velocity");
829 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
830 LOCATIONS_NULL_ARG_CHECK(manager);
831 LOCATIONS_NULL_ARG_CHECK(climb);
832 LOCATIONS_NULL_ARG_CHECK(direction);
833 LOCATIONS_NULL_ARG_CHECK(speed);
834 LOCATIONS_NULL_ARG_CHECK(timestamp);
836 location_manager_s *handle = (location_manager_s *) manager;
837 LocationVelocity *vel = NULL;
838 LocationAccuracy *acc = NULL;
840 int ret = location_get_velocity(handle->object, &vel, &acc);
841 if (ret != LOCATION_ERROR_NONE)
842 return __convert_error_code(ret);
845 *direction = vel->direction;
847 *timestamp = vel->timestamp;
848 location_velocity_free(vel);
849 location_accuracy_free(acc);
850 return LOCATIONS_ERROR_NONE;
853 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
856 LOCATIONS_LOGD("location_manager_get_accuracy");
857 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
858 LOCATIONS_NULL_ARG_CHECK(manager);
859 LOCATIONS_NULL_ARG_CHECK(level);
860 LOCATIONS_NULL_ARG_CHECK(horizontal);
861 LOCATIONS_NULL_ARG_CHECK(vertical);
862 location_manager_s *handle = (location_manager_s *) manager;
865 LocationPosition *pos = NULL;
866 LocationAccuracy *acc = NULL;
867 ret = location_get_position(handle->object, &pos, &acc);
868 if (ret != LOCATION_ERROR_NONE)
869 return __convert_error_code(ret);
872 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
875 *horizontal = acc->horizontal_accuracy;
876 *vertical = acc->vertical_accuracy;
877 location_position_free(pos);
878 location_accuracy_free(acc);
879 return LOCATIONS_ERROR_NONE;
882 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
884 LOCATIONS_LOGD("location_manager_get_last_position");
885 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
886 LOCATIONS_NULL_ARG_CHECK(manager);
887 LOCATIONS_NULL_ARG_CHECK(altitude);
888 LOCATIONS_NULL_ARG_CHECK(latitude);
889 LOCATIONS_NULL_ARG_CHECK(longitude);
890 LOCATIONS_NULL_ARG_CHECK(timestamp);
892 location_manager_s *handle = (location_manager_s *) manager;
895 LocationPosition *last_pos = NULL;
896 LocationAccuracy *last_acc = NULL;
897 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
898 if (ret != LOCATION_ERROR_NONE)
899 return __convert_error_code(ret);
901 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
902 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
904 *latitude = last_pos->latitude;
905 *longitude = last_pos->longitude;
906 *altitude = last_pos->altitude;
908 *timestamp = last_pos->timestamp;
909 location_position_free(last_pos);
910 location_accuracy_free(last_acc);
911 return LOCATIONS_ERROR_NONE;
914 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)
916 LOCATIONS_LOGD("location_manager_get_last_location");
917 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
918 LOCATIONS_NULL_ARG_CHECK(manager);
919 LOCATIONS_NULL_ARG_CHECK(altitude);
920 LOCATIONS_NULL_ARG_CHECK(latitude);
921 LOCATIONS_NULL_ARG_CHECK(longitude);
922 LOCATIONS_NULL_ARG_CHECK(climb);
923 LOCATIONS_NULL_ARG_CHECK(direction);
924 LOCATIONS_NULL_ARG_CHECK(speed);
925 LOCATIONS_NULL_ARG_CHECK(level);
926 LOCATIONS_NULL_ARG_CHECK(horizontal);
927 LOCATIONS_NULL_ARG_CHECK(vertical);
928 LOCATIONS_NULL_ARG_CHECK(timestamp);
930 location_manager_s *handle = (location_manager_s *) manager;
933 LocationPosition *last_pos = NULL;
934 LocationVelocity *last_vel = NULL;
935 LocationAccuracy *last_acc = NULL;
936 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
937 if (ret != LOCATION_ERROR_NONE)
938 return __convert_error_code(ret);
940 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
941 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
943 *latitude = last_pos->latitude;
944 *longitude = last_pos->longitude;
945 *altitude = last_pos->altitude;
947 *timestamp = last_pos->timestamp;
948 *climb = last_vel->climb;
949 *direction = last_vel->direction;
950 *speed = last_vel->speed;
951 *level = last_acc->level;
952 *horizontal = last_acc->horizontal_accuracy;
953 *vertical = last_acc->vertical_accuracy;
954 location_position_free(last_pos);
955 location_velocity_free(last_vel);
956 location_accuracy_free(last_acc);
957 return LOCATIONS_ERROR_NONE;
960 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
962 LOCATIONS_LOGD("location_manager_get_last_velocity");
963 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
964 LOCATIONS_NULL_ARG_CHECK(manager);
965 LOCATIONS_NULL_ARG_CHECK(climb);
966 LOCATIONS_NULL_ARG_CHECK(direction);
967 LOCATIONS_NULL_ARG_CHECK(speed);
968 LOCATIONS_NULL_ARG_CHECK(timestamp);
970 location_manager_s *handle = (location_manager_s *) manager;
973 LocationVelocity *last_vel = NULL;
974 LocationAccuracy *last_acc = NULL;
975 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
976 if (ret != LOCATION_ERROR_NONE)
977 return __convert_error_code(ret);
979 *climb = last_vel->climb;
980 *direction = last_vel->direction;
981 *speed = last_vel->speed;
982 *timestamp = last_vel->timestamp;
983 location_velocity_free(last_vel);
984 location_accuracy_free(last_acc);
985 return LOCATIONS_ERROR_NONE;
988 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
990 LOCATIONS_LOGD("location_manager_get_last_accuracy");
991 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
992 LOCATIONS_NULL_ARG_CHECK(manager);
993 LOCATIONS_NULL_ARG_CHECK(level);
994 LOCATIONS_NULL_ARG_CHECK(horizontal);
995 LOCATIONS_NULL_ARG_CHECK(vertical);
996 location_manager_s *handle = (location_manager_s *) manager;
999 LocationPosition *last_pos = NULL;
1000 LocationAccuracy *last_acc = NULL;
1001 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1002 if (ret != LOCATION_ERROR_NONE)
1003 return __convert_error_code(ret);
1005 *level = last_acc->level;
1006 *horizontal = last_acc->horizontal_accuracy;
1007 *vertical = last_acc->vertical_accuracy;
1008 location_position_free(last_pos);
1009 location_accuracy_free(last_acc);
1010 return LOCATIONS_ERROR_NONE;
1013 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1015 dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1016 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1017 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1018 LOCATIONS_NULL_ARG_CHECK(state);
1020 int ret = LOCATION_ERROR_NONE;
1021 LocationAccessState auth = LOCATION_ACCESS_NONE;
1022 ret = location_get_accessibility_state(&auth);
1023 if (ret != LOCATION_ERROR_NONE) {
1024 *state = LOCATIONS_ACCESS_STATE_NONE;
1025 return __convert_error_code(ret);
1029 case LOCATION_ACCESS_DENIED:
1030 *state = LOCATIONS_ACCESS_STATE_DENIED;
1032 case LOCATION_ACCESS_ALLOWED:
1033 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1035 case LOCATION_ACCESS_NONE:
1037 *state = LOCATIONS_ACCESS_STATE_NONE;
1041 return LOCATIONS_ERROR_NONE;
1044 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)
1046 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1047 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1048 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1049 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1050 LOCATIONS_NULL_ARG_CHECK(manager);
1051 location_manager_s *handle = (location_manager_s *) manager;
1052 g_object_set(handle->object, "min-interval", interval, NULL);
1053 g_object_set(handle->object, "min-distance", distance, NULL);
1054 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1057 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1059 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1060 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1061 LOCATIONS_NULL_ARG_CHECK(manager);
1062 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1065 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1067 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1068 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1069 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1070 LOCATIONS_NULL_ARG_CHECK(manager);
1071 location_manager_s *handle = (location_manager_s *) manager;
1072 g_object_set(handle->object, "loc-interval", interval, NULL);
1073 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1076 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1078 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1079 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1080 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1083 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1085 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1086 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1087 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1088 LOCATIONS_NULL_ARG_CHECK(manager);
1089 location_manager_s *handle = (location_manager_s *) manager;
1090 g_object_set(handle->object, "pos-interval", interval, NULL);
1091 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1094 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1096 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1097 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1098 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1101 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1103 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1104 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1105 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1106 LOCATIONS_NULL_ARG_CHECK(manager);
1107 location_manager_s *handle = (location_manager_s *) manager;
1108 g_object_set(handle->object, "vel-interval", interval, NULL);
1109 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1112 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1114 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1115 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1116 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1119 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1122 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1123 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1124 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1127 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1129 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1130 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1131 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1134 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1136 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1137 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1138 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1141 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1143 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1144 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1145 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1148 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1150 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1151 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1152 LOCATIONS_NULL_ARG_CHECK(callback);
1154 LocationMethod _method = __convert_LocationMethod(method);
1155 int ret = LOCATION_ERROR_NONE;
1157 if (_method == LOCATION_METHOD_NONE) {
1158 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1159 } else if (_method == LOCATION_METHOD_PASSIVE) {
1160 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1161 return LOCATIONS_ERROR_INCORRECT_METHOD;
1164 g_location_setting[_method].callback = callback;
1165 g_location_setting[_method].user_data = user_data;
1167 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1168 if (ret != LOCATION_ERROR_NONE)
1169 return __convert_error_code(ret);
1171 return LOCATIONS_ERROR_NONE;
1174 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1176 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1177 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1178 LocationMethod _method = __convert_LocationMethod(method);
1179 int ret = LOCATION_ERROR_NONE;
1181 if (_method == LOCATION_METHOD_NONE) {
1182 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1183 } else if (_method == LOCATION_METHOD_PASSIVE) {
1184 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1185 return LOCATIONS_ERROR_INCORRECT_METHOD;
1188 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1189 if (ret != LOCATION_ERROR_NONE) {
1190 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1191 ret = __convert_error_code(ret);
1194 g_location_setting[method].callback = NULL;
1195 g_location_setting[method].user_data = NULL;
1197 return LOCATIONS_ERROR_NONE;
1200 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1202 LOCATIONS_LOGD("location_manager_get_distance");
1203 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1204 LOCATIONS_NULL_ARG_CHECK(distance);
1205 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1206 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1207 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1208 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1210 int ret = LOCATION_ERROR_NONE;
1213 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1214 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1216 ret = location_get_distance(start, end, &u_distance);
1217 if (ret != LOCATION_ERROR_NONE)
1218 return __convert_error_code(ret);
1220 *distance = (double)u_distance;
1222 return LOCATIONS_ERROR_NONE;
1225 /*/////////////////////////////////////// */
1226 /* GPS Status & Satellites */
1227 /*////////////////////////////////////// */
1229 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1231 LOCATIONS_LOGD("gps_status_get_nmea");
1232 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1233 LOCATIONS_NULL_ARG_CHECK(manager);
1234 LOCATIONS_NULL_ARG_CHECK(nmea);
1235 location_manager_s *handle = (location_manager_s *) manager;
1238 int ret = location_get_nmea(handle->object, &nmea_data);
1239 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1240 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1241 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1242 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1245 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1246 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1249 *nmea = g_strdup(nmea_data);
1252 return LOCATIONS_ERROR_NONE;
1255 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1257 LOCATIONS_LOGD("gps_status_get_satellite");
1258 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1259 LOCATIONS_NULL_ARG_CHECK(manager);
1260 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1261 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1262 LOCATIONS_NULL_ARG_CHECK(timestamp);
1263 location_manager_s *handle = (location_manager_s *) manager;
1264 LocationSatellite *sat = NULL;
1265 int ret = location_get_satellite(handle->object, &sat);
1266 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1267 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1268 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1269 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1272 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1273 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1276 *num_of_active = sat->num_of_sat_used;
1277 *num_of_inview = sat->num_of_sat_inview;
1278 *timestamp = sat->timestamp;
1279 location_satellite_free(sat);
1281 return LOCATIONS_ERROR_NONE;
1284 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1286 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1287 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1288 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1289 LOCATIONS_NULL_ARG_CHECK(manager);
1290 LOCATIONS_NULL_ARG_CHECK(callback);
1292 location_manager_s *handle = (location_manager_s *) manager;
1293 int ret = location_set_option(handle->object, "USE_SV");
1294 if (ret != LOCATION_ERROR_NONE) {
1295 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1296 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1297 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1301 g_object_set(handle->object, "sat-interval", interval, NULL);
1302 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1305 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1307 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1308 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1309 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1312 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1314 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1315 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1316 LOCATIONS_NULL_ARG_CHECK(manager);
1317 LOCATIONS_NULL_ARG_CHECK(callback);
1319 location_manager_s *handle = (location_manager_s *) manager;
1320 LocationSatellite *sat = NULL;
1321 int ret = location_get_satellite(handle->object, &sat);
1322 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1323 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1324 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1325 return LOCATIONS_ERROR_INCORRECT_METHOD;
1326 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1327 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1328 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1331 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1332 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1336 for (i = 0; i < sat->num_of_sat_inview; i++) {
1342 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1343 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1346 location_satellite_free(sat);
1348 return LOCATIONS_ERROR_NONE;
1351 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1353 LOCATIONS_LOGD("gps_status_get_last_satellite");
1354 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1355 LOCATIONS_NULL_ARG_CHECK(manager);
1356 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1357 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1358 LOCATIONS_NULL_ARG_CHECK(timestamp);
1360 location_manager_s *handle = (location_manager_s *) manager;
1361 int ret = LOCATION_ERROR_NONE;
1362 LocationSatellite *last_sat = NULL;
1363 ret = location_get_last_satellite(handle->object, &last_sat);
1364 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1365 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1366 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1367 return LOCATIONS_ERROR_INCORRECT_METHOD;
1368 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1369 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1370 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1373 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1374 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1377 *num_of_active = last_sat->num_of_sat_used;
1378 *num_of_inview = last_sat->num_of_sat_inview;
1379 *timestamp = last_sat->timestamp;
1380 location_satellite_free(last_sat);
1381 return LOCATIONS_ERROR_NONE;
1384 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1386 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1387 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1388 LOCATIONS_NULL_ARG_CHECK(manager);
1389 LOCATIONS_NULL_ARG_CHECK(callback);
1390 location_manager_s *handle = (location_manager_s *) manager;
1391 int ret = LOCATION_ERROR_NONE;
1392 LocationSatellite *last_sat = NULL;
1394 ret = location_get_last_satellite(handle->object, &last_sat);
1395 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1396 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1397 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1398 return LOCATIONS_ERROR_INCORRECT_METHOD;
1401 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1402 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1406 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1412 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1413 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1416 location_satellite_free(last_sat);
1417 return LOCATIONS_ERROR_NONE;
1424 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)
1426 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1427 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1429 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1430 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1431 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1432 LOCATIONS_NULL_ARG_CHECK(manager);
1433 LOCATIONS_NULL_ARG_CHECK(callback);
1434 location_manager_s *handle = (location_manager_s *) manager;
1435 g_object_set(handle->object, "batch-period", batch_period, NULL);
1436 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1437 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1440 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1442 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1443 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1444 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
1447 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1449 LOCATIONS_LOGD("location_manager_start_batch");
1450 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1451 LOCATIONS_NULL_ARG_CHECK(manager);
1452 location_manager_s *handle = (location_manager_s *) manager;
1454 if (LOCATIONS_METHOD_GPS == handle->method) {
1455 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1456 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1458 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1459 return LOCATIONS_ERROR_INCORRECT_METHOD;
1462 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1463 LOCATIONS_LOGD("batch status set : Start");
1465 int ret = location_start_batch(handle->object);
1466 if (ret != LOCATION_ERROR_NONE)
1467 return __convert_error_code(ret);
1469 return LOCATIONS_ERROR_NONE;
1472 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1474 LOCATIONS_LOGD("location_manager_stop_batch");
1475 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1476 LOCATIONS_NULL_ARG_CHECK(manager);
1477 location_manager_s *handle = (location_manager_s *) manager;
1479 if (LOCATIONS_METHOD_GPS == handle->method) {
1480 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1481 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1482 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1486 int ret = location_stop_batch(handle->object);
1487 if (ret != LOCATION_ERROR_NONE)
1488 return __convert_error_code(ret);
1490 return LOCATIONS_ERROR_NONE;
1493 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1495 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1496 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1497 LOCATIONS_NULL_ARG_CHECK(manager);
1498 LOCATIONS_NULL_ARG_CHECK(callback);
1499 location_manager_s *handle = (location_manager_s *) manager;
1500 LocationBatch *batch = NULL;
1502 int ret = location_get_batch(handle->object, &batch);
1503 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1504 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1505 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1506 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1509 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1510 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1514 for (i = 0; i < batch->num_of_location; i++) {
1524 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1525 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1528 location_batch_free(batch);
1530 return LOCATIONS_ERROR_NONE;
1533 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1535 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1536 LOCATIONS_NULL_ARG_CHECK(enabled);
1537 int is_enabled_val = -1;
1538 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1539 if (ret != LOCATION_ERROR_NONE)
1540 return __convert_error_code(ret);
1542 if (is_enabled_val == -1)
1543 return TIZEN_ERROR_PERMISSION_DENIED;
1545 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1546 return LOCATIONS_ERROR_NONE;
1549 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1551 LOCATIONS_LOGD("enable: %d", enable);
1552 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1553 int ret = LOCATION_ERROR_NONE;
1555 ret = location_enable_mock(enable);
1556 return __convert_error_code(ret);
1559 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1560 const double speed, const double direction, const double accuracy)
1562 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1563 LOCATIONS_NULL_ARG_CHECK(manager);
1565 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1566 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1567 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1569 location_manager_s *handle = (location_manager_s *) manager;
1570 int ret = LOCATION_ERROR_NONE;
1572 LocationPosition *pos = NULL;
1573 LocationVelocity *vel = NULL;
1574 LocationAccuracy *acc = NULL;
1576 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1577 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1578 if (ret == LOCATIONS_ERROR_NONE) {
1580 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1582 return __convert_error_code(ret);
1585 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1587 LOCATIONS_LOGE("Failed to create position");
1588 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1590 vel = location_velocity_new(0, speed, direction, 0);
1592 LOCATIONS_LOGE("Failed to create velocity");
1593 location_position_free(pos);
1594 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1597 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1599 LOCATIONS_LOGE("Failed to create accuracy");
1600 location_position_free(pos);
1601 location_velocity_free(vel);
1602 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1605 ret = location_set_mock_location(handle->object, pos, vel, acc);
1606 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1607 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1608 return LOCATIONS_ERROR_INCORRECT_METHOD;
1611 location_position_free(pos);
1612 location_velocity_free(vel);
1613 location_accuracy_free(acc);
1615 return __convert_error_code(ret);
1618 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1620 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1621 LOCATIONS_NULL_ARG_CHECK(manager);
1623 location_manager_s *handle = (location_manager_s *) manager;
1626 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1627 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1628 if (ret == LOCATIONS_ERROR_NONE) {
1630 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1632 return __convert_error_code(ret);
1635 ret = location_clear_mock_location(handle->object);
1636 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1637 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
1638 return LOCATIONS_ERROR_INCORRECT_METHOD;
1641 return __convert_error_code(ret);