sync with latest 3.0
[platform/core/api/location-manager.git] / src / locations.c
index b148c9a..b8e1a8a 100755 (executable)
@@ -69,26 +69,28 @@ static LocationMethod __convert_LocationMethod(location_method_e method)
 
 static void __cb_service_updated(GObject *self, guint type, gpointer data, gpointer velocity, gpointer accuracy, gpointer userdata)
 {
-       LOCATIONS_LOGD("Callback function has been invoked. ");
        location_manager_s *handle = (location_manager_s *) userdata;
 
        if (type == SATELLITE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_SATELLITE]) {
                LocationSatellite *sat = (LocationSatellite *)data;
-               LOCATIONS_LOGD("Current satellite information: timestamp : %d, number of active : %d, number of inview : %d",
+               LOCATIONS_LOGD("callback invoked[TYPE_SATELLITE] 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]);
        } else if (type == DISTANCE_UPDATED && handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE]) {
                LocationPosition *pos = (LocationPosition *) data;
-               LocationVelocity *vel = (LocationVelocity *) velocity;  /* current velocity */
-               ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(0, pos->latitude, pos->longitude, pos->altitude,
-                                                               vel->speed, vel->direction, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
+               LocationVelocity *vel = (LocationVelocity *) velocity;
+               LocationAccuracy *acc = (LocationAccuracy *) accuracy;
+               ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_DISTANCE])(pos->latitude, pos->longitude, pos->altitude,
+                                                               vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_DISTANCE]);
+               LOCATIONS_LOGD("callback invoked[TYPE_DISTANCE] timestamp : %d", pos->timestamp);
        } else {
 
                if (handle->user_cb[_LOCATIONS_EVENT_TYPE_POSITION] && (type & POSITION_UPDATED) != 0) {
                        LocationPosition *pos = (LocationPosition *) data;
                        ((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]);
+                       LOCATIONS_LOGD("callback invoked[TYPE_POSITION] timestamp : %d", pos->timestamp);
                }
 
                if (handle->user_cb[_LOCATIONS_EVENT_TYPE_VELOCITY] && (type & VELOCITY_UPDATED) != 0) {
@@ -103,6 +105,7 @@ static void __cb_service_updated(GObject *self, guint type, gpointer data, gpoin
                        LocationAccuracy *acc = (LocationAccuracy *) accuracy;
                        ((location_changed_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_POS_VEL])(pos->latitude, pos->longitude, pos->altitude,
                                                                        vel->speed, vel->direction, acc->horizontal_accuracy, pos->timestamp, handle->user_data[_LOCATIONS_EVENT_TYPE_POS_VEL]);
+                       LOCATIONS_LOGD("callback invoked[TYPE_POS_VEL] timestamp : %d", pos->timestamp);
                }
        }
 }
