Support HW batch mode when sensor API is available 20/66120/2 accepted/tizen/common/20160420.140647 accepted/tizen/ivi/20160420.043729 accepted/tizen/mobile/20160420.043628 accepted/tizen/tv/20160420.043646 accepted/tizen/wearable/20160420.043721 submit/tizen/20160419.102349
authorkj7.sung <kj7.sung@samsung.com>
Fri, 15 Apr 2016 08:55:45 +0000 (17:55 +0900)
committerkj7.sung <kj7.sung@samsung.com>
Fri, 15 Apr 2016 09:44:58 +0000 (18:44 +0900)
Change-Id: Ib67dfa96b5a76bd5f478605489f2f4f77154748b
Signed-off-by: kj7.sung <kj7.sung@samsung.com>
CMakeLists.txt
lbs-location.pc.in
location/manager/location-batch.c
location/manager/location-batch.h
location/manager/location-gps.c
location/manager/location-setting.h
packaging/liblbs-location.changes
packaging/liblbs-location.spec

index 995ba52..7529e37 100755 (executable)
@@ -25,7 +25,7 @@ ELSE(FEATURE_PROFILE_TV)
 ENDIF(FEATURE_PROFILE_TV)
 
 pkg_check_modules(pkgs REQUIRED glib-2.0 gthread-2.0 gobject-2.0 gmodule-2.0 capi-appfw-app-manager
-               dlog vconf json-glib-1.0 bundle eventsystem libtzplatform-config ${PRIVACY_PKG})
+               dlog vconf json-glib-1.0 bundle eventsystem libtzplatform-config capi-system-sensor ${PRIVACY_PKG})
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 26a2ce0..d616eda 100644 (file)
@@ -5,7 +5,7 @@ includedir=@INCLUDEDIR@/location
 
 Name: location
 Description: Tizen Location FW
-Requires: glib-2.0 gobject-2.0 gmodule-2.0 vconf
+Requires: glib-2.0 gobject-2.0 gmodule-2.0 vconf capi-system-sensor
 Version: @VERSION@
 Libs: -L${libdir} -llbs-location
 Cflags: -I${includedir} -I${includedir}/location
index 717a5f7..e2c7940 100755 (executable)
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <tzplatform_config.h>
+#include <sensor.h>
 #include "location-batch.h"
 #include "location-log.h"
 
@@ -121,6 +122,32 @@ location_get_batch_file(int num_of_location)
        return batch;
 }
 
