Add new utilities
This change makes modifications to existing utilities and adds a couple of new utilites to help with the launcher Change-Id: Ib65ffe8e60c7e4a824c5c362765df5dcba872424 CRs-fixed: 600179
This commit is contained in:
parent
7e53be85c9
commit
4460543e7d
8 changed files with 458 additions and 182 deletions
|
@ -19,7 +19,8 @@ LOCAL_SRC_FILES += \
|
|||
linked_list.c \
|
||||
loc_target.cpp \
|
||||
loc_timer.c \
|
||||
../platform_lib_abstractions/elapsed_millis_since_boot.cpp
|
||||
../platform_lib_abstractions/elapsed_millis_since_boot.cpp \
|
||||
loc_misc_utils.cpp
|
||||
|
||||
LOCAL_CFLAGS += \
|
||||
-fno-short-enums \
|
||||
|
@ -46,7 +47,8 @@ LOCAL_COPY_HEADERS:= \
|
|||
loc_timer.h \
|
||||
../platform_lib_abstractions/platform_lib_includes.h \
|
||||
../platform_lib_abstractions/platform_lib_time.h \
|
||||
../platform_lib_abstractions/platform_lib_macros.h
|
||||
../platform_lib_abstractions/platform_lib_macros.h \
|
||||
loc_misc_utils.h
|
||||
|
||||
LOCAL_MODULE := libgps.utils
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
|
@ -39,6 +39,7 @@
|
|||
#include <time.h>
|
||||
#include <loc_cfg.h>
|
||||
#include <log_util.h>
|
||||
#include <loc_misc_utils.h>
|
||||
#ifdef USE_GLIB
|
||||
#include <glib.h>
|
||||
#endif
|
||||
|
@ -57,62 +58,17 @@ static uint8_t TIMESTAMP = 0;
|
|||
/* Parameter spec table */
|
||||
static loc_param_s_type loc_parameter_table[] =
|
||||
{
|
||||
{"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'},
|
||||
{"TIMESTAMP", &TIMESTAMP, NULL, 'n'},
|
||||
{"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'},
|
||||
{"TIMESTAMP", &TIMESTAMP, NULL, 'n'},
|
||||
};
|
||||
int loc_param_num = sizeof(loc_parameter_table) / sizeof(loc_param_s_type);
|
||||
|
||||
/*===========================================================================
|
||||
FUNCTION trim_space
|
||||
|
||||
DESCRIPTION
|
||||
Removes leading and trailing spaces of the string
|
||||
|
||||
DEPENDENCIES
|
||||
N/A
|
||||
|
||||
RETURN VALUE
|
||||
None
|
||||
|
||||
SIDE EFFECTS
|
||||
N/A
|
||||
===========================================================================*/
|
||||
void trim_space(char *org_string)
|
||||
{
|
||||
char *scan_ptr, *write_ptr;
|
||||
char *first_nonspace = NULL, *last_nonspace = NULL;
|
||||
|
||||
scan_ptr = write_ptr = org_string;
|
||||
|
||||
while (*scan_ptr)
|
||||
{
|
||||
if ( !isspace(*scan_ptr) && first_nonspace == NULL)
|
||||
{
|
||||
first_nonspace = scan_ptr;
|
||||
}
|
||||
|
||||
if (first_nonspace != NULL)
|
||||
{
|
||||
*(write_ptr++) = *scan_ptr;
|
||||
if ( !isspace(*scan_ptr))
|
||||
{
|
||||
last_nonspace = write_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
scan_ptr++;
|
||||
}
|
||||
|
||||
if (last_nonspace) { *last_nonspace = '\0'; }
|
||||
}
|
||||
|
||||
typedef struct loc_param_v_type
|
||||
{
|
||||
char* param_name;
|
||||
|
||||
char* param_str_value;
|
||||
int param_int_value;
|
||||
double param_double_value;
|
||||
char* param_name;
|
||||
char* param_str_value;
|
||||
int param_int_value;
|
||||
double param_double_value;
|
||||
}loc_param_v_type;
|
||||
|
||||
/*===========================================================================
|
||||
|
@ -136,61 +92,166 @@ RETURN VALUE
|
|||
SIDE EFFECTS
|
||||
N/A
|
||||
===========================================================================*/
|
||||
void loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value)
|
||||
int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value)
|
||||
{
|
||||
if(NULL == config_entry || NULL == config_value)
|
||||
{
|
||||
LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
int ret=-1;
|
||||
if(NULL == config_entry || NULL == config_value)
|
||||
{
|
||||
LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strcmp(config_entry->param_name, config_value->param_name) == 0 &&
|
||||
config_entry->param_ptr)
|
||||
{
|
||||
switch (config_entry->param_type)
|
||||
{
|
||||
case 's':
|
||||
if (strcmp(config_value->param_str_value, "NULL") == 0)
|
||||
{
|
||||
*((char*)config_entry->param_ptr) = '\0';
|
||||
}
|
||||
else {
|
||||
strlcpy((char*) config_entry->param_ptr,
|
||||
config_value->param_str_value,
|
||||
LOC_MAX_PARAM_STRING + 1);
|
||||
}
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr);
|
||||
if (strcmp(config_entry->param_name, config_value->param_name) == 0 &&
|
||||
config_entry->param_ptr)
|
||||
{
|
||||
switch (config_entry->param_type)
|
||||
{
|
||||
case 's':
|
||||
if (strcmp(config_value->param_str_value, "NULL") == 0)
|
||||
{
|
||||
*((char*)config_entry->param_ptr) = '\0';
|
||||
}
|
||||
else {
|
||||
strlcpy((char*) config_entry->param_ptr,
|
||||
config_value->param_str_value,
|
||||
LOC_MAX_PARAM_STRING + 1);
|
||||
}
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr);
|
||||
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
*((int *)config_entry->param_ptr) = config_value->param_int_value;
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, config_entry->param_name, config_value->param_int_value);
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
ret = 0;
|
||||
break;
|
||||
case 'n':
|
||||
*((int *)config_entry->param_ptr) = config_value->param_int_value;
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, config_entry->param_name, config_value->param_int_value);
|
||||
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
*((double *)config_entry->param_ptr) = config_value->param_double_value;
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, config_entry->param_name, config_value->param_double_value);
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
ret = 0;
|
||||
break;
|
||||
case 'f':
|
||||
*((double *)config_entry->param_ptr) = config_value->param_double_value;
|
||||
/* Log INI values */
|
||||
LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, config_entry->param_name, config_value->param_double_value);
|
||||
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name);
|
||||
}
|
||||
}
|
||||
if(NULL != config_entry->param_set)
|
||||
{
|
||||
*(config_entry->param_set) = 1;
|
||||
}
|
||||
ret = 0;
|
||||
break;
|
||||
default:
|
||||
LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*===========================================================================
|
||||
FUNCTION loc_read_conf_r (repetitive)
|
||||
|
||||
DESCRIPTION
|
||||
Reads the specified configuration file and sets defined values based on
|
||||
the passed in configuration table. This table maps strings to values to
|
||||
set along with the type of each of these values.
|
||||
The difference between this and loc_read_conf is that this function returns
|
||||
the file pointer position at the end of filling a config table. Also, it
|
||||
reads a fixed number of parameters at a time which is equal to the length
|
||||
of the configuration table. This functionality enables the caller to
|
||||
repeatedly call the function to read data from the same file.
|
||||
|
||||
PARAMETERS:
|
||||
conf_fp : file pointer
|
||||
config_table: table definition of strings to places to store information
|
||||
table_length: length of the configuration table
|
||||
|
||||
DEPENDENCIES
|
||||
N/A
|
||||
|
||||
RETURN VALUE
|
||||
0: Table filled successfully
|
||||
1: No more parameters to read
|
||||
-1: Error filling table
|
||||
|
||||
SIDE EFFECTS
|
||||
N/A
|
||||
===========================================================================*/
|
||||
int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length)
|
||||
{
|
||||
char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */
|
||||
char *lasts;
|
||||
loc_param_v_type config_value;
|
||||
uint32_t i;
|
||||
int ret=0;
|
||||
|
||||
unsigned int num_params=table_length;
|
||||
if(conf_fp == NULL) {
|
||||
LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__);
|
||||
ret = -1;
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Clear all validity bits */
|
||||
for(i = 0; NULL != config_table && i < table_length; i++)
|
||||
{
|
||||
if(NULL != config_table[i].param_set)
|
||||
{
|
||||
*(config_table[i].param_set) = 0;
|
||||
}
|
||||
}
|
||||
LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params);
|
||||
while(num_params)
|
||||
{
|
||||
if(!fgets(input_buf, LOC_MAX_PARAM_LINE, conf_fp)) {
|
||||
LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__);
|
||||
break;
|
||||
}
|
||||
|
||||
memset(&config_value, 0, sizeof(config_value));
|
||||
|
||||
/* Separate variable and value */
|
||||
config_value.param_name = strtok_r(input_buf, "=", &lasts);
|
||||
/* skip lines that do not contain "=" */
|
||||
if (config_value.param_name == NULL) continue;
|
||||
config_value.param_str_value = strtok_r(NULL, "=", &lasts);
|
||||
/* skip lines that do not contain two operands */
|
||||
if (config_value.param_str_value == NULL) continue;
|
||||
|
||||
/* Trim leading and trailing spaces */
|
||||
loc_util_trim_space(config_value.param_name);
|
||||
loc_util_trim_space(config_value.param_str_value);
|
||||
|
||||
/* Parse numerical value */
|
||||
if ((strlen(config_value.param_str_value) >=3) &&
|
||||
(config_value.param_str_value[0] == '0') &&
|
||||
(tolower(config_value.param_str_value[1]) == 'x'))
|
||||
{
|
||||
/* hex */
|
||||
config_value.param_int_value = (int) strtol(&config_value.param_str_value[2],
|
||||
(char**) NULL, 16);
|
||||
}
|
||||
else {
|
||||
config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
|
||||
config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
|
||||
}
|
||||
|
||||
for(i = 0; NULL != config_table && i < table_length; i++)
|
||||
{
|
||||
if(!loc_set_config_entry(&config_table[i], &config_value)) {
|
||||
num_params--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*===========================================================================
|
||||
|
@ -215,72 +276,25 @@ RETURN VALUE
|
|||
SIDE EFFECTS
|
||||
N/A
|
||||
===========================================================================*/
|
||||
void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, uint32_t table_length)
|
||||
void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table,
|
||||
uint32_t table_length)
|
||||
{
|
||||
FILE *gps_conf_fp = NULL;
|
||||
char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */
|
||||
char *lasts;
|
||||
loc_param_v_type config_value;
|
||||
uint32_t i;
|
||||
FILE *gps_conf_fp = NULL;
|
||||
char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */
|
||||
char *lasts;
|
||||
loc_param_v_type config_value;
|
||||
uint32_t i;
|
||||
|
||||
if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL)
|
||||
{
|
||||
LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOC_LOGW("%s: no %s file found", __FUNCTION__, conf_file_name);
|
||||
loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
|
||||
return; /* no parameter file */
|
||||
}
|
||||
|
||||
/* Clear all validity bits */
|
||||
for(i = 0; NULL != config_table && i < table_length; i++)
|
||||
{
|
||||
if(NULL != config_table[i].param_set)
|
||||
{
|
||||
*(config_table[i].param_set) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while(fgets(input_buf, LOC_MAX_PARAM_LINE, gps_conf_fp) != NULL)
|
||||
{
|
||||
memset(&config_value, 0, sizeof(config_value));
|
||||
|
||||
/* Separate variable and value */
|
||||
config_value.param_name = strtok_r(input_buf, "=", &lasts);
|
||||
if (config_value.param_name == NULL) continue; /* skip lines that do not contain "=" */
|
||||
config_value.param_str_value = strtok_r(NULL, "=", &lasts);
|
||||
if (config_value.param_str_value == NULL) continue; /* skip lines that do not contain two operands */
|
||||
|
||||
/* Trim leading and trailing spaces */
|
||||
trim_space(config_value.param_name);
|
||||
trim_space(config_value.param_str_value);
|
||||
|
||||
/* Parse numerical value */
|
||||
if (config_value.param_str_value[0] == '0' && tolower(config_value.param_str_value[1]) == 'x')
|
||||
{
|
||||
/* hex */
|
||||
config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], (char**) NULL, 16);
|
||||
}
|
||||
else {
|
||||
config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */
|
||||
config_value.param_int_value = atoi(config_value.param_str_value); /* dec */
|
||||
}
|
||||
|
||||
for(i = 0; NULL != config_table && i < table_length; i++)
|
||||
{
|
||||
loc_set_config_entry(&config_table[i], &config_value);
|
||||
}
|
||||
|
||||
for(i = 0; i < loc_param_num; i++)
|
||||
{
|
||||
loc_set_config_entry(&loc_parameter_table[i], &config_value);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(gps_conf_fp);
|
||||
|
||||
/* Initialize logging mechanism with parsed data */
|
||||
loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
|
||||
if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL)
|
||||
{
|
||||
LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name);
|
||||
if(table_length && config_table) {
|
||||
loc_read_conf_r(gps_conf_fp, config_table, table_length);
|
||||
rewind(gps_conf_fp);
|
||||
}
|
||||
loc_read_conf_r(gps_conf_fp, loc_parameter_table, loc_param_num);
|
||||
fclose(gps_conf_fp);
|
||||
}
|
||||
/* Initialize logging mechanism with parsed data */
|
||||
loc_logger_init(DEBUG_LEVEL, TIMESTAMP);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
|
@ -30,6 +30,7 @@
|
|||
#ifndef LOC_CFG_H
|
||||
#define LOC_CFG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define LOC_MAX_PARAM_NAME 48
|
||||
|
@ -75,7 +76,7 @@ extern "C" {
|
|||
extern void loc_read_conf(const char* conf_file_name,
|
||||
loc_param_s_type* config_table,
|
||||
uint32_t table_length);
|
||||
|
||||
extern int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
114
utils/loc_misc_utils.cpp
Normal file
114
utils/loc_misc_utils.cpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation, nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <log_util.h>
|
||||
#include <loc_misc_utils.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define LOG_NDDEBUG 0
|
||||
#define LOG_TAG "LocSvc_misc_utils"
|
||||
|
||||
int loc_util_split_string(char *raw_string, char **split_strings_ptr,
|
||||
int max_num_substrings, char delimiter)
|
||||
{
|
||||
int raw_string_index=0;
|
||||
int num_split_strings=0;
|
||||
unsigned char end_string=0;
|
||||
int raw_string_length=0;
|
||||
|
||||
if(!raw_string || !split_strings_ptr) {
|
||||
LOC_LOGE("%s:%d]: NULL parameters", __func__, __LINE__);
|
||||
num_split_strings = -1;
|
||||
goto err;
|
||||
}
|
||||
LOC_LOGD("%s:%d]: raw string: %s\n", __func__, __LINE__, raw_string);
|
||||
raw_string_length = strlen(raw_string) + 1;
|
||||
split_strings_ptr[num_split_strings] = &raw_string[raw_string_index];
|
||||
for(raw_string_index=0; raw_string_index < raw_string_length; raw_string_index++) {
|
||||
if(raw_string[raw_string_index] == '\0')
|
||||
end_string=1;
|
||||
if((raw_string[raw_string_index] == delimiter) || end_string) {
|
||||
raw_string[raw_string_index] = '\0';
|
||||
LOC_LOGD("%s:%d]: split string: %s\n",
|
||||
__func__, __LINE__, split_strings_ptr[num_split_strings]);
|
||||
num_split_strings++;
|
||||
if(((raw_string_index + 1) < raw_string_length) &&
|
||||
(num_split_strings < max_num_substrings)) {
|
||||
split_strings_ptr[num_split_strings] = &raw_string[raw_string_index+1];
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(end_string)
|
||||
break;
|
||||
}
|
||||
err:
|
||||
LOC_LOGD("%s:%d]: num_split_strings: %d\n", __func__, __LINE__, num_split_strings);
|
||||
return num_split_strings;
|
||||
}
|
||||
|
||||
void loc_util_trim_space(char *org_string)
|
||||
{
|
||||
char *scan_ptr, *write_ptr;
|
||||
char *first_nonspace = NULL, *last_nonspace = NULL;
|
||||
|
||||
if(org_string == NULL) {
|
||||
LOC_LOGE("%s:%d]: NULL parameter", __func__, __LINE__);
|
||||
goto err;
|
||||
}
|
||||
|
||||
scan_ptr = write_ptr = org_string;
|
||||
|
||||
while (*scan_ptr) {
|
||||
//Find the first non-space character
|
||||
if ( !isspace(*scan_ptr) && first_nonspace == NULL) {
|
||||
first_nonspace = scan_ptr;
|
||||
}
|
||||
//Once the first non-space character is found in the
|
||||
//above check, keep shifting the characters to the left
|
||||
//to replace the spaces
|
||||
if (first_nonspace != NULL) {
|
||||
*(write_ptr++) = *scan_ptr;
|
||||
//Keep track of which was the last non-space character
|
||||
//encountered
|
||||
//last_nonspace will not be updated in the case where
|
||||
//the string ends with spaces
|
||||
if ( !isspace(*scan_ptr)) {
|
||||
last_nonspace = write_ptr;
|
||||
}
|
||||
}
|
||||
scan_ptr++;
|
||||
}
|
||||
//Add NULL terminator after the last non-space character
|
||||
if (last_nonspace) { *last_nonspace = '\0'; }
|
||||
err:
|
||||
return;
|
||||
}
|
99
utils/loc_misc_utils.h
Normal file
99
utils/loc_misc_utils.h
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* Copyright (c) 2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* * Neither the name of The Linux Foundation, nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#ifndef _LOC_MISC_UTILS_H_
|
||||
#define _LOC_MISC_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*===========================================================================
|
||||
FUNCTION loc_split_string
|
||||
|
||||
DESCRIPTION:
|
||||
This function is used to split a delimiter separated string into
|
||||
sub-strings. This function does not allocate new memory to store the split
|
||||
strings. Instead, it places '\0' in places of delimiters and assings the
|
||||
starting address of the substring within the raw string as the string address
|
||||
The input raw_string no longer remains to be a collection of sub-strings
|
||||
after this function is executed.
|
||||
Please make a copy of the input string before calling this function if
|
||||
necessary
|
||||
|
||||
PARAMETERS:
|
||||
char *raw_string: is the original string with delimiter separated substrings
|
||||
char **split_strings_ptr: is the arraw of pointers which will hold the addresses
|
||||
of individual substrings
|
||||
int max_num_substrings: is the maximum number of substrings that are expected
|
||||
by the caller. The array of pointers in the above parameter
|
||||
is usually this long
|
||||
char delimiter: is the delimiter that separates the substrings. Examples: ' ', ';'
|
||||
|
||||
DEPENDENCIES
|
||||
N/A
|
||||
|
||||
RETURN VALUE
|
||||
int Number of split strings
|
||||
|
||||
SIDE EFFECTS
|
||||
The input raw_string no longer remains a delimiter separated single string.
|
||||
|
||||
EXAMPLE
|
||||
delimiter = ' ' //space
|
||||
raw_string = "hello new user" //delimiter is space ' '
|
||||
addresses = 0123456789abcd
|
||||
split_strings_ptr[0] = &raw_string[0]; //split_strings_ptr[0] contains "hello"
|
||||
split_strings_ptr[1] = &raw_string[6]; //split_strings_ptr[1] contains "new"
|
||||
split_strings_ptr[2] = &raw_string[a]; //split_strings_ptr[2] contains "user"
|
||||
|
||||
===========================================================================*/
|
||||
int loc_util_split_string(char *raw_string, char **split_strings_ptr, int max_num_substrings,
|
||||
char delimiter);
|
||||
|
||||
/*===========================================================================
|
||||
FUNCTION trim_space
|
||||
|
||||
DESCRIPTION
|
||||
Removes leading and trailing spaces of the string
|
||||
|
||||
DEPENDENCIES
|
||||
N/A
|
||||
|
||||
RETURN VALUE
|
||||
None
|
||||
|
||||
SIDE EFFECTS
|
||||
N/A
|
||||
===========================================================================*/
|
||||
void loc_util_trim_space(char *org_string);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_LOC_MISC_UTILS_H_
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
|
@ -141,6 +141,34 @@ static bool is_qca1530(void)
|
|||
return res;
|
||||
}
|
||||
|
||||
/*The character array passed to this function should have length
|
||||
of atleast PROPERTY_VALUE_MAX*/
|
||||
void loc_get_target_baseband(char *baseband, int array_length)
|
||||
{
|
||||
if(baseband && (array_length >= PROPERTY_VALUE_MAX)) {
|
||||
property_get("ro.baseband", baseband, "");
|
||||
LOC_LOGD("%s:%d]: Baseband: %s\n", __func__, __LINE__, baseband);
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: NULL parameter or array length less than PROPERTY_VALUE_MAX\n",
|
||||
__func__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
/*The character array passed to this function should have length
|
||||
of atleast PROPERTY_VALUE_MAX*/
|
||||
void loc_get_platform_name(char *platform_name, int array_length)
|
||||
{
|
||||
if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) {
|
||||
property_get("ro.board.platform", platform_name, "");
|
||||
LOC_LOGD("%s:%d]: Target name: %s\n", __func__, __LINE__, platform_name);
|
||||
}
|
||||
else {
|
||||
LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n",
|
||||
__func__, __LINE__);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int loc_get_target(void)
|
||||
{
|
||||
if (gTarget != (unsigned int)-1)
|
||||
|
@ -163,7 +191,8 @@ unsigned int loc_get_target(void)
|
|||
goto detected;
|
||||
}
|
||||
|
||||
property_get("ro.baseband", baseband, "");
|
||||
loc_get_target_baseband(baseband, sizeof(baseband));
|
||||
|
||||
if (!access(hw_platform, F_OK)) {
|
||||
read_a_line(hw_platform, rd_hw_platform, LINE_LEN);
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
|
@ -45,6 +45,13 @@ extern "C"
|
|||
|
||||
unsigned int loc_get_target(void);
|
||||
|
||||
/*The character array passed to this function should have length
|
||||
of atleast PROPERTY_VALUE_MAX*/
|
||||
void loc_get_target_baseband(char *baseband, int array_length);
|
||||
/*The character array passed to this function should have length
|
||||
of atleast PROPERTY_VALUE_MAX*/
|
||||
void loc_get_platform_name(char *platform_name, int array_length);
|
||||
|
||||
/* Please remember to update 'target_name' in loc_log.cpp,
|
||||
if do any changes to this enum. */
|
||||
typedef enum {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (c) 2011 The Linux Foundation. All rights reserved.
|
||||
/* Copyright (c) 2011-2014 The Linux Foundation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
|
@ -96,24 +96,34 @@ extern char* get_timestamp(char* str, unsigned long buf_size);
|
|||
if that value remains unchanged, it means gps.conf did not
|
||||
provide a value and we default to the initial value to use
|
||||
Android's logging levels*/
|
||||
#define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5))
|
||||
|
||||
#define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5))
|
||||
|
||||
#define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5))
|
||||
|
||||
#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5))
|
||||
|
||||
#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5))
|
||||
|
||||
#define LOC_LOGE(...) \
|
||||
if ((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("W/"__VA_ARGS__); }
|
||||
IF_LOC_LOGE { ALOGE("E/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("E/"__VA_ARGS__); }
|
||||
|
||||
#define LOC_LOGW(...) \
|
||||
if ((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \
|
||||
IF_LOC_LOGW { ALOGE("W/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGW("W/"__VA_ARGS__); }
|
||||
|
||||
#define LOC_LOGI(...) \
|
||||
if ((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("I/"__VA_ARGS__); } \
|
||||
IF_LOC_LOGI { ALOGE("I/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGI("I/"__VA_ARGS__); }
|
||||
|
||||
#define LOC_LOGD(...) \
|
||||
if ((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("D/"__VA_ARGS__); } \
|
||||
IF_LOC_LOGD { ALOGE("D/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGD("D/"__VA_ARGS__); }
|
||||
|
||||
#define LOC_LOGV(...) \
|
||||
if ((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("V/"__VA_ARGS__); } \
|
||||
IF_LOC_LOGV { ALOGE("V/"__VA_ARGS__); } \
|
||||
else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGV("V/"__VA_ARGS__); }
|
||||
|
||||
#else /* DEBUG_DMN_LOC_API */
|
||||
|
|
Loading…
Reference in a new issue