@@ -133,7 +136,7 @@ static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer us
 
 static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
 {
-       LOCATIONS_LOGD("Invoked. status = %d", status);
+       LOCATIONS_LOGD("Invoked[service_enabled]. status = %d", status);
        location_manager_s *handle = (location_manager_s *) userdata;
        if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
                ((location_service_state_changed_cb)
@@ -143,7 +146,7 @@ static void __cb_service_enabled(GObject *self, guint status, gpointer userdata)
 
 static void __cb_service_disabled(GObject *self, guint status, gpointer userdata)
 {
-       LOCATIONS_LOGD("Invoked. status = %d", status);
+       LOCATIONS_LOGD("Invoked[service_disabled]. status = %d", status);
        location_manager_s *handle = (location_manager_s *) userdata;
        if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
                ((location_service_state_changed_cb)
@@ -151,26 +154,6 @@ static void __cb_service_disabled(GObject *self, guint status, gpointer userdata
        }
 }
 
-#if 0
-static void __cb_service_status_changed(GObject *self, guint status, gpointer userdata)
-{
-       LOCATIONS_LOGD("Invoked. status = %u", status);
-       location_manager_s *handle = (location_manager_s *) userdata;
-
-       if (handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]) {
-               if (status == LOCATION_STATUS_2D_FIX || status == LOCATION_STATUS_3D_FIX)
-                       ((location_service_state_changed_cb)
-                        handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ENABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
-               else if (status == LOCATION_STATUS_NO_FIX)
-                       ((location_service_state_changed_cb)
-                                handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_DISABLED, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
-               else if (status == LOCATION_STATUS_MOCK_FAIL)
-                       ((location_service_state_changed_cb)
-                                handle->user_cb[_LOCATIONS_EVENT_TYPE_SERVICE_STATE])(LOCATIONS_SERVICE_ERROR, handle->user_data[_LOCATIONS_EVENT_TYPE_SERVICE_STATE]);
-       }
-}
-#endif
-
 static int __compare_position(gconstpointer a, gconstpointer b)
 {
        if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
@@ -406,8 +389,14 @@ EXPORT_API bool location_manager_is_supported_method(location_method_e method)
                return false;
        }
 
-       set_last_result(LOCATIONS_ERROR_NONE);
-       return location_is_supported_method(_method);
+       gboolean ret =  location_is_supported_method(_method);
+       if (ret) {
+               set_last_result(LOCATIONS_ERROR_NONE);
+               return true;
+       } else {
+               set_last_result(LOCATIONS_ERROR_NOT_SUPPORTED);
+               return false;
+       }
 }
 
 EXPORT_API int location_manager_is_enabled_method(location_method_e method, bool *enable)
@@ -481,24 +470,14 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage
 {
        LOCATIONS_LOGD("location_manager_create (method : %d)", method);
 
-       if (method == LOCATIONS_METHOD_HYBRID) {
+       if (method == LOCATIONS_METHOD_HYBRID)
+               LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
+       else if (method == LOCATIONS_METHOD_GPS)
+               LOCATIONS_NOT_SUPPORTED_CHECK(__is_gps_supported());
+       else if (method == LOCATIONS_METHOD_WPS)
+               LOCATIONS_NOT_SUPPORTED_CHECK(__is_wps_supported());
+       else if (method == LOCATIONS_METHOD_PASSIVE)
                LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
-       } else if (method == LOCATIONS_METHOD_GPS) {
-               if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
-                       LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
-                       return LOCATIONS_ERROR_NOT_SUPPORTED;
-               }
-       } else if (method == LOCATIONS_METHOD_WPS) {
-               if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
-                       LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
-                       return LOCATIONS_ERROR_NOT_SUPPORTED;
-               }
-       } else if (method == LOCATIONS_METHOD_PASSIVE) {
-               if (__is_location_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
-                       LOCATIONS_LOGE("LOCATIONS_ERROR_NOT_SUPPORTED(0x%08x) : fail to location feature", LOCATIONS_ERROR_NOT_SUPPORTED);
-                       return LOCATIONS_ERROR_NOT_SUPPORTED;
-               }
-       }
 
        LocationMethod _method = __convert_LocationMethod(method);
        if (_method == LOCATION_METHOD_NONE) {
@@ -527,7 +506,7 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage
 
        memset(handle, 0, sizeof(location_manager_s));
 
-       handle->object = location_new(_method);
+       handle->object = location_new(_method, FALSE);
        if (handle->object == NULL) {
                LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : fail to location_new", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
                free(handle);
@@ -543,11 +522,6 @@ EXPORT_API int location_manager_create(location_method_e method, location_manage
        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);
 
-#if 0
-       if (!handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED])
-               handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = g_signal_connect(handle->object, "status-changed", G_CALLBACK(__cb_service_status_changed), handle);
-#endif
-
        *manager = (location_manager_h) handle;
        return LOCATIONS_ERROR_NONE;
 }
@@ -569,19 +543,12 @@ EXPORT_API int location_manager_destroy(location_manager_h manager)
                handle->sig_id[_LOCATION_SIGNAL_SERVICE_DISABLED] = 0;
        }
 
-#if 0
-       if (handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]) {
-               g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED]);
-               handle->sig_id[_LOCATION_SIGNAL_STATUS_CHANGED] = 0;
-       }
-#endif
-
        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;
        }
 
-       int ret = location_free(handle->object);
+       int ret = location_free(handle->object, FALSE);
        if (ret != LOCATIONS_ERROR_NONE)
                return __convert_error_code(ret);
 
@@ -1086,9 +1053,6 @@ EXPORT_API int location_manager_unset_distance_based_location_changed_cb(locatio
        LOCATIONS_LOGD("location_manager_unset_distance_updated_cb");
        LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
        LOCATIONS_NULL_ARG_CHECK(manager);
-       location_manager_s *handle = (location_manager_s *) manager;
-       g_object_set(handle->object, "min-interval", 0, NULL);
-       g_object_set(handle->object, "min-distance", 0, NULL);
        return __unset_callback(_LOCATIONS_EVENT_TYPE_DISTANCE, manager);
 }
 
@@ -1184,8 +1148,12 @@ 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);
+       } else if (_method == LOCATION_METHOD_PASSIVE) {
+               LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
+               return LOCATIONS_ERROR_INCORRECT_METHOD;
+       }
 
        g_location_setting[_method].callback = callback;
        g_location_setting[_method].user_data = user_data;
@@ -1204,8 +1172,12 @@ 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);
+       } else if (_method == LOCATION_METHOD_PASSIVE) {
+               LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD");
+               return LOCATIONS_ERROR_INCORRECT_METHOD;
+       }
 
        ret = location_ignore_setting_notify(_method, __setting_changed_cb);
        if (ret != LOCATION_ERROR_NONE) {