+#ifdef TIZEN_DEVICE
+EXPORT_API gboolean location_set_sensor_batch(LocationBatch *batch, sensor_event_s *event)
+{
+       g_return_val_if_fail(batch, FALSE);
+       g_return_val_if_fail(event, FALSE);
+       g_return_val_if_fail(batch->num_of_location > event->values[4], FALSE);
+       unsigned long long timestamp = event->timestamp;
+       float latitude  = event->values[0];
+       float longitude = event->values[1];
+       float altitude  = event->values[2];
+       float speed     = event->values[3];
+       int idx   = (int)(event->values[4]);
+
+       batch->batch_data[idx].timestamp = batch->start_time - (time_t)((timestamp / 1001000) % 100000);
+       batch->batch_data[idx].latitude = latitude;
+       batch->batch_data[idx].longitude = longitude;
+       batch->batch_data[idx].altitude = altitude;
+       batch->batch_data[idx].speed = speed;
+       batch->batch_data[idx].direction = 0;
+       batch->batch_data[idx].horizontal_accuracy = 0;
+       batch->batch_data[idx].vertical_accuracy = 0;
+
+       return TRUE;
+}
+#endif
+
 EXPORT_API LocationBatch *
 location_batch_copy(const LocationBatch *batch)
 {
index 7868246..4336d1c 100644 (file)
@@ -23,6 +23,7 @@
 #define __LOCATION_BATCH_H_
 
 #include <location-types.h>
+#include <sensor.h>
 
 G_BEGIN_DECLS
 
@@ -63,6 +64,7 @@ typedef struct {
  */
 struct _LocationBatch {
        guint num_of_location;  /*/< The number of location batch. */
+       time_t start_time;
        LocationBatchDetail *batch_data;
 };
 
@@ -80,6 +82,10 @@ LocationBatch *location_get_batch_file(int num_of_location);
 
 void location_batch_free(LocationBatch *batch);
 
+#ifdef TIZEN_DEVICE
+gboolean location_set_sensor_batch(LocationBatch *batch, sensor_event_s *event);
+#endif
+
 /**
  * @} @}
  */
index cf61b31..a172fac 100755 (executable)
@@ -24,6 +24,7 @@
 #endif
 
 #include <app_manager.h>
+#include <sensor.h>
 #include "location-setting.h"
 #include "location-log.h"
 
@@ -42,6 +43,7 @@ typedef struct _LocationGpsPrivate {
        LocationGpsMod          *mod;
        GMutex                          mutex;
        gboolean                        is_started;
+       gboolean                        is_batch_invoked;
        guint                           app_type;
        gboolean                        set_noti;
        gboolean                        enabled;
@@ -70,6 +72,10 @@ typedef struct _LocationGpsPrivate {
        guint                           pos_searching_timer;
        guint                           vel_searching_timer;
 #endif
+#ifdef TIZEN_DEVICE
+       sensor_h sensor;
+       sensor_listener_h sensor_listener;
+#endif
 } LocationGpsPrivate;
 
 enum {
@@ -316,6 +322,7 @@ gps_location_cb(gboolean enabled,
                           &(priv->acc));
 }
 
+#ifndef TIZEN_DEVICE
 static void
 gps_batch_cb(gboolean enabled,
              guint num_of_location,
@@ -332,6 +339,7 @@ gps_batch_cb(gboolean enabled,
 
        g_signal_emit(self, signals[BATCH_UPDATED], 0, num_of_location);
 }
+#endif
 
 static void
 gps_satellite_cb(gboolean enabled,
@@ -485,6 +493,101 @@ location_gps_stop(LocationGps *self)
        return ret;
 }
 
+#ifdef TIZEN_DEVICE
+static void __sensor_event_cb(sensor_h s, sensor_event_s *event, void *data)
+{
+       LocationGpsPrivate *priv = GET_PRIVATE(data);
+       g_return_if_fail(priv);
+       g_return_if_fail(event);
+
+       int remain_idx = (int)(event->values[4]);
+
+       if (priv->is_batch_invoked) {
+               location_batch_free(priv->batch);
+               priv->is_batch_invoked = FALSE;
+               priv->batch = NULL;
+       }
+
+       if (priv->batch == NULL) {
+               g_return_if_fail(event->value_count <= 5);
+               priv->batch = location_batch_new(remain_idx + 1);
+               g_return_if_fail(priv->batch);
+               priv->batch->num_of_location = remain_idx + 1;
+               time_t start;
+               time(&start);
+               priv->batch->start_time = start + (time_t)((event->timestamp / 1001000) % 100000);
+       }
+
+       location_set_sensor_batch(priv->batch, event);
+
+       if (remain_idx == 0) {
+               g_signal_emit(data, signals[BATCH_UPDATED], 0, priv->batch->num_of_location);
+               priv->is_batch_invoked = TRUE;
+       }
+}
+
+static int __set_sensor_batch(LocationGps *self, int batch_interval)
+{
+       LOCATION_LOGD("__set_sensor_batch");
+       LocationGpsPrivate *priv = GET_PRIVATE(self);
+       g_return_val_if_fail(priv, LOCATION_ERROR_NOT_AVAILABLE);
+
+       if (priv->batch != NULL) {
+               location_batch_free(priv->batch);
+               priv->batch = NULL;
+       }
+
+       int update_interval = batch_interval * 1000;    /* in ms */
+       int ret = 0;
+       bool supported = false;
+
+       ret = sensor_is_supported((sensor_type_e)0x1A02, &supported);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_is_supported() failed");
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+
+       if (!supported) {
+               LOCATION_LOGD("Not supported");
+               return LOCATION_ERROR_NOT_SUPPORTED;
+       }
+
+       ret = sensor_get_default_sensor((sensor_type_e)0x1A02, &priv->sensor);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_get_default_sensor() failed (%d)", ret);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+
+       ret = sensor_create_listener(priv->sensor, &priv->sensor_listener);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_create_listener() failed (%d)", ret);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+
+       ret = sensor_listener_set_event_cb(priv->sensor_listener, update_interval, __sensor_event_cb, self);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_listener_set_event_cb() failed");
+               sensor_destroy_listener(priv->sensor_listener);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+
+       ret = sensor_listener_set_option(priv->sensor_listener, SENSOR_OPTION_ALWAYS_ON);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_listener_set_option() failed");
+               sensor_destroy_listener(priv->sensor_listener);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+       ret = sensor_listener_start(priv->sensor_listener);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_listener_set_event_cb() failed");
+               sensor_destroy_listener(priv->sensor_listener);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+
+       return LOCATION_ERROR_NONE;
+}
+#endif
+
 static int
 location_gps_start_batch(LocationGps *self)
 {
@@ -502,6 +605,9 @@ location_gps_start_batch(LocationGps *self)
        if (!location_setting_get_int(VCONFKEY_LOCATION_ENABLED)) {
                ret = LOCATION_ERROR_SETTING_OFF;
        } else {
+#ifdef TIZEN_DEVICE
+               return  __set_sensor_batch(self, priv->batch_interval);
+#else
                __set_started(self, TRUE);
                ret = priv->mod->ops.start_batch(priv->mod->handler, gps_batch_cb, priv->batch_interval, priv->batch_period, self);
                if (ret != LOCATION_ERROR_NONE) {
@@ -509,6 +615,7 @@ location_gps_start_batch(LocationGps *self)
                        __set_started(self, FALSE);
                        return ret;
                }
+#endif
        }
 
        return ret;
@@ -526,6 +633,21 @@ location_gps_stop_batch(LocationGps *self)
 
        int ret = LOCATION_ERROR_NONE;
 
+#ifdef TIZEN_DEVICE
+       ret = sensor_listener_stop(priv->sensor_listener);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_listener_stop() failed (%d)", ret);
+               return LOCATION_ERROR_NOT_AVAILABLE;
+       }
+       ret = sensor_listener_unset_event_cb(priv->sensor_listener);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_listener_unset_event_cb() failed (%d)", ret);
+       }
+       ret = sensor_destroy_listener(priv->sensor_listener);
+       if (ret != SENSOR_ERROR_NONE) {
+               LOCATION_LOGD("sensor_destroy_listener() failed (%d)", ret);
+       }
+#else
        if (__get_started(self) == TRUE) {
                __set_started(self, FALSE);
                ret = priv->mod->ops.stop_batch(priv->mod->handler);
@@ -535,6 +657,7 @@ location_gps_stop_batch(LocationGps *self)
        } else {
                return LOCATION_ERROR_NONE;
        }
+#endif
 
        __reset_pos_data_from_priv(priv);
 
@@ -719,10 +842,10 @@ location_gps_set_property(GObject *object,
                                guint interval = g_value_get_uint(value);
                                LOCATION_LOGD("Set prop>> PROP_BATCH_INTERVAL: %u", interval);
                                if (interval > 0) {
-                                       if (interval < LOCATION_UPDATE_INTERVAL_MAX)
+                                       if (interval < LOCATION_BATCH_INTERVAL_MAX)
                                                priv->batch_interval = interval;
                                        else
-                                               priv->batch_interval = (guint)LOCATION_UPDATE_INTERVAL_MAX;
+                                               priv->batch_interval = (guint)LOCATION_BATCH_INTERVAL_MAX;
                                } else
                                        priv->batch_interval = (guint)LOCATION_UPDATE_INTERVAL_DEFAULT;
 
@@ -1113,10 +1236,12 @@ location_gps_get_batch(LocationGps *self,
        g_return_val_if_fail(priv->mod, LOCATION_ERROR_NOT_AVAILABLE);
        setting_retval_if_fail(VCONFKEY_LOCATION_ENABLED);
 
+#ifndef TIZEN_DEVICE
        if (__get_started(self) != TRUE) {
                LOCATION_LOGE("location is not started");
                return LOCATION_ERROR_NOT_AVAILABLE;
        }
+#endif
 
        if (priv->batch) {
                *batch = location_batch_copy(priv->batch);
@@ -1213,6 +1338,7 @@ location_gps_init(LocationGps *self)
 
        g_mutex_init(&priv->mutex);
        priv->is_started = FALSE;
+       priv->is_batch_invoked = FALSE;
        priv->set_noti = FALSE;
        priv->enabled = FALSE;
        priv->signal_type = 0;
@@ -1243,6 +1369,11 @@ location_gps_init(LocationGps *self)
 #endif
        priv->loc_timeout = 0;
 
+#ifdef TIZEN_DEVICE
+       priv->sensor = NULL;
+       priv->sensor_listener = NULL;
+#endif
+
        priv->app_type = location_get_app_type(NULL);
        if (priv->app_type == 0) {
                LOCATION_LOGW("Fail to get app_type");
@@ -1411,7 +1542,7 @@ location_gps_class_init(LocationGpsClass *klass)
                                                            "gps batch interval interval prop",
                                                            "gps batch interval interval data",
                                                            LOCATION_UPDATE_INTERVAL_MIN,
-                                                           LOCATION_UPDATE_INTERVAL_MAX,
+                                                           LOCATION_BATCH_INTERVAL_MAX,
                                                            LOCATION_UPDATE_INTERVAL_DEFAULT,
                                                            G_PARAM_READWRITE);
 
index ffced76..9d0da24 100644 (file)
 #define LOCATION_UPDATE_INTERVAL_MIN           1
 #define LOCATION_UPDATE_INTERVAL_MAX           120
 #define LOCATION_UPDATE_INTERVAL_DEFAULT       LOCATION_UPDATE_INTERVAL_MIN
-#define LOCATION_BATCH_PERIOD_MIN                      120
-#define LOCATION_BATCH_PERIOD_MAX                      600
-#define LOCATION_BATCH_PERIOD_DEFAULT          LOCATION_BATCH_PERIOD_MIN
+#define LOCATION_BATCH_INTERVAL_MAX                    255
+#define LOCATION_BATCH_PERIOD_MIN                      1
+#define LOCATION_BATCH_PERIOD_MAX                      60000
+#define LOCATION_BATCH_PERIOD_DEFAULT          150
 #define LOCATION_MIN_INTERVAL_MIN                      1
 #define LOCATION_MIN_INTERVAL_MAX                      120
 #define LOCATION_MIN_INTERVAL_DEFAULT          LOCATION_MIN_INTERVAL_MIN
index 57b9bae..f569d94 100644 (file)
@@ -1,5 +1,12 @@
+[Version]      libslp-location_1.2.0
+[Date]         15 Apr 2016
+[Changes]      Support HW batch mode when sensor API is available
+[Developer]    Kyoungjun Sung <kj7.sung@samsung.com>
+
+================================================================================
+
 [Version]      libslp-location_1.1.0
-[Date]         24 May 2016
+[Date]         24 Mar 2016
 [Changes]      Privacy check method changed to cynara
 [Developer]    Kyoungjun Sung <kj7.sung@samsung.com>
 
index 4d14cba..08f1467 100755 (executable)
@@ -1,6 +1,6 @@
 Name: liblbs-location
 Summary: Location Based Service Library
-Version: 1.1.0
+Version: 1.2.0
 Release: 1
 Group: Location/Libraries
 License: Apache-2.0
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(json-glib-1.0)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(eventsystem)
 BuildRequires:  pkgconfig(libtzplatform-config)
+BuildRequires:  pkgconfig(capi-system-sensor)
 
 %description
 Location Based Service Library
@@ -47,6 +48,12 @@ export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
 export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
 export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
 
+%ifarch %arm aarch64
+export CFLAGS="$CFLAGS -DTIZEN_DEVICE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEVICE"
+export FFLAGS="$FFLAGS -DTIZEN_DEVICE"
+%endif
+
 # Call make instruction with smp support
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} \