Fixed batch behavior in emulator mode 39/78839/1 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_wearable tizen_3.0.m2 accepted/tizen/3.0.m2/mobile/20170104.125103 accepted/tizen/3.0.m2/wearable/20170104.125726 accepted/tizen/3.0/common/20161114.105747 accepted/tizen/3.0/ivi/20161011.044309 accepted/tizen/3.0/wearable/20161015.083209 accepted/tizen/common/20160805.125858 accepted/tizen/ivi/20160808.080506 accepted/tizen/mobile/20160808.080421 accepted/tizen/unified/20170309.033226 accepted/tizen/wearable/20160808.080454 submit/tizen/20160805.024428 submit/tizen_3.0.m2/20170104.093750 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_ivi/20161010.000003 submit/tizen_3.0_mobile/20161015.000003 submit/tizen_3.0_wearable/20161015.000003 submit/tizen_unified/20170308.100408
authorkj7.sung <kj7.sung@samsung.com>
Thu, 7 Jul 2016 05:35:32 +0000 (14:35 +0900)
committerkj7.sung <kj7.sung@samsung.com>
Thu, 7 Jul 2016 05:35:32 +0000 (14:35 +0900)
Change-Id: I38b226feea28e1e42fc91dea56782b6ff015e4e5
Signed-off-by: kj7.sung <kj7.sung@samsung.com>
gps-plugin/include/gps_plugin_debug.h
gps-plugin/src/gps_plugin_replay.c
gps-plugin/src/nmea_parser.c
packaging/lbs-server-plugin-replay.spec

index d06956ecc2215ffff47b9e107c7c6bcf14771197..e74a02d3e3bd7e61a65573d4245cbba3870ec92b 100644 (file)
@@ -31,9 +31,9 @@ extern "C" {
 
 #ifdef GPS_DLOG
 #include <dlog.h>
-#define TAG_GPS_PLUGIN         "gps-plugin"
+#define TAG_GPS_PLUGIN         "LBS_REPLAY"
 
-#define DBG_LOW                LOG_UNKNOWN /* LOG_DEBUG */
+#define DBG_LOW                LOG_DEBUG
 #define DBG_INFO       LOG_INFO
 #define DBG_WARN       LOG_WARN
 #define DBG_ERR                LOG_ERROR
index 544ca63ba88515f8aa0af9f2695de6b12720aaf7..851f00a0bbe55bd94d6cb1a8e16a5f082b538a61 100644 (file)
@@ -51,6 +51,7 @@ typedef struct {
        int lcd_mode;
 
        int batch_mode;
+       int batch_client_count;
        int batch_interval;
        int batch_period;
        int num_of_batch;
@@ -109,51 +110,47 @@ void gps_plugin_replay_pos_event(pos_data_t *data)
 
 void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer)
 {
+       char buf[256] = {0, };
        time_t timestamp;
        time(&timestamp);
 
        const char *batch_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/location_batch.log");
        if (timer->batch_fd == NULL) {
-               if (timer->batch_mode == BATCH_MODE_ON) {
-
-                       struct stat st = {0};
-                       const char *lbs_server_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server");
-                       if (stat(lbs_server_path, &st) == -1) {
-                               if (mkdir(lbs_server_path, 0777) == -1) {
-                                       LOG_PLUGIN(DBG_ERR, "Fail to create lbs-server folder");
-                                       return ;
-                               }
-                       }
 
-                       timer->batch_fd = fopen(batch_path, "w+");
-                       if (timer->batch_fd == NULL) {
-                               LOG_PLUGIN(DBG_ERR, "Fail to open file [Not available batch_fd]");
+               struct stat st = {0};
+               const char *lbs_server_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server");
+               if (stat(lbs_server_path, &st) == -1) {
+                       if (mkdir(lbs_server_path, 0777) == -1) {
+                               LOG_PLUGIN(DBG_ERR, "Fail to create lbs-server folder");
                                return ;
                        }
                }
+
+               timer->batch_fd = fopen(batch_path, "w+");
+               if (timer->batch_fd == NULL) {
+                       LOG_PLUGIN(DBG_ERR, "Fail to open file [Not available batch_fd]");
+                       return ;
+               }
        }
 
        if (data != NULL) {
-               if (timer->batch_mode == BATCH_MODE_ON) {
-                       int ret = -1;
-                       char buf[256] = {0, };
-
-                       g_snprintf(buf, 256, "%ld;%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;%.2lf;\n", timestamp, data->latitude, data->longitude, data->altitude, data->speed, data->bearing, data->hor_accuracy, data->ver_accuracy);
-                       LOG_PLUGIN(DBG_LOW, "Add location info to batch file [%s]", buf);
 
-                       ret = fwrite(buf, 1, strlen(buf), timer->batch_fd);
-                       if (ret != strlen(buf))
-                               LOG_PLUGIN(DBG_ERR, "Fail to write file[%s]", batch_path);
-
-                       (timer->num_of_batch)++ ;
-               }
+               g_snprintf(buf, 256, "%ld;%.6lf;%.6lf;%.2lf;%.2lf;%.2lf;%.2lf;%.2lf;\n",
+                                               timestamp, data->latitude, data->longitude, data->altitude,
+                                               data->speed, data->bearing, data->hor_accuracy, data->ver_accuracy);
+               LOG_PLUGIN(DBG_LOW, "Add location info to batch file [%s]", buf);
        }
 
        if (timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL) {
-               if ((timestamp - timer->batch_start_time) >= timer->batch_interval)
-                       timer->is_flush = TRUE;
+               fwrite(buf, 1, strlen(buf), timer->batch_fd);
 
+               (timer->num_of_batch)++ ;
+               timer->is_flush = TRUE;
        } else {
+               if ((timestamp - timer->batch_start_time) % timer->batch_interval == 0) {
+                       fwrite(buf, 1, strlen(buf), timer->batch_fd);
+                       (timer->num_of_batch)++ ;
+               }
                if ((timestamp - timer->batch_start_time) >= timer->batch_period)
                        timer->is_flush = TRUE;
        }
@@ -306,11 +303,11 @@ gboolean gps_plugin_replay_read_nmea(replay_timeout *timer, char *nmea_data)
                        ref++;
                        if (ref > 1) {
                                fseek(timer->fd, -strlen(buf), SEEK_CUR);
-                               LOG_PLUGIN(DBG_LOW, "2nd GPGGA : stop to read nmea data");
+                               /* LOG_PLUGIN(DBG_LOW, "2nd GPGGA : stop to read nmea data"); */
                                ret = TRUE;
                                break;
                        } else if (ref == 1) {
-                               LOG_PLUGIN(DBG_LOW, "1st GPGGA : start to read nmea data");
+                               /* LOG_PLUGIN(DBG_LOW, "1st GPGGA : start to read nmea data"); */
                                strncpy(nmea_data, buf, strlen(buf));
                        }
                } else {
@@ -331,7 +328,7 @@ gboolean gps_plugin_replay_read_nmea(replay_timeout *timer, char *nmea_data)
                rewind(timer->fd);
                ret = TRUE;
        } else {
-               LOG_PLUGIN(DBG_LOW, "read nmea data [%s]", nmea_data);
+               /* LOG_PLUGIN(DBG_LOW, "read nmea data [%s]", nmea_data); */
        }
        return ret;
 }
@@ -402,62 +399,15 @@ gboolean gps_plugin_replay_timeout_cb(gpointer data)
        }
 
        if (g_gps_event_cb != NULL) {
-               if (err != READ_NOT_FIXED)
-                       gps_plugin_replay_pos_event(timer->pos_data);
-
-               gps_plugin_replay_sv_event(timer->sv_data);
-       }
-       ret = TRUE;
-       return ret;
-}
-
-gboolean gps_plugin_batch_replay_timeout_cb(gpointer data)
-{
-       gboolean ret = FALSE;
-       read_error_t err = READ_SUCCESS;
-       char nmea_data[REPLAY_NMEA_SET_SIZE] = { 0, };
-       replay_timeout *timer = (replay_timeout *) data;
-
-       if (timer == NULL) {
-               LOG_PLUGIN(DBG_ERR, "replay handel[timer] is NULL");
-               return FALSE;
-       }
-
-       memset(timer->pos_data, 0, sizeof(pos_data_t));
-       memset(timer->batch_data, 0, sizeof(batch_data_t));
-       memset(timer->sv_data, 0, sizeof(sv_data_t));
-
-       if (timer->replay_mode == REPLAY_NMEA) {
-               if (gps_plugin_replay_read_nmea(timer, nmea_data) == FALSE) {
-                       LOG_PLUGIN(DBG_ERR, "Fail to read nmea data from file");
-                       return FALSE;
-               } else {
-                       err = nmea_parser(nmea_data, timer->pos_data, timer->sv_data);
-                       if (err == READ_ERROR) {
-                               LOG_PLUGIN(DBG_ERR, "Fail to parser nmea data from file");
-                       } else if (err == READ_NOT_FIXED) {
-                               LOG_PLUGIN(DBG_LOW, "GPS position is not fixed");
-                               timer->sv_data->pos_valid = FALSE;
+               if (err != READ_NOT_FIXED) {
+                       if (timer->batch_mode == BATCH_MODE_ON) {
+                               gps_plugin_replay_batch_event(timer->pos_data, timer);
                        }
+
+                       gps_plugin_replay_pos_event(timer->pos_data);
                }
-       } else if (timer->replay_mode == REPLAY_MANUAL) {
-               if (gps_plugin_replay_read_manual(timer->pos_data) == FALSE) {
-                       LOG_PLUGIN(DBG_ERR, "Fail to read manual data");
-                       err = READ_ERROR;
-                       return FALSE;
-               } else {
-                       timer->sv_data->pos_valid = TRUE;
-                       err = READ_SUCCESS;
-               }
-       } else if (timer->replay_mode == REPLAY_OFF) {
-               LOG_PLUGIN(DBG_WARN, "replay_mode is OFF");
-               err = READ_NOT_FIXED;
-               timer->sv_data->pos_valid = FALSE;
-       }
 
-       if (g_gps_event_cb != NULL) {
-               if (timer->batch_mode == BATCH_MODE_ON)
-                       gps_plugin_replay_batch_event(timer->pos_data, timer);
+               gps_plugin_replay_sv_event(timer->sv_data);
        }
        ret = TRUE;
        return ret;
@@ -518,6 +468,7 @@ gboolean gps_plugin_get_nmea_fd(replay_timeout *timer)
 
 gboolean gps_plugin_start_replay_mode(replay_timeout *timer)
 {
+       LOG_PLUGIN(DBG_LOW, "gps_plugin_start replay mode");
        gboolean ret = FALSE;
 
        if (timer->replay_mode == REPLAY_NMEA) {
@@ -557,60 +508,48 @@ gboolean gps_plugin_start_replay_mode(replay_timeout *timer)
        return ret;
 }
 
-gboolean gps_plugin_start_batch_mode(replay_timeout *timer, int batch_interval, int batch_period)
+gboolean gps_plugin_update_batch_mode(replay_timeout *timer, int batch_interval, int batch_period)
 {
        gboolean ret = FALSE;
        time_t timestamp;
        time(&timestamp);
 
-       if (timer->replay_mode == REPLAY_NMEA) {
-               if (gps_plugin_get_nmea_fd(timer) == FALSE)
-                       return FALSE;
-       }
-
-       if (timer->default_context == NULL) {
-               timer->default_context = g_main_context_default();
-
-               if (timer->default_context == NULL)
-                       return ret;
+       if (timer->batch_mode == BATCH_MODE_OFF) {
+               timer->batch_mode = BATCH_MODE_ON;
+               timer->batch_client_count = 0;
        }
+       timer->batch_client_count++;
 
-       if (timer->timeout_src != NULL) {
-               LOG_PLUGIN(DBG_ERR, "timeout_src is already existed");
-               ret = FALSE;
-       } else {
-               timer->timeout_src = g_timeout_source_new_seconds(batch_interval);
-               if (timer->timeout_src != NULL) {
-                       g_source_set_callback(timer->timeout_src, &gps_plugin_batch_replay_timeout_cb, timer, NULL);
-                       if (g_source_attach(timer->timeout_src, timer->default_context) > 0) {
-                               LOG_PLUGIN(DBG_LOW, "timeout_src(0x%x) is created & attatched to 0x%x", timer->timeout_src, timer->default_context);
-                               ret = TRUE;
-                       } else {
-                               gps_plugin_stop_replay_mode(timer);
-                               ret = FALSE;
-                       }
-               }
-       }
-
-       gps_plugin_respond_start_session(ret);
-
-       timer->batch_mode = BATCH_MODE_ON;
        timer->batch_interval = batch_interval;
        timer->batch_period = batch_period;
        timer->batch_start_time = timestamp;
 
+       LOG_PLUGIN(DBG_LOW, "batch_client_count = %d", timer->batch_client_count);
        return ret;
 }
 
-void gps_plugin_stop_batch_mode(replay_timeout *timer)
+void gps_plugin_stop_batch_mode(replay_timeout *timer, int batch_interval, int batch_period)
 {
-       if (timer->batch_mode == BATCH_MODE_ON)
+       if (timer->batch_client_count > 0)
+               timer->batch_client_count--;
+
+       LOG_PLUGIN(DBG_ERR, "batch_client_count = %d", timer->batch_client_count);
+       if (timer->batch_client_count <= 0) {
                timer->batch_mode = BATCH_MODE_OFF;
+               timer->batch_interval = 0;
+               timer->batch_period = 0;
 
-       if (timer->batch_fd != NULL) {
-               fclose(timer->batch_fd);
-               timer->batch_fd = NULL;
-               timer->num_of_batch = 0;
+               if (timer->batch_fd != NULL) {
+                       fclose(timer->batch_fd);
+                       timer->batch_fd = NULL;
+                       timer->num_of_batch = 0;
+               }
+       } else {
+               timer->batch_interval = batch_interval;
+               timer->batch_period = batch_period;
+               time_t timestamp;
+               time(&timestamp);
+               timer->batch_start_time = timestamp;
        }
 }
 
@@ -660,7 +599,10 @@ replay_timeout *gps_plugin_replay_timer_init()
 
        timer->batch_fd = NULL;
        timer->num_of_batch = 0;
+       timer->batch_client_count = 0;
        timer->batch_mode = BATCH_MODE_OFF;
+       timer->batch_interval = 0;
+       timer->batch_period = 0;
        timer->is_flush = FALSE;
 
        if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &timer->replay_mode) == FALSE)
@@ -769,11 +711,16 @@ int gps_plugin_replay_gps_request(gps_action_t gps_action, void *gps_action_data
                gps_plugin_stop_replay_mode(g_replay_timer);
                break;
        case GPS_ACTION_START_BATCH:
-               gps_plugin_start_batch_mode(g_replay_timer, gps_start_data->interval, gps_start_data->period);
+               if (!gps_start_data->session_status)    /* need to start */
+                       gps_plugin_start_replay_mode(g_replay_timer);
+
+               gps_plugin_update_batch_mode(g_replay_timer, gps_start_data->interval, gps_start_data->period);
                break;
        case GPS_ACTION_STOP_BATCH:
-               gps_plugin_stop_batch_mode(g_replay_timer);
-               gps_plugin_stop_replay_mode(g_replay_timer);
+               if (!gps_start_data->session_status)    /* need to stop */
+                       gps_plugin_stop_replay_mode(g_replay_timer);
+
+               gps_plugin_stop_batch_mode(g_replay_timer, gps_start_data->interval, gps_start_data->period);
                break;
        case GPS_INDI_SUPL_VERIFICATION:
        case GPS_INDI_SUPL_DNSQUERY:
index d8bf178bcde0227d5f038cf9dedcafc49a9b62ee..945bd1730164b995cd8fa525f2b651751f52c9fc 100644 (file)
@@ -83,7 +83,7 @@ int nmea_parser_tokenize(char input[], char *token[])
        token[num_tokens] = s;
        num_tokens++;
        state = 0;
-       LOG_PLUGIN(DBG_LOW, "input:%s \n", input);
+       /* LOG_PLUGIN(DBG_LOW, "input:%s \n", input); */
 
        while ((*s != 0) && (num_tokens < MAX_TOEKNS)) {
                switch (state) {
@@ -197,7 +197,7 @@ static int nmea_parser_gprmc(char *token[], pos_data_t *pos)
 
        status = token[2];      /*warn = *token[2]; */
        if (strcmp(status, "V") == 0) {
-               LOG_PLUGIN(DBG_LOW, "Not fixed");
+               /* LOG_PLUGIN(DBG_LOW, "Not fixed"); */
                return READ_NOT_FIXED;
        }
 
@@ -224,7 +224,7 @@ static int nmea_parser_gpgll(char *token[], pos_data_t *pos)
 
        status = token[6];      /*warn = *token[2]; */
        if (strcmp(status, "V") == 0) {
-               LOG_PLUGIN(DBG_LOW, "Not fixed");
+               /* LOG_PLUGIN(DBG_LOW, "Not fixed"); */
                return READ_NOT_FIXED;
        }
 
@@ -243,7 +243,7 @@ static int nmea_parser_gpgsa(char *token[], pos_data_t *pos)
 
        fix_type = atoi(token[2]);
        if (fix_type == 1) {
-               LOG_PLUGIN(DBG_LOW, "Not fixed");
+               /* LOG_PLUGIN(DBG_LOW, "Not fixed"); */
                return READ_NOT_FIXED;
        }
 
@@ -352,14 +352,14 @@ int nmea_parser(char *data, pos_data_t *pos, sv_data_t *sv)
                num_sen++;
                nmea_sen[num_sen] = (char *)strtok_r(NULL, "$", &last);
        }
-       LOG_PLUGIN(DBG_LOW, "Number of NMEA sentences:%d \n", num_sen);
+       /* LOG_PLUGIN(DBG_LOW, "Number of NMEA sentences:%d \n", num_sen); */
 
        while (num_sen > 0) {
                if (nmea_parser_verify_checksum(nmea_sen[count]) == 0) {
                        nmea_parser_tokenize(nmea_sen[count], token);
                        err = nmea_parser_sentence(token[0], token, pos, sv);
                        if (err == READ_NOT_FIXED) {
-                               LOG_PLUGIN(DBG_LOW, "NOT Fixed");
+                               /* LOG_PLUGIN(DBG_LOW, "NOT Fixed"); */
                                ret = err;
                        } else if (err == READ_ERROR) {
                                ret = err;
index 3df890c80feadae658d84e48ecbb2783a3288e1c..867b3188474beb90bc768af651a1fd9905ba7d63 100644 (file)
@@ -1,6 +1,6 @@
 Name:       lbs-server-plugin-replay
 Summary:    LBS Server plugin library for replay mode
-Version:    0.2.4
+Version:    0.2.5
 Release:    1
 Group:      Location/Libraries
 License:    Apache-2.0