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, pos->timestamp,
88 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, vel->timestamp,
94 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_service_enabled(GObject *self, guint status, gpointer userdata)
124 LOCATIONS_LOGD("Callback function has been invoked. ");
125 location_manager_s *handle = (location_manager_s *) userdata;
126 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
127 ((location_service_state_changed_cb)
128 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
132 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
134 LOCATIONS_LOGD("Callback function has been invoked. ");
135 location_manager_s *handle = (location_manager_s *) userdata;
136 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
137 ((location_service_state_changed_cb)
138 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
141 static int __compare_position(gconstpointer a, gconstpointer b)
143 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
150 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
154 if (bound1->type == bound2->type) {
155 switch (bound1->type) {
156 case LOCATION_BOUNDARY_CIRCLE:
157 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
161 case LOCATION_BOUNDARY_RECT:
162 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
166 case LOCATION_BOUNDARY_POLYGON: {
167 GList *boundary1_next = NULL;
168 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
169 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
173 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
174 if (boundary2_start == NULL) return -1;
176 boundary2_prev = g_list_previous(boundary2_start);
177 boundary2_next = g_list_next(boundary2_start);
179 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
180 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
182 boundary1_next = g_list_next(bound1->polygon.position_list);
183 if (boundary1_next != NULL && boundary2_prev != NULL &&
184 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
185 boundary1_next = g_list_next(boundary1_next);
186 while (boundary1_next) {
187 boundary2_prev = g_list_previous(boundary2_prev);
188 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
189 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
192 boundary1_next = g_list_next(boundary1_next);
195 } else if (boundary1_next != NULL && boundary2_next != NULL &&
196 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
197 boundary1_next = g_list_next(boundary1_next);
198 while (boundary1_next) {
199 boundary2_next = g_list_next(boundary2_next);
200 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
201 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
204 boundary1_next = g_list_next(boundary1_next);
219 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
221 LOCATIONS_LOGD("ENTER >>>");
222 location_manager_s *handle = (location_manager_s *) userdata;
223 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
224 LocationPosition *pos = (LocationPosition *) position;
225 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
226 pos->latitude, pos->longitude,
227 pos->altitude, pos->timestamp,
229 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
232 location_bounds_s *bounds;
233 GList *bounds_list = g_list_first(handle->bounds_list);
234 while (bounds_list) {
235 bounds = (location_bounds_s *)bounds_list->data;
236 if (__boundary_compare(boundary, bounds->boundary) == 0) {
237 LOCATIONS_LOGD("Find zone in boundary");
238 if (bounds->user_cb) {
239 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
243 bounds_list = g_list_next(bounds_list);
245 LOCATIONS_LOGD("EXIT <<<");
248 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
250 LOCATIONS_LOGD("ENTER >>>");
251 location_manager_s *handle = (location_manager_s *) userdata;
252 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
253 LocationPosition *pos = (LocationPosition *) position;
254 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
255 pos->latitude, pos->longitude,
256 pos->altitude, pos->timestamp,
258 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
261 location_bounds_s *bounds;
262 GList *bounds_list = g_list_first(handle->bounds_list);
263 while (bounds_list) {
264 bounds = (location_bounds_s *)bounds_list->data;
265 if (__boundary_compare(boundary, bounds->boundary) == 0) {
266 LOCATIONS_LOGD("Find zone out boundary");
267 if (bounds->user_cb) {
268 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
272 bounds_list = g_list_next(bounds_list);
274 LOCATIONS_LOGD("EXIT <<<");
277 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
279 location_manager_s *handle = (location_manager_s *) user_data;
281 if (handle != NULL && boundary != NULL) {
283 location_bounds_h bounds;
284 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
285 location_coords_s center;
286 center.latitude = boundary->circle.center->latitude;
287 center.longitude = boundary->circle.center->longitude;
288 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
289 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
290 location_coords_s left_top;
291 location_coords_s right_bottom;
292 left_top.latitude = boundary->rect.left_top->latitude;
293 left_top.longitude = boundary->rect.left_top->longitude;
294 right_bottom.latitude = boundary->rect.right_bottom->latitude;
295 right_bottom.longitude = boundary->rect.right_bottom->longitude;
296 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
297 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
298 GList *list = boundary->polygon.position_list;
299 int size = g_list_length(list);
301 location_coords_s coords[size];
304 LocationPosition *pos = list->data;
305 coords[cnt].latitude = pos->latitude;
306 coords[cnt].longitude = pos->longitude;
307 list = g_list_next(list);
310 ret = location_bounds_create_polygon(coords, size, &bounds);
313 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
316 if (ret != LOCATIONS_ERROR_NONE) {
317 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
319 if (handle->is_continue_foreach_bounds) {
320 handle->is_continue_foreach_bounds =
321 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
324 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
326 location_bounds_destroy(bounds);
329 LOCATIONS_LOGD("__foreach_boundary() has been failed");
333 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
335 LOCATIONS_LOGD("method: [%d]", method);
336 location_method_e _method = __convert_location_method_e(method);
337 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
338 if (_setting_changed == NULL) {
339 LOCATIONS_LOGE("Invaild userdata\n");
343 if (_setting_changed[_method].callback != NULL) {
344 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
348 /*/////////////////////////////////////// */
349 /* Location Manager */
350 /*////////////////////////////////////// */
352 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
354 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
355 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
356 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
360 if (method == LOCATIONS_METHOD_GPS) {
361 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
362 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
365 } else if (method == LOCATIONS_METHOD_WPS) {
366 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
367 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
372 LocationMethod _method = __convert_LocationMethod(method);
373 if (_method == LOCATION_METHOD_NONE) {
374 LOCATIONS_LOGE("Not supported method [%d]", method);
375 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
379 set_last_result(LOCATIONS_ERROR_NONE);
380 return location_is_supported_method(_method);
383 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
385 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
387 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
388 LOCATIONS_LOGE("Not supported method [%d]", method);
389 return LOCATIONS_ERROR_INCORRECT_METHOD;
392 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
393 LOCATIONS_NULL_ARG_CHECK(enable);
394 int is_enabled_val = -1;
395 LocationMethod _method = __convert_LocationMethod(method);
396 int ret = location_is_enabled_method(_method, &is_enabled_val);
397 if (ret != LOCATION_ERROR_NONE) {
398 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
399 return LOCATIONS_ERROR_INCORRECT_METHOD;
400 return __convert_error_code(ret);
402 if (is_enabled_val == -1) {
403 return TIZEN_ERROR_PERMISSION_DENIED;
406 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
407 return LOCATIONS_ERROR_NONE;
410 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
412 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
414 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
415 LOCATIONS_LOGE("Not supported method [%d]", method);
416 return LOCATIONS_ERROR_INCORRECT_METHOD;
419 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
422 if (LOCATIONS_METHOD_HYBRID == method) {
423 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
424 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
425 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
427 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
428 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
429 return __convert_error_code(ret);
431 return LOCATIONS_ERROR_NONE;
434 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
435 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
436 return LOCATIONS_ERROR_NOT_SUPPORTED;
438 else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
439 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
440 return LOCATIONS_ERROR_NOT_SUPPORTED;
443 LocationMethod _method = __convert_LocationMethod(method);
445 int ret = location_enable_method(_method, enable);
447 return __convert_error_code(ret);
452 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
454 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
456 if (method == LOCATIONS_METHOD_HYBRID) {
457 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
458 } else if (method == LOCATIONS_METHOD_GPS) {
459 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
460 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
461 return LOCATIONS_ERROR_NOT_SUPPORTED;
463 } else if (method == LOCATIONS_METHOD_WPS) {
464 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
465 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
466 return LOCATIONS_ERROR_NOT_SUPPORTED;
470 LocationMethod _method = __convert_LocationMethod(method);
471 if (_method == LOCATION_METHOD_NONE) {
472 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
473 return LOCATIONS_ERROR_NOT_SUPPORTED;
475 if (!location_is_supported_method(_method)) {
476 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
477 return LOCATIONS_ERROR_NOT_SUPPORTED;
480 /*It is moved here becasue of TCS. */
481 LOCATIONS_NULL_ARG_CHECK(manager);
483 if (location_init() != LOCATION_ERROR_NONE) {
484 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
485 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
488 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
489 if (handle == NULL) {
490 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
491 return LOCATIONS_ERROR_OUT_OF_MEMORY;
494 memset(handle, 0, sizeof(location_manager_s));
496 handle->object = location_new(_method);
497 if (handle->object == NULL) {
498 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
500 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
502 handle->method = method;
503 handle->is_continue_foreach_bounds = TRUE;
504 handle->bounds_list = NULL;
506 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
507 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
509 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
510 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
512 *manager = (location_manager_h) handle;
513 return LOCATIONS_ERROR_NONE;
516 EXPORT_API int location_manager_destroy(location_manager_h manager)
518 LOCATIONS_LOGD("location_manager_destroy");
519 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
520 LOCATIONS_NULL_ARG_CHECK(manager);
521 location_manager_s *handle = (location_manager_s *) manager;
523 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
524 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
525 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
528 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
529 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
530 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
533 int ret = location_free(handle->object);
534 if (ret != LOCATIONS_ERROR_NONE) {
535 return __convert_error_code(ret);
538 return LOCATIONS_ERROR_NONE;
541 EXPORT_API int location_manager_start(location_manager_h manager)
543 LOCATIONS_LOGD("location_manager_start");
544 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
545 LOCATIONS_NULL_ARG_CHECK(manager);
546 location_manager_s *handle = (location_manager_s *) manager;
548 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
549 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
551 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
552 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
553 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
555 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
556 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
558 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
561 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
562 LOCATIONS_LOGI("Satellite update_cb is set");
563 location_set_option(handle->object, "USE_SV");
566 int ret = location_start(handle->object);
567 if (ret != LOCATION_ERROR_NONE) {
568 return __convert_error_code(ret);
570 return LOCATIONS_ERROR_NONE;
573 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
575 LOCATIONS_LOGD("location_manager_request_single_location");
576 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
577 LOCATIONS_NULL_ARG_CHECK(manager);
578 LOCATIONS_NULL_ARG_CHECK(callback);
579 if (timeout <= 0 || timeout > 120) {
580 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
581 return LOCATIONS_ERROR_INVALID_PARAMETER;
584 location_manager_s *handle = (location_manager_s *) manager;
585 int ret = LOCATIONS_ERROR_NONE;
587 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
588 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
590 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
591 if (ret != LOCATIONS_ERROR_NONE) {
595 ret = location_request_single_location(handle->object, timeout);
596 if (ret != LOCATION_ERROR_NONE) {
597 return __convert_error_code(ret);
599 return LOCATIONS_ERROR_NONE;
602 EXPORT_API int location_manager_stop(location_manager_h manager)
604 LOCATIONS_LOGD("location_manager_stop");
605 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
606 LOCATIONS_NULL_ARG_CHECK(manager);
608 location_manager_s *handle = (location_manager_s *) manager;
610 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
611 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
612 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
615 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
616 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
617 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
618 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
621 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
622 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
623 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
627 int ret = location_stop(handle->object);
628 if (ret != LOCATION_ERROR_NONE) {
629 return __convert_error_code(ret);
631 return LOCATIONS_ERROR_NONE;
634 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
636 LOCATIONS_LOGD("location_manager_add_boundary");
637 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
638 LOCATIONS_NULL_ARG_CHECK(manager);
639 LOCATIONS_NULL_ARG_CHECK(bounds);
641 location_manager_s *handle = (location_manager_s *) manager;
642 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
643 int ret = location_boundary_add(handle->object, bound_handle->boundary);
644 if (ret != LOCATION_ERROR_NONE) {
645 return __convert_error_code(ret);
647 bound_handle->is_added = TRUE;
648 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
649 return LOCATIONS_ERROR_NONE;
652 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
654 LOCATIONS_LOGD("location_manager_remove_boundary");
655 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
656 LOCATIONS_NULL_ARG_CHECK(manager);
657 LOCATIONS_NULL_ARG_CHECK(bounds);
659 location_manager_s *handle = (location_manager_s *) manager;
660 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
661 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
662 if (ret != LOCATION_ERROR_NONE) {
663 return __convert_error_code(ret);
665 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
666 bound_handle->is_added = FALSE;
667 return LOCATIONS_ERROR_NONE;
670 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
672 LOCATIONS_LOGD("location_manager_foreach_boundary");
673 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
674 LOCATIONS_NULL_ARG_CHECK(manager);
675 LOCATIONS_NULL_ARG_CHECK(callback);
677 location_manager_s *handle = (location_manager_s *) manager;
678 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
679 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
680 handle->is_continue_foreach_bounds = TRUE;
681 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
682 if (ret != LOCATION_ERROR_NONE) {
683 return __convert_error_code(ret);
685 return LOCATIONS_ERROR_NONE;
688 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
690 LOCATIONS_LOGD("location_manager_get_method %d", method);
691 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
692 LOCATIONS_NULL_ARG_CHECK(manager);
693 LOCATIONS_NULL_ARG_CHECK(method);
695 location_manager_s *handle = (location_manager_s *) manager;
696 LocationMethod _method = LOCATION_METHOD_NONE;
697 g_object_get(handle->object, "method", &_method, NULL);
699 case LOCATION_METHOD_NONE:
700 *method = LOCATIONS_METHOD_NONE;
702 case LOCATION_METHOD_HYBRID:
703 *method = LOCATIONS_METHOD_HYBRID;
705 case LOCATION_METHOD_GPS:
706 *method = LOCATIONS_METHOD_GPS;
708 case LOCATION_METHOD_WPS:
709 *method = LOCATIONS_METHOD_WPS;
712 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
713 LOCATIONS_ERROR_INVALID_PARAMETER, method);
714 return LOCATIONS_ERROR_INVALID_PARAMETER;
717 /**method = handle->method; */
718 return LOCATIONS_ERROR_NONE;
721 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
724 LOCATIONS_LOGD("location_manager_get_position");
725 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
726 LOCATIONS_NULL_ARG_CHECK(manager);
727 LOCATIONS_NULL_ARG_CHECK(altitude);
728 LOCATIONS_NULL_ARG_CHECK(latitude);
729 LOCATIONS_NULL_ARG_CHECK(longitude);
730 LOCATIONS_NULL_ARG_CHECK(timestamp);
732 location_manager_s *handle = (location_manager_s *) manager;
734 LocationPosition *pos = NULL;
735 LocationAccuracy *acc = NULL;
736 ret = location_get_position(handle->object, &pos, &acc);
737 if (ret != LOCATION_ERROR_NONE) {
738 return __convert_error_code(ret);
741 if (pos->status == LOCATION_STATUS_NO_FIX) {
742 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
744 *latitude = pos->latitude;
745 *longitude = pos->longitude;
746 *altitude = pos->altitude;
748 *timestamp = pos->timestamp;
749 location_position_free(pos);
750 location_accuracy_free(acc);
751 return LOCATIONS_ERROR_NONE;
754 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)
756 LOCATIONS_LOGD("location_manager_get_location");
757 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
758 LOCATIONS_NULL_ARG_CHECK(manager);
759 LOCATIONS_NULL_ARG_CHECK(altitude);
760 LOCATIONS_NULL_ARG_CHECK(latitude);
761 LOCATIONS_NULL_ARG_CHECK(longitude);
762 LOCATIONS_NULL_ARG_CHECK(climb);
763 LOCATIONS_NULL_ARG_CHECK(direction);
764 LOCATIONS_NULL_ARG_CHECK(speed);
765 LOCATIONS_NULL_ARG_CHECK(level);
766 LOCATIONS_NULL_ARG_CHECK(horizontal);
767 LOCATIONS_NULL_ARG_CHECK(vertical);
768 LOCATIONS_NULL_ARG_CHECK(timestamp);
770 location_manager_s *handle = (location_manager_s *) manager;
772 LocationPosition *pos = NULL;
773 LocationVelocity *vel = NULL;
774 LocationAccuracy *acc = NULL;
775 ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
776 if (ret != LOCATION_ERROR_NONE) {
777 return __convert_error_code(ret);
780 if (pos->status == LOCATION_STATUS_NO_FIX) {
781 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
783 *latitude = pos->latitude;
784 *longitude = pos->longitude;
785 *altitude = pos->altitude;
787 *timestamp = pos->timestamp;
789 *direction = vel->direction;
792 *horizontal = acc->horizontal_accuracy;
793 *vertical = acc->vertical_accuracy;
795 location_position_free(pos);
796 location_velocity_free(vel);
797 location_accuracy_free(acc);
798 return LOCATIONS_ERROR_NONE;
801 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
803 LOCATIONS_LOGD("location_manager_get_velocity");
804 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
805 LOCATIONS_NULL_ARG_CHECK(manager);
806 LOCATIONS_NULL_ARG_CHECK(climb);
807 LOCATIONS_NULL_ARG_CHECK(direction);
808 LOCATIONS_NULL_ARG_CHECK(speed);
809 LOCATIONS_NULL_ARG_CHECK(timestamp);
811 location_manager_s *handle = (location_manager_s *) manager;
813 LocationVelocity *vel = NULL;
814 LocationAccuracy *acc = NULL;
815 ret = location_get_velocity(handle->object, &vel, &acc);
816 if (ret != LOCATION_ERROR_NONE) {
817 return __convert_error_code(ret);
821 *direction = vel->direction;
823 *timestamp = vel->timestamp;
824 location_velocity_free(vel);
825 location_accuracy_free(acc);
826 return LOCATIONS_ERROR_NONE;
829 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
832 LOCATIONS_LOGD("location_manager_get_accuracy");
833 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
834 LOCATIONS_NULL_ARG_CHECK(manager);
835 LOCATIONS_NULL_ARG_CHECK(level);
836 LOCATIONS_NULL_ARG_CHECK(horizontal);
837 LOCATIONS_NULL_ARG_CHECK(vertical);
838 location_manager_s *handle = (location_manager_s *) manager;
841 LocationPosition *pos = NULL;
842 LocationAccuracy *acc = NULL;
843 ret = location_get_position(handle->object, &pos, &acc);
844 if (ret != LOCATION_ERROR_NONE) {
845 return __convert_error_code(ret);
849 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
853 *horizontal = acc->horizontal_accuracy;
854 *vertical = acc->vertical_accuracy;
855 location_position_free(pos);
856 location_accuracy_free(acc);
857 return LOCATIONS_ERROR_NONE;
860 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
862 LOCATIONS_LOGD("location_manager_get_last_position");
863 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
864 LOCATIONS_NULL_ARG_CHECK(manager);
865 LOCATIONS_NULL_ARG_CHECK(altitude);
866 LOCATIONS_NULL_ARG_CHECK(latitude);
867 LOCATIONS_NULL_ARG_CHECK(longitude);
868 LOCATIONS_NULL_ARG_CHECK(timestamp);
870 location_manager_s *handle = (location_manager_s *) manager;
873 LocationPosition *last_pos = NULL;
874 LocationAccuracy *last_acc = NULL;
875 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
876 if (ret != LOCATION_ERROR_NONE) {
877 return __convert_error_code(ret);
880 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
881 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
883 *latitude = last_pos->latitude;
884 *longitude = last_pos->longitude;
885 *altitude = last_pos->altitude;
887 *timestamp = last_pos->timestamp;
888 location_position_free(last_pos);
889 location_accuracy_free(last_acc);
890 return LOCATIONS_ERROR_NONE;
893 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)
895 LOCATIONS_LOGD("location_manager_get_last_location");
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(climb);
902 LOCATIONS_NULL_ARG_CHECK(direction);
903 LOCATIONS_NULL_ARG_CHECK(speed);
904 LOCATIONS_NULL_ARG_CHECK(level);
905 LOCATIONS_NULL_ARG_CHECK(horizontal);
906 LOCATIONS_NULL_ARG_CHECK(vertical);
907 LOCATIONS_NULL_ARG_CHECK(timestamp);
909 location_manager_s *handle = (location_manager_s *) manager;
912 LocationPosition *last_pos = NULL;
913 LocationVelocity *last_vel = NULL;
914 LocationAccuracy *last_acc = NULL;
915 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
916 if (ret != LOCATION_ERROR_NONE) {
917 return __convert_error_code(ret);
920 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
921 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
923 *latitude = last_pos->latitude;
924 *longitude = last_pos->longitude;
925 *altitude = last_pos->altitude;
927 *timestamp = last_pos->timestamp;
928 *climb = last_vel->climb;
929 *direction = last_vel->direction;
930 *speed = last_vel->speed;
931 *level = last_acc->level;
932 *horizontal = last_acc->horizontal_accuracy;
933 *vertical = last_acc->vertical_accuracy;
934 location_position_free(last_pos);
935 location_velocity_free(last_vel);
936 location_accuracy_free(last_acc);
937 return LOCATIONS_ERROR_NONE;
940 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
942 LOCATIONS_LOGD("location_manager_get_last_velocity");
943 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
944 LOCATIONS_NULL_ARG_CHECK(manager);
945 LOCATIONS_NULL_ARG_CHECK(climb);
946 LOCATIONS_NULL_ARG_CHECK(direction);
947 LOCATIONS_NULL_ARG_CHECK(speed);
948 LOCATIONS_NULL_ARG_CHECK(timestamp);
950 location_manager_s *handle = (location_manager_s *) manager;
953 LocationVelocity *last_vel = NULL;
954 LocationAccuracy *last_acc = NULL;
955 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
956 if (ret != LOCATION_ERROR_NONE) {
957 return __convert_error_code(ret);
960 *climb = last_vel->climb;
961 *direction = last_vel->direction;
962 *speed = last_vel->speed;
963 *timestamp = last_vel->timestamp;
964 location_velocity_free(last_vel);
965 location_accuracy_free(last_acc);
966 return LOCATIONS_ERROR_NONE;
969 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
971 LOCATIONS_LOGD("location_manager_get_last_accuracy");
972 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
973 LOCATIONS_NULL_ARG_CHECK(manager);
974 LOCATIONS_NULL_ARG_CHECK(level);
975 LOCATIONS_NULL_ARG_CHECK(horizontal);
976 LOCATIONS_NULL_ARG_CHECK(vertical);
977 location_manager_s *handle = (location_manager_s *) manager;
980 LocationPosition *last_pos = NULL;
981 LocationAccuracy *last_acc = NULL;
982 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
983 if (ret != LOCATION_ERROR_NONE) {
984 return __convert_error_code(ret);
987 *level = last_acc->level;
988 *horizontal = last_acc->horizontal_accuracy;
989 *vertical = last_acc->vertical_accuracy;
990 location_position_free(last_pos);
991 location_accuracy_free(last_acc);
992 return LOCATIONS_ERROR_NONE;
995 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
997 LOCATIONS_LOGD("location_manager_get_accessibility_state");
998 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
999 LOCATIONS_NULL_ARG_CHECK(state);
1001 int ret = LOCATION_ERROR_NONE;
1002 LocationAccessState auth = LOCATION_ACCESS_NONE;
1003 ret = location_get_accessibility_state(&auth);
1004 if (ret != LOCATION_ERROR_NONE) {
1005 *state = LOCATIONS_ACCESS_STATE_NONE;
1006 return __convert_error_code(ret);
1010 case LOCATION_ACCESS_DENIED:
1011 *state = LOCATIONS_ACCESS_STATE_DENIED;
1013 case LOCATION_ACCESS_ALLOWED:
1014 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1016 case LOCATION_ACCESS_NONE:
1018 *state = LOCATIONS_ACCESS_STATE_NONE;
1022 return LOCATIONS_ERROR_NONE;
1025 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)
1027 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1028 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1029 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1030 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1031 LOCATIONS_NULL_ARG_CHECK(manager);
1032 location_manager_s *handle = (location_manager_s *) manager;
1033 g_object_set(handle->object, "min-interval", interval, NULL);
1034 g_object_set(handle->object, "min-distance", distance, NULL);
1035 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1038 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1040 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1041 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1042 LOCATIONS_NULL_ARG_CHECK(manager);
1043 location_manager_s *handle = (location_manager_s *) manager;
1044 g_object_set(handle->object, "min-interval", 0, NULL);
1045 g_object_set(handle->object, "min-distance", 0, NULL);
1046 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1049 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1051 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1052 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1053 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1054 LOCATIONS_NULL_ARG_CHECK(manager);
1055 location_manager_s *handle = (location_manager_s *) manager;
1056 g_object_set(handle->object, "loc-interval", interval, NULL);
1057 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1060 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1062 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1063 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1064 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1067 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1069 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1070 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1071 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1072 LOCATIONS_NULL_ARG_CHECK(manager);
1073 location_manager_s *handle = (location_manager_s *) manager;
1074 g_object_set(handle->object, "pos-interval", interval, NULL);
1075 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1078 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1080 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1081 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1082 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1085 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1087 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1088 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1089 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1090 LOCATIONS_NULL_ARG_CHECK(manager);
1091 location_manager_s *handle = (location_manager_s *) manager;
1092 g_object_set(handle->object, "vel-interval", interval, NULL);
1093 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1096 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1098 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1099 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1100 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1103 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1106 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1107 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1108 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1111 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1113 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1114 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1115 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1118 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1120 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1121 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1122 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1125 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1127 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1128 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1129 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1132 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1134 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1135 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1136 LOCATIONS_NULL_ARG_CHECK(callback);
1138 LocationMethod _method = __convert_LocationMethod(method);
1139 int ret = LOCATION_ERROR_NONE;
1141 if (_method == LOCATION_METHOD_NONE) {
1142 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1145 g_location_setting[_method].callback = callback;
1146 g_location_setting[_method].user_data = user_data;
1148 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1149 if (ret != LOCATION_ERROR_NONE) {
1150 return __convert_error_code(ret);
1153 return LOCATIONS_ERROR_NONE;
1156 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1158 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1159 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1160 LocationMethod _method = __convert_LocationMethod(method);
1161 int ret = LOCATION_ERROR_NONE;
1163 if (_method == LOCATION_METHOD_NONE) {
1164 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1167 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1168 if (ret != LOCATION_ERROR_NONE) {
1169 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1170 ret = __convert_error_code(ret);
1173 g_location_setting[method].callback = NULL;
1174 g_location_setting[method].user_data = NULL;
1176 return LOCATIONS_ERROR_NONE;
1179 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1181 LOCATIONS_LOGD("location_manager_get_distance");
1182 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1183 LOCATIONS_NULL_ARG_CHECK(distance);
1184 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1185 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1186 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1187 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1189 int ret = LOCATION_ERROR_NONE;
1192 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1193 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1195 ret = location_get_distance(start, end, &u_distance);
1196 if (ret != LOCATION_ERROR_NONE) {
1197 return __convert_error_code(ret);
1200 *distance = (double)u_distance;
1202 return LOCATIONS_ERROR_NONE;
1205 /*/////////////////////////////////////// */
1206 /* GPS Status & Satellites */
1207 /*////////////////////////////////////// */
1209 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1211 LOCATIONS_LOGD("gps_status_get_nmea");
1212 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1213 LOCATIONS_NULL_ARG_CHECK(manager);
1214 LOCATIONS_NULL_ARG_CHECK(nmea);
1215 location_manager_s *handle = (location_manager_s *) manager;
1218 int ret = location_get_nmea(handle->object, &nmea_data);
1219 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1220 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1221 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1222 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1225 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1226 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1229 *nmea = g_strdup(nmea_data);
1232 return LOCATIONS_ERROR_NONE;
1235 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1237 LOCATIONS_LOGD("gps_status_get_satellite");
1238 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1239 LOCATIONS_NULL_ARG_CHECK(manager);
1240 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1241 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1242 LOCATIONS_NULL_ARG_CHECK(timestamp);
1243 location_manager_s *handle = (location_manager_s *) manager;
1244 LocationSatellite *sat = NULL;
1245 int ret = location_get_satellite(handle->object, &sat);
1246 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1247 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1248 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1249 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1252 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1253 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1256 *num_of_active = sat->num_of_sat_used;
1257 *num_of_inview = sat->num_of_sat_inview;
1258 *timestamp = sat->timestamp;
1259 location_satellite_free(sat);
1261 return LOCATIONS_ERROR_NONE;
1264 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1266 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1267 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1268 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1269 LOCATIONS_NULL_ARG_CHECK(manager);
1270 LOCATIONS_NULL_ARG_CHECK(callback);
1272 location_manager_s *handle = (location_manager_s *) manager;
1273 location_set_option(handle->object, "USE_SV");
1274 g_object_set(handle->object, "sat-interval", interval, NULL);
1275 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1278 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1280 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1281 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1282 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1285 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1287 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1288 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1289 LOCATIONS_NULL_ARG_CHECK(manager);
1290 LOCATIONS_NULL_ARG_CHECK(callback);
1292 location_manager_s *handle = (location_manager_s *) manager;
1293 LocationSatellite *sat = NULL;
1294 int ret = location_get_satellite(handle->object, &sat);
1295 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1296 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1297 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1298 return LOCATIONS_ERROR_INCORRECT_METHOD;
1299 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1300 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1301 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1304 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1305 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1309 for (i = 0; i < sat->num_of_sat_inview; i++) {
1315 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1316 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1319 location_satellite_free(sat);
1321 return LOCATIONS_ERROR_NONE;
1324 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1326 LOCATIONS_LOGD("gps_status_get_last_satellite");
1327 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1328 LOCATIONS_NULL_ARG_CHECK(manager);
1329 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1330 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1331 LOCATIONS_NULL_ARG_CHECK(timestamp);
1333 location_manager_s *handle = (location_manager_s *) manager;
1334 int ret = LOCATION_ERROR_NONE;
1335 LocationSatellite *last_sat = NULL;
1336 ret = location_get_last_satellite(handle->object, &last_sat);
1337 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1338 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1339 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1340 return LOCATIONS_ERROR_INCORRECT_METHOD;
1341 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1342 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1343 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1346 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1347 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1350 *num_of_active = last_sat->num_of_sat_used;
1351 *num_of_inview = last_sat->num_of_sat_inview;
1352 *timestamp = last_sat->timestamp;
1353 location_satellite_free(last_sat);
1354 return LOCATIONS_ERROR_NONE;
1357 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1359 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1360 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1361 LOCATIONS_NULL_ARG_CHECK(manager);
1362 LOCATIONS_NULL_ARG_CHECK(callback);
1363 location_manager_s *handle = (location_manager_s *) manager;
1365 LocationSatellite *last_sat = NULL;
1366 ret = location_get_last_satellite(handle->object, &last_sat);
1367 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1368 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1369 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1370 return LOCATIONS_ERROR_INCORRECT_METHOD;
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;
1378 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1384 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1385 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1389 location_satellite_free(last_sat);
1390 return LOCATIONS_ERROR_NONE;