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
This commit is contained in:
Valeri Atamaniouk 2015-10-21 18:53:58 +03:00
parent 15ea4fca38
commit 78bb13288e
6 changed files with 62 additions and 59 deletions

View file

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@ -49,7 +49,7 @@ void LocPosMode::logv() const
} }
/* GPS status names */ /* GPS status names */
static loc_name_val_s_type gps_status_name[] = static const loc_name_val_s_type gps_status_name[] =
{ {
NAME_VAL( GPS_STATUS_NONE ), NAME_VAL( GPS_STATUS_NONE ),
NAME_VAL( GPS_STATUS_SESSION_BEGIN ), NAME_VAL( GPS_STATUS_SESSION_BEGIN ),
@ -57,7 +57,7 @@ static loc_name_val_s_type gps_status_name[] =
NAME_VAL( GPS_STATUS_ENGINE_ON ), NAME_VAL( GPS_STATUS_ENGINE_ON ),
NAME_VAL( GPS_STATUS_ENGINE_OFF ), NAME_VAL( GPS_STATUS_ENGINE_OFF ),
}; };
static int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type); static const int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type);
/* Find Android GPS status name */ /* Find Android GPS status name */
const char* loc_get_gps_status_name(GpsStatusValue gps_status) const char* loc_get_gps_status_name(GpsStatusValue gps_status)
@ -68,7 +68,7 @@ const char* loc_get_gps_status_name(GpsStatusValue gps_status)
static loc_name_val_s_type loc_eng_position_modes[] = static const loc_name_val_s_type loc_eng_position_modes[] =
{ {
NAME_VAL( LOC_POSITION_MODE_STANDALONE ), NAME_VAL( LOC_POSITION_MODE_STANDALONE ),
NAME_VAL( LOC_POSITION_MODE_MS_BASED ), NAME_VAL( LOC_POSITION_MODE_MS_BASED ),
@ -79,7 +79,7 @@ static loc_name_val_s_type loc_eng_position_modes[] =
NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ), NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ),
NAME_VAL( LOC_POSITION_MODE_RESERVED_5 ) NAME_VAL( LOC_POSITION_MODE_RESERVED_5 )
}; };
static int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type); static const int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type);
const char* loc_get_position_mode_name(GpsPositionMode mode) const char* loc_get_position_mode_name(GpsPositionMode mode)
{ {
@ -88,12 +88,12 @@ const char* loc_get_position_mode_name(GpsPositionMode mode)
static loc_name_val_s_type loc_eng_position_recurrences[] = static const loc_name_val_s_type loc_eng_position_recurrences[] =
{ {
NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ), NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ),
NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE ) NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE )
}; };
static int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type); static const int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type);
const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur) const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
{ {
@ -102,7 +102,7 @@ const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
static loc_name_val_s_type loc_eng_aiding_data_bits[] = static const loc_name_val_s_type loc_eng_aiding_data_bits[] =
{ {
NAME_VAL( GPS_DELETE_EPHEMERIS ), NAME_VAL( GPS_DELETE_EPHEMERIS ),
NAME_VAL( GPS_DELETE_ALMANAC ), NAME_VAL( GPS_DELETE_ALMANAC ),
@ -118,7 +118,7 @@ static loc_name_val_s_type loc_eng_aiding_data_bits[] =
NAME_VAL( GPS_DELETE_CELLDB_INFO ), NAME_VAL( GPS_DELETE_CELLDB_INFO ),
NAME_VAL( GPS_DELETE_ALL) NAME_VAL( GPS_DELETE_ALL)
}; };
static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type); static const int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type);
const char* loc_get_aiding_data_mask_names(GpsAidingData data) const char* loc_get_aiding_data_mask_names(GpsAidingData data)
{ {
@ -126,7 +126,7 @@ const char* loc_get_aiding_data_mask_names(GpsAidingData data)
} }
static loc_name_val_s_type loc_eng_agps_types[] = static const loc_name_val_s_type loc_eng_agps_types[] =
{ {
NAME_VAL( AGPS_TYPE_INVALID ), NAME_VAL( AGPS_TYPE_INVALID ),
NAME_VAL( AGPS_TYPE_ANY ), NAME_VAL( AGPS_TYPE_ANY ),
@ -134,7 +134,7 @@ static loc_name_val_s_type loc_eng_agps_types[] =
NAME_VAL( AGPS_TYPE_C2K ), NAME_VAL( AGPS_TYPE_C2K ),
NAME_VAL( AGPS_TYPE_WWAN_ANY ) NAME_VAL( AGPS_TYPE_WWAN_ANY )
}; };
static int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type); static const int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type);
const char* loc_get_agps_type_name(AGpsType type) const char* loc_get_agps_type_name(AGpsType type)
{ {
@ -142,14 +142,14 @@ const char* loc_get_agps_type_name(AGpsType type)
} }
static loc_name_val_s_type loc_eng_ni_types[] = static const loc_name_val_s_type loc_eng_ni_types[] =
{ {
NAME_VAL( GPS_NI_TYPE_VOICE ), NAME_VAL( GPS_NI_TYPE_VOICE ),
NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ), NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ),
NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ), NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ),
NAME_VAL( GPS_NI_TYPE_EMERGENCY_SUPL ) NAME_VAL( GPS_NI_TYPE_EMERGENCY_SUPL )
}; };
static int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type); static const int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type);
const char* loc_get_ni_type_name(GpsNiType type) const char* loc_get_ni_type_name(GpsNiType type)
{ {
@ -157,13 +157,13 @@ const char* loc_get_ni_type_name(GpsNiType type)
} }
static loc_name_val_s_type loc_eng_ni_responses[] = static const loc_name_val_s_type loc_eng_ni_responses[] =
{ {
NAME_VAL( GPS_NI_RESPONSE_ACCEPT ), NAME_VAL( GPS_NI_RESPONSE_ACCEPT ),
NAME_VAL( GPS_NI_RESPONSE_DENY ), NAME_VAL( GPS_NI_RESPONSE_DENY ),
NAME_VAL( GPS_NI_RESPONSE_DENY ) NAME_VAL( GPS_NI_RESPONSE_DENY )
}; };
static int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type); static const int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type);
const char* loc_get_ni_response_name(GpsUserResponseType response) const char* loc_get_ni_response_name(GpsUserResponseType response)
{ {
@ -171,7 +171,7 @@ const char* loc_get_ni_response_name(GpsUserResponseType response)
} }
static loc_name_val_s_type loc_eng_ni_encodings[] = static const loc_name_val_s_type loc_eng_ni_encodings[] =
{ {
NAME_VAL( GPS_ENC_NONE ), NAME_VAL( GPS_ENC_NONE ),
NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ), NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ),
@ -179,55 +179,55 @@ static loc_name_val_s_type loc_eng_ni_encodings[] =
NAME_VAL( GPS_ENC_SUPL_UCS2 ), NAME_VAL( GPS_ENC_SUPL_UCS2 ),
NAME_VAL( GPS_ENC_UNKNOWN ) NAME_VAL( GPS_ENC_UNKNOWN )
}; };
static int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type); static const int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type);
const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding) const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding)
{ {
return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding); return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding);
} }
static loc_name_val_s_type loc_eng_agps_bears[] = static const loc_name_val_s_type loc_eng_agps_bears[] =
{ {
NAME_VAL( AGPS_APN_BEARER_INVALID ), NAME_VAL( AGPS_APN_BEARER_INVALID ),
NAME_VAL( AGPS_APN_BEARER_IPV4 ), NAME_VAL( AGPS_APN_BEARER_IPV4 ),
NAME_VAL( AGPS_APN_BEARER_IPV6 ), NAME_VAL( AGPS_APN_BEARER_IPV6 ),
NAME_VAL( AGPS_APN_BEARER_IPV4V6 ) NAME_VAL( AGPS_APN_BEARER_IPV4V6 )
}; };
static int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type); static const int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type);
const char* loc_get_agps_bear_name(AGpsBearerType bearer) const char* loc_get_agps_bear_name(AGpsBearerType bearer)
{ {
return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer); return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer);
} }
static loc_name_val_s_type loc_eng_server_types[] = static const loc_name_val_s_type loc_eng_server_types[] =
{ {
NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ), NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ),
NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ), NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ),
NAME_VAL( LOC_AGPS_MPC_SERVER ), NAME_VAL( LOC_AGPS_MPC_SERVER ),
NAME_VAL( LOC_AGPS_SUPL_SERVER ) NAME_VAL( LOC_AGPS_SUPL_SERVER )
}; };
static int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type); static const int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type);
const char* loc_get_server_type_name(LocServerType type) const char* loc_get_server_type_name(LocServerType type)
{ {
return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type); return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type);
} }
static loc_name_val_s_type loc_eng_position_sess_status_types[] = static const loc_name_val_s_type loc_eng_position_sess_status_types[] =
{ {
NAME_VAL( LOC_SESS_SUCCESS ), NAME_VAL( LOC_SESS_SUCCESS ),
NAME_VAL( LOC_SESS_INTERMEDIATE ), NAME_VAL( LOC_SESS_INTERMEDIATE ),
NAME_VAL( LOC_SESS_FAILURE ) NAME_VAL( LOC_SESS_FAILURE )
}; };
static int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type); static const int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type);
const char* loc_get_position_sess_status_name(enum loc_sess_status status) const char* loc_get_position_sess_status_name(enum loc_sess_status status)
{ {
return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status); return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status);
} }
static loc_name_val_s_type loc_eng_agps_status_names[] = static const loc_name_val_s_type loc_eng_agps_status_names[] =
{ {
NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ), NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ),
NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ), NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ),
@ -235,7 +235,7 @@ static loc_name_val_s_type loc_eng_agps_status_names[] =
NAME_VAL( GPS_AGPS_DATA_CONN_DONE ), NAME_VAL( GPS_AGPS_DATA_CONN_DONE ),
NAME_VAL( GPS_AGPS_DATA_CONN_FAILED ) NAME_VAL( GPS_AGPS_DATA_CONN_FAILED )
}; };
static int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type); static const int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type);
const char* loc_get_agps_status_name(AGpsStatusValue status) const char* loc_get_agps_status_name(AGpsStatusValue status)
{ {

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2009-2014, The Linux Foundation. All rights reserved. /* Copyright (c) 2009-2015, The Linux Foundation. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@ -94,7 +94,7 @@ loc_gps_cfg_s_type gps_conf;
loc_sap_cfg_s_type sap_conf; loc_sap_cfg_s_type sap_conf;
/* Parameter spec table */ /* Parameter spec table */
static loc_param_s_type gps_conf_table[] = static const loc_param_s_type gps_conf_table[] =
{ {
{"GPS_LOCK", &gps_conf.GPS_LOCK, NULL, 'n'}, {"GPS_LOCK", &gps_conf.GPS_LOCK, NULL, 'n'},
{"SUPL_VER", &gps_conf.SUPL_VER, NULL, 'n'}, {"SUPL_VER", &gps_conf.SUPL_VER, NULL, 'n'},
@ -113,7 +113,7 @@ static loc_param_s_type gps_conf_table[] =
{"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", &gps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL, NULL, 'n'}, {"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", &gps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL, NULL, 'n'},
}; };
static loc_param_s_type sap_conf_table[] = static const loc_param_s_type sap_conf_table[] =
{ {
{"GYRO_BIAS_RANDOM_WALK", &sap_conf.GYRO_BIAS_RANDOM_WALK, &sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'}, {"GYRO_BIAS_RANDOM_WALK", &sap_conf.GYRO_BIAS_RANDOM_WALK, &sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'},
{"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'}, {"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},

View file

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@ -56,12 +56,12 @@ static uint32_t DEBUG_LEVEL = 0xff;
static uint32_t TIMESTAMP = 0; static uint32_t TIMESTAMP = 0;
/* Parameter spec table */ /* 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'}, {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'},
{"TIMESTAMP", &TIMESTAMP, 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 typedef struct loc_param_v_type
{ {
@ -92,7 +92,7 @@ RETURN VALUE
SIDE EFFECTS SIDE EFFECTS
N/A 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; int ret=-1;
if(NULL == config_entry || NULL == config_value) if(NULL == config_entry || NULL == config_value)
@ -181,7 +181,7 @@ SIDE EFFECTS
N/A N/A
===========================================================================*/ ===========================================================================*/
int loc_fill_conf_item(char* input_buf, 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; int ret = 0;
@ -258,7 +258,7 @@ RETURN VALUE
SIDE EFFECTS SIDE EFFECTS
N/A 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; int ret=0;
@ -322,7 +322,7 @@ SIDE EFFECTS
N/A N/A
===========================================================================*/ ===========================================================================*/
int loc_update_conf(const char* conf_data, int32_t 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)
{ {
int ret = -1; int ret = -1;
@ -377,7 +377,7 @@ RETURN VALUE
SIDE EFFECTS SIDE EFFECTS
N/A 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) uint32_t table_length)
{ {
FILE *conf_fp = NULL; FILE *conf_fp = NULL;

View file

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@ -54,7 +54,7 @@
*============================================================================*/ *============================================================================*/
typedef struct typedef struct
{ {
char param_name[LOC_MAX_PARAM_NAME]; const char *param_name;
void *param_ptr; void *param_ptr;
uint8_t *param_set; /* was this value set by config file? */ uint8_t *param_set; /* was this value set by config file? */
char param_type; /* 'n' for number, char param_type; /* 'n' for number,
@ -78,12 +78,12 @@ extern "C" {
* *
*============================================================================*/ *============================================================================*/
void loc_read_conf(const char* conf_file_name, 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); 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); uint32_t table_length);
int loc_update_conf(const char* conf_data, int32_t 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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * 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; loc_logger_s_type loc_logger;
/* Get names from value */ /* 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++) for (i = 0; i < table_size; i++)
{ {
if (table[i].val & (long) mask) 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 */ /* 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++) for (i = 0; i < table_size; i++)
{ {
if (table[i].val == (long) value) 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; 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_SUCCESS ),
NAME_VAL( eMSG_Q_FAILURE_GENERAL ), 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_UNAVAILABLE_RESOURCE ),
NAME_VAL( eMSG_Q_INSUFFICIENT_BUFFER ) 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 */ /* Find msg_q status name */
const char* loc_get_msg_q_status(int status) const char* loc_get_msg_q_status(int status)
@ -107,7 +107,7 @@ const char* log_succ_fail_string(int is_succ)
} }
//Target names //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_NONE),
NAME_VAL(GNSS_MSM), NAME_VAL(GNSS_MSM),
@ -118,7 +118,7 @@ loc_name_val_s_type target_name[] =
NAME_VAL(GNSS_UNKNOWN) 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]; static char ret[BUFFER_SIZE];
index = getTargetGnssType(target); index = getTargetGnssType(target);
if( index >= target_name_num || index < 0) if( index < 0 || (unsigned)index >= target_name_num )
index = target_name_num - 1; index = target_name_num - 1;
if( (target & HAS_SSC) == HAS_SSC ) { if( (target & HAS_SSC) == HAS_SSC ) {
@ -168,7 +168,7 @@ RETURN VALUE
The time string 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 timeval now; /* sec and usec */
struct tm now_tm; /* broken-down time */ struct tm now_tm; /* broken-down time */

View file

@ -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 * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are * modification, are permitted provided that the following conditions are
@ -36,11 +36,12 @@ extern "C"
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <stdlib.h>
#include "loc_target.h" #include "loc_target.h"
typedef struct typedef struct
{ {
char name[128]; const char *name;
long val; long val;
} loc_name_val_s_type; } loc_name_val_s_type;
@ -49,17 +50,19 @@ typedef struct
#define UNKNOWN_STR "UNKNOWN" #define UNKNOWN_STR "UNKNOWN"
#define CHECK_MASK(type, value, mask_var, mask) \ #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 */ /* 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);
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);
const char* loc_get_msg_q_status(int status); const char* loc_get_msg_q_status(int status);
const char* loc_get_target_name(unsigned int target); const char* loc_get_target_name(unsigned int target);
extern const char* log_succ_fail_string(int is_succ); 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 #ifdef __cplusplus
} }