diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-02-01 13:30:21 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-02-01 13:30:21 +0900 |
commit | 5bd798a6d40b798b464f90efde0b079c20961a73 (patch) | |
tree | 623197fd8a1c961af788aacb578b9f0da1ec5700 /src/locations.c | |
parent | a6e5bd2b3a95c55116a12ad2656e0f55d0a6def3 (diff) | |
download | location-manager-5bd798a6d40b798b464f90efde0b079c20961a73.tar.gz location-manager-5bd798a6d40b798b464f90efde0b079c20961a73.tar.bz2 location-manager-5bd798a6d40b798b464f90efde0b079c20961a73.zip |
tizen 2.3 releasetizen_2.3_releasesubmit/tizen_2.3/20150202.060839tizen_2.3
Diffstat (limited to 'src/locations.c')
-rwxr-xr-x | src/locations.c | 753 |
1 files changed, 593 insertions, 160 deletions
diff --git a/src/locations.c b/src/locations.c index c871165..c369c82 100755 --- a/src/locations.c +++ b/src/locations.c @@ -17,8 +17,15 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <locations_private.h> -#include <location_bounds.h> +#ifdef TIZEN_WEARABLE +#include <unistd.h> +#include <package_manager.h> +#include <app_manager.h> +#include <app_control.h> +#endif +#include "location_internal.h" +#include "location_bounds.h" +#include "location_batch.h" #define LOCATIONS_NULL_ARG_CHECK(arg) \ @@ -28,6 +35,8 @@ * Internal Implementation */ +static location_setting_changed_s g_location_setting[LOCATIONS_METHOD_WPS+1]; + static int __convert_error_code(int code) { int ret; @@ -62,42 +71,115 @@ static int __convert_error_code(int code) msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE"; ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } - LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code); + if (ret != LOCATIONS_ERROR_NONE) + LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code); return ret; } +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; + } + return _method; +} + +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_NONE: + default: + _method = LOCATION_METHOD_NONE; + break; + } + return _method; +} + static void __cb_service_updated(GObject * self, guint type, gpointer data, gpointer accuracy, gpointer userdata) { - LOCATIONS_LOGI("Callback function has been invoked. "); + LOCATIONS_LOGD("Callback function has been invoked. "); location_manager_s *handle = (location_manager_s *) userdata; if (type == VELOCITY_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) { LocationVelocity *vel = (LocationVelocity *) data; - LOCATIONS_LOGI("Current velocity: timestamp : %d", vel->timestamp); + LOCATIONS_LOGD("Current velocity: timestamp : %d", vel->timestamp); ((location_velocity_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY]) (vel->speed, vel->direction, - vel->climb, vel->timestamp, - handle->user_data - [_LOCATIONS_EVENT_TYPE_VELOCITY]); + vel->climb, vel->timestamp, + handle->user_data + [_LOCATIONS_EVENT_TYPE_VELOCITY]); } else if (type == POSITION_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) { LocationPosition *pos = (LocationPosition *) data; - LOCATIONS_LOGI("Current position: timestamp : %d", pos->timestamp); + LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp); ((location_position_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION]) (pos->latitude, pos->longitude, - pos->altitude, pos->timestamp, - handle->user_data - [_LOCATIONS_EVENT_TYPE_POSITION]); + pos->altitude, pos->timestamp, + handle->user_data + [_LOCATIONS_EVENT_TYPE_POSITION]); } else if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) { LocationSatellite *sat = (LocationSatellite *)data; - LOCATIONS_LOGI("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d", - sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview); + LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d", + sat->timestamp, sat->num_of_sat_used, sat->num_of_sat_inview); ((gps_status_satellite_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) (sat->num_of_sat_used, sat->num_of_sat_inview, sat->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_SATELLITE]); } } +static void __cb_location_updated(GObject * self, int error, gpointer position, gpointer velocity, gpointer accuracy, gpointer userdata) +{ + LOCATIONS_LOGD("Callback function has been invoked. "); + int converted_err = __convert_error_code(error); + location_manager_s *handle = (location_manager_s *) userdata; + LocationPosition *pos = (LocationPosition*) position; + LocationVelocity *vel = (LocationVelocity*) velocity; + + LOCATIONS_LOGD("Current position: timestamp : %d", pos->timestamp); + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) { + ((location_updated_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_LOCATION]) (converted_err, pos->latitude, pos->longitude, pos->altitude, + pos->timestamp, vel->speed, vel->climb, vel->direction, handle->user_data[_LOCATIONS_EVENT_TYPE_LOCATION]); + } +} + +#if 0 +static gboolean __cb_single_service_stop(gpointer user_data) +{ + location_manager_s *handle = (location_manager_s *) user_data; + + if (handle->timeout) { + g_source_remove(handle->timeout); + handle->timeout = 0; + } + + location_stop(handle->object); + + return FALSE; +} +#endif + static void __cb_service_enabled(GObject * self, guint status, gpointer userdata) { - LOCATIONS_LOGI("Callback function has been invoked. "); + LOCATIONS_LOGD("Callback function has been invoked. "); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { ((location_service_state_changed_cb) @@ -108,7 +190,7 @@ static void __cb_service_enabled(GObject * self, guint status, gpointer userdata static void __cb_service_disabled(GObject * self, guint status, gpointer userdata) { - LOCATIONS_LOGI("Callback function has been invoked. "); + LOCATIONS_LOGD("Callback function has been invoked. "); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) ((location_service_state_changed_cb) @@ -116,6 +198,86 @@ static void __cb_service_disabled(GObject * self, guint status, gpointer userdat handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); } +#ifdef TIZEN_WEARABLE +static void __show_popup_host_setting_off() +{ + app_control_h app_control_handle = NULL; + int ret; + do { + ret = app_control_create(&app_control_handle); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_create failed. Error %d", ret); + break; + } + + ret = app_control_set_operation(app_control_handle, "http://tizen.org/appcontrol/operation/configure/location"); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_set_operation failed. Error %d", ret); + break; + } + + ret = app_control_set_app_id(app_control_handle, "com.samsung.setting-location"); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_set_app_id failed. Error %d", ret); + break; + } + + ret = app_control_add_extra_data(app_control_handle, "popup", "provider_setting_off"); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_add_extra_data failed. Error %d", ret); + break; + } + + ret = app_control_send_launch_request(app_control_handle, NULL, NULL); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_send_launch_request failed. Error %d", ret); + break; + } + } while(0); + + if (app_control_handle != NULL) { + ret = app_control_destroy(app_control_handle); + if (ret != APP_CONTROL_ERROR_NONE) { + LOCATIONS_LOGD("app_control_destroy failed. Error %d", ret); + } + } +} + +static void __cb_service_error_emitted(GObject * self, guint error_code, gpointer userdata) +{ + LOCATIONS_LOGD("Error[%d] Callback function has been invoked. ", error_code); + location_manager_s *handle = (location_manager_s *) userdata; + const char *svoice = "com.samsung.svoice"; + + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) { + switch (error_code) { + case LOCATION_ERROR_SETTING_OFF: { + pid_t pid = 0; + char *app_id = NULL; + int ret = 0; + + pid = getpid(); + ret = app_manager_get_app_id (pid, &app_id); + if (ret == APP_MANAGER_ERROR_NONE && app_id && strncmp(app_id, svoice, strlen(svoice)) != 0) { + __show_popup_host_setting_off(); + } else { + LOCATIONS_LOGD("########## SVoice ################"); + } + ((location_service_state_changed_cb)handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) + (LOCATIONS_SERVICE_HOST_SETTING_OFF, + handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]); + break; + } + + default: { + break; + } + } + } + +} +#endif + static int __compare_position (gconstpointer a, gconstpointer b) { if(location_position_equal((LocationPosition*) a, (LocationPosition *)b) == TRUE) { @@ -158,7 +320,8 @@ static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * boun if (boundary2_next == NULL) boundary2_next = g_list_first(bound2->polygon.position_list); boundary1_next = g_list_next(bound1->polygon.position_list); - if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_prev->data) == TRUE) { + 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); @@ -169,7 +332,8 @@ static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * boun boundary1_next = g_list_next(boundary1_next); } ret = 0; - } else if (location_position_equal((LocationPosition*)boundary1_next->data, (LocationPosition*)boundary2_next->data) == TRUE) { + } 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); @@ -194,15 +358,15 @@ static int __boundary_compare(LocationBoundary * bound1, LocationBoundary * boun static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata) { - LOCATIONS_LOGI("Callback function has been invoked."); + LOCATIONS_LOGD("Callback function has been invoked."); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) { LocationPosition *pos = (LocationPosition *) position; ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_IN, - pos->latitude, pos->longitude, - pos->altitude, pos->timestamp, - handle->user_data - [_LOCATIONS_EVENT_TYPE_BOUNDARY]); + pos->latitude, pos->longitude, + pos->altitude, pos->timestamp, + handle->user_data + [_LOCATIONS_EVENT_TYPE_BOUNDARY]); } location_bounds_s *bounds; @@ -210,7 +374,7 @@ static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, g while (bounds_list) { bounds = (location_bounds_s *)bounds_list->data; if (__boundary_compare(boundary, bounds->boundary) == 0) { - LOCATIONS_LOGI("Find zone in boundary"); + LOCATIONS_LOGD("Find zone in boundary"); ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_IN, bounds->user_data); break; } @@ -220,15 +384,15 @@ static void __cb_zone_in(GObject * self, gpointer boundary, gpointer position, g static void __cb_zone_out(GObject * self, gpointer boundary, gpointer position, gpointer accuracy, gpointer userdata) { - LOCATIONS_LOGI("Callback function has been invoked."); + LOCATIONS_LOGD("Callback function has been invoked."); location_manager_s *handle = (location_manager_s *) userdata; if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) { LocationPosition *pos = (LocationPosition *) position; ((location_zone_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BOUNDARY]) (LOCATIONS_BOUNDARY_OUT, - pos->latitude, pos->longitude, - pos->altitude, pos->timestamp, - handle->user_data - [_LOCATIONS_EVENT_TYPE_BOUNDARY]); + pos->latitude, pos->longitude, + pos->altitude, pos->timestamp, + handle->user_data + [_LOCATIONS_EVENT_TYPE_BOUNDARY]); } location_bounds_s *bounds; @@ -236,7 +400,7 @@ static void __cb_zone_out(GObject * self, gpointer boundary, gpointer position, while (bounds_list) { bounds = (location_bounds_s *)bounds_list->data; if (__boundary_compare(boundary, bounds->boundary) == 0) { - LOCATIONS_LOGI("Find zone out boundary"); + LOCATIONS_LOGD("Find zone out boundary"); ((location_bounds_state_changed_cb) bounds->user_cb) (LOCATIONS_BOUNDARY_OUT, bounds->user_data); break; } @@ -251,7 +415,7 @@ static int __set_callback(_location_event_e type, location_manager_h manager, vo location_manager_s *handle = (location_manager_s *) manager; handle->user_cb[type] = callback; handle->user_data[type] = user_data; - LOCATIONS_LOGI("event type : %d. ", type); + LOCATIONS_LOGD("event type : %d. ", type); return LOCATIONS_ERROR_NONE; } @@ -261,7 +425,7 @@ static int __unset_callback(_location_event_e type, location_manager_h manager) location_manager_s *handle = (location_manager_s *) manager; handle->user_cb[type] = NULL; handle->user_data[type] = NULL; - LOCATIONS_LOGI("event type : %d. ", type); + LOCATIONS_LOGD("event type : %d. ", type); return LOCATIONS_ERROR_NONE; } @@ -309,15 +473,30 @@ static void __foreach_boundary(LocationBoundary * boundary, void *user_data) } else { if (handle->is_continue_foreach_bounds) { handle->is_continue_foreach_bounds = - ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds, - handle-> - user_data - [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]); + ((location_bounds_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]) (bounds, + handle-> + user_data + [_LOCATIONS_EVENT_TYPE_FOREACH_BOUNDS]); } location_bounds_destroy(bounds); } } else { - LOCATIONS_LOGI("__foreach_boundary() has been failed"); + LOCATIONS_LOGD("__foreach_boundary() has been failed"); + } +} + +static void __setting_changed_cb(LocationMethod method, gboolean enable, void *user_data) +{ + LOCATIONS_LOGD("__setting_changed_cb method [%d]", method); + location_method_e _method = __convert_location_method_e(method); + location_setting_changed_s *_setting_changed = (location_setting_changed_s *)user_data; + if (_setting_changed == NULL) { + LOCATIONS_LOGE("Invaild userdata\n"); + return; + } + + if (_setting_changed[_method].callback != NULL) { + _setting_changed[_method].callback(_method, enable, _setting_changed[_method].user_data); } } @@ -325,61 +504,192 @@ static void __foreach_boundary(LocationBoundary * boundary, void *user_data) // Location Manager //////////////////////////////////////// +static void __cb_batch_updated(GObject * self, guint num_of_location, gpointer userdata) +{ + LOCATIONS_LOGD("Batch callback function has been invoked."); + location_manager_s *handle = (location_manager_s *) userdata; + + 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]); + } +} + +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_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_NULL_ARG_CHECK(manager); + LOCATIONS_NULL_ARG_CHECK(callback); + location_manager_s *handle = (location_manager_s *) manager; + g_object_set(handle->object, "batch-period", batch_period, NULL); + g_object_set(handle->object, "batch-interval", batch_interval, NULL); + return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data); +} + +EXPORT_API int location_manager_unset_location_batch_cb (location_manager_h manager) +{ + LOCATIONS_LOGD("location_manager_unset_location_batch_cb"); + 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_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]) { + 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"); + } + + int ret = location_start_batch(handle->object); + if (ret != LOCATION_ERROR_NONE) { + return __convert_error_code(ret); + } + + return LOCATIONS_ERROR_NONE; +} + +EXPORT_API int location_manager_stop_batch(location_manager_h manager) +{ + LOCATIONS_LOGD("location_manager_stop_batch"); + 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]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]); + handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0; + } + } else { + LOCATIONS_LOGE("method is not GPS"); + } + + int ret = location_stop_batch(handle->object); + if (ret != LOCATION_ERROR_NONE) { + return __convert_error_code(ret); + } + + return LOCATIONS_ERROR_NONE; +} + +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_NULL_ARG_CHECK(manager); + LOCATIONS_NULL_ARG_CHECK(callback); + location_manager_s *handle = (location_manager_s *) manager; + LocationBatch *batch = NULL; + + int ret = location_get_batch (handle->object, &batch); + if (ret != LOCATION_ERROR_NONE || batch == NULL) { + if (ret == LOCATION_ERROR_NOT_SUPPORTED) { + LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + return LOCATIONS_ERROR_INCORRECT_METHOD; + } else if (ret == LOCATION_ERROR_NOT_ALLOWED) { + LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"); + return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; + } + + LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ", + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; + } + + int i; + for (i = 0; i < batch->num_of_location; i++) { + gdouble latitude; + gdouble longitude; + gdouble altitude; + gdouble speed; + gdouble direction; + gdouble h_accuracy; + gdouble v_accuracy; + 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) { + break; + } + } + location_batch_free(batch); + batch = NULL; + return LOCATIONS_ERROR_NONE; +} + /* * Public Implementation */ EXPORT_API bool location_manager_is_supported_method(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_CPS: - _method = LOCATION_METHOD_CPS; - break; - default: - _method = LOCATION_METHOD_NONE; - break; + LOCATIONS_LOGD("location_manager_is_supported_method %d", method); + LocationMethod _method = __convert_LocationMethod(method); + if (_method == LOCATION_METHOD_NONE) { + LOCATIONS_LOGE("Not supported method [%d]", method); + set_last_result(LOCATIONS_ERROR_INCORRECT_METHOD); + return false; } + + set_last_result(LOCATIONS_ERROR_NONE); return location_is_supported_method(_method); } +EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable) +{ + if (LOCATIONS_METHOD_HYBRID > method || LOCATIONS_METHOD_WPS < method) { + LOCATIONS_LOGE("Not supported method [%d]", method); + return LOCATIONS_ERROR_INCORRECT_METHOD; + } + + LOCATIONS_LOGD("location_manager_is_enabled_method %d", method); + LOCATIONS_NULL_ARG_CHECK(enable); + int is_enabled_val = -1; + LocationMethod _method = __convert_LocationMethod(method); + int ret = location_is_enabled_method(_method, &is_enabled_val); + if (ret != LOCATION_ERROR_NONE) { + if (ret == LOCATION_ERROR_NOT_SUPPORTED) + return LOCATIONS_ERROR_INCORRECT_METHOD; + return __convert_error_code(ret); + } + if (is_enabled_val == -1) + return TIZEN_ERROR_PERMISSION_DENIED; + + *enable = (is_enabled_val == 0)?FALSE:TRUE; + return LOCATIONS_ERROR_NONE; +} + EXPORT_API int location_manager_create(location_method_e method, location_manager_h * manager) { + LOCATIONS_LOGD("location_manager_create (method : %d)", method); + + LocationMethod _method = __convert_LocationMethod(method); + if (_method == LOCATION_METHOD_NONE) { + LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_init", LOCATIONS_ERROR_NOT_SUPPORTED); + return LOCATIONS_ERROR_NOT_SUPPORTED; + } + if (!location_is_supported_method(_method)) { + LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location_is_supported_method", LOCATIONS_ERROR_NOT_SUPPORTED); + return LOCATIONS_ERROR_NOT_SUPPORTED; + } + + //It is moved here becasue of TCS. LOCATIONS_NULL_ARG_CHECK(manager); - if (location_init() != LOCATION_ERROR_NONE) - return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; - 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_CPS: - _method = LOCATION_METHOD_CPS; - break; - case LOCATIONS_METHOD_NONE: + if (location_init() != LOCATION_ERROR_NONE) { + LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_init", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; - 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; - } } location_manager_s *handle = (location_manager_s *) malloc(sizeof(location_manager_s)); @@ -392,8 +702,7 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage handle->object = location_new(_method); if (handle->object == NULL) { - LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); free(handle); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } @@ -401,8 +710,16 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage handle->is_continue_foreach_bounds = TRUE; handle->bounds_list = NULL; - handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle); - handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle); + if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) + handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = g_signal_connect(handle->object, "service-enabled", G_CALLBACK(__cb_service_enabled), handle); + + if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) + handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = g_signal_connect(handle->object, "service-disabled", G_CALLBACK(__cb_service_disabled), handle); + + #ifdef TIZEN_WEARABLE + if (!handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) + handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = g_signal_connect(handle->object, "error-emitted", G_CALLBACK(__cb_service_error_emitted), handle); + #endif *manager = (location_manager_h) handle; return LOCATIONS_ERROR_NONE; @@ -410,11 +727,26 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage EXPORT_API int location_manager_destroy(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_destroy"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; - g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]); - g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]); + if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED]); + handle->sig_id[_LOCATION_SIGNAL_SERVICE_ENABLED] = 0; + } + + if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED]); + handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0; + } + + #ifdef TIZEN_WEARABLE + if (handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED]); + handle->sig_id[_LOCATION_SIGNAL_ERROR_EMITTED] = 0; + } + #endif int ret = location_free(handle->object); if (ret != LOCATIONS_ERROR_NONE) { @@ -426,12 +758,28 @@ EXPORT_API int location_manager_destroy(location_manager_h manager) EXPORT_API int location_manager_start(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_start"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; - handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle); - handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle); - handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle); + if (!handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) + handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = g_signal_connect(handle->object, "service-updated", G_CALLBACK(__cb_service_updated), handle); + + if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) + { + if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) + handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = g_signal_connect(handle->object, "zone-in", G_CALLBACK(__cb_zone_in), handle); + + if (!handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) + handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = g_signal_connect(handle->object, "zone-out", G_CALLBACK(__cb_zone_out), handle); + } else { + LOCATIONS_LOGI("This method [%d] is not supported zone-in, zone-out signal.", handle->method); + } + + if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE] != NULL) { + LOCATIONS_LOGI("Satellite update_cb is set"); + location_set_option(handle->object, "USE_SV"); + } int ret = location_start(handle->object); if (ret != LOCATION_ERROR_NONE) { @@ -440,14 +788,57 @@ EXPORT_API int location_manager_start(location_manager_h manager) return LOCATIONS_ERROR_NONE; } +EXPORT_API int location_manager_request_single_location(location_manager_h manager, int timeout, location_updated_cb callback, void *user_data) +{ + LOCATIONS_LOGD("location_manager_request_single_location"); + LOCATIONS_NULL_ARG_CHECK(manager); + LOCATIONS_NULL_ARG_CHECK(callback); + if (timeout <= 0 || timeout > 120) { + LOCATIONS_LOGE("timeout scope is incorrect(1~120) [%d]", timeout); + return LOCATIONS_ERROR_INVALID_PARAMETER; + } + + location_manager_s *handle = (location_manager_s *) manager; + int ret = LOCATIONS_ERROR_NONE; + + if (!handle->sig_id[_LOCATION_SIGNAL_LOCATION_UPDATED]) + 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) { + return ret; + } + + ret = location_request_single_location(handle->object, timeout); + if (ret != LOCATION_ERROR_NONE) { + return __convert_error_code(ret); + } + return LOCATIONS_ERROR_NONE; +} + EXPORT_API int location_manager_stop(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_stop"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; - g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]); - g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]); - g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]); + if (handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED]); + handle->sig_id[_LOCATION_SIGNAL_SERVICE_UPDATED] = 0; + } + + if (LOCATIONS_METHOD_HYBRID <= handle->method && LOCATIONS_METHOD_WPS >= handle->method) + { + if (handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_IN]); + handle->sig_id[_LOCATION_SIGNAL_ZONE_IN] = 0; + } + + if (handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]) { + g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT]); + handle->sig_id[_LOCATION_SIGNAL_ZONE_OUT] = 0; + } + } int ret = location_stop(handle->object); if (ret != LOCATION_ERROR_NONE) { @@ -458,6 +849,7 @@ EXPORT_API int location_manager_stop(location_manager_h manager) EXPORT_API int location_manager_add_boundary(location_manager_h manager, location_bounds_h bounds) { + LOCATIONS_LOGD("location_manager_add_boundary"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(bounds); @@ -474,6 +866,7 @@ EXPORT_API int location_manager_add_boundary(location_manager_h manager, locatio EXPORT_API int location_manager_remove_boundary(location_manager_h manager, location_bounds_h bounds) { + LOCATIONS_LOGD("location_manager_remove_boundary"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(bounds); @@ -490,6 +883,7 @@ EXPORT_API int location_manager_remove_boundary(location_manager_h manager, loca EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, location_bounds_cb callback, void *user_data) { + LOCATIONS_LOGD("location_manager_foreach_boundary"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); @@ -506,6 +900,7 @@ EXPORT_API int location_manager_foreach_boundary(location_manager_h manager, loc EXPORT_API int location_manager_get_method(location_manager_h manager, location_method_e * method) { + LOCATIONS_LOGD("location_manager_get_method %d", method); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(method); location_manager_s *handle = (location_manager_s *) manager; @@ -524,13 +919,10 @@ EXPORT_API int location_manager_get_method(location_manager_h manager, location_ case LOCATION_METHOD_WPS: *method = LOCATIONS_METHOD_WPS; break; - case LOCATION_METHOD_CPS: - *method = LOCATIONS_METHOD_CPS; - break; default: { LOCATIONS_LOGE("LOCATIONS_ERROR_INVALID_PARAMETER(0x%08x) : Out of range (location_method_e) - method : %d ", - LOCATIONS_ERROR_INVALID_PARAMETER, method); + LOCATIONS_ERROR_INVALID_PARAMETER, method); return LOCATIONS_ERROR_INVALID_PARAMETER; } } @@ -539,8 +931,9 @@ EXPORT_API int location_manager_get_method(location_manager_h manager, location_ } EXPORT_API int location_manager_get_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, - time_t * timestamp) + time_t * timestamp) { + LOCATIONS_LOGD("location_manager_get_position"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); @@ -557,17 +950,11 @@ EXPORT_API int location_manager_get_position(location_manager_h manager, double } if (pos->status == LOCATION_STATUS_NO_FIX) { - *altitude = -1; - *latitude = -1; - *longitude = -1; + return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } else { - if (pos->status == LOCATION_STATUS_3D_FIX) { - *altitude = pos->altitude; - } else { - *altitude = -1; - } *latitude = pos->latitude; *longitude = pos->longitude; + *altitude = pos->altitude; } *timestamp = pos->timestamp; location_position_free(pos); @@ -577,6 +964,7 @@ EXPORT_API int location_manager_get_position(location_manager_h manager, double 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) { + LOCATIONS_LOGD("location_manager_get_location"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); @@ -600,17 +988,11 @@ EXPORT_API int location_manager_get_location(location_manager_h manager, double } if (pos->status == LOCATION_STATUS_NO_FIX) { - *altitude = -1; - *latitude = -1; - *longitude = -1; + return __convert_error_code(LOCATION_ERROR_NOT_AVAILABLE); } else { - if (pos->status == LOCATION_STATUS_3D_FIX) { - *altitude = pos->altitude; - } else { - *altitude = -1; - } *latitude = pos->latitude; *longitude = pos->longitude; + *altitude = pos->altitude; } *timestamp = pos->timestamp; *climb = vel->climb; @@ -628,6 +1010,7 @@ EXPORT_API int location_manager_get_location(location_manager_h manager, double EXPORT_API int location_manager_get_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp) { + LOCATIONS_LOGD("location_manager_get_velocity"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(climb); LOCATIONS_NULL_ARG_CHECK(direction); @@ -653,8 +1036,9 @@ EXPORT_API int location_manager_get_velocity(location_manager_h manager, double } EXPORT_API int location_manager_get_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal, - double *vertical) + double *vertical) { + LOCATIONS_LOGD("location_manager_get_accuracy"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(level); LOCATIONS_NULL_ARG_CHECK(horizontal); @@ -682,8 +1066,9 @@ EXPORT_API int location_manager_get_accuracy(location_manager_h manager, locatio } EXPORT_API int location_manager_get_last_position(location_manager_h manager, double *altitude, double *latitude, double *longitude, - time_t * timestamp) + time_t * timestamp) { + LOCATIONS_LOGD("location_manager_get_last_position"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); @@ -701,17 +1086,11 @@ EXPORT_API int location_manager_get_last_position(location_manager_h manager, do } if (last_pos->status == LOCATION_STATUS_NO_FIX) { - *altitude = -1; - *latitude = -1; - *longitude = -1; + return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } else { - if (last_pos->status == LOCATION_STATUS_3D_FIX) { - *altitude = last_pos->altitude; - } else { - *altitude = -1; - } *latitude = last_pos->latitude; *longitude = last_pos->longitude; + *altitude = last_pos->altitude; } *timestamp = last_pos->timestamp; location_position_free(last_pos); @@ -721,6 +1100,7 @@ EXPORT_API int location_manager_get_last_position(location_manager_h manager, do 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) { + LOCATIONS_LOGD("location_manager_get_last_location"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(altitude); LOCATIONS_NULL_ARG_CHECK(latitude); @@ -745,17 +1125,11 @@ EXPORT_API int location_manager_get_last_location(location_manager_h manager, do } if (last_pos->status == LOCATION_STATUS_NO_FIX) { - *altitude = -1; - *latitude = -1; - *longitude = -1; + return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } else { - if (last_pos->status == LOCATION_STATUS_3D_FIX) { - *altitude = last_pos->altitude; - } else { - *altitude = -1; - } *latitude = last_pos->latitude; *longitude = last_pos->longitude; + *altitude = last_pos->altitude; } *timestamp = last_pos->timestamp; *climb = last_vel->climb; @@ -772,6 +1146,7 @@ EXPORT_API int location_manager_get_last_location(location_manager_h manager, do EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, double *climb, double *direction, double *speed, time_t * timestamp) { + LOCATIONS_LOGD("location_manager_get_last_velocity"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(climb); LOCATIONS_NULL_ARG_CHECK(direction); @@ -798,8 +1173,9 @@ EXPORT_API int location_manager_get_last_velocity(location_manager_h manager, do } EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, location_accuracy_level_e * level, double *horizontal, - double *vertical) + double *vertical) { + LOCATIONS_LOGD("location_manager_get_last_accuracy"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(level); LOCATIONS_NULL_ARG_CHECK(horizontal); @@ -824,6 +1200,7 @@ EXPORT_API int location_manager_get_last_accuracy(location_manager_h manager, lo EXPORT_API int location_manager_get_accessibility_state(location_accessibility_state_e* state) { + LOCATIONS_LOGD("location_manager_get_accessibility_state"); LOCATIONS_NULL_ARG_CHECK(state); int ret = LOCATION_ERROR_NONE; @@ -852,8 +1229,9 @@ EXPORT_API int location_manager_get_accessibility_state(location_accessibility_s EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manager, location_position_updated_cb callback, int interval, void *user_data) { + LOCATIONS_LOGD("location_manager_set_position_updated_cb"); LOCATIONS_CHECK_CONDITION(interval >= 1 - && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_object_set(handle->object, "pos-interval", interval, NULL); @@ -862,13 +1240,15 @@ EXPORT_API int location_manager_set_position_updated_cb(location_manager_h manag EXPORT_API int location_manager_unset_position_updated_cb(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_unset_position_updated_cb"); return __unset_callback(_LOCATIONS_EVENT_TYPE_POSITION, manager); } EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manager, location_velocity_updated_cb callback, int interval, void *user_data) { + LOCATIONS_LOGD("location_manager_set_velocity_updated_cb"); LOCATIONS_CHECK_CONDITION(interval >= 1 - && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_NULL_ARG_CHECK(manager); location_manager_s *handle = (location_manager_s *) manager; g_object_set(handle->object, "vel-interval", interval, NULL); @@ -877,32 +1257,81 @@ EXPORT_API int location_manager_set_velocity_updated_cb(location_manager_h manag EXPORT_API int location_manager_unset_velocity_updated_cb(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_unset_velocity_updated_cb"); return __unset_callback(_LOCATIONS_EVENT_TYPE_VELOCITY, manager); } EXPORT_API int location_manager_set_service_state_changed_cb(location_manager_h manager, location_service_state_changed_cb callback, - void *user_data) + void *user_data) { + LOCATIONS_LOGD("location_manager_set_service_state_changed_cb"); return __set_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager, callback, user_data); } EXPORT_API int location_manager_unset_service_state_changed_cb(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_unset_service_state_changed_cb"); return __unset_callback(_LOCATIONS_EVENT_TYPE_SERVICE_STATE, manager); } EXPORT_API int location_manager_set_zone_changed_cb(location_manager_h manager, location_zone_changed_cb callback, void *user_data) { + LOCATIONS_LOGD("location_manager_set_zone_changed_cb"); return __set_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager, callback, user_data); } EXPORT_API int location_manager_unset_zone_changed_cb(location_manager_h manager) { + LOCATIONS_LOGD("location_manager_unset_zone_changed_cb"); return __unset_callback(_LOCATIONS_EVENT_TYPE_BOUNDARY, manager); } +EXPORT_API int location_manager_set_setting_changed_cb(location_method_e method, location_setting_changed_cb callback, void *user_data) +{ + LOCATIONS_LOGD("location_manager_set_setting_changed_cb"); + LOCATIONS_NULL_ARG_CHECK(callback); + + LocationMethod _method = __convert_LocationMethod(method); + int ret = LOCATION_ERROR_NONE; + + if (_method == LOCATION_METHOD_NONE) { + return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; + } + + 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); + return __convert_error_code(ret); +} + +EXPORT_API int location_manager_unset_setting_changed_cb(location_method_e method /*, location_setting_changed_cb callback */) +{ + LOCATIONS_LOGD("location_manager_unset_setting_changed_cb"); +// LOCATIONS_NULL_ARG_CHECK(callback); + LocationMethod _method = __convert_LocationMethod(method); + int ret = LOCATION_ERROR_NONE; +/* + if (g_location_setting[method].callback != callback) { + LOCATIONS_LOGE("Invalid parameter"); + return LOCATIONS_ERROR_INVALID_PARAMETER; + } +*/ + ret = location_ignore_setting_notify(_method, __setting_changed_cb); + if (ret != LOCATION_ERROR_NONE) { + LOCATIONS_LOGE("Fail to ignore notify. Error[%d]", ret); + ret = __convert_error_code(ret); + } + + g_location_setting[method].callback = NULL; + g_location_setting[method].user_data = NULL; + + return LOCATIONS_ERROR_NONE; +} + EXPORT_API int location_manager_get_distance(double start_latitude, double start_longitude, double end_latitude, double end_longitude, double *distance) { + LOCATIONS_LOGD("location_manager_get_distance"); LOCATIONS_NULL_ARG_CHECK(distance); LOCATIONS_CHECK_CONDITION(start_latitude>=-90 && start_latitude<=90,LOCATIONS_ERROR_INVALID_PARAMETER,"LOCATIONS_ERROR_INVALID_PARAMETER"); LOCATIONS_CHECK_CONDITION(start_longitude>=-180 && start_longitude<=180,LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); @@ -925,25 +1354,13 @@ EXPORT_API int location_manager_get_distance(double start_latitude, double start return LOCATIONS_ERROR_NONE; } -EXPORT_API int location_manager_send_command(const char *cmd) -{ - LOCATIONS_NULL_ARG_CHECK(cmd); - - int ret; - ret = location_send_command(cmd); - if (ret != LOCATION_ERROR_NONE) { - return __convert_error_code(ret); - } - - return LOCATIONS_ERROR_NONE; -} - ///////////////////////////////////////// // GPS Status & Satellites //////////////////////////////////////// EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea) { + LOCATIONS_LOGD("gps_status_get_nmea"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(nmea); location_manager_s *handle = (location_manager_s *) manager; @@ -953,26 +1370,26 @@ EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea) g_object_get(handle->object, "method", &_method, NULL); if (_method != LOCATION_METHOD_GPS) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } } else if (handle->method != LOCATIONS_METHOD_GPS) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } gchar *nmea_data = NULL; g_object_get(handle->object, "nmea", &nmea_data, NULL); if (nmea_data == NULL) { LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : nmea data is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } *nmea = NULL; *nmea = strdup(nmea_data); if (*nmea == NULL) { LOCATIONS_LOGE("LOCATIONS_ERROR_OUT_OF_MEMORY(0x%08x) : fail to strdup ", - LOCATIONS_ERROR_OUT_OF_MEMORY); + LOCATIONS_ERROR_OUT_OF_MEMORY); return LOCATIONS_ERROR_OUT_OF_MEMORY; } g_free(nmea_data); @@ -981,6 +1398,7 @@ EXPORT_API int gps_status_get_nmea(location_manager_h manager, char **nmea) EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp) { + LOCATIONS_LOGD("gps_status_get_satellite"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(num_of_active); LOCATIONS_NULL_ARG_CHECK(num_of_inview); @@ -991,12 +1409,15 @@ EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_ if (ret != LOCATION_ERROR_NONE || sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; + } else if (ret == LOCATION_ERROR_NOT_ALLOWED) { + LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"); + return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; } LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } @@ -1010,22 +1431,26 @@ EXPORT_API int gps_status_get_satellite(location_manager_h manager, int *num_of_ EXPORT_API int gps_status_set_satellite_updated_cb(location_manager_h manager, gps_status_satellite_updated_cb callback, int interval, void *user_data) { + LOCATIONS_LOGD("gps_status_set_satellite_updated_cb"); LOCATIONS_CHECK_CONDITION(interval >= 1 - && interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER"); + && interval <= 120, 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; + location_set_option(handle->object, "USE_SV"); g_object_set(handle->object, "sat-interval", interval, NULL); return __set_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager, callback, user_data); } EXPORT_API int gps_status_unset_satellite_updated_cb(location_manager_h manager) { + LOCATIONS_LOGD("gps_status_unset_satellite_updated_cb"); return __unset_callback(_LOCATIONS_EVENT_TYPE_SATELLITE, manager); } - EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, void *user_data) { + LOCATIONS_LOGD("gps_status_foreach_satellites_in_view"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; @@ -1034,12 +1459,15 @@ EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, if (ret != LOCATION_ERROR_NONE || sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; + } else if (ret == LOCATION_ERROR_NOT_ALLOWED) { + LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"); + return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; } LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } @@ -1061,6 +1489,7 @@ EXPORT_API int gps_status_foreach_satellites_in_view(location_manager_h manager, EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *num_of_active, int *num_of_inview, time_t *timestamp) { + LOCATIONS_LOGD("gps_status_get_last_satellite"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(num_of_active); LOCATIONS_NULL_ARG_CHECK(num_of_inview); @@ -1072,12 +1501,15 @@ EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *nu if (ret != LOCATION_ERROR_NONE || last_sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; + } else if (ret == LOCATION_ERROR_NOT_ALLOWED) { + LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED"); + return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED; } LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } @@ -1089,8 +1521,9 @@ EXPORT_API int gps_status_get_last_satellite(location_manager_h manager, int *nu } EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h manager, gps_status_get_satellites_cb callback, - void *user_data) + void *user_data) { + LOCATIONS_LOGD("gps_status_foreach_last_satellites_in_view"); LOCATIONS_NULL_ARG_CHECK(manager); LOCATIONS_NULL_ARG_CHECK(callback); location_manager_s *handle = (location_manager_s *) manager; @@ -1100,12 +1533,12 @@ EXPORT_API int gps_status_foreach_last_satellites_in_view(location_manager_h man if (ret != LOCATION_ERROR_NONE || last_sat == NULL) { if (ret == LOCATION_ERROR_NOT_SUPPORTED) { LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", - LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); + LOCATIONS_ERROR_INCORRECT_METHOD, handle->method); return LOCATIONS_ERROR_INCORRECT_METHOD; } LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : satellite is NULL ", - LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); + LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE); return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE; } |