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_WPS + 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_NONE:
61 _method = LOCATION_METHOD_NONE;
67 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
69 LOCATIONS_LOGD("Callback function has been invoked. ");
70 location_manager_s *handle = (location_manager_s *) userdata;
72 if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
73 LocationSatellite *sat = (LocationSatellite *)data;
74 LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
75 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
76 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
77 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
78 } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
79 LocationPosition *pos = (LocationPosition *) data;
80 LocationVelocity *vel = (LocationVelocity *) velocity; /* current velocity */
81 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
82 vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
85 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
86 LocationPosition *pos = (LocationPosition *) data;
87 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude,
88 pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
91 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
92 LocationVelocity *vel = (LocationVelocity *) velocity;
93 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb,
94 vel->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
97 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
98 LocationPosition *pos = (LocationPosition *) data;
99 LocationVelocity *vel = (LocationVelocity *) velocity;
100 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
101 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
102 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
107 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
109 LOCATIONS_LOGD("Callback function has been invoked. ");
110 int converted_err = __convert_error_code(error);
111 location_manager_s *handle = (location_manager_s *) userdata;
112 LocationPosition *pos = (LocationPosition *) position;
113 LocationVelocity *vel = (LocationVelocity *) velocity;
115 LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
116 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
117 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
118 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
122 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
124 LOCATIONS_LOGD("Batch callback function has been invoked.");
125 location_manager_s *handle = (location_manager_s *) userdata;
127 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
128 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
131 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
133 LOCATIONS_LOGD("Invoked. status = %d", status);
134 location_manager_s *handle = (location_manager_s *) userdata;
135 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
136 ((location_service_state_changed_cb)
137 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
141 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
143 LOCATIONS_LOGD("Invoked. 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_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
152 static void __cb_service_status_changed(GObject *self, guint status, gpointer userdata)
154 LOCATIONS_LOGD("Invoked. status = %u", status);
155 location_manager_s *handle = (location_manager_s *) userdata;
157 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
158 if (status == LOCATION_STATUS_2D_FIX || status == LOCATION_STATUS_3D_FIX)
159 ((location_service_state_changed_cb)
160 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
161 else if (status == LOCATION_STATUS_NO_FIX)
162 ((location_service_state_changed_cb)
163 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
164 else if (status == LOCATION_STATUS_MOCK_FAIL)
165 ((location_service_state_changed_cb)
166 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ERROR, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
171 static int __compare_position(gconstpointer a, gconstpointer b)
173 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
179 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
183 if (bound1->type == bound2->type) {
184 switch (bound1->type) {
185 case LOCATION_BOUNDARY_CIRCLE:
186 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius)
190 case LOCATION_BOUNDARY_RECT:
191 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom))
195 case LOCATION_BOUNDARY_POLYGON: {
196 GList *boundary1_next = NULL;
197 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
198 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list))
201 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
202 if (boundary2_start == NULL) return -1;
204 boundary2_prev = g_list_previous(boundary2_start);
205 boundary2_next = g_list_next(boundary2_start);
207 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
208 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
210 boundary1_next = g_list_next(bound1->polygon.position_list);
211 if (boundary1_next != NULL && boundary2_prev != NULL &&
212 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
213 boundary1_next = g_list_next(boundary1_next);
214 while (boundary1_next) {
215 boundary2_prev = g_list_previous(boundary2_prev);
216 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
217 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
220 boundary1_next = g_list_next(boundary1_next);
223 } else if (boundary1_next != NULL && boundary2_next != NULL &&
224 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
225 boundary1_next = g_list_next(boundary1_next);
226 while (boundary1_next) {
227 boundary2_next = g_list_next(boundary2_next);
228 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
229 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
232 boundary1_next = g_list_next(boundary1_next);
247 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
249 LOCATIONS_LOGD("ENTER >>>");
250 location_manager_s *handle = (location_manager_s *) userdata;
251 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
252 LocationPosition *pos = (LocationPosition *) position;
253 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
254 pos->latitude, pos->longitude,
255 pos->altitude, pos->timestamp,
257 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
260 location_bounds_s *bounds;
261 GList *bounds_list = g_list_first(handle->bounds_list);
262 while (bounds_list) {
263 bounds = (location_bounds_s *)bounds_list->data;
264 if (__boundary_compare(boundary, bounds->boundary) == 0) {
265 LOCATIONS_LOGD("Find zone in boundary");
267 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
271 bounds_list = g_list_next(bounds_list);
273 LOCATIONS_LOGD("EXIT <<<");
276 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
278 LOCATIONS_LOGD("ENTER >>>");
279 location_manager_s *handle = (location_manager_s *) userdata;
280 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
281 LocationPosition *pos = (LocationPosition *) position;
282 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
283 pos->latitude, pos->longitude,
284 pos->altitude, pos->timestamp,
286 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
289 location_bounds_s *bounds;
290 GList *bounds_list = g_list_first(handle->bounds_list);
291 while (bounds_list) {
292 bounds = (location_bounds_s *)bounds_list->data;
293 if (__boundary_compare(boundary, bounds->boundary) == 0) {
294 LOCATIONS_LOGD("Find zone out boundary");
296 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
300 bounds_list = g_list_next(bounds_list);
302 LOCATIONS_LOGD("EXIT <<<");
305 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
307 location_manager_s *handle = (location_manager_s *) user_data;
309 if (handle != NULL && boundary != NULL) {
311 location_bounds_h bounds;
312 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
313 location_coords_s center;
314 center.latitude = boundary->circle.center->latitude;
315 center.longitude = boundary->circle.center->longitude;
316 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
317 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
318 location_coords_s left_top;
319 location_coords_s right_bottom;
320 left_top.latitude = boundary->rect.left_top->latitude;
321 left_top.longitude = boundary->rect.left_top->longitude;
322 right_bottom.latitude = boundary->rect.right_bottom->latitude;
323 right_bottom.longitude = boundary->rect.right_bottom->longitude;
324 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
325 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
326 GList *list = boundary->polygon.position_list;
327 int size = g_list_length(list);
329 location_coords_s coords[size];
332 LocationPosition *pos = list->data;
333 coords[cnt].latitude = pos->latitude;
334 coords[cnt].longitude = pos->longitude;
335 list = g_list_next(list);
338 ret = location_bounds_create_polygon(coords, size, &bounds);
341 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
344 if (ret != LOCATIONS_ERROR_NONE) {
345 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
347 if (handle->is_continue_foreach_bounds) {
348 handle->is_continue_foreach_bounds =
349 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
352 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
354 location_bounds_destroy(bounds);
357 LOCATIONS_LOGD("__foreach_boundary() has been failed");
361 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
363 LOCATIONS_LOGD("method: [%d]", method);
364 location_method_e _method = __convert_location_method_e(method);
365 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
366 if (_setting_changed == NULL) {
367 LOCATIONS_LOGE("Invaild userdata\n");
371 if (_setting_changed[_method].callback != NULL)
372 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
375 /*/////////////////////////////////////// */
376 /* Location Manager */
377 /*////////////////////////////////////// */
379 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
381 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
382 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
383 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
387 if (method == LOCATIONS_METHOD_GPS) {
388 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
389 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
392 } else if (method == LOCATIONS_METHOD_WPS) {
393 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
394 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
399 LocationMethod _method = __convert_LocationMethod(method);
400 if (_method == LOCATION_METHOD_NONE) {
401 LOCATIONS_LOGE("Not supported method [%d]", method);
402 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
406 set_last_result(LOCATIONS_ERROR_NONE);
407 return location_is_supported_method(_method);
410 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
412 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
414 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
415 LOCATIONS_LOGE("Not supported method [%d]", method);
416 return LOCATIONS_ERROR_INCORRECT_METHOD;
419 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
420 LOCATIONS_NULL_ARG_CHECK(enable);
421 int is_enabled_val = -1;
422 LocationMethod _method = __convert_LocationMethod(method);
423 int ret = location_is_enabled_method(_method, &is_enabled_val);
424 if (ret != LOCATION_ERROR_NONE) {
425 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
426 return LOCATIONS_ERROR_INCORRECT_METHOD;
427 return __convert_error_code(ret);
430 if (is_enabled_val == -1)
431 return TIZEN_ERROR_PERMISSION_DENIED;
433 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
434 return LOCATIONS_ERROR_NONE;
437 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
439 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
441 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
442 LOCATIONS_LOGE("Not supported method [%d]", method);
443 return LOCATIONS_ERROR_INCORRECT_METHOD;
446 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
449 if (LOCATIONS_METHOD_HYBRID == method) {
450 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
451 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
452 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
454 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
455 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
456 return __convert_error_code(ret);
458 return LOCATIONS_ERROR_NONE;
461 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
462 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
463 return LOCATIONS_ERROR_NOT_SUPPORTED;
464 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
465 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
466 return LOCATIONS_ERROR_NOT_SUPPORTED;
469 LocationMethod _method = __convert_LocationMethod(method);
471 int ret = location_enable_method(_method, enable);
473 return __convert_error_code(ret);
477 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
479 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
481 if (method == LOCATIONS_METHOD_HYBRID) {
482 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
483 } else if (method == LOCATIONS_METHOD_GPS) {
484 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
485 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
486 return LOCATIONS_ERROR_NOT_SUPPORTED;
488 } else if (method == LOCATIONS_METHOD_WPS) {
489 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
490 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
491 return LOCATIONS_ERROR_NOT_SUPPORTED;
495 LocationMethod _method = __convert_LocationMethod(method);
496 if (_method == LOCATION_METHOD_NONE) {
497 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
498 return LOCATIONS_ERROR_NOT_SUPPORTED;
501 if (!location_is_supported_method(_method)) {
502 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
503 return LOCATIONS_ERROR_NOT_SUPPORTED;
506 /*It is moved here becasue of TCS. */
507 LOCATIONS_NULL_ARG_CHECK(manager);
509 if (location_init() != LOCATION_ERROR_NONE) {
510 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
511 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
514 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
515 if (handle == NULL) {
516 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
517 return LOCATIONS_ERROR_OUT_OF_MEMORY;
520 memset(handle, 0, sizeof(location_manager_s));
522 handle->object = location_new(_method);
523 if (handle->object == NULL) {
524 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
526 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
528 handle->method = method;
529 handle->is_continue_foreach_bounds = TRUE;
530 handle->bounds_list = NULL;
532 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
533 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
535 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
536 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
539 if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED])
540 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle);
543 *manager = (location_manager_h) handle;
544 return LOCATIONS_ERROR_NONE;
547 EXPORT_API int location_manager_destroy(location_manager_h manager)
549 LOCATIONS_LOGD("location_manager_destroy");
550 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
551 LOCATIONS_NULL_ARG_CHECK(manager);
552 location_manager_s *handle = (location_manager_s *) manager;
554 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
555 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
556 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
559 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
560 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
561 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
565 if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) {
566 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]);
567 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0;
571 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
572 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
573 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
576 int ret = location_free(handle->object);
577 if (ret != LOCATIONS_ERROR_NONE)
578 return __convert_error_code(ret);
581 return LOCATIONS_ERROR_NONE;
584 EXPORT_API int location_manager_start(location_manager_h manager)
586 LOCATIONS_LOGD("location_manager_start");
587 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
588 LOCATIONS_NULL_ARG_CHECK(manager);
589 location_manager_s *handle = (location_manager_s *) manager;
591 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
592 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
594 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_WPS) {
595 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
596 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
598 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
599 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
601 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
604 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
605 LOCATIONS_LOGI("Satellite update_cb is set");
606 location_set_option(handle->object, "USE_SV");
609 int ret = location_start(handle->object);
610 if (ret != LOCATION_ERROR_NONE)
611 return __convert_error_code(ret);
613 return LOCATIONS_ERROR_NONE;
616 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
618 LOCATIONS_LOGD("location_manager_request_single_location");
619 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
620 LOCATIONS_NULL_ARG_CHECK(manager);
621 LOCATIONS_NULL_ARG_CHECK(callback);
622 if (timeout <= 0 || timeout > 120) {
623 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
624 return LOCATIONS_ERROR_INVALID_PARAMETER;
627 location_manager_s *handle = (location_manager_s *) manager;
628 int ret = LOCATIONS_ERROR_NONE;
630 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
631 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
633 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
634 if (ret != LOCATIONS_ERROR_NONE)
637 ret = location_request_single_location(handle->object, timeout);
638 if (ret != LOCATION_ERROR_NONE)
639 return __convert_error_code(ret);
641 return LOCATIONS_ERROR_NONE;
644 EXPORT_API int location_manager_stop(location_manager_h manager)
646 LOCATIONS_LOGD("location_manager_stop");
647 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
648 LOCATIONS_NULL_ARG_CHECK(manager);
650 location_manager_s *handle = (location_manager_s *) manager;
652 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
653 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
654 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
657 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_WPS) {
658 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
659 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
660 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
663 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
664 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
665 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
669 int ret = location_stop(handle->object);
670 if (ret != LOCATION_ERROR_NONE)
671 return __convert_error_code(ret);
673 return LOCATIONS_ERROR_NONE;
676 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
678 LOCATIONS_LOGD("location_manager_add_boundary");
679 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
680 LOCATIONS_NULL_ARG_CHECK(manager);
681 LOCATIONS_NULL_ARG_CHECK(bounds);
683 location_manager_s *handle = (location_manager_s *) manager;
684 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
685 int ret = location_boundary_add(handle->object, bound_handle->boundary);
686 if (ret != LOCATION_ERROR_NONE)
687 return __convert_error_code(ret);
689 bound_handle->is_added = TRUE;
690 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
691 return LOCATIONS_ERROR_NONE;
694 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
696 LOCATIONS_LOGD("location_manager_remove_boundary");
697 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
698 LOCATIONS_NULL_ARG_CHECK(manager);
699 LOCATIONS_NULL_ARG_CHECK(bounds);
701 location_manager_s *handle = (location_manager_s *) manager;
702 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
703 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
704 if (ret != LOCATION_ERROR_NONE)
705 return __convert_error_code(ret);
707 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
708 bound_handle->is_added = FALSE;
709 return LOCATIONS_ERROR_NONE;
712 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
714 LOCATIONS_LOGD("location_manager_foreach_boundary");
715 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
716 LOCATIONS_NULL_ARG_CHECK(manager);
717 LOCATIONS_NULL_ARG_CHECK(callback);
719 location_manager_s *handle = (location_manager_s *) manager;
720 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
721 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
722 handle->is_continue_foreach_bounds = TRUE;
723 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
724 if (ret != LOCATION_ERROR_NONE)
725 return __convert_error_code(ret);
727 return LOCATIONS_ERROR_NONE;
730 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
732 LOCATIONS_LOGD("location_manager_get_method %d", method);
733 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
734 LOCATIONS_NULL_ARG_CHECK(manager);
735 LOCATIONS_NULL_ARG_CHECK(method);
737 location_manager_s *handle = (location_manager_s *) manager;
738 LocationMethod _method = LOCATION_METHOD_NONE;
739 g_object_get(handle->object, "method", &_method, NULL);
741 case LOCATION_METHOD_NONE:
742 *method = LOCATIONS_METHOD_NONE;
744 case LOCATION_METHOD_HYBRID:
745 *method = LOCATIONS_METHOD_HYBRID;
747 case LOCATION_METHOD_GPS:
748 *method = LOCATIONS_METHOD_GPS;
750 case LOCATION_METHOD_WPS:
751 *method = LOCATIONS_METHOD_WPS;
754 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
755 return LOCATIONS_ERROR_INVALID_PARAMETER;
758 return LOCATIONS_ERROR_NONE;
761 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
764 LOCATIONS_LOGD("location_manager_get_position");
765 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
766 LOCATIONS_NULL_ARG_CHECK(manager);
767 LOCATIONS_NULL_ARG_CHECK(altitude);
768 LOCATIONS_NULL_ARG_CHECK(latitude);
769 LOCATIONS_NULL_ARG_CHECK(longitude);
770 LOCATIONS_NULL_ARG_CHECK(timestamp);
772 location_manager_s *handle = (location_manager_s *) manager;
773 LocationPosition *pos = NULL;
774 LocationAccuracy *acc = NULL;
775 int ret = location_get_position(handle->object, &pos, &acc);
776 if (ret != LOCATION_ERROR_NONE)
777 return __convert_error_code(ret);
779 if (pos->status == LOCATION_STATUS_NO_FIX) {
780 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
782 *latitude = pos->latitude;
783 *longitude = pos->longitude;
784 *altitude = pos->altitude;
786 *timestamp = pos->timestamp;
787 location_position_free(pos);
788 location_accuracy_free(acc);
789 return LOCATIONS_ERROR_NONE;
792 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)
794 LOCATIONS_LOGD("location_manager_get_location");
795 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
796 LOCATIONS_NULL_ARG_CHECK(manager);
797 LOCATIONS_NULL_ARG_CHECK(altitude);
798 LOCATIONS_NULL_ARG_CHECK(latitude);
799 LOCATIONS_NULL_ARG_CHECK(longitude);
800 LOCATIONS_NULL_ARG_CHECK(climb);
801 LOCATIONS_NULL_ARG_CHECK(direction);
802 LOCATIONS_NULL_ARG_CHECK(speed);
803 LOCATIONS_NULL_ARG_CHECK(level);
804 LOCATIONS_NULL_ARG_CHECK(horizontal);
805 LOCATIONS_NULL_ARG_CHECK(vertical);
806 LOCATIONS_NULL_ARG_CHECK(timestamp);
808 location_manager_s *handle = (location_manager_s *) manager;
809 LocationPosition *pos = NULL;
810 LocationVelocity *vel = NULL;
811 LocationAccuracy *acc = NULL;
812 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
813 if (ret != LOCATION_ERROR_NONE)
814 return __convert_error_code(ret);
816 if (pos->status == LOCATION_STATUS_NO_FIX) {
817 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
819 *latitude = pos->latitude;
820 *longitude = pos->longitude;
821 *altitude = pos->altitude;
823 *timestamp = pos->timestamp;
825 *direction = vel->direction;
828 *horizontal = acc->horizontal_accuracy;
829 *vertical = acc->vertical_accuracy;
831 location_position_free(pos);
832 location_velocity_free(vel);
833 location_accuracy_free(acc);
834 return LOCATIONS_ERROR_NONE;
837 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
839 LOCATIONS_LOGD("location_manager_get_velocity");
840 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
841 LOCATIONS_NULL_ARG_CHECK(manager);
842 LOCATIONS_NULL_ARG_CHECK(climb);
843 LOCATIONS_NULL_ARG_CHECK(direction);
844 LOCATIONS_NULL_ARG_CHECK(speed);
845 LOCATIONS_NULL_ARG_CHECK(timestamp);
847 location_manager_s *handle = (location_manager_s *) manager;
848 LocationVelocity *vel = NULL;
849 LocationAccuracy *acc = NULL;
851 int ret = location_get_velocity(handle->object, &vel, &acc);
852 if (ret != LOCATION_ERROR_NONE)
853 return __convert_error_code(ret);
856 *direction = vel->direction;
858 *timestamp = vel->timestamp;
859 location_velocity_free(vel);
860 location_accuracy_free(acc);
861 return LOCATIONS_ERROR_NONE;
864 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
867 LOCATIONS_LOGD("location_manager_get_accuracy");
868 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
869 LOCATIONS_NULL_ARG_CHECK(manager);
870 LOCATIONS_NULL_ARG_CHECK(level);
871 LOCATIONS_NULL_ARG_CHECK(horizontal);
872 LOCATIONS_NULL_ARG_CHECK(vertical);
873 location_manager_s *handle = (location_manager_s *) manager;
876 LocationPosition *pos = NULL;
877 LocationAccuracy *acc = NULL;
878 ret = location_get_position(handle->object, &pos, &acc);
879 if (ret != LOCATION_ERROR_NONE)
880 return __convert_error_code(ret);
883 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
886 *horizontal = acc->horizontal_accuracy;
887 *vertical = acc->vertical_accuracy;
888 location_position_free(pos);
889 location_accuracy_free(acc);
890 return LOCATIONS_ERROR_NONE;
893 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
895 LOCATIONS_LOGD("location_manager_get_last_position");
896 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
897 LOCATIONS_NULL_ARG_CHECK(manager);
898 LOCATIONS_NULL_ARG_CHECK(altitude);
899 LOCATIONS_NULL_ARG_CHECK(latitude);
900 LOCATIONS_NULL_ARG_CHECK(longitude);
901 LOCATIONS_NULL_ARG_CHECK(timestamp);
903 location_manager_s *handle = (location_manager_s *) manager;
906 LocationPosition *last_pos = NULL;
907 LocationAccuracy *last_acc = NULL;
908 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
909 if (ret != LOCATION_ERROR_NONE)
910 return __convert_error_code(ret);
912 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
913 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
915 *latitude = last_pos->latitude;
916 *longitude = last_pos->longitude;
917 *altitude = last_pos->altitude;
919 *timestamp = last_pos->timestamp;
920 location_position_free(last_pos);
921 location_accuracy_free(last_acc);
922 return LOCATIONS_ERROR_NONE;
925 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)
927 LOCATIONS_LOGD("location_manager_get_last_location");
928 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
929 LOCATIONS_NULL_ARG_CHECK(manager);
930 LOCATIONS_NULL_ARG_CHECK(altitude);
931 LOCATIONS_NULL_ARG_CHECK(latitude);
932 LOCATIONS_NULL_ARG_CHECK(longitude);
933 LOCATIONS_NULL_ARG_CHECK(climb);
934 LOCATIONS_NULL_ARG_CHECK(direction);
935 LOCATIONS_NULL_ARG_CHECK(speed);
936 LOCATIONS_NULL_ARG_CHECK(level);
937 LOCATIONS_NULL_ARG_CHECK(horizontal);
938 LOCATIONS_NULL_ARG_CHECK(vertical);
939 LOCATIONS_NULL_ARG_CHECK(timestamp);
941 location_manager_s *handle = (location_manager_s *) manager;
944 LocationPosition *last_pos = NULL;
945 LocationVelocity *last_vel = NULL;
946 LocationAccuracy *last_acc = NULL;
947 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
948 if (ret != LOCATION_ERROR_NONE)
949 return __convert_error_code(ret);
951 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
952 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
954 *latitude = last_pos->latitude;
955 *longitude = last_pos->longitude;
956 *altitude = last_pos->altitude;
958 *timestamp = last_pos->timestamp;
959 *climb = last_vel->climb;
960 *direction = last_vel->direction;
961 *speed = last_vel->speed;
962 *level = last_acc->level;
963 *horizontal = last_acc->horizontal_accuracy;
964 *vertical = last_acc->vertical_accuracy;
965 location_position_free(last_pos);
966 location_velocity_free(last_vel);
967 location_accuracy_free(last_acc);
968 return LOCATIONS_ERROR_NONE;
971 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
973 LOCATIONS_LOGD("location_manager_get_last_velocity");
974 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
975 LOCATIONS_NULL_ARG_CHECK(manager);
976 LOCATIONS_NULL_ARG_CHECK(climb);
977 LOCATIONS_NULL_ARG_CHECK(direction);
978 LOCATIONS_NULL_ARG_CHECK(speed);
979 LOCATIONS_NULL_ARG_CHECK(timestamp);
981 location_manager_s *handle = (location_manager_s *) manager;
984 LocationVelocity *last_vel = NULL;
985 LocationAccuracy *last_acc = NULL;
986 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
987 if (ret != LOCATION_ERROR_NONE)
988 return __convert_error_code(ret);
990 *climb = last_vel->climb;
991 *direction = last_vel->direction;
992 *speed = last_vel->speed;
993 *timestamp = last_vel->timestamp;
994 location_velocity_free(last_vel);
995 location_accuracy_free(last_acc);
996 return LOCATIONS_ERROR_NONE;
999 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
1001 LOCATIONS_LOGD("location_manager_get_last_accuracy");
1002 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1003 LOCATIONS_NULL_ARG_CHECK(manager);
1004 LOCATIONS_NULL_ARG_CHECK(level);
1005 LOCATIONS_NULL_ARG_CHECK(horizontal);
1006 LOCATIONS_NULL_ARG_CHECK(vertical);
1007 location_manager_s *handle = (location_manager_s *) manager;
1010 LocationPosition *last_pos = NULL;
1011 LocationAccuracy *last_acc = NULL;
1012 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1013 if (ret != LOCATION_ERROR_NONE)
1014 return __convert_error_code(ret);
1016 *level = last_acc->level;
1017 *horizontal = last_acc->horizontal_accuracy;
1018 *vertical = last_acc->vertical_accuracy;
1019 location_position_free(last_pos);
1020 location_accuracy_free(last_acc);
1021 return LOCATIONS_ERROR_NONE;
1024 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1026 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1027 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1028 LOCATIONS_NULL_ARG_CHECK(state);
1030 int ret = LOCATION_ERROR_NONE;
1031 LocationAccessState auth = LOCATION_ACCESS_NONE;
1032 ret = location_get_accessibility_state(&auth);
1033 if (ret != LOCATION_ERROR_NONE) {
1034 *state = LOCATIONS_ACCESS_STATE_NONE;
1035 return __convert_error_code(ret);
1039 case LOCATION_ACCESS_DENIED:
1040 *state = LOCATIONS_ACCESS_STATE_DENIED;
1042 case LOCATION_ACCESS_ALLOWED:
1043 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1045 case LOCATION_ACCESS_NONE:
1047 *state = LOCATIONS_ACCESS_STATE_NONE;
1051 return LOCATIONS_ERROR_NONE;
1054 EXPORT_API int location_manager_set_distance_based_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, double distance, void *user_data)
1056 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1057 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1058 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1059 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1060 LOCATIONS_NULL_ARG_CHECK(manager);
1061 location_manager_s *handle = (location_manager_s *) manager;
1062 g_object_set(handle->object, "min-interval", interval, NULL);
1063 g_object_set(handle->object, "min-distance", distance, NULL);
1064 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1067 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1069 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1070 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1071 LOCATIONS_NULL_ARG_CHECK(manager);
1072 location_manager_s *handle = (location_manager_s *) manager;
1073 g_object_set(handle->object, "min-interval", 0, NULL);
1074 g_object_set(handle->object, "min-distance", 0, NULL);
1075 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1078 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1080 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1081 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1082 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1083 LOCATIONS_NULL_ARG_CHECK(manager);
1084 location_manager_s *handle = (location_manager_s *) manager;
1085 g_object_set(handle->object, "loc-interval", interval, NULL);
1086 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1089 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1091 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1092 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1093 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1096 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1098 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1099 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1100 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1101 LOCATIONS_NULL_ARG_CHECK(manager);
1102 location_manager_s *handle = (location_manager_s *) manager;
1103 g_object_set(handle->object, "pos-interval", interval, NULL);
1104 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1107 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1109 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1110 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1111 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1114 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1116 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1117 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1118 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1119 LOCATIONS_NULL_ARG_CHECK(manager);
1120 location_manager_s *handle = (location_manager_s *) manager;
1121 g_object_set(handle->object, "vel-interval", interval, NULL);
1122 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1125 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1127 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1128 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1129 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1132 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1135 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1136 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1137 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1140 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1142 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1143 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1144 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1147 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1149 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1150 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1151 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1154 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1156 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1157 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1158 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1161 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1163 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1164 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1165 LOCATIONS_NULL_ARG_CHECK(callback);
1167 LocationMethod _method = __convert_LocationMethod(method);
1168 int ret = LOCATION_ERROR_NONE;
1170 if (_method == LOCATION_METHOD_NONE)
1171 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1173 g_location_setting[_method].callback = callback;
1174 g_location_setting[_method].user_data = user_data;
1176 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1177 if (ret != LOCATION_ERROR_NONE)
1178 return __convert_error_code(ret);
1180 return LOCATIONS_ERROR_NONE;
1183 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1185 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1186 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1187 LocationMethod _method = __convert_LocationMethod(method);
1188 int ret = LOCATION_ERROR_NONE;
1190 if (_method == LOCATION_METHOD_NONE)
1191 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1193 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1194 if (ret != LOCATION_ERROR_NONE) {
1195 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1196 ret = __convert_error_code(ret);
1199 g_location_setting[method].callback = NULL;
1200 g_location_setting[method].user_data = NULL;
1202 return LOCATIONS_ERROR_NONE;
1205 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1207 LOCATIONS_LOGD("location_manager_get_distance");
1208 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1209 LOCATIONS_NULL_ARG_CHECK(distance);
1210 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1211 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1212 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1213 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1215 int ret = LOCATION_ERROR_NONE;
1218 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1219 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1221 ret = location_get_distance(start, end, &u_distance);
1222 if (ret != LOCATION_ERROR_NONE)
1223 return __convert_error_code(ret);
1225 *distance = (double)u_distance;
1227 return LOCATIONS_ERROR_NONE;
1230 /*/////////////////////////////////////// */
1231 /* GPS Status & Satellites */
1232 /*////////////////////////////////////// */
1234 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1236 LOCATIONS_LOGD("gps_status_get_nmea");
1237 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1238 LOCATIONS_NULL_ARG_CHECK(manager);
1239 LOCATIONS_NULL_ARG_CHECK(nmea);
1240 location_manager_s *handle = (location_manager_s *) manager;
1243 int ret = location_get_nmea(handle->object, &nmea_data);
1244 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1245 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1246 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1247 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1250 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1251 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1254 *nmea = g_strdup(nmea_data);
1257 return LOCATIONS_ERROR_NONE;
1260 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1262 LOCATIONS_LOGD("gps_status_get_satellite");
1263 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1264 LOCATIONS_NULL_ARG_CHECK(manager);
1265 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1266 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1267 LOCATIONS_NULL_ARG_CHECK(timestamp);
1268 location_manager_s *handle = (location_manager_s *) manager;
1269 LocationSatellite *sat = NULL;
1270 int ret = location_get_satellite(handle->object, &sat);
1271 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1272 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1273 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1274 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1277 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1278 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1281 *num_of_active = sat->num_of_sat_used;
1282 *num_of_inview = sat->num_of_sat_inview;
1283 *timestamp = sat->timestamp;
1284 location_satellite_free(sat);
1286 return LOCATIONS_ERROR_NONE;
1289 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1291 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1292 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1293 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1294 LOCATIONS_NULL_ARG_CHECK(manager);
1295 LOCATIONS_NULL_ARG_CHECK(callback);
1297 location_manager_s *handle = (location_manager_s *) manager;
1298 int ret = location_set_option(handle->object, "USE_SV");
1299 if (ret != LOCATION_ERROR_NONE) {
1300 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1301 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1302 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1306 g_object_set(handle->object, "sat-interval", interval, NULL);
1307 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1310 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1312 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1313 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1314 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1317 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1319 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1320 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1321 LOCATIONS_NULL_ARG_CHECK(manager);
1322 LOCATIONS_NULL_ARG_CHECK(callback);
1324 location_manager_s *handle = (location_manager_s *) manager;
1325 LocationSatellite *sat = NULL;
1326 int ret = location_get_satellite(handle->object, &sat);
1327 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1328 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1329 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1330 return LOCATIONS_ERROR_INCORRECT_METHOD;
1331 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1332 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1333 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1336 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1337 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1341 for (i = 0; i < sat->num_of_sat_inview; i++) {
1347 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1348 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1351 location_satellite_free(sat);
1353 return LOCATIONS_ERROR_NONE;
1356 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1358 LOCATIONS_LOGD("gps_status_get_last_satellite");
1359 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1360 LOCATIONS_NULL_ARG_CHECK(manager);
1361 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1362 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1363 LOCATIONS_NULL_ARG_CHECK(timestamp);
1365 location_manager_s *handle = (location_manager_s *) manager;
1366 int ret = LOCATION_ERROR_NONE;
1367 LocationSatellite *last_sat = NULL;
1368 ret = location_get_last_satellite(handle->object, &last_sat);
1369 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1370 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1371 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1372 return LOCATIONS_ERROR_INCORRECT_METHOD;
1373 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1374 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1375 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1378 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1379 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1382 *num_of_active = last_sat->num_of_sat_used;
1383 *num_of_inview = last_sat->num_of_sat_inview;
1384 *timestamp = last_sat->timestamp;
1385 location_satellite_free(last_sat);
1386 return LOCATIONS_ERROR_NONE;
1389 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1391 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1392 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1393 LOCATIONS_NULL_ARG_CHECK(manager);
1394 LOCATIONS_NULL_ARG_CHECK(callback);
1395 location_manager_s *handle = (location_manager_s *) manager;
1396 int ret = LOCATION_ERROR_NONE;
1397 LocationSatellite *last_sat = NULL;
1399 ret = location_get_last_satellite(handle->object, &last_sat);
1400 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1401 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1402 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1403 return LOCATIONS_ERROR_INCORRECT_METHOD;
1406 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1407 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1411 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1417 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1418 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1421 location_satellite_free(last_sat);
1422 return LOCATIONS_ERROR_NONE;
1429 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)
1431 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1432 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1434 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1435 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1436 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1437 LOCATIONS_NULL_ARG_CHECK(manager);
1438 LOCATIONS_NULL_ARG_CHECK(callback);
1439 location_manager_s *handle = (location_manager_s *) manager;
1440 g_object_set(handle->object, "batch-period", batch_period, NULL);
1441 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1442 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1445 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1447 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1448 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1449 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
1452 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1454 LOCATIONS_LOGD("location_manager_start_batch");
1455 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1456 LOCATIONS_NULL_ARG_CHECK(manager);
1457 location_manager_s *handle = (location_manager_s *) manager;
1459 if (LOCATIONS_METHOD_GPS == handle->method) {
1460 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1461 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1463 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1464 return LOCATIONS_ERROR_INCORRECT_METHOD;
1467 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1468 LOCATIONS_LOGD("batch status set : Start");
1470 int ret = location_start_batch(handle->object);
1471 if (ret != LOCATION_ERROR_NONE)
1472 return __convert_error_code(ret);
1474 return LOCATIONS_ERROR_NONE;
1477 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1479 LOCATIONS_LOGD("location_manager_stop_batch");
1480 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1481 LOCATIONS_NULL_ARG_CHECK(manager);
1482 location_manager_s *handle = (location_manager_s *) manager;
1484 if (LOCATIONS_METHOD_GPS == handle->method) {
1485 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1486 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1487 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1491 int ret = location_stop_batch(handle->object);
1492 if (ret != LOCATION_ERROR_NONE)
1493 return __convert_error_code(ret);
1495 return LOCATIONS_ERROR_NONE;
1498 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1500 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1501 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1502 LOCATIONS_NULL_ARG_CHECK(manager);
1503 LOCATIONS_NULL_ARG_CHECK(callback);
1504 location_manager_s *handle = (location_manager_s *) manager;
1505 LocationBatch *batch = NULL;
1507 int ret = location_get_batch(handle->object, &batch);
1508 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1509 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1510 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1511 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1514 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1515 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1519 for (i = 0; i < batch->num_of_location; i++) {
1529 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1530 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1533 location_batch_free(batch);
1535 return LOCATIONS_ERROR_NONE;
1538 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1540 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1541 LOCATIONS_NULL_ARG_CHECK(enabled);
1542 int is_enabled_val = -1;
1543 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1544 if (ret != LOCATION_ERROR_NONE)
1545 return __convert_error_code(ret);
1547 if (is_enabled_val == -1)
1548 return TIZEN_ERROR_PERMISSION_DENIED;
1550 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1551 return LOCATIONS_ERROR_NONE;
1554 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1556 LOCATIONS_LOGD("enable: %d", enable);
1557 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1558 int ret = LOCATION_ERROR_NONE;
1560 ret = location_enable_mock(enable);
1561 return __convert_error_code(ret);
1564 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1565 const double speed, const double direction, const double accuracy)
1567 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1568 LOCATIONS_NULL_ARG_CHECK(manager);
1570 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1571 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1572 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1574 location_manager_s *handle = (location_manager_s *) manager;
1575 int ret = LOCATION_ERROR_NONE;
1577 LocationPosition *pos = NULL;
1578 LocationVelocity *vel = NULL;
1579 LocationAccuracy *acc = NULL;
1581 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1582 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1583 if (ret == LOCATIONS_ERROR_NONE) {
1585 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1587 return __convert_error_code(ret);
1590 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1592 LOCATIONS_LOGE("Failed to create position");
1593 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1595 vel = location_velocity_new(0, speed, direction, 0);
1597 LOCATIONS_LOGE("Failed to create velocity");
1598 location_position_free(pos);
1599 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1602 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1604 LOCATIONS_LOGE("Failed to create accuracy");
1605 location_position_free(pos);
1606 location_velocity_free(vel);
1607 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1610 ret = location_set_mock_location(handle->object, pos, vel, acc);
1612 location_position_free(pos);
1613 location_velocity_free(vel);
1614 location_accuracy_free(acc);
1616 return __convert_error_code(ret);
1619 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1621 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1622 LOCATIONS_NULL_ARG_CHECK(manager);
1624 location_manager_s *handle = (location_manager_s *) manager;
1627 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1628 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1629 if (ret == LOCATIONS_ERROR_NONE) {
1631 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1633 return __convert_error_code(ret);
1636 ret = location_clear_mock_location(handle->object);
1637 return __convert_error_code(ret);