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 *) data;
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,
129 handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
133 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
135 LOCATIONS_LOGD("Callback function has been invoked. ");
136 location_manager_s *handle = (location_manager_s *) userdata;
137 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])
138 ((location_service_state_changed_cb)
139 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED,
140 handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
143 static int __compare_position(gconstpointer a, gconstpointer b)
145 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
152 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
156 if (bound1->type == bound2->type) {
157 switch (bound1->type) {
158 case LOCATION_BOUNDARY_CIRCLE:
159 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) {
163 case LOCATION_BOUNDARY_RECT:
164 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) {
168 case LOCATION_BOUNDARY_POLYGON: {
169 GList *boundary1_next = NULL;
170 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
171 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) {
175 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
176 if (boundary2_start == NULL) return -1;
178 boundary2_prev = g_list_previous(boundary2_start);
179 boundary2_next = g_list_next(boundary2_start);
181 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
182 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
184 boundary1_next = g_list_next(bound1->polygon.position_list);
185 if (boundary1_next != NULL && boundary2_prev != NULL &&
186 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
187 boundary1_next = g_list_next(boundary1_next);
188 while (boundary1_next) {
189 boundary2_prev = g_list_previous(boundary2_prev);
190 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
191 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
194 boundary1_next = g_list_next(boundary1_next);
197 } else if (boundary1_next != NULL && boundary2_next != NULL &&
198 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
199 boundary1_next = g_list_next(boundary1_next);
200 while (boundary1_next) {
201 boundary2_next = g_list_next(boundary2_next);
202 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
203 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
206 boundary1_next = g_list_next(boundary1_next);
221 static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
223 LOCATIONS_LOGD("ENTER >>>");
224 location_manager_s *handle = (location_manager_s *) userdata;
225 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
226 LocationPosition *pos = (LocationPosition *) position;
227 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_IN,
228 pos->latitude, pos->longitude,
229 pos->altitude, pos->timestamp,
231 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
234 location_bounds_s *bounds;
235 GList *bounds_list = g_list_first(handle->bounds_list);
236 while (bounds_list) {
237 bounds = (location_bounds_s *)bounds_list->data;
238 if (__boundary_compare(boundary, bounds->boundary) == 0) {
239 LOCATIONS_LOGD("Find zone in boundary");
240 if (bounds->user_cb) {
241 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
245 bounds_list = g_list_next(bounds_list);
247 LOCATIONS_LOGD("EXIT <<<");
250 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
252 LOCATIONS_LOGD("ENTER >>>");
253 location_manager_s *handle = (location_manager_s *) userdata;
254 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
255 LocationPosition *pos = (LocationPosition *) position;
256 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
257 pos->latitude, pos->longitude,
258 pos->altitude, pos->timestamp,
260 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
263 location_bounds_s *bounds;
264 GList *bounds_list = g_list_first(handle->bounds_list);
265 while (bounds_list) {
266 bounds = (location_bounds_s *)bounds_list->data;
267 if (__boundary_compare(boundary, bounds->boundary) == 0) {
268 LOCATIONS_LOGD("Find zone out boundary");
269 if (bounds->user_cb) {
270 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
274 bounds_list = g_list_next(bounds_list);
276 LOCATIONS_LOGD("EXIT <<<");
279 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
281 location_manager_s *handle = (location_manager_s *) user_data;
283 if (handle != NULL && boundary != NULL) {
285 location_bounds_h bounds;
286 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
287 location_coords_s center;
288 center.latitude = boundary->circle.center->latitude;
289 center.longitude = boundary->circle.center->longitude;
290 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
291 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
292 location_coords_s left_top;
293 location_coords_s right_bottom;
294 left_top.latitude = boundary->rect.left_top->latitude;
295 left_top.longitude = boundary->rect.left_top->longitude;
296 right_bottom.latitude = boundary->rect.right_bottom->latitude;
297 right_bottom.longitude = boundary->rect.right_bottom->longitude;
298 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
299 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
300 GList *list = boundary->polygon.position_list;
301 int size = g_list_length(list);
303 location_coords_s coords[size];
306 LocationPosition *pos = list->data;
307 coords[cnt].latitude = pos->latitude;
308 coords[cnt].longitude = pos->longitude;
309 list = g_list_next(list);
312 ret = location_bounds_create_polygon(coords, size, &bounds);
315 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
318 if (ret != LOCATIONS_ERROR_NONE) {
319 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
321 if (handle->is_continue_foreach_bounds) {
322 handle->is_continue_foreach_bounds =
323 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
326 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
328 location_bounds_destroy(bounds);
331 LOCATIONS_LOGD("__foreach_boundary() has been failed");
335 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
337 LOCATIONS_LOGD("__setting_changed_cb method [%d]", method);
338 location_method_e _method = __convert_location_method_e(method);
339 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
340 if (_setting_changed == NULL) {
341 LOCATIONS_LOGE("Invaild userdata\n");
345 if (_setting_changed[_method].callback != NULL) {
346 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
350 /*/////////////////////////////////////// */
351 /* Location Manager */
352 /*////////////////////////////////////// */
354 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
356 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
357 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
358 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
362 LocationMethod _method = __convert_LocationMethod(method);
363 if (_method == LOCATION_METHOD_NONE) {
364 LOCATIONS_LOGE("Not supported method [%d]", method);
365 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
369 set_last_result(LOCATIONS_ERROR_NONE);
370 return location_is_supported_method(_method);
373 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
375 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
377 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
378 LOCATIONS_LOGE("Not supported method [%d]", method);
379 return LOCATIONS_ERROR_INCORRECT_METHOD;
382 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
383 LOCATIONS_NULL_ARG_CHECK(enable);
384 int is_enabled_val = -1;
385 LocationMethod _method = __convert_LocationMethod(method);
386 int ret = location_is_enabled_method(_method, &is_enabled_val);
387 if (ret != LOCATION_ERROR_NONE) {
388 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
389 return LOCATIONS_ERROR_INCORRECT_METHOD;
390 return __convert_error_code(ret);
392 if (is_enabled_val == -1)
393 return TIZEN_ERROR_PERMISSION_DENIED;
395 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
396 return LOCATIONS_ERROR_NONE;
399 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
401 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
403 if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) {
404 LOCATIONS_LOGE("Not supported method [%d]", method);
405 return LOCATIONS_ERROR_INCORRECT_METHOD;
408 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
410 LocationMethod _method = __convert_LocationMethod(method);
412 int ret = location_enable_method(_method, enable);
413 return __convert_error_code(ret);
417 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
419 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
420 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
422 LocationMethod _method = __convert_LocationMethod(method);
423 if (_method == LOCATION_METHOD_NONE) {
424 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
425 return LOCATIONS_ERROR_NOT_SUPPORTED;
427 if (!location_is_supported_method(_method)) {
428 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
429 return LOCATIONS_ERROR_NOT_SUPPORTED;
432 /*It is moved here becasue of TCS. */
433 LOCATIONS_NULL_ARG_CHECK(manager);
435 if (location_init() != LOCATION_ERROR_NONE) {
436 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
437 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
440 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
441 if (handle == NULL) {
442 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
443 return LOCATIONS_ERROR_OUT_OF_MEMORY;
446 memset(handle, 0, sizeof(location_manager_s));
448 handle->object = location_new(_method);
449 if (handle->object == NULL) {
450 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
452 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
454 handle->method = method;
455 handle->is_continue_foreach_bounds = TRUE;
456 handle->bounds_list = NULL;
458 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
459 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
461 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
462 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
464 *manager = (location_manager_h) handle;
465 return LOCATIONS_ERROR_NONE;
468 EXPORT_API int location_manager_destroy(location_manager_h manager)
470 LOCATIONS_LOGD("location_manager_destroy");
471 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
472 LOCATIONS_NULL_ARG_CHECK(manager);
473 location_manager_s *handle = (location_manager_s *) manager;
475 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
476 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
477 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
480 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
481 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
482 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
485 int ret = location_free(handle->object);
486 if (ret != LOCATIONS_ERROR_NONE) {
487 return __convert_error_code(ret);
490 return LOCATIONS_ERROR_NONE;
493 EXPORT_API int location_manager_start(location_manager_h manager)
495 LOCATIONS_LOGD("location_manager_start");
496 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
497 LOCATIONS_NULL_ARG_CHECK(manager);
498 location_manager_s *handle = (location_manager_s *) manager;
500 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
501 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
503 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
504 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
505 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
507 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
508 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
510 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
513 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
514 LOCATIONS_LOGI("Satellite update_cb is set");
515 location_set_option(handle->object, "USE_SV");
518 int ret = location_start(handle->object);
519 if (ret != LOCATION_ERROR_NONE) {
520 return __convert_error_code(ret);
522 return LOCATIONS_ERROR_NONE;
525 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
527 LOCATIONS_LOGD("location_manager_request_single_location");
528 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
529 LOCATIONS_NULL_ARG_CHECK(manager);
530 LOCATIONS_NULL_ARG_CHECK(callback);
531 if (timeout <= 0 || timeout > 120) {
532 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
533 return LOCATIONS_ERROR_INVALID_PARAMETER;
536 location_manager_s *handle = (location_manager_s *) manager;
537 int ret = LOCATIONS_ERROR_NONE;
539 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
540 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
542 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
543 if (ret != LOCATIONS_ERROR_NONE) {
547 ret = location_request_single_location(handle->object, timeout);
548 if (ret != LOCATION_ERROR_NONE) {
549 return __convert_error_code(ret);
551 return LOCATIONS_ERROR_NONE;
554 EXPORT_API int location_manager_stop(location_manager_h manager)
556 LOCATIONS_LOGD("location_manager_stop");
557 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
558 LOCATIONS_NULL_ARG_CHECK(manager);
560 location_manager_s *handle = (location_manager_s *) manager;
562 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
563 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
564 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
567 if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) {
568 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
569 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
570 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
573 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
574 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
575 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
579 int ret = location_stop(handle->object);
580 if (ret != LOCATION_ERROR_NONE) {
581 return __convert_error_code(ret);
583 return LOCATIONS_ERROR_NONE;
586 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
588 LOCATIONS_LOGD("location_manager_add_boundary");
589 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
590 LOCATIONS_NULL_ARG_CHECK(manager);
591 LOCATIONS_NULL_ARG_CHECK(bounds);
593 location_manager_s *handle = (location_manager_s *) manager;
594 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
595 int ret = location_boundary_add(handle->object, bound_handle->boundary);
596 if (ret != LOCATION_ERROR_NONE) {
597 return __convert_error_code(ret);
599 bound_handle->is_added = TRUE;
600 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
601 return LOCATIONS_ERROR_NONE;
604 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
606 LOCATIONS_LOGD("location_manager_remove_boundary");
607 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
608 LOCATIONS_NULL_ARG_CHECK(manager);
609 LOCATIONS_NULL_ARG_CHECK(bounds);
611 location_manager_s *handle = (location_manager_s *) manager;
612 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
613 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
614 if (ret != LOCATION_ERROR_NONE) {
615 return __convert_error_code(ret);
617 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
618 bound_handle->is_added = FALSE;
619 return LOCATIONS_ERROR_NONE;
622 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
624 LOCATIONS_LOGD("location_manager_foreach_boundary");
625 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
626 LOCATIONS_NULL_ARG_CHECK(manager);
627 LOCATIONS_NULL_ARG_CHECK(callback);
629 location_manager_s *handle = (location_manager_s *) manager;
630 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
631 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
632 handle->is_continue_foreach_bounds = TRUE;
633 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
634 if (ret != LOCATION_ERROR_NONE) {
635 return __convert_error_code(ret);
637 return LOCATIONS_ERROR_NONE;
640 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
642 LOCATIONS_LOGD("location_manager_get_method %d", method);
643 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
644 LOCATIONS_NULL_ARG_CHECK(manager);
645 LOCATIONS_NULL_ARG_CHECK(method);
647 location_manager_s *handle = (location_manager_s *) manager;
648 LocationMethod _method = LOCATION_METHOD_NONE;
649 g_object_get(handle->object, "method", &_method, NULL);
651 case LOCATION_METHOD_NONE:
652 *method = LOCATIONS_METHOD_NONE;
654 case LOCATION_METHOD_HYBRID:
655 *method = LOCATIONS_METHOD_HYBRID;
657 case LOCATION_METHOD_GPS:
658 *method = LOCATIONS_METHOD_GPS;
660 case LOCATION_METHOD_WPS:
661 *method = LOCATIONS_METHOD_WPS;
664 LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ",
665 LOCATIONS_ERROR_INVALID_PARAMETER, method);
666 return LOCATIONS_ERROR_INVALID_PARAMETER;
669 /**method = handle->method; */
670 return LOCATIONS_ERROR_NONE;
673 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
676 LOCATIONS_LOGD("location_manager_get_position");
677 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
678 LOCATIONS_NULL_ARG_CHECK(manager);
679 LOCATIONS_NULL_ARG_CHECK(altitude);
680 LOCATIONS_NULL_ARG_CHECK(latitude);
681 LOCATIONS_NULL_ARG_CHECK(longitude);
682 LOCATIONS_NULL_ARG_CHECK(timestamp);
684 location_manager_s *handle = (location_manager_s *) manager;
686 LocationPosition *pos = NULL;
687 LocationAccuracy *acc = NULL;
688 ret = location_get_position(handle->object, &pos, &acc);
689 if (ret != LOCATION_ERROR_NONE) {
690 return __convert_error_code(ret);
693 if (pos->status == LOCATION_STATUS_NO_FIX) {
694 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
696 *latitude = pos->latitude;
697 *longitude = pos->longitude;
698 *altitude = pos->altitude;
700 *timestamp = pos->timestamp;
701 location_position_free(pos);
702 location_accuracy_free(acc);
703 return LOCATIONS_ERROR_NONE;
706 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)
708 LOCATIONS_LOGD("location_manager_get_location");
709 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
710 LOCATIONS_NULL_ARG_CHECK(manager);
711 LOCATIONS_NULL_ARG_CHECK(altitude);
712 LOCATIONS_NULL_ARG_CHECK(latitude);
713 LOCATIONS_NULL_ARG_CHECK(longitude);
714 LOCATIONS_NULL_ARG_CHECK(climb);
715 LOCATIONS_NULL_ARG_CHECK(direction);
716 LOCATIONS_NULL_ARG_CHECK(speed);
717 LOCATIONS_NULL_ARG_CHECK(level);
718 LOCATIONS_NULL_ARG_CHECK(horizontal);
719 LOCATIONS_NULL_ARG_CHECK(vertical);
720 LOCATIONS_NULL_ARG_CHECK(timestamp);
722 location_manager_s *handle = (location_manager_s *) manager;
724 LocationPosition *pos = NULL;
725 LocationVelocity *vel = NULL;
726 LocationAccuracy *acc = NULL;
727 ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
728 if (ret != LOCATION_ERROR_NONE) {
729 return __convert_error_code(ret);
732 if (pos->status == LOCATION_STATUS_NO_FIX) {
733 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
735 *latitude = pos->latitude;
736 *longitude = pos->longitude;
737 *altitude = pos->altitude;
739 *timestamp = pos->timestamp;
741 *direction = vel->direction;
744 *horizontal = acc->horizontal_accuracy;
745 *vertical = acc->vertical_accuracy;
747 location_position_free(pos);
748 location_velocity_free(vel);
749 location_accuracy_free(acc);
750 return LOCATIONS_ERROR_NONE;
753 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
755 LOCATIONS_LOGD("location_manager_get_velocity");
756 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
757 LOCATIONS_NULL_ARG_CHECK(manager);
758 LOCATIONS_NULL_ARG_CHECK(climb);
759 LOCATIONS_NULL_ARG_CHECK(direction);
760 LOCATIONS_NULL_ARG_CHECK(speed);
761 LOCATIONS_NULL_ARG_CHECK(timestamp);
763 location_manager_s *handle = (location_manager_s *) manager;
765 LocationVelocity *vel = NULL;
766 LocationAccuracy *acc = NULL;
767 ret = location_get_velocity(handle->object, &vel, &acc);
768 if (ret != LOCATION_ERROR_NONE) {
769 return __convert_error_code(ret);
773 *direction = vel->direction;
775 *timestamp = vel->timestamp;
776 location_velocity_free(vel);
777 location_accuracy_free(acc);
778 return LOCATIONS_ERROR_NONE;
781 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
784 LOCATIONS_LOGD("location_manager_get_accuracy");
785 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
786 LOCATIONS_NULL_ARG_CHECK(manager);
787 LOCATIONS_NULL_ARG_CHECK(level);
788 LOCATIONS_NULL_ARG_CHECK(horizontal);
789 LOCATIONS_NULL_ARG_CHECK(vertical);
790 location_manager_s *handle = (location_manager_s *) manager;
793 LocationPosition *pos = NULL;
794 LocationAccuracy *acc = NULL;
795 ret = location_get_position(handle->object, &pos, &acc);
796 if (ret != LOCATION_ERROR_NONE) {
797 return __convert_error_code(ret);
801 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
805 *horizontal = acc->horizontal_accuracy;
806 *vertical = acc->vertical_accuracy;
807 location_position_free(pos);
808 location_accuracy_free(acc);
809 return LOCATIONS_ERROR_NONE;
812 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
815 LOCATIONS_LOGD("location_manager_get_last_position");
816 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
817 LOCATIONS_NULL_ARG_CHECK(manager);
818 LOCATIONS_NULL_ARG_CHECK(altitude);
819 LOCATIONS_NULL_ARG_CHECK(latitude);
820 LOCATIONS_NULL_ARG_CHECK(longitude);
821 LOCATIONS_NULL_ARG_CHECK(timestamp);
823 location_manager_s *handle = (location_manager_s *) manager;
826 LocationPosition *last_pos = NULL;
827 LocationAccuracy *last_acc = NULL;
828 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
829 if (ret != LOCATION_ERROR_NONE) {
830 return __convert_error_code(ret);
833 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
834 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
836 *latitude = last_pos->latitude;
837 *longitude = last_pos->longitude;
838 *altitude = last_pos->altitude;
840 *timestamp = last_pos->timestamp;
841 location_position_free(last_pos);
842 location_accuracy_free(last_acc);
843 return LOCATIONS_ERROR_NONE;
846 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)
848 LOCATIONS_LOGD("location_manager_get_last_location");
849 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
850 LOCATIONS_NULL_ARG_CHECK(manager);
851 LOCATIONS_NULL_ARG_CHECK(altitude);
852 LOCATIONS_NULL_ARG_CHECK(latitude);
853 LOCATIONS_NULL_ARG_CHECK(longitude);
854 LOCATIONS_NULL_ARG_CHECK(climb);
855 LOCATIONS_NULL_ARG_CHECK(direction);
856 LOCATIONS_NULL_ARG_CHECK(speed);
857 LOCATIONS_NULL_ARG_CHECK(level);
858 LOCATIONS_NULL_ARG_CHECK(horizontal);
859 LOCATIONS_NULL_ARG_CHECK(vertical);
860 LOCATIONS_NULL_ARG_CHECK(timestamp);
862 location_manager_s *handle = (location_manager_s *) manager;
865 LocationPosition *last_pos = NULL;
866 LocationVelocity *last_vel = NULL;
867 LocationAccuracy *last_acc = NULL;
868 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
869 if (ret != LOCATION_ERROR_NONE) {
870 return __convert_error_code(ret);
873 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
874 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
876 *latitude = last_pos->latitude;
877 *longitude = last_pos->longitude;
878 *altitude = last_pos->altitude;
880 *timestamp = last_pos->timestamp;
881 *climb = last_vel->climb;
882 *direction = last_vel->direction;
883 *speed = last_vel->speed;
884 *level = last_acc->level;
885 *horizontal = last_acc->horizontal_accuracy;
886 *vertical = last_acc->vertical_accuracy;
887 location_position_free(last_pos);
888 location_velocity_free(last_vel);
889 location_accuracy_free(last_acc);
890 return LOCATIONS_ERROR_NONE;
893 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
895 LOCATIONS_LOGD("location_manager_get_last_velocity");
896 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
897 LOCATIONS_NULL_ARG_CHECK(manager);
898 LOCATIONS_NULL_ARG_CHECK(climb);
899 LOCATIONS_NULL_ARG_CHECK(direction);
900 LOCATIONS_NULL_ARG_CHECK(speed);
901 LOCATIONS_NULL_ARG_CHECK(timestamp);
903 location_manager_s *handle = (location_manager_s *) manager;
906 LocationVelocity *last_vel = NULL;
907 LocationAccuracy *last_acc = NULL;
908 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
909 if (ret != LOCATION_ERROR_NONE) {
910 return __convert_error_code(ret);
913 *climb = last_vel->climb;
914 *direction = last_vel->direction;
915 *speed = last_vel->speed;
916 *timestamp = last_vel->timestamp;
917 location_velocity_free(last_vel);
918 location_accuracy_free(last_acc);
919 return LOCATIONS_ERROR_NONE;
922 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
925 LOCATIONS_LOGD("location_manager_get_last_accuracy");
926 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
927 LOCATIONS_NULL_ARG_CHECK(manager);
928 LOCATIONS_NULL_ARG_CHECK(level);
929 LOCATIONS_NULL_ARG_CHECK(horizontal);
930 LOCATIONS_NULL_ARG_CHECK(vertical);
931 location_manager_s *handle = (location_manager_s *) manager;
934 LocationPosition *last_pos = NULL;
935 LocationAccuracy *last_acc = NULL;
936 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
937 if (ret != LOCATION_ERROR_NONE) {
938 return __convert_error_code(ret);
941 *level = last_acc->level;
942 *horizontal = last_acc->horizontal_accuracy;
943 *vertical = last_acc->vertical_accuracy;
944 location_position_free(last_pos);
945 location_accuracy_free(last_acc);
946 return LOCATIONS_ERROR_NONE;
949 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
951 LOCATIONS_LOGD("location_manager_get_accessibility_state");
952 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
953 LOCATIONS_NULL_ARG_CHECK(state);
955 int ret = LOCATION_ERROR_NONE;
956 LocationAccessState auth = LOCATION_ACCESS_NONE;
957 ret = location_get_accessibility_state(&auth);
958 if (ret != LOCATION_ERROR_NONE) {
959 *state = LOCATIONS_ACCESS_STATE_NONE;
960 return __convert_error_code(ret);
964 case LOCATION_ACCESS_DENIED:
965 *state = LOCATIONS_ACCESS_STATE_DENIED;
967 case LOCATION_ACCESS_ALLOWED:
968 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
970 case LOCATION_ACCESS_NONE:
972 *state = LOCATIONS_ACCESS_STATE_NONE;
976 return LOCATIONS_ERROR_NONE;
979 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)
981 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
982 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
983 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
984 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
985 LOCATIONS_NULL_ARG_CHECK(manager);
986 location_manager_s *handle = (location_manager_s *) manager;
987 g_object_set(handle->object, "min-interval", interval, NULL);
988 g_object_set(handle->object, "min-distance", distance, NULL);
989 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
992 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
994 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
995 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
996 LOCATIONS_NULL_ARG_CHECK(manager);
997 location_manager_s *handle = (location_manager_s *) manager;
998 g_object_set(handle->object, "min-interval", 0, NULL);
999 g_object_set(handle->object, "min-distance", 0, NULL);
1000 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1003 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1005 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1006 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1007 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1008 LOCATIONS_NULL_ARG_CHECK(manager);
1009 location_manager_s *handle = (location_manager_s *) manager;
1010 g_object_set(handle->object, "loc-interval", interval, NULL);
1011 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1014 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1016 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1017 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1018 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1021 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1023 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1024 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1025 LOCATIONS_CHECK_CONDITION(interval >= 1
1026 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1027 LOCATIONS_NULL_ARG_CHECK(manager);
1028 location_manager_s *handle = (location_manager_s *) manager;
1029 g_object_set(handle->object, "pos-interval", interval, NULL);
1030 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1033 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1035 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1036 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1037 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1040 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1042 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1043 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1044 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1045 LOCATIONS_NULL_ARG_CHECK(manager);
1046 location_manager_s *handle = (location_manager_s *) manager;
1047 g_object_set(handle->object, "vel-interval", interval, NULL);
1048 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1051 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1053 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1054 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1055 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1058 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1061 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1062 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1063 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1066 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1068 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1069 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1070 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1073 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1075 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1076 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1077 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1080 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1082 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1083 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1084 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1087 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1089 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1090 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1091 LOCATIONS_NULL_ARG_CHECK(callback);
1093 LocationMethod _method = __convert_LocationMethod(method);
1094 int ret = LOCATION_ERROR_NONE;
1096 if (_method == LOCATION_METHOD_NONE) {
1097 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1100 g_location_setting[_method].callback = callback;
1101 g_location_setting[_method].user_data = user_data;
1103 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1104 if (ret != LOCATION_ERROR_NONE) {
1105 return __convert_error_code(ret);
1108 return LOCATIONS_ERROR_NONE;
1111 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1113 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1114 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1115 LocationMethod _method = __convert_LocationMethod(method);
1116 int ret = LOCATION_ERROR_NONE;
1118 if (_method == LOCATION_METHOD_NONE) {
1119 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1122 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1123 if (ret != LOCATION_ERROR_NONE) {
1124 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1125 ret = __convert_error_code(ret);
1128 g_location_setting[method].callback = NULL;
1129 g_location_setting[method].user_data = NULL;
1131 return LOCATIONS_ERROR_NONE;
1134 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1136 LOCATIONS_LOGD("location_manager_get_distance");
1137 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1138 LOCATIONS_NULL_ARG_CHECK(distance);
1139 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1140 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1141 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1142 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1144 int ret = LOCATION_ERROR_NONE;
1147 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1148 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1150 ret = location_get_distance(start, end, &u_distance);
1151 if (ret != LOCATION_ERROR_NONE) {
1152 return __convert_error_code(ret);
1155 *distance = (double)u_distance;
1157 return LOCATIONS_ERROR_NONE;
1160 /*/////////////////////////////////////// */
1161 /* GPS Status & Satellites */
1162 /*////////////////////////////////////// */
1164 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1166 LOCATIONS_LOGD("gps_status_get_nmea");
1167 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1168 LOCATIONS_NULL_ARG_CHECK(manager);
1169 LOCATIONS_NULL_ARG_CHECK(nmea);
1170 location_manager_s *handle = (location_manager_s *) manager;
1173 int ret = location_get_nmea(handle->object, &nmea_data);
1174 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1175 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1176 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1177 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1180 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ",
1181 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1182 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1185 *nmea = g_strdup(nmea_data);
1188 return LOCATIONS_ERROR_NONE;
1191 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1193 LOCATIONS_LOGD("gps_status_get_satellite");
1194 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1195 LOCATIONS_NULL_ARG_CHECK(manager);
1196 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1197 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1198 LOCATIONS_NULL_ARG_CHECK(timestamp);
1199 location_manager_s *handle = (location_manager_s *) manager;
1200 LocationSatellite *sat = NULL;
1201 int ret = location_get_satellite(handle->object, &sat);
1202 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1203 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1204 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1205 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1208 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
1209 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1210 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1213 *num_of_active = sat->num_of_sat_used;
1214 *num_of_inview = sat->num_of_sat_inview;
1215 *timestamp = sat->timestamp;
1216 location_satellite_free(sat);
1218 return LOCATIONS_ERROR_NONE;
1221 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1223 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1224 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1225 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1226 LOCATIONS_NULL_ARG_CHECK(manager);
1227 LOCATIONS_NULL_ARG_CHECK(callback);
1229 location_manager_s *handle = (location_manager_s *) manager;
1230 location_set_option(handle->object, "USE_SV");
1231 g_object_set(handle->object, "sat-interval", interval, NULL);
1232 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1235 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1237 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1238 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1239 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1242 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1244 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1245 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1246 LOCATIONS_NULL_ARG_CHECK(manager);
1247 LOCATIONS_NULL_ARG_CHECK(callback);
1249 location_manager_s *handle = (location_manager_s *) manager;
1250 LocationSatellite *sat = NULL;
1251 int ret = location_get_satellite(handle->object, &sat);
1252 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1253 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1254 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
1255 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1256 return LOCATIONS_ERROR_INCORRECT_METHOD;
1257 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1258 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1259 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1262 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
1263 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1264 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1268 for (i = 0; i < sat->num_of_sat_inview; i++) {
1274 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1275 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1278 location_satellite_free(sat);
1280 return LOCATIONS_ERROR_NONE;
1283 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1285 LOCATIONS_LOGD("gps_status_get_last_satellite");
1286 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1287 LOCATIONS_NULL_ARG_CHECK(manager);
1288 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1289 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1290 LOCATIONS_NULL_ARG_CHECK(timestamp);
1292 location_manager_s *handle = (location_manager_s *) manager;
1293 int ret = LOCATION_ERROR_NONE;
1294 LocationSatellite *last_sat = NULL;
1295 ret = location_get_last_satellite(handle->object, &last_sat);
1296 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1297 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1298 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
1299 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1300 return LOCATIONS_ERROR_INCORRECT_METHOD;
1301 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1302 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1303 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1306 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
1307 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1308 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1311 *num_of_active = last_sat->num_of_sat_used;
1312 *num_of_inview = last_sat->num_of_sat_inview;
1313 *timestamp = last_sat->timestamp;
1314 location_satellite_free(last_sat);
1315 return LOCATIONS_ERROR_NONE;
1318 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback,
1321 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1322 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
1323 LOCATIONS_NULL_ARG_CHECK(manager);
1324 LOCATIONS_NULL_ARG_CHECK(callback);
1325 location_manager_s *handle = (location_manager_s *) manager;
1327 LocationSatellite *last_sat = NULL;
1328 ret = location_get_last_satellite(handle->object, &last_sat);
1329 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1330 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1331 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d",
1332 LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1333 return LOCATIONS_ERROR_INCORRECT_METHOD;
1336 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ",
1337 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1338 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1342 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1348 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1349 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) {
1353 location_satellite_free(last_sat);
1354 return LOCATIONS_ERROR_NONE;