diff options
author | Valeri Atamaniouk <valeria@codeaurora.org> | 2015-10-21 18:53:58 +0300 |
---|---|---|
committer | Valeri Atamaniouk <valeria@codeaurora.org> | 2015-11-09 11:33:15 +0200 |
commit | 78bb13288e9ac69a985cf8a4b8c15b21770b59c5 (patch) | |
tree | 16c9b3b8582db269f758c24b3a44c439539fa7ff /utils | |
parent | 15ea4fca381ca7cc2085fae72318a9b0c1cedbed (diff) | |
download | gps-78bb13288e9ac69a985cf8a4b8c15b21770b59c5.tar.gz |
Location: reduce memory footprint
Reduce memory footprint by moving data sets into const
data segments. Update function parameters to accept const
parameters when appropriate.
CRs-fixed: 928770
Change-Id: I42955cf18de2b0541cfaed89359cdcf9ae6fea8a
Diffstat (limited to 'utils')
-rw-r--r-- | utils/loc_cfg.cpp | 16 | ||||
-rw-r--r-- | utils/loc_cfg.h | 10 | ||||
-rw-r--r-- | utils/loc_log.cpp | 22 | ||||
-rw-r--r-- | utils/loc_log.h | 17 |
4 files changed, 34 insertions, 31 deletions
diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index 5c33320..967d2f3 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, 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 @@ -56,12 +56,12 @@ static uint32_t DEBUG_LEVEL = 0xff; static uint32_t TIMESTAMP = 0; /* Parameter spec table */ -static loc_param_s_type loc_param_table[] = +static const loc_param_s_type loc_param_table[] = { {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, }; -int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); +static const int loc_param_num = sizeof(loc_param_table) / sizeof(loc_param_s_type); typedef struct loc_param_v_type { @@ -92,7 +92,7 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) +int loc_set_config_entry(const loc_param_s_type* config_entry, loc_param_v_type* config_value) { int ret=-1; if(NULL == config_entry || NULL == config_value) @@ -181,7 +181,7 @@ SIDE EFFECTS N/A ===========================================================================*/ int loc_fill_conf_item(char* input_buf, - loc_param_s_type* config_table, uint32_t table_length) + const loc_param_s_type* config_table, uint32_t table_length) { int ret = 0; @@ -258,7 +258,7 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length) +int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table, uint32_t table_length) { int ret=0; @@ -322,7 +322,7 @@ SIDE EFFECTS N/A ===========================================================================*/ int loc_update_conf(const char* conf_data, int32_t length, - loc_param_s_type* config_table, uint32_t table_length) + const loc_param_s_type* config_table, uint32_t table_length) { int ret = -1; @@ -377,7 +377,7 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, +void loc_read_conf(const char* conf_file_name, const loc_param_s_type* config_table, uint32_t table_length) { FILE *conf_fp = NULL; diff --git a/utils/loc_cfg.h b/utils/loc_cfg.h index ea4865b..9045e1d 100644 --- a/utils/loc_cfg.h +++ b/utils/loc_cfg.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2015, 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 @@ -54,7 +54,7 @@ *============================================================================*/ typedef struct { - char param_name[LOC_MAX_PARAM_NAME]; + const char *param_name; void *param_ptr; uint8_t *param_set; /* was this value set by config file? */ char param_type; /* 'n' for number, @@ -78,12 +78,12 @@ extern "C" { * *============================================================================*/ void loc_read_conf(const char* conf_file_name, - loc_param_s_type* config_table, + const loc_param_s_type* config_table, uint32_t table_length); -int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, +int loc_read_conf_r(FILE *conf_fp, const loc_param_s_type* config_table, uint32_t table_length); int loc_update_conf(const char* conf_data, int32_t length, - loc_param_s_type* config_table, uint32_t table_length); + const loc_param_s_type* config_table, uint32_t table_length); #ifdef __cplusplus } #endif diff --git a/utils/loc_log.cpp b/utils/loc_log.cpp index 5500dea..76f0c53 100644 --- a/utils/loc_log.cpp +++ b/utils/loc_log.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2012, 2015, 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 @@ -57,9 +57,9 @@ const char EXIT_ERROR_TAG[] = "Exiting with error"; loc_logger_s_type loc_logger; /* Get names from value */ -const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask) +const char* loc_get_name_from_mask(const loc_name_val_s_type table[], size_t table_size, long mask) { - int i; + size_t i; for (i = 0; i < table_size; i++) { if (table[i].val & (long) mask) @@ -71,9 +71,9 @@ const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, } /* Get names from value */ -const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value) +const char* loc_get_name_from_val(const loc_name_val_s_type table[], size_t table_size, long value) { - int i; + size_t i; for (i = 0; i < table_size; i++) { if (table[i].val == (long) value) @@ -84,7 +84,7 @@ const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, l return UNKNOWN_STR; } -static loc_name_val_s_type loc_msg_q_status[] = +static const loc_name_val_s_type loc_msg_q_status[] = { NAME_VAL( eMSG_Q_SUCCESS ), NAME_VAL( eMSG_Q_FAILURE_GENERAL ), @@ -93,7 +93,7 @@ static loc_name_val_s_type loc_msg_q_status[] = NAME_VAL( eMSG_Q_UNAVAILABLE_RESOURCE ), NAME_VAL( eMSG_Q_INSUFFICIENT_BUFFER ) }; -static int loc_msg_q_status_num = sizeof(loc_msg_q_status) / sizeof(loc_name_val_s_type); +static const size_t loc_msg_q_status_num = LOC_TABLE_SIZE(loc_msg_q_status); /* Find msg_q status name */ const char* loc_get_msg_q_status(int status) @@ -107,7 +107,7 @@ const char* log_succ_fail_string(int is_succ) } //Target names -loc_name_val_s_type target_name[] = +static const loc_name_val_s_type target_name[] = { NAME_VAL(GNSS_NONE), NAME_VAL(GNSS_MSM), @@ -118,7 +118,7 @@ loc_name_val_s_type target_name[] = NAME_VAL(GNSS_UNKNOWN) }; -static int target_name_num = sizeof(target_name)/sizeof(loc_name_val_s_type); +static const size_t target_name_num = LOC_TABLE_SIZE(target_name); /*=========================================================================== @@ -139,7 +139,7 @@ const char *loc_get_target_name(unsigned int target) static char ret[BUFFER_SIZE]; index = getTargetGnssType(target); - if( index >= target_name_num || index < 0) + if( index < 0 || (unsigned)index >= target_name_num ) index = target_name_num - 1; if( (target & HAS_SSC) == HAS_SSC ) { @@ -168,7 +168,7 @@ RETURN VALUE The time string ===========================================================================*/ -char *loc_get_time(char *time_string, unsigned long buf_size) +char *loc_get_time(char *time_string, size_t buf_size) { struct timeval now; /* sec and usec */ struct tm now_tm; /* broken-down time */ diff --git a/utils/loc_log.h b/utils/loc_log.h index 82dc636..be492b1 100644 --- a/utils/loc_log.h +++ b/utils/loc_log.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2012, 2015 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 @@ -36,12 +36,13 @@ extern "C" #endif #include <ctype.h> +#include <stdlib.h> #include "loc_target.h" typedef struct { - char name[128]; - long val; + const char *name; + long val; } loc_name_val_s_type; #define NAME_VAL(x) {"" #x "", x } @@ -49,17 +50,19 @@ typedef struct #define UNKNOWN_STR "UNKNOWN" #define CHECK_MASK(type, value, mask_var, mask) \ - ((mask_var & mask) ? (type) value : (type) (-1)) + (((mask_var) & (mask)) ? (type) (value) : (type) (-1)) + +#define LOC_TABLE_SIZE(table) (sizeof(table)/sizeof((table)[0])) /* Get names from value */ -const char* loc_get_name_from_mask(loc_name_val_s_type table[], int table_size, long mask); -const char* loc_get_name_from_val(loc_name_val_s_type table[], int table_size, long value); +const char* loc_get_name_from_mask(const loc_name_val_s_type table[], size_t table_size, long mask); +const char* loc_get_name_from_val(const loc_name_val_s_type table[], size_t table_size, long value); const char* loc_get_msg_q_status(int status); const char* loc_get_target_name(unsigned int target); extern const char* log_succ_fail_string(int is_succ); -extern char *loc_get_time(char *time_string, unsigned long buf_size); +extern char *loc_get_time(char *time_string, size_t buf_size); #ifdef __cplusplus } |