From: kj7.sung Date: Fri, 15 Apr 2016 08:27:30 +0000 (+0900) Subject: Change batch range to support device behavior X-Git-Tag: accepted/tizen/common/20160420.140615^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F66112%2F2;p=platform%2Fcore%2Fapi%2Flocation-manager.git Change batch range to support device behavior Signed-off-by: kj7.sung Change-Id: I573b97bb52f654ab8aff335e644b28827e17df91 --- diff --git a/include/location_internal.h b/include/location_internal.h index 2c5e894..5075c20 100755 --- a/include/location_internal.h +++ b/include/location_internal.h @@ -120,6 +120,7 @@ int __convert_error_code(int code); int __is_gps_supported(void); int __is_gps_satellite_supported(void); int __is_wps_supported(void); +int __is_batch_supported(void); int __is_location_supported(void); int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data); int __unset_callback(_location_event_e type, location_manager_h manager); diff --git a/packaging/capi-location-manager.changes b/packaging/capi-location-manager.changes index 6e5df2a..edaa3b1 100644 --- a/packaging/capi-location-manager.changes +++ b/packaging/capi-location-manager.changes @@ -1,11 +1,24 @@ +[Version] capi-location-manager_0.7.1 +[Date] 15 Apr 2016 +[Title] Change batch range to support device behavior +[Developer] Kyoungjun Sung + +================================================================================ + +[Version] capi-location-manager_0.7.0 +[Date] 21 Jan 2016 +[Title] Added mock location APIs +[Developer] Young-Ae Kang + +================================================================================ + [Version] capi-location-manager_0.6.0 [Date] 29 May 2015 -[Title] [ACR-225][2.4][location-manager][Add] Turn Location setting on or off; enum LOCATIONS_SERVICE_HOST_SETTING_OFF was deleted. +[Title] [ACR-225][2.4][location-manager][Add] Turn Location setting on or off; enum LOCATIONS_SERVICE_HOST_SETTING_OFF was deleted. [Developer] Young-Ae Kang ================================================================================ - [Version] capi-location-manager_0.5.2 [Date] 17 Apr 2015 [Title] Fixed the bug of gps_status_get_nmea(). diff --git a/packaging/capi-location-manager.spec b/packaging/capi-location-manager.spec index c639022..cc34a63 100644 --- a/packaging/capi-location-manager.spec +++ b/packaging/capi-location-manager.spec @@ -1,6 +1,6 @@ Name: capi-location-manager Summary: A Location Manager library in Tizen Native API -Version: 0.7.0 +Version: 0.7.1 Release: 1 Group: Location/API License: Apache-2.0 diff --git a/src/location_batch.c b/src/location_batch.c index 3801ae4..e586609 100644 --- a/src/location_batch.c +++ b/src/location_batch.c @@ -31,9 +31,8 @@ static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer us LOCATIONS_LOGD("Batch callback function has been invoked."); location_manager_s *handle = (location_manager_s *) userdata; - if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH]) { + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH]) ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]); - } } /*/////////////////////////////////////// */ @@ -43,10 +42,11 @@ static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer us 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) { LOCATIONS_LOGD("location_manager_set_location_batch_cb"); - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported()); - LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); - LOCATIONS_CHECK_CONDITION(batch_period >= 120 && batch_period <= 600, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; @@ -58,33 +58,30 @@ EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager) { LOCATIONS_LOGD("location_manager_unset_location_batch_cb"); - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported()); return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager); } EXPORT_API int location_manager_start_batch(location_manager_h manager) { LOCATIONS_LOGD("location_manager_start_batch"); - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported()); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; if (LOCATIONS_METHOD_GPS == handle->method) { - if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) { + if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle); - } } else { LOCATIONS_LOGE("method is not GPS"); } - if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL) { - LOCATIONS_LOGI("batch status set : Start"); - } + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL) + LOCATIONS_LOGD("batch status set : Start"); int ret = location_start_batch(handle->object); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } return LOCATIONS_ERROR_NONE; } @@ -92,7 +89,7 @@ EXPORT_API int location_manager_start_batch(location_manager_h manager) EXPORT_API int location_manager_stop_batch(location_manager_h manager) { LOCATIONS_LOGD("location_manager_stop_batch"); - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported()); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; @@ -106,9 +103,8 @@ EXPORT_API int location_manager_stop_batch(location_manager_h manager) } int ret = location_stop_batch(handle->object); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } return LOCATIONS_ERROR_NONE; } @@ -116,7 +112,7 @@ EXPORT_API int location_manager_stop_batch(location_manager_h manager) EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data) { LOCATIONS_LOGD("location_manager_foreach_location_batch"); - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); + LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported()); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; @@ -132,8 +128,7 @@ EXPORT_API int location_manager_foreach_location_batch(location_manager_h manage return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; } - LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } @@ -149,9 +144,8 @@ EXPORT_API int location_manager_foreach_location_batch(location_manager_h manage guint timestamp; location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp); - if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE) { + if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE) break; - } } location_batch_free(batch); batch = NULL; diff --git a/src/location_bounds.c b/src/location_bounds.c index 3f16f6f..d39ca3a 100644 --- a/src/location_bounds.c +++ b/src/location_bounds.c @@ -35,17 +35,17 @@ static location_bounds_type_e __convert_bounds_type(LocationBoundaryType type) { location_bounds_type_e ret; switch (type) { - case LOCATION_BOUNDARY_CIRCLE: - ret = LOCATION_BOUNDS_CIRCLE; - break; - case LOCATION_BOUNDARY_POLYGON: - ret = LOCATION_BOUNDS_POLYGON; - break; - case LOCATION_BOUNDARY_NONE: - case LOCATION_BOUNDARY_RECT: - default: - ret = LOCATION_BOUNDS_RECT; - break; + case LOCATION_BOUNDARY_CIRCLE: + ret = LOCATION_BOUNDS_CIRCLE; + break; + case LOCATION_BOUNDARY_POLYGON: + ret = LOCATION_BOUNDS_POLYGON; + break; + case LOCATION_BOUNDARY_NONE: + case LOCATION_BOUNDARY_RECT: + default: + ret = LOCATION_BOUNDS_RECT; + break; } return ret; } @@ -60,13 +60,11 @@ EXPORT_API int location_bounds_create_rect(location_coords_s top_left, location_ LOCATIONS_CHECK_CONDITION(bottom_right.longitude >= -180 && bottom_right.longitude <= 180, LOCATION_BOUNDS_ERROR_INVALID_PARAMETER, "LOCATION_BOUNDS_ERROR_INVALID_PARAMETER"); if ((bottom_right.longitude - top_left.longitude) < 180 && (bottom_right.longitude - top_left.longitude) > -180) { - if (bottom_right.longitude <= top_left.longitude || bottom_right.latitude >= top_left.latitude) { + if (bottom_right.longitude <= top_left.longitude || bottom_right.latitude >= top_left.latitude) return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER; - } } else { - if (bottom_right.latitude >= top_left.latitude) { + if (bottom_right.latitude >= top_left.latitude) return LOCATION_BOUNDS_ERROR_INVALID_PARAMETER; - } } LocationPosition *lt = location_position_new(0, top_left.latitude, top_left.longitude, 0, LOCATION_STATUS_2D_FIX); diff --git a/src/location_internal.c b/src/location_internal.c index b1bd492..0beb7f5 100644 --- a/src/location_internal.c +++ b/src/location_internal.c @@ -25,46 +25,46 @@ int __convert_error_code(int code) int ret; const char *msg = NULL; switch (code) { - case LOCATION_ERROR_NONE: - ret = LOCATIONS_ERROR_NONE; - msg = "LOCATIONS_ERROR_NONE"; - break; - case LOCATION_ERROR_PARAMETER: - ret = LOCATIONS_ERROR_INVALID_PARAMETER; - msg = "LOCATIONS_ERROR_INVALID_PARAMETER"; - break; - case LOCATION_ERROR_NOT_ALLOWED: - ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; - msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"; - break; - case LOCATION_ERROR_NOT_SUPPORTED: - ret = LOCATIONS_ERROR_NOT_SUPPORTED; - msg = "LOCATIONS_ERROR_NOT_SUPPORTED"; - break; - case LOCATION_ERROR_NETWORK_FAILED: - case LOCATION_ERROR_NETWORK_NOT_CONNECTED: - ret = LOCATIONS_ERROR_NETWORK_FAILED; - msg = "LOCATIONS_ERROR_NETWORK_FAILED"; - break; - case LOCATION_ERROR_SETTING_OFF: - ret = LOCATIONS_ERROR_SETTING_OFF; - msg = "LOCATIONS_ERROR_SETTING_OFF"; - break; - case LOCATION_ERROR_SECURITY_DENIED: - ret = LOCATIONS_ERROR_SECURITY_RESTRICTED; - msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED"; - break; - case LOCATION_ERROR_NOT_AVAILABLE: - case LOCATION_ERROR_CONFIGURATION: - case LOCATION_ERROR_UNKNOWN: - default: - msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE"; - ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; + case LOCATION_ERROR_NONE: + ret = LOCATIONS_ERROR_NONE; + msg = "LOCATIONS_ERROR_NONE"; + break; + case LOCATION_ERROR_PARAMETER: + ret = LOCATIONS_ERROR_INVALID_PARAMETER; + msg = "LOCATIONS_ERROR_INVALID_PARAMETER"; + break; + case LOCATION_ERROR_NOT_ALLOWED: + ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; + msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"; + break; + case LOCATION_ERROR_NOT_SUPPORTED: + ret = LOCATIONS_ERROR_NOT_SUPPORTED; + msg = "LOCATIONS_ERROR_NOT_SUPPORTED"; + break; + case LOCATION_ERROR_NETWORK_FAILED: + case LOCATION_ERROR_NETWORK_NOT_CONNECTED: + ret = LOCATIONS_ERROR_NETWORK_FAILED; + msg = "LOCATIONS_ERROR_NETWORK_FAILED"; + break; + case LOCATION_ERROR_SETTING_OFF: + ret = LOCATIONS_ERROR_SETTING_OFF; + msg = "LOCATIONS_ERROR_SETTING_OFF"; + break; + case LOCATION_ERROR_SECURITY_DENIED: + ret = LOCATIONS_ERROR_SECURITY_RESTRICTED; + msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED"; + break; + case LOCATION_ERROR_NOT_AVAILABLE: + case LOCATION_ERROR_CONFIGURATION: + case LOCATION_ERROR_UNKNOWN: + default: + msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE"; + ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code); - } + return ret; } @@ -74,12 +74,12 @@ int __is_gps_supported(void) int retval = 0; retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps", &is_supported); - if (retval != SYSTEM_INFO_ERROR_NONE) { + if (retval != SYSTEM_INFO_ERROR_NONE) LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval); - } - if (is_supported == false) { + + if (is_supported == false) return LOCATIONS_ERROR_NOT_SUPPORTED; - } + return LOCATIONS_ERROR_NONE; } @@ -89,12 +89,12 @@ int __is_gps_satellite_supported(void) int retval = 0; retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps.satellite", &is_supported); - if (retval != SYSTEM_INFO_ERROR_NONE) { + if (retval != SYSTEM_INFO_ERROR_NONE) LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval); - } - if (is_supported == false) { + + if (is_supported == false) return LOCATIONS_ERROR_NOT_SUPPORTED; - } + return LOCATIONS_ERROR_NONE; } @@ -104,28 +104,42 @@ int __is_wps_supported(void) int retval = 0; retval = system_info_get_platform_bool("http://tizen.org/feature/location.wps", &is_supported); - if (retval != SYSTEM_INFO_ERROR_NONE) { + if (retval != SYSTEM_INFO_ERROR_NONE) LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval); - } - if (is_supported == false) { + + if (is_supported == false) return LOCATIONS_ERROR_NOT_SUPPORTED; - } + return LOCATIONS_ERROR_NONE; } int __is_location_supported(void) { if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) { - if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) { + if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) return LOCATIONS_ERROR_NOT_SUPPORTED; - } else { + else return LOCATIONS_ERROR_NONE; - } } return LOCATIONS_ERROR_NONE; } +int __is_batch_supported(void) +{ + bool is_supported = false; + int retval = 0; + + retval = system_info_get_platform_bool("http://tizen.org/feature/location.batch", &is_supported); + if (retval != SYSTEM_INFO_ERROR_NONE) + LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval); + + if (is_supported == false) + return LOCATIONS_ERROR_NOT_SUPPORTED; + + return LOCATIONS_ERROR_NONE; +} + int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data) { LOCATIONS_NULL_ARG_CHECK(manager); diff --git a/src/locations.c b/src/locations.c index 786484a..3b094bf 100755 --- a/src/locations.c +++ b/src/locations.c @@ -27,18 +27,18 @@ static location_method_e __convert_location_method_e(LocationMethod method) { location_method_e _method = LOCATIONS_METHOD_NONE; switch (method) { - case LOCATION_METHOD_HYBRID: - _method = LOCATIONS_METHOD_HYBRID; - break; - case LOCATION_METHOD_GPS: - _method = LOCATIONS_METHOD_GPS; - break; - case LOCATION_METHOD_WPS: - _method = LOCATIONS_METHOD_WPS; - break; - case LOCATION_METHOD_NONE: - default: - break; + case LOCATION_METHOD_HYBRID: + _method = LOCATIONS_METHOD_HYBRID; + break; + case LOCATION_METHOD_GPS: + _method = LOCATIONS_METHOD_GPS; + break; + case LOCATION_METHOD_WPS: + _method = LOCATIONS_METHOD_WPS; + break; + case LOCATION_METHOD_NONE: + default: + break; } return _method; } @@ -47,22 +47,22 @@ static LocationMethod __convert_LocationMethod(location_method_e method) { LocationMethod _method = LOCATION_METHOD_NONE; switch (method) { - case LOCATIONS_METHOD_HYBRID: - _method = LOCATION_METHOD_HYBRID; - break; - case LOCATIONS_METHOD_GPS: - _method = LOCATION_METHOD_GPS; - break; - case LOCATIONS_METHOD_WPS: - _method = LOCATION_METHOD_WPS; - break; - case LOCATIONS_METHOD_MOCK: - _method = LOCATION_METHOD_MOCK; - break; - case LOCATIONS_METHOD_NONE: - default: - _method = LOCATION_METHOD_NONE; - break; + case LOCATIONS_METHOD_HYBRID: + _method = LOCATION_METHOD_HYBRID; + break; + case LOCATIONS_METHOD_GPS: + _method = LOCATION_METHOD_GPS; + break; + case LOCATIONS_METHOD_WPS: + _method = LOCATION_METHOD_WPS; + break; + case LOCATIONS_METHOD_MOCK: + _method = LOCATION_METHOD_MOCK; + break; + case LOCATIONS_METHOD_NONE: + default: + _method = LOCATION_METHOD_NONE; + break; } return _method; } @@ -164,9 +164,8 @@ static void __cb_service_status_changed(GObject *self, guint status, gpointer us static int __compare_position(gconstpointer a, gconstpointer b) { - if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) { + if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) return 0; - } return -1; } @@ -177,64 +176,63 @@ static int __boundary_compare(LocationBoundary *bound1, LocationBoundary *bound2 if (bound1->type == bound2->type) { switch (bound1->type) { - case LOCATION_BOUNDARY_CIRCLE: - if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) { - ret = 0; - } - break; - case LOCATION_BOUNDARY_RECT: - if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) { - ret = 0; - } - break; - case LOCATION_BOUNDARY_POLYGON: { - GList *boundary1_next = NULL; - GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; - if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) { - return -1; - } - - boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position); - if (boundary2_start == NULL) return -1; + case LOCATION_BOUNDARY_CIRCLE: + if (location_position_equal(bound1->circle.center, bound2->circle.center) && bound1->circle.radius == bound2->circle.radius) + ret = 0; - boundary2_prev = g_list_previous(boundary2_start); - boundary2_next = g_list_next(boundary2_start); + break; + case LOCATION_BOUNDARY_RECT: + if (location_position_equal(bound1->rect.left_top, bound2->rect.left_top) && location_position_equal(bound1->rect.right_bottom, bound2->rect.right_bottom)) + ret = 0; - if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list); - if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list); + break; + case LOCATION_BOUNDARY_POLYGON: { + GList *boundary1_next = NULL; + GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL; + if (g_list_length(bound1->polygon.position_list) != g_list_length(bound2->polygon.position_list)) + return -1; + + boundary2_start = g_list_find_custom(bound2->polygon.position_list, g_list_nth_data(bound1->polygon.position_list, 0), (GCompareFunc) __compare_position); + if (boundary2_start == NULL) return -1; + + boundary2_prev = g_list_previous(boundary2_start); + boundary2_next = g_list_next(boundary2_start); + + if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list); + if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list); + + boundary1_next = g_list_next(bound1->polygon.position_list); + if (boundary1_next != NULL && boundary2_prev != NULL && + location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) { + boundary1_next = g_list_next(boundary1_next); + while (boundary1_next) { + boundary2_prev = g_list_previous(boundary2_prev); + if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list); + if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) + return -1; - boundary1_next = g_list_next(bound1->polygon.position_list); - if (boundary1_next != NULL && boundary2_prev != NULL && - location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) { boundary1_next = g_list_next(boundary1_next); - while (boundary1_next) { - boundary2_prev = g_list_previous(boundary2_prev); - if (boundary2_prev == NULL) boundary2_prev = g_list_last(bound2->polygon.position_list); - if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) { - return -1; - } - boundary1_next = g_list_next(boundary1_next); - } - ret = 0; - } else if (boundary1_next != NULL && boundary2_next != NULL && - location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) { + } + ret = 0; + } else if (boundary1_next != NULL && boundary2_next != NULL && + location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) { + boundary1_next = g_list_next(boundary1_next); + while (boundary1_next) { + boundary2_next = g_list_next(boundary2_next); + if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list); + if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) + return -1; + boundary1_next = g_list_next(boundary1_next); - while (boundary1_next) { - boundary2_next = g_list_next(boundary2_next); - if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list); - if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) { - return -1; - } - boundary1_next = g_list_next(boundary1_next); - } - ret = 0; - } else { - return -1; } - break; + ret = 0; + } else { + return -1; } - default: break; + } + default: + break; } } return ret; @@ -259,9 +257,9 @@ static void __cb_zone_in(GObject *self, gpointer boundary, gpointer position, gp bounds = (location_bounds_s *)bounds_list->data; if (__boundary_compare(boundary, bounds->boundary) == 0) { LOCATIONS_LOGD("Find zone in boundary"); - if (bounds->user_cb) { + if (bounds->user_cb) ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_IN, bounds->user_data); - } + break; } bounds_list = g_list_next(bounds_list); @@ -288,9 +286,9 @@ static void __cb_zone_out(GObject *self, gpointer boundary, gpointer position, g bounds = (location_bounds_s *)bounds_list->data; if (__boundary_compare(boundary, bounds->boundary) == 0) { LOCATIONS_LOGD("Find zone out boundary"); - if (bounds->user_cb) { + if (bounds->user_cb) ((location_bounds_state_changed_cb) bounds->user_cb)(LOCATIONS_BOUNDARY_OUT, bounds->user_data); - } + break; } bounds_list = g_list_next(bounds_list); @@ -364,9 +362,8 @@ static void __setting_changed_cb(LocationMethod method, gboolean enable, void *u return; } - if (_setting_changed[_method].callback != NULL) { + if (_setting_changed[_method].callback != NULL) _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data); - } } /*/////////////////////////////////////// */ @@ -423,9 +420,8 @@ EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool return LOCATIONS_ERROR_INCORRECT_METHOD; return __convert_error_code(ret); } - if (is_enabled_val == -1) { + if (is_enabled_val == -1) return TIZEN_ERROR_PERMISSION_DENIED; - } *enable = (is_enabled_val == 0) ? FALSE : TRUE; return LOCATIONS_ERROR_NONE; @@ -580,9 +576,9 @@ EXPORT_API int location_manager_destroy(location_manager_h manager) } int ret = location_free(handle->object); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) return __convert_error_code(ret); - } + free(handle); return LOCATIONS_ERROR_NONE; } @@ -613,9 +609,9 @@ EXPORT_API int location_manager_start(location_manager_h manager) } int ret = location_start(handle->object); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + return LOCATIONS_ERROR_NONE; } @@ -637,14 +633,13 @@ EXPORT_API int location_manager_request_single_location(location_manager_h manag handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED] = g_signal_connect(handle->object, "location-updated", G_CALLBACK(__cb_location_updated), handle); ret = __set_callback(_LOCATIONS_EVENT_TYPE_LOCATION, manager, callback, user_data); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) return ret; - } ret = location_request_single_location(handle->object, timeout); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + return LOCATIONS_ERROR_NONE; } @@ -674,9 +669,9 @@ EXPORT_API int location_manager_stop(location_manager_h manager) } int ret = location_stop(handle->object); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + return LOCATIONS_ERROR_NONE; } @@ -690,9 +685,9 @@ EXPORT_API int location_manager_add_boundary(location_manager_h manager, locatio location_manager_s *handle = (location_manager_s *) manager; location_bounds_s *bound_handle = (location_bounds_s *) bounds; int ret = location_boundary_add(handle->object, bound_handle->boundary); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + bound_handle->is_added = TRUE; handle->bounds_list = g_list_append(handle->bounds_list, bound_handle); return LOCATIONS_ERROR_NONE; @@ -708,9 +703,9 @@ EXPORT_API int location_manager_remove_boundary(location_manager_h manager, loca location_manager_s *handle = (location_manager_s *) manager; location_bounds_s *bound_handle = (location_bounds_s *) bounds; int ret = location_boundary_remove(handle->object, bound_handle->boundary); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + handle->bounds_list = g_list_remove(handle->bounds_list, bound_handle); bound_handle->is_added = FALSE; return LOCATIONS_ERROR_NONE; @@ -728,9 +723,9 @@ EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, loc handle->user_data[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS] = user_data; handle->is_continue_foreach_bounds = TRUE; int ret = location_boundary_foreach(handle->object, __foreach_boundary, handle); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } + return LOCATIONS_ERROR_NONE; } @@ -745,26 +740,25 @@ EXPORT_API int location_manager_get_method(location_manager_h manager, location_ LocationMethod _method = LOCATION_METHOD_NONE; g_object_get(handle->object, "method", &_method, NULL); switch (_method) { - case LOCATION_METHOD_NONE: - *method = LOCATIONS_METHOD_NONE; - break; - case LOCATION_METHOD_HYBRID: - *method = LOCATIONS_METHOD_HYBRID; - break; - case LOCATION_METHOD_GPS: - *method = LOCATIONS_METHOD_GPS; - break; - case LOCATION_METHOD_WPS: - *method = LOCATIONS_METHOD_WPS; - break; - case LOCATION_METHOD_MOCK: - *method = LOCATIONS_METHOD_MOCK; - break; - default: { - LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ", - LOCATIONS_ERROR_INVALID_PARAMETER, method); - return LOCATIONS_ERROR_INVALID_PARAMETER; - } + case LOCATION_METHOD_NONE: + *method = LOCATIONS_METHOD_NONE; + break; + case LOCATION_METHOD_HYBRID: + *method = LOCATIONS_METHOD_HYBRID; + break; + case LOCATION_METHOD_GPS: + *method = LOCATIONS_METHOD_GPS; + break; + case LOCATION_METHOD_WPS: + *method = LOCATIONS_METHOD_WPS; + break; + case LOCATION_METHOD_MOCK: + *method = LOCATIONS_METHOD_MOCK; + break; + default: { + LOCATIONS_LOGE("[LOCATIONS_ERROR_INVALID_PARAMETER] method : %d ", method); + return LOCATIONS_ERROR_INVALID_PARAMETER; + } } return LOCATIONS_ERROR_NONE; } @@ -785,9 +779,8 @@ EXPORT_API int location_manager_get_position(location_manager_h manager, double LocationPosition *pos = NULL; LocationAccuracy *acc = NULL; ret = location_get_position(handle->object, &pos, &acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } if (pos->status == LOCATION_STATUS_NO_FIX) { return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; @@ -824,9 +817,8 @@ EXPORT_API int location_manager_get_location(location_manager_h manager, double LocationVelocity *vel = NULL; LocationAccuracy *acc = NULL; ret = location_get_position_ext(handle->object, &pos, &vel, &acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } if (pos->status == LOCATION_STATUS_NO_FIX) { return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE); @@ -864,9 +856,8 @@ EXPORT_API int location_manager_get_velocity(location_manager_h manager, double LocationVelocity *vel = NULL; LocationAccuracy *acc = NULL; ret = location_get_velocity(handle->object, &vel, &acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } *climb = vel->climb; *direction = vel->direction; @@ -892,13 +883,11 @@ EXPORT_API int location_manager_get_accuracy(location_manager_h manager, locatio LocationPosition *pos = NULL; LocationAccuracy *acc = NULL; ret = location_get_position(handle->object, &pos, &acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } - if (acc == NULL) { + if (acc == NULL) return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE); - } *level = acc->level; *horizontal = acc->horizontal_accuracy; @@ -924,9 +913,8 @@ EXPORT_API int location_manager_get_last_position(location_manager_h manager, do LocationPosition *last_pos = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_position(handle->object, &last_pos, &last_acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } if (last_pos->status == LOCATION_STATUS_NO_FIX) { return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; @@ -964,9 +952,8 @@ EXPORT_API int location_manager_get_last_location(location_manager_h manager, do LocationVelocity *last_vel = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_position_ext(handle->object, &last_pos, &last_vel, &last_acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } if (last_pos->status == LOCATION_STATUS_NO_FIX) { return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; @@ -1004,9 +991,8 @@ EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, do LocationVelocity *last_vel = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_velocity(handle->object, &last_vel, &last_acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } *climb = last_vel->climb; *direction = last_vel->direction; @@ -1031,9 +1017,8 @@ EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, lo LocationPosition *last_pos = NULL; LocationAccuracy *last_acc = NULL; ret = location_get_last_position(handle->object, &last_pos, &last_acc); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } *level = last_acc->level; *horizontal = last_acc->horizontal_accuracy; @@ -1058,16 +1043,16 @@ EXPORT_API int location_manager_get_accessibility_state(location_accessibility_s } switch (auth) { - case LOCATION_ACCESS_DENIED: - *state = LOCATIONS_ACCESS_STATE_DENIED; - break; - case LOCATION_ACCESS_ALLOWED: - *state = LOCATIONS_ACCESS_STATE_ALLOWED; - break; - case LOCATION_ACCESS_NONE: - default: - *state = LOCATIONS_ACCESS_STATE_NONE; - break; + case LOCATION_ACCESS_DENIED: + *state = LOCATIONS_ACCESS_STATE_DENIED; + break; + case LOCATION_ACCESS_ALLOWED: + *state = LOCATIONS_ACCESS_STATE_ALLOWED; + break; + case LOCATION_ACCESS_NONE: + default: + *state = LOCATIONS_ACCESS_STATE_NONE; + break; } return LOCATIONS_ERROR_NONE; @@ -1189,17 +1174,15 @@ EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, LocationMethod _method = __convert_LocationMethod(method); int ret = LOCATION_ERROR_NONE; - if (_method == LOCATION_METHOD_NONE) { + if (_method == LOCATION_METHOD_NONE) return __convert_error_code(LOCATION_ERROR_PARAMETER); - } g_location_setting[_method].callback = callback; g_location_setting[_method].user_data = user_data; ret = location_add_setting_notify(_method, __setting_changed_cb, &g_location_setting); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } return LOCATIONS_ERROR_NONE; } @@ -1211,9 +1194,8 @@ EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e metho LocationMethod _method = __convert_LocationMethod(method); int ret = LOCATION_ERROR_NONE; - if (_method == LOCATION_METHOD_NONE) { + if (_method == LOCATION_METHOD_NONE) return __convert_error_code(LOCATION_ERROR_PARAMETER); - } ret = location_ignore_setting_notify(_method, __setting_changed_cb); if (ret != LOCATION_ERROR_NONE) { @@ -1244,9 +1226,8 @@ EXPORT_API int location_manager_get_distance(double start_latitude, double start LocationPosition *end = location_position_new(0, end_latitude, end_longitude, 0, LOCATION_STATUS_2D_FIX); ret = location_get_distance(start, end, &u_distance); - if (ret != LOCATION_ERROR_NONE) { + if (ret != LOCATION_ERROR_NONE) return __convert_error_code(ret); - } *distance = (double)u_distance; @@ -1441,9 +1422,8 @@ EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h man guint azimuth; gint snr; location_satellite_get_satellite_details(last_sat, i, &prn, &used, &elevation, &azimuth, &snr); - if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) { + if (callback(azimuth, elevation, prn, snr, used, user_data) != TRUE) break; - } } location_satellite_free(last_sat); return LOCATIONS_ERROR_NONE; @@ -1483,10 +1463,8 @@ EXPORT_API int location_manager_set_mock_location(location_manager_h manager, co ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled); LOCATIONS_LOGD("enable: %d, ret: %d", enabled, ret); if (ret == LOCATIONS_ERROR_NONE) { - if (enabled == 0) { + if (enabled == 0) return __convert_error_code(LOCATION_ERROR_SETTING_OFF); - } - } else { return __convert_error_code(ret); } @@ -1524,9 +1502,8 @@ EXPORT_API int location_manager_clear_mock_location(location_manager_h manager) ret = location_is_enabled_method(LOCATION_METHOD_MOCK, &enabled); if (ret == LOCATIONS_ERROR_NONE) { - if (enabled == 0) { + if (enabled == 0) return __convert_error_code(LOCATION_ERROR_SETTING_OFF); - } } else { return __convert_error_code(ret); } @@ -1534,89 +1511,3 @@ EXPORT_API int location_manager_clear_mock_location(location_manager_h manager) ret = location_clear_mock_location(handle->object); return __convert_error_code(ret); } - - -#if 0 -/** - * @brief Gets the state of location service. - * @since_tizen 3.0 - * @param[in] manager The location manager handle - * @param[out] state The current state of location service - * @return 0 on success, otherwise a negative error value - * @retval #LOCATIONS_ERROR_NONE Successful - * @retval #LOCATIONS_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #LOCATIONS_ERROR_NOT_SUPPORTED Not supported - * @see location_manager_create() - * @see location_manager_set_setting_changed_cb() - * @see location_manager_unset_setting_changed_cb() - */ -int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state); - -EXPORT_API int location_manager_get_service_state(location_manager_h manager, location_service_state_e *state) -{ - LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported()); - LOCATIONS_NULL_ARG_CHECK(manager); - LOCATIONS_NULL_ARG_CHECK(state); - - location_manager_s *handle = (location_manager_s *) manager; - - int service_state = -1; - - int ret = location_get_service_state(handle->object, &service_state); - if (ret != LOCATION_ERROR_NONE) { - if (ret == LOCATION_ERROR_NOT_SUPPORTED) - return LOCATIONS_ERROR_INCORRECT_METHOD; - return __convert_error_code(ret); - } - - switch (service_state) { - case -1: - ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; - *state = LOCATIONS_SERVICE_DISABLED; - break; - case 0: - *state = LOCATIONS_SERVICE_DISABLED; - break; - case 1: - *state = LOCATIONS_SERVICE_ENABLED; - break; - default: - *state = LOCATIONS_SERVICE_ERROR; - break; - - } - - return ret; -} - -EXPORT_API int location_add_test_provider(const LocationMethod method, const int enable) -{ - int ret = 0; - char *_key = NULL; - -#ifndef TIZEN_PROFILE_TV - ret = location_check_privilege(LOCATION_ENABLE_PRIVILEGE); - if (ret != LOCATION_ERROR_NONE) { - LOCATION_LOGE("Cannot use location service for privacy[%d]", ret); - return LOCATION_ERROR_NOT_ALLOWED; - } -#endif - - if (method == LOCATION_METHOD_MOCK) { - _key = __convert_setting_key(method); - if (!_key) { - LOCATION_LOGE("Invalid method[%d]", method); - return LOCATION_ERROR_NOT_SUPPORTED; - } - ret = vconf_set_int(_key, enable); - if (ret != VCONF_OK) { - LOCATION_SECLOG("vconf_set_int failed [%s], ret=[%d]", _key, ret); - g_free(_key); - return LOCATION_ERROR_NOT_ALLOWED; - } - - g_free(_key); - } - return ret; -} -#endif diff --git a/test/location_test.c b/test/location_test.c index 6def155..e86eca2 100755 --- a/test/location_test.c +++ b/test/location_test.c @@ -54,8 +54,7 @@ static gboolean wait_test() } #if 0 -void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, - void *user_data) +void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp, void *user_data) { if (state == LOCATIONS_BOUNDARY_IN) { fprintf(stderr, "Entering zone\n"); @@ -68,8 +67,7 @@ void zone_event_cb(location_boundary_state_e state, double latitude, double long fprintf(stderr, "Time: %s\n", ctime(×tamp)); } -static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, - void *user_data) +static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use, void *user_data) { fprintf(stderr, "[Last Satellite information] azimuth : %d, elevation: %d, prn: %d, snr: %d, used: %d\n", azimuth, elevation, prn, snr, is_in_use); @@ -93,15 +91,14 @@ static bool __location_bounds_cb(location_bounds_h bounds, void *user_data) location_coords_s center; double radius; location_bounds_get_circle_coords(bounds, ¢er, &radius); - fprintf(stderr, "location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center.latitude, - center.longitude, radius); + fprintf(stderr, "location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center.latitude, center.longitude, radius); } else if (type == LOCATION_BOUNDS_RECT) { location_coords_s left_top; location_coords_s right_bottom; location_bounds_get_rect_coords(bounds, &left_top, &right_bottom); fprintf(stderr, "location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n", - left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude); + left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude); } else if (type == LOCATION_BOUNDS_POLYGON) { location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL); } @@ -118,15 +115,15 @@ void location_bounds_test() double radius = 30; location_bounds_h bounds_circle; ret = location_bounds_create_circle(center, radius, &bounds_circle); - if (ret != LOCATION_BOUNDS_ERROR_NONE) { + if (ret != LOCATION_BOUNDS_ERROR_NONE) fprintf(stderr, "location_bounds_create_circle() failed\n"); - } else + else fprintf(stderr, "Bounds(circle) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_circle); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, "Setting boundary failed\n"); - } else + else fprintf(stderr, "Boundary set\n"); location_coords_s center2; @@ -136,7 +133,7 @@ void location_bounds_test() fprintf(stderr, "location_bounds_get_circle_coords() failed\n"); } else fprintf(stderr, "location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center2.latitude, - center2.longitude, radius2); + center2.longitude, radius2); /*Add the rect bounds */ location_coords_s left_top; @@ -149,15 +146,15 @@ void location_bounds_test() location_bounds_h bounds_rect; ret = location_bounds_create_rect(left_top, right_bottom, &bounds_rect); - if (ret != LOCATION_BOUNDS_ERROR_NONE) { + if (ret != LOCATION_BOUNDS_ERROR_NONE) fprintf(stderr, "location_bounds_create_rect() failed\n"); - } else + else fprintf(stderr, "Bounds(rect) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_rect); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, "Setting boundary failed\n"); - } else + else fprintf(stderr, "Boundary set\n"); location_coords_s left_top2; @@ -168,7 +165,7 @@ void location_bounds_test() fprintf(stderr, "location_bounds_get_rect_coords() failed\n"); } else fprintf(stderr, "location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n", left_top2.latitude, - left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude); + left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude); /*Add the polygon bounds */ @@ -184,21 +181,20 @@ void location_bounds_test() location_bounds_h bounds_poly; ret = location_bounds_create_polygon(coord_list, poly_size, &bounds_poly); - if (ret != LOCATION_BOUNDS_ERROR_NONE) { + if (ret != LOCATION_BOUNDS_ERROR_NONE) fprintf(stderr, "location_bounds_create_polygon() failed\n"); - } else + else fprintf(stderr, "Bounds(polygon) has been created successfully.\n"); ret = location_manager_add_boundary(manager, bounds_poly); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, "Setting boundary failed\n"); - } else + else fprintf(stderr, "Boundary set\n"); ret = location_bounds_foreach_polygon_coords(bounds_poly, __poly_coords_cb, NULL); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, "location_bounds_get_rect_coords() failed\n"); - } location_coords_s test_coords; test_coords.latitude = 12; @@ -211,9 +207,8 @@ void location_bounds_test() /*print current bounds */ ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, "location_manager_foreach_boundary() failed\n"); - } } @@ -228,37 +223,32 @@ void location_get_last_information_test() int num_of_inview, num_of_active; ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, ×tamp); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_last_position ---> %d \n", ret); - } else { + else fprintf(stderr, "[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude); - } ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, ×tamp); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_last_velocity ---> %d \n", ret); - } else { + else fprintf(stderr, "climb: %f, direction: %f, speed: %f\n", climb, direction, speed); - } ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_last_accuracy ---> %d \n", ret); - } else { + else fprintf(stderr, "Level: %d, horizontal: %g, vertical: %g\n", level, horizontal, vertical); - } ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, ×tamp); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: gps_status_get_last_satellite_count_in_view ---> %d \n", ret); - } else { + else fprintf(stderr, "[%ld] Satellite number of active: %d, in view: %d\n", timestamp, num_of_active, num_of_inview); - } ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: gps_status_foreach_last_satellites_in_view ---> %d \n", ret); - } } #endif @@ -273,21 +263,19 @@ static void _state_change_cb(location_service_state_e state, void *user_data) double longitude; time_t timestamp; ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, ×tamp); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_position ---> %d \n", ret); - } else { + else fprintf(stderr, "[%ld] lat: %f, lng: %f, alt: %f\n", timestamp, latitude, longitude, altitude); - } location_accuracy_level_e level; double horizontal; double vertical; ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret); - } else { + else fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical); - } #if 0 char *nmea; ret = gps_status_get_nmea(lm, &nmea); @@ -312,17 +300,15 @@ void _position_updated_cb(double latitude, double longitude, double altitude, ti double horizontal; double vertical; int ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) fprintf(stderr, " Fail: location_manager_get_accuracy ---> %d \n", ret); - } else { + else fprintf(stderr, "Level: %d, horizontal: %f, vertical %f\n", level, horizontal, vertical); - } repeat_count++; - if (repeat_count > 9) { + if (repeat_count > 9) test_timer = g_timeout_add_seconds(1, wait_test, NULL); - } } void _velocity_updated_cb(double speed, double direction, double climb, time_t timestamp, void *user_data) @@ -347,9 +333,9 @@ void _location_changed_cb(double latitude, double longitude, double altitude, do repeat_count++; - if (repeat_count > 5) { + if (repeat_count > 5) test_timer = g_timeout_add_seconds(1, wait_test, NULL); - } + } bool _get_location_cb(double latitude, double longitude, double altitude, double speed, double direction, double horizontal, double vertical, time_t timestamp, void *user_data) @@ -366,14 +352,13 @@ void _location_batch_cb(int num_of_location, void *user_data) location_manager_h manager = user_data; - if (num_of_location > 0) { + if (num_of_location > 0) location_manager_foreach_location_batch(manager, _get_location_cb, user_data); - } + repeat_count++; - if (repeat_count > 1) { + if (repeat_count > 1) test_timer = g_timeout_add_seconds(1, wait_test, NULL); - } } static void _setting_cb(location_method_e method, bool enable, void *user_data) @@ -452,9 +437,8 @@ static int test_set_mock_location(gpointer user_data) ret = location_manager_set_mock_location(manager, 20, 20, 0, 40, 50, 100); fprintf(stderr, "\n==== location_manager_set_location: %d ====\n\n", ret); - if (ret != LOCATIONS_ERROR_NONE) { + if (ret != LOCATIONS_ERROR_NONE) g_timeout_add_seconds(3, test_clear_mock_location, manager); - } return FALSE; } @@ -483,9 +467,8 @@ static void print_menu() fprintf(stderr, "[0] Exit!!!\n\n"); fprintf(stderr, "Select menu: "); - if (scanf("%d", &menu) < 0) { + if (scanf("%d", &menu) < 0) fprintf(stderr, "Can't read menu !!!\n"); - } } static int location_test() @@ -499,202 +482,201 @@ static int location_test() print_menu(); switch (menu) { - case 1: - case 2: - case 3: { - basic = 1; - - int method = menu - 1; - ret = location_manager_create(method, &manager); - fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret); - - ret = location_manager_start(manager); - fprintf(stderr, "start: %d\n", ret); - - if (method == LOCATIONS_METHOD_GPS) { - ret = gps_status_set_satellite_updated_cb(manager, _satellite_updated_cb, 1, &manager); - fprintf(stderr, "gps_status_set_satellite_updated_cb: %d\n", ret); - } - break; - } - case 4: - case 5: - case 6: { - int timeout = 30; - - fprintf(stderr, "\n Input timeout ==> "); - ret = scanf("%d", &timeout); - - int method = menu - 4; - ret = location_manager_create(method, &manager); - ret = location_manager_request_single_location(manager, timeout, _location_cb, manager); - fprintf(stderr, "request single_location (method: %d): %d\n", method, ret); - break; - } - case 11: - case 12: - case 13: { - int interval = 1; - - fprintf(stderr, "\n Input position interval ==> "); - ret = scanf("%d", &interval); + case 1: + case 2: + case 3: { + basic = 1; - int method = menu - 11; - ret = location_manager_create(method, &manager); - fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret); + int method = menu - 1; + ret = location_manager_create(method, &manager); + fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret); - ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); - fprintf(stderr, "set_position_updated_cb: %d\n", ret); + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); - /* - ret = location_manager_set_velocity_updated_cb(manager, _velocity_updated_cb, interval*2, (void *)manager); - fprintf(stderr, "set_velocity_updated_cb: %d\n", ret); - */ + if (method == LOCATIONS_METHOD_GPS) { + ret = gps_status_set_satellite_updated_cb(manager, _satellite_updated_cb, 1, &manager); + fprintf(stderr, "gps_status_set_satellite_updated_cb: %d\n", ret); + } + break; + } + case 4: + case 5: + case 6: { + int timeout = 30; + + fprintf(stderr, "\n Input timeout ==> "); + ret = scanf("%d", &timeout); + + int method = menu - 4; + ret = location_manager_create(method, &manager); + ret = location_manager_request_single_location(manager, timeout, _location_cb, manager); + fprintf(stderr, "request single_location (method: %d): %d\n", method, ret); + break; + } + case 11: + case 12: + case 13: { + int interval = 1; - ret = location_manager_set_location_changed_cb(manager, _location_changed_cb, interval * 2, (void *)manager); - fprintf(stderr, "set_location_changed_cb: %d\n", ret); + fprintf(stderr, "\n Input position interval ==> "); + ret = scanf("%d", &interval); - ret = location_manager_start(manager); - fprintf(stderr, "start: %d\n", ret); - break; - } - case 21: - case 22: - case 23: { - int interval = 1; - int method = menu - 21; + int method = menu - 11; + ret = location_manager_create(method, &manager); + fprintf(stderr, "location_manager_create (method: %d): %d\n", method, ret); - fprintf(stderr, "\n Input position interval ==> "); - ret = scanf("%d", &interval); + ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); + fprintf(stderr, "set_position_updated_cb: %d\n", ret); - ret = location_manager_create(method, &manager); - fprintf(stderr, "location_manager_create (method : %d)", method); + /* + ret = location_manager_set_velocity_updated_cb(manager, _velocity_updated_cb, interval*2, (void *)manager); + fprintf(stderr, "set_velocity_updated_cb: %d\n", ret); + */ - /*ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); */ - /*fprintf(stderr, "set position changed callback: %d\n", ret); */ + ret = location_manager_set_location_changed_cb(manager, _location_changed_cb, interval * 2, (void *)manager); + fprintf(stderr, "set_location_changed_cb: %d\n", ret); - ret = location_manager_set_distance_based_location_changed_cb(manager, _location_changed_cb, interval, 30, (void *)manager); - fprintf(stderr, "set_distance_based_location_changed_cb: %d\n", ret); + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); + break; + } + case 21: + case 22: + case 23: { + int interval = 1; + int method = menu - 21; - ret = location_manager_start(manager); - fprintf(stderr, "start: %d\n", ret); - break; - } - case 31: { - int interval = 1; - fprintf(stderr, "\n Input batch interval ==> "); - ret = scanf("%d", &interval); + fprintf(stderr, "\n Input position interval ==> "); + ret = scanf("%d", &interval); - int period = 60; - fprintf(stderr, " Input batch period ==> "); - ret = scanf("%d", &period); + ret = location_manager_create(method, &manager); + fprintf(stderr, "location_manager_create (method : %d)", method); - ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager); - fprintf(stderr, "location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS); + /*ret = location_manager_set_position_updated_cb(manager, _position_updated_cb, interval, (void *)manager); */ + /*fprintf(stderr, "set position changed callback: %d\n", ret); */ - ret = location_manager_set_location_batch_cb(manager, _location_batch_cb, interval, period, (void *)manager); - fprintf(stderr, "set_location_batch_cb: %d\n", ret); + ret = location_manager_set_distance_based_location_changed_cb(manager, _location_changed_cb, interval, 30, (void *)manager); + fprintf(stderr, "set_distance_based_location_changed_cb: %d\n", ret); - ret = location_manager_start_batch(manager); - fprintf(stderr, "start_batch: %d\n", ret); - break; - } - case 41: { - basic = 1; - int onoff = 1; + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); + break; + } + case 31: { + int interval = 1; + fprintf(stderr, "\n Input batch interval ==> "); + ret = scanf("%d", &interval); - fprintf(stderr, "\n Mock Location (ON: 1 or OFF: 0) Input ==> "); - ret = scanf("%d", &onoff); + int period = 60; + fprintf(stderr, " Input batch period ==> "); + ret = scanf("%d", &period); - ret = location_manager_enable_mock_location(onoff); - fprintf(stderr, "Enabling mock test: ret=%d\n", ret); + ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager); + fprintf(stderr, "location_manager_create (method : %d)\n", LOCATIONS_METHOD_GPS); - ret = location_manager_create(LOCATIONS_METHOD_MOCK, &manager); - fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_MOCK, ret); + ret = location_manager_set_location_batch_cb(manager, _location_batch_cb, interval, period, (void *)manager); + fprintf(stderr, "set_location_batch_cb: %d\n", ret); - ret = location_manager_set_mock_location(manager, 10, 20, 0, 40, 50, 100); - fprintf(stderr, "location_manager_set_mock_location: %d\n", ret); - if (ret == LOCATIONS_ERROR_SETTING_OFF) { - fprintf(stderr, "Setting for Mock Location is turned OFF!!!\n"); - break; - } + ret = location_manager_start_batch(manager); + fprintf(stderr, "start_batch: %d\n", ret); + break; + } + case 41: { + basic = 1; + int onoff = 1; - ret = location_manager_start(manager); - fprintf(stderr, "start: %d\n", ret); + fprintf(stderr, "\n Mock Location (ON: 1 or OFF: 0) Input ==> "); + ret = scanf("%d", &onoff); - g_timeout_add_seconds(3, test_clear_mock_location, manager); + ret = location_manager_enable_mock_location(onoff); + fprintf(stderr, "Enabling mock test: ret=%d\n", ret); - g_timeout_add_seconds(10, wait_test, NULL); + ret = location_manager_create(LOCATIONS_METHOD_MOCK, &manager); + fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_MOCK, ret); + ret = location_manager_set_mock_location(manager, 10, 20, 0, 40, 50, 100); + fprintf(stderr, "location_manager_set_mock_location: %d\n", ret); + if (ret == LOCATIONS_ERROR_SETTING_OFF) { + fprintf(stderr, "Setting for Mock Location is turned OFF!!!\n"); break; } - case 42: { - basic = 1; - ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager); - fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_HYBRID, ret); + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); - ret = location_manager_start(manager); - fprintf(stderr, "start: %d\n", ret); + g_timeout_add_seconds(3, test_clear_mock_location, manager); + g_timeout_add_seconds(10, wait_test, NULL); - /* - int state = 0; - ret = location_manager_get_service_state(manager, &state); - fprintf(stderr, "the current state: %d, ret = %d\n", state, ret); - */ + break; + } + case 42: { + basic = 1; - g_timeout_add_seconds(5, test_set_mock_location, manager); + ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager); + fprintf(stderr, "location_manager_create (method: %d): %d\n", LOCATIONS_METHOD_HYBRID, ret); - break; + ret = location_manager_start(manager); + fprintf(stderr, "start: %d\n", ret); + + /* + int state = 0; + ret = location_manager_get_service_state(manager, &state); + fprintf(stderr, "the current state: %d, ret = %d\n", state, ret); + */ + + g_timeout_add_seconds(5, test_set_mock_location, manager); + + break; + } + case 51: + case 52: + case 53: { + int method = menu - 51; + int onoff = 1; + + fprintf(stderr, "\n Input ON: 1 or OFF: 0 ==> "); + ret = scanf("%d", &onoff); + + if (onoff == 0 || onoff == 1) { + ret = enable_method(method, onoff); + fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret); } - case 51: - case 52: - case 53: { - int method = menu - 51; - int onoff = 1; - - fprintf(stderr, "\n Input ON: 1 or OFF: 0 ==> "); - ret = scanf("%d", &onoff); - - if (onoff == 0 || onoff == 1) { - ret = enable_method(method, onoff); - fprintf(stderr, "Enabling method: [%d], ret=%d\n", method, ret); - } - break; - } - case 61: { - location_bounds_h hPolyLocationBound = NULL; - bool bIsContained = false; - int nPolySize = 3; - location_coords_s location_coord_list[nPolySize]; - location_coord_list[0].latitude = 10; - location_coord_list[0].longitude = 10; - location_coord_list[1].latitude = 20; - location_coord_list[1].longitude = 20; - location_coord_list[2].latitude = 30; - location_coord_list[2].longitude = 10; - - /* Checking coordinates in location boundary */ - location_coords_s testLocationCoordinates; - testLocationCoordinates.latitude = 20; - testLocationCoordinates.longitude = 12; - location_bound_error_e nRet = location_bounds_create_polygon(location_coord_list, nPolySize, &hPolyLocationBound); - - fprintf(stderr, "location_bounds_create_polygon: %d\n", nRet); - - bIsContained = location_bounds_contains_coordinates(hPolyLocationBound, testLocationCoordinates); - fprintf(stderr, "bIsContained: %d\n", bIsContained); - - location_bounds_destroy(hPolyLocationBound); - break; - } - case 0: - g_timeout_add_seconds(1, exit_program, NULL); - return 0; - default: - fprintf(stderr, "Exit!!! Input: %d\n", menu); - g_timeout_add_seconds(1, exit_program, NULL); - return 0; + break; + } + case 61: { + location_bounds_h hPolyLocationBound = NULL; + bool bIsContained = false; + int nPolySize = 3; + location_coords_s location_coord_list[nPolySize]; + location_coord_list[0].latitude = 10; + location_coord_list[0].longitude = 10; + location_coord_list[1].latitude = 20; + location_coord_list[1].longitude = 20; + location_coord_list[2].latitude = 30; + location_coord_list[2].longitude = 10; + + /* Checking coordinates in location boundary */ + location_coords_s testLocationCoordinates; + testLocationCoordinates.latitude = 20; + testLocationCoordinates.longitude = 12; + location_bound_error_e nRet = location_bounds_create_polygon(location_coord_list, nPolySize, &hPolyLocationBound); + + fprintf(stderr, "location_bounds_create_polygon: %d\n", nRet); + + bIsContained = location_bounds_contains_coordinates(hPolyLocationBound, testLocationCoordinates); + fprintf(stderr, "bIsContained: %d\n", bIsContained); + + location_bounds_destroy(hPolyLocationBound); + break; + } + case 0: + g_timeout_add_seconds(1, exit_program, NULL); + return 0; + default: + fprintf(stderr, "Exit!!! Input: %d\n", menu); + g_timeout_add_seconds(1, exit_program, NULL); + return 0; } if (ret != LOCATIONS_ERROR_NONE) {