diff --git a/core/Android.mk b/core/Android.mk index 11cecc65..3e2b2eb8 100644 --- a/core/Android.mk +++ b/core/Android.mk @@ -42,7 +42,8 @@ LOCAL_COPY_HEADERS:= \ UlpProxyBase.h \ gps_extended_c.h \ gps_extended.h \ - loc_core_log.h + loc_core_log.h \ + LocAdapterProxyBase.h LOCAL_PRELINK_MODULE := false diff --git a/core/LocAdapterBase.cpp b/core/LocAdapterBase.cpp index 8bbe873f..a65cb310 100644 --- a/core/LocAdapterBase.cpp +++ b/core/LocAdapterBase.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -33,6 +33,7 @@ #include #include #include +#include namespace loc_core { @@ -41,16 +42,27 @@ namespace loc_core { // But if getLocApi(targetEnumType target) is overriden, // the right locApi should get created. LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, - ContextBase* context) : + ContextBase* context, LocAdapterProxyBase *adapterProxyBase) : mEvtMask(mask), mContext(context), - mLocApi(context->getLocApi()), mMsgTask(context->getMsgTask()) + mLocApi(context->getLocApi()), mLocAdapterProxyBase(adapterProxyBase), + mMsgTask(context->getMsgTask()) { mLocApi->addAdapter(this); } -void LocAdapterBase:: - handleEngineDownEvent() -DEFAULT_IMPL() +void LocAdapterBase::handleEngineUpEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineUpEvent(); + } +} + +void LocAdapterBase::handleEngineDownEvent() +{ + if (mLocAdapterProxyBase) { + mLocAdapterProxyBase->handleEngineDownEvent(); + } +} void LocAdapterBase:: reportPosition(UlpLocation &location, diff --git a/core/LocAdapterBase.h b/core/LocAdapterBase.h index 8222b24b..4e6ff24b 100644 --- a/core/LocAdapterBase.h +++ b/core/LocAdapterBase.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -35,19 +35,22 @@ namespace loc_core { +class LocAdapterProxyBase; + class LocAdapterBase { protected: const LOC_API_ADAPTER_EVENT_MASK_T mEvtMask; ContextBase* mContext; LocApiBase* mLocApi; + LocAdapterProxyBase* mLocAdapterProxyBase; const MsgTask* mMsgTask; inline LocAdapterBase(const MsgTask* msgTask) : - mEvtMask(0), mContext(NULL), mLocApi(NULL), mMsgTask(msgTask) {} + mEvtMask(0), mContext(NULL), mLocApi(NULL), mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {} public: inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, - ContextBase* context); + ContextBase* context, LocAdapterProxyBase *adapterProxyBase = NULL); inline LOC_API_ADAPTER_EVENT_MASK_T checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const { return mEvtMask & mask; @@ -68,7 +71,7 @@ public: // This will be overridden by the individual adapters // if necessary. inline virtual void setUlpProxy(UlpProxyBase* ulp) {} - inline virtual void handleEngineUpEvent() {} + virtual void handleEngineUpEvent(); virtual void handleEngineDownEvent(); inline virtual void setPositionModeInt(LocPosMode& posMode) {} virtual void startFixInt() {} diff --git a/core/LocAdapterProxyBase.h b/core/LocAdapterProxyBase.h new file mode 100644 index 00000000..adc868c6 --- /dev/null +++ b/core/LocAdapterProxyBase.h @@ -0,0 +1,56 @@ +/* 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_ADAPTER_PROXY_BASE_H +#define LOC_ADAPTER_PROXY_BASE_H + +#include +#include + +namespace loc_core { + +class LocAdapterProxyBase { +private: + const LocAdapterBase *mLocAdapterBase; +protected: + inline LocAdapterProxyBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context): + mLocAdapterBase(new LocAdapterBase(mask, context, this)) { + } + inline virtual ~LocAdapterProxyBase() { + delete mLocAdapterBase; + } +public: + inline virtual void handleEngineUpEvent() {}; + inline virtual void handleEngineDownEvent() {}; +}; + +} // namespace loc_core + +#endif //LOC_ADAPTER_PROXY_BASE_H \ No newline at end of file diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 80e23755..8b6713c1 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -404,7 +404,8 @@ enum loc_api_adapter_err LocApiBase:: DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) enum loc_api_adapter_err LocApiBase:: - setSensorControlConfig(int sensorUsage) + setSensorControlConfig(int sensorUsage, + int sensorProvider) DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) enum loc_api_adapter_err LocApiBase:: diff --git a/core/LocApiBase.h b/core/LocApiBase.h index e162cfc7..1d96313e 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -158,7 +158,7 @@ public: virtual enum loc_api_adapter_err setLPPConfig(uint32_t profile); virtual enum loc_api_adapter_err - setSensorControlConfig(int sensorUsage); + setSensorControlConfig(int sensorUsage, int sensorProvider); virtual enum loc_api_adapter_err setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, diff --git a/core/UlpProxyBase.h b/core/UlpProxyBase.h index 0873748b..90097571 100644 --- a/core/UlpProxyBase.h +++ b/core/UlpProxyBase.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2013-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 @@ -37,11 +37,19 @@ class LocAdapterBase; class UlpProxyBase { public: - inline UlpProxyBase() {} + LocPosMode mPosMode; + bool mFixSet; + inline UlpProxyBase() { + mPosMode.mode = LOC_POSITION_MODE_INVALID; + mFixSet = false; + } inline virtual ~UlpProxyBase() {} - inline virtual bool sendStartFix() { return false;} - inline virtual bool sendStopFix() { return false;} - inline virtual bool sendFixMode(LocPosMode ¶ms) { return false;} + inline virtual bool sendStartFix() { mFixSet = true; return false; } + inline virtual bool sendStopFix() { mFixSet = false; return false; } + inline virtual bool sendFixMode(LocPosMode ¶ms) { + mPosMode = params; + return false; + } inline virtual bool reportPosition(UlpLocation &location, GpsLocationExtended &locationExtended, void* locationExt, diff --git a/core/gps_extended_c.h b/core/gps_extended_c.h index f970b644..7b9b43a5 100644 --- a/core/gps_extended_c.h +++ b/core/gps_extended_c.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2013-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 @@ -61,6 +61,8 @@ extern "C" { #define ULP_MIN_INTERVAL_INVALID 0xffffffff +/*Emergency SUPL*/ +#define GPS_NI_TYPE_EMERGENCY_SUPL 4 typedef struct { /** set to sizeof(UlpLocation) */ @@ -285,52 +287,54 @@ enum loc_api_adapter_err { }; enum loc_api_adapter_event_index { - LOC_API_ADAPTER_REPORT_POSITION = 0, // Position report comes in loc_parsed_position_s_type - LOC_API_ADAPTER_REPORT_SATELLITE, // Satellite in view report - LOC_API_ADAPTER_REPORT_NMEA_1HZ, // NMEA report at 1HZ rate - LOC_API_ADAPTER_REPORT_NMEA_POSITION, // NMEA report at position report rate - LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY, // NI notification/verification request - LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA, // Assistance data, eg: time, predicted orbits request - LOC_API_ADAPTER_REQUEST_LOCATION_SERVER, // Request for location server - LOC_API_ADAPTER_REPORT_IOCTL, // Callback report for loc_ioctl - LOC_API_ADAPTER_REPORT_STATUS, // Misc status report: eg, engine state - LOC_API_ADAPTER_REQUEST_WIFI, // - LOC_API_ADAPTER_SENSOR_STATUS, // - LOC_API_ADAPTER_REQUEST_TIME_SYNC, // - LOC_API_ADAPTER_REPORT_SPI, // - LOC_API_ADAPTER_REPORT_NI_GEOFENCE, // - LOC_API_ADAPTER_GEOFENCE_GEN_ALERT, // - LOC_API_ADAPTER_REPORT_GENFENCE_BREACH, // - LOC_API_ADAPTER_PEDOMETER_CTRL, // - LOC_API_ADAPTER_MOTION_CTRL, // - LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA, // Wifi ap data - LOC_API_ADAPTER_BATCH_FULL, // Batching on full - LOC_API_ADAPTER_BATCHED_POSITION_REPORT, // Batching on fix + LOC_API_ADAPTER_REPORT_POSITION = 0, // Position report comes in loc_parsed_position_s_type + LOC_API_ADAPTER_REPORT_SATELLITE, // Satellite in view report + LOC_API_ADAPTER_REPORT_NMEA_1HZ, // NMEA report at 1HZ rate + LOC_API_ADAPTER_REPORT_NMEA_POSITION, // NMEA report at position report rate + LOC_API_ADAPTER_REQUEST_NI_NOTIFY_VERIFY, // NI notification/verification request + LOC_API_ADAPTER_REQUEST_ASSISTANCE_DATA, // Assistance data, eg: time, predicted orbits request + LOC_API_ADAPTER_REQUEST_LOCATION_SERVER, // Request for location server + LOC_API_ADAPTER_REPORT_IOCTL, // Callback report for loc_ioctl + LOC_API_ADAPTER_REPORT_STATUS, // Misc status report: eg, engine state + LOC_API_ADAPTER_REQUEST_WIFI, // + LOC_API_ADAPTER_SENSOR_STATUS, // + LOC_API_ADAPTER_REQUEST_TIME_SYNC, // + LOC_API_ADAPTER_REPORT_SPI, // + LOC_API_ADAPTER_REPORT_NI_GEOFENCE, // + LOC_API_ADAPTER_GEOFENCE_GEN_ALERT, // + LOC_API_ADAPTER_REPORT_GENFENCE_BREACH, // + LOC_API_ADAPTER_PEDOMETER_CTRL, // + LOC_API_ADAPTER_MOTION_CTRL, // + LOC_API_ADAPTER_REQUEST_WIFI_AP_DATA, // Wifi ap data + LOC_API_ADAPTER_BATCH_FULL, // Batching on full + LOC_API_ADAPTER_BATCHED_POSITION_REPORT, // Batching on fix + LOC_API_ADAPTER_BATCHED_GENFENCE_BREACH_REPORT, // LOC_API_ADAPTER_EVENT_MAX }; -#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1<setUlpProxy(mUlp); - } - }; - - sendMsg(new LocSetUlpProxy(mLocEngAdapter, ulp)); -} LocEngAdapter::LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask, void* owner, ContextBase* context, @@ -95,6 +79,23 @@ LocEngAdapter::~LocEngAdapter() LOC_LOGV("LocEngAdapter deleted"); } +void LocInternalAdapter::setUlpProxy(UlpProxyBase* ulp) { + struct LocSetUlpProxy : public LocMsg { + LocAdapterBase* mAdapter; + UlpProxyBase* mUlp; + inline LocSetUlpProxy(LocAdapterBase* adapter, UlpProxyBase* ulp) : + LocMsg(), mAdapter(adapter), mUlp(ulp) { + } + virtual void proc() const { + LOC_LOGV("%s] ulp %p adapter %p", __func__, + mUlp, mAdapter); + mAdapter->setUlpProxy(mUlp); + } + }; + + sendMsg(new LocSetUlpProxy(mLocEngAdapter, ulp)); +} + void LocEngAdapter::setUlpProxy(UlpProxyBase* ulp) { if (ulp == mUlp) { @@ -102,18 +103,24 @@ void LocEngAdapter::setUlpProxy(UlpProxyBase* ulp) //and we get the same object back for UlpProxyBase . Do nothing return; } - delete mUlp; + LOC_LOGV("%s] %p", __func__, ulp); if (NULL == ulp) { + LOC_LOGE("%s:%d]: ulp pointer is NULL", __func__, __LINE__); ulp = new UlpProxyBase(); } - mUlp = ulp; - if (LOC_POSITION_MODE_INVALID != mFixCriteria.mode) { + if (LOC_POSITION_MODE_INVALID != mUlp->mPosMode.mode) { // need to send this mode and start msg to ULP - mUlp->sendFixMode(mFixCriteria); - mUlp->sendStartFix(); + ulp->sendFixMode(mUlp->mPosMode); } + + if(mUlp->mFixSet) { + ulp->sendStartFix(); + } + + delete mUlp; + mUlp = ulp; } void LocInternalAdapter::reportPosition(UlpLocation &location, @@ -294,4 +301,3 @@ void LocEngAdapter::handleEngineUpEvent() { sendMsg(new LocEngUp(mOwner)); } - diff --git a/loc_api/libloc_api_50001/LocEngAdapter.h b/loc_api/libloc_api_50001/LocEngAdapter.h index d03dc660..6de663c0 100644 --- a/loc_api/libloc_api_50001/LocEngAdapter.h +++ b/loc_api/libloc_api_50001/LocEngAdapter.h @@ -185,9 +185,9 @@ public: return mLocApi->setLPPConfig(profile); } inline enum loc_api_adapter_err - setSensorControlConfig(int sensorUsage) + setSensorControlConfig(int sensorUsage, int sensorProvider) { - return mLocApi->setSensorControlConfig(sensorUsage); + return mLocApi->setSensorControlConfig(sensorUsage, sensorProvider); } inline enum loc_api_adapter_err setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, diff --git a/loc_api/libloc_api_50001/loc_eng.cpp b/loc_api/libloc_api_50001/loc_eng.cpp index 6d6d701a..5d8381e7 100644 --- a/loc_api/libloc_api_50001/loc_eng.cpp +++ b/loc_api/libloc_api_50001/loc_eng.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2009-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 @@ -118,6 +118,7 @@ static loc_param_s_type loc_parameter_table[] = {"QUIPC_ENABLED", &gps_conf.QUIPC_ENABLED, NULL, 'n'}, {"LPP_PROFILE", &gps_conf.LPP_PROFILE, NULL, 'n'}, {"A_GLONASS_POS_PROTOCOL_SELECT", &gps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'}, + {"SENSOR_PROVIDER", &sap_conf.SENSOR_PROVIDER, NULL, 'n'}, }; static void loc_default_parameters(void) @@ -160,6 +161,9 @@ static void loc_default_parameters(void) /*By default no positioning protocol is selected on A-GLONASS system*/ gps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0; + + /* default provider is SSC */ + sap_conf.SENSOR_PROVIDER = 1; } // 2nd half of init(), singled out for @@ -497,18 +501,20 @@ struct LocEngLppConfig : public LocMsg { struct LocEngSensorControlConfig : public LocMsg { LocEngAdapter* mAdapter; const int mSensorsDisabled; + const int mSensorProvider; inline LocEngSensorControlConfig(LocEngAdapter* adapter, - int sensorsDisabled) : - LocMsg(), mAdapter(adapter), mSensorsDisabled(sensorsDisabled) + int sensorsDisabled, int sensorProvider) : + LocMsg(), mAdapter(adapter), mSensorsDisabled(sensorsDisabled), + mSensorProvider(sensorProvider) { locallog(); } inline virtual void proc() const { - mAdapter->setSensorControlConfig(mSensorsDisabled); + mAdapter->setSensorControlConfig(mSensorsDisabled, mSensorProvider); } inline void locallog() const { - LOC_LOGV("LocEngSensorControlConfig - Sensors Disabled: %d", - mSensorsDisabled); + LOC_LOGV("LocEngSensorControlConfig - Sensors Disabled: %d, Sensor Provider: %d", + mSensorsDisabled, mSensorProvider); } inline virtual void log() const { locallog(); @@ -1554,7 +1560,8 @@ static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data) LocEngAdapter* adapter = loc_eng_data.adapter; adapter->sendMsg(new LocEngSuplVer(adapter, gps_conf.SUPL_VER)); adapter->sendMsg(new LocEngLppConfig(adapter, gps_conf.LPP_PROFILE)); - adapter->sendMsg(new LocEngSensorControlConfig(adapter, sap_conf.SENSOR_USAGE)); + adapter->sendMsg(new LocEngSensorControlConfig(adapter, sap_conf.SENSOR_USAGE, + sap_conf.SENSOR_PROVIDER)); adapter->sendMsg(new LocEngAGlonassProtocol(adapter, gps_conf.A_GLONASS_POS_PROTOCOL_SELECT)); /* Make sure at least one of the sensor property is specified by the user in the gps.conf file. */ @@ -2086,9 +2093,9 @@ void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* call AGPS_TYPE_SUPL, false); - loc_eng_data.adapter->sendMsg(new LocEngDataClientInit(&loc_eng_data)); - if (adapter->mAgpsEnabled) { + loc_eng_data.adapter->sendMsg(new LocEngDataClientInit(&loc_eng_data)); + loc_eng_dmn_conn_loc_api_server_launch(callbacks->create_thread_cb, NULL, NULL, &loc_eng_data); } diff --git a/loc_api/libloc_api_50001/loc_eng.h b/loc_api/libloc_api_50001/loc_eng.h index 2dfd50f7..e50e4a58 100644 --- a/loc_api/libloc_api_50001/loc_eng.h +++ b/loc_api/libloc_api_50001/loc_eng.h @@ -171,6 +171,7 @@ typedef struct double RATE_RANDOM_WALK_SPECTRAL_DENSITY; uint8_t VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID; double VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY; + unsigned long SENSOR_PROVIDER; } loc_sap_cfg_s_type; extern loc_gps_cfg_s_type gps_conf; diff --git a/loc_api/libloc_api_50001/loc_eng_dmn_conn.h b/loc_api/libloc_api_50001/loc_eng_dmn_conn.h index c7c100b2..1d8c1428 100644 --- a/loc_api/libloc_api_50001/loc_eng_dmn_conn.h +++ b/loc_api/libloc_api_50001/loc_eng_dmn_conn.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-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,11 +33,11 @@ #ifdef _ANDROID_ -#define GPSONE_LOC_API_Q_PATH "/data/misc/gpsone_d/gpsone_loc_api_q" -#define GPSONE_LOC_API_RESP_Q_PATH "/data/misc/gpsone_d/gpsone_loc_api_resp_q" -#define QUIPC_CTRL_Q_PATH "/data/misc/gpsone_d/quipc_ctrl_q" -#define MSAPM_CTRL_Q_PATH "/data/misc/gpsone_d/msapm_ctrl_q" -#define MSAPU_CTRL_Q_PATH "/data/misc/gpsone_d/msapu_ctrl_q" +#define GPSONE_LOC_API_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_q" +#define GPSONE_LOC_API_RESP_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_resp_q" +#define QUIPC_CTRL_Q_PATH "/data/misc/location/gpsone_d/quipc_ctrl_q" +#define MSAPM_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapm_ctrl_q" +#define MSAPU_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapu_ctrl_q" #else diff --git a/loc_api/libloc_api_50001/loc_eng_ni.cpp b/loc_api/libloc_api_50001/loc_eng_ni.cpp index f017cab6..74abfd42 100644 --- a/loc_api/libloc_api_50001/loc_eng_ni.cpp +++ b/loc_api/libloc_api_50001/loc_eng_ni.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2009-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 @@ -218,6 +218,8 @@ static void* ni_thread_proc(void *args) "pthread_cond_timedwait = %d\n",rc ); loc_eng_ni_data_p->respRecvd = FALSE; /* Reset the user response flag for the next session*/ + LOC_LOGD("loc_eng_ni_data_p->resp is %d\n",loc_eng_ni_data_p->resp); + // adding this check to support modem restart, in which case, we need the thread // to exit without calling sending data. We made sure that rawRequest is NULL in // loc_eng_ni_reset_on_engine_restart() @@ -225,9 +227,14 @@ static void* ni_thread_proc(void *args) LocEngInformNiResponse *msg = NULL; if (NULL != loc_eng_ni_data_p->rawRequest) { - msg = new LocEngInformNiResponse(adapter, - loc_eng_ni_data_p->resp, - loc_eng_ni_data_p->rawRequest); + if (loc_eng_ni_data_p->resp != GPS_NI_RESPONSE_IGNORE) { + LOC_LOGD("loc_eng_ni_data_p->resp != GPS_NI_RESPONSE_IGNORE \n"); + msg = new LocEngInformNiResponse(adapter, + loc_eng_ni_data_p->resp, + loc_eng_ni_data_p->rawRequest); + } else { + LOC_LOGD("this is the ignore reply for SUPL ES\n"); + } loc_eng_ni_data_p->rawRequest = NULL; } pthread_mutex_unlock(&loc_eng_ni_data_p->tLock); @@ -236,6 +243,7 @@ static void* ni_thread_proc(void *args) loc_eng_ni_data_p->reqID++; if (NULL != msg) { + LOC_LOGD("ni_thread_proc: adapter->sendMsg(msg)\n"); adapter->sendMsg(msg); } diff --git a/loc_api/libloc_api_50001/loc_eng_ni.h b/loc_api/libloc_api_50001/loc_eng_ni.h index 9cbc57dc..8c076041 100644 --- a/loc_api/libloc_api_50001/loc_eng_ni.h +++ b/loc_api/libloc_api_50001/loc_eng_ni.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2009,2011 The Linux Foundation. All rights reserved. +/* Copyright (c) 2009,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 @@ -34,6 +34,7 @@ #define LOC_NI_NO_RESPONSE_TIME 20 /* secs */ #define LOC_NI_NOTIF_KEY_ADDRESS "Address" +#define GPS_NI_RESPONSE_IGNORE 4 typedef struct { pthread_t thread; /* NI thread */ diff --git a/utils/Android.mk b/utils/Android.mk index abfbb6fa..07c1b1da 100644 --- a/utils/Android.mk +++ b/utils/Android.mk @@ -19,7 +19,8 @@ LOCAL_SRC_FILES += \ linked_list.c \ loc_target.cpp \ loc_timer.c \ - ../platform_lib_abstractions/elapsed_millis_since_boot.cpp + ../platform_lib_abstractions/elapsed_millis_since_boot.cpp \ + loc_misc_utils.cpp LOCAL_CFLAGS += \ -fno-short-enums \ @@ -46,7 +47,8 @@ LOCAL_COPY_HEADERS:= \ loc_timer.h \ ../platform_lib_abstractions/platform_lib_includes.h \ ../platform_lib_abstractions/platform_lib_time.h \ - ../platform_lib_abstractions/platform_lib_macros.h + ../platform_lib_abstractions/platform_lib_macros.h \ + loc_misc_utils.h LOCAL_MODULE := libgps.utils diff --git a/utils/loc_cfg.cpp b/utils/loc_cfg.cpp index 73d1ca41..abf8086c 100644 --- a/utils/loc_cfg.cpp +++ b/utils/loc_cfg.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef USE_GLIB #include #endif @@ -57,62 +58,17 @@ static uint8_t TIMESTAMP = 0; /* Parameter spec table */ static loc_param_s_type loc_parameter_table[] = { - {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, - {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, + {"DEBUG_LEVEL", &DEBUG_LEVEL, NULL, 'n'}, + {"TIMESTAMP", &TIMESTAMP, NULL, 'n'}, }; int loc_param_num = sizeof(loc_parameter_table) / sizeof(loc_param_s_type); -/*=========================================================================== -FUNCTION trim_space - -DESCRIPTION - Removes leading and trailing spaces of the string - -DEPENDENCIES - N/A - -RETURN VALUE - None - -SIDE EFFECTS - N/A -===========================================================================*/ -void trim_space(char *org_string) -{ - char *scan_ptr, *write_ptr; - char *first_nonspace = NULL, *last_nonspace = NULL; - - scan_ptr = write_ptr = org_string; - - while (*scan_ptr) - { - if ( !isspace(*scan_ptr) && first_nonspace == NULL) - { - first_nonspace = scan_ptr; - } - - if (first_nonspace != NULL) - { - *(write_ptr++) = *scan_ptr; - if ( !isspace(*scan_ptr)) - { - last_nonspace = write_ptr; - } - } - - scan_ptr++; - } - - if (last_nonspace) { *last_nonspace = '\0'; } -} - typedef struct loc_param_v_type { - char* param_name; - - char* param_str_value; - int param_int_value; - double param_double_value; + char* param_name; + char* param_str_value; + int param_int_value; + double param_double_value; }loc_param_v_type; /*=========================================================================== @@ -136,61 +92,166 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -void loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) +int loc_set_config_entry(loc_param_s_type* config_entry, loc_param_v_type* config_value) { - if(NULL == config_entry || NULL == config_value) - { - LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); - return; - } + int ret=-1; + if(NULL == config_entry || NULL == config_value) + { + LOC_LOGE("%s: INVALID config entry or parameter", __FUNCTION__); + return ret; + } - if (strcmp(config_entry->param_name, config_value->param_name) == 0 && - config_entry->param_ptr) - { - switch (config_entry->param_type) - { - case 's': - if (strcmp(config_value->param_str_value, "NULL") == 0) - { - *((char*)config_entry->param_ptr) = '\0'; - } - else { - strlcpy((char*) config_entry->param_ptr, - config_value->param_str_value, - LOC_MAX_PARAM_STRING + 1); - } - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr); + if (strcmp(config_entry->param_name, config_value->param_name) == 0 && + config_entry->param_ptr) + { + switch (config_entry->param_type) + { + case 's': + if (strcmp(config_value->param_str_value, "NULL") == 0) + { + *((char*)config_entry->param_ptr) = '\0'; + } + else { + strlcpy((char*) config_entry->param_ptr, + config_value->param_str_value, + LOC_MAX_PARAM_STRING + 1); + } + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %s", __FUNCTION__, config_entry->param_name, (char*)config_entry->param_ptr); - if(NULL != config_entry->param_set) - { - *(config_entry->param_set) = 1; - } - break; - case 'n': - *((int *)config_entry->param_ptr) = config_value->param_int_value; - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, config_entry->param_name, config_value->param_int_value); + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'n': + *((int *)config_entry->param_ptr) = config_value->param_int_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %d", __FUNCTION__, config_entry->param_name, config_value->param_int_value); - if(NULL != config_entry->param_set) - { - *(config_entry->param_set) = 1; - } - break; - case 'f': - *((double *)config_entry->param_ptr) = config_value->param_double_value; - /* Log INI values */ - LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, config_entry->param_name, config_value->param_double_value); + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + case 'f': + *((double *)config_entry->param_ptr) = config_value->param_double_value; + /* Log INI values */ + LOC_LOGD("%s: PARAM %s = %f", __FUNCTION__, config_entry->param_name, config_value->param_double_value); - if(NULL != config_entry->param_set) - { - *(config_entry->param_set) = 1; - } - break; - default: - LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name); - } - } + if(NULL != config_entry->param_set) + { + *(config_entry->param_set) = 1; + } + ret = 0; + break; + default: + LOC_LOGE("%s: PARAM %s parameter type must be n, f, or s", __FUNCTION__, config_entry->param_name); + } + } + return ret; +} + +/*=========================================================================== +FUNCTION loc_read_conf_r (repetitive) + +DESCRIPTION + Reads the specified configuration file and sets defined values based on + the passed in configuration table. This table maps strings to values to + set along with the type of each of these values. + The difference between this and loc_read_conf is that this function returns + the file pointer position at the end of filling a config table. Also, it + reads a fixed number of parameters at a time which is equal to the length + of the configuration table. This functionality enables the caller to + repeatedly call the function to read data from the same file. + +PARAMETERS: + conf_fp : file pointer + config_table: table definition of strings to places to store information + table_length: length of the configuration table + +DEPENDENCIES + N/A + +RETURN VALUE + 0: Table filled successfully + 1: No more parameters to read + -1: Error filling table + +SIDE EFFECTS + N/A +===========================================================================*/ +int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length) +{ + char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */ + char *lasts; + loc_param_v_type config_value; + uint32_t i; + int ret=0; + + unsigned int num_params=table_length; + if(conf_fp == NULL) { + LOC_LOGE("%s:%d]: ERROR: File pointer is NULL\n", __func__, __LINE__); + ret = -1; + goto err; + } + + /* Clear all validity bits */ + for(i = 0; NULL != config_table && i < table_length; i++) + { + if(NULL != config_table[i].param_set) + { + *(config_table[i].param_set) = 0; + } + } + LOC_LOGD("%s:%d]: num_params: %d\n", __func__, __LINE__, num_params); + while(num_params) + { + if(!fgets(input_buf, LOC_MAX_PARAM_LINE, conf_fp)) { + LOC_LOGD("%s:%d]: fgets returned NULL\n", __func__, __LINE__); + break; + } + + memset(&config_value, 0, sizeof(config_value)); + + /* Separate variable and value */ + config_value.param_name = strtok_r(input_buf, "=", &lasts); + /* skip lines that do not contain "=" */ + if (config_value.param_name == NULL) continue; + config_value.param_str_value = strtok_r(NULL, "=", &lasts); + /* skip lines that do not contain two operands */ + if (config_value.param_str_value == NULL) continue; + + /* Trim leading and trailing spaces */ + loc_util_trim_space(config_value.param_name); + loc_util_trim_space(config_value.param_str_value); + + /* Parse numerical value */ + if ((strlen(config_value.param_str_value) >=3) && + (config_value.param_str_value[0] == '0') && + (tolower(config_value.param_str_value[1]) == 'x')) + { + /* hex */ + config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], + (char**) NULL, 16); + } + else { + config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */ + config_value.param_int_value = atoi(config_value.param_str_value); /* dec */ + } + + for(i = 0; NULL != config_table && i < table_length; i++) + { + if(!loc_set_config_entry(&config_table[i], &config_value)) { + num_params--; + } + } + } + +err: + return ret; } /*=========================================================================== @@ -215,72 +276,25 @@ RETURN VALUE SIDE EFFECTS N/A ===========================================================================*/ -void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, uint32_t table_length) +void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, + uint32_t table_length) { - FILE *gps_conf_fp = NULL; - char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */ - char *lasts; - loc_param_v_type config_value; - uint32_t i; + FILE *gps_conf_fp = NULL; + char input_buf[LOC_MAX_PARAM_LINE]; /* declare a char array */ + char *lasts; + loc_param_v_type config_value; + uint32_t i; - if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL) - { - LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); - } - else - { - LOC_LOGW("%s: no %s file found", __FUNCTION__, conf_file_name); - loc_logger_init(DEBUG_LEVEL, TIMESTAMP); - return; /* no parameter file */ - } - - /* Clear all validity bits */ - for(i = 0; NULL != config_table && i < table_length; i++) - { - if(NULL != config_table[i].param_set) - { - *(config_table[i].param_set) = 0; - } - } - - while(fgets(input_buf, LOC_MAX_PARAM_LINE, gps_conf_fp) != NULL) - { - memset(&config_value, 0, sizeof(config_value)); - - /* Separate variable and value */ - config_value.param_name = strtok_r(input_buf, "=", &lasts); - if (config_value.param_name == NULL) continue; /* skip lines that do not contain "=" */ - config_value.param_str_value = strtok_r(NULL, "=", &lasts); - if (config_value.param_str_value == NULL) continue; /* skip lines that do not contain two operands */ - - /* Trim leading and trailing spaces */ - trim_space(config_value.param_name); - trim_space(config_value.param_str_value); - - /* Parse numerical value */ - if (config_value.param_str_value[0] == '0' && tolower(config_value.param_str_value[1]) == 'x') - { - /* hex */ - config_value.param_int_value = (int) strtol(&config_value.param_str_value[2], (char**) NULL, 16); - } - else { - config_value.param_double_value = (double) atof(config_value.param_str_value); /* float */ - config_value.param_int_value = atoi(config_value.param_str_value); /* dec */ - } - - for(i = 0; NULL != config_table && i < table_length; i++) - { - loc_set_config_entry(&config_table[i], &config_value); - } - - for(i = 0; i < loc_param_num; i++) - { - loc_set_config_entry(&loc_parameter_table[i], &config_value); - } - } - - fclose(gps_conf_fp); - - /* Initialize logging mechanism with parsed data */ - loc_logger_init(DEBUG_LEVEL, TIMESTAMP); + if((gps_conf_fp = fopen(conf_file_name, "r")) != NULL) + { + LOC_LOGD("%s: using %s", __FUNCTION__, conf_file_name); + if(table_length && config_table) { + loc_read_conf_r(gps_conf_fp, config_table, table_length); + rewind(gps_conf_fp); + } + loc_read_conf_r(gps_conf_fp, loc_parameter_table, loc_param_num); + fclose(gps_conf_fp); + } + /* Initialize logging mechanism with parsed data */ + loc_logger_init(DEBUG_LEVEL, TIMESTAMP); } diff --git a/utils/loc_cfg.h b/utils/loc_cfg.h index df833389..268f4c24 100644 --- a/utils/loc_cfg.h +++ b/utils/loc_cfg.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -30,6 +30,7 @@ #ifndef LOC_CFG_H #define LOC_CFG_H +#include #include #define LOC_MAX_PARAM_NAME 48 @@ -75,7 +76,7 @@ extern "C" { extern void loc_read_conf(const char* conf_file_name, loc_param_s_type* config_table, uint32_t table_length); - +extern int loc_read_conf_r(FILE *conf_fp, loc_param_s_type* config_table, uint32_t table_length); #ifdef __cplusplus } #endif diff --git a/utils/loc_misc_utils.cpp b/utils/loc_misc_utils.cpp new file mode 100644 index 00000000..7e96313f --- /dev/null +++ b/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 +#include +#include +#include +#include + +#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/utils/loc_misc_utils.h b/utils/loc_misc_utils.h new file mode 100644 index 00000000..7d66d842 --- /dev/null +++ b/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/utils/loc_target.cpp b/utils/loc_target.cpp index a3ef6b3c..d46747ac 100644 --- a/utils/loc_target.cpp +++ b/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 @@ -56,7 +56,10 @@ #define LENGTH(s) (sizeof(s) - 1) #define GPS_CHECK_NO_ERROR 0 #define GPS_CHECK_NO_GPS_HW 1 -#define QCA1530_DETECT_TIMEOUT 30 +/* When system server is started, it uses 20 seconds as ActivityManager + * timeout. After that it sends SIGSTOP signal to process. + */ +#define QCA1530_DETECT_TIMEOUT 15 #define QCA1530_DETECT_PRESENT "yes" #define QCA1530_DETECT_PROGRESS "detect" @@ -98,7 +101,7 @@ static int read_a_line(const char * file_path, char * line, int line_size) */ static bool is_qca1530(void) { - static const char qca1530_property_name[] = "persist.qca1530"; + static const char qca1530_property_name[] = "sys.qca1530"; bool res = false; int ret, i; char buf[PROPERTY_VALUE_MAX]; @@ -141,6 +144,34 @@ static bool is_qca1530(void) return res; } +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length) +{ + if(baseband && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.baseband", baseband, ""); + LOC_LOGD("%s:%d]: Baseband: %s\n", __func__, __LINE__, baseband); + } + else { + LOC_LOGE("%s:%d]: NULL parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length) +{ + if(platform_name && (array_length >= PROPERTY_VALUE_MAX)) { + property_get("ro.board.platform", platform_name, ""); + LOC_LOGD("%s:%d]: Target name: %s\n", __func__, __LINE__, platform_name); + } + else { + LOC_LOGE("%s:%d]: Null parameter or array length less than PROPERTY_VALUE_MAX\n", + __func__, __LINE__); + } +} + unsigned int loc_get_target(void) { if (gTarget != (unsigned int)-1) @@ -163,7 +194,8 @@ unsigned int loc_get_target(void) goto detected; } - property_get("ro.baseband", baseband, ""); + loc_get_target_baseband(baseband, sizeof(baseband)); + if (!access(hw_platform, F_OK)) { read_a_line(hw_platform, rd_hw_platform, LINE_LEN); } else { diff --git a/utils/loc_target.h b/utils/loc_target.h index 4aebb851..9aa525fc 100644 --- a/utils/loc_target.h +++ b/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 @@ -45,6 +45,13 @@ extern "C" unsigned int loc_get_target(void); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_target_baseband(char *baseband, int array_length); +/*The character array passed to this function should have length + of atleast PROPERTY_VALUE_MAX*/ +void loc_get_platform_name(char *platform_name, int array_length); + /* Please remember to update 'target_name' in loc_log.cpp, if do any changes to this enum. */ typedef enum { diff --git a/utils/log_util.h b/utils/log_util.h index 7fb0c780..5606defa 100644 --- a/utils/log_util.h +++ b/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 @@ -96,24 +96,34 @@ extern char* get_timestamp(char* str, unsigned long buf_size); if that value remains unchanged, it means gps.conf did not provide a value and we default to the initial value to use Android's logging levels*/ +#define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5)) + +#define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5)) + +#define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5)) + +#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) + +#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) + #define LOC_LOGE(...) \ -if ((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \ -else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("W/"__VA_ARGS__); } +IF_LOC_LOGE { ALOGE("E/"__VA_ARGS__); } \ +else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("E/"__VA_ARGS__); } #define LOC_LOGW(...) \ -if ((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \ +IF_LOC_LOGW { ALOGE("W/"__VA_ARGS__); } \ else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGW("W/"__VA_ARGS__); } #define LOC_LOGI(...) \ -if ((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("I/"__VA_ARGS__); } \ +IF_LOC_LOGI { ALOGE("I/"__VA_ARGS__); } \ else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGI("I/"__VA_ARGS__); } #define LOC_LOGD(...) \ -if ((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("D/"__VA_ARGS__); } \ +IF_LOC_LOGD { ALOGE("D/"__VA_ARGS__); } \ else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGD("D/"__VA_ARGS__); } #define LOC_LOGV(...) \ -if ((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("V/"__VA_ARGS__); } \ +IF_LOC_LOGV { ALOGE("V/"__VA_ARGS__); } \ else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGV("V/"__VA_ARGS__); } #else /* DEBUG_DMN_LOC_API */