#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;
int batch_interval;
int batch_period;
int num_of_batch;
+ int batch_buf_size;
time_t batch_start_time;
gboolean is_flush;
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;
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;
} 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) {
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);
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;
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)
timer->timeout_src = NULL;
timer->default_context = NULL;
+ timer->batch_buf = NULL;
return timer;
}