diff options
author | crancocco <shulaibai@hustunique.com> | 2016-06-25 22:55:16 +0800 |
---|---|---|
committer | davidevinavil <davidevinavil@gmail.com> | 2017-01-21 18:26:28 +0100 |
commit | b80452111794b613819d5ad51e1690c4dd923e97 (patch) | |
tree | df2b4d14fdd89a40f6e11a24d93949e7bebfd8e5 /gps/utils | |
parent | 8126cb8c09f99ae625364c98b1301d0c5390e27d (diff) |
z2_plus: Update GPS HAL from upstream
* Tag LA.HB.1.3.2-15400-8x96.0
Change-Id: I2ba108f26a2ef4fc78504ef8c08ca41624ccb193
Diffstat (limited to 'gps/utils')
-rw-r--r-- | gps/utils/LocSharedLock.h | 7 | ||||
-rw-r--r-- | gps/utils/MsgTask.cpp | 2 | ||||
-rw-r--r-- | gps/utils/linked_list.c | 6 | ||||
-rw-r--r-- | gps/utils/loc_cfg.cpp | 16 | ||||
-rw-r--r-- | gps/utils/loc_cfg.h | 10 | ||||
-rw-r--r-- | gps/utils/loc_log.cpp | 22 | ||||
-rw-r--r-- | gps/utils/loc_log.h | 17 | ||||
-rw-r--r-- | gps/utils/msg_q.c | 8 |
8 files changed, 46 insertions, 42 deletions
diff --git a/gps/utils/LocSharedLock.h b/gps/utils/LocSharedLock.h index 6b9e27f..7fe6237 100644 --- a/gps/utils/LocSharedLock.h +++ b/gps/utils/LocSharedLock.h @@ -30,6 +30,7 @@ #define __LOC_SHARED_LOCK__ #include <stddef.h> +#include <cutils/atomic.h> #include <pthread.h> // This is a utility created for use cases such that there are more than @@ -39,16 +40,16 @@ // this share lock's share() method has to be called, so that the obj // can maintain an accurate client count. class LocSharedLock { - uint32_t mRef; + volatile int32_t mRef; pthread_mutex_t mMutex; inline ~LocSharedLock() { pthread_mutex_destroy(&mMutex); } public: // first client to create this LockSharedLock inline LocSharedLock() : mRef(1) { pthread_mutex_init(&mMutex, NULL); } // following client(s) are to *share()* this lock created by the first client - inline LocSharedLock* share() { mRef++; return this; } + inline LocSharedLock* share() { android_atomic_inc(&mRef); return this; } // whe a client no longer needs this shared lock, drop() shall be called. - inline void drop() { if (0 == --mRef) delete this; } + inline void drop() { if (1 == android_atomic_dec(&mRef)) delete this; } // locking the lock to enter critical section inline void lock() { pthread_mutex_lock(&mMutex); } // unlocking the lock to leave the critical section diff --git a/gps/utils/MsgTask.cpp b/gps/utils/MsgTask.cpp index fdb1102..6f9d0e9 100644 --- a/gps/utils/MsgTask.cpp +++ b/gps/utils/MsgTask.cpp @@ -83,7 +83,7 @@ void MsgTask::prerun() { } bool MsgTask::run() { - LOC_LOGD("MsgTask::loop() listening ...\n"); + LOC_LOGV("MsgTask::loop() listening ...\n"); LocMsg* msg; msq_q_err_type result = msg_q_rcv((void*)mQ, (void **)&msg); if (eMSG_Q_SUCCESS != result) { diff --git a/gps/utils/linked_list.c b/gps/utils/linked_list.c index 92617fe..2c91714 100644 --- a/gps/utils/linked_list.c +++ b/gps/utils/linked_list.c @@ -109,7 +109,7 @@ linked_list_err_type linked_list_destroy(void** list_data) ===========================================================================*/ linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dealloc)(void*)) { - LOC_LOGD("%s: Adding to list data_obj = 0x%08X\n", __FUNCTION__, data_obj); + LOC_LOGV("%s: Adding to list data_obj = 0x%08X\n", __FUNCTION__, data_obj); if( list_data == NULL ) { LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); @@ -161,7 +161,7 @@ linked_list_err_type linked_list_add(void* list_data, void *data_obj, void (*dea ===========================================================================*/ linked_list_err_type linked_list_remove(void* list_data, void **data_obj) { - LOC_LOGD("%s: Removing from list\n", __FUNCTION__); + LOC_LOGV("%s: Removing from list\n", __FUNCTION__); if( list_data == NULL ) { LOC_LOGE("%s: Invalid list parameter!\n", __FUNCTION__); @@ -268,7 +268,7 @@ linked_list_err_type linked_list_search(void* list_data, void **data_p, bool (*equal)(void* data_0, void* data), void* data_0, bool rm_if_found) { - LOC_LOGD("%s: Search the list\n", __FUNCTION__); + LOC_LOGV("%s: Search the list\n", __FUNCTION__); if( list_data == NULL || NULL == equal ) { LOC_LOGE("%s: Invalid list parameter! list_data %p equal %p\n", diff --git a/gps/utils/loc_cfg.cpp b/gps/utils/loc_cfg.cpp index 5c33320..967d2f3 100644 --- a/gps/utils/loc_cfg.cpp +++ b/gps/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/gps/utils/loc_cfg.h b/gps/utils/loc_cfg.h index ea4865b..9045e1d 100644 --- a/gps/utils/loc_cfg.h +++ b/gps/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/gps/utils/loc_log.cpp b/gps/utils/loc_log.cpp index 5500dea..76f0c53 100644 --- a/gps/utils/loc_log.cpp +++ b/gps/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/gps/utils/loc_log.h b/gps/utils/loc_log.h index 82dc636..be492b1 100644 --- a/gps/utils/loc_log.h +++ b/gps/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 } diff --git a/gps/utils/msg_q.c b/gps/utils/msg_q.c index f82d4c0..5be8547 100644 --- a/gps/utils/msg_q.c +++ b/gps/utils/msg_q.c @@ -199,7 +199,7 @@ msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*) msg_q* p_msg_q = (msg_q*)msg_q_data; pthread_mutex_lock(&p_msg_q->list_mutex); - LOC_LOGD("%s: Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); + LOC_LOGV("%s: Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); if( p_msg_q->unblocked ) { @@ -215,7 +215,7 @@ msq_q_err_type msg_q_snd(void* msg_q_data, void* msg_obj, void (*dealloc)(void*) pthread_mutex_unlock(&p_msg_q->list_mutex); - LOC_LOGD("%s: Finished Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); + LOC_LOGV("%s: Finished Sending message with handle = 0x%08X\n", __FUNCTION__, msg_obj); return rv; } @@ -242,7 +242,7 @@ msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj) msg_q* p_msg_q = (msg_q*)msg_q_data; - LOC_LOGD("%s: Waiting on message\n", __FUNCTION__); + LOC_LOGV("%s: Waiting on message\n", __FUNCTION__); pthread_mutex_lock(&p_msg_q->list_mutex); @@ -263,7 +263,7 @@ msq_q_err_type msg_q_rcv(void* msg_q_data, void** msg_obj) pthread_mutex_unlock(&p_msg_q->list_mutex); - LOC_LOGD("%s: Received message 0x%08X rv = %d\n", __FUNCTION__, *msg_obj, rv); + LOC_LOGV("%s: Received message 0x%08X rv = %d\n", __FUNCTION__, *msg_obj, rv); return rv; } |