diff options
Diffstat (limited to 'gps/utils')
-rw-r--r-- | gps/utils/Android.mk | 21 | ||||
-rw-r--r-- | gps/utils/Makefile.am | 44 | ||||
-rw-r--r-- | gps/utils/linked_list.c | 2 | ||||
-rw-r--r-- | gps/utils/loc_cfg.cpp | 382 | ||||
-rw-r--r-- | gps/utils/loc_cfg.h | 12 | ||||
-rw-r--r-- | gps/utils/loc_log.cpp | 42 | ||||
-rw-r--r-- | gps/utils/loc_log.h | 6 | ||||
-rw-r--r-- | gps/utils/loc_misc_utils.cpp | 114 | ||||
-rw-r--r-- | gps/utils/loc_misc_utils.h | 99 | ||||
-rw-r--r-- | gps/utils/loc_target.cpp | 183 | ||||
-rw-r--r-- | gps/utils/loc_target.h | 42 | ||||
-rw-r--r-- | gps/utils/loc_timer.c | 202 | ||||
-rw-r--r-- | gps/utils/loc_timer.h | 63 | ||||
-rw-r--r-- | gps/utils/log_util.h | 66 | ||||
-rw-r--r-- | gps/utils/msg_q.c | 20 | ||||
-rw-r--r-- | gps/utils/msg_q.h | 20 | ||||
-rw-r--r-- | gps/utils/sec_gps.c | 12 |
17 files changed, 1055 insertions, 275 deletions
diff --git a/gps/utils/Android.mk b/gps/utils/Android.mk index 205fb16..a91a6ed 100644 --- a/gps/utils/Android.mk +++ b/gps/utils/Android.mk @@ -8,14 +8,20 @@ include $(CLEAR_VARS) ## Libs LOCAL_SHARED_LIBRARIES := \ libutils \ - libcutils + libcutils \ + liblog LOCAL_SRC_FILES += \ + sec_gps.c \ loc_log.cpp \ loc_cfg.cpp \ msg_q.c \ linked_list.c \ - loc_target.cpp + loc_target.cpp \ + loc_timer.c \ + ../platform_lib_abstractions/elapsed_millis_since_boot.cpp \ + loc_misc_utils.cpp + LOCAL_CFLAGS += \ -fno-short-enums \ @@ -24,7 +30,8 @@ LOCAL_CFLAGS += \ LOCAL_LDFLAGS += -Wl,--export-dynamic ## Includes -LOCAL_C_INCLUDES:= +LOCAL_C_INCLUDES:= \ + $(LOCAL_PATH)/../platform_lib_abstractions LOCAL_COPY_HEADERS_TO:= gps.utils/ LOCAL_COPY_HEADERS:= \ @@ -33,7 +40,13 @@ LOCAL_COPY_HEADERS:= \ log_util.h \ linked_list.h \ msg_q.h \ - loc_target.h + loc_target.h \ + loc_timer.h \ + ../platform_lib_abstractions/platform_lib_includes.h \ + ../platform_lib_abstractions/platform_lib_time.h \ + ../platform_lib_abstractions/platform_lib_macros.h \ + loc_misc_utils.h + LOCAL_MODULE := libgps.utils diff --git a/gps/utils/Makefile.am b/gps/utils/Makefile.am new file mode 100644 index 0000000..e5935f0 --- /dev/null +++ b/gps/utils/Makefile.am @@ -0,0 +1,44 @@ +AM_CFLAGS = -Wundef \ + -MD \ + -Wno-trigraphs \ + -g -O0 \ + -fno-inline \ + -fno-short-enums \ + -fpic \ + -I../platform_lib_abstractions + +libgps_utils_so_la_h_sources = log_util.h \ + msg_q.h \ + linked_list.h \ + loc_cfg.h \ + loc_log.h \ + ../platform_lib_abstractions/platform_lib_includes.h \ + ../platform_lib_abstractions/platform_lib_time.h \ + ../platform_lib_abstractions/platform_lib_macros.h + +libgps_utils_so_la_c_sources = linked_list.c \ + msg_q.c \ + loc_cfg.cpp \ + loc_log.cpp \ + ../platform_lib_abstractions/elapsed_millis_since_boot.cpp + +library_includedir = $(pkgincludedir)/utils + +library_include_HEADERS = $(libgps_utils_so_la_h_sources) + +libgps_utils_so_la_SOURCES = $(libgps_utils_so_la_c_sources) + +if USE_GLIB +libgps_utils_so_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ +libgps_utils_so_la_LDFLAGS = -lstdc++ -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0 +libgps_utils_so_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@ +else +libgps_utils_so_la_CFLAGS = $(AM_CFLAGS) +libgps_utils_so_la_LDFLAGS = -lpthread -shared -version-info 1:0:0 +libgps_utils_so_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) +endif + +libgps_utils_so_la_LIBADD = -lstdc++ -lcutils + +#Create and Install libraries +lib_LTLIBRARIES = libgps_utils_so.la diff --git a/gps/utils/linked_list.c b/gps/utils/linked_list.c index 31ec52d..92617fe 100644 --- a/gps/utils/linked_list.c +++ b/gps/utils/linked_list.c @@ -32,7 +32,7 @@ #define LOG_TAG "LocSvc_utils_ll" #include "log_util.h" - +#include "platform_lib_includes.h" #include <stdlib.h> #include <stdint.h> diff --git a/gps/utils/loc_cfg.cpp b/gps/utils/loc_cfg.cpp index 3f7dec9..abf8086 100644 --- a/gps/utils/loc_cfg.cpp +++ b/gps/utils/loc_cfg.cpp @@ -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 @@ -9,7 +9,7 @@ * 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 + * * 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. * @@ -39,6 +39,11 @@ #include <time.h> #include <loc_cfg.h> #include <log_util.h> +#include <loc_misc_utils.h> +#ifdef USE_GLIB +#include <glib.h> +#endif +#include "platform_lib_includes.h" /*============================================================================= * @@ -47,49 +52,36 @@ *============================================================================*/ /* Parameter data */ -static uint8_t DEBUG_LEVEL = 3; +static uint8_t DEBUG_LEVEL = 0xff; 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 loc_default_parameters - -DESCRIPTION - Resets the parameters to default - -DEPENDENCIES - N/A - -RETURN VALUE - None - -SIDE EFFECTS - N/A -===========================================================================*/ - -static void loc_default_parameters() +typedef struct loc_param_v_type { - /* defaults */ - DEBUG_LEVEL = 3; /* debug level */ - TIMESTAMP = 0; - - /* reset logging mechanism */ - loc_logger_init(DEBUG_LEVEL, TIMESTAMP); -} + char* param_name; + char* param_str_value; + int param_int_value; + double param_double_value; +}loc_param_v_type; /*=========================================================================== -FUNCTION trim_space +FUNCTION loc_set_config_entry DESCRIPTION - Removes leading and trailing spaces of the string + Potentially sets a given configuration table entry based on the passed in + configuration value. This is done by using a string comparison of the + parameter names and those found in the configuration file. + +PARAMETERS: + config_entry: configuration entry in the table to possibly set + config_value: value to store in the entry if the parameter names match DEPENDENCIES N/A @@ -100,120 +92,166 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -void trim_space(char *org_string) +int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) { - 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'; } + 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(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; + } + 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; + } + ret = 0; + break; + default: + LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name); + } + } + return ret; } -typedef struct loc_param_v_type -{ - char* param_name; - - char* param_str_value; - int param_int_value; - double param_double_value; -}loc_param_v_type; - /*=========================================================================== -FUNCTION loc_set_config_entry +FUNCTION loc_read_conf_r (repetitive) DESCRIPTION - Potentially sets a given configuration table entry based on the passed in - configuration value. This is done by using a string comparison of the - parameter names and those found in the configuration file. + 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: - config_entry: configuration entry in the table to possibly set - config_value: value to store in the entry if the parameter names match + 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 - None + 0: Table filled successfully + 1: No more parameters to read + -1: Error filling table SIDE EFFECTS N/A ===========================================================================*/ -void loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) +int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length) { - if(NULL == config_entry || NULL == config_value) - { - LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); - return; - } - - 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; - } - 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); - } - } + 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; } /*=========================================================================== @@ -238,73 +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; - - loc_default_parameters(); - - if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL) - { - LOC_LOGD("%s: using %s", __FUNCTION__, GPS_CONF_FILE); - } - else - { - LOC_LOGW("%s: no %s file found", __FUNCTION__, GPS_CONF_FILE); - 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); + 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); + 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); } diff --git a/gps/utils/loc_cfg.h b/gps/utils/loc_cfg.h index 155db65..268f4c2 100644 --- a/gps/utils/loc_cfg.h +++ b/gps/utils/loc_cfg.h @@ -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 @@ -9,7 +9,7 @@ * 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 + * * 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. * @@ -30,17 +30,13 @@ #ifndef LOC_CFG_H #define LOC_CFG_H +#include <stdio.h> #include <stdint.h> #define LOC_MAX_PARAM_NAME 48 #define LOC_MAX_PARAM_STRING 80 #define LOC_MAX_PARAM_LINE 80 -// Don't want to overwrite the pre-def'ed value -#ifndef GPS_CONF_FILE -#define GPS_CONF_FILE "/etc/gps.conf" //??? platform independent -#endif - #define UTIL_READ_CONF_DEFAULT(filename) \ loc_read_conf((filename), NULL, 0); @@ -80,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 diff --git a/gps/utils/loc_log.cpp b/gps/utils/loc_log.cpp index b75cf93..9a7ce5e 100644 --- a/gps/utils/loc_log.cpp +++ b/gps/utils/loc_log.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2012, 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 @@ -9,7 +9,7 @@ * 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 + * * 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. * @@ -34,7 +34,13 @@ #include <sys/time.h> #include "loc_log.h" #include "msg_q.h" +#ifdef USE_GLIB +#include <time.h> +#endif /* USE_GLIB */ #include "log_util.h" +#include "platform_lib_includes.h" + +#define BUFFER_SIZE 120 // Logging Improvements const char *loc_logger_boolStr[]={"False","True"}; @@ -102,11 +108,13 @@ const char* log_succ_fail_string(int is_succ) //Target names loc_name_val_s_type target_name[] = { - NAME_VAL(TARGET_OTHER), - NAME_VAL(TARGET_APQ8064_STANDALONE), - NAME_VAL(TARGET_APQ8064_FUSION3), - NAME_VAL(TARGET_MPQ8064), - NAME_VAL(TARGET_MSM8930) + NAME_VAL(GNSS_NONE), + NAME_VAL(GNSS_MSM), + NAME_VAL(GNSS_GSS), + NAME_VAL(GNSS_MDM), + NAME_VAL(GNSS_QCA1530), + NAME_VAL(GNSS_AUTO), + NAME_VAL(GNSS_UNKNOWN) }; static int target_name_num = sizeof(target_name)/sizeof(loc_name_val_s_type); @@ -124,11 +132,27 @@ RETURN VALUE The target name string ===========================================================================*/ -const char *loc_get_target_name(targetEnumType target) +const char *loc_get_target_name(unsigned int target) { - return loc_get_name_from_val(target_name, target_name_num, (long)target); + int index = 0; + static char ret[BUFFER_SIZE]; + + index = getTargetGnssType(target); + if( index >= target_name_num || index < 0) + index = target_name_num - 1; + + if( (target & HAS_SSC) == HAS_SSC ) { + snprintf(ret, sizeof(ret), " %s with SSC", + loc_get_name_from_val(target_name, target_name_num, (long)index) ); + } + else { + snprintf(ret, sizeof(ret), " %s without SSC", + loc_get_name_from_val(target_name, target_name_num, (long)index) ); + } + return ret; } + /*=========================================================================== FUNCTION loc_get_time diff --git a/gps/utils/loc_log.h b/gps/utils/loc_log.h index 46f4e3e..82dc636 100644 --- a/gps/utils/loc_log.h +++ b/gps/utils/loc_log.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2012, 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 @@ -9,7 +9,7 @@ * 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 + * * 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. * @@ -55,7 +55,7 @@ typedef struct 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_msg_q_status(int status); -const char* loc_get_target_name(targetEnumType target); +const char* loc_get_target_name(unsigned int target); extern const char* log_succ_fail_string(int is_succ); diff --git a/gps/utils/loc_misc_utils.cpp b/gps/utils/loc_misc_utils.cpp new file mode 100644 index 0000000..7e96313 --- /dev/null +++ b/gps/utils/loc_misc_utils.cpp @@ -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; +} diff --git a/gps/utils/loc_misc_utils.h b/gps/utils/loc_misc_utils.h new file mode 100644 index 0000000..7d66d84 --- /dev/null +++ b/gps/utils/loc_misc_utils.h @@ -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_ diff --git a/gps/utils/loc_target.cpp b/gps/utils/loc_target.cpp index 348ad9d..4c41d93 100644 --- a/gps/utils/loc_target.cpp +++ b/gps/utils/loc_target.cpp @@ -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 @@ -33,7 +33,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <errno.h> -#include <hardware/gps.h> +#include "hardware/gps.h" #include <cutils/properties.h> #include "loc_target.h" #include "loc_log.h" @@ -44,16 +44,24 @@ #define MPQ8064_ID_1 "130" #define MSM8930_ID_1 "142" #define MSM8930_ID_2 "116" +#define APQ8030_ID_1 "157" +#define APQ8074_ID_1 "184" #define LINE_LEN 100 #define STR_LIQUID "Liquid" #define STR_SURF "Surf" +#define STR_MTP "MTP" +#define STR_APQ "apq" +#define STR_AUTO "auto" #define IS_STR_END(c) ((c) == '\0' || (c) == '\n' || (c) == '\r') #define LENGTH(s) (sizeof(s) - 1) #define GPS_CHECK_NO_ERROR 0 #define GPS_CHECK_NO_GPS_HW 1 +#define QCA1530_DETECT_TIMEOUT 30 +#define QCA1530_DETECT_PRESENT "yes" +#define QCA1530_DETECT_PROGRESS "detect" -static int gss_fd = 0; +static unsigned int gTarget = (unsigned int)-1; static int read_a_line(const char * file_path, char * line, int line_size) { @@ -77,33 +85,160 @@ static int read_a_line(const char * file_path, char * line, int line_size) return result; } -targetEnumType get_target(void) +/*! + * \brief Checks if QCA1530 is avalable. + * + * Function verifies if qca1530 SoC is configured on the device. The test is + * based on property value. For 1530 scenario, the value shall be one of the + * following: "yes", "no", "detect". All other values are treated equally to + * "no". When the value is "detect" the system waits for SoC detection to + * finish before returning result. + * + * \retval true - QCA1530 is available. + * \retval false - QCA1530 is not available. + */ +static bool is_qca1530(void) +{ + static const char qca1530_property_name[] = "persist.qca1530"; + bool res = false; + int ret, i; + char buf[PROPERTY_VALUE_MAX]; + + memset(buf, 0, sizeof(buf)); + + for (i = 0; i < QCA1530_DETECT_TIMEOUT; ++i) + { + ret = property_get(qca1530_property_name, buf, NULL); + if (ret < 0) + { + LOC_LOGV( "qca1530: property %s is not accessible, ret=%d", + qca1530_property_name, + ret); + + break; + } + + LOC_LOGV( "qca1530: property %s is set to %s", + qca1530_property_name, + buf); + + if (!memcmp(buf, QCA1530_DETECT_PRESENT, + sizeof(QCA1530_DETECT_PRESENT))) + { + res = true; + break; + } + if (!memcmp(buf, QCA1530_DETECT_PROGRESS, + sizeof(QCA1530_DETECT_PROGRESS))) + { + LOC_LOGV("qca1530: SoC detection is in progress."); + sleep(1); + continue; + } + break; + } + + LOC_LOGD("qca1530: detected=%s", res ? "true" : "false"); + 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) { - targetEnumType target = TARGET_OTHER; + 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) + return gTarget; - char hw_platform[] = "/sys/devices/system/soc/soc0/hw_platform"; - char id[] = "/sys/devices/system/soc/soc0/id"; - char mdm[] = "/dev/mdm"; // No such file or directory + static const char hw_platform[] = "/sys/devices/soc0/hw_platform"; + static const char id[] = "/sys/devices/soc0/soc_id"; + static const char hw_platform_dep[] = + "/sys/devices/system/soc/soc0/hw_platform"; + static const char id_dep[] = "/sys/devices/system/soc/soc0/id"; + static const char mdm[] = "/dev/mdm"; // No such file or directory char rd_hw_platform[LINE_LEN]; char rd_id[LINE_LEN]; char rd_mdm[LINE_LEN]; + char baseband[LINE_LEN]; + + if (is_qca1530()) { + gTarget = TARGET_QCA1530; + goto detected; + } + + loc_get_target_baseband(baseband, sizeof(baseband)); + + if (!access(hw_platform, F_OK)) { + read_a_line(hw_platform, rd_hw_platform, LINE_LEN); + } else { + read_a_line(hw_platform_dep, rd_hw_platform, LINE_LEN); + } + if (!access(id, F_OK)) { + read_a_line(id, rd_id, LINE_LEN); + } else { + read_a_line(id_dep, rd_id, LINE_LEN); + } - read_a_line(hw_platform, rd_hw_platform, LINE_LEN); - read_a_line(id, rd_id, LINE_LEN); - - if(!memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) ) - target = TARGET_MPQ8064; - else if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) || - (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) ) { - if(!read_a_line( mdm, rd_mdm, LINE_LEN)) - target = TARGET_APQ8064_FUSION3; - else if( (!memcmp(rd_id, APQ8064_ID_1, LENGTH(APQ8064_ID_1)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_1)])) || - (!memcmp(rd_id, APQ8064_ID_2, LENGTH(APQ8064_ID_2)) && IS_STR_END(rd_id[LENGTH(APQ8064_ID_2)])) ) - target = TARGET_APQ8064_STANDALONE; + if( !memcmp(baseband, STR_AUTO, LENGTH(STR_AUTO)) ) + { + gTarget = TARGET_AUTO; + goto detected; } - else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) || - (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) - target = TARGET_MSM8930; - return target; + + if( !memcmp(baseband, STR_APQ, LENGTH(STR_APQ)) ){ + if( !memcmp(rd_id, MPQ8064_ID_1, LENGTH(MPQ8064_ID_1)) + && IS_STR_END(rd_id[LENGTH(MPQ8064_ID_1)]) ) + gTarget = TARGET_MPQ; + else + gTarget = TARGET_APQ_SA; + } + else { + if( (!memcmp(rd_hw_platform, STR_LIQUID, LENGTH(STR_LIQUID)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_LIQUID)])) || + (!memcmp(rd_hw_platform, STR_SURF, LENGTH(STR_SURF)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_SURF)])) || + (!memcmp(rd_hw_platform, STR_MTP, LENGTH(STR_MTP)) + && IS_STR_END(rd_hw_platform[LENGTH(STR_MTP)]))) { + + if (!read_a_line( mdm, rd_mdm, LINE_LEN)) + gTarget = TARGET_MDM; + } + else if( (!memcmp(rd_id, MSM8930_ID_1, LENGTH(MSM8930_ID_1)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_1)])) || + (!memcmp(rd_id, MSM8930_ID_2, LENGTH(MSM8930_ID_2)) + && IS_STR_END(rd_id[LENGTH(MSM8930_ID_2)])) ) + gTarget = TARGET_MSM_NO_SSC; + else + gTarget = TARGET_UNKNOWN; + } + +detected: + LOC_LOGD("HAL: %s returned %d", __FUNCTION__, gTarget); + return gTarget; } diff --git a/gps/utils/loc_target.h b/gps/utils/loc_target.h index 489aadd..873ddfc 100644 --- a/gps/utils/loc_target.h +++ b/gps/utils/loc_target.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 @@ -28,21 +28,47 @@ */ #ifndef LOC_TARGET_H #define LOC_TARGET_H +#define TARGET_SET(gnss,ssc) ( (gnss<<1)|ssc ) +#define TARGET_DEFAULT TARGET_SET(GNSS_MSM, HAS_SSC) +#define TARGET_MDM TARGET_SET(GNSS_MDM, HAS_SSC) +#define TARGET_APQ_SA TARGET_SET(GNSS_GSS, NO_SSC) +#define TARGET_MPQ TARGET_SET(GNSS_NONE,NO_SSC) +#define TARGET_MSM_NO_SSC TARGET_SET(GNSS_MSM, NO_SSC) +#define TARGET_QCA1530 TARGET_SET(GNSS_QCA1530, NO_SSC) +#define TARGET_AUTO TARGET_SET(GNSS_AUTO, NO_SSC) +#define TARGET_UNKNOWN TARGET_SET(GNSS_UNKNOWN, NO_SSC) +#define getTargetGnssType(target) (target>>1) #ifdef __cplusplus extern "C" { #endif +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 { - TARGET_OTHER = 0, - TARGET_APQ8064_STANDALONE, - TARGET_APQ8064_FUSION3, - TARGET_MPQ8064, - TARGET_MSM8930 -}targetEnumType; + GNSS_NONE = 0, + GNSS_MSM, + GNSS_GSS, + GNSS_MDM, + GNSS_QCA1530, + GNSS_AUTO, + GNSS_UNKNOWN +}GNSS_TARGET; -targetEnumType get_target(void); +typedef enum { + NO_SSC = 0, + HAS_SSC +}SSC_TYPE; #ifdef __cplusplus } diff --git a/gps/utils/loc_timer.c b/gps/utils/loc_timer.c new file mode 100644 index 0000000..2beca5f --- /dev/null +++ b/gps/utils/loc_timer.c @@ -0,0 +1,202 @@ +/* Copyright (c) 2013, 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<stdlib.h> +#include<sys/time.h> +#include "loc_timer.h" +#include<time.h> +#include<errno.h> + +enum timer_state { + READY = 100, + WAITING, + DONE, + ABORT +}; + +typedef struct { + loc_timer_callback callback_func; + void *user_data; + unsigned int time_msec; + pthread_cond_t timer_cond; + pthread_mutex_t timer_mutex; + enum timer_state state; +}timer_data; + +static void *timer_thread(void *thread_data) +{ + int ret = -ETIMEDOUT; + struct timespec ts; + struct timeval tv; + timer_data* t = (timer_data*)thread_data; + + LOC_LOGD("%s:%d]: Enter. Delay = %d\n", __func__, __LINE__, t->time_msec); + + gettimeofday(&tv, NULL); + clock_gettime(CLOCK_REALTIME, &ts); + if(t->time_msec >= 1000) { + ts.tv_sec += t->time_msec/1000; + t->time_msec = t->time_msec % 1000; + } + if(t->time_msec) + ts.tv_nsec += t->time_msec * 1000000; + if(ts.tv_nsec > 999999999) { + LOC_LOGD("%s:%d]: Large nanosecs\n", __func__, __LINE__); + ts.tv_sec += 1; + ts.tv_nsec -= 1000000000; + } + LOC_LOGD("%s:%d]: ts.tv_sec:%d; ts.tv_nsec:%d\n" + "\t Current time: %d sec; %d nsec", + __func__, __LINE__, (int)ts.tv_sec, (int)ts.tv_nsec, + (int)tv.tv_sec, (int)tv.tv_usec*1000); + + pthread_mutex_lock(&(t->timer_mutex)); + if (READY == t->state) { + t->state = WAITING; + ret = pthread_cond_timedwait(&t->timer_cond, &t->timer_mutex, &ts); + t->state = DONE; + } + pthread_mutex_unlock(&(t->timer_mutex)); + + switch (ret) { + case ETIMEDOUT: + LOC_LOGV("%s:%d]: loc_timer timed out", __func__, __LINE__); + break; + case 0: + LOC_LOGV("%s:%d]: loc_timer stopped", __func__, __LINE__); + break; + case -ETIMEDOUT: + LOC_LOGV("%s:%d]: loc_timer cancelled", __func__, __LINE__); + break; + default: + LOC_LOGE("%s:%d]: Call to pthread timedwait failed; ret=%d\n", + __func__, __LINE__, ret); + break; + } + + if(ETIMEDOUT == ret) + t->callback_func(t->user_data, ret); + + // A (should be rare) race condition is that, when the loc_time_stop is called + // and acquired mutex, we reach here. pthread_mutex_destroy will fail with + // error code EBUSY. We give it 6 tries in 5 seconds. Should be eanough time + // for loc_timer_stop to complete. With the 7th try, we also perform unlock + // prior to destroy. + { + int i; + for (i = 0; EBUSY == pthread_mutex_destroy(&t->timer_mutex) && i <= 5; i++) { + if (i < 5) { + sleep(1); + } else { + // nah, forget it, something is seriously wrong. Mutex has been + // held too long. Unlock the mutext here. + pthread_mutex_unlock(&t->timer_mutex); + } + } + } + pthread_cond_destroy(&t->timer_cond); + + free(t); + LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__); + return NULL; +} + +void* loc_timer_start(unsigned int msec, loc_timer_callback cb_func, + void* caller_data) +{ + timer_data *t=NULL; + pthread_attr_t tattr; + pthread_t id; + LOC_LOGD("%s:%d]: Enter\n", __func__, __LINE__); + if(cb_func == NULL || msec == 0) { + LOC_LOGE("%s:%d]: Error: Wrong parameters\n", __func__, __LINE__); + goto _err; + } + t = (timer_data *)calloc(1, sizeof(timer_data)); + if(t == NULL) { + LOC_LOGE("%s:%d]: Could not allocate memory. Failing.\n", + __func__, __LINE__); + goto _err; + } + + if(pthread_cond_init(&(t->timer_cond), NULL)) { + LOC_LOGE("%s:%d]: Pthread cond init failed\n", __func__, __LINE__); + goto t_err; + } + if(pthread_mutex_init(&(t->timer_mutex), NULL)) { + LOC_LOGE("%s:%d]: Pthread mutex init failed\n", __func__, __LINE__); + goto cond_err; + } + + t->callback_func = cb_func; + t->user_data = caller_data; + t->time_msec = msec; + t->state = READY; + + if (pthread_attr_init(&tattr)) { + LOC_LOGE("%s:%d]: Pthread mutex init failed\n", __func__, __LINE__); + goto mutex_err; + } + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); + + if(pthread_create(&(id), &tattr, timer_thread, (void *)t)) { + LOC_LOGE("%s:%d]: Could not create thread\n", __func__, __LINE__); + goto attr_err; + } + + LOC_LOGD("%s:%d]: Created thread with id: %d\n", + __func__, __LINE__, (int)id); + goto _err; + +attr_err: + pthread_attr_destroy(&tattr); +mutex_err: + pthread_mutex_destroy(&t->timer_mutex); +cond_err: + pthread_cond_destroy(&t->timer_cond); +t_err: + free(t); +_err: + LOC_LOGD("%s:%d]: Exit\n", __func__, __LINE__); + return t; +} + +void loc_timer_stop(void* handle) { + timer_data* t = (timer_data*)handle; + + if (NULL != t && (READY == t->state || WAITING == t->state) && + pthread_mutex_lock(&(t->timer_mutex)) == 0) { + if (READY == t->state || WAITING == t->state) { + pthread_cond_signal(&t->timer_cond); + t->state = ABORT; + } + pthread_mutex_unlock(&(t->timer_mutex)); + } +} diff --git a/gps/utils/loc_timer.h b/gps/utils/loc_timer.h new file mode 100644 index 0000000..0034d27 --- /dev/null +++ b/gps/utils/loc_timer.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2013, 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_DELAY_H__ +#define __LOC_DELAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include<pthread.h> +#include "log_util.h" + +/* + Return values: + Success = 0 + Failure = Non zero +*/ +typedef void(*loc_timer_callback)(void *user_data, int result); + + +/* + Returns the handle, which can be used to stop the timer +*/ +void* loc_timer_start(unsigned int delay_msec, + loc_timer_callback, + void* user_data); + +/* + handle becomes invalid upon the return of the callback +*/ +void loc_timer_stop(void* handle); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif //__LOC_DELAY_H__ diff --git a/gps/utils/log_util.h b/gps/utils/log_util.h index 9187e4f..8ff6b5a 100644 --- a/gps/utils/log_util.h +++ b/gps/utils/log_util.h @@ -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 @@ -30,6 +30,23 @@ #ifndef __LOG_UTIL_H__ #define __LOG_UTIL_H__ +#ifndef USE_GLIB +#include <utils/Log.h> +#endif /* USE_GLIB */ + +#ifdef USE_GLIB + +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +#ifndef LOG_TAG +#define LOG_TAG "GPS_UTILS" + +#endif // LOG_TAG + +#endif /* USE_GLIB */ + #ifdef __cplusplus extern "C" { @@ -72,41 +89,54 @@ extern const char ENTRY_TAG[]; extern void loc_logger_init(unsigned long debug, unsigned long timestamp); extern char* get_timestamp(char* str, unsigned long buf_size); - -#include <utils/Log.h> - #ifndef DEBUG_DMN_LOC_API /* LOGGING MACROS */ -#define LOC_LOGE(...) ALOGE("E/"__VA_ARGS__) +/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp + 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_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) { ALOGE("W/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGW("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) { ALOGE("I/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGI("W/"__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) { ALOGE("D/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGD("W/"__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) { ALOGE("V/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL <= 0) { ALOGV("W/"__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 */ -#define LOC_LOGE(...) ALOGE("E/"__VA_ARGS__) +#define LOC_LOGE(...) ALOGE("E/" __VA_ARGS__) -#define LOC_LOGW(...) ALOGW("W/"__VA_ARGS__) +#define LOC_LOGW(...) ALOGW("W/" __VA_ARGS__) -#define LOC_LOGI(...) ALOGI("I/"__VA_ARGS__) +#define LOC_LOGI(...) ALOGI("I/" __VA_ARGS__) -#define LOC_LOGD(...) ALOGD("D/"__VA_ARGS__) +#define LOC_LOGD(...) ALOGD("D/" __VA_ARGS__) -#define LOC_LOGV(...) ALOGV("V/"__VA_ARGS__) +#define LOC_LOGV(...) ALOGV("V/" __VA_ARGS__) #endif /* DEBUG_DMN_LOC_API */ diff --git a/gps/utils/msg_q.c b/gps/utils/msg_q.c index df1d7a5..f82d4c0 100644 --- a/gps/utils/msg_q.c +++ b/gps/utils/msg_q.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2012, 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 @@ -9,7 +9,7 @@ * 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 + * * 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. * @@ -30,7 +30,7 @@ #define LOG_TAG "LocSvc_utils_q" #include "log_util.h" - +#include "platform_lib_includes.h" #include "linked_list.h" #include <stdio.h> #include <stdlib.h> @@ -138,6 +138,20 @@ msq_q_err_type msg_q_init(void** msg_q_data) /*=========================================================================== + FUNCTION: msg_q_init2 + + ===========================================================================*/ +const void* msg_q_init2() +{ + void* q = NULL; + if (eMSG_Q_SUCCESS != msg_q_init(&q)) { + q = NULL; + } + return q; +} + +/*=========================================================================== + FUNCTION: msg_q_destroy ===========================================================================*/ diff --git a/gps/utils/msg_q.h b/gps/utils/msg_q.h index d3d5cc5..453b8ce 100644 --- a/gps/utils/msg_q.h +++ b/gps/utils/msg_q.h @@ -58,7 +58,7 @@ FUNCTION msg_q_init DESCRIPTION Initializes internal structures for message queue. - msg_q_data: State of message queue to be initialized. + msg_q_data: pointer to an opaque Q handle to be returned; NULL if fails DEPENDENCIES N/A @@ -73,6 +73,24 @@ SIDE EFFECTS msq_q_err_type msg_q_init(void** msg_q_data); /*=========================================================================== +FUNCTION msg_q_init2 + +DESCRIPTION + Initializes internal structures for message queue. + +DEPENDENCIES + N/A + +RETURN VALUE + opaque handle to the Q created; NULL if create fails + +SIDE EFFECTS + N/A + +===========================================================================*/ +const void* msg_q_init2(); + +/*=========================================================================== FUNCTION msg_q_destroy DESCRIPTION diff --git a/gps/utils/sec_gps.c b/gps/utils/sec_gps.c new file mode 100644 index 0000000..d5b1226 --- /dev/null +++ b/gps/utils/sec_gps.c @@ -0,0 +1,12 @@ + + +int sec_gps_conf(void) +{ + return 0; +} + +int Sec_Configuration(void) +{ + return 0; +} + |