From 1baf75181f4309f0976469870f02e049e11408bb Mon Sep 17 00:00:00 2001 From: "kj7.sung" Date: Thu, 21 Sep 2017 11:03:53 +0900 Subject: [PATCH] sync : Fix build warning - batch changed to dbus (file logging removed) Change-Id: I60a41c994cd3a164d5b5bba576793b197d97a246 Signed-off-by: kj7.sung --- gps-plugin/src/gps_plugin_replay.c | 95 ++++++++++++------------- packaging/lbs-server-plugin-replay.spec | 2 +- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/gps-plugin/src/gps_plugin_replay.c b/gps-plugin/src/gps_plugin_replay.c index 7e47745..a6996a6 100644 --- a/gps-plugin/src/gps_plugin_replay.c +++ b/gps-plugin/src/gps_plugin_replay.c @@ -36,18 +36,12 @@ #define REPLAY_NMEA_SET_SIZE 4096 #define REPLAY_NMEA_SENTENCE_SIZE 128 -#define MIN(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) - gps_event_cb g_gps_event_cb = NULL; void *g_user_data = NULL; typedef struct { FILE *fd; - FILE *batch_fd; int interval; int replay_mode; int lcd_mode; @@ -57,6 +51,7 @@ typedef struct { int batch_interval; int batch_period; int num_of_batch; + int batch_buf_size; time_t batch_start_time; gboolean is_flush; @@ -64,6 +59,7 @@ typedef struct { batch_data_t *batch_data; sv_data_t *sv_data; nmea_data_t *nmea_data; + pos_data_t *batch_buf; GSource *timeout_src; GMainContext *default_context; @@ -110,64 +106,63 @@ void gps_plugin_replay_pos_event(pos_data_t *data) g_gps_event_cb(&gps_event, g_user_data); } +void add_batch_data(pos_data_t *data, replay_timeout *timer, int idx, time_t timestamp) +{ + timer->batch_buf[idx].timestamp = timestamp; + timer->batch_buf[idx].latitude = data->latitude; + timer->batch_buf[idx].longitude = data->longitude; + timer->batch_buf[idx].altitude = data->altitude; + timer->batch_buf[idx].speed = data->speed; + timer->batch_buf[idx].bearing = data->bearing; + timer->batch_buf[idx].hor_accuracy = data->hor_accuracy; + timer->batch_buf[idx].ver_accuracy = data->ver_accuracy; +} + void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer) { - char buf[256] = {0, }; time_t timestamp; time(×tamp); - const char *batch_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/location_batch.log"); - if (timer->batch_fd == NULL) { - - 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 (timer->num_of_batch < 1) { + if (timer->batch_buf) { + free(timer->batch_buf); + timer->batch_buf = NULL; } - } - - if (data != NULL) { - 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); + int size = timer->batch_period / timer->batch_interval; + timer->batch_buf = (pos_data_t *) malloc(sizeof(pos_data_t) * size); + LOG_PLUGIN(DBG_LOW, "--> set batch_buf[size : %d]", size); + timer->batch_buf_size = size; } if (timer->lcd_mode == VCONFKEY_PM_STATE_NORMAL) { - fwrite(buf, 1, strlen(buf), timer->batch_fd); - (timer->num_of_batch)++ ; + if (timer->num_of_batch < timer->batch_buf_size) { + add_batch_data(data, timer, timer->num_of_batch, timestamp); + (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 (timer->num_of_batch < timer->batch_buf_size) { + add_batch_data(data, timer, timer->num_of_batch, timestamp); + (timer->num_of_batch)++ ; + } } + if ((timestamp - timer->batch_start_time) >= timer->batch_period) timer->is_flush = TRUE; } + /** + * invoke collected postion infomations in every batch period. + */ if (timer->is_flush) { LOG_PLUGIN(DBG_LOW, "Batch invoked, Batch interval is expired or Batch stopped"); gps_event_info_t gps_event; memset(&gps_event, 0, sizeof(gps_event_info_t)); - if (timer->batch_fd != NULL) { - if (fclose(timer->batch_fd) != 0) - LOG_PLUGIN(DBG_ERR, "Fail to close file"); - timer->batch_fd = NULL; - } - gps_event.event_id = GPS_EVENT_REPORT_BATCH; timer->batch_start_time = timestamp; timer->is_flush = FALSE; @@ -178,6 +173,7 @@ void gps_plugin_replay_batch_event(pos_data_t *data, replay_timeout *timer) } else { gps_event.event_data.batch_ind.error = GPS_ERR_NONE; gps_event.event_data.batch_ind.batch.num_of_location = timer->num_of_batch; + gps_event.event_data.batch_ind.batch.data = timer->batch_buf; } if (g_gps_event_cb != NULL) { @@ -452,15 +448,15 @@ gboolean gps_plugin_get_nmea_fd(replay_timeout *timer) if (str == NULL) return FALSE; - const char *nmea_file_path = tzplatform_mkpath(TZ_SYS_MEDIA, "lbs-server/replay/"); + const char *nmea_file_path = tzplatform_mkpath(TZ_SYS_SHARE, "location/replay/"); snprintf(replay_file_path, sizeof(replay_file_path), "%s%s", nmea_file_path, str); - SECLOG_PLUGIN(DBG_ERR, "replay file name : %s", replay_file_path); + SECLOG_PLUGIN(DBG_ERR, "check custom replay : %s", replay_file_path); free(str); timer->fd = fopen(replay_file_path, "r"); if (timer->fd == NULL) { - SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", replay_file_path); const char *default_nmea_log = tzplatform_mkpath(TZ_SYS_RO_ETC, "lbs-server/replay/nmea_replay.log"); + SECLOG_PLUGIN(DBG_ERR, "fopen failed(%s). loading default(%s) ", replay_file_path, default_nmea_log); timer->fd = fopen(default_nmea_log, "r"); if (timer->fd == NULL) { SECLOG_PLUGIN(DBG_ERR, "fopen(%s) failed", default_nmea_log); @@ -543,11 +539,13 @@ void gps_plugin_stop_batch_mode(replay_timeout *timer, int batch_interval, int b 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_buf) { + free(timer->batch_buf); + timer->batch_buf = NULL; } + timer->num_of_batch = 0; + timer->batch_buf_size = 0; + } else { timer->batch_interval = batch_interval; timer->batch_period = batch_period; @@ -601,12 +599,12 @@ replay_timeout *gps_plugin_replay_timer_init() timer->fd = NULL; timer->interval = 1; - 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->batch_buf_size = 0; timer->is_flush = FALSE; if (setting_get_int(VCONFKEY_LOCATION_REPLAY_MODE, &timer->replay_mode) == FALSE) @@ -655,6 +653,7 @@ replay_timeout *gps_plugin_replay_timer_init() timer->timeout_src = NULL; timer->default_context = NULL; + timer->batch_buf = NULL; return timer; } diff --git a/packaging/lbs-server-plugin-replay.spec b/packaging/lbs-server-plugin-replay.spec index ceb7038..358b9ff 100644 --- a/packaging/lbs-server-plugin-replay.spec +++ b/packaging/lbs-server-plugin-replay.spec @@ -1,6 +1,6 @@ Name: lbs-server-plugin-replay Summary: LBS Server plugin library for replay mode -Version: 0.2.5 +Version: 0.2.7 Release: 1 Group: Location/Libraries License: Apache-2.0 -- 2.34.1