2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <system_info.h>
21 #include "locations.h"
22 #include "location_internal.h"
24 static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_PASSIVE + 1];
26 static location_method_e __convert_location_method_e(LocationMethod method)
28 location_method_e _method = LOCATIONS_METHOD_NONE;
30 case LOCATION_METHOD_HYBRID:
31 _method = LOCATIONS_METHOD_HYBRID;
33 case LOCATION_METHOD_GPS:
34 _method = LOCATIONS_METHOD_GPS;
36 case LOCATION_METHOD_WPS:
37 _method = LOCATIONS_METHOD_WPS;
39 case LOCATION_METHOD_NONE:
46 static LocationMethod __convert_LocationMethod(location_method_e method)
48 LocationMethod _method = LOCATION_METHOD_NONE;
50 case LOCATIONS_METHOD_HYBRID:
51 _method = LOCATION_METHOD_HYBRID;
53 case LOCATIONS_METHOD_GPS:
54 _method = LOCATION_METHOD_GPS;
56 case LOCATIONS_METHOD_WPS:
57 _method = LOCATION_METHOD_WPS;
59 case LOCATIONS_METHOD_PASSIVE:
60 _method = LOCATION_METHOD_PASSIVE;
62 case LOCATIONS_METHOD_NONE:
64 _method = LOCATION_METHOD_NONE;
70 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
72 LOCATIONS_LOGD("Callback function has been invoked. ");
73 location_manager_s *handle = (location_manager_s *) userdata;
75 if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
76 LocationSatellite *sat = (LocationSatellite *)data;
77 LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
78 sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview);
79 ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE])(sat->num_of_sat_used, sat->num_of_sat_inview,
80 sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]);
81 } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
82 LocationPosition *pos = (LocationPosition *) data;
83 LocationVelocity *vel = (LocationVelocity *) velocity; /* current velocity */
84 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
85 vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
88 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
89 LocationPosition *pos = (LocationPosition *) data;
90 ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION])(pos->latitude, pos->longitude, pos->altitude,
91 pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POSITION]);
94 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
95 LocationVelocity *vel = (LocationVelocity *) velocity;
96 ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY])(vel->speed, vel->direction, vel->climb,
97 vel->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_VELOCITY]);
100 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL] && (type & LOCATION_CHANGED) != 0) {
101 LocationPosition *pos = (LocationPosition *) data;
102 LocationVelocity *vel = (LocationVelocity *) velocity;
103 LocationAccuracy *acc = (LocationAccuracy *) accuracy;
104 ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
105 vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
110 static void __cb_location_updated(GObject *self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata)
112 LOCATIONS_LOGD("Callback function has been invoked. ");
113 int converted_err = __convert_error_code(error);
114 location_manager_s *handle = (location_manager_s *) userdata;
115 LocationPosition *pos = (LocationPosition *) position;
116 LocationVelocity *vel = (LocationVelocity *) velocity;
118 LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp);
119 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) {
120 ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION])(converted_err, pos->latitude, pos->longitude, pos->altitude,
121 pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]);
125 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
127 LOCATIONS_LOGD("Batch callback function has been invoked.");
128 location_manager_s *handle = (location_manager_s *) userdata;
130 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])
131 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
134 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
136 LOCATIONS_LOGD("Invoked. status = %d", status);
137 location_manager_s *handle = (location_manager_s *) userdata;
138 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
139 ((location_service_state_changed_cb)
140 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
144 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
146 LOCATIONS_LOGD("Invoked. status = %d", status);
147 location_manager_s *handle = (location_manager_s *) userdata;
148 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
149 ((location_service_state_changed_cb)
150 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
155 static void __cb_service_status_changed(GObject *self, guint status, gpointer userdata)
157 LOCATIONS_LOGD("Invoked. status = %u", status);
158 location_manager_s *handle = (location_manager_s *) userdata;
160 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
161 if (status == LOCATION_STATUS_2D_FIX || status == LOCATION_STATUS_3D_FIX)
162 ((location_service_state_changed_cb)
163 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
164 else if (status == LOCATION_STATUS_NO_FIX)
165 ((location_service_state_changed_cb)
166 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
167 else if (status == LOCATION_STATUS_MOCK_FAIL)
168 ((location_service_state_changed_cb)
169 handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ERROR, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
174 static int __compare_position(gconstpointer a, gconstpointer b)
176 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
182 static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2)
186 if (bound1->type == bound2->type) {
187 switch (bound1->type) {
188 case LOCATION_BOUNDARY_CIRCLE:
189 if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius)
193 case LOCATION_BOUNDARY_RECT:
194 if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom))
198 case LOCATION_BOUNDARY_POLYGON: {
199 GList *boundary1_next = NULL;
200 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
201 if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list))
204 boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position);
205 if (boundary2_start == NULL) return -1;
207 boundary2_prev = g_list_previous(boundary2_start);
208 boundary2_next = g_list_next(boundary2_start);
210 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
211 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
213 boundary1_next = g_list_next(bound1->polygon.position_list);
214 if (boundary1_next != NULL && boundary2_prev != NULL &&
215 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
216 boundary1_next = g_list_next(boundary1_next);
217 while (boundary1_next) {
218 boundary2_prev = g_list_previous(boundary2_prev);
219 if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list);
220 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
223 boundary1_next = g_list_next(boundary1_next);
226 } else if (boundary1_next != NULL && boundary2_next != NULL &&
227 location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
228 boundary1_next = g_list_next(boundary1_next);
229 while (boundary1_next) {
230 boundary2_next = g_list_next(boundary2_next);
231 if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list);
232 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
235 boundary1_next = g_list_next(boundary1_next);
250 static void __cb_zone_in(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_IN,
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 in boundary");
270 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data);
274 bounds_list = g_list_next(bounds_list);
276 LOCATIONS_LOGD("EXIT <<<");
279 static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata)
281 LOCATIONS_LOGD("ENTER >>>");
282 location_manager_s *handle = (location_manager_s *) userdata;
283 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) {
284 LocationPosition *pos = (LocationPosition *) position;
285 ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY])(LOCATIONS_BOUNDARY_OUT,
286 pos->latitude, pos->longitude,
287 pos->altitude, pos->timestamp,
289 [_LOCATIONS_EVENT_TYPE_BOUNDARY]);
292 location_bounds_s *bounds;
293 GList *bounds_list = g_list_first(handle->bounds_list);
294 while (bounds_list) {
295 bounds = (location_bounds_s *)bounds_list->data;
296 if (__boundary_compare(boundary, bounds->boundary) == 0) {
297 LOCATIONS_LOGD("Find zone out boundary");
299 ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data);
303 bounds_list = g_list_next(bounds_list);
305 LOCATIONS_LOGD("EXIT <<<");
308 static void __foreach_boundary(LocationBoundary *boundary, void *user_data)
310 location_manager_s *handle = (location_manager_s *) user_data;
312 if (handle != NULL && boundary != NULL) {
314 location_bounds_h bounds;
315 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
316 location_coords_s center;
317 center.latitude = boundary->circle.center->latitude;
318 center.longitude = boundary->circle.center->longitude;
319 ret = location_bounds_create_circle(center, boundary->circle.radius, &bounds);
320 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
321 location_coords_s left_top;
322 location_coords_s right_bottom;
323 left_top.latitude = boundary->rect.left_top->latitude;
324 left_top.longitude = boundary->rect.left_top->longitude;
325 right_bottom.latitude = boundary->rect.right_bottom->latitude;
326 right_bottom.longitude = boundary->rect.right_bottom->longitude;
327 ret = location_bounds_create_rect(left_top, right_bottom, &bounds);
328 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
329 GList *list = boundary->polygon.position_list;
330 int size = g_list_length(list);
332 location_coords_s coords[size];
335 LocationPosition *pos = list->data;
336 coords[cnt].latitude = pos->latitude;
337 coords[cnt].longitude = pos->longitude;
338 list = g_list_next(list);
341 ret = location_bounds_create_polygon(coords, size, &bounds);
344 LOCATIONS_LOGI("Invalid boundary type : %d", boundary->type);
347 if (ret != LOCATIONS_ERROR_NONE) {
348 LOCATIONS_LOGI("Failed to create location_bounds : (0x%08x) ", ret);
350 if (handle->is_continue_foreach_bounds) {
351 handle->is_continue_foreach_bounds =
352 ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS])(bounds,
355 [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]);
357 location_bounds_destroy(bounds);
360 LOCATIONS_LOGD("__foreach_boundary() has been failed");
364 static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data)
366 LOCATIONS_LOGD("method: [%d]", method);
367 location_method_e _method = __convert_location_method_e(method);
368 location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data;
369 if (_setting_changed == NULL) {
370 LOCATIONS_LOGE("Invaild userdata\n");
374 if (_setting_changed[_method].callback != NULL)
375 _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data);
378 /*/////////////////////////////////////// */
379 /* Location Manager */
380 /*////////////////////////////////////// */
382 EXPORT_API bool location_manager_is_supported_method(location_method_e method)
384 LOCATIONS_LOGD("location_manager_is_supported_method %d", method);
385 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
386 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
390 if (method == LOCATIONS_METHOD_GPS) {
391 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
392 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
395 } else if (method == LOCATIONS_METHOD_WPS) {
396 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
397 set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
402 LocationMethod _method = __convert_LocationMethod(method);
403 if (_method == LOCATION_METHOD_NONE) {
404 LOCATIONS_LOGE("Not supported method [%d]", method);
405 set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD);
409 set_last_result(LOCATIONS_ERROR_NONE);
410 return location_is_supported_method(_method);
413 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
415 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
417 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
418 LOCATIONS_LOGE("Not supported method [%d]", method);
419 return LOCATIONS_ERROR_INCORRECT_METHOD;
422 LOCATIONS_LOGD("location_manager_is_enabled_method %d", method);
423 LOCATIONS_NULL_ARG_CHECK(enable);
424 int is_enabled_val = -1;
425 LocationMethod _method = __convert_LocationMethod(method);
426 int ret = location_is_enabled_method(_method, &is_enabled_val);
427 if (ret != LOCATION_ERROR_NONE) {
428 if (ret == LOCATION_ERROR_NOT_SUPPORTED)
429 return LOCATIONS_ERROR_INCORRECT_METHOD;
430 return __convert_error_code(ret);
433 if (is_enabled_val == -1)
434 return TIZEN_ERROR_PERMISSION_DENIED;
436 *enable = (is_enabled_val == 0) ? FALSE : TRUE;
437 return LOCATIONS_ERROR_NONE;
440 EXPORT_API int location_manager_enable_method(const location_method_e method, const bool enable)
442 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
444 if (method < LOCATIONS_METHOD_HYBRID || method > LOCATIONS_METHOD_WPS) {
445 LOCATIONS_LOGE("Not supported method [%d]", method);
446 return LOCATIONS_ERROR_INCORRECT_METHOD;
449 LOCATIONS_LOGD("method: %d, enable: %d", method, enable);
452 if (LOCATIONS_METHOD_HYBRID == method) {
453 if (__is_gps_supported() == LOCATIONS_ERROR_NONE) {
454 ret = location_enable_method(LOCATION_METHOD_GPS, enable);
455 if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret);
457 if (__is_wps_supported() == LOCATIONS_ERROR_NONE) {
458 ret = location_enable_method(LOCATION_METHOD_WPS, enable);
459 return __convert_error_code(ret);
461 return LOCATIONS_ERROR_NONE;
464 if ((LOCATIONS_METHOD_GPS == method) && (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
465 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
466 return LOCATIONS_ERROR_NOT_SUPPORTED;
467 } else if ((LOCATIONS_METHOD_WPS == method) && (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED)) {
468 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x)", LOCATIONS_ERROR_NOT_SUPPORTED);
469 return LOCATIONS_ERROR_NOT_SUPPORTED;
472 LocationMethod _method = __convert_LocationMethod(method);
474 int ret = location_enable_method(_method, enable);
476 return __convert_error_code(ret);
480 EXPORT_API int location_manager_create(location_method_e method, location_manager_h *manager)
482 LOCATIONS_LOGD("location_manager_create (method : %d)", method);
484 if (method == LOCATIONS_METHOD_HYBRID) {
485 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
486 } else if (method == LOCATIONS_METHOD_GPS) {
487 if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
488 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
489 return LOCATIONS_ERROR_NOT_SUPPORTED;
491 } else if (method == LOCATIONS_METHOD_WPS) {
492 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
493 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
494 return LOCATIONS_ERROR_NOT_SUPPORTED;
496 } else if (method == LOCATIONS_METHOD_PASSIVE) {
497 if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
498 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
499 return LOCATIONS_ERROR_NOT_SUPPORTED;
503 LocationMethod _method = __convert_LocationMethod(method);
504 if (_method == LOCATION_METHOD_NONE) {
505 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED);
506 return LOCATIONS_ERROR_NOT_SUPPORTED;
509 if (!location_is_supported_method(_method)) {
510 LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED);
511 return LOCATIONS_ERROR_NOT_SUPPORTED;
514 /*It is moved here becasue of TCS. */
515 LOCATIONS_NULL_ARG_CHECK(manager);
517 if (location_init() != LOCATION_ERROR_NONE) {
518 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
519 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
522 location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s));
523 if (handle == NULL) {
524 LOCATIONS_LOGE("OUT_OF_MEMORY(0x%08x)", LOCATIONS_ERROR_OUT_OF_MEMORY);
525 return LOCATIONS_ERROR_OUT_OF_MEMORY;
528 memset(handle, 0, sizeof(location_manager_s));
530 handle->object = location_new(_method);
531 if (handle->object == NULL) {
532 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
534 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
536 handle->method = method;
537 handle->is_continue_foreach_bounds = TRUE;
538 handle->bounds_list = NULL;
540 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED])
541 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle);
543 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED])
544 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle);
547 if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED])
548 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle);
551 *manager = (location_manager_h) handle;
552 return LOCATIONS_ERROR_NONE;
555 EXPORT_API int location_manager_destroy(location_manager_h manager)
557 LOCATIONS_LOGD("location_manager_destroy");
558 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
559 LOCATIONS_NULL_ARG_CHECK(manager);
560 location_manager_s *handle = (location_manager_s *) manager;
562 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) {
563 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]);
564 handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0;
567 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) {
568 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]);
569 handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
573 if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) {
574 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]);
575 handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0;
579 if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) {
580 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]);
581 handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0;
584 int ret = location_free(handle->object);
585 if (ret != LOCATIONS_ERROR_NONE)
586 return __convert_error_code(ret);
589 return LOCATIONS_ERROR_NONE;
592 EXPORT_API int location_manager_start(location_manager_h manager)
594 LOCATIONS_LOGD("location_manager_start");
595 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
596 LOCATIONS_NULL_ARG_CHECK(manager);
597 location_manager_s *handle = (location_manager_s *) manager;
599 if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED])
600 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle);
602 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
603 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN])
604 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle);
606 if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT])
607 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle);
609 LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method);
612 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) {
613 LOCATIONS_LOGI("Satellite update_cb is set");
614 location_set_option(handle->object, "USE_SV");
617 int ret = location_start(handle->object);
618 if (ret != LOCATION_ERROR_NONE)
619 return __convert_error_code(ret);
621 return LOCATIONS_ERROR_NONE;
624 EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data)
626 LOCATIONS_LOGD("location_manager_request_single_location");
627 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
628 LOCATIONS_NULL_ARG_CHECK(manager);
629 LOCATIONS_NULL_ARG_CHECK(callback);
630 if (timeout <= 0 || timeout > 120) {
631 LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout);
632 return LOCATIONS_ERROR_INVALID_PARAMETER;
635 location_manager_s *handle = (location_manager_s *) manager;
636 int ret = LOCATIONS_ERROR_NONE;
638 if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED])
639 handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle);
641 ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data);
642 if (ret != LOCATIONS_ERROR_NONE)
645 ret = location_request_single_location(handle->object, timeout);
646 if (ret != LOCATION_ERROR_NONE) {
647 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
648 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD : method - %d", handle->method);
649 return LOCATIONS_ERROR_INCORRECT_METHOD;
651 return __convert_error_code(ret);
654 return LOCATIONS_ERROR_NONE;
657 EXPORT_API int location_manager_stop(location_manager_h manager)
659 LOCATIONS_LOGD("location_manager_stop");
660 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
661 LOCATIONS_NULL_ARG_CHECK(manager);
663 location_manager_s *handle = (location_manager_s *) manager;
665 if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) {
666 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]);
667 handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0;
670 if (handle->method >= LOCATIONS_METHOD_HYBRID && handle->method <= LOCATIONS_METHOD_PASSIVE) {
671 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) {
672 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]);
673 handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0;
676 if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) {
677 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]);
678 handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0;
682 int ret = location_stop(handle->object);
683 if (ret != LOCATION_ERROR_NONE)
684 return __convert_error_code(ret);
686 return LOCATIONS_ERROR_NONE;
689 EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds)
691 LOCATIONS_LOGD("location_manager_add_boundary");
692 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
693 LOCATIONS_NULL_ARG_CHECK(manager);
694 LOCATIONS_NULL_ARG_CHECK(bounds);
696 location_manager_s *handle = (location_manager_s *) manager;
697 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
698 int ret = location_boundary_add(handle->object, bound_handle->boundary);
699 if (ret != LOCATION_ERROR_NONE)
700 return __convert_error_code(ret);
702 bound_handle->is_added = TRUE;
703 handle->bounds_list = g_list_append(handle->bounds_list, bound_handle);
704 return LOCATIONS_ERROR_NONE;
707 EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds)
709 LOCATIONS_LOGD("location_manager_remove_boundary");
710 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
711 LOCATIONS_NULL_ARG_CHECK(manager);
712 LOCATIONS_NULL_ARG_CHECK(bounds);
714 location_manager_s *handle = (location_manager_s *) manager;
715 location_bounds_s *bound_handle = (location_bounds_s *) bounds;
716 int ret = location_boundary_remove(handle->object, bound_handle->boundary);
717 if (ret != LOCATION_ERROR_NONE)
718 return __convert_error_code(ret);
720 handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle);
721 bound_handle->is_added = FALSE;
722 return LOCATIONS_ERROR_NONE;
725 EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data)
727 LOCATIONS_LOGD("location_manager_foreach_boundary");
728 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
729 LOCATIONS_NULL_ARG_CHECK(manager);
730 LOCATIONS_NULL_ARG_CHECK(callback);
732 location_manager_s *handle = (location_manager_s *) manager;
733 handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = callback;
734 handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data;
735 handle->is_continue_foreach_bounds = TRUE;
736 int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle);
737 if (ret != LOCATION_ERROR_NONE)
738 return __convert_error_code(ret);
740 return LOCATIONS_ERROR_NONE;
743 EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e *method)
745 LOCATIONS_LOGD("location_manager_get_method %d", method);
746 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
747 LOCATIONS_NULL_ARG_CHECK(manager);
748 LOCATIONS_NULL_ARG_CHECK(method);
750 location_manager_s *handle = (location_manager_s *) manager;
751 LocationMethod _method = LOCATION_METHOD_NONE;
752 g_object_get(handle->object, "method", &_method, NULL);
754 case LOCATION_METHOD_NONE:
755 *method = LOCATIONS_METHOD_NONE;
757 case LOCATION_METHOD_HYBRID:
758 *method = LOCATIONS_METHOD_HYBRID;
760 case LOCATION_METHOD_GPS:
761 *method = LOCATIONS_METHOD_GPS;
763 case LOCATION_METHOD_WPS:
764 *method = LOCATIONS_METHOD_WPS;
766 case LOCATION_METHOD_PASSIVE:
767 *method = LOCATIONS_METHOD_PASSIVE;
770 LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method);
771 return LOCATIONS_ERROR_INVALID_PARAMETER;
774 return LOCATIONS_ERROR_NONE;
777 EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude,
780 LOCATIONS_LOGD("location_manager_get_position");
781 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
782 LOCATIONS_NULL_ARG_CHECK(manager);
783 LOCATIONS_NULL_ARG_CHECK(altitude);
784 LOCATIONS_NULL_ARG_CHECK(latitude);
785 LOCATIONS_NULL_ARG_CHECK(longitude);
786 LOCATIONS_NULL_ARG_CHECK(timestamp);
788 location_manager_s *handle = (location_manager_s *) manager;
789 LocationPosition *pos = NULL;
790 LocationAccuracy *acc = NULL;
791 int ret = location_get_position(handle->object, &pos, &acc);
792 if (ret != LOCATION_ERROR_NONE)
793 return __convert_error_code(ret);
795 if (pos->status == LOCATION_STATUS_NO_FIX) {
796 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
798 *latitude = pos->latitude;
799 *longitude = pos->longitude;
800 *altitude = pos->altitude;
802 *timestamp = pos->timestamp;
803 location_position_free(pos);
804 location_accuracy_free(acc);
805 return LOCATIONS_ERROR_NONE;
808 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)
810 LOCATIONS_LOGD("location_manager_get_location");
811 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
812 LOCATIONS_NULL_ARG_CHECK(manager);
813 LOCATIONS_NULL_ARG_CHECK(altitude);
814 LOCATIONS_NULL_ARG_CHECK(latitude);
815 LOCATIONS_NULL_ARG_CHECK(longitude);
816 LOCATIONS_NULL_ARG_CHECK(climb);
817 LOCATIONS_NULL_ARG_CHECK(direction);
818 LOCATIONS_NULL_ARG_CHECK(speed);
819 LOCATIONS_NULL_ARG_CHECK(level);
820 LOCATIONS_NULL_ARG_CHECK(horizontal);
821 LOCATIONS_NULL_ARG_CHECK(vertical);
822 LOCATIONS_NULL_ARG_CHECK(timestamp);
824 location_manager_s *handle = (location_manager_s *) manager;
825 LocationPosition *pos = NULL;
826 LocationVelocity *vel = NULL;
827 LocationAccuracy *acc = NULL;
828 int ret = location_get_position_ext(handle->object, &pos, &vel, &acc);
829 if (ret != LOCATION_ERROR_NONE)
830 return __convert_error_code(ret);
832 if (pos->status == LOCATION_STATUS_NO_FIX) {
833 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
835 *latitude = pos->latitude;
836 *longitude = pos->longitude;
837 *altitude = pos->altitude;
839 *timestamp = pos->timestamp;
841 *direction = vel->direction;
844 *horizontal = acc->horizontal_accuracy;
845 *vertical = acc->vertical_accuracy;
847 location_position_free(pos);
848 location_velocity_free(vel);
849 location_accuracy_free(acc);
850 return LOCATIONS_ERROR_NONE;
853 EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
855 LOCATIONS_LOGD("location_manager_get_velocity");
856 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
857 LOCATIONS_NULL_ARG_CHECK(manager);
858 LOCATIONS_NULL_ARG_CHECK(climb);
859 LOCATIONS_NULL_ARG_CHECK(direction);
860 LOCATIONS_NULL_ARG_CHECK(speed);
861 LOCATIONS_NULL_ARG_CHECK(timestamp);
863 location_manager_s *handle = (location_manager_s *) manager;
864 LocationVelocity *vel = NULL;
865 LocationAccuracy *acc = NULL;
867 int ret = location_get_velocity(handle->object, &vel, &acc);
868 if (ret != LOCATION_ERROR_NONE)
869 return __convert_error_code(ret);
872 *direction = vel->direction;
874 *timestamp = vel->timestamp;
875 location_velocity_free(vel);
876 location_accuracy_free(acc);
877 return LOCATIONS_ERROR_NONE;
880 EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal,
883 LOCATIONS_LOGD("location_manager_get_accuracy");
884 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
885 LOCATIONS_NULL_ARG_CHECK(manager);
886 LOCATIONS_NULL_ARG_CHECK(level);
887 LOCATIONS_NULL_ARG_CHECK(horizontal);
888 LOCATIONS_NULL_ARG_CHECK(vertical);
889 location_manager_s *handle = (location_manager_s *) manager;
892 LocationPosition *pos = NULL;
893 LocationAccuracy *acc = NULL;
894 ret = location_get_position(handle->object, &pos, &acc);
895 if (ret != LOCATION_ERROR_NONE)
896 return __convert_error_code(ret);
899 return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE);
902 *horizontal = acc->horizontal_accuracy;
903 *vertical = acc->vertical_accuracy;
904 location_position_free(pos);
905 location_accuracy_free(acc);
906 return LOCATIONS_ERROR_NONE;
909 EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, time_t *timestamp)
911 LOCATIONS_LOGD("location_manager_get_last_position");
912 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
913 LOCATIONS_NULL_ARG_CHECK(manager);
914 LOCATIONS_NULL_ARG_CHECK(altitude);
915 LOCATIONS_NULL_ARG_CHECK(latitude);
916 LOCATIONS_NULL_ARG_CHECK(longitude);
917 LOCATIONS_NULL_ARG_CHECK(timestamp);
919 location_manager_s *handle = (location_manager_s *) manager;
922 LocationPosition *last_pos = NULL;
923 LocationAccuracy *last_acc = NULL;
924 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
925 if (ret != LOCATION_ERROR_NONE)
926 return __convert_error_code(ret);
928 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
929 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
931 *latitude = last_pos->latitude;
932 *longitude = last_pos->longitude;
933 *altitude = last_pos->altitude;
935 *timestamp = last_pos->timestamp;
936 location_position_free(last_pos);
937 location_accuracy_free(last_acc);
938 return LOCATIONS_ERROR_NONE;
941 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)
943 LOCATIONS_LOGD("location_manager_get_last_location");
944 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
945 LOCATIONS_NULL_ARG_CHECK(manager);
946 LOCATIONS_NULL_ARG_CHECK(altitude);
947 LOCATIONS_NULL_ARG_CHECK(latitude);
948 LOCATIONS_NULL_ARG_CHECK(longitude);
949 LOCATIONS_NULL_ARG_CHECK(climb);
950 LOCATIONS_NULL_ARG_CHECK(direction);
951 LOCATIONS_NULL_ARG_CHECK(speed);
952 LOCATIONS_NULL_ARG_CHECK(level);
953 LOCATIONS_NULL_ARG_CHECK(horizontal);
954 LOCATIONS_NULL_ARG_CHECK(vertical);
955 LOCATIONS_NULL_ARG_CHECK(timestamp);
957 location_manager_s *handle = (location_manager_s *) manager;
960 LocationPosition *last_pos = NULL;
961 LocationVelocity *last_vel = NULL;
962 LocationAccuracy *last_acc = NULL;
963 ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc);
964 if (ret != LOCATION_ERROR_NONE)
965 return __convert_error_code(ret);
967 if (last_pos->status == LOCATION_STATUS_NO_FIX) {
968 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
970 *latitude = last_pos->latitude;
971 *longitude = last_pos->longitude;
972 *altitude = last_pos->altitude;
974 *timestamp = last_pos->timestamp;
975 *climb = last_vel->climb;
976 *direction = last_vel->direction;
977 *speed = last_vel->speed;
978 *level = last_acc->level;
979 *horizontal = last_acc->horizontal_accuracy;
980 *vertical = last_acc->vertical_accuracy;
981 location_position_free(last_pos);
982 location_velocity_free(last_vel);
983 location_accuracy_free(last_acc);
984 return LOCATIONS_ERROR_NONE;
987 EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t *timestamp)
989 LOCATIONS_LOGD("location_manager_get_last_velocity");
990 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
991 LOCATIONS_NULL_ARG_CHECK(manager);
992 LOCATIONS_NULL_ARG_CHECK(climb);
993 LOCATIONS_NULL_ARG_CHECK(direction);
994 LOCATIONS_NULL_ARG_CHECK(speed);
995 LOCATIONS_NULL_ARG_CHECK(timestamp);
997 location_manager_s *handle = (location_manager_s *) manager;
1000 LocationVelocity *last_vel = NULL;
1001 LocationAccuracy *last_acc = NULL;
1002 ret = location_get_last_velocity(handle->object, &last_vel, &last_acc);
1003 if (ret != LOCATION_ERROR_NONE)
1004 return __convert_error_code(ret);
1006 *climb = last_vel->climb;
1007 *direction = last_vel->direction;
1008 *speed = last_vel->speed;
1009 *timestamp = last_vel->timestamp;
1010 location_velocity_free(last_vel);
1011 location_accuracy_free(last_acc);
1012 return LOCATIONS_ERROR_NONE;
1015 EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e *level, double *horizontal, double *vertical)
1017 LOCATIONS_LOGD("location_manager_get_last_accuracy");
1018 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1019 LOCATIONS_NULL_ARG_CHECK(manager);
1020 LOCATIONS_NULL_ARG_CHECK(level);
1021 LOCATIONS_NULL_ARG_CHECK(horizontal);
1022 LOCATIONS_NULL_ARG_CHECK(vertical);
1023 location_manager_s *handle = (location_manager_s *) manager;
1026 LocationPosition *last_pos = NULL;
1027 LocationAccuracy *last_acc = NULL;
1028 ret = location_get_last_position(handle->object, &last_pos, &last_acc);
1029 if (ret != LOCATION_ERROR_NONE)
1030 return __convert_error_code(ret);
1032 *level = last_acc->level;
1033 *horizontal = last_acc->horizontal_accuracy;
1034 *vertical = last_acc->vertical_accuracy;
1035 location_position_free(last_pos);
1036 location_accuracy_free(last_acc);
1037 return LOCATIONS_ERROR_NONE;
1040 EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e *state)
1042 dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: location_manager_get_accessibility_state() is deprecated and will be removed from next release.");
1043 LOCATIONS_LOGD("location_manager_get_accessibility_state");
1044 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1045 LOCATIONS_NULL_ARG_CHECK(state);
1047 int ret = LOCATION_ERROR_NONE;
1048 LocationAccessState auth = LOCATION_ACCESS_NONE;
1049 ret = location_get_accessibility_state(&auth);
1050 if (ret != LOCATION_ERROR_NONE) {
1051 *state = LOCATIONS_ACCESS_STATE_NONE;
1052 return __convert_error_code(ret);
1056 case LOCATION_ACCESS_DENIED:
1057 *state = LOCATIONS_ACCESS_STATE_DENIED;
1059 case LOCATION_ACCESS_ALLOWED:
1060 *state = LOCATIONS_ACCESS_STATE_ALLOWED;
1062 case LOCATION_ACCESS_NONE:
1064 *state = LOCATIONS_ACCESS_STATE_NONE;
1068 return LOCATIONS_ERROR_NONE;
1071 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)
1073 LOCATIONS_LOGD("location_manager_set_distance_updated_cb");
1074 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1075 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1076 LOCATIONS_CHECK_CONDITION(distance > 0 && distance <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1077 LOCATIONS_NULL_ARG_CHECK(manager);
1078 location_manager_s *handle = (location_manager_s *) manager;
1079 g_object_set(handle->object, "min-interval", interval, NULL);
1080 g_object_set(handle->object, "min-distance", distance, NULL);
1081 return __set_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager, callback, user_data);
1084 EXPORT_API int location_manager_unset_distance_based_location_changed_cb(location_manager_h manager)
1086 LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
1087 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1088 LOCATIONS_NULL_ARG_CHECK(manager);
1089 location_manager_s *handle = (location_manager_s *) manager;
1090 g_object_set(handle->object, "min-interval", 0, NULL);
1091 g_object_set(handle->object, "min-distance", 0, NULL);
1092 return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
1095 EXPORT_API int location_manager_set_location_changed_cb(location_manager_h manager, location_changed_cb callback, int interval, void *user_data)
1097 LOCATIONS_LOGD("location_manager_set_location_updated_cb");
1098 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1099 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1100 LOCATIONS_NULL_ARG_CHECK(manager);
1101 location_manager_s *handle = (location_manager_s *) manager;
1102 g_object_set(handle->object, "loc-interval", interval, NULL);
1103 return __set_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager, callback, user_data);
1106 EXPORT_API int location_manager_unset_location_changed_cb(location_manager_h manager)
1108 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1109 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1110 return __unset_callback(_LOCATIONS_EVENT_TYPE_POS_VEL, manager);
1113 EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data)
1115 LOCATIONS_LOGD("location_manager_set_position_updated_cb");
1116 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1117 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1118 LOCATIONS_NULL_ARG_CHECK(manager);
1119 location_manager_s *handle = (location_manager_s *) manager;
1120 g_object_set(handle->object, "pos-interval", interval, NULL);
1121 return __set_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager, callback, user_data);
1124 EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager)
1126 LOCATIONS_LOGD("location_manager_unset_position_updated_cb");
1127 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1128 return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager);
1131 EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data)
1133 LOCATIONS_LOGD("location_manager_set_velocity_updated_cb");
1134 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1135 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1136 LOCATIONS_NULL_ARG_CHECK(manager);
1137 location_manager_s *handle = (location_manager_s *) manager;
1138 g_object_set(handle->object, "vel-interval", interval, NULL);
1139 return __set_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager, callback, user_data);
1142 EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager)
1144 LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb");
1145 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1146 return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager);
1149 EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback,
1152 LOCATIONS_LOGD("location_manager_set_service_state_changed_cb");
1153 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1154 return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data);
1157 EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager)
1159 LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb");
1160 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1161 return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager);
1164 EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data)
1166 LOCATIONS_LOGD("location_manager_set_zone_changed_cb");
1167 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1168 return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data);
1171 EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager)
1173 LOCATIONS_LOGD("location_manager_unset_zone_changed_cb");
1174 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1175 return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager);
1178 EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data)
1180 LOCATIONS_LOGD("location_manager_set_setting_changed_cb");
1181 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1182 LOCATIONS_NULL_ARG_CHECK(callback);
1184 LocationMethod _method = __convert_LocationMethod(method);
1185 int ret = LOCATION_ERROR_NONE;
1187 if (_method == LOCATION_METHOD_NONE)
1188 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1190 g_location_setting[_method].callback = callback;
1191 g_location_setting[_method].user_data = user_data;
1193 ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting);
1194 if (ret != LOCATION_ERROR_NONE)
1195 return __convert_error_code(ret);
1197 return LOCATIONS_ERROR_NONE;
1200 EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method)
1202 LOCATIONS_LOGD("location_manager_unset_setting_changed_cb");
1203 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1204 LocationMethod _method = __convert_LocationMethod(method);
1205 int ret = LOCATION_ERROR_NONE;
1207 if (_method == LOCATION_METHOD_NONE)
1208 return __convert_error_code(LOCATION_ERROR_PARAMETER);
1210 ret = location_ignore_setting_notify(_method, __setting_changed_cb);
1211 if (ret != LOCATION_ERROR_NONE) {
1212 LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret);
1213 ret = __convert_error_code(ret);
1216 g_location_setting[method].callback = NULL;
1217 g_location_setting[method].user_data = NULL;
1219 return LOCATIONS_ERROR_NONE;
1222 EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance)
1224 LOCATIONS_LOGD("location_manager_get_distance");
1225 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1226 LOCATIONS_NULL_ARG_CHECK(distance);
1227 LOCATIONS_CHECK_CONDITION(start_latitude >= -90 && start_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1228 LOCATIONS_CHECK_CONDITION(start_longitude >= -180 && start_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1229 LOCATIONS_CHECK_CONDITION(end_latitude >= -90 && end_latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1230 LOCATIONS_CHECK_CONDITION(end_longitude >= -180 && end_longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1232 int ret = LOCATION_ERROR_NONE;
1235 LocationPosition *start = location_position_new(0, start_latitude, start_longitude, 0, LOCATION_STATUS_2D_FIX);
1236 LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX);
1238 ret = location_get_distance(start, end, &u_distance);
1239 if (ret != LOCATION_ERROR_NONE)
1240 return __convert_error_code(ret);
1242 *distance = (double)u_distance;
1244 return LOCATIONS_ERROR_NONE;
1247 /*/////////////////////////////////////// */
1248 /* GPS Status & Satellites */
1249 /*////////////////////////////////////// */
1251 EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea)
1253 LOCATIONS_LOGD("gps_status_get_nmea");
1254 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1255 LOCATIONS_NULL_ARG_CHECK(manager);
1256 LOCATIONS_NULL_ARG_CHECK(nmea);
1257 location_manager_s *handle = (location_manager_s *) manager;
1260 int ret = location_get_nmea(handle->object, &nmea_data);
1261 if (ret != LOCATION_ERROR_NONE || nmea == NULL) {
1262 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1263 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1264 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1267 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : NMEA is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1268 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1271 *nmea = g_strdup(nmea_data);
1274 return LOCATIONS_ERROR_NONE;
1277 EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1279 LOCATIONS_LOGD("gps_status_get_satellite");
1280 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1281 LOCATIONS_NULL_ARG_CHECK(manager);
1282 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1283 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1284 LOCATIONS_NULL_ARG_CHECK(timestamp);
1285 location_manager_s *handle = (location_manager_s *) manager;
1286 LocationSatellite *sat = NULL;
1287 int ret = location_get_satellite(handle->object, &sat);
1288 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1289 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1290 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1291 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1294 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1295 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1298 *num_of_active = sat->num_of_sat_used;
1299 *num_of_inview = sat->num_of_sat_inview;
1300 *timestamp = sat->timestamp;
1301 location_satellite_free(sat);
1303 return LOCATIONS_ERROR_NONE;
1306 EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data)
1308 LOCATIONS_LOGD("gps_status_set_satellite_updated_cb");
1309 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1310 LOCATIONS_CHECK_CONDITION(interval >= 1 && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1311 LOCATIONS_NULL_ARG_CHECK(manager);
1312 LOCATIONS_NULL_ARG_CHECK(callback);
1314 location_manager_s *handle = (location_manager_s *) manager;
1315 int ret = location_set_option(handle->object, "USE_SV");
1316 if (ret != LOCATION_ERROR_NONE) {
1317 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1318 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1319 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1323 g_object_set(handle->object, "sat-interval", interval, NULL);
1324 return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data);
1327 EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager)
1329 LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb");
1330 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1331 return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager);
1334 EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1336 LOCATIONS_LOGD("gps_status_foreach_satellites_in_view");
1337 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1338 LOCATIONS_NULL_ARG_CHECK(manager);
1339 LOCATIONS_NULL_ARG_CHECK(callback);
1341 location_manager_s *handle = (location_manager_s *) manager;
1342 LocationSatellite *sat = NULL;
1343 int ret = location_get_satellite(handle->object, &sat);
1344 if (ret != LOCATION_ERROR_NONE || sat == NULL) {
1345 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1346 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1347 return LOCATIONS_ERROR_INCORRECT_METHOD;
1348 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1349 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1350 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1353 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1354 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1358 for (i = 0; i < sat->num_of_sat_inview; i++) {
1364 location_satellite_get_satellite_details(sat, i, &prn, &used, &elevation, &azimuth, &snr);
1365 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1368 location_satellite_free(sat);
1370 return LOCATIONS_ERROR_NONE;
1373 EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp)
1375 LOCATIONS_LOGD("gps_status_get_last_satellite");
1376 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1377 LOCATIONS_NULL_ARG_CHECK(manager);
1378 LOCATIONS_NULL_ARG_CHECK(num_of_active);
1379 LOCATIONS_NULL_ARG_CHECK(num_of_inview);
1380 LOCATIONS_NULL_ARG_CHECK(timestamp);
1382 location_manager_s *handle = (location_manager_s *) manager;
1383 int ret = LOCATION_ERROR_NONE;
1384 LocationSatellite *last_sat = NULL;
1385 ret = location_get_last_satellite(handle->object, &last_sat);
1386 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1387 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1388 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1389 return LOCATIONS_ERROR_INCORRECT_METHOD;
1390 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1391 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1392 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1395 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1396 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1399 *num_of_active = last_sat->num_of_sat_used;
1400 *num_of_inview = last_sat->num_of_sat_inview;
1401 *timestamp = last_sat->timestamp;
1402 location_satellite_free(last_sat);
1403 return LOCATIONS_ERROR_NONE;
1406 EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data)
1408 LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view");
1409 LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_satellite_supported());
1410 LOCATIONS_NULL_ARG_CHECK(manager);
1411 LOCATIONS_NULL_ARG_CHECK(callback);
1412 location_manager_s *handle = (location_manager_s *) manager;
1413 int ret = LOCATION_ERROR_NONE;
1414 LocationSatellite *last_sat = NULL;
1416 ret = location_get_last_satellite(handle->object, &last_sat);
1417 if (ret != LOCATION_ERROR_NONE || last_sat == NULL) {
1418 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
1419 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
1420 return LOCATIONS_ERROR_INCORRECT_METHOD;
1423 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
1424 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1428 for (i = 0; i < last_sat->num_of_sat_inview; i++) {
1434 location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr);
1435 if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE)
1438 location_satellite_free(last_sat);
1439 return LOCATIONS_ERROR_NONE;
1446 EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager, location_batch_cb callback, int batch_interval, int batch_period, void *user_data)
1448 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
1449 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1451 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1452 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1453 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1454 LOCATIONS_NULL_ARG_CHECK(manager);
1455 LOCATIONS_NULL_ARG_CHECK(callback);
1456 location_manager_s *handle = (location_manager_s *) manager;
1457 g_object_set(handle->object, "batch-period", batch_period, NULL);
1458 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
1459 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
1462 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
1464 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
1465 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1466 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
1469 EXPORT_API int location_manager_start_batch(location_manager_h manager)
1471 LOCATIONS_LOGD("location_manager_start_batch");
1472 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1473 LOCATIONS_NULL_ARG_CHECK(manager);
1474 location_manager_s *handle = (location_manager_s *) manager;
1476 if (LOCATIONS_METHOD_GPS == handle->method) {
1477 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED])
1478 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
1480 LOCATIONS_LOGE("method is not GPS [LOCATIONS_ERROR_INCORRECT_METHOD]");
1481 return LOCATIONS_ERROR_INCORRECT_METHOD;
1484 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
1485 LOCATIONS_LOGD("batch status set : Start");
1487 int ret = location_start_batch(handle->object);
1488 if (ret != LOCATION_ERROR_NONE)
1489 return __convert_error_code(ret);
1491 return LOCATIONS_ERROR_NONE;
1494 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
1496 LOCATIONS_LOGD("location_manager_stop_batch");
1497 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1498 LOCATIONS_NULL_ARG_CHECK(manager);
1499 location_manager_s *handle = (location_manager_s *) manager;
1501 if (LOCATIONS_METHOD_GPS == handle->method) {
1502 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
1503 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
1504 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
1508 int ret = location_stop_batch(handle->object);
1509 if (ret != LOCATION_ERROR_NONE)
1510 return __convert_error_code(ret);
1512 return LOCATIONS_ERROR_NONE;
1515 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
1517 LOCATIONS_LOGD("location_manager_foreach_location_batch");
1518 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
1519 LOCATIONS_NULL_ARG_CHECK(manager);
1520 LOCATIONS_NULL_ARG_CHECK(callback);
1521 location_manager_s *handle = (location_manager_s *) manager;
1522 LocationBatch *batch = NULL;
1524 int ret = location_get_batch(handle->object, &batch);
1525 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
1526 if (ret == LOCATION_ERROR_NOT_ALLOWED) {
1527 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
1528 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
1531 LOCATIONS_LOGE("Batch is NULL [LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE]");
1532 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
1536 for (i = 0; i < batch->num_of_location; i++) {
1546 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
1547 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
1550 location_batch_free(batch);
1552 return LOCATIONS_ERROR_NONE;
1555 EXPORT_API int location_manager_is_enabled_mock_location(bool *enabled)
1557 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1558 LOCATIONS_NULL_ARG_CHECK(enabled);
1559 int is_enabled_val = -1;
1560 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &is_enabled_val);
1561 if (ret != LOCATION_ERROR_NONE)
1562 return __convert_error_code(ret);
1564 if (is_enabled_val == -1)
1565 return TIZEN_ERROR_PERMISSION_DENIED;
1567 *enabled = (is_enabled_val == 0) ? FALSE : TRUE;
1568 return LOCATIONS_ERROR_NONE;
1571 EXPORT_API int location_manager_enable_mock_location(const bool enable)
1573 LOCATIONS_LOGD("enable: %d", enable);
1574 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1575 int ret = LOCATION_ERROR_NONE;
1577 ret = location_enable_mock(enable);
1578 return __convert_error_code(ret);
1581 EXPORT_API int location_manager_set_mock_location(location_manager_h manager, const double latitude, const double longitude, const double altitude,
1582 const double speed, const double direction, const double accuracy)
1584 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1585 LOCATIONS_NULL_ARG_CHECK(manager);
1587 LOCATIONS_CHECK_CONDITION(latitude >= -90 && latitude <= 90, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1588 LOCATIONS_CHECK_CONDITION(longitude >= -180 && longitude <= 180, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1589 LOCATIONS_CHECK_CONDITION(direction >= 0 && direction <= 360, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
1591 location_manager_s *handle = (location_manager_s *) manager;
1592 int ret = LOCATION_ERROR_NONE;
1594 LocationPosition *pos = NULL;
1595 LocationVelocity *vel = NULL;
1596 LocationAccuracy *acc = NULL;
1598 ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1599 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1600 if (ret == LOCATIONS_ERROR_NONE) {
1602 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1604 return __convert_error_code(ret);
1607 pos = location_position_new(0, latitude, longitude, 0, LOCATION_STATUS_3D_FIX);
1609 LOCATIONS_LOGE("Failed to create position");
1610 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1612 vel = location_velocity_new(0, speed, direction, 0);
1614 LOCATIONS_LOGE("Failed to create velocity");
1615 location_position_free(pos);
1616 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1619 acc = location_accuracy_new(LOCATION_ACCURACY_LEVEL_DETAILED, accuracy, -1);
1621 LOCATIONS_LOGE("Failed to create accuracy");
1622 location_position_free(pos);
1623 location_velocity_free(vel);
1624 return LOCATIONS_ERROR_OUT_OF_MEMORY;
1627 ret = location_set_mock_location(handle->object, pos, vel, acc);
1629 location_position_free(pos);
1630 location_velocity_free(vel);
1631 location_accuracy_free(acc);
1633 return __convert_error_code(ret);
1636 EXPORT_API int location_manager_clear_mock_location(location_manager_h manager)
1638 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
1639 LOCATIONS_NULL_ARG_CHECK(manager);
1641 location_manager_s *handle = (location_manager_s *) manager;
1644 int ret = location_is_enabled_method(INTERNAL_METHOD_MOCK, &enabled);
1645 LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret);
1646 if (ret == LOCATIONS_ERROR_NONE) {
1648 return __convert_error_code(LOCATION_ERROR_SETTING_OFF);
1650 return __convert_error_code(ret);
1653 ret = location_clear_mock_location(handle->object);
1654 return __convert_error_code(ret);