From a915406668658c66698be3386c8796eb438ea282 Mon Sep 17 00:00:00 2001 From: Kevin Tang Date: Sun, 14 Jul 2013 17:45:13 -0700 Subject: [PATCH] Location Hal Design Level Change for FLP Requirement Changes can be highlighted with below summary: * Split the original LocApiAdapter to LocAdapter and LocApi. Now different adapter implementations can flexibly connect to different LocApi; * LocApi continues to abstract the API binding to RPC or QMI; * MsgTask which creates and owns a msg Q and a thread, and it define a LocMsg base msg class. The handler pulls a msg out of the Q and calls its proc() method. This makes it possible for msg sender to keep the data in the msg encapsulated, as it no longer requires a central msg handler who must under- stand all data format. This used to be where all the compile time dependencies are tangled together; * Added Context to bundle MsgTask and LocApi; * Added LocDualContext specifically for the FLP Location Hal architecture requirement; * Placed all the base classes of the above in loc_core folder / loc_core namespace / libloc_core.so, so other libraries can easily use derive from here without having to pull in the loc_eng implementation, which is a large library to include or link to; Change-Id: I40abfba96dea76757c98530c1f5e076b34ba4ac7 --- core/Android.mk | 49 + core/ContextBase.cpp | 63 + core/ContextBase.h | 61 + core/LocAdapterBase.cpp | 147 ++ core/LocAdapterBase.h | 97 + core/LocApiBase.cpp | 475 ++++ core/LocApiBase.h | 254 ++ core/LocDualContext.cpp | 117 + core/LocDualContext.h | 68 + core/MsgTask.cpp | 133 + core/MsgTask.h | 66 + core/gps_extended.h | 92 + core/gps_extended_c.h | 256 ++ core/loc_core_log.cpp | 250 ++ .../loc_ulp.h => core/loc_core_log.h | 68 +- loc_api/Android.mk | 2 - .../libloc_api-rpc-glue/Android.mk | 12 +- .../{LocApiRpcAdapter.h => LocApiRpc.h} | 40 +- .../{LocApiRpcAdapter.cpp => LocApiRpc.cpp} | 276 +- loc_api/libloc_api_50001/Android.mk | 68 +- loc_api/libloc_api_50001/LocApiAdapter.cpp | 269 -- loc_api/libloc_api_50001/LocApiAdapter.h | 250 -- loc_api/libloc_api_50001/LocEngAdapter.cpp | 207 ++ loc_api/libloc_api_50001/LocEngAdapter.h | 238 ++ loc_api/libloc_api_50001/Makefile.am | 4 +- loc_api/libloc_api_50001/gps_extended.h | 111 - loc_api/libloc_api_50001/loc.cpp | 72 +- loc_api/libloc_api_50001/loc.h | 39 +- loc_api/libloc_api_50001/loc_eng.cpp | 2221 ++++++++++------- loc_api/libloc_api_50001/loc_eng.h | 31 +- loc_api/libloc_api_50001/loc_eng_agps.cpp | 21 +- loc_api/libloc_api_50001/loc_eng_agps.h | 29 +- .../loc_eng_dmn_conn_handler.cpp | 132 +- loc_api/libloc_api_50001/loc_eng_log.cpp | 201 -- loc_api/libloc_api_50001/loc_eng_log.h | 14 - loc_api/libloc_api_50001/loc_eng_msg.cpp | 133 - loc_api/libloc_api_50001/loc_eng_msg.h | 914 ++----- loc_api/libloc_api_50001/loc_eng_ni.cpp | 56 +- loc_api/libloc_api_50001/loc_eng_nmea.cpp | 6 +- loc_api/libloc_api_50001/loc_eng_xtra.cpp | 62 +- 40 files changed, 4617 insertions(+), 2987 deletions(-) create mode 100644 core/Android.mk create mode 100644 core/ContextBase.cpp create mode 100644 core/ContextBase.h create mode 100644 core/LocAdapterBase.cpp create mode 100644 core/LocAdapterBase.h create mode 100644 core/LocApiBase.cpp create mode 100644 core/LocApiBase.h create mode 100644 core/LocDualContext.cpp create mode 100644 core/LocDualContext.h create mode 100644 core/MsgTask.cpp create mode 100644 core/MsgTask.h create mode 100644 core/gps_extended.h create mode 100644 core/gps_extended_c.h create mode 100644 core/loc_core_log.cpp rename loc_api/libloc_api_50001/loc_ulp.h => core/loc_core_log.h (50%) rename loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/{LocApiRpcAdapter.h => LocApiRpc.h} (84%) rename loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/{LocApiRpcAdapter.cpp => LocApiRpc.cpp} (85%) delete mode 100644 loc_api/libloc_api_50001/LocApiAdapter.cpp delete mode 100644 loc_api/libloc_api_50001/LocApiAdapter.h create mode 100644 loc_api/libloc_api_50001/LocEngAdapter.cpp create mode 100644 loc_api/libloc_api_50001/LocEngAdapter.h delete mode 100644 loc_api/libloc_api_50001/gps_extended.h delete mode 100644 loc_api/libloc_api_50001/loc_eng_msg.cpp diff --git a/core/Android.mk b/core/Android.mk new file mode 100644 index 00000000..f9074dbd --- /dev/null +++ b/core/Android.mk @@ -0,0 +1,49 @@ +ifneq ($(BUILD_TINY_ANDROID),true) + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libloc_core +LOCAL_MODULE_OWNER := qcom + +LOCAL_MODULE_TAGS := optional + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + libgps.utils \ + libdl \ + libandroid_runtime + +LOCAL_SRC_FILES += \ + MsgTask.cpp \ + LocApiBase.cpp \ + LocAdapterBase.cpp \ + ContextBase.cpp \ + LocDualContext.cpp \ + loc_core_log.cpp + +LOCAL_CFLAGS += \ + -fno-short-enums \ + -D_ANDROID_ + +LOCAL_C_INCLUDES:= \ + $(TARGET_OUT_HEADERS)/gps.utils + +LOCAL_COPY_HEADERS_TO:= libloc_core/ +LOCAL_COPY_HEADERS:= \ + MsgTask.h \ + LocApiBase.h \ + LocAdapterBase.h \ + ContextBase.h \ + LocDualContext.h \ + gps_extended_c.h \ + gps_extended.h \ + loc_core_log.h + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +endif # not BUILD_TINY_ANDROID diff --git a/core/ContextBase.cpp b/core/ContextBase.cpp new file mode 100644 index 00000000..7922cc21 --- /dev/null +++ b/core/ContextBase.cpp @@ -0,0 +1,63 @@ +/* Copyright (c) 2011-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. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_CtxBase" + +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +const char* ContextBase::mIzatLibName = "libloc_api_v02.so "; +// we initialized this handle to 1 because it can't possibly +// 1 if it ever gets assigned a value. NULL on the otherhand +// is possilbe. +void* ContextBase::mIzatLibHandle = (void*)1; + +void* ContextBase::getIzatLibHandle() +{ + if ((void*)1 == mIzatLibHandle) { + mIzatLibHandle = dlopen(mIzatLibName, RTLD_NOW); + } + return mIzatLibHandle; +} + +ContextBase::ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask) : + mMsgTask(msgTask), + mLocApi(LocApiBase::create(mMsgTask, exMask, getIzatLibHandle())) +{ +} + +} diff --git a/core/ContextBase.h b/core/ContextBase.h new file mode 100644 index 00000000..b04def33 --- /dev/null +++ b/core/ContextBase.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2011-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_CONTEXT_BASE__ +#define __LOC_CONTEXT_BASE__ + +#include +#include +#include +#include + +namespace loc_core { + +class LocAdapterBase; + +class ContextBase { + static const char* mIzatLibName; + static void* mIzatLibHandle; +protected: + const MsgTask* mMsgTask; + LocApiBase* mLocApi; + +protected: + ContextBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask); + inline virtual ~ContextBase() { delete mLocApi; } + +public: + static void* getIzatLibHandle(); + inline const MsgTask* getMsgTask() { return mMsgTask; } + inline LocApiBase* getLocApi() { return mLocApi; } +}; + +} // namespace loc_core + +#endif //__LOC_CONTEXT_BASE__ diff --git a/core/LocAdapterBase.cpp b/core/LocAdapterBase.cpp new file mode 100644 index 00000000..27b9f61f --- /dev/null +++ b/core/LocAdapterBase.cpp @@ -0,0 +1,147 @@ +/* Copyright (c) 2011-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. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_LocAdapterBase" + +#include +#include +#include +#include + +namespace loc_core { + +struct LocOpenMsg : public LocMsg { + LocAdapterBase* mLocAdapter; + LocApiBase* mLocApi; + inline LocOpenMsg(LocAdapterBase* locAdapter, + LocApiBase* locApi) : + LocMsg(), mLocAdapter(locAdapter), mLocApi(locApi) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->addAdapter(mLocAdapter); + } + inline void locallog() { + LOC_LOGV("LocOpen"); + } + inline virtual void log() { + locallog(); + } +}; + +// This is the top level class, so the constructor will +// always gets called. Here we prepare for the default. +// 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) : + mEvtMask(mask), mContext(context), + mLocApi(context->getLocApi()), mMsgTask(context->getMsgTask()) +{ + sendMsg(new LocOpenMsg(this, mLocApi)); +} + +// This will be overridden by the individual adapters +// if necessary. +#define DEFAULT_IMPL(rtv) \ +{ \ + LOC_LOGW("%s: default implementation invoked", __func__); \ + return rtv; \ +} + +void LocAdapterBase:: + handleEngineDownEvent() +DEFAULT_IMPL() + +void LocAdapterBase:: + reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) +DEFAULT_IMPL() + +void LocAdapterBase:: + reportSv(GpsSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportStatus(GpsStatusValue status) +DEFAULT_IMPL() + + +void LocAdapterBase:: + reportNmea(const char* nmea, int length) +DEFAULT_IMPL() + +bool LocAdapterBase:: + reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestXtraData() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestTime() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestLocation() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestATL(int connHandle, AGpsType agps_type) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + releaseATL(int connHandle) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestSuplES(int connHandle) +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportDataCallOpened() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + reportDataCallClosed() +DEFAULT_IMPL(false) + +bool LocAdapterBase:: + requestNiNotify(GpsNiNotification ¬ify, const void* data) +DEFAULT_IMPL(false) +} // namespace loc_core diff --git a/core/LocAdapterBase.h b/core/LocAdapterBase.h new file mode 100644 index 00000000..aca70f59 --- /dev/null +++ b/core/LocAdapterBase.h @@ -0,0 +1,97 @@ +/* Copyright (c) 2011-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_API_ADAPTER_BASE_H +#define LOC_API_ADAPTER_BASE_H + +#include +#include + +namespace loc_core { + +class LocAdapterBase { +protected: + const LOC_API_ADAPTER_EVENT_MASK_T mEvtMask; + ContextBase* mContext; + LocApiBase* mLocApi; + const MsgTask* mMsgTask; + + LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, + ContextBase* context); + inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } + +public: + inline LOC_API_ADAPTER_EVENT_MASK_T + checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const { + return mEvtMask & mask; + } + + inline LOC_API_ADAPTER_EVENT_MASK_T getEvtMask() const { + return mEvtMask; + } + + inline void sendMsg(const LocMsg* msg) const { + mMsgTask->sendMsg(msg); + } + + inline void sendMsg(const LocMsg* msg) { + mMsgTask->sendMsg(msg); + } + + // This will be overridden by the individual adapters + // if necessary. + inline virtual void handleEngineUpEvent() {} + virtual void handleEngineDownEvent() ; + virtual void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + virtual void reportSv(GpsSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + virtual void reportStatus(GpsStatusValue status); + virtual void reportNmea(const char* nmea, int length); + virtual bool reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + virtual bool requestXtraData(); + virtual bool requestTime(); + virtual bool requestLocation(); + virtual bool requestATL(int connHandle, AGpsType agps_type); + virtual bool releaseATL(int connHandle); + virtual bool requestSuplES(int connHandle); + virtual bool reportDataCallOpened(); + virtual bool reportDataCallClosed(); + virtual bool requestNiNotify(GpsNiNotification ¬ify, + const void* data); + inline virtual bool isInSession() { return false; } +}; + +} // namespace loc_core + +#endif //LOC_API_ADAPTER_BASE_H diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp new file mode 100644 index 00000000..c6fef931 --- /dev/null +++ b/core/LocApiBase.cpp @@ -0,0 +1,475 @@ +/* Copyright (c) 2011-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. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_LocApiBase" + +#include +#include +#include +#include +#include + +namespace loc_core { + +#define TO_ALL_LOCADAPTERS(call) TO_ALL_ADAPTERS(mLocAdapters, (call)) +#define TO_1ST_HANDLING_LOCADAPTERS(call) TO_1ST_HANDLING_ADAPTER(mLocAdapters, (call)) + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size) +{ + int i; + for (i = 0; i < data_size; i++) + { + char ch = data[i]; + if (i*2 + 3 <= string_size) + { + snprintf(&hexstring[i*2], 3, "%02X", ch); + } + else { + break; + } + } + return i; +} + +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size) +{ + const char addr_prefix = 0x91; + int i, idxOutput = 0; + + if (!data || !addr_string) { return 0; } + + if (data[0] != addr_prefix) + { + LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]); + addr_string[0] = '\0'; + return 0; // prefix not correct + } + + for (i = 1; i < data_size; i++) + { + unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4; + if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; } + if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; } + } + + addr_string[idxOutput] = '\0'; // Terminates the string + + return idxOutput; +} + +struct LocSsrMsg : public LocMsg { + LocApiBase* mLocApi; + inline LocSsrMsg(LocApiBase* locApi) : + LocMsg(), mLocApi(locApi) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->close(); + mLocApi->open(mLocApi->getEvtMask()); + } + inline void locallog() { + LOC_LOGV("LocSsrMsg"); + } + inline virtual void log() { + locallog(); + } +}; + +LocApiBase* LocApiBase::create(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask, + void* libHandle) +{ + LocApiBase* locApi = NULL; + + // first if can not be MPQ + if (TARGET_MPQ != get_target()) { + getLocApi_t* getter = NULL; + // needto check if locaction.so exists + void* handle = ContextBase::getIzatLibHandle(); + + if (NULL == handle || + NULL == (getter = (getLocApi_t*)dlsym(handle, "getLocApi")) || + NULL == (locApi = (*getter)(msgTask, exMask))) { + // only RPC is the option now + handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW); + if (NULL != handle) { + getter = (getLocApi_t*)dlsym(handle, "getLocApi"); + if (NULL != getter) { + locApi = (*getter)(msgTask, exMask); + } + } + } + } + + // locApi could still be NULL at this time + // we would then create a dummy one + if (NULL == locApi) { + locApi = new LocApiBase(msgTask, exMask); + } + + return locApi; +} + +LocApiBase::LocApiBase(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T excludedMask) : + mExcludedMask(excludedMask), mMsgTask(msgTask), mMask(0) +{ + memset(mLocAdapters, 0, sizeof(mLocAdapters)); +} + +LOC_API_ADAPTER_EVENT_MASK_T LocApiBase::getEvtMask() +{ + LOC_API_ADAPTER_EVENT_MASK_T mask = 0; + + TO_ALL_LOCADAPTERS(mask |= mLocAdapters[i]->getEvtMask()); + + return mask & ~mExcludedMask; +} + +bool LocApiBase::isInSession() +{ + bool inSession = false; + + TO_ALL_LOCADAPTERS(inSession = mLocAdapters[i]->isInSession()); + + return inSession; +} + +void LocApiBase::addAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { + if (mLocAdapters[i] == NULL) { + mLocAdapters[i] = adapter; + open(mMask | (adapter->getEvtMask() & ~mExcludedMask)); + break; + } + } +} + +void LocApiBase::removeAdapter(LocAdapterBase* adapter) +{ + for (int i = 0; + i < MAX_ADAPTERS && NULL != mLocAdapters[i]; + i++) { + if (mLocAdapters[i] == adapter) { + mLocAdapters[i] = NULL; + + // shift the rest of the adapters up so that the pointers + // in the array do not have holes. This should be more + // performant, because the array maintenance is much much + // less frequent than event handlings, which need to linear + // search all the adapters + int j = i; + while (++i < MAX_ADAPTERS && mLocAdapters[i] != NULL); + + // i would be MAX_ADAPTERS or point to a NULL + i--; + // i now should point to a none NULL adapter within valid + // range although i could be equal to j, but it won't hurt. + // No need to check it, as it gains nothing. + mLocAdapters[j] = mLocAdapters[i]; + // this makes sure that we exit the for loop + mLocAdapters[i] = NULL; + + // if we have an empty list of adapters + if (0 == i) { + close(); + } else { + // else we need to remove the bit + open(getEvtMask() & ~mExcludedMask); + } + } + } +} + +void LocApiBase::handleEngineUpEvent() +{ + // This will take care of renegotiating the loc handle + mMsgTask->sendMsg(new LocSsrMsg(this)); + + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineUpEvent()); +} + +void LocApiBase::handleEngineDownEvent() +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent()); +} + +void LocApiBase::reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportPosition(location, + locationExtended, + locationExt, + status, + loc_technology_mask) + ); +} + +void LocApiBase::reportSv(GpsSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS( + mLocAdapters[i]->reportSv(svStatus, + locationExtended, + svExt) + ); +} + +void LocApiBase::reportStatus(GpsStatusValue status) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status)); +} + +void LocApiBase::reportNmea(const char* nmea, int length) +{ + // loop through adapters, and deliver to all adapters. + TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmea(nmea, length)); +} + +void LocApiBase::reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportXtraServer(url1, url2, url3, maxlength)); + +} + +void LocApiBase::requestXtraData() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestXtraData()); +} + +void LocApiBase::requestTime() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestTime()); +} + +void LocApiBase::requestLocation() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation()); +} + +void LocApiBase::requestATL(int connHandle, AGpsType agps_type) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestATL(connHandle, agps_type)); +} + +void LocApiBase::releaseATL(int connHandle) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->releaseATL(connHandle)); +} + +void LocApiBase::requestSuplES(int connHandle) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestSuplES(connHandle)); +} + +void LocApiBase::reportDataCallOpened() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallOpened()); +} + +void LocApiBase::reportDataCallClosed() +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallClosed()); +} + +void LocApiBase::requestNiNotify(GpsNiNotification ¬ify, const void* data) +{ + // loop through adapters, and deliver to the first handling adapter. + TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotify(notify, data)); +} + + +// downward calls +// All below functions are to be defined by adapter specific modules: +// RPC, QMI, etc. The default implementation is empty. +#define DEFAULT_IMPL(rtv) \ +{ \ + LOC_LOGW("%s: default implementation invoked", __func__); \ + return rtv; \ +} + +enum loc_api_adapter_err LocApiBase:: + open(LOC_API_ADAPTER_EVENT_MASK_T mask) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + close() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + startFix(const LocPosMode& posMode) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + stopFix() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + deleteAidingData(GpsAidingData f) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + enableData(int enable) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setAPN(char* apn, int len) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + injectPosition(double latitude, double longitude, float accuracy) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setTime(GpsUtcTime time, int64_t timeReference, int uncertainty) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setXtraData(char* data, int length) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + requestXtraServer() +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + atlOpenStatus(int handle, int is_succ, char* apn, + AGpsBearerType bear, AGpsType agpsType) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + atlCloseStatus(int handle, int is_succ) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setPositionMode(const LocPosMode& posMode) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setServer(const char* url, int len) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setServer(unsigned int ip, int port, + LocServerType type) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + informNiResponse(GpsUserResponseType userResponse, + const void* passThroughData) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSUPLVersion(uint32_t version) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setLPPConfig(uint32_t profile) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorControlConfig(int sensorUsage) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, + float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, + float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, + float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, + float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, + float velocityBiasVarianceRandomWalk) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setSensorPerfControlConfig(int controlMode, + int accelSamplesPerBatch, + int accelBatchesPerSec, + int gyroSamplesPerBatch, + int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, + int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, + int gyroBatchesPerSecHigh, + int algorithmConfig) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setExtPowerConfig(int isBatteryCharging) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +enum loc_api_adapter_err LocApiBase:: + setAGLONASSProtocol(unsigned long aGlonassProtocol) +DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS) + +int LocApiBase:: + initDataServiceClient() +DEFAULT_IMPL(-1) + +int LocApiBase:: + openAndStartDataCall() +DEFAULT_IMPL(-1) + +void LocApiBase:: + stopDataCall() +DEFAULT_IMPL() + +void LocApiBase:: + closeDataCall() +DEFAULT_IMPL() + + +} // namespace loc_core diff --git a/core/LocApiBase.h b/core/LocApiBase.h new file mode 100644 index 00000000..c027b3f8 --- /dev/null +++ b/core/LocApiBase.h @@ -0,0 +1,254 @@ +/* Copyright (c) 2011-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_API_BASE_H +#define LOC_API_BASE_H + +#include +#include +#include +#include + +#define smaller_of(a, b) (((a) > (b)) ? (b) : (a)) +#define MAX_APN_LEN 100 + +namespace loc_core { + +int hexcode(char *hexstring, int string_size, + const char *data, int data_size); +int decodeAddress(char *addr_string, int string_size, + const char *data, int data_size); + +enum loc_api_adapter_err { + LOC_API_ADAPTER_ERR_SUCCESS = 0, + LOC_API_ADAPTER_ERR_GENERAL_FAILURE = 1, + LOC_API_ADAPTER_ERR_UNSUPPORTED = 2, + LOC_API_ADAPTER_ERR_INVALID_HANDLE = 4, + LOC_API_ADAPTER_ERR_INVALID_PARAMETER = 5, + LOC_API_ADAPTER_ERR_ENGINE_BUSY = 6, + LOC_API_ADAPTER_ERR_PHONE_OFFLINE = 7, + LOC_API_ADAPTER_ERR_TIMEOUT = 8, + LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9, + + LOC_API_ADAPTER_ERR_ENGINE_DOWN = 100, + LOC_API_ADAPTER_ERR_FAILURE, + LOC_API_ADAPTER_ERR_UNKNOWN +}; + +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_EVENT_MAX +}; + +#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1< +#include +#include +#include +#include +#include + +namespace loc_core { + +// nothing exclude for foreground +const LOC_API_ADAPTER_EVENT_MASK_T +LocDualContext::mFgExclMask = 0; +// excluded events for background clients +const LOC_API_ADAPTER_EVENT_MASK_T +LocDualContext::mBgExclMask = + (LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | + LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_GEOFENCE_GEN_ALERT); + +const MsgTask* LocDualContext::mMsgTask = NULL; +ContextBase* LocDualContext::mFgContext = NULL; +ContextBase* LocDualContext::mBgContext = NULL; + +char LocDualContext::mHasAgpsExt = 0xff; + +// the name must be shorter than 15 chars +const char* LocDualContext::mLocationHalName = "Loc_hal_worker"; + +const MsgTask* LocDualContext::getMsgTask(MsgTask::tCreate tCreator, + const char* name) +{ + if (NULL == mMsgTask) { + mMsgTask = new MsgTask(tCreator, name); + } + return mMsgTask; +} + +ContextBase* LocDualContext::getLocFgContext(MsgTask::tCreate tCreator, + const char* name) +{ + if (NULL == mFgContext) { + const MsgTask* msgTask = getMsgTask(tCreator, name); + mFgContext = new LocDualContext(msgTask, + mFgExclMask); + } + return mFgContext; +} + +ContextBase* LocDualContext::getLocBgContext(MsgTask::tCreate tCreator, + const char* name) +{ + if (NULL == mBgContext) { + const MsgTask* msgTask = getMsgTask(tCreator, name); + mBgContext = new LocDualContext(msgTask, + mBgExclMask); + } + return mBgContext; +} + +bool LocDualContext::hasAgpsExt() +{ + if (0xff == mHasAgpsExt) { + mHasAgpsExt = 0; + void* handle = ContextBase::getIzatLibHandle(); + if (NULL != handle) { + bool(*getter)() = (bool(*)())dlsym(handle, "hasAgpsExt"); + if (NULL != getter && (*getter)()) { + mHasAgpsExt = 1; + } + } + } + + return mHasAgpsExt == 1; +} + +LocDualContext::LocDualContext(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask) : + ContextBase(msgTask, exMask) +{ +} + +} diff --git a/core/LocDualContext.h b/core/LocDualContext.h new file mode 100644 index 00000000..4e03bf44 --- /dev/null +++ b/core/LocDualContext.h @@ -0,0 +1,68 @@ +/* Copyright (c) 2011-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_ENG_CONTEXT__ +#define __LOC_ENG_CONTEXT__ + +#include +#include +#include +#include + +namespace loc_core { + +class LocDualContext : public ContextBase { + static const MsgTask* mMsgTask; + static ContextBase* mFgContext; + static ContextBase* mBgContext; + static char mHasAgpsExt; + + static const MsgTask* getMsgTask(MsgTask::tCreate tCreator, + const char* name); + +protected: + LocDualContext(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask); + inline virtual ~LocDualContext() {} + +public: + static const LOC_API_ADAPTER_EVENT_MASK_T mFgExclMask; + static const LOC_API_ADAPTER_EVENT_MASK_T mBgExclMask; + static const char* mLocationHalName; + + static ContextBase* getLocFgContext(MsgTask::tCreate tCreator, + const char* name); + static ContextBase* getLocBgContext(MsgTask::tCreate tCreator, + const char* name); + + static bool hasAgpsExt(); +}; + +} + +#endif //__LOC_ENG_CONTEXT__ diff --git a/core/MsgTask.cpp b/core/MsgTask.cpp new file mode 100644 index 00000000..37813394 --- /dev/null +++ b/core/MsgTask.cpp @@ -0,0 +1,133 @@ +/* Copyright (c) 2011-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. + * + */ +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_MsgTask" + +#include +#include +#include +#include +#include +#include +#include + +namespace loc_core { + +#define MAX_TASK_COMM_LEN 15 + +static void LocMsgDestroy(void* msg) { + delete (LocMsg*)msg; +} + +MsgTask::MsgTask(tCreate tCreator, const char* threadName) : + mQ(msg_q_init2()), mAssociator(NULL){ + if (tCreator) { + tCreator(threadName, loopMain, + (void*)new MsgTask(mQ, mAssociator)); + } else { + createPThread(threadName); + } +} + +MsgTask::MsgTask(tAssociate tAssociator, const char* threadName) : + mQ(msg_q_init2()), mAssociator(tAssociator){ + createPThread(threadName); +} + +inline +MsgTask::MsgTask(const void* q, tAssociate associator) : + mQ(q), mAssociator(associator){ +} + +MsgTask::~MsgTask() { + msg_q_unblock((void*)mQ); +} + +void MsgTask::createPThread(const char* threadName) { + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + pthread_t tid; + // create the thread here, then if successful + // and a name is given, we set the thread name + if (!pthread_create(&tid, &attr, loopMain, + (void*)new MsgTask(mQ, mAssociator)) && + NULL != threadName) { + char lname[MAX_TASK_COMM_LEN+1]; + memcpy(lname, threadName, MAX_TASK_COMM_LEN); + lname[MAX_TASK_COMM_LEN] = 0; + pthread_setname_np(tid, lname); + } +} + +void MsgTask::sendMsg(const LocMsg* msg) const { + msg_q_snd((void*)mQ, (void*)msg, LocMsgDestroy); +} + +void* MsgTask::loopMain(void* arg) { + MsgTask* copy = (MsgTask*)arg; + + // make sure we do not run in background scheduling group + set_sched_policy(gettid(), SP_FOREGROUND); + + if (NULL != copy->mAssociator) { + copy->mAssociator(); + } + + LocMsg* msg; + int cnt = 0; + + while (1) { + LOC_LOGD("MsgTask::loop() %d listening ...\n", cnt++); + + msq_q_err_type result = msg_q_rcv((void*)copy->mQ, (void **)&msg); + + if (eMSG_Q_SUCCESS != result) { + LOC_LOGE("%s:%d] fail receiving msg: %s\n", __func__, __LINE__, + loc_get_msg_q_status(result)); + // destroy the Q and exit + msg_q_destroy((void**)&(copy->mQ)); + delete copy; + return NULL; + } + + msg->log(); + // there is where each individual msg handling is invoked + msg->proc(); + + delete msg; + } + + delete copy; + + return NULL; +} + +} diff --git a/core/MsgTask.h b/core/MsgTask.h new file mode 100644 index 00000000..d09de731 --- /dev/null +++ b/core/MsgTask.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2011-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 __MSG_TASK__ +#define __MSG_TASK__ + +#include +#include +#include +#include + +namespace loc_core { + +struct LocMsg { + inline LocMsg() {} + inline virtual ~LocMsg() {} + virtual void proc() const = 0; + inline virtual void log() const {} +}; + +class MsgTask { +public: + typedef void* (*tStart)(void*); + typedef pthread_t (*tCreate)(const char* name, tStart start, void* arg); + typedef int (*tAssociate)(); + MsgTask(tCreate tCreator, const char* threadName); + MsgTask(tAssociate tAssociator, const char* threadName); + ~MsgTask(); + void sendMsg(const LocMsg* msg) const; + +private: + const void* mQ; + tAssociate mAssociator; + MsgTask(const void* q, tAssociate associator); + static void* loopMain(void* copy); + void createPThread(const char* name); +}; + +} // namespace loc_core + +#endif //__MSG_TASK__ diff --git a/core/gps_extended.h b/core/gps_extended.h new file mode 100644 index 00000000..88b0415b --- /dev/null +++ b/core/gps_extended.h @@ -0,0 +1,92 @@ +/* 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 GPS_EXTENDED_H +#define GPS_EXTENDED_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include + +struct LocPosMode +{ + LocPositionMode mode; + GpsPositionRecurrence recurrence; + uint32_t min_interval; + uint32_t preferred_accuracy; + uint32_t preferred_time; + char credentials[14]; + char provider[8]; + LocPosMode(LocPositionMode m, GpsPositionRecurrence recr, + uint32_t gap, uint32_t accu, uint32_t time, + const char* cred, const char* prov) : + mode(m), recurrence(recr), + min_interval(gap < MIN_POSSIBLE_FIX_INTERVAL ? MIN_POSSIBLE_FIX_INTERVAL : gap), + preferred_accuracy(accu), preferred_time(time) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + if (NULL != cred) { + memcpy(credentials, cred, sizeof(credentials)-1); + } + if (NULL != prov) { + memcpy(provider, prov, sizeof(provider)-1); + } + } + + inline LocPosMode() : + mode(LOC_POSITION_MODE_MS_BASED), + recurrence(GPS_POSITION_RECURRENCE_PERIODIC), + min_interval(MIN_POSSIBLE_FIX_INTERVAL), + preferred_accuracy(50), preferred_time(120000) { + memset(credentials, 0, sizeof(credentials)); + memset(provider, 0, sizeof(provider)); + } + + inline bool equals(const LocPosMode &anotherMode) const + { + return anotherMode.mode == mode && + anotherMode.recurrence == recurrence && + anotherMode.min_interval == min_interval && + anotherMode.preferred_accuracy == preferred_accuracy && + anotherMode.preferred_time == preferred_time && + !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) && + !strncmp(anotherMode.provider, provider, sizeof(provider)-1); + } + + void logv() const; +}; + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GPS_EXTENDED_H */ + diff --git a/core/gps_extended_c.h b/core/gps_extended_c.h new file mode 100644 index 00000000..640668ff --- /dev/null +++ b/core/gps_extended_c.h @@ -0,0 +1,256 @@ +/* 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 GPS_EXTENDED_C_H +#define GPS_EXTENDED_C_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#include +#include +#include + +/** Location has valid source information. */ +#define LOCATION_HAS_SOURCE_INFO 0x0020 +/** GpsLocation has valid "is indoor?" flag */ +#define GPS_LOCATION_HAS_IS_INDOOR 0x0040 +/** GpsLocation has valid floor number */ +#define GPS_LOCATION_HAS_FLOOR_NUMBER 0x0080 +/** GpsLocation has valid map URL*/ +#define GPS_LOCATION_HAS_MAP_URL 0x0100 +/** GpsLocation has valid map index */ +#define GPS_LOCATION_HAS_MAP_INDEX 0x0200 + +/** Sizes for indoor fields */ +#define GPS_LOCATION_MAP_URL_SIZE 400 +#define GPS_LOCATION_MAP_INDEX_SIZE 16 + +/** Position source is ULP */ +#define ULP_LOCATION_IS_FROM_HYBRID 0x0001 +/** Position source is GNSS only */ +#define ULP_LOCATION_IS_FROM_GNSS 0x0002 + +#define ULP_MIN_INTERVAL_INVALID 0xffffffff + + +typedef struct { + /** set to sizeof(UlpLocation) */ + size_t size; + GpsLocation gpsLocation; + /* Provider indicator for HYBRID or GPS */ + uint16_t position_source; + /*allows HAL to pass additional information related to the location */ + int rawDataSize; /* in # of bytes */ + void * rawData; + bool is_indoor; + float floor_number; + char map_url[GPS_LOCATION_MAP_URL_SIZE]; + unsigned char map_index[GPS_LOCATION_MAP_INDEX_SIZE]; +} UlpLocation; + +/** AGPS type */ +typedef int16_t AGpsExtType; +#define AGPS_TYPE_INVALID -1 +#define AGPS_TYPE_ANY 0 +#define AGPS_TYPE_SUPL 1 +#define AGPS_TYPE_C2K 2 +#define AGPS_TYPE_WWAN_ANY 3 +#define AGPS_TYPE_WIFI 4 +#define AGPS_TYPE_SUPL_ES 5 + +/** SSID length */ +#define SSID_BUF_SIZE (32+1) + +typedef int16_t AGpsBearerType; +#define AGPS_APN_BEARER_INVALID -1 +#define AGPS_APN_BEARER_IPV4 0 +#define AGPS_APN_BEARER_IPV6 1 +#define AGPS_APN_BEARER_IPV4V6 2 + +#define GPS_DELETE_ALMANAC_CORR 0x00001000 +#define GPS_DELETE_FREQ_BIAS_EST 0x00002000 +#define GPS_DELETE_EPHEMERIS_GLO 0x00004000 +#define GPS_DELETE_ALMANAC_GLO 0x00008000 +#define GPS_DELETE_SVDIR_GLO 0x00010000 +#define GPS_DELETE_SVSTEER_GLO 0x00020000 +#define GPS_DELETE_ALMANAC_CORR_GLO 0x00040000 +#define GPS_DELETE_TIME_GPS 0x00080000 +#define GPS_DELETE_TIME_GLO 0x00100000 + +/** GPS extended callback structure. */ +typedef struct { + /** set to sizeof(GpsCallbacks) */ + size_t size; + gps_set_capabilities set_capabilities_cb; + gps_acquire_wakelock acquire_wakelock_cb; + gps_release_wakelock release_wakelock_cb; + gps_create_thread create_thread_cb; + gps_request_utc_time request_utc_time_cb; +} GpsExtCallbacks; + +/** Callback to report the xtra server url to the client. + * The client should use this url when downloading xtra unless overwritten + * in the gps.conf file + */ +typedef void (* report_xtra_server)(const char*, const char*, const char*); + +/** Callback structure for the XTRA interface. */ +typedef struct { + gps_xtra_download_request download_request_cb; + gps_create_thread create_thread_cb; + report_xtra_server report_xtra_server_cb; +} GpsXtraExtCallbacks; + +/** Represents the status of AGPS. */ +typedef struct { + /** set to sizeof(AGpsExtStatus) */ + size_t size; + + AGpsExtType type; + AGpsStatusValue status; + uint32_t ipv4_addr; + char ipv6_addr[16]; + char ssid[SSID_BUF_SIZE]; + char password[SSID_BUF_SIZE]; +} AGpsExtStatus; + +/** Callback with AGPS status information. + * Can only be called from a thread created by create_thread_cb. + */ +typedef void (* agps_status_extended)(AGpsExtStatus* status); + +/** Callback structure for the AGPS interface. */ +typedef struct { + agps_status_extended status_cb; + gps_create_thread create_thread_cb; +} AGpsExtCallbacks; + + +/** GPS NI callback structure. */ +typedef struct +{ + /** + * Sends the notification request from HAL to GPSLocationProvider. + */ + gps_ni_notify_callback notify_cb; + gps_create_thread create_thread_cb; +} GpsNiExtCallbacks; + +typedef enum loc_server_type { + LOC_AGPS_CDMA_PDE_SERVER, + LOC_AGPS_CUSTOM_PDE_SERVER, + LOC_AGPS_MPC_SERVER, + LOC_AGPS_SUPL_SERVER +} LocServerType; + +typedef enum loc_position_mode_type { + LOC_POSITION_MODE_STANDALONE, + LOC_POSITION_MODE_MS_BASED, + LOC_POSITION_MODE_MS_ASSISTED, + LOC_POSITION_MODE_RESERVED_1, + LOC_POSITION_MODE_RESERVED_2, + LOC_POSITION_MODE_RESERVED_3, + LOC_POSITION_MODE_RESERVED_4, + LOC_POSITION_MODE_RESERVED_5 +} LocPositionMode; + +#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */ + +/** Flags to indicate which values are valid in a GpsLocationExtended. */ +typedef uint16_t GpsLocationExtendedFlags; +/** GpsLocationExtended has valid pdop, hdop, vdop. */ +#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001 +/** GpsLocationExtended has valid altitude mean sea level. */ +#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002 +/** UlpLocation has valid magnetic deviation. */ +#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004 +/** UlpLocation has valid mode indicator. */ +#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008 +/** GpsLocationExtended has valid vertical uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010 +/** GpsLocationExtended has valid speed uncertainty */ +#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020 + +/** Represents gps location extended. */ +typedef struct { + /** set to sizeof(GpsLocationExtended) */ + size_t size; + /** Contains GpsLocationExtendedFlags bits. */ + uint16_t flags; + /** Contains the Altitude wrt mean sea level */ + float altitudeMeanSeaLevel; + /** Contains Position Dilusion of Precision. */ + float pdop; + /** Contains Horizontal Dilusion of Precision. */ + float hdop; + /** Contains Vertical Dilusion of Precision. */ + float vdop; + /** Contains Magnetic Deviation. */ + float magneticDeviation; + /** vertical uncertainty in meters */ + float vert_unc; + /** speed uncertainty in m/s */ + float speed_unc; +} GpsLocationExtended; + +enum loc_sess_status { + LOC_SESS_SUCCESS, + LOC_SESS_INTERMEDIATE, + LOC_SESS_FAILURE +}; + +typedef uint32_t LocPosTechMask; +#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000) +#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001) +#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002) +#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004) +#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008) +#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010) +#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020) +#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040) +#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080) + +typedef enum { + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, + LOC_ENG_IF_REQUEST_SENDER_ID_MODEM, + LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN +} loc_if_req_sender_id_e_type; + + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* GPS_EXTENDED_C_H */ + diff --git a/core/loc_core_log.cpp b/core/loc_core_log.cpp new file mode 100644 index 00000000..f67dfe0b --- /dev/null +++ b/core/loc_core_log.cpp @@ -0,0 +1,250 @@ +/* Copyright (c) 2011-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. + * + */ + +#define LOG_NDDEBUG 0 +#define LOG_TAG "LocSvc_core_log" + +#include +#include +#include + +void LocPosMode::logv() const +{ + LOC_LOGV ("Position mode: %s\n Position recurrence: %s\n " + "min interval: %d\n preferred accuracy: %d\n " + "preferred time: %d\n credentials: %s provider: %s", + loc_get_position_mode_name(mode), + loc_get_position_recurrence_name(recurrence), + min_interval, + preferred_accuracy, + preferred_time, + credentials, + provider); +} + +/* GPS status names */ +static loc_name_val_s_type gps_status_name[] = +{ + NAME_VAL( GPS_STATUS_NONE ), + NAME_VAL( GPS_STATUS_SESSION_BEGIN ), + NAME_VAL( GPS_STATUS_SESSION_END ), + NAME_VAL( GPS_STATUS_ENGINE_ON ), + NAME_VAL( GPS_STATUS_ENGINE_OFF ), +}; +static int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type); + +/* Find Android GPS status name */ +const char* loc_get_gps_status_name(GpsStatusValue gps_status) +{ + return loc_get_name_from_val(gps_status_name, gps_status_num, + (long) gps_status); +} + + + +static loc_name_val_s_type loc_eng_position_modes[] = +{ + NAME_VAL( LOC_POSITION_MODE_STANDALONE ), + NAME_VAL( LOC_POSITION_MODE_MS_BASED ), + NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ), + NAME_VAL( LOC_POSITION_MODE_RESERVED_5 ) +}; +static int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_mode_name(GpsPositionMode mode) +{ + return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode); +} + + + +static loc_name_val_s_type loc_eng_position_recurrences[] = +{ + NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ), + NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE ) +}; +static int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur) +{ + return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur); +} + + + +static loc_name_val_s_type loc_eng_aiding_data_bits[] = +{ + NAME_VAL( GPS_DELETE_EPHEMERIS ), + NAME_VAL( GPS_DELETE_ALMANAC ), + NAME_VAL( GPS_DELETE_POSITION ), + NAME_VAL( GPS_DELETE_TIME ), + NAME_VAL( GPS_DELETE_IONO ), + NAME_VAL( GPS_DELETE_UTC ), + NAME_VAL( GPS_DELETE_HEALTH ), + NAME_VAL( GPS_DELETE_SVDIR ), + NAME_VAL( GPS_DELETE_SVSTEER ), + NAME_VAL( GPS_DELETE_SADATA ), + NAME_VAL( GPS_DELETE_RTI ), + NAME_VAL( GPS_DELETE_CELLDB_INFO ), + NAME_VAL( GPS_DELETE_ALMANAC_CORR ), + NAME_VAL( GPS_DELETE_FREQ_BIAS_EST ), + NAME_VAL( GPS_DELETE_EPHEMERIS_GLO ), + NAME_VAL( GPS_DELETE_ALMANAC_GLO ), + NAME_VAL( GPS_DELETE_SVDIR_GLO ), + NAME_VAL( GPS_DELETE_SVSTEER_GLO ), + NAME_VAL( GPS_DELETE_ALMANAC_CORR_GLO ), + NAME_VAL( GPS_DELETE_TIME_GPS ), + NAME_VAL( GPS_DELETE_TIME_GLO ) +}; +static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type); + +const char* loc_get_aiding_data_mask_names(GpsAidingData data) +{ + return NULL; +} + + +static loc_name_val_s_type loc_eng_agps_types[] = +{ + NAME_VAL( AGPS_TYPE_INVALID ), + NAME_VAL( AGPS_TYPE_ANY ), + NAME_VAL( AGPS_TYPE_SUPL ), + NAME_VAL( AGPS_TYPE_C2K ), + NAME_VAL( AGPS_TYPE_WWAN_ANY ) +}; +static int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_type_name(AGpsType type) +{ + return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type); +} + + +static loc_name_val_s_type loc_eng_ni_types[] = +{ + NAME_VAL( GPS_NI_TYPE_VOICE ), + NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ), + NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ) +}; +static int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_type_name(GpsNiType type) +{ + return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type); +} + + +static loc_name_val_s_type loc_eng_ni_responses[] = +{ + NAME_VAL( GPS_NI_RESPONSE_ACCEPT ), + NAME_VAL( GPS_NI_RESPONSE_DENY ), + NAME_VAL( GPS_NI_RESPONSE_DENY ) +}; +static int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_response_name(GpsUserResponseType response) +{ + return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response); +} + + +static loc_name_val_s_type loc_eng_ni_encodings[] = +{ + NAME_VAL( GPS_ENC_NONE ), + NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ), + NAME_VAL( GPS_ENC_SUPL_UTF8 ), + NAME_VAL( GPS_ENC_SUPL_UCS2 ), + NAME_VAL( GPS_ENC_UNKNOWN ) +}; +static int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type); + +const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding) +{ + return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding); +} + +static loc_name_val_s_type loc_eng_agps_bears[] = +{ + NAME_VAL( AGPS_APN_BEARER_INVALID ), + NAME_VAL( AGPS_APN_BEARER_IPV4 ), + NAME_VAL( AGPS_APN_BEARER_IPV4 ), + NAME_VAL( AGPS_APN_BEARER_IPV4V6 ) +}; +static int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_bear_name(AGpsBearerType bearer) +{ + return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer); +} + +static loc_name_val_s_type loc_eng_server_types[] = +{ + NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ), + NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ), + NAME_VAL( LOC_AGPS_MPC_SERVER ), + NAME_VAL( LOC_AGPS_SUPL_SERVER ) +}; +static int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_server_type_name(LocServerType type) +{ + return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type); +} + +static loc_name_val_s_type loc_eng_position_sess_status_types[] = +{ + NAME_VAL( LOC_SESS_SUCCESS ), + NAME_VAL( LOC_SESS_INTERMEDIATE ), + NAME_VAL( LOC_SESS_FAILURE ) +}; +static int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type); + +const char* loc_get_position_sess_status_name(enum loc_sess_status status) +{ + return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status); +} + +static loc_name_val_s_type loc_eng_agps_status_names[] = +{ + NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ), + NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ), + NAME_VAL( GPS_AGPS_DATA_CONNECTED ), + NAME_VAL( GPS_AGPS_DATA_CONN_DONE ), + NAME_VAL( GPS_AGPS_DATA_CONN_FAILED ) +}; +static int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type); + +const char* loc_get_agps_status_name(AGpsStatusValue status) +{ + return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status); +} diff --git a/loc_api/libloc_api_50001/loc_ulp.h b/core/loc_core_log.h similarity index 50% rename from loc_api/libloc_api_50001/loc_ulp.h rename to core/loc_core_log.h index f4b1d0ed..8a1825ac 100644 --- a/loc_api/libloc_api_50001/loc_ulp.h +++ b/core/loc_core_log.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, The Linux Foundation. All rights reserved. +/* Copyright (c) 2011-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 @@ -27,58 +27,32 @@ * */ -#ifndef __LOC_ULP_H__ -#define __LOC_ULP_H__ +#ifndef LOC_CORE_LOG_H +#define LOC_CORE_LOG_H #ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ +extern "C" +{ +#endif #include -#include -#include - -/** Location has valid source information. */ -#define LOCATION_HAS_SOURCE_INFO 0x0020 -/** GpsLocation has valid "is indoor?" flag */ -#define GPS_LOCATION_HAS_IS_INDOOR 0x0040 -/** GpsLocation has valid floor number */ -#define GPS_LOCATION_HAS_FLOOR_NUMBER 0x0080 -/** GpsLocation has valid map URL*/ -#define GPS_LOCATION_HAS_MAP_URL 0x0100 -/** GpsLocation has valid map index */ -#define GPS_LOCATION_HAS_MAP_INDEX 0x0200 - -/** Sizes for indoor fields */ -#define GPS_LOCATION_MAP_URL_SIZE 400 -#define GPS_LOCATION_MAP_INDEX_SIZE 16 - -/** Position source is ULP */ -#define ULP_LOCATION_IS_FROM_HYBRID 0x0001 -/** Position source is GNSS only */ -#define ULP_LOCATION_IS_FROM_GNSS 0x0002 - -#define ULP_MIN_INTERVAL_INVALID 0xffffffff - - -typedef struct { - /** set to sizeof(UlpLocation) */ - size_t size; - GpsLocation gpsLocation; - /* Provider indicator for HYBRID or GPS */ - uint16_t position_source; - /*allows HAL to pass additional information related to the location */ - int rawDataSize; /* in # of bytes */ - void * rawData; - bool is_indoor; - float floor_number; - char map_url[GPS_LOCATION_MAP_URL_SIZE]; - unsigned char map_index[GPS_LOCATION_MAP_INDEX_SIZE]; -} UlpLocation; +#include +const char* loc_get_gps_status_name(GpsStatusValue gps_status); +const char* loc_get_position_mode_name(GpsPositionMode mode); +const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur); +const char* loc_get_aiding_data_mask_names(GpsAidingData data); +const char* loc_get_agps_type_name(AGpsType type); +const char* loc_get_ni_type_name(GpsNiType type); +const char* loc_get_ni_response_name(GpsUserResponseType response); +const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding); +const char* loc_get_agps_bear_name(AGpsBearerType bear); +const char* loc_get_server_type_name(LocServerType type); +const char* loc_get_position_sess_status_name(enum loc_sess_status status); +const char* loc_get_agps_status_name(AGpsStatusValue status); #ifdef __cplusplus } -#endif /* __cplusplus */ +#endif -#endif //__LOC_ULP_H__ +#endif /* LOC_CORE_LOG_H */ diff --git a/loc_api/Android.mk b/loc_api/Android.mk index c87df1f9..743b3860 100644 --- a/loc_api/Android.mk +++ b/loc_api/Android.mk @@ -6,8 +6,6 @@ LOCAL_PATH := $(call my-dir) ifneq ($(TARGET_NO_RPC),true) GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api-rpc-50001/ -GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api-rpc/ -GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api/ endif #TARGET_NO_RPC diff --git a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk index c7a245b8..bb3d924b 100644 --- a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk +++ b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/Android.mk @@ -9,7 +9,7 @@ source_files:= \ src/loc_apicb_appinit.c \ src/loc_api_fixup.c \ src/loc_api_log.c \ - src/LocApiRpcAdapter.cpp + src/LocApiRpc.cpp LOCAL_SRC_FILES:= $(source_files) @@ -26,7 +26,7 @@ LOCAL_SHARED_LIBRARIES:= \ libcutils \ libcommondefs \ libgps.utils \ - libloc_adapter + libloc_core LOCAL_STATIC_LIBRARIES := \ libloc_api_rpcgen @@ -37,20 +37,20 @@ LOCAL_C_INCLUDES:= \ $(LOCAL_PATH) \ $(LOCAL_PATH)/rpc_inc \ $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libloc_core \ $(TARGET_OUT_HEADERS)/loc_api/rpcgen/inc \ - $(TARGET_OUT_HEADERS)/libcommondefs-rpc \ $(TARGET_OUT_HEADERS)/libcommondefs/rpcgen/inc \ $(TARGET_OUT_HEADERS)/librpc \ $(TARGET_OUT_HEADERS)/libloc-rpc/rpc_inc \ - $(TARGET_OUT_HEADERS)/libloc_eng \ - hardware/msm7k/librpc + $(TOP)/hardware/msm7k/librpc LOCAL_COPY_HEADERS_TO:= libloc_api-rpc-qc/$(RPC_INC) LOCAL_COPY_HEADERS:= \ $(RPC_INC)/loc_api_rpc_glue.h \ $(RPC_INC)/loc_api_fixup.h \ $(RPC_INC)/loc_api_sync_call.h \ - $(RPC_INC)/loc_apicb_appinit.h + $(RPC_INC)/loc_apicb_appinit.h \ + $(RPC_INC)/LocApiRpc.h LOCAL_MODULE:= libloc_api-rpc-qc LOCAL_MODULE_OWNER := qcom diff --git a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpcAdapter.h b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h similarity index 84% rename from loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpcAdapter.h rename to loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h index 32ea6e7f..fef42199 100644 --- a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpcAdapter.h +++ b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/rpc_inc/LocApiRpc.h @@ -26,24 +26,30 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ -#ifndef LOC_API_RPC_ADAPTER_H -#define LOC_API_RPC_ADAPTER_H +#ifndef LOC_API_RPC_H +#define LOC_API_RPC_H #include +#include #include -#include +#include +#include +using namespace loc_core; -class LocApiRpcAdapter : public LocApiAdapter { +class LocApiRpc : public LocApiBase { // RPC communication establishment rpc_loc_client_handle_type client_handle; - rpc_loc_event_mask_type eMask; int dataEnableLastSet; char apnLastSet[MAX_APN_LEN]; + static const LOC_API_ADAPTER_EVENT_MASK_T maskAll; static const rpc_loc_event_mask_type locBits[]; static rpc_loc_event_mask_type convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask); static enum loc_api_adapter_err convertErr(int rpcErr); + static GpsNiEncodingType convertNiEncodingType(int loc_encoding); + static int NIEventFillVerfiyType(GpsNiNotification ¬if, + rpc_loc_ni_notify_verify_e_type notif_priv); void reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr); void reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr); @@ -51,13 +57,16 @@ class LocApiRpcAdapter : public LocApiAdapter { void reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr); void ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr); void NIEvent(const rpc_loc_ni_event_s_type *ni_req_ptr); - int NIEventFillVerfiyType(GpsNiNotification ¬if, - rpc_loc_ni_notify_verify_e_type notif_priv); - GpsNiEncodingType convertNiEncodingType(int loc_encoding); + + virtual enum loc_api_adapter_err + open(LOC_API_ADAPTER_EVENT_MASK_T mask); + virtual enum loc_api_adapter_err + close(); public: - LocApiRpcAdapter(LocEng &locEng); - ~LocApiRpcAdapter(); + LocApiRpc(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask); + ~LocApiRpc(); int locEventCB(rpc_loc_client_handle_type client_handle, rpc_loc_event_mask_type loc_event, @@ -67,13 +76,11 @@ public: // RPC adapter interface implementations virtual enum loc_api_adapter_err - reinit(); - virtual enum loc_api_adapter_err - startFix(); + startFix(const LocPosMode& posMode); virtual enum loc_api_adapter_err stopFix(); virtual enum loc_api_adapter_err - setPositionMode(const LocPosMode *mode); + setPositionMode(const LocPosMode& mode); inline virtual enum loc_api_adapter_err enableData(int enable) { return enableData(enable, false); } virtual enum loc_api_adapter_err @@ -108,4 +115,7 @@ public: virtual void setInSession(bool inSession); }; -#endif //LOC_API_RPC_ADAPTER_H +extern "C" LocApiBase* getLocApi(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask); + +#endif //LOC_API_RPC_H diff --git a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpcAdapter.cpp b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp similarity index 85% rename from loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpcAdapter.cpp rename to loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp index e836f103..879244da 100644 --- a/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpcAdapter.cpp +++ b/loc_api/libloc_api-rpc-50001/libloc_api-rpc-glue/src/LocApiRpc.cpp @@ -27,24 +27,27 @@ * */ #define LOG_NDDEBUG 0 -#define LOG_TAG "LocSvc_adapter" +#define LOG_TAG "LocSvc_api_rpc" #include #include #ifndef USE_GLIB #include #endif /* USE_GLIB */ -#include "LocApiRpcAdapter.h" -#include "loc_api_rpcgen_common_rpc.h" -#include "log_util.h" -#include "loc_log.h" -#include "loc_api_log.h" +#include +#include +#include +#include +#include +#include +#include #ifdef USE_GLIB #include #endif -#include "librpc.h" -#include "platform_lib_includes.h" +#include +#include +using namespace loc_core; #define LOC_XTRA_INJECT_DEFAULT_TIMEOUT (3100) #define XTRA_BLOCK_SIZE (3072) @@ -77,7 +80,7 @@ static int32 loc_event_cb { MODEM_LOG_CALLFLOW(%s, loc_get_event_name(loc_event)); loc_callback_log(loc_event, loc_event_payload); - int32 ret_val = ((LocApiRpcAdapter*)user)->locEventCB(client_handle, loc_event, loc_event_payload); + int32 ret_val = ((LocApiRpc*)user)->locEventCB(client_handle, loc_event, loc_event_payload); EXIT_LOG(%d, ret_val); return ret_val; } @@ -101,17 +104,21 @@ SIDE EFFECTS static void loc_rpc_global_cb(void* user, CLIENT* clnt, enum rpc_reset_event event) { MODEM_LOG_CALLFLOW(%s, loc_get_rpc_reset_event_name(event)); - ((LocApiRpcAdapter*)user)->locRpcGlobalCB(clnt, event); + ((LocApiRpc*)user)->locRpcGlobalCB(clnt, event); EXIT_LOG(%p, VOID_RET); } +const LOC_API_ADAPTER_EVENT_MASK_T LocApiRpc::maskAll = + LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST | + LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | + LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; -LocApiAdapter* getLocApiAdapter(LocEng &locEng) -{ - return new LocApiRpcAdapter(locEng); -} - -const rpc_loc_event_mask_type LocApiRpcAdapter::locBits[] = +const rpc_loc_event_mask_type LocApiRpc::locBits[] = { RPC_LOC_EVENT_PARSED_POSITION_REPORT, RPC_LOC_EVENT_SATELLITE_REPORT, @@ -124,27 +131,24 @@ const rpc_loc_event_mask_type LocApiRpcAdapter::locBits[] = RPC_LOC_EVENT_STATUS_REPORT }; -LocApiRpcAdapter::LocApiRpcAdapter(LocEng &locEng) : - LocApiAdapter(locEng), +// constructor +LocApiRpc::LocApiRpc(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask) : + LocApiBase(msgTask, exMask), client_handle(RPC_LOC_CLIENT_HANDLE_INVALID), - eMask(convertMask(locEng.eventMask)), dataEnableLastSet(-1) { memset(apnLastSet, 0, sizeof(apnLastSet)); loc_api_glue_init(); } -LocApiRpcAdapter::~LocApiRpcAdapter() +LocApiRpc::~LocApiRpc() { - if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) { - loc_clear(client_handle); - } - - loc_close(client_handle); + close(); } rpc_loc_event_mask_type -LocApiRpcAdapter::convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask) +LocApiRpc::convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask) { rpc_loc_event_mask_type newMask = 0; @@ -159,7 +163,7 @@ LocApiRpcAdapter::convertMask(LOC_API_ADAPTER_EVENT_MASK_T mask) } enum loc_api_adapter_err -LocApiRpcAdapter::convertErr(int rpcErr) +LocApiRpc::convertErr(int rpcErr) { switch(rpcErr) { @@ -188,7 +192,7 @@ LocApiRpcAdapter::convertErr(int rpcErr) } } -void LocApiRpcAdapter::locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event) +void LocApiRpc::locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event) { static rpc_loc_engine_state_e_type last_state = RPC_LOC_ENGINE_STATE_MAX; @@ -208,12 +212,10 @@ void LocApiRpcAdapter::locRpcGlobalCB(CLIENT* clnt, enum rpc_reset_event event) } } -int32 LocApiRpcAdapter::locEventCB(rpc_loc_client_handle_type client_handle, +int32 LocApiRpc::locEventCB(rpc_loc_client_handle_type client_handle, rpc_loc_event_mask_type loc_event, const rpc_loc_event_payload_u_type* loc_event_payload) { - locEngHandle.acquireWakelock(); - // Parsed report if (loc_event & RPC_LOC_EVENT_PARSED_POSITION_REPORT) { @@ -269,60 +271,89 @@ int32 LocApiRpcAdapter::locEventCB(rpc_loc_client_handle_type client_handle, NIEvent(&loc_event_payload->rpc_loc_event_payload_u_type_u.ni_request); } - locEngHandle.releaseWakeLock(); return RPC_LOC_API_SUCCESS;//We simply want to return sucess here as we do not want to // cause any issues in RPC thread context } enum loc_api_adapter_err -LocApiRpcAdapter::reinit() +LocApiRpc::open(LOC_API_ADAPTER_EVENT_MASK_T mask) { enum loc_api_adapter_err ret_val = LOC_API_ADAPTER_ERR_SUCCESS; - if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) { - loc_clear(client_handle); - } - client_handle = loc_open(eMask, loc_event_cb, loc_rpc_global_cb, this); + // RPC does not dynamically update the event mask. And in the + // case of RPC, all we support are positioning (gps + agps) + // masks anyways, so we simply mask all of them on always. + // After doing so the first time in a power cycle, we know there + // will the following if condition will never be true any more. + mask = maskAll; - if (client_handle < 0) { - ret_val = LOC_API_ADAPTER_ERR_INVALID_HANDLE; + if (mask != mMask) { + if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) { + close(); + } + + mMask = mask; + // it is important to cap the mask here, because not all LocApi's + // can enable the same bits, e.g. foreground and bckground. + client_handle = loc_open(convertMask(mask), + loc_event_cb, + loc_rpc_global_cb, this); + + if (client_handle < 0) { + mMask = 0; + client_handle = RPC_LOC_CLIENT_HANDLE_INVALID; + ret_val = LOC_API_ADAPTER_ERR_INVALID_HANDLE; + } } return ret_val; } enum loc_api_adapter_err -LocApiRpcAdapter::startFix() { - LOC_LOGD("LocApiRpcAdapter::startFix() called"); +LocApiRpc::close() +{ + if (RPC_LOC_CLIENT_HANDLE_INVALID != client_handle) { + loc_clear(client_handle); + } + + loc_close(client_handle); + mMask = 0; + client_handle = RPC_LOC_CLIENT_HANDLE_INVALID; + + return LOC_API_ADAPTER_ERR_SUCCESS; +} + +enum loc_api_adapter_err +LocApiRpc::startFix(const LocPosMode& posMode) { + LOC_LOGD("LocApiRpc::startFix() called"); return convertErr( loc_start_fix(client_handle) ); } enum loc_api_adapter_err -LocApiRpcAdapter::stopFix() { - LOC_LOGD("LocApiRpcAdapter::stopFix() called"); +LocApiRpc::stopFix() { + LOC_LOGD("LocApiRpc::stopFix() called"); return convertErr( loc_stop_fix(client_handle) ); } enum loc_api_adapter_err -LocApiRpcAdapter::setPositionMode(const LocPosMode *posMode) +LocApiRpc::setPositionMode(const LocPosMode& posMode) { rpc_loc_ioctl_data_u_type ioctl_data; - rpc_loc_fix_criteria_s_type *fix_criteria_ptr; + rpc_loc_fix_criteria_s_type *fix_criteria_ptr = + &ioctl_data.rpc_loc_ioctl_data_u_type_u.fix_criteria; rpc_loc_ioctl_e_type ioctl_type = RPC_LOC_IOCTL_SET_FIX_CRITERIA; rpc_loc_operation_mode_e_type op_mode; int ret_val; - - if (NULL != posMode) - fixCriteria = *posMode; + const LocPosMode* fixCriteria = &posMode; ALOGD ("loc_eng_set_position mode, client = %d, interval = %d, mode = %d\n", - (int32) client_handle, fixCriteria.min_interval, fixCriteria.mode); + (int32) client_handle, fixCriteria->min_interval, fixCriteria->mode); - switch (fixCriteria.mode) + switch (fixCriteria->mode) { case LOC_POSITION_MODE_MS_BASED: op_mode = RPC_LOC_OPER_MODE_MSB; @@ -348,25 +379,24 @@ LocApiRpcAdapter::setPositionMode(const LocPosMode *posMode) op_mode = RPC_LOC_OPER_MODE_STANDALONE; } - fix_criteria_ptr = &ioctl_data.rpc_loc_ioctl_data_u_type_u.fix_criteria; fix_criteria_ptr->valid_mask = RPC_LOC_FIX_CRIT_VALID_PREFERRED_OPERATION_MODE | RPC_LOC_FIX_CRIT_VALID_RECURRENCE_TYPE; - fix_criteria_ptr->min_interval = fixCriteria.min_interval; + fix_criteria_ptr->min_interval = fixCriteria->min_interval; fix_criteria_ptr->preferred_operation_mode = op_mode; - fix_criteria_ptr->min_interval = fixCriteria.min_interval; + fix_criteria_ptr->min_interval = fixCriteria->min_interval; fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_MIN_INTERVAL; - if (fixCriteria.preferred_accuracy > 0) { - fix_criteria_ptr->preferred_accuracy = fixCriteria.preferred_accuracy; + if (fixCriteria->preferred_accuracy > 0) { + fix_criteria_ptr->preferred_accuracy = fixCriteria->preferred_accuracy; fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_ACCURACY; } - if (fixCriteria.preferred_time > 0) { - fix_criteria_ptr->preferred_response_time = fixCriteria.preferred_time; + if (fixCriteria->preferred_time > 0) { + fix_criteria_ptr->preferred_response_time = fixCriteria->preferred_time; fix_criteria_ptr->valid_mask |= RPC_LOC_FIX_CRIT_VALID_PREFERRED_RESPONSE_TIME; } - switch (fixCriteria.recurrence) { + switch (fixCriteria->recurrence) { case GPS_POSITION_RECURRENCE_SINGLE: fix_criteria_ptr->recurrence_type = RPC_LOC_SINGLE_FIX; break; @@ -387,7 +417,7 @@ LocApiRpcAdapter::setPositionMode(const LocPosMode *posMode) } enum loc_api_adapter_err -LocApiRpcAdapter::setTime(GpsUtcTime time, int64_t timeReference, int uncertainty) +LocApiRpc::setTime(GpsUtcTime time, int64_t timeReference, int uncertainty) { rpc_loc_ioctl_data_u_type ioctl_data; rpc_loc_assist_data_time_s_type *time_info_ptr; @@ -413,7 +443,7 @@ LocApiRpcAdapter::setTime(GpsUtcTime time, int64_t timeReference, int uncertaint } enum loc_api_adapter_err -LocApiRpcAdapter::injectPosition(double latitude, double longitude, float accuracy) +LocApiRpc::injectPosition(double latitude, double longitude, float accuracy) { /* IOCTL data */ rpc_loc_ioctl_data_u_type ioctl_data; @@ -452,7 +482,7 @@ LocApiRpcAdapter::injectPosition(double latitude, double longitude, float accura } enum loc_api_adapter_err -LocApiRpcAdapter::informNiResponse(GpsUserResponseType userResponse, +LocApiRpc::informNiResponse(GpsUserResponseType userResponse, const void* passThroughData) { rpc_loc_ioctl_data_u_type data; @@ -489,7 +519,7 @@ LocApiRpcAdapter::informNiResponse(GpsUserResponseType userResponse, } enum loc_api_adapter_err -LocApiRpcAdapter::setAPN(char* apn, int len, boolean force) +LocApiRpc::setAPN(char* apn, int len, boolean force) { enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS; int size = sizeof(apnLastSet); @@ -500,7 +530,7 @@ LocApiRpcAdapter::setAPN(char* apn, int len, boolean force) } memcpy(apnLastSet, apn, size); - if (false == navigating) { + if (!isInSession()) { rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_LBS_APN_PROFILE, {0}}; ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].srv_system_type = LOC_APN_PROFILE_SRV_SYS_MAX; ioctl_data.rpc_loc_ioctl_data_u_type_u.apn_profiles[0].pdp_type = LOC_APN_PROFILE_PDN_TYPE_IPV4; @@ -518,17 +548,16 @@ LocApiRpcAdapter::setAPN(char* apn, int len, boolean force) return rtv; } -void LocApiRpcAdapter::setInSession(bool inSession) +void LocApiRpc::setInSession(bool inSession) { - LocApiAdapter::setInSession(inSession); - if (false == navigating) { + if (!inSession) { enableData(dataEnableLastSet, true); setAPN(apnLastSet, sizeof(apnLastSet)-1, true); } } enum loc_api_adapter_err -LocApiRpcAdapter::setServer(const char* url, int len) +LocApiRpc::setServer(const char* url, int len) { rpc_loc_ioctl_data_u_type ioctl_data; rpc_loc_server_info_s_type *server_info_ptr; @@ -559,7 +588,7 @@ LocApiRpcAdapter::setServer(const char* url, int len) } enum loc_api_adapter_err -LocApiRpcAdapter::setServer(unsigned int ip, int port, LocServerType type) +LocApiRpc::setServer(unsigned int ip, int port, LocServerType type) { rpc_loc_ioctl_data_u_type ioctl_data; rpc_loc_server_info_s_type *server_info_ptr; @@ -594,13 +623,13 @@ LocApiRpcAdapter::setServer(unsigned int ip, int port, LocServerType type) } enum loc_api_adapter_err -LocApiRpcAdapter::enableData(int enable, boolean force) +LocApiRpc::enableData(int enable, boolean force) { enum loc_api_adapter_err rtv = LOC_API_ADAPTER_ERR_SUCCESS; if (force || dataEnableLastSet != enable) { dataEnableLastSet = enable; - if (false == navigating) { + if (!isInSession()) { rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_DATA_ENABLE, {0}}; ioctl_data.rpc_loc_ioctl_data_u_type_u.data_enable = enable; @@ -617,7 +646,7 @@ LocApiRpcAdapter::enableData(int enable, boolean force) } enum loc_api_adapter_err -LocApiRpcAdapter::deleteAidingData(GpsAidingData bits) +LocApiRpc::deleteAidingData(GpsAidingData bits) { rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_DELETE_ASSIST_DATA, {0}}; ioctl_data.rpc_loc_ioctl_data_u_type_u.assist_data_delete.type = bits; @@ -631,7 +660,7 @@ LocApiRpcAdapter::deleteAidingData(GpsAidingData bits) ); } -void LocApiRpcAdapter::reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr) +void LocApiRpc::reportPosition(const rpc_loc_parsed_position_s_type *location_report_ptr) { LocPosTechMask tech_Mask = LOC_POS_TECH_MASK_DEFAULT; @@ -723,30 +752,36 @@ void LocApiRpcAdapter::reportPosition(const rpc_loc_parsed_position_s_type *loca } LOC_LOGV("reportPosition: fire callback\n"); - LocApiAdapter::reportPosition(location, - locationExtended, - locEngHandle.extPosInfo((void*)location_report_ptr), - (location_report_ptr->session_status == RPC_LOC_SESS_STATUS_IN_PROGESS ? - LOC_SESS_INTERMEDIATE : LOC_SESS_SUCCESS), - tech_Mask); + enum loc_sess_status fixStatus = + (location_report_ptr->session_status + == RPC_LOC_SESS_STATUS_IN_PROGESS ? + LOC_SESS_INTERMEDIATE : LOC_SESS_SUCCESS); + LocApiBase::reportPosition(location, + locationExtended, + (void*)location_report_ptr, + fixStatus, + tech_Mask); } } else { - LocApiAdapter::reportPosition(location, - locationExtended, - NULL, - LOC_SESS_FAILURE); - LOC_LOGV("loc_eng_report_position: ignore position report when session status = %d\n", location_report_ptr->session_status); + LocApiBase::reportPosition(location, + locationExtended, + NULL, + LOC_SESS_FAILURE); + LOC_LOGV("loc_eng_report_position: ignore position report " + "when session status = %d\n", + location_report_ptr->session_status); } } else { - LOC_LOGV("loc_eng_report_position: ignore position report when session status is not set\n"); + LOC_LOGV("loc_eng_report_position: ignore position report " + "when session status is not set\n"); } } -void LocApiRpcAdapter::reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr) +void LocApiRpc::reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr) { GpsSvStatus SvStatus = {0}; GpsLocationExtended locationExtended = {0}; @@ -846,51 +881,52 @@ void LocApiRpcAdapter::reportSv(const rpc_loc_gnss_info_s_type *gnss_report_ptr) if (SvStatus.num_svs >= 0) { - LocApiAdapter::reportSv(SvStatus, - locationExtended, - locEngHandle.extSvInfo((void*)gnss_report_ptr)); + LocApiBase::reportSv(SvStatus, + locationExtended, + (void*)gnss_report_ptr); } } -void LocApiRpcAdapter::reportStatus(const rpc_loc_status_event_s_type *status_report_ptr) +void LocApiRpc::reportStatus(const rpc_loc_status_event_s_type *status_report_ptr) { if (status_report_ptr->event == RPC_LOC_STATUS_EVENT_ENGINE_STATE) { if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_ON) { - LocApiAdapter::reportStatus(GPS_STATUS_ENGINE_ON); - LocApiAdapter::reportStatus(GPS_STATUS_SESSION_BEGIN); + LocApiBase::reportStatus(GPS_STATUS_ENGINE_ON); + LocApiBase::reportStatus(GPS_STATUS_SESSION_BEGIN); } else if (status_report_ptr->payload.rpc_loc_status_event_payload_u_type_u.engine_state == RPC_LOC_ENGINE_STATE_OFF) { - LocApiAdapter::reportStatus(GPS_STATUS_SESSION_END); - LocApiAdapter::reportStatus(GPS_STATUS_ENGINE_OFF); + LocApiBase::reportStatus(GPS_STATUS_SESSION_END); + LocApiBase::reportStatus(GPS_STATUS_ENGINE_OFF); } else { - LocApiAdapter::reportStatus(GPS_STATUS_NONE); + LocApiBase::reportStatus(GPS_STATUS_NONE); } } } -void LocApiRpcAdapter::reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr) +void LocApiRpc::reportNmea(const rpc_loc_nmea_report_s_type *nmea_report_ptr) { #if (AMSS_VERSION==3200) - LocApiAdapter::reportNmea(nmea_report_ptr->nmea_sentences.nmea_sentences_val, - nmea_report_ptr->nmea_sentences.nmea_sentences_len); + LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences.nmea_sentences_val, + nmea_report_ptr->nmea_sentences.nmea_sentences_len); #else - LocApiAdapter::reportNmea(nmea_report_ptr->nmea_sentences, - nmea_report_ptr->length); + LocApiBase::reportNmea(nmea_report_ptr->nmea_sentences, + nmea_report_ptr->length); LOC_LOGD("loc_eng_report_nmea: $%c%c%c\n", - nmea_report_ptr->nmea_sentences[3], nmea_report_ptr->nmea_sentences[4], + nmea_report_ptr->nmea_sentences[3], + nmea_report_ptr->nmea_sentences[4], nmea_report_ptr->nmea_sentences[5]); #endif /* #if (AMSS_VERSION==3200) */ } enum loc_api_adapter_err -LocApiRpcAdapter::setXtraData(char* data, int length) +LocApiRpc::setXtraData(char* data, int length) { int rpc_ret_val = RPC_LOC_API_GENERAL_FAILURE; int total_parts; @@ -968,7 +1004,7 @@ LocApiRpcAdapter::setXtraData(char* data, int length) /* Request the Xtra Server Url from the modem */ enum loc_api_adapter_err -LocApiRpcAdapter::requestXtraServer() +LocApiRpc::requestXtraServer() { loc_api_adapter_err err; rpc_loc_ioctl_data_u_type data; @@ -1001,16 +1037,19 @@ LocApiRpcAdapter::requestXtraServer() return LOC_API_ADAPTER_ERR_GENERAL_FAILURE; } - LocApiAdapter::reportXtraServer(callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.predicted_orbits_data_source.servers[0], - callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.predicted_orbits_data_source.servers[1], - callback_data.data.rpc_loc_ioctl_callback_data_u_type_u.predicted_orbits_data_source.servers[2], - 255); + reportXtraServer(callback_data.data.rpc_loc_ioctl_callback_data_u_type_u. + predicted_orbits_data_source.servers[0], + callback_data.data.rpc_loc_ioctl_callback_data_u_type_u. + predicted_orbits_data_source.servers[1], + callback_data.data.rpc_loc_ioctl_callback_data_u_type_u. + predicted_orbits_data_source.servers[2], + 255); return LOC_API_ADAPTER_ERR_SUCCESS; } enum loc_api_adapter_err -LocApiRpcAdapter::atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType) +LocApiRpc::atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType) { rpc_loc_server_open_status_e_type open_status = is_succ ? RPC_LOC_SERVER_OPEN_SUCCESS : RPC_LOC_SERVER_OPEN_FAIL; rpc_loc_ioctl_data_u_type ioctl_data; @@ -1084,7 +1123,7 @@ LocApiRpcAdapter::atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerTy } enum loc_api_adapter_err -LocApiRpcAdapter::atlCloseStatus(int handle, int is_succ) +LocApiRpc::atlCloseStatus(int handle, int is_succ) { rpc_loc_ioctl_data_u_type ioctl_data; ioctl_data.disc = RPC_LOC_IOCTL_INFORM_SERVER_CLOSE_STATUS; @@ -1104,7 +1143,7 @@ LocApiRpcAdapter::atlCloseStatus(int handle, int is_succ) ); } -void LocApiRpcAdapter::ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr) +void LocApiRpc::ATLEvent(const rpc_loc_server_request_s_type *server_request_ptr) { int connHandle; AGpsType agps_type; @@ -1140,7 +1179,7 @@ void LocApiRpcAdapter::ATLEvent(const rpc_loc_server_request_s_type *server_requ } } -void LocApiRpcAdapter::NIEvent(const rpc_loc_ni_event_s_type *ni_req) +void LocApiRpc::NIEvent(const rpc_loc_ni_event_s_type *ni_req) { GpsNiNotification notif = {0}; @@ -1203,8 +1242,8 @@ void LocApiRpcAdapter::NIEvent(const rpc_loc_ni_event_s_type *ni_req) #endif /* #if (AMSS_VERSION==3200) */ char lcs_addr[32]; // Decoded LCS address for UMTS CP NI - addr_len = LocApiAdapter::decodeAddress(lcs_addr, sizeof lcs_addr, address_source, - umts_cp_req->ext_client_address_data.ext_client_address_len); + addr_len = decodeAddress(lcs_addr, sizeof lcs_addr, address_source, + umts_cp_req->ext_client_address_data.ext_client_address_len); // The address is ASCII string if (addr_len) @@ -1283,10 +1322,10 @@ void LocApiRpcAdapter::NIEvent(const rpc_loc_ni_event_s_type *ni_req) // this copy will get freed in loc_eng_ni when loc_ni_respond() is called rpc_loc_ni_event_s_type *copy = (rpc_loc_ni_event_s_type *)malloc(sizeof(*copy)); memcpy(copy, ni_req, sizeof(*copy)); - LocApiAdapter::requestNiNotify(notif, (const void*)copy); + requestNiNotify(notif, (const void*)copy); } -int LocApiRpcAdapter::NIEventFillVerfiyType(GpsNiNotification ¬if, +int LocApiRpc::NIEventFillVerfiyType(GpsNiNotification ¬if, rpc_loc_ni_notify_verify_e_type notif_priv) { switch (notif_priv) @@ -1317,7 +1356,7 @@ int LocApiRpcAdapter::NIEventFillVerfiyType(GpsNiNotification ¬if, } enum loc_api_adapter_err -LocApiRpcAdapter::setSUPLVersion(uint32_t version) +LocApiRpc::setSUPLVersion(uint32_t version) { rpc_loc_ioctl_data_u_type ioctl_data = {RPC_LOC_IOCTL_SET_SUPL_VERSION, {0}}; ioctl_data.rpc_loc_ioctl_data_u_type_u.supl_version = (int)version; @@ -1330,7 +1369,7 @@ LocApiRpcAdapter::setSUPLVersion(uint32_t version) ); } -GpsNiEncodingType LocApiRpcAdapter::convertNiEncodingType(int loc_encoding) +GpsNiEncodingType LocApiRpc::convertNiEncodingType(int loc_encoding) { switch (loc_encoding) { @@ -1346,3 +1385,8 @@ GpsNiEncodingType LocApiRpcAdapter::convertNiEncodingType(int loc_encoding) return GPS_ENC_UNKNOWN; } } + +LocApiBase* getLocApi(const MsgTask* msgTask, + LOC_API_ADAPTER_EVENT_MASK_T exMask) { + return new LocApiRpc(msgTask, exMask); +} diff --git a/loc_api/libloc_api_50001/Android.mk b/loc_api/libloc_api_50001/Android.mk index 07172654..dd14b5e5 100644 --- a/loc_api/libloc_api_50001/Android.mk +++ b/loc_api/libloc_api_50001/Android.mk @@ -5,7 +5,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := libloc_adapter +LOCAL_MODULE := libloc_eng LOCAL_MODULE_OWNER := qcom LOCAL_MODULE_TAGS := optional @@ -13,51 +13,9 @@ LOCAL_MODULE_TAGS := optional LOCAL_SHARED_LIBRARIES := \ libutils \ libcutils \ + libdl \ liblog \ - libgps.utils \ - libdl - -LOCAL_SRC_FILES += \ - loc_eng_log.cpp \ - LocApiAdapter.cpp - -LOCAL_CFLAGS += \ - -fno-short-enums \ - -D_ANDROID_ - -LOCAL_C_INCLUDES:= \ - $(TARGET_OUT_HEADERS)/gps.utils \ - hardware/qcom/gps/loc_api/libloc_api_50001 - -LOCAL_COPY_HEADERS_TO:= libloc_eng/ -LOCAL_COPY_HEADERS:= \ - LocApiAdapter.h \ - loc.h \ - gps_extended.h \ - loc_eng.h \ - loc_eng_xtra.h \ - loc_eng_ni.h \ - loc_eng_agps.h \ - loc_eng_msg.h \ - loc_eng_msg_id.h \ - loc_eng_log.h \ - loc_ulp.h - -LOCAL_PRELINK_MODULE := false - -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libloc_eng - -LOCAL_MODULE_TAGS := optional - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libcutils \ - liblog \ - libloc_adapter \ + libloc_core \ libgps.utils LOCAL_SRC_FILES += \ @@ -66,7 +24,8 @@ LOCAL_SRC_FILES += \ loc_eng_xtra.cpp \ loc_eng_ni.cpp \ loc_eng_log.cpp \ - loc_eng_nmea.cpp + loc_eng_nmea.cpp \ + LocEngAdapter.cpp LOCAL_SRC_FILES += \ loc_eng_dmn_conn.cpp \ @@ -81,8 +40,22 @@ LOCAL_CFLAGS += \ LOCAL_C_INCLUDES:= \ $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libloc_core \ + hardware/qcom/gps/loc_api/libloc_api_50001 \ hardware/qcom/gps/loc_api/ulp/inc +LOCAL_COPY_HEADERS_TO:= libloc_eng/ +LOCAL_COPY_HEADERS:= \ + LocEngAdapter.h \ + loc.h \ + loc_eng.h \ + loc_eng_xtra.h \ + loc_eng_ni.h \ + loc_eng_agps.h \ + loc_eng_msg.h \ + loc_eng_msg_id.h \ + loc_eng_log.h + LOCAL_PRELINK_MODULE := false include $(BUILD_SHARED_LIBRARY) @@ -90,6 +63,7 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := gps.$(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE) +LOCAL_MODULE_OWNER := qcom LOCAL_MODULE_TAGS := optional @@ -100,6 +74,7 @@ LOCAL_SHARED_LIBRARIES := \ libcutils \ liblog \ libloc_eng \ + libloc_core \ libgps.utils \ libdl \ libandroid_runtime @@ -119,6 +94,7 @@ endif ## Includes LOCAL_C_INCLUDES:= \ $(TARGET_OUT_HEADERS)/gps.utils \ + $(TARGET_OUT_HEADERS)/libloc_core \ hardware/qcom/gps/loc_api/ulp/inc LOCAL_PRELINK_MODULE := false diff --git a/loc_api/libloc_api_50001/LocApiAdapter.cpp b/loc_api/libloc_api_50001/LocApiAdapter.cpp deleted file mode 100644 index b26a4008..00000000 --- a/loc_api/libloc_api_50001/LocApiAdapter.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/* 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 - * 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. - * - */ -#define LOG_NDDEBUG 0 -#define LOG_TAG "LocSvc_adapter" - -#include -#include -#include "loc_eng_msg.h" -#include "loc_log.h" -#include "loc_eng_ni.h" - -static void* noProc(void* data) -{ - return NULL; -} - -LocEng::LocEng(void* caller, - LOC_API_ADAPTER_EVENT_MASK_T emask, - gps_acquire_wakelock acqwl, - gps_release_wakelock relwl, - loc_msg_sender msgSender, - loc_msg_sender msgUlpSender, - loc_ext_parser posParser, - loc_ext_parser svParser) : - owner(caller), - eventMask(emask), acquireWakelock(acqwl), - releaseWakeLock(relwl), sendMsge(msgSender), - sendUlpMsg(msgUlpSender), - extPosInfo(NULL == posParser ? noProc : posParser), - extSvInfo(NULL == svParser ? noProc : svParser) -{ - LOC_LOGV("LocEng constructor %p, %p", posParser, svParser); -} - -LocApiAdapter::LocApiAdapter(LocEng &locEng) : - locEngHandle(locEng), fixCriteria(), navigating(false) -{ - LOC_LOGD("LocApiAdapter created"); -} - -LocApiAdapter::~LocApiAdapter() -{ - LOC_LOGV("LocApiAdapter deleted"); -} - -LocApiAdapter* LocApiAdapter::getLocApiAdapter(LocEng &locEng) -{ - void* handle; - LocApiAdapter* adapter = NULL; - - handle = dlopen ("libloc_api_v02.so", RTLD_NOW); - - if (!handle) { - handle = dlopen ("libloc_api-rpc-qc.so", RTLD_NOW); - } - - if (!handle) { - adapter = new LocApiAdapter(locEng); - } else { - getLocApiAdapter_t* getHandle = (getLocApiAdapter_t*)dlsym(handle, "getLocApiAdapter"); - - adapter = (*getHandle)(locEng); - } - - return adapter; -} - -int LocApiAdapter::hexcode(char *hexstring, int string_size, - const char *data, int data_size) -{ - int i; - for (i = 0; i < data_size; i++) - { - char ch = data[i]; - if (i*2 + 3 <= string_size) - { - snprintf(&hexstring[i*2], 3, "%02X", ch); - } - else { - break; - } - } - return i; -} - -int LocApiAdapter::decodeAddress(char *addr_string, int string_size, - const char *data, int data_size) -{ - const char addr_prefix = 0x91; - int i, idxOutput = 0; - - if (!data || !addr_string) { return 0; } - - if (data[0] != addr_prefix) - { - LOC_LOGW("decodeAddress: address prefix is not 0x%x but 0x%x", addr_prefix, data[0]); - addr_string[0] = '\0'; - return 0; // prefix not correct - } - - for (i = 1; i < data_size; i++) - { - unsigned char ch = data[i], low = ch & 0x0F, hi = ch >> 4; - if (low <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = low + '0'; } - if (hi <= 9 && idxOutput < string_size - 1) { addr_string[idxOutput++] = hi + '0'; } - } - - addr_string[idxOutput] = '\0'; // Terminates the string - - return idxOutput; -} - -void LocApiAdapter::reportPosition(UlpLocation &location, - GpsLocationExtended &locationExtended, - void* locationExt, - enum loc_sess_status status, - LocPosTechMask loc_technology_mask ) -{ - loc_eng_msg_report_position *msg(new loc_eng_msg_report_position(locEngHandle.owner, - location, - locationExtended, - locationExt, - status, - loc_technology_mask)); - if (locEngHandle.sendUlpMsg) { - locEngHandle.sendUlpMsg(locEngHandle.owner, msg); - } else { - locEngHandle.sendMsge(locEngHandle.owner, msg); - } -} - -void LocApiAdapter::reportSv(GpsSvStatus &svStatus, GpsLocationExtended &locationExtended, void* svExt) -{ - loc_eng_msg_report_sv *msg(new loc_eng_msg_report_sv(locEngHandle.owner, svStatus, locationExtended, svExt)); - - //We want to send SV info to ULP to help it in determining GNSS signal strength - //ULP will forward the SV reports to HAL without any modifications - if (locEngHandle.sendUlpMsg) { - locEngHandle.sendUlpMsg(locEngHandle.owner, msg); - } else { - locEngHandle.sendMsge(locEngHandle.owner, msg); - } -} - -void LocApiAdapter::reportStatus(GpsStatusValue status) -{ - loc_eng_msg_report_status *msg(new loc_eng_msg_report_status(locEngHandle.owner, status)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::reportNmea(const char* nmea, int length) -{ - loc_eng_msg_report_nmea *msg(new loc_eng_msg_report_nmea(locEngHandle.owner, nmea, length)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::reportXtraServer(const char* url1, const char* url2, const char* url3, const int maxlength) -{ - loc_eng_msg_report_xtra_server *msg(new loc_eng_msg_report_xtra_server(locEngHandle.owner, url1, url2, url3, maxlength)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestATL(int connHandle, AGpsType agps_type) -{ - loc_eng_msg_request_atl *msg(new loc_eng_msg_request_atl(locEngHandle.owner, connHandle, agps_type)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestSuplES(int connHandle) -{ - loc_eng_msg_request_supl_es *msg(new loc_eng_msg_request_supl_es(locEngHandle.owner, connHandle)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::releaseDataHandle(void) -{ - loc_eng_msg_close_data_call *msg(new loc_eng_msg_close_data_call(locEngHandle.owner)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::releaseATL(int connHandle) -{ - loc_eng_msg_release_atl *msg(new loc_eng_msg_release_atl(locEngHandle.owner, connHandle)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestXtraData() -{ - LOC_LOGD("XTRA download request"); - - loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_REQUEST_XTRA_DATA)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestTime() -{ - LOC_LOGD("loc_event_cb: XTRA time download request"); - loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_REQUEST_TIME)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestLocation() -{ - LOC_LOGD("loc_event_cb: XTRA time download request... not supported"); - // loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_REQUEST_POSITION)); - // locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::requestNiNotify(GpsNiNotification ¬if, const void* data) -{ - notif.size = sizeof(notif); - notif.timeout = LOC_NI_NO_RESPONSE_TIME; - - loc_eng_msg_request_ni *msg(new loc_eng_msg_request_ni(locEngHandle.owner, notif, data)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::handleEngineDownEvent() -{ - loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_ENGINE_DOWN)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::handleEngineUpEvent() -{ - loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_ENGINE_UP)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::reportDataCallOpened() -{ - loc_eng_msg_atl_open_success *msg(new loc_eng_msg_atl_open_success(locEngHandle.owner, - AGPS_TYPE_INVALID, - NULL, 0, 0)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} - -void LocApiAdapter::reportDataCallClosed() -{ - loc_eng_msg_atl_closed *msg(new loc_eng_msg_atl_closed(locEngHandle.owner, - AGPS_TYPE_INVALID)); - locEngHandle.sendMsge(locEngHandle.owner, msg); -} diff --git a/loc_api/libloc_api_50001/LocApiAdapter.h b/loc_api/libloc_api_50001/LocApiAdapter.h deleted file mode 100644 index ace934e4..00000000 --- a/loc_api/libloc_api_50001/LocApiAdapter.h +++ /dev/null @@ -1,250 +0,0 @@ -/* Copyright (c) 2011-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_API_ADAPTER_H -#define LOC_API_ADAPTER_H - -#include -#include -#include -#include -#include -#include -#include "platform_lib_includes.h" - -#define MAX_APN_LEN 100 -#define MAX_URL_LEN 256 -#define smaller_of(a, b) (((a) > (b)) ? (b) : (a)) - -enum loc_api_adapter_err { - LOC_API_ADAPTER_ERR_SUCCESS = 0, - LOC_API_ADAPTER_ERR_GENERAL_FAILURE = 1, - LOC_API_ADAPTER_ERR_UNSUPPORTED = 2, - LOC_API_ADAPTER_ERR_INVALID_HANDLE = 4, - LOC_API_ADAPTER_ERR_INVALID_PARAMETER = 5, - LOC_API_ADAPTER_ERR_ENGINE_BUSY = 6, - LOC_API_ADAPTER_ERR_PHONE_OFFLINE = 7, - LOC_API_ADAPTER_ERR_TIMEOUT = 8, - LOC_API_ADAPTER_ERR_SERVICE_NOT_PRESENT = 9, - - LOC_API_ADAPTER_ERR_ENGINE_DOWN = 100, - LOC_API_ADAPTER_ERR_FAILURE, - LOC_API_ADAPTER_ERR_UNKNOWN -}; - -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_EVENT_MAX -}; - -#define LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT (1< +#include "loc_eng_msg.h" +#include "loc_log.h" + +using namespace loc_core; + +LocEngAdapter::LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask, + void* owner, loc_msg_sender msgSender, + MsgTask::tCreate tCreator) : + LocAdapterBase(mask, + LocDualContext::getLocFgContext( + tCreator, + LocDualContext::mLocationHalName)), + mOwner(owner), mSendUlpMsg(msgSender), mNavigating(false), + mAgpsEnabled(loc_core::LocDualContext::hasAgpsExt()) +{ + memset(&mFixCriteria, 0, sizeof(mFixCriteria)); + LOC_LOGD("LocEngAdapter created"); +} + +inline +LocEngAdapter::~LocEngAdapter() +{ + LOC_LOGV("LocEngAdapter deleted"); +} + +void LocEngAdapter::reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask ) +{ + if (mSendUlpMsg) { + loc_eng_msg_report_position *msg( + new loc_eng_msg_report_position(mOwner, + location, + locationExtended, + locationExt, + status, + loc_technology_mask)); + mSendUlpMsg(mOwner, msg); + } else { + sendMsg(new LocEngReportPosition(mOwner, + location, + locationExtended, + locationExt, + status, + loc_technology_mask)); + } +} + +void LocEngAdapter::reportSv(GpsSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt) +{ + + // We want to send SV info to ULP to help it in determining GNSS + // signal strength ULP will forward the SV reports to HAL without + // any modifications + if (mSendUlpMsg) { + loc_eng_msg_report_sv *msg( + new loc_eng_msg_report_sv(mOwner, svStatus, + locationExtended, svExt)); + mSendUlpMsg(mOwner, msg); + } else { + sendMsg(new LocEngReportSv(mOwner, svStatus, + locationExtended, svExt)); + } +} + +inline +void LocEngAdapter::reportStatus(GpsStatusValue status) +{ + sendMsg(new LocEngReportStatus(mOwner, status)); +} + +inline +void LocEngAdapter::reportNmea(const char* nmea, int length) +{ + sendMsg(new LocEngReportNmea(mOwner, nmea, length)); +} + +inline +bool LocEngAdapter::reportXtraServer(const char* url1, + const char* url2, + const char* url3, + const int maxlength) +{ + if (mAgpsEnabled) { + sendMsg(new LocEngReportXtraServer(mOwner, url1, + url2, url3, maxlength)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::requestATL(int connHandle, AGpsType agps_type) +{ + if (mAgpsEnabled) { + sendMsg(new LocEngRequestATL(mOwner, + connHandle, agps_type)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::releaseATL(int connHandle) +{ + if (mAgpsEnabled) { + sendMsg(new LocEngReleaseATL(mOwner, connHandle)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::requestXtraData() +{ + if (mAgpsEnabled) { + sendMsg(new LocEngRequestXtra(mOwner)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::requestTime() +{ + if (mAgpsEnabled) { + sendMsg(new LocEngRequestXtra(mOwner)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::requestNiNotify(GpsNiNotification ¬if, const void* data) +{ + if (mAgpsEnabled) { + notif.size = sizeof(notif); + notif.timeout = LOC_NI_NO_RESPONSE_TIME; + + sendMsg(new LocEngRequestNi(mOwner, notif, data)); + } + return mAgpsEnabled; +} + +inline +bool LocEngAdapter::requestSuplES(int connHandle) +{ + sendMsg(new LocEngRequestSuplEs(mOwner, connHandle)); + return true; +} + +inline +bool LocEngAdapter::reportDataCallOpened() +{ + sendMsg(new LocEngSuplEsOpened(mOwner)); + return true; +} + +inline +bool LocEngAdapter::reportDataCallClosed() +{ + sendMsg(new LocEngSuplEsClosed(mOwner)); + return true; +} + +inline +void LocEngAdapter::handleEngineDownEvent() +{ + sendMsg(new LocEngDown(mOwner)); +} + +inline +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 new file mode 100644 index 00000000..7e6f73bd --- /dev/null +++ b/loc_api/libloc_api_50001/LocEngAdapter.h @@ -0,0 +1,238 @@ +/* Copyright (c) 2011-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_API_ENG_ADAPTER_H +#define LOC_API_ENG_ADAPTER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_URL_LEN 256 + +using namespace loc_core; + +typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp); + +class LocEngAdapter : public LocAdapterBase { + void* mOwner; + loc_msg_sender mSendUlpMsg; + LocPosMode mFixCriteria; + bool mNavigating; + +public: + const bool mAgpsEnabled; + + LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask, + void* owner, loc_msg_sender msgSender, + MsgTask::tCreate tCreator); + virtual ~LocEngAdapter(); + + inline enum loc_api_adapter_err + startFix() + { + return mLocApi->startFix(mFixCriteria); + } + inline enum loc_api_adapter_err + stopFix() + { + return mLocApi->stopFix(); + } + inline enum loc_api_adapter_err + deleteAidingData(GpsAidingData f) + { + return mLocApi->deleteAidingData(f); + } + inline enum loc_api_adapter_err + enableData(int enable) + { + return mLocApi->enableData(enable); + } + inline enum loc_api_adapter_err + setAPN(char* apn, int len) + { + return mLocApi->setAPN(apn, len); + } + inline enum loc_api_adapter_err + injectPosition(double latitude, double longitude, float accuracy) + { + return mLocApi->injectPosition(latitude, longitude, accuracy); + } + inline enum loc_api_adapter_err + setTime(GpsUtcTime time, int64_t timeReference, int uncertainty) + { + return mLocApi->setTime(time, timeReference, uncertainty); + } + inline enum loc_api_adapter_err + setXtraData(char* data, int length) + { + return mLocApi->setXtraData(data, length); + } + inline enum loc_api_adapter_err + requestXtraServer() + { + return mLocApi->requestXtraServer(); + } + inline enum loc_api_adapter_err + atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bearer, AGpsType agpsType) + { + return mLocApi->atlOpenStatus(handle, is_succ, apn, bearer, agpsType); + } + inline enum loc_api_adapter_err + atlCloseStatus(int handle, int is_succ) + { + return mLocApi->atlCloseStatus(handle, is_succ); + } + inline enum loc_api_adapter_err + setPositionMode(const LocPosMode *posMode) + { + if (NULL != posMode) { + mFixCriteria = *posMode; + } + return mLocApi->setPositionMode(mFixCriteria); + } + inline enum loc_api_adapter_err + setServer(const char* url, int len) + { + return mLocApi->setServer(url, len); + } + inline enum loc_api_adapter_err + setServer(unsigned int ip, int port, + LocServerType type) + { + return mLocApi->setServer(ip, port, type); + } + inline enum loc_api_adapter_err + informNiResponse(GpsUserResponseType userResponse, const void* passThroughData) + { + return mLocApi->informNiResponse(userResponse, passThroughData); + } + inline enum loc_api_adapter_err + setSUPLVersion(uint32_t version) + { + return mLocApi->setSUPLVersion(version); + } + inline enum loc_api_adapter_err + setLPPConfig(uint32_t profile) + { + return mLocApi->setLPPConfig(profile); + } + inline enum loc_api_adapter_err + setSensorControlConfig(int sensorUsage) + { + return mLocApi->setSensorControlConfig(sensorUsage); + } + inline enum loc_api_adapter_err + setSensorProperties(bool gyroBiasVarianceRandomWalk_valid, float gyroBiasVarianceRandomWalk, + bool accelBiasVarianceRandomWalk_valid, float accelBiasVarianceRandomWalk, + bool angleBiasVarianceRandomWalk_valid, float angleBiasVarianceRandomWalk, + bool rateBiasVarianceRandomWalk_valid, float rateBiasVarianceRandomWalk, + bool velocityBiasVarianceRandomWalk_valid, float velocityBiasVarianceRandomWalk) + { + return mLocApi->setSensorProperties(gyroBiasVarianceRandomWalk_valid, gyroBiasVarianceRandomWalk, + accelBiasVarianceRandomWalk_valid, accelBiasVarianceRandomWalk, + angleBiasVarianceRandomWalk_valid, angleBiasVarianceRandomWalk, + rateBiasVarianceRandomWalk_valid, rateBiasVarianceRandomWalk, + velocityBiasVarianceRandomWalk_valid, velocityBiasVarianceRandomWalk); + } + inline virtual enum loc_api_adapter_err + setSensorPerfControlConfig(int controlMode, int accelSamplesPerBatch, int accelBatchesPerSec, + int gyroSamplesPerBatch, int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, int algorithmConfig) + { + return mLocApi->setSensorPerfControlConfig(controlMode, accelSamplesPerBatch, accelBatchesPerSec, + gyroSamplesPerBatch, gyroBatchesPerSec, + accelSamplesPerBatchHigh, accelBatchesPerSecHigh, + gyroSamplesPerBatchHigh, gyroBatchesPerSecHigh, + algorithmConfig); + } + inline virtual enum loc_api_adapter_err + setExtPowerConfig(int isBatteryCharging) + { + return mLocApi->setExtPowerConfig(isBatteryCharging); + } + inline virtual enum loc_api_adapter_err + setAGLONASSProtocol(unsigned long aGlonassProtocol) + { + return mLocApi->setAGLONASSProtocol(aGlonassProtocol); + } + inline virtual int initDataServiceClient() + { + return mLocApi->initDataServiceClient(); + } + inline virtual int openAndStartDataCall() + { + return mLocApi->openAndStartDataCall(); + } + inline virtual void stopDataCall() + { + mLocApi->stopDataCall(); + } + inline virtual void closeDataCall() + { + mLocApi->closeDataCall(); + } + + virtual void handleEngineDownEvent(); + virtual void handleEngineUpEvent(); + virtual void reportPosition(UlpLocation &location, + GpsLocationExtended &locationExtended, + void* locationExt, + enum loc_sess_status status, + LocPosTechMask loc_technology_mask); + virtual void reportSv(GpsSvStatus &svStatus, + GpsLocationExtended &locationExtended, + void* svExt); + virtual void reportStatus(GpsStatusValue status); + virtual void reportNmea(const char* nmea, int length); + virtual bool reportXtraServer(const char* url1, const char* url2, + const char* url3, const int maxlength); + virtual bool requestXtraData(); + virtual bool requestTime(); + virtual bool requestATL(int connHandle, AGpsType agps_type); + virtual bool releaseATL(int connHandle); + virtual bool requestNiNotify(GpsNiNotification ¬ify, const void* data); + virtual bool requestSuplES(int connHandle); + virtual bool reportDataCallOpened(); + virtual bool reportDataCallClosed(); + + inline const LocPosMode& getPositionMode() const + {return mFixCriteria;} + inline virtual bool isInSession() + { return mNavigating; } + inline void setInSession(bool inSession) + { mNavigating = inSession; mLocApi->setInSession(inSession); } +}; + +#endif //LOC_API_ENG_ADAPTER_H diff --git a/loc_api/libloc_api_50001/Makefile.am b/loc_api/libloc_api_50001/Makefile.am index 93e633f5..cee948c1 100644 --- a/loc_api/libloc_api_50001/Makefile.am +++ b/loc_api/libloc_api_50001/Makefile.am @@ -5,7 +5,7 @@ AM_CFLAGS = \ -fno-short-enums \ -DFEATURE_GNSS_BIT_API -libloc_adapter_so_la_SOURCES = loc_eng_log.cpp LocApiAdapter.cpp +libloc_adapter_so_la_SOURCES = loc_eng_log.cpp LocEngAdapter.cpp if USE_GLIB libloc_adapter_so_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@ @@ -62,7 +62,7 @@ endif libgps_default_so_la_LIBADD = -lstdc++ -lcutils ../../utils/libgps_utils_so.la -ldl libloc_eng_so.la library_include_HEADERS = \ - LocApiAdapter.h \ + LocEngAdapter.h \ loc.h \ loc_eng.h \ loc_eng_xtra.h \ diff --git a/loc_api/libloc_api_50001/gps_extended.h b/loc_api/libloc_api_50001/gps_extended.h deleted file mode 100644 index f1db4729..00000000 --- a/loc_api/libloc_api_50001/gps_extended.h +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (c) 2013, The Linux Foundation. All rights reserved. - * - * Not a Contribution. - * - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GPS_EXTENDED_H -#define GPS_EXTENDED_H - -/** AGPS type */ -typedef int16_t AGpsExtType; -#define AGPS_TYPE_INVALID -1 -#define AGPS_TYPE_ANY 0 -#define AGPS_TYPE_SUPL 1 -#define AGPS_TYPE_C2K 2 -#define AGPS_TYPE_WWAN_ANY 3 -#define AGPS_TYPE_WIFI 4 - -/** SSID length */ -#define SSID_BUF_SIZE (32+1) - -typedef int16_t AGpsBearerType; -#define AGPS_APN_BEARER_INVALID -1 -#define AGPS_APN_BEARER_IPV4 0 -#define AGPS_APN_BEARER_IPV6 1 -#define AGPS_APN_BEARER_IPV4V6 2 - -#define GPS_DELETE_ALMANAC_CORR 0x00001000 -#define GPS_DELETE_FREQ_BIAS_EST 0x00002000 -#define GPS_DELETE_EPHEMERIS_GLO 0x00004000 -#define GPS_DELETE_ALMANAC_GLO 0x00008000 -#define GPS_DELETE_SVDIR_GLO 0x00010000 -#define GPS_DELETE_SVSTEER_GLO 0x00020000 -#define GPS_DELETE_ALMANAC_CORR_GLO 0x00040000 -#define GPS_DELETE_TIME_GPS 0x00080000 -#define GPS_DELETE_TIME_GLO 0x00100000 - -/** GPS extended callback structure. */ -typedef struct { - /** set to sizeof(GpsCallbacks) */ - size_t size; - gps_set_capabilities set_capabilities_cb; - gps_acquire_wakelock acquire_wakelock_cb; - gps_release_wakelock release_wakelock_cb; - gps_create_thread create_thread_cb; - gps_request_utc_time request_utc_time_cb; -} GpsExtCallbacks; - -/** Callback to report the xtra server url to the client. - * The client should use this url when downloading xtra unless overwritten - * in the gps.conf file - */ -typedef void (* report_xtra_server)(const char*, const char*, const char*); - -/** Callback structure for the XTRA interface. */ -typedef struct { - gps_xtra_download_request download_request_cb; - gps_create_thread create_thread_cb; - report_xtra_server report_xtra_server_cb; -} GpsXtraExtCallbacks; - -/** Represents the status of AGPS. */ -typedef struct { - /** set to sizeof(AGpsExtStatus) */ - size_t size; - - AGpsExtType type; - AGpsStatusValue status; - uint32_t ipv4_addr; - char ipv6_addr[16]; - char ssid[SSID_BUF_SIZE]; - char password[SSID_BUF_SIZE]; -} AGpsExtStatus; - -/** Callback with AGPS status information. - * Can only be called from a thread created by create_thread_cb. - */ -typedef void (* agps_status_extended)(AGpsExtStatus* status); - -/** Callback structure for the AGPS interface. */ -typedef struct { - agps_status_extended status_cb; - gps_create_thread create_thread_cb; -} AGpsExtCallbacks; - - -/** GPS NI callback structure. */ -typedef struct -{ - /** - * Sends the notification request from HAL to GPSLocationProvider. - */ - gps_ni_notify_callback notify_cb; - gps_create_thread create_thread_cb; -} GpsNiExtCallbacks; - -#endif /* GPS_EXTENDED_H */ - diff --git a/loc_api/libloc_api_50001/loc.cpp b/loc_api/libloc_api_50001/loc.cpp index 4ada9072..9749703a 100644 --- a/loc_api/libloc_api_50001/loc.cpp +++ b/loc_api/libloc_api_50001/loc.cpp @@ -31,7 +31,7 @@ #define LOG_TAG "LocSvc_afw" #include -#include +#include #include #include #include @@ -43,9 +43,16 @@ #include #include #include -#include - +#include +#include #include + +namespace android { + namespace AndroidRuntime { + void* createJavaThread(const char* name, void (*start)(void *), void* arg); + } +} + //Globals defns static const ulpInterface * loc_eng_ulp_inf = NULL; static const ulpInterface * loc_eng_get_ulp_inf(void); @@ -206,7 +213,7 @@ const GpsInterface* gps_get_hardware_interface () extern "C" const GpsInterface* get_gps_interface() { unsigned int target = TARGET_DEFAULT; - if (NULL == loc_afw_data.context) { + if (NULL == loc_afw_data.adapter) { loc_eng_read_config(); //We load up libulp module at this point itself @@ -245,8 +252,8 @@ static void loc_free_msg(void* msg) void loc_ulp_msg_sender(void* loc_eng_data_p, void* msg) { - LocEngContext* loc_eng_context = (LocEngContext*)((loc_eng_data_s_type*)loc_eng_data_p)->context; - msg_q_snd((void*)loc_eng_context->ulp_q, msg, loc_free_msg); + loc_eng_data_s_type* loc_eng = (loc_eng_data_s_type*)loc_eng_data_p; + msg_q_snd(loc_eng->ulp_q, msg, loc_free_msg); } /*=========================================================================== @@ -270,25 +277,24 @@ static int loc_hal_init(void) { int retVal = -1; ENTRY_LOG(); + LOC_API_ADAPTER_EVENT_MASK_T event; -#ifdef TARGET_USES_QCOM_BSP - LOC_API_ADAPTER_EVENT_MASK_T event = - LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | - LOC_API_ADAPTER_BIT_SATELLITE_REPORT | - LOC_API_ADAPTER_BIT_IOCTL_REPORT | - LOC_API_ADAPTER_BIT_STATUS_REPORT | - LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; -#else - LOC_API_ADAPTER_EVENT_MASK_T event = - LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | - LOC_API_ADAPTER_BIT_SATELLITE_REPORT | - LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST | - LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST | - LOC_API_ADAPTER_BIT_IOCTL_REPORT | - LOC_API_ADAPTER_BIT_STATUS_REPORT | - LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | - LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; -#endif + if (loc_core::LocDualContext::hasAgpsExt()) { + event = LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT; + } else { + event = LOC_API_ADAPTER_BIT_PARSED_POSITION_REPORT | + LOC_API_ADAPTER_BIT_SATELLITE_REPORT | + LOC_API_ADAPTER_BIT_LOCATION_SERVER_REQUEST | + LOC_API_ADAPTER_BIT_ASSISTANCE_DATA_REQUEST | + LOC_API_ADAPTER_BIT_IOCTL_REPORT | + LOC_API_ADAPTER_BIT_STATUS_REPORT | + LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT | + LOC_API_ADAPTER_BIT_NI_NOTIFY_VERIFY_REQUEST; + } LocCallbacks clientCallbacks = {local_loc_cb, /* location_cb */ local_status_cb, /* status_cb */ local_sv_cb, /* sv_status_cb */ @@ -467,9 +473,9 @@ static int loc_inject_time(GpsUtcTime time, int64_t timeReference, int uncertain ENTRY_LOG(); int ret_val = 0; - #ifndef TARGET_USES_QCOM_BSP + if (loc_core::LocDualContext::hasAgpsExt()) { ret_val = loc_eng_inject_time(loc_afw_data, time, timeReference, uncertainty); - #endif + } EXIT_LOG(%d, ret_val); return ret_val; @@ -610,21 +616,21 @@ const void* loc_get_extension(const char* name) LOC_LOGD("%s:%d] For Interface = %s\n",__func__, __LINE__, name); if (strcmp(name, GPS_XTRA_INTERFACE) == 0) { - #ifndef TARGET_USES_QCOM_BSP + if (loc_core::LocDualContext::hasAgpsExt()) { ret_val = &sLocEngXTRAInterface; - #endif + } } else if (strcmp(name, AGPS_INTERFACE) == 0) { - #ifndef TARGET_USES_QCOM_BSP + if (loc_core::LocDualContext::hasAgpsExt()) { ret_val = &sLocEngAGpsInterface; - #endif + } } else if (strcmp(name, GPS_NI_INTERFACE) == 0) { - #ifndef TARGET_USES_QCOM_BSP + if (loc_core::LocDualContext::hasAgpsExt()) { ret_val = &sLocEngNiInterface; - #endif + } } else if (strcmp(name, AGPS_RIL_INTERFACE) == 0) { @@ -1022,7 +1028,7 @@ static int loc_init(GpsCallbacks* callbacks) EXIT_LOG(%d, retVal); return retVal; } - memset(&afw_cb_data, NULL, sizeof (LocCallbacks)); + memset(&afw_cb_data, 0, sizeof (afw_cb_data)); gps_loc_cb = callbacks->location_cb; afw_cb_data.status_cb = callbacks->status_cb; gps_sv_cb = callbacks->sv_status_cb; diff --git a/loc_api/libloc_api_50001/loc.h b/loc_api/libloc_api_50001/loc.h index 146063a2..334e03ee 100644 --- a/loc_api/libloc_api_50001/loc.h +++ b/loc_api/libloc_api_50001/loc.h @@ -37,28 +37,7 @@ extern "C" { #include #include #include -#include -#include "gps_extended.h" - -#define MIN_POSSIBLE_FIX_INTERVAL 1000 /* msec */ - -typedef enum loc_server_type { - LOC_AGPS_CDMA_PDE_SERVER, - LOC_AGPS_CUSTOM_PDE_SERVER, - LOC_AGPS_MPC_SERVER, - LOC_AGPS_SUPL_SERVER -} LocServerType; - -typedef enum loc_position_mode_type { - LOC_POSITION_MODE_STANDALONE, - LOC_POSITION_MODE_MS_BASED, - LOC_POSITION_MODE_MS_ASSISTED, - LOC_POSITION_MODE_RESERVED_1, - LOC_POSITION_MODE_RESERVED_2, - LOC_POSITION_MODE_RESERVED_3, - LOC_POSITION_MODE_RESERVED_4, - LOC_POSITION_MODE_RESERVED_5 -} LocPositionMode; +#include typedef void (*loc_location_cb_ext) (UlpLocation* location, void* locExt); typedef void (*loc_sv_status_cb_ext) (GpsSvStatus* sv_status, void* svExt); @@ -78,22 +57,6 @@ typedef struct { gps_request_utc_time request_utc_time_cb; } LocCallbacks; -enum loc_sess_status { - LOC_SESS_SUCCESS, - LOC_SESS_INTERMEDIATE, - LOC_SESS_FAILURE -}; - -typedef uint32_t LocPosTechMask; -#define LOC_POS_TECH_MASK_DEFAULT ((LocPosTechMask)0x00000000) -#define LOC_POS_TECH_MASK_SATELLITE ((LocPosTechMask)0x00000001) -#define LOC_POS_TECH_MASK_CELLID ((LocPosTechMask)0x00000002) -#define LOC_POS_TECH_MASK_WIFI ((LocPosTechMask)0x00000004) -#define LOC_POS_TECH_MASK_SENSORS ((LocPosTechMask)0x00000008) -#define LOC_POS_TECH_MASK_REFERENCE_LOCATION ((LocPosTechMask)0x00000010) -#define LOC_POS_TECH_MASK_INJECTED_COARSE_POSITION ((LocPosTechMask)0x00000020) -#define LOC_POS_TECH_MASK_AFLT ((LocPosTechMask)0x00000040) -#define LOC_POS_TECH_MASK_HYBRID ((LocPosTechMask)0x00000080) void loc_ulp_msg_sender(void* loc_eng_data_p, void* msg); #ifdef __cplusplus diff --git a/loc_api/libloc_api_50001/loc_eng.cpp b/loc_api/libloc_api_50001/loc_eng.cpp index db3cb3f9..ff5fd63c 100644 --- a/loc_api/libloc_api_50001/loc_eng.cpp +++ b/loc_api/libloc_api_50001/loc_eng.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,7 @@ #include #include -#include "LocApiAdapter.h" +#include #include #ifndef USE_GLIB @@ -70,6 +71,7 @@ #include #include "log_util.h" #include "platform_lib_includes.h" +#include "loc_core_log.h" #include "loc_eng_log.h" #define SUCCESS TRUE @@ -83,16 +85,10 @@ #define SAP_CONF_FILE "/etc/sap.conf" #endif -static void loc_eng_deferred_action_thread(void* context); -static void* loc_eng_create_msg_q(); -static void loc_eng_free_msg(void* msg); +using namespace loc_core; -pthread_mutex_t LocEngContext::lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t LocEngContext::cond = PTHREAD_COND_INITIALIZER; -LocEngContext* LocEngContext::me = NULL; boolean configAlreadyRead = false; unsigned int agpsStatus = 0; - loc_gps_cfg_s_type gps_conf; loc_sap_cfg_s_type sap_conf; @@ -169,60 +165,6 @@ static void loc_default_parameters(void) gps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0; } -LocEngContext::LocEngContext(gps_create_thread threadCreator) : - deferred_q((const void*)loc_eng_create_msg_q()), - - //TODO: should we conditionally create ulp msg q? - ulp_q((const void*)loc_eng_create_msg_q()), - - deferred_action_thread(threadCreator("loc_eng",loc_eng_deferred_action_thread, this)), - counter(0) -{ - LOC_LOGV("LocEngContext %d : %d pthread_id %ld\n", - getpid(), GETTID_PLATFORM_LIB_ABSTRACTION, - deferred_action_thread); -} - -LocEngContext* LocEngContext::get(gps_create_thread threadCreator) -{ - pthread_mutex_lock(&lock); - // gonna need mutex protection here... - if (NULL == me) { - me = new LocEngContext(threadCreator); - } - me->counter++; - - pthread_mutex_unlock(&lock); - return me; -} - -void LocEngContext::drop() -{ - if (deferred_action_thread != pthread_self()) { - pthread_mutex_lock(&lock); - counter--; - if (counter == 0) { - loc_eng_msg *msg(new loc_eng_msg(this, LOC_ENG_MSG_QUIT)); - msg_q_snd((void*)deferred_q, msg, loc_eng_free_msg); - - // I am not sure if this is going to be hazardous. The calling thread - // might be blocked for a while, if the q is loaded. I am wondering - // if we should just dump all the msgs in the q upon QUIT. - pthread_cond_wait(&cond, &lock); - - msg_q_destroy((void**)&deferred_q); - - msg_q_destroy((void**)&ulp_q); - - delete me; - me = NULL; - } - pthread_mutex_unlock(&lock); - } else { - LOC_LOGE("The HAL thread cannot free itself"); - } -} - // 2nd half of init(), singled out for // modem restart to use. static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data); @@ -241,7 +183,1197 @@ static void loc_eng_agps_close_status(loc_eng_data_s_type &loc_eng_data, int is_ static void loc_eng_handle_engine_down(loc_eng_data_s_type &loc_eng_data) ; static void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data) ; -static char extra_data[100]; +static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data); +static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data); + +static void deleteAidingData(loc_eng_data_s_type &logEng); +static AgpsStateMachine* +getAgpsStateMachine(loc_eng_data_s_type& logEng, AGpsExtType agpsType); + +static void loc_eng_free_msg(void* msg) +{ + delete (loc_eng_msg*)msg; +} + +static void update_aiding_data_for_deletion(loc_eng_data_s_type& loc_eng_data) { + if (loc_eng_data.engine_status != GPS_STATUS_ENGINE_ON && + loc_eng_data.aiding_data_for_deletion != 0) + { + loc_eng_data.adapter->deleteAidingData(loc_eng_data.aiding_data_for_deletion); + loc_eng_data.aiding_data_for_deletion = 0; + } +} + +static void* noProc(void* data) +{ + return NULL; +} + + +/********************************************************************* + * definitions of the static messages used in the file + *********************************************************************/ +// case LOC_ENG_MSG_REQUEST_NI: +LocEngRequestNi::LocEngRequestNi(void* locEng, + GpsNiNotification ¬if, + const void* data) : + LocMsg(), mLocEng(locEng), mNotify(notif), mPayload(data) { + locallog(); +} +void LocEngRequestNi::proc() const { + loc_eng_ni_request_handler(*((loc_eng_data_s_type*)mLocEng), + &mNotify, mPayload); +} +void LocEngRequestNi::locallog() const +{ + LOC_LOGV("id: %d\n type: %s\n flags: %d\n time out: %d\n " + "default response: %s\n requestor id encoding: %s\n" + " text encoding: %s\n passThroughData: %p", + mNotify.notification_id, + loc_get_ni_type_name(mNotify.ni_type), + mNotify.notify_flags, + mNotify.timeout, + loc_get_ni_response_name(mNotify.default_response), + loc_get_ni_encoding_name(mNotify.requestor_id_encoding), + loc_get_ni_encoding_name(mNotify.text_encoding), + mPayload); +} +inline void LocEngRequestNi::log() const { + locallog(); +} + +// case LOC_ENG_MSG_INFORM_NI_RESPONSE: +// in loc_eng_ni.cpp + +// case LOC_ENG_MSG_START_FIX: +LocEngStartFix::LocEngStartFix(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) +{ + locallog(); +} +inline void LocEngStartFix::proc() const +{ + loc_eng_start_handler(*mLocEng); +} +inline void LocEngStartFix::locallog() const +{ + LOC_LOGV("LocEngStartFix"); +} +inline void LocEngStartFix::log() const +{ + locallog(); +} +void LocEngStartFix::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_STOP_FIX: +LocEngStopFix::LocEngStopFix(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) +{ + locallog(); +} +inline void LocEngStopFix::proc() const +{ + loc_eng_stop_handler(*mLocEng); +} +inline void LocEngStopFix::locallog() const +{ + LOC_LOGV("LocEngStopFix"); +} +inline void LocEngStopFix::log() const +{ + locallog(); +} +void LocEngStopFix::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_SET_POSITION_MODE: +LocEngPositionMode::LocEngPositionMode(LocEngAdapter* adapter, + LocPosMode &mode) : + LocMsg(), mAdapter(adapter), mPosMode(mode) +{ + mPosMode.logv(); +} +inline void LocEngPositionMode::proc() const { + mAdapter->setPositionMode(&mPosMode); +} +inline void LocEngPositionMode::log() const { + mPosMode.logv(); +} +void LocEngPositionMode::send() const { + mAdapter->sendMsg(this); +} + +// case LOC_ENG_MSG_SET_TIME: +struct LocEngSetTime : public LocMsg { + LocEngAdapter* mAdapter; + const GpsUtcTime mTime; + const int64_t mTimeReference; + const int mUncertainty; + inline LocEngSetTime(LocEngAdapter* adapter, + GpsUtcTime t, int64_t tf, int unc) : + LocMsg(), mAdapter(adapter), + mTime(t), mTimeReference(tf), mUncertainty(unc) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setTime(mTime, mTimeReference, mUncertainty); + } + inline void locallog() const { + LOC_LOGV("time: %lld\n timeReference: %lld\n uncertainty: %d", + mTime, mTimeReference, mUncertainty); + } + inline virtual void log() const { + locallog(); + } +}; + + // case LOC_ENG_MSG_INJECT_LOCATION: +struct LocEngInjectLocation : public LocMsg { + LocEngAdapter* mAdapter; + const double mLatitude; + const double mLongitude; + const float mAccuracy; + inline LocEngInjectLocation(LocEngAdapter* adapter, + double lat, double lon, float accur) : + LocMsg(), mAdapter(adapter), + mLatitude(lat), mLongitude(lon), mAccuracy(accur) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->injectPosition(mLatitude, mLongitude, mAccuracy); + } + inline void locallog() const { + LOC_LOGV("latitude: %f\n longitude: %f\n accuracy: %f", + mLatitude, mLongitude, mAccuracy); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SERVER_IPV4: +struct LocEngSetServerIpv4 : public LocMsg { + LocEngAdapter* mAdapter; + const unsigned int mNlAddr; + const int mPort; + const LocServerType mServerType; + inline LocEngSetServerIpv4(LocEngAdapter* adapter, + unsigned int ip, + int port, + LocServerType type) : + LocMsg(), mAdapter(adapter), + mNlAddr(ip), mPort(port), mServerType(type) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setServer(mNlAddr, mPort, mServerType); + } + inline void locallog() const { + LOC_LOGV("LocEngSetServerIpv4 - addr: %x, port: %d, type: %s", + mNlAddr, mPort, loc_get_server_type_name(mServerType)); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SERVER_URL: +struct LocEngSetServerUrl : public LocMsg { + LocEngAdapter* mAdapter; + const int mLen; + char* mUrl; + inline LocEngSetServerUrl(LocEngAdapter* adapter, + char* urlString, + int url_len) : + LocMsg(), mAdapter(adapter), + mLen(url_len), mUrl(new char[mLen+1]) + { + memcpy((void*)mUrl, (void*)urlString, url_len); + mUrl[mLen] = 0; + locallog(); + } + inline ~LocEngSetServerUrl() + { + delete[] mUrl; + } + inline virtual void proc() const { + mAdapter->setServer(mUrl, mLen); + } + inline void locallog() const { + LOC_LOGV("LocEngSetServerUrl - url: %s", mUrl); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_A_GLONASS_PROTOCOL: +struct LocEngAGlonassProtocol : public LocMsg { + LocEngAdapter* mAdapter; + const unsigned long mAGlonassProtocl; + inline LocEngAGlonassProtocol(LocEngAdapter* adapter, + unsigned long protocol) : + LocMsg(), mAdapter(adapter), mAGlonassProtocl(protocol) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setAGLONASSProtocol(mAGlonassProtocl); + } + inline void locallog() const { + LOC_LOGV("A-GLONASS protocol: 0x%lx", mAGlonassProtocl); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SUPL_VERSION: +struct LocEngSuplVer : public LocMsg { + LocEngAdapter* mAdapter; + const int mSuplVer; + inline LocEngSuplVer(LocEngAdapter* adapter, + int suplVer) : + LocMsg(), mAdapter(adapter), mSuplVer(suplVer) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSUPLVersion(mSuplVer); + } + inline void locallog() const { + LOC_LOGV("SUPL Version: %d", mSuplVer); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_LPP_CONFIG: +struct LocEngLppConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mLppConfig; + inline LocEngLppConfig(LocEngAdapter* adapter, + int lppConfig) : + LocMsg(), mAdapter(adapter), mLppConfig(lppConfig) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setLPPConfig(mLppConfig); + } + inline void locallog() const { + LOC_LOGV("LocEngLppConfig - profile: %d", mLppConfig); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG: +struct LocEngSensorControlConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mSensorsDisabled; + inline LocEngSensorControlConfig(LocEngAdapter* adapter, + int sensorsDisabled) : + LocMsg(), mAdapter(adapter), mSensorsDisabled(sensorsDisabled) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorControlConfig(mSensorsDisabled); + } + inline void locallog() const { + LOC_LOGV("LocEngSensorControlConfig - Sensors Disabled: %d", + mSensorsDisabled); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_PROPERTIES: +struct LocEngSensorProperties : public LocMsg { + LocEngAdapter* mAdapter; + const bool mGyroBiasVarianceRandomWalkValid; + const float mGyroBiasVarianceRandomWalk; + const bool mAccelRandomWalkValid; + const float mAccelRandomWalk; + const bool mAngleRandomWalkValid; + const float mAngleRandomWalk; + const bool mRateRandomWalkValid; + const float mRateRandomWalk; + const bool mVelocityRandomWalkValid; + const float mVelocityRandomWalk; + inline LocEngSensorProperties(LocEngAdapter* adapter, + bool gyroBiasRandomWalk_valid, + float gyroBiasRandomWalk, + bool accelRandomWalk_valid, + float accelRandomWalk, + bool angleRandomWalk_valid, + float angleRandomWalk, + bool rateRandomWalk_valid, + float rateRandomWalk, + bool velocityRandomWalk_valid, + float velocityRandomWalk) : + LocMsg(), mAdapter(adapter), + mGyroBiasVarianceRandomWalkValid(gyroBiasRandomWalk_valid), + mGyroBiasVarianceRandomWalk(gyroBiasRandomWalk), + mAccelRandomWalkValid(accelRandomWalk_valid), + mAccelRandomWalk(accelRandomWalk), + mAngleRandomWalkValid(angleRandomWalk_valid), + mAngleRandomWalk(angleRandomWalk), + mRateRandomWalkValid(rateRandomWalk_valid), + mRateRandomWalk(rateRandomWalk), + mVelocityRandomWalkValid(velocityRandomWalk_valid), + mVelocityRandomWalk(velocityRandomWalk) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorProperties(mGyroBiasVarianceRandomWalkValid, + mGyroBiasVarianceRandomWalk, + mAccelRandomWalkValid, + mAccelRandomWalk, + mAngleRandomWalkValid, + mAngleRandomWalk, + mRateRandomWalkValid, + mRateRandomWalk, + mVelocityRandomWalkValid, + mVelocityRandomWalk); + } + inline void locallog() const { + LOC_LOGV("Sensor properties validity, Gyro Random walk: %d " + "Accel Random Walk: %d " + "Angle Random Walk: %d Rate Random Walk: %d " + "Velocity Random Walk: %d\n" + "Sensor properties, Gyro Random walk: %f " + "Accel Random Walk: %f " + "Angle Random Walk: %f Rate Random Walk: %f " + "Velocity Random Walk: %f", + mGyroBiasVarianceRandomWalkValid, + mAccelRandomWalkValid, + mAngleRandomWalkValid, + mRateRandomWalkValid, + mVelocityRandomWalkValid, + mGyroBiasVarianceRandomWalk, + mAccelRandomWalk, + mAngleRandomWalk, + mRateRandomWalk, + mVelocityRandomWalk + ); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG: +struct LocEngSensorPerfControlConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mControlMode; + const int mAccelSamplesPerBatch; + const int mAccelBatchesPerSec; + const int mGyroSamplesPerBatch; + const int mGyroBatchesPerSec; + const int mAccelSamplesPerBatchHigh; + const int mAccelBatchesPerSecHigh; + const int mGyroSamplesPerBatchHigh; + const int mGyroBatchesPerSecHigh; + const int mAlgorithmConfig; + inline LocEngSensorPerfControlConfig(LocEngAdapter* adapter, + int controlMode, + int accelSamplesPerBatch, + int accelBatchesPerSec, + int gyroSamplesPerBatch, + int gyroBatchesPerSec, + int accelSamplesPerBatchHigh, + int accelBatchesPerSecHigh, + int gyroSamplesPerBatchHigh, + int gyroBatchesPerSecHigh, + int algorithmConfig) : + LocMsg(), mAdapter(adapter), + mControlMode(controlMode), + mAccelSamplesPerBatch(accelSamplesPerBatch), + mAccelBatchesPerSec(accelBatchesPerSec), + mGyroSamplesPerBatch(gyroSamplesPerBatch), + mGyroBatchesPerSec(gyroBatchesPerSec), + mAccelSamplesPerBatchHigh(accelSamplesPerBatchHigh), + mAccelBatchesPerSecHigh(accelBatchesPerSecHigh), + mGyroSamplesPerBatchHigh(gyroSamplesPerBatchHigh), + mGyroBatchesPerSecHigh(gyroBatchesPerSecHigh), + mAlgorithmConfig(algorithmConfig) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setSensorPerfControlConfig(mControlMode, + mAccelSamplesPerBatch, + mAccelBatchesPerSec, + mGyroSamplesPerBatch, + mGyroBatchesPerSec, + mAccelSamplesPerBatchHigh, + mAccelBatchesPerSecHigh, + mGyroSamplesPerBatchHigh, + mGyroBatchesPerSecHigh, + mAlgorithmConfig); + } + inline void locallog() const { + LOC_LOGV("Sensor Perf Control Config (performanceControlMode)(%u) " + "accel(#smp,#batches) (%u,%u) " + "gyro(#smp,#batches) (%u,%u), " + "accel_high(#smp,#batches) (%u,%u) " + "gyro_high(#smp,#batches) (%u,%u), " + "algorithmConfig(%u)\n", + mControlMode, + mAccelSamplesPerBatch, mAccelBatchesPerSec, + mGyroSamplesPerBatch, mGyroBatchesPerSec, + mAccelSamplesPerBatchHigh, mAccelBatchesPerSecHigh, + mGyroSamplesPerBatchHigh, mGyroBatchesPerSecHigh, + mAlgorithmConfig); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_EXT_POWER_CONFIG: +struct LocEngExtPowerConfig : public LocMsg { + LocEngAdapter* mAdapter; + const int mIsBatteryCharging; + inline LocEngExtPowerConfig(LocEngAdapter* adapter, + int isBatteryCharging) : + LocMsg(), mAdapter(adapter), + mIsBatteryCharging(isBatteryCharging) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->setExtPowerConfig(mIsBatteryCharging); + } + inline void locallog() const { + LOC_LOGV("LocEngExtPowerConfig - isBatteryCharging: %d", + mIsBatteryCharging); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_REPORT_POSITION: +LocEngReportPosition::LocEngReportPosition(void* locEng, + UlpLocation &loc, + GpsLocationExtended &locExtended, + void* locExt, + enum loc_sess_status st, + LocPosTechMask technology) : + LocMsg(), mLocEng(locEng), mLocation(loc), + mLocationExtended(locExtended), + mLocationExt(((loc_eng_data_s_type*)mLocEng)->location_ext_parser(locExt)), + mStatus(st), mTechMask(technology) +{ + locallog(); +} +void LocEngReportPosition::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + + if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) { + bool reported = false; + if (locEng->location_cb != NULL) { + if (LOC_SESS_FAILURE == mStatus) { + // in case we want to handle the failure case + locEng->location_cb(NULL, NULL); + reported = true; + } + // what's in the else if is... (line by line) + // 1. this is a final fix; and + // 1.1 it is a Satellite fix; or + // 1.2 it is a sensor fix + // 2. (must be intermediate fix... implicit) + // 2.1 we accepte intermediate; and + // 2.2 it is NOT the case that + // 2.2.1 there is inaccuracy; and + // 2.2.2 we care about inaccuracy; and + // 2.2.3 the inaccuracy exceeds our tolerance + else if ((LOC_SESS_SUCCESS == mStatus && + ((LOC_POS_TECH_MASK_SATELLITE | + LOC_POS_TECH_MASK_SENSORS) & + mTechMask)) || + (LOC_SESS_INTERMEDIATE == locEng->intermediateFix && + !((mLocation.gpsLocation.flags & + GPS_LOCATION_HAS_ACCURACY) && + (gps_conf.ACCURACY_THRES != 0) && + (mLocation.gpsLocation.accuracy > + gps_conf.ACCURACY_THRES)))) { + locEng->location_cb((UlpLocation*)&(mLocation), + (void*)mLocationExt); + reported = true; + } + } + + // if we have reported this fix + if (reported && + // and if this is a singleshot + GPS_POSITION_RECURRENCE_SINGLE == + locEng->adapter->getPositionMode().recurrence) { + if (LOC_SESS_INTERMEDIATE == mStatus) { + // modem could be still working for a final fix, + // although we no longer need it. So stopFix(). + locEng->adapter->stopFix(); + } + // turn off the session flag. + locEng->adapter->setInSession(false); + } + + if (locEng->generateNmea && + mLocation.position_source == ULP_LOCATION_IS_FROM_GNSS) + { + unsigned char generate_nmea = reported && + (mStatus != LOC_SESS_FAILURE); + loc_eng_nmea_generate_pos(locEng, mLocation, mLocationExtended, + generate_nmea); + } + + // Free the allocated memory for rawData + UlpLocation* gp = (UlpLocation*)&(mLocation); + if (gp != NULL && gp->rawData != NULL) + { + delete (char*)gp->rawData; + gp->rawData = NULL; + gp->rawDataSize = 0; + } + } +} +void LocEngReportPosition::locallog() const { + LOC_LOGV("flags: %d\n source: %d\n latitude: %f\n longitude: %f\n " + "altitude: %f\n speed: %f\n bearing: %f\n accuracy: %f\n " + "timestamp: %lld\n rawDataSize: %d\n rawData: %p\n Session" + " status: %d\n Technology mask: %u", + mLocation.gpsLocation.flags, mLocation.position_source, + mLocation.gpsLocation.latitude, mLocation.gpsLocation.longitude, + mLocation.gpsLocation.altitude, mLocation.gpsLocation.speed, + mLocation.gpsLocation.bearing, mLocation.gpsLocation.accuracy, + mLocation.gpsLocation.timestamp, mLocation.rawDataSize, + mLocation.rawData, mStatus, mTechMask); +} +void LocEngReportPosition::log() const { + locallog(); +} +void LocEngReportPosition::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + + +// case LOC_ENG_MSG_REPORT_SV: +LocEngReportSv::LocEngReportSv(void* locEng, + GpsSvStatus &sv, + GpsLocationExtended &locExtended, + void* svExt) : + LocMsg(), mLocEng(locEng), mSvStatus(sv), + mLocationExtended(locExtended), + mSvExt(((loc_eng_data_s_type*)mLocEng)->sv_ext_parser(svExt)) +{ + locallog(); +} +void LocEngReportSv::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + + if (locEng->mute_session_state != LOC_MUTE_SESS_IN_SESSION) + { + if (locEng->sv_status_cb != NULL) { + locEng->sv_status_cb((GpsSvStatus*)&(mSvStatus), + (void*)mSvExt); + } + + if (locEng->generateNmea) + { + loc_eng_nmea_generate_sv(locEng, mSvStatus, mLocationExtended); + } + } +} +void LocEngReportSv::locallog() const { + LOC_LOGV("num sv: %d\n ephemeris mask: %dxn almanac mask: %x\n " + "used in fix mask: %x\n sv: prn snr " + "elevation azimuth", + mSvStatus.num_svs, mSvStatus.ephemeris_mask, + mSvStatus.almanac_mask, mSvStatus.used_in_fix_mask); + for (int i = 0; i < mSvStatus.num_svs && i < GPS_MAX_SVS; i++) { + LOC_LOGV(" %d: %d %f %f %f\n ", + i, + mSvStatus.sv_list[i].prn, + mSvStatus.sv_list[i].snr, + mSvStatus.sv_list[i].elevation, + mSvStatus.sv_list[i].azimuth); + } +} +inline void LocEngReportSv::log() const { + locallog(); +} +void LocEngReportSv::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_REPORT_STATUS: +LocEngReportStatus::LocEngReportStatus(void* locEng, + GpsStatusValue engineStatus) : + LocMsg(), mLocEng(locEng), mStatus(engineStatus) +{ + locallog(); +} +inline void LocEngReportStatus::proc() const +{ + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + + loc_eng_report_status(*locEng, mStatus); + update_aiding_data_for_deletion(*locEng); +} +inline void LocEngReportStatus::locallog() const { + LOC_LOGV("LocEngReportStatus"); +} +inline void LocEngReportStatus::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REPORT_NMEA: +LocEngReportNmea::LocEngReportNmea(void* locEng, + const char* data, int len) : + LocMsg(), mLocEng(locEng), mNmea(new char[len]), mLen(len) +{ + memcpy((void*)mNmea, (void*)data, len); + locallog(); +} +void LocEngReportNmea::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*) mLocEng; + + struct timeval tv; + gettimeofday(&tv, (struct timezone *) NULL); + int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000; + CALLBACK_LOG_CALLFLOW("nmea_cb", %d, mLen); + locEng->nmea_cb(now, mNmea, mLen); +} +inline void LocEngReportNmea::locallog() const { + LOC_LOGV("LocEngReportNmea"); +} +inline void LocEngReportNmea::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REPORT_XTRA_SERVER: +LocEngReportXtraServer::LocEngReportXtraServer(void* locEng, + const char *url1, + const char *url2, + const char *url3, + const int maxlength) : + LocMsg(), mLocEng(locEng), mMaxLen(maxlength), + mServers(new char[3*(mMaxLen+1)]) +{ + strlcpy(mServers, url1, mMaxLen); + strlcpy(&mServers[mMaxLen], url2, mMaxLen); + strlcpy(&mServers[mMaxLen<<1], url3, mMaxLen); + locallog(); +} +void LocEngReportXtraServer::proc() const { + loc_eng_xtra_data_s_type* locEngXtra = + &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data); + + if (locEngXtra->report_xtra_server_cb != NULL) { + CALLBACK_LOG_CALLFLOW("report_xtra_server_cb", %s, mServers); + locEngXtra->report_xtra_server_cb(mServers, + &mServers[mMaxLen], + &mServers[mMaxLen<<1]); + } else { + LOC_LOGE("Callback function for request xtra is NULL"); + } +} +inline void LocEngReportXtraServer::locallog() const { + LOC_LOGV("LocEngReportXtraServers: server1: %s\n server2: %s\n" + " server3: %s\n", + mServers, &mServers[mMaxLen], &mServers[mMaxLen<<1]); +} +inline void LocEngReportXtraServer::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_BIT: +// case LOC_ENG_MSG_RELEASE_BIT: +LocEngReqRelBIT::LocEngReqRelBIT(void* locEng, AGpsExtType type, + int ipv4, char* ipv6, bool isReq) : + LocMsg(), mLocEng(locEng), mType(type), mIPv4Addr(ipv4), + mIPv6Addr(ipv6 ? new char[16] : NULL), mIsReq(isReq) { + if (NULL != ipv6) + memcpy(mIPv6Addr, ipv6, 16); + locallog(); +} +inline LocEngReqRelBIT::~LocEngReqRelBIT() { + if (mIPv6Addr) { + delete[] mIPv6Addr; + } +} +void LocEngReqRelBIT::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + BITSubscriber s(getAgpsStateMachine(*locEng, mType), + mIPv4Addr, mIPv6Addr); + AgpsStateMachine* sm = (AgpsStateMachine*)s.mStateMachine; + + if (mIsReq) { + sm->subscribeRsrc((Subscriber*)&s); + } else { + sm->unsubscribeRsrc((Subscriber*)&s); + } +} +inline void LocEngReqRelBIT::locallog() const { + LOC_LOGV("LocEngRequestBIT - ipv4: %d.%d.%d.%d, ipv6: %s", + (unsigned char)(mIPv4Addr>>24), + (unsigned char)(mIPv4Addr>>16), + (unsigned char)(mIPv4Addr>>8), + (unsigned char)mIPv4Addr, + NULL != mIPv6Addr ? mIPv6Addr : ""); +} +inline void LocEngReqRelBIT::log() const { + locallog(); +} +void LocEngReqRelBIT::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_RELEASE_BIT: +struct LocEngReleaseBIT : public LocMsg { + const BITSubscriber mSubscriber; + inline LocEngReleaseBIT(const AgpsStateMachine* stateMachine, + unsigned int ipv4, char* ipv6) : + LocMsg(), + mSubscriber(stateMachine, ipv4, ipv6) + { + locallog(); + } + inline virtual void proc() const + { + AgpsStateMachine* sm = (AgpsStateMachine*)mSubscriber.mStateMachine; + sm->unsubscribeRsrc((Subscriber*)&mSubscriber); + } + inline void locallog() const { + LOC_LOGV("LocEngReleaseBIT - ipv4: %d.%d.%d.%d, ipv6: %s", + (unsigned char)(mSubscriber.ID>>24), + (unsigned char)(mSubscriber.ID>>16), + (unsigned char)(mSubscriber.ID>>8), + (unsigned char)mSubscriber.ID, + NULL != mSubscriber.mIPv6Addr ? mSubscriber.mIPv6Addr : ""); + } + virtual void log() const { + locallog(); + } +}; + +// LocEngSuplEsOpened +LocEngSuplEsOpened::LocEngSuplEsOpened(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +void LocEngSuplEsOpened::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + AgpsStateMachine* sm = locEng->ds_nif; + sm->onRsrcEvent(RSRC_GRANTED); +} +void LocEngSuplEsOpened::locallog() const { + LOC_LOGV("LocEngSuplEsOpened"); +} +void LocEngSuplEsOpened::log() const { + locallog(); +} + +// LocEngSuplEsClosed +LocEngSuplEsClosed::LocEngSuplEsClosed(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +void LocEngSuplEsClosed::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + AgpsStateMachine* sm = locEng->ds_nif; + sm->onRsrcEvent(RSRC_RELEASED); +} +void LocEngSuplEsClosed::locallog() const { + LOC_LOGV("LocEngSuplEsClosed"); +} +void LocEngSuplEsClosed::log() const { + locallog(); +} + + +// case LOC_ENG_MSG_REQUEST_SUPL_ES: +LocEngRequestSuplEs::LocEngRequestSuplEs(void* locEng, int id) : + LocMsg(), mLocEng(locEng), mID(id) { + locallog(); +} +void LocEngRequestSuplEs::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + AgpsStateMachine* sm = locEng->ds_nif; + DSSubscriber s(sm, mID); + sm->subscribeRsrc((Subscriber*)&s); +} +inline void LocEngRequestSuplEs::locallog() const { + LOC_LOGV("LocEngRequestSuplEs"); +} +inline void LocEngRequestSuplEs::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_ATL: +LocEngRequestATL::LocEngRequestATL(void* locEng, int id, + AGpsExtType agps_type) : + LocMsg(), mLocEng(locEng), mID(id), mType(agps_type) { + locallog(); +} +void LocEngRequestATL::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + AgpsStateMachine* sm = (AgpsStateMachine*) + getAgpsStateMachine(*locEng, mType); + ATLSubscriber s(mID, + sm, + locEng->adapter, + AGPS_TYPE_INVALID == mType); + sm->subscribeRsrc((Subscriber*)&s); +} +inline void LocEngRequestATL::locallog() const { + LOC_LOGV("LocEngRequestATL"); +} +inline void LocEngRequestATL::log() const { + locallog(); +} + +// case LOC_ENG_MSG_RELEASE_ATL: +LocEngReleaseATL::LocEngReleaseATL(void* locEng, int id) : + LocMsg(), mLocEng(locEng), mID(id) { + locallog(); +} +void LocEngReleaseATL::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + ATLSubscriber s1(mID, locEng->agnss_nif, locEng->adapter, false); + if (locEng->agnss_nif->unsubscribeRsrc((Subscriber*)&s1)) { + LOC_LOGD("%s:%d]: Unsubscribed from agnss_nif", + __func__, __LINE__); + } else { + ATLSubscriber s2(mID, locEng->internet_nif, locEng->adapter, false); + if (locEng->internet_nif->unsubscribeRsrc((Subscriber*)&s2)) { + LOC_LOGD("%s:%d]: Unsubscribed from internet_nif", + __func__, __LINE__); + } else { + DSSubscriber s3(locEng->ds_nif, mID); + if(locEng->ds_nif->unsubscribeRsrc((Subscriber*)&s3)) { + LOC_LOGD("%s:%d]: Unsubscribed from ds_nif", + __func__, __LINE__); + } else { + LOC_LOGW("%s:%d]: Could not release ATL. " + "No subscribers found\n", + __func__, __LINE__); + locEng->adapter->atlCloseStatus(mID, 0); + } + } + } +} +inline void LocEngReleaseATL::locallog() const { + LOC_LOGV("LocEngReleaseATL"); +} +inline void LocEngReleaseATL::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_WIFI: +// case LOC_ENG_MSG_RELEASE_WIFI: +LocEngReqRelWifi::LocEngReqRelWifi(void* locEng, AGpsExtType type, + loc_if_req_sender_id_e_type sender_id, + char* s, char* p, bool isReq) : + LocMsg(), mLocEng(locEng), mType(type), mSenderId(sender_id), + mSSID(NULL == s ? NULL : new char[SSID_BUF_SIZE]), + mPassword(NULL == p ? NULL : new char[SSID_BUF_SIZE]), + mIsReq(isReq) { + if (NULL != s) + strlcpy(mSSID, s, SSID_BUF_SIZE); + if (NULL != p) + strlcpy(mPassword, p, SSID_BUF_SIZE); + locallog(); +} +LocEngReqRelWifi::~LocEngReqRelWifi() { + if (NULL != mSSID) { + delete[] mSSID; + } + if (NULL != mPassword) { + delete[] mPassword; + } +} +void LocEngReqRelWifi::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + WIFISubscriber s(locEng->wifi_nif, mSSID, mPassword, mSenderId); + if (mIsReq) { + locEng->wifi_nif->subscribeRsrc((Subscriber*)&s); + } else { + locEng->wifi_nif->unsubscribeRsrc((Subscriber*)&s); + } +} +inline void LocEngReqRelWifi::locallog() const { + LOC_LOGV("%s - senderId: %d, ssid: %s, password: %s", + mIsReq ? "LocEngRequestWifi" : "LocEngReleaseWifi", + mSenderId, + NULL != mSSID ? mSSID : "", + NULL != mPassword ? mPassword : ""); +} +inline void LocEngReqRelWifi::log() const { + locallog(); +} +void LocEngReqRelWifi::send() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + locEng->adapter->sendMsg(this); +} + +// case LOC_ENG_MSG_REQUEST_XTRA_DATA: +LocEngRequestXtra::LocEngRequestXtra(void* locEng) : + mLocEng(locEng) { + locallog(); +} +void LocEngRequestXtra::proc() const +{ + loc_eng_xtra_data_s_type* locEngXtra = + &(((loc_eng_data_s_type*)mLocEng)->xtra_module_data); + + if (locEngXtra->download_request_cb != NULL) { + CALLBACK_LOG_CALLFLOW("download_request_cb", %p, mLocEng); + locEngXtra->download_request_cb(); + } else { + LOC_LOGE("Callback function for request xtra is NULL"); + } +} +inline void LocEngRequestXtra::locallog() const { + LOC_LOGV("LocEngReqXtra"); +} +inline void LocEngRequestXtra::log() const { + locallog(); +} + +// case LOC_ENG_MSG_REQUEST_TIME: +LocEngRequestTime::LocEngRequestTime(void* locEng) : + LocMsg(), mLocEng(locEng) +{ + locallog(); +} +void LocEngRequestTime::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + if (locEng->request_utc_time_cb != NULL) { + locEng->request_utc_time_cb(); + } else { + LOC_LOGE("Callback function for request time is NULL"); + } +} +inline void LocEngRequestTime::locallog() const { + LOC_LOGV("LocEngReqTime"); +} +inline void LocEngRequestTime::log() const { + locallog(); +} + +// case LOC_ENG_MSG_DELETE_AIDING_DATA: +struct LocEngDelAidData : public LocMsg { + loc_eng_data_s_type* mLocEng; + const GpsAidingData mType; + inline LocEngDelAidData(loc_eng_data_s_type* locEng, + GpsAidingData f) : + LocMsg(), mLocEng(locEng), mType(f) + { + locallog(); + } + inline virtual void proc() const { + mLocEng->aiding_data_for_deletion = mType; + update_aiding_data_for_deletion(*mLocEng); + } + inline void locallog() const { + LOC_LOGV("aiding data msak %d", mType); + } + virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ENABLE_DATA: +struct LocEngEnableData : public LocMsg { + LocEngAdapter* mAdapter; + const int mEnable; + char* mAPN; + const int mLen; + inline LocEngEnableData(LocEngAdapter* adapter, + const char* name, int len, int enable) : + LocMsg(), mAdapter(adapter), + mEnable(enable), mAPN(NULL), mLen(len) + { + if (NULL != name) { + mAPN = new char[len+1]; + memcpy((void*)mAPN, (void*)name, len); + mAPN[len] = 0; + } + locallog(); + } + inline ~LocEngEnableData() { + if (NULL != mAPN) { + delete[] mAPN; + } + } + inline virtual void proc() const { + mAdapter->enableData(mEnable); + if (NULL != mAPN) { + mAdapter->setAPN(mAPN, mLen); + } + } + inline void locallog() const { + LOC_LOGV("apn: %s\n enable: %d", + (NULL == mAPN) ? "NULL" : mAPN, mEnable); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_INJECT_XTRA_DATA: +// loc_eng_xtra.cpp + +// case LOC_ENG_MSG_LOC_INIT: +struct LocEngInit : public LocMsg { + loc_eng_data_s_type* mLocEng; + inline LocEngInit(loc_eng_data_s_type* locEng) : + LocMsg(), mLocEng(locEng) + { + locallog(); + } + inline virtual void proc() const { + loc_eng_reinit(*mLocEng); + } + inline void locallog() const + { + LOC_LOGV("LocEngInit"); + } + inline virtual void log() const + { + locallog(); + } +}; + +// case LOC_ENG_MSG_REQUEST_XTRA_SERVER: +// loc_eng_xtra.cpp + +// case LOC_ENG_MSG_ATL_OPEN_SUCCESS: +struct LocEngAtlOpenSuccess : public LocMsg { + AgpsStateMachine* mStateMachine; + const int mLen; + char* mAPN; + const AGpsBearerType mBearerType; + inline LocEngAtlOpenSuccess(AgpsStateMachine* statemachine, + const char* name, + int len, + AGpsBearerType btype) : + LocMsg(), + mStateMachine(statemachine), mLen(len), + mAPN(new char[len+1]), mBearerType(btype) + { + memcpy((void*)mAPN, (void*)name, len); + mAPN[len] = 0; + locallog(); + } + inline ~LocEngAtlOpenSuccess() + { + delete[] mAPN; + } + inline virtual void proc() const { + mStateMachine->setBearer(mBearerType); + mStateMachine->setAPN(mAPN, mLen); + mStateMachine->onRsrcEvent(RSRC_GRANTED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlClosed agps type: %s\n apn: %s\n" + " bearer type: %s", + loc_get_agps_type_name(mStateMachine->getType()), + mAPN, + loc_get_agps_bear_name(mBearerType)); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ATL_CLOSED: +struct LocEngAtlClosed : public LocMsg { + AgpsStateMachine* mStateMachine; + inline LocEngAtlClosed(AgpsStateMachine* statemachine) : + LocMsg(), mStateMachine(statemachine) { + locallog(); + } + inline virtual void proc() const { + mStateMachine->onRsrcEvent(RSRC_RELEASED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlClosed"); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ATL_OPEN_FAILED: +struct LocEngAtlOpenFailed : public LocMsg { + AgpsStateMachine* mStateMachine; + inline LocEngAtlOpenFailed(AgpsStateMachine* statemachine) : + LocMsg(), mStateMachine(statemachine) { + locallog(); + } + inline virtual void proc() const { + mStateMachine->onRsrcEvent(RSRC_DENIED); + } + inline void locallog() const { + LOC_LOGV("LocEngAtlOpenFailed"); + } + inline virtual void log() const { + locallog(); + } +}; + +// case LOC_ENG_MSG_ENGINE_DOWN: +LocEngDown::LocEngDown(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +inline void LocEngDown::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + loc_eng_handle_engine_down(*locEng); +} +inline void LocEngDown::locallog() const { + LOC_LOGV("LocEngDown"); +} +inline void LocEngDown::log() const { + locallog(); +} + +// case LOC_ENG_MSG_ENGINE_UP: +LocEngUp::LocEngUp(void* locEng) : + LocMsg(), mLocEng(locEng) { + locallog(); +} +inline void LocEngUp::proc() const { + loc_eng_data_s_type* locEng = (loc_eng_data_s_type*)mLocEng; + loc_eng_handle_engine_up(*locEng); +} +inline void LocEngUp::locallog() const { + LOC_LOGV("LocEngUp"); +} +inline void LocEngUp::log() const { + locallog(); +} + /********************************************************************* * Initialization checking macros *********************************************************************/ @@ -255,27 +1387,6 @@ static char extra_data[100]; } #define INIT_CHECK(ctx, ret) STATE_CHECK(ctx, "instance not initialized", ret) -void loc_eng_msg_sender(void* loc_eng_data_p, void* msg) -{ - LocEngContext* loc_eng_context = (LocEngContext*)((loc_eng_data_s_type*)loc_eng_data_p)->context; - msg_q_snd((void*)loc_eng_context->deferred_q, msg, loc_eng_free_msg); -} - -static void* loc_eng_create_msg_q() -{ - void* q = NULL; - if (eMSG_Q_SUCCESS != msg_q_init(&q)) { - LOC_LOGE("loc_eng_create_msg_q Q init failed."); - q = NULL; - } - return q; -} - -static void loc_eng_free_msg(void* msg) -{ - delete (loc_eng_msg*)msg; -} - /*=========================================================================== FUNCTION loc_eng_init @@ -308,15 +1419,11 @@ int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, return ret_val; } - STATE_CHECK((NULL == loc_eng_data.context), + STATE_CHECK((NULL == loc_eng_data.adapter), "instance already initialized", return 0); memset(&loc_eng_data, 0, sizeof (loc_eng_data)); - // Create context (msg q + thread) (if not yet created) - // This will also parse gps.conf, if not done. - loc_eng_data.context = (void*)LocEngContext::get(callbacks->create_thread_cb); - // Save callbacks loc_eng_data.location_cb = callbacks->location_cb; loc_eng_data.sv_status_cb = callbacks->sv_status_cb; @@ -325,6 +1432,10 @@ int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, loc_eng_data.acquire_wakelock_cb = callbacks->acquire_wakelock_cb; loc_eng_data.release_wakelock_cb = callbacks->release_wakelock_cb; loc_eng_data.request_utc_time_cb = callbacks->request_utc_time_cb; + loc_eng_data.location_ext_parser = callbacks->location_ext_parser ? + callbacks->location_ext_parser : noProc; + loc_eng_data.sv_ext_parser = callbacks->sv_ext_parser ? + callbacks->sv_ext_parser : noProc; loc_eng_data.intermediateFix = gps_conf.INTERMEDIATE_POS; // initial states taken care of by the memset above @@ -342,22 +1453,15 @@ int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, loc_eng_data.generateNmea = false; } - LocEng locEngHandle(&loc_eng_data, event, loc_eng_data.acquire_wakelock_cb, - loc_eng_data.release_wakelock_cb, loc_eng_msg_sender, loc_external_msg_sender, - callbacks->location_ext_parser, callbacks->sv_ext_parser); - loc_eng_data.client_handle = LocApiAdapter::getLocApiAdapter(locEngHandle); + loc_eng_data.adapter = + new LocEngAdapter(event, &loc_eng_data, + loc_external_msg_sender, + (MsgTask::tCreate)callbacks->create_thread_cb); - if (NULL == loc_eng_data.client_handle) { - // drop the context and declare failure - ((LocEngContext*)(loc_eng_data.context))->drop(); - loc_eng_data.context = NULL; - } else { - LOC_LOGD("loc_eng_init created client, id = %p\n", loc_eng_data.client_handle); + LOC_LOGD("loc_eng_init created client, id = %p\n", + loc_eng_data.adapter); - /*send reinit event to QMI instead of call reinit directly*/ - loc_eng_msg *msg(new loc_eng_msg(locEngHandle.owner, LOC_ENG_MSG_LOC_INIT)); - locEngHandle.sendMsge(locEngHandle.owner, msg); - } + loc_eng_data.adapter->sendMsg(new LocEngInit(&loc_eng_data)); EXIT_LOG(%d, ret_val); return ret_val; @@ -366,30 +1470,16 @@ int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data) { ENTRY_LOG(); - int ret_val = loc_eng_data.client_handle->reinit(); + int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; if (LOC_API_ADAPTER_ERR_SUCCESS == ret_val) { LOC_LOGD("loc_eng_reinit reinit() successful"); - loc_eng_msg_suple_version *supl_msg(new loc_eng_msg_suple_version(&loc_eng_data, - gps_conf.SUPL_VER)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - supl_msg, loc_eng_free_msg); - - loc_eng_msg_lpp_config *lpp_msg(new loc_eng_msg_lpp_config(&loc_eng_data, - gps_conf.LPP_PROFILE)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - lpp_msg, loc_eng_free_msg); - - loc_eng_msg_sensor_control_config *sensor_control_config_msg( - new loc_eng_msg_sensor_control_config(&loc_eng_data, sap_conf.SENSOR_USAGE)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - sensor_control_config_msg, loc_eng_free_msg); - - loc_eng_msg_a_glonass_protocol *a_glonass_protocol_msg(new loc_eng_msg_a_glonass_protocol(&loc_eng_data, - gps_conf.A_GLONASS_POS_PROTOCOL_SELECT)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - a_glonass_protocol_msg, loc_eng_free_msg); + 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 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. */ if( sap_conf.GYRO_BIAS_RANDOM_WALK_VALID || @@ -398,43 +1488,32 @@ static int loc_eng_reinit(loc_eng_data_s_type &loc_eng_data) sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID || sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) { - loc_eng_msg_sensor_properties *sensor_properties_msg( - new loc_eng_msg_sensor_properties(&loc_eng_data, - sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, - sap_conf.GYRO_BIAS_RANDOM_WALK, - sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, - sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, - sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, - sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, - sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, - sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, - sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, - sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - sensor_properties_msg, loc_eng_free_msg); + adapter->sendMsg(new LocEngSensorProperties(adapter, + sap_conf.GYRO_BIAS_RANDOM_WALK_VALID, + sap_conf.GYRO_BIAS_RANDOM_WALK, + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, + sap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY)); } - loc_eng_msg_sensor_perf_control_config *sensor_perf_control_conf_msg( - new loc_eng_msg_sensor_perf_control_config(&loc_eng_data, - sap_conf.SENSOR_CONTROL_MODE, - sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, - sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, - sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, - sap_conf.SENSOR_GYRO_BATCHES_PER_SEC, - sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, - sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, - sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, - sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, - sap_conf.SENSOR_ALGORITHM_CONFIG_MASK)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - sensor_perf_control_conf_msg, loc_eng_free_msg); + adapter->sendMsg(new LocEngSensorPerfControlConfig(adapter, + sap_conf.SENSOR_CONTROL_MODE, + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC, + sap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, + sap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, + sap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, + sap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, + sap_conf.SENSOR_ALGORITHM_CONFIG_MASK)); - //Send data disable to modem. This will be set to enable when - //an UPDATE_NETWORK_STATE event is received from Android - loc_eng_msg_set_data_enable *msg(new loc_eng_msg_set_data_enable(&loc_eng_data, NULL, - 0, (agpsStatus ? 1:0))); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + adapter->sendMsg(new LocEngEnableData(adapter, NULL, 0, (agpsStatus ? 1:0))); } EXIT_LOG(%d, ret_val); @@ -460,7 +1539,7 @@ SIDE EFFECTS void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return); + INIT_CHECK(loc_eng_data.adapter, return); // XTRA has no state, so we are fine with it. @@ -476,7 +1555,7 @@ void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data) loc_eng_data.internet_nif = NULL; } #endif - if (loc_eng_data.client_handle->isInSession()) + if (loc_eng_data.adapter->isInSession()) { LOC_LOGD("loc_eng_cleanup: fix not stopped. stop it now."); loc_eng_stop(loc_eng_data); @@ -484,9 +1563,6 @@ void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data) #if 0 // can't afford to actually clean up, for many reason. - ((LocEngContext*)(loc_eng_data.context))->drop(); - loc_eng_data.context = NULL; - // De-initialize ulp if (locEngUlpInf != NULL) { @@ -494,12 +1570,9 @@ void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data) msg_q_destroy( &loc_eng_data.ulp_q); } - if (loc_eng_data.client_handle != NULL) - { - LOC_LOGD("loc_eng_init: client opened. close it now."); - delete loc_eng_data.client_handle; - loc_eng_data.client_handle = NULL; - } + LOC_LOGD("loc_eng_init: client opened. close it now."); + delete loc_eng_data.adapter; + loc_eng_data.adapter = NULL; loc_eng_dmn_conn_loc_api_server_unblock(); loc_eng_dmn_conn_loc_api_server_join(); @@ -529,15 +1602,19 @@ SIDE EFFECTS int loc_eng_start(loc_eng_data_s_type &loc_eng_data) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return -1); + INIT_CHECK(loc_eng_data.adapter, return -1); - void* target_q = loc_eng_data.ulp_initialized ? - (void*)((LocEngContext*)(loc_eng_data.context))->ulp_q : - (void*)((LocEngContext*)(loc_eng_data.context))->deferred_q; + if(loc_eng_data.ulp_q) + { + //Pass the start messgage to ULP if present & activated + loc_eng_msg *msg(new loc_eng_msg(&loc_eng_data, LOC_ENG_MSG_START_FIX)); + msg_q_snd(loc_eng_data.ulp_q, msg, loc_eng_free_msg); + } + else + { + loc_eng_data.adapter->sendMsg(new LocEngStartFix(&loc_eng_data)); + } - //Pass the start messgage to ULP if present & activated - loc_eng_msg *msg(new loc_eng_msg(&loc_eng_data, LOC_ENG_MSG_START_FIX)); - msg_q_snd( target_q, msg, loc_eng_free_msg); EXIT_LOG(%d, 0); return 0; } @@ -547,13 +1624,13 @@ static int loc_eng_start_handler(loc_eng_data_s_type &loc_eng_data) ENTRY_LOG(); int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; - if (!loc_eng_data.client_handle->isInSession()) { - ret_val = loc_eng_data.client_handle->startFix(); + if (!loc_eng_data.adapter->isInSession()) { + ret_val = loc_eng_data.adapter->startFix(); if (ret_val == LOC_API_ADAPTER_ERR_SUCCESS || ret_val == LOC_API_ADAPTER_ERR_ENGINE_DOWN) { - loc_eng_data.client_handle->setInSession(TRUE); + loc_eng_data.adapter->setInSession(TRUE); loc_inform_gps_status(loc_eng_data, GPS_STATUS_SESSION_BEGIN); } } @@ -581,15 +1658,18 @@ SIDE EFFECTS int loc_eng_stop(loc_eng_data_s_type &loc_eng_data) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return -1); + INIT_CHECK(loc_eng_data.adapter, return -1); - void* target_q = loc_eng_data.ulp_initialized ? - (void*)((LocEngContext*)(loc_eng_data.context))->ulp_q : - (void*)((LocEngContext*)(loc_eng_data.context))->deferred_q; - - //Pass the start messgage to ULP if present & activated - loc_eng_msg *msg(new loc_eng_msg(&loc_eng_data, LOC_ENG_MSG_STOP_FIX)); - msg_q_snd( target_q, msg, loc_eng_free_msg); + if(loc_eng_data.ulp_q) + { + //Pass the start messgage to ULP if present & activated + loc_eng_msg *msg(new loc_eng_msg(&loc_eng_data, LOC_ENG_MSG_STOP_FIX)); + msg_q_snd(loc_eng_data.ulp_q, msg, loc_eng_free_msg); + } + else + { + loc_eng_data.adapter->sendMsg(new LocEngStopFix(&loc_eng_data)); + } EXIT_LOG(%d, 0); return 0; @@ -600,15 +1680,15 @@ static int loc_eng_stop_handler(loc_eng_data_s_type &loc_eng_data) ENTRY_LOG(); int ret_val = LOC_API_ADAPTER_ERR_SUCCESS; - if (loc_eng_data.client_handle->isInSession()) { + if (loc_eng_data.adapter->isInSession()) { - ret_val = loc_eng_data.client_handle->stopFix(); + ret_val = loc_eng_data.adapter->stopFix(); if (ret_val == LOC_API_ADAPTER_ERR_SUCCESS) { loc_inform_gps_status(loc_eng_data, GPS_STATUS_SESSION_END); } - loc_eng_data.client_handle->setInSession(FALSE); + loc_eng_data.adapter->setInSession(FALSE); } EXIT_LOG(%d, ret_val); @@ -658,16 +1738,23 @@ int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data, LocPosMode ¶ms) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return -1); + INIT_CHECK(loc_eng_data.adapter, return -1); loc_eng_msg_position_mode *msg( new loc_eng_msg_position_mode(&loc_eng_data, params)); - void* target_q = loc_eng_data.ulp_initialized? - (void*)((LocEngContext*)(loc_eng_data.context))->ulp_q: - (void*)((LocEngContext*)(loc_eng_data.context))->deferred_q; + if(loc_eng_data.ulp_q) + { + loc_eng_msg_position_mode *msg( + new loc_eng_msg_position_mode(&loc_eng_data, params)); + //Pass the start messgage to ULP if present & activated + msg_q_snd(loc_eng_data.ulp_q, msg, loc_eng_free_msg); + } + else + { + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngPositionMode(adapter, params)); + } - //Pass the start messgage to ULP if present & activated - msg_q_snd(target_q, msg, loc_eng_free_msg); EXIT_LOG(%d, 0); return 0; } @@ -692,14 +1779,10 @@ int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data, GpsUtcTime time, int64_t timeReference, int uncertainty) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return -1); - loc_eng_msg_set_time *msg( - new loc_eng_msg_set_time(&loc_eng_data, - time, - timeReference, - uncertainty)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + INIT_CHECK(loc_eng_data.adapter, return -1); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngSetTime(adapter, time, timeReference, + uncertainty)); EXIT_LOG(%d, 0); return 0; } @@ -725,14 +1808,10 @@ int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data, double latitude, double longitude, float accuracy) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return -1); - loc_eng_msg_inject_location *msg( - new loc_eng_msg_inject_location(&loc_eng_data, - latitude, - longitude, - accuracy)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + INIT_CHECK(loc_eng_data.adapter, return -1); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngInjectLocation(adapter, latitude, longitude, + accuracy)); EXIT_LOG(%d, 0); return 0; @@ -762,13 +1841,9 @@ SIDE EFFECTS void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data, GpsAidingData f) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return); + INIT_CHECK(loc_eng_data.adapter, return); - loc_eng_msg_delete_aiding_data *msg( - new loc_eng_msg_delete_aiding_data(&loc_eng_data, - f)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + loc_eng_data.adapter->sendMsg(new LocEngDelAidData(&loc_eng_data, f)); EXIT_LOG(%s, VOID_RET); } @@ -794,19 +1869,14 @@ static void loc_inform_gps_status(loc_eng_data_s_type &loc_eng_data, GpsStatusVa { ENTRY_LOG(); - static GpsStatusValue last_status = GPS_STATUS_NONE; - - GpsStatus gs = { sizeof(gs),status }; - - if (loc_eng_data.status_cb) { - CALLBACK_LOG_CALLFLOW("status_cb", %s, loc_get_gps_status_name(gs.status)); + GpsStatus gs = { sizeof(gs),status }; + CALLBACK_LOG_CALLFLOW("status_cb", %s, + loc_get_gps_status_name(gs.status)); loc_eng_data.status_cb(&gs); } - last_status = status; - EXIT_LOG(%s, VOID_RET); } @@ -821,7 +1891,7 @@ static int dataCallCb(void *cb_data) int ret=0; if(cb_data != NULL) { dsCbData *cbData = (dsCbData *)cb_data; - LocApiAdapter *locAdapter = (LocApiAdapter *)cbData->mAdapter; + LocEngAdapter *locAdapter = (LocEngAdapter *)cbData->mAdapter; if(cbData->action == GPS_REQUEST_AGPS_DATA_CONN) { LOC_LOGD("dataCallCb GPS_REQUEST_AGPS_DATA_CONN\n"); ret = locAdapter->openAndStartDataCall(); @@ -897,7 +1967,7 @@ SIDE EFFECTS void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* callbacks) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context, return); + INIT_CHECK(loc_eng_data.adapter, return); STATE_CHECK((NULL == loc_eng_data.agps_status_cb), "agps instance already initialized", return); @@ -920,11 +1990,11 @@ void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* call (void *)loc_eng_data.agps_status_cb, AGPS_TYPE_WIFI, true); - if(!loc_eng_data.client_handle->initDataServiceClient()) { + if(!loc_eng_data.adapter->initDataServiceClient()) { LOC_LOGD("%s:%d]: Creating new ds state machine\n", __func__, __LINE__); loc_eng_data.ds_nif = new DSStateMachine(servicerTypeExt, (void *)dataCallCb, - loc_eng_data.client_handle); + loc_eng_data.adapter); LOC_LOGD("%s:%d]: Created new ds state machine\n", __func__, __LINE__); } @@ -935,6 +2005,37 @@ void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data, AGpsExtCallbacks* call EXIT_LOG(%s, VOID_RET); } +static void deleteAidingData(loc_eng_data_s_type &logEng) { + if (logEng.engine_status != GPS_STATUS_ENGINE_ON && + logEng.aiding_data_for_deletion != 0) { + logEng.adapter->deleteAidingData(logEng.aiding_data_for_deletion); + logEng.aiding_data_for_deletion = 0; + } +} + +static AgpsStateMachine* +getAgpsStateMachine(loc_eng_data_s_type &locEng, AGpsExtType agpsType) { + AgpsStateMachine* stateMachine; + switch (agpsType) { + case AGPS_TYPE_WIFI: { + stateMachine = locEng.wifi_nif; + break; + } + case AGPS_TYPE_INVALID: + case AGPS_TYPE_SUPL: { + stateMachine = locEng.agnss_nif; + break; + } + case AGPS_TYPE_SUPL_ES: { + stateMachine = locEng.ds_nif; + break; + } + default: + stateMachine = locEng.internet_nif; + } + return stateMachine; +} + /*=========================================================================== FUNCTION loc_eng_agps_open @@ -956,7 +2057,7 @@ int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, const char* apn, AGpsBearerType bearerType) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context && loc_eng_data.agps_status_cb, + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, return -1); if (apn == NULL) @@ -968,11 +2069,10 @@ int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType, LOC_LOGD("loc_eng_agps_open APN name = [%s]", apn); int apn_len = smaller_of(strlen (apn), MAX_APN_LEN); - loc_eng_msg_atl_open_success *msg( - new loc_eng_msg_atl_open_success(&loc_eng_data, agpsType, apn, - apn_len, bearerType)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + + loc_eng_data.adapter->sendMsg( + new LocEngAtlOpenSuccess(sm, apn, apn_len, bearerType)); EXIT_LOG(%d, 0); return 0; @@ -998,12 +2098,11 @@ SIDE EFFECTS int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context && loc_eng_data.agps_status_cb, + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, return -1); - loc_eng_msg_atl_closed *msg(new loc_eng_msg_atl_closed(&loc_eng_data, agpsType)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + loc_eng_data.adapter->sendMsg(new LocEngAtlClosed(sm)); EXIT_LOG(%d, 0); return 0; @@ -1029,12 +2128,11 @@ SIDE EFFECTS int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType) { ENTRY_LOG_CALLFLOW(); - INIT_CHECK(loc_eng_data.context && loc_eng_data.agps_status_cb, + INIT_CHECK(loc_eng_data.adapter && loc_eng_data.agps_status_cb, return -1); - loc_eng_msg_atl_open_failed *msg(new loc_eng_msg_atl_open_failed(&loc_eng_data, agpsType)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + AgpsStateMachine* sm = getAgpsStateMachine(loc_eng_data, agpsType); + loc_eng_data.adapter->sendMsg(new LocEngAtlOpenFailed(sm)); EXIT_LOG(%d, 0); return 0; @@ -1105,16 +2203,14 @@ static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data, { ENTRY_LOG(); int ret = 0; + LocEngAdapter* adapter = loc_eng_data.adapter; if (LOC_AGPS_SUPL_SERVER == type) { char url[MAX_URL_LEN]; unsigned int len = snprintf(url, sizeof(url), "%s:%u", hostname, (unsigned) port); if (sizeof(url) > len) { - loc_eng_msg_set_server_url *msg(new loc_eng_msg_set_server_url(&loc_eng_data, - url, len)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + adapter->sendMsg(new LocEngSetServerUrl(adapter, url, len)); } } else if (LOC_AGPS_CDMA_PDE_SERVER == type || LOC_AGPS_CUSTOM_PDE_SERVER == type || @@ -1126,12 +2222,7 @@ static int loc_eng_set_server(loc_eng_data_s_type &loc_eng_data, ret = -2; } else { unsigned int ip = htonl(addr.s_addr); - loc_eng_msg_set_server_ipv4 *msg(new loc_eng_msg_set_server_ipv4(&loc_eng_data, - ip, - port, - type)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + adapter->sendMsg(new LocEngSetServerIpv4(adapter, ip, port, type)); } } else { LOC_LOGE("loc_eng_set_server, type %d cannot be resolved.\n", type); @@ -1166,7 +2257,7 @@ int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data, ENTRY_LOG_CALLFLOW(); int ret_val = 0; - if (NULL != loc_eng_data.context) + if (NULL != loc_eng_data.adapter) { ret_val = loc_eng_set_server(loc_eng_data, type, hostname, port); } else { @@ -1224,15 +2315,13 @@ void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_d //us to inform the modem after GPS is enabled agpsStatus = available; - INIT_CHECK(loc_eng_data.context, return); + INIT_CHECK(loc_eng_data.adapter, return); if (apn != NULL) { LOC_LOGD("loc_eng_agps_ril_update_network_availability: APN Name = [%s]\n", apn); int apn_len = smaller_of(strlen (apn), MAX_APN_LEN); - loc_eng_msg_set_data_enable *msg(new loc_eng_msg_set_data_enable(&loc_eng_data, apn, - apn_len, available)); - msg_q_snd((void*)((LocEngContext*)(loc_eng_data.context))->deferred_q, - msg, loc_eng_free_msg); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngEnableData(adapter, apn, apn_len, available)); } EXIT_LOG(%s, VOID_RET); } @@ -1275,7 +2364,7 @@ static void loc_eng_report_status (loc_eng_data_s_type &loc_eng_data, GpsStatusV } // Session End is not reported during Android navigating state - boolean navigating = loc_eng_data.client_handle->isInSession(); + boolean navigating = loc_eng_data.adapter->isInSession(); if (status != GPS_STATUS_NONE && !(status == GPS_STATUS_SESSION_END && navigating) && !(status == GPS_STATUS_SESSION_BEGIN && !navigating)) @@ -1346,10 +2435,10 @@ void loc_eng_handle_engine_up(loc_eng_data_s_type &loc_eng_data) loc_eng_report_status(loc_eng_data, GPS_STATUS_ENGINE_ON); // modem is back up. If we crashed in the middle of navigating, we restart. - if (loc_eng_data.client_handle->isInSession()) { + if (loc_eng_data.adapter->isInSession()) { // This sets the copy in adapter to modem - loc_eng_data.client_handle->setPositionMode(NULL); - loc_eng_data.client_handle->setInSession(false); + loc_eng_data.adapter->setPositionMode(NULL); + loc_eng_data.adapter->setInSession(false); loc_eng_start_handler(loc_eng_data); } EXIT_LOG(%s, VOID_RET); @@ -1378,610 +2467,6 @@ static int set_sched_policy(int tid, SchedPolicy policy) } #endif /* USE_GLIB */ -/*=========================================================================== -FUNCTION loc_eng_deferred_action_thread - -DESCRIPTION - Main routine for the thread to execute loc_eng commands. - -DEPENDENCIES - None - -RETURN VALUE - None - -SIDE EFFECTS - N/A - -===========================================================================*/ -static void loc_eng_deferred_action_thread(void* arg) -{ - ENTRY_LOG(); - loc_eng_msg *msg; - static int cnt = 0; - LocEngContext* context = (LocEngContext*)arg; - - // make sure we do not run in background scheduling group - set_sched_policy(GETTID_PLATFORM_LIB_ABSTRACTION, SP_FOREGROUND); - - while (1) - { - LOC_LOGD("%s:%d] %d listening ...\n", __func__, __LINE__, cnt++); - - // we are only sending / receiving msg pointers - msq_q_err_type result = msg_q_rcv((void*)context->deferred_q, (void **) &msg); - if (eMSG_Q_SUCCESS != result) { - LOC_LOGE("%s:%d] fail receiving msg: %s\n", __func__, __LINE__, - loc_get_msg_q_status(result)); - return; - } - - loc_eng_data_s_type* loc_eng_data_p = (loc_eng_data_s_type*)msg->owner; - - LOC_LOGD("%s:%d] received msg_id = %s context = %p\n", - __func__, __LINE__, loc_get_msg_name(msg->msgid), loc_eng_data_p->context); - - // need to ensure the instance data is valid - STATE_CHECK(NULL != loc_eng_data_p->context, - "instance cleanup happened", - delete msg; return); - - switch(msg->msgid) { - case LOC_ENG_MSG_QUIT: - { - LocEngContext* context = (LocEngContext*)loc_eng_data_p->context; - pthread_mutex_lock(&(context->lock)); - pthread_cond_signal(&(context->cond)); - pthread_mutex_unlock(&(context->lock)); - EXIT_LOG(%s, "LOC_ENG_MSG_QUIT, signal the main thread and return"); - } - return; - - case LOC_ENG_MSG_REQUEST_NI: - { - loc_eng_msg_request_ni *niMsg = (loc_eng_msg_request_ni*)msg; - loc_eng_ni_request_handler(*loc_eng_data_p, &niMsg->notify, niMsg->passThroughData); - } - break; - - case LOC_ENG_MSG_INFORM_NI_RESPONSE: - { - loc_eng_msg_inform_ni_response *nrMsg = (loc_eng_msg_inform_ni_response*)msg; - loc_eng_data_p->client_handle->informNiResponse(nrMsg->response, - nrMsg->passThroughData); - } - break; - - case LOC_ENG_MSG_START_FIX: - loc_eng_start_handler(*loc_eng_data_p); - break; - - case LOC_ENG_MSG_STOP_FIX: - if (loc_eng_data_p->agps_request_pending) - { - loc_eng_data_p->stop_request_pending = true; - LOC_LOGD("loc_eng_stop - deferring stop until AGPS data call is finished\n"); - } else { - loc_eng_stop_handler(*loc_eng_data_p); - } - break; - - case LOC_ENG_MSG_SET_POSITION_MODE: - { - loc_eng_msg_position_mode *pmMsg = (loc_eng_msg_position_mode*)msg; - loc_eng_data_p->client_handle->setPositionMode(&(pmMsg->pMode)); - } - break; - - case LOC_ENG_MSG_SET_TIME: - { - loc_eng_msg_set_time *tMsg = (loc_eng_msg_set_time*)msg; - loc_eng_data_p->client_handle->setTime(tMsg->time, tMsg->timeReference, - tMsg->uncertainty); - } - break; - - case LOC_ENG_MSG_INJECT_LOCATION: - { - loc_eng_msg_inject_location *ilMsg = (loc_eng_msg_inject_location*) msg; - loc_eng_data_p->client_handle->injectPosition(ilMsg->latitude, ilMsg->longitude, - ilMsg->accuracy); - } - break; - - case LOC_ENG_MSG_SET_SERVER_IPV4: - { - loc_eng_msg_set_server_ipv4 *ssiMsg = (loc_eng_msg_set_server_ipv4*)msg; - loc_eng_data_p->client_handle->setServer(ssiMsg->nl_addr, - ssiMsg->port, - ssiMsg->serverType); - } - break; - - case LOC_ENG_MSG_SET_SERVER_URL: - { - loc_eng_msg_set_server_url *ssuMsg = (loc_eng_msg_set_server_url*)msg; - loc_eng_data_p->client_handle->setServer(ssuMsg->url, ssuMsg->len); - } - break; - - case LOC_ENG_MSG_A_GLONASS_PROTOCOL: - { - loc_eng_msg_a_glonass_protocol *svMsg = (loc_eng_msg_a_glonass_protocol*)msg; - loc_eng_data_p->client_handle->setAGLONASSProtocol(svMsg->a_glonass_protocol); - } - break; - - case LOC_ENG_MSG_SUPL_VERSION: - { - loc_eng_msg_suple_version *svMsg = (loc_eng_msg_suple_version*)msg; - loc_eng_data_p->client_handle->setSUPLVersion(svMsg->supl_version); - } - break; - - case LOC_ENG_MSG_LPP_CONFIG: - { - loc_eng_msg_lpp_config *svMsg = (loc_eng_msg_lpp_config*)msg; - loc_eng_data_p->client_handle->setLPPConfig(svMsg->lpp_config); - } - break; - - case LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG: - { - loc_eng_msg_sensor_control_config *sccMsg = (loc_eng_msg_sensor_control_config*)msg; - loc_eng_data_p->client_handle->setSensorControlConfig(sccMsg->sensorsDisabled); - } - break; - - case LOC_ENG_MSG_SET_SENSOR_PROPERTIES: - { - loc_eng_msg_sensor_properties *spMsg = (loc_eng_msg_sensor_properties*)msg; - loc_eng_data_p->client_handle->setSensorProperties(spMsg->gyroBiasVarianceRandomWalk_valid, - spMsg->gyroBiasVarianceRandomWalk, - spMsg->accelRandomWalk_valid, - spMsg->accelRandomWalk, - spMsg->angleRandomWalk_valid, - spMsg->angleRandomWalk, - spMsg->rateRandomWalk_valid, - spMsg->rateRandomWalk, - spMsg->velocityRandomWalk_valid, - spMsg->velocityRandomWalk); - } - break; - - case LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG: - { - loc_eng_msg_sensor_perf_control_config *spccMsg = (loc_eng_msg_sensor_perf_control_config*)msg; - loc_eng_data_p->client_handle->setSensorPerfControlConfig(spccMsg->controlMode, spccMsg->accelSamplesPerBatch, spccMsg->accelBatchesPerSec, - spccMsg->gyroSamplesPerBatch, spccMsg->gyroBatchesPerSec, - spccMsg->accelSamplesPerBatchHigh, spccMsg->accelBatchesPerSecHigh, - spccMsg->gyroSamplesPerBatchHigh, spccMsg->gyroBatchesPerSecHigh, - spccMsg->algorithmConfig); - } - break; - - case LOC_ENG_MSG_EXT_POWER_CONFIG: - { - loc_eng_msg_ext_power_config *pwrMsg = (loc_eng_msg_ext_power_config*)msg; - loc_eng_data_p->client_handle->setExtPowerConfig(pwrMsg->isBatteryCharging); - } - break; - - case LOC_ENG_MSG_REPORT_POSITION: - if (loc_eng_data_p->mute_session_state != LOC_MUTE_SESS_IN_SESSION) - { - bool reported = false; - loc_eng_msg_report_position *rpMsg = (loc_eng_msg_report_position*)msg; - if (loc_eng_data_p->location_cb != NULL) { - if (LOC_SESS_FAILURE == rpMsg->status) { - // in case we want to handle the failure case - loc_eng_data_p->location_cb(NULL, NULL); - reported = true; - } - // what's in the else if is... (line by line) - // 1. this is a good fix; or - // 1.1 it is a Satellite fix; or - // 1.1.1 it is a sensor fix - // 2. (must be intermediate fix... implicit) - // 2.1 we accepte intermediate; and - // 2.2 it is NOT the case that - // 2.2.1 there is inaccuracy; and - // 2.2.2 we care about inaccuracy; and - // 2.2.3 the inaccuracy exceeds our tolerance - else if ((LOC_SESS_SUCCESS == rpMsg->status && - (((LOC_POS_TECH_MASK_SATELLITE & rpMsg->technology_mask) || - (LOC_POS_TECH_MASK_SENSORS & rpMsg->technology_mask)))) || - (LOC_SESS_INTERMEDIATE == loc_eng_data_p->intermediateFix && - !((rpMsg->location.gpsLocation.flags & GPS_LOCATION_HAS_ACCURACY) && - (gps_conf.ACCURACY_THRES != 0) && - (rpMsg->location.gpsLocation.accuracy > gps_conf.ACCURACY_THRES)))) { - loc_eng_data_p->location_cb((UlpLocation*)&(rpMsg->location), - (void*)rpMsg->locationExt); - reported = true; - } - } - - // if we have reported this fix - if (reported && - // and if this is a singleshot - GPS_POSITION_RECURRENCE_SINGLE == - loc_eng_data_p->client_handle->getPositionMode().recurrence) { - if (LOC_SESS_INTERMEDIATE == rpMsg->status) { - // modem could be still working for a final fix, - // although we no longer need it. So stopFix(). - loc_eng_data_p->client_handle->stopFix(); - } - // turn off the session flag. - loc_eng_data_p->client_handle->setInSession(false); - } - - if (loc_eng_data_p->generateNmea && rpMsg->location.position_source == ULP_LOCATION_IS_FROM_GNSS) - { - unsigned char generate_nmea = reported && (rpMsg->status != LOC_SESS_FAILURE); - loc_eng_nmea_generate_pos(loc_eng_data_p, rpMsg->location, - rpMsg->locationExtended, - generate_nmea); - } - - // Free the allocated memory for rawData - UlpLocation* gp = (UlpLocation*)&(rpMsg->location); - if (gp != NULL && gp->rawData != NULL) - { - delete (char*)gp->rawData; - gp->rawData = NULL; - gp->rawDataSize = 0; - } - } - - break; - - case LOC_ENG_MSG_REPORT_SV: - if (loc_eng_data_p->mute_session_state != LOC_MUTE_SESS_IN_SESSION) - { - loc_eng_msg_report_sv *rsMsg = (loc_eng_msg_report_sv*)msg; - if (loc_eng_data_p->sv_status_cb != NULL) { - loc_eng_data_p->sv_status_cb((GpsSvStatus*)&(rsMsg->svStatus), - (void*)rsMsg->svExt); - } - - if (loc_eng_data_p->generateNmea) - { - loc_eng_nmea_generate_sv(loc_eng_data_p, rsMsg->svStatus, rsMsg->locationExtended); - } - - } - break; - - case LOC_ENG_MSG_REPORT_STATUS: - loc_eng_report_status(*loc_eng_data_p, ((loc_eng_msg_report_status*)msg)->status); - break; - - case LOC_ENG_MSG_REPORT_NMEA: - if (NULL != loc_eng_data_p->nmea_cb) { - loc_eng_msg_report_nmea* nmMsg = (loc_eng_msg_report_nmea*)msg; - struct timeval tv; - gettimeofday(&tv, (struct timezone *) NULL); - int64_t now = tv.tv_sec * 1000LL + tv.tv_usec / 1000; - CALLBACK_LOG_CALLFLOW("nmea_cb", %p, nmMsg->nmea); - loc_eng_data_p->nmea_cb(now, nmMsg->nmea, nmMsg->length); - } - break; - - case LOC_ENG_MSG_REPORT_XTRA_SERVER: - if (NULL != loc_eng_data_p->xtra_module_data.report_xtra_server_cb) { - loc_eng_msg_report_xtra_server* xsMsg = (loc_eng_msg_report_xtra_server*)msg; - CALLBACK_LOG_CALLFLOW("report_xtra_server_cb", %s, xsMsg->server1); - loc_eng_data_p->xtra_module_data.report_xtra_server_cb(xsMsg->server1, xsMsg->server2, xsMsg->server3); - } - break; - - case LOC_ENG_MSG_REQUEST_BIT: - { - AgpsStateMachine* stateMachine; - loc_eng_msg_request_bit* brqMsg = (loc_eng_msg_request_bit*)msg; - if (brqMsg->ifType == LOC_ENG_IF_REQUEST_TYPE_SUPL) { - stateMachine = loc_eng_data_p->agnss_nif; - } else if (brqMsg->ifType == LOC_ENG_IF_REQUEST_TYPE_ANY) { - stateMachine = loc_eng_data_p->internet_nif; - } else { - LOC_LOGD("%s]%d: unknown I/F request type = 0x%x\n", __func__, __LINE__, brqMsg->ifType); - break; - } - BITSubscriber subscriber(stateMachine, brqMsg->ipv4Addr, brqMsg->ipv6Addr); - - stateMachine->subscribeRsrc((Subscriber*)&subscriber); - } - break; - - case LOC_ENG_MSG_RELEASE_BIT: - { - AgpsStateMachine* stateMachine; - loc_eng_msg_release_bit* brlMsg = (loc_eng_msg_release_bit*)msg; - if (brlMsg->ifType == LOC_ENG_IF_REQUEST_TYPE_SUPL) { - stateMachine = loc_eng_data_p->agnss_nif; - } else if (brlMsg->ifType == LOC_ENG_IF_REQUEST_TYPE_ANY) { - stateMachine = loc_eng_data_p->internet_nif; - } else { - LOC_LOGD("%s]%d: unknown I/F request type = 0x%x\n", __func__, __LINE__, brlMsg->ifType); - break; - } - BITSubscriber subscriber(stateMachine, brlMsg->ipv4Addr, brlMsg->ipv6Addr); - - stateMachine->unsubscribeRsrc((Subscriber*)&subscriber); - } - break; - - case LOC_ENG_MSG_REQUEST_ATL: - { - loc_eng_msg_request_atl* arqMsg = (loc_eng_msg_request_atl*)msg; - boolean backwardCompatibleMode = AGPS_TYPE_INVALID == arqMsg->type; - AgpsStateMachine* stateMachine = (AGPS_TYPE_SUPL == arqMsg->type || - backwardCompatibleMode) ? - loc_eng_data_p->agnss_nif : - loc_eng_data_p->internet_nif; - ATLSubscriber subscriber(arqMsg->handle, - stateMachine, - loc_eng_data_p->client_handle, - backwardCompatibleMode); - - stateMachine->subscribeRsrc((Subscriber*)&subscriber); - } - break; - - case LOC_ENG_MSG_RELEASE_ATL: - { - loc_eng_msg_release_atl* arlMsg = (loc_eng_msg_release_atl*)msg; - ATLSubscriber s1(arlMsg->handle, - loc_eng_data_p->agnss_nif, - loc_eng_data_p->client_handle, - false); - // attempt to unsubscribe from agnss_nif first - if (loc_eng_data_p->agnss_nif->unsubscribeRsrc((Subscriber*)&s1)) { - LOC_LOGD("%s:%d]: Unsubscribed from agnss_nif", __func__, __LINE__); - } - else { - ATLSubscriber s2(arlMsg->handle, - loc_eng_data_p->internet_nif, - loc_eng_data_p->client_handle, - false); - // if unsuccessful, try internet_nif - if(loc_eng_data_p->internet_nif->unsubscribeRsrc((Subscriber*)&s2)) { - LOC_LOGD("%s:%d]: Unsubscribed from internet_nif", __func__, __LINE__); - } - else { - DSSubscriber s3(loc_eng_data_p->ds_nif, - arlMsg->handle); - LOC_LOGD("%s:%d]: Request to stop Emergency call. Handle: %d\n", - __func__, __LINE__, arlMsg->handle); - if(loc_eng_data_p->ds_nif->unsubscribeRsrc((Subscriber*)&s3)) { - LOC_LOGD("%s:%d]: Unsubscribed from ds_nif", __func__, __LINE__); - } - else { - LOC_LOGE("%s:%d]: Could not release ATL. No subscribers found\n", - __func__, __LINE__); - loc_eng_data_p->client_handle->atlCloseStatus(arlMsg->handle, 0); - } - } - } - } - break; - - case LOC_ENG_MSG_REQUEST_WIFI: - { - loc_eng_msg_request_wifi *wrqMsg = (loc_eng_msg_request_wifi *)msg; - if (wrqMsg->senderId == LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC || - wrqMsg->senderId == LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM || - wrqMsg->senderId == LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU) { - AgpsStateMachine* stateMachine = loc_eng_data_p->wifi_nif; - WIFISubscriber subscriber(stateMachine, wrqMsg->ssid, wrqMsg->password, wrqMsg->senderId); - stateMachine->subscribeRsrc((Subscriber*)&subscriber); - } else { - LOC_LOGE("%s]%d ERROR: unknown sender ID", __func__, __LINE__); - break; - } - } - break; - - case LOC_ENG_MSG_RELEASE_WIFI: - { - AgpsStateMachine* stateMachine = loc_eng_data_p->wifi_nif; - loc_eng_msg_release_wifi* wrlMsg = (loc_eng_msg_release_wifi*)msg; - WIFISubscriber subscriber(stateMachine, wrlMsg->ssid, wrlMsg->password, wrlMsg->senderId); - stateMachine->unsubscribeRsrc((Subscriber*)&subscriber); - } - break; - - case LOC_ENG_MSG_REQUEST_XTRA_DATA: - if (loc_eng_data_p->xtra_module_data.download_request_cb != NULL) - { - loc_eng_data_p->xtra_module_data.download_request_cb(); - } - break; - - case LOC_ENG_MSG_REQUEST_TIME: - if (loc_eng_data_p->request_utc_time_cb != NULL) - { - loc_eng_data_p->request_utc_time_cb(); - } - else - { - LOC_LOGE("%s] ERROR: Callback function for request_time is NULL", __func__); - } - break; - - case LOC_ENG_MSG_REQUEST_POSITION: - break; - - case LOC_ENG_MSG_DELETE_AIDING_DATA: - loc_eng_data_p->aiding_data_for_deletion |= ((loc_eng_msg_delete_aiding_data*)msg)->type; - break; - - case LOC_ENG_MSG_ENABLE_DATA: - { - loc_eng_msg_set_data_enable *unaMsg = (loc_eng_msg_set_data_enable*)msg; - loc_eng_data_p->client_handle->enableData(unaMsg->enable); - if(unaMsg->apn != NULL) - loc_eng_data_p->client_handle->setAPN(unaMsg->apn, unaMsg->length); - } - break; - - case LOC_ENG_MSG_INJECT_XTRA_DATA: - { - loc_eng_msg_inject_xtra_data *xdMsg = (loc_eng_msg_inject_xtra_data*)msg; - loc_eng_data_p->client_handle->setXtraData(xdMsg->data, xdMsg->length); - } - break; - - case LOC_ENG_MSG_REQUEST_XTRA_SERVER: - { - loc_eng_data_p->client_handle->requestXtraServer(); - } - break; - - case LOC_ENG_MSG_ATL_OPEN_SUCCESS: - { - loc_eng_msg_atl_open_success *aosMsg = (loc_eng_msg_atl_open_success*)msg; - AgpsStateMachine* stateMachine; - LOC_LOGD("%s:%d]: AGPS_TYPE: %d\n", __func__, __LINE__, (int)aosMsg->agpsType); - switch (aosMsg->agpsType) { - case AGPS_TYPE_WIFI: { - LOC_LOGD("%s:%d]: AGPS Type wifi\n", __func__, __LINE__); - stateMachine = loc_eng_data_p->wifi_nif; - break; - } - case AGPS_TYPE_SUPL: { - LOC_LOGD("%s:%d]: AGPS Type supl\n", __func__, __LINE__); - stateMachine = loc_eng_data_p->agnss_nif; - break; - } - case AGPS_TYPE_INVALID: { - stateMachine = loc_eng_data_p->ds_nif; - LOC_LOGD("%s:%d]: AGPS Type invalid\n", __func__, __LINE__); - } - break; - default: { - LOC_LOGD("%s:%d]: AGPS Type default internet\n", __func__, __LINE__); - stateMachine = loc_eng_data_p->internet_nif; - } - } - - stateMachine->setBearer(aosMsg->bearerType); - stateMachine->setAPN(aosMsg->apn, aosMsg->length); - stateMachine->onRsrcEvent(RSRC_GRANTED); - } - break; - - case LOC_ENG_MSG_ATL_CLOSED: - { - loc_eng_msg_atl_closed *acsMsg = (loc_eng_msg_atl_closed*)msg; - AgpsStateMachine* stateMachine; - - switch (acsMsg->agpsType) { - case AGPS_TYPE_WIFI: { - stateMachine = loc_eng_data_p->wifi_nif; - break; - } - case AGPS_TYPE_SUPL: { - stateMachine = loc_eng_data_p->agnss_nif; - break; - } - case AGPS_TYPE_INVALID: { - stateMachine = loc_eng_data_p->ds_nif; - break; - } - default: { - stateMachine = loc_eng_data_p->internet_nif; - } - } - stateMachine->onRsrcEvent(RSRC_RELEASED); - } - break; - - case LOC_ENG_MSG_ATL_OPEN_FAILED: - { - loc_eng_msg_atl_open_failed *aofMsg = (loc_eng_msg_atl_open_failed*)msg; - AgpsStateMachine* stateMachine; - - switch (aofMsg->agpsType) { - case AGPS_TYPE_WIFI: { - stateMachine = loc_eng_data_p->wifi_nif; - break; - } - case AGPS_TYPE_SUPL: { - stateMachine = loc_eng_data_p->agnss_nif; - break; - } - default: { - stateMachine = loc_eng_data_p->internet_nif; - } - } - stateMachine->onRsrcEvent(RSRC_DENIED); - } - break; - - case LOC_ENG_MSG_ENGINE_DOWN: - loc_eng_handle_engine_down(*loc_eng_data_p); - break; - - case LOC_ENG_MSG_ENGINE_UP: - loc_eng_handle_engine_up(*loc_eng_data_p); - break; - - case LOC_ENG_MSG_LOC_INIT: - { - loc_eng_reinit(*loc_eng_data_p); - } - break; - - case LOC_ENG_MSG_REQUEST_SUPL_ES: - { - loc_eng_msg_request_supl_es *reqMsg = - (loc_eng_msg_request_supl_es *)msg; - AgpsStateMachine *stateMachine = loc_eng_data_p->ds_nif; - DSSubscriber subscriber(stateMachine, reqMsg->handle); - LOC_LOGD("%s:%d]: Starting data call\n", __func__, __LINE__); - stateMachine->subscribeRsrc((Subscriber *)&subscriber); - } - break; - - case LOC_ENG_MSG_CLOSE_DATA_CALL: - { - loc_eng_data_p->client_handle->closeDataCall(); - LOC_LOGD("%s:%d]: Request to close data call\n", - __func__, __LINE__); - } - break; - - default: - LOC_LOGE("unsupported msgid = %d\n", msg->msgid); - break; - } - - if ( (msg->msgid == LOC_ENG_MSG_ATL_OPEN_FAILED) | - (msg->msgid == LOC_ENG_MSG_ATL_CLOSED) | - (msg->msgid == LOC_ENG_MSG_ATL_OPEN_SUCCESS) ) - { - loc_eng_data_p->agps_request_pending = false; - if (loc_eng_data_p->stop_request_pending) { - loc_eng_stop_handler(*loc_eng_data_p); - loc_eng_data_p->stop_request_pending = false; - } - } - loc_eng_data_p->stop_request_pending = false; - - if (loc_eng_data_p->engine_status != GPS_STATUS_ENGINE_ON && - loc_eng_data_p->aiding_data_for_deletion != 0) - { - loc_eng_data_p->client_handle->deleteAidingData(loc_eng_data_p->aiding_data_for_deletion); - loc_eng_data_p->aiding_data_for_deletion = 0; - } - - delete msg; - } - - EXIT_LOG(%s, VOID_RET); -} - /*=========================================================================== FUNCTION loc_eng_ulp_init @@ -2008,7 +2493,7 @@ int loc_eng_ulp_init(loc_eng_data_s_type &loc_eng_data, const ulpInterface * loc { // Initialize the ULP interface ((ulpInterface *)loc_eng_ulpInf)->init(loc_eng_data); - loc_eng_data.ulp_initialized = TRUE; + loc_eng_data.ulp_q = (void*)msg_q_init2(); ret_val = 0; } else diff --git a/loc_api/libloc_api_50001/loc_eng.h b/loc_api/libloc_api_50001/loc_eng.h index f9566196..fdda66a2 100644 --- a/loc_api/libloc_api_50001/loc_eng.h +++ b/loc_api/libloc_api_50001/loc_eng.h @@ -55,9 +55,8 @@ typedef unsigned char boolean; #include #include #include -#include #include -#include +#include // The data connection minimal open time #define DATA_OPEN_MIN_TIME 1 /* sec */ @@ -79,25 +78,10 @@ enum loc_mute_session_e_type { LOC_MUTE_SESS_IN_SESSION }; -struct LocEngContext { - // Data variables used by deferred action thread - const void* deferred_q; - const void* ulp_q; - const pthread_t deferred_action_thread; - static LocEngContext* get(gps_create_thread threadCreator); - void drop(); - static pthread_mutex_t lock; - static pthread_cond_t cond; -private: - int counter; - static LocEngContext *me; - LocEngContext(gps_create_thread threadCreator); -}; - // Module data typedef struct loc_eng_data_s { - LocApiAdapter *client_handle; + LocEngAdapter *adapter; loc_location_cb_ext location_cb; gps_status_callback status_cb; loc_sv_status_cb_ext sv_status_cb; @@ -109,9 +93,6 @@ typedef struct loc_eng_data_s gps_request_utc_time request_utc_time_cb; boolean intermediateFix; AGpsStatusValue agps_status; - // used to defer stopping the GPS engine until AGPS data calls are done - boolean agps_request_pending; - boolean stop_request_pending; loc_eng_xtra_data_s_type xtra_module_data; loc_eng_ni_data_s_type loc_eng_ni_data; @@ -129,8 +110,6 @@ typedef struct loc_eng_data_s // Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off GpsAidingData aiding_data_for_deletion; - void* context; - // For muting session broadcast loc_mute_session_e_type mute_session_state; @@ -151,7 +130,10 @@ typedef struct loc_eng_data_s int mpc_host_set; char mpc_host_buf[101]; int mpc_port_buf; - bool ulp_initialized; + void *ulp_q; + + loc_ext_parser location_ext_parser; + loc_ext_parser sv_ext_parser; } loc_eng_data_s_type; #include "ulp.h" @@ -256,6 +238,7 @@ extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data, const void* passThrough); extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data); int loc_eng_read_config(void); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/loc_api/libloc_api_50001/loc_eng_agps.cpp b/loc_api/libloc_api_50001/loc_eng_agps.cpp index b7821c9e..d6cc1369 100644 --- a/loc_api/libloc_api_50001/loc_eng_agps.cpp +++ b/loc_api/libloc_api_50001/loc_eng_agps.cpp @@ -33,10 +33,10 @@ #include #include #include -#include "platform_lib_includes.h" +#include #include #include -#include +#include //====================================================================== // C callbacks @@ -109,7 +109,7 @@ bool BITSubscriber::equals(const Subscriber *s) const return (ID == bitS->ID && (INADDR_NONE != (unsigned int)ID || - 0 == strncmp(ipv6Addr, bitS->ipv6Addr, sizeof(ipv6Addr)))); + 0 == strncmp(mIPv6Addr, bitS->mIPv6Addr, sizeof(mIPv6Addr)))); } bool BITSubscriber::notifyRsrcStatus(Notification ¬ification) @@ -152,13 +152,13 @@ bool ATLSubscriber::notifyRsrcStatus(Notification ¬ification) { case RSRC_UNSUBSCRIBE: case RSRC_RELEASED: - ((LocApiAdapter*)mLocAdapter)->atlCloseStatus(ID, 1); + ((LocEngAdapter*)mLocAdapter)->atlCloseStatus(ID, 1); break; case RSRC_DENIED: { AGpsExtType type = mBackwardCompatibleMode ? AGPS_TYPE_INVALID : mStateMachine->getType(); - ((LocApiAdapter*)mLocAdapter)->atlOpenStatus(ID, 0, + ((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 0, (char*)mStateMachine->getAPN(), mStateMachine->getBearer(), type); @@ -168,7 +168,7 @@ bool ATLSubscriber::notifyRsrcStatus(Notification ¬ification) { AGpsExtType type = mBackwardCompatibleMode ? AGPS_TYPE_INVALID : mStateMachine->getType(); - ((LocApiAdapter*)mLocAdapter)->atlOpenStatus(ID, 1, + ((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 1, (char*)mStateMachine->getAPN(), mStateMachine->getBearer(), type); @@ -627,6 +627,7 @@ AgpsStateMachine::AgpsStateMachine(servicerType servType, mStatePtr(new AgpsReleasedState(this)),mType(type), mAPN(NULL), mAPNLen(0), + mBearer(AGPS_APN_BEARER_INVALID), mEnforceSingleSubscriber(enforceSingleSubscriber), mServicer(Servicer :: getServicer(servType, (void *)cb_func)) { @@ -826,7 +827,7 @@ err: } DSStateMachine :: DSStateMachine(servicerType type, void *cb_func, - LocApiAdapter* adapterHandle): + LocEngAdapter* adapterHandle): AgpsStateMachine(type, cb_func, AGPS_TYPE_INVALID,false), mLocAdapter(adapterHandle) { @@ -947,17 +948,17 @@ void DSStateMachine :: informStatus(AgpsRsrcStatus status, int ID) const LOC_LOGD("DSStateMachine :: informStatus. Status=%d\n",(int)status); switch(status) { case RSRC_UNSUBSCRIBE: - ((LocApiAdapter*)mLocAdapter)->atlCloseStatus(ID, 1); + mLocAdapter->atlCloseStatus(ID, 1); break; case RSRC_RELEASED: - ((LocApiAdapter*)mLocAdapter)->releaseDataHandle(); + mLocAdapter->closeDataCall(); break; case RSRC_DENIED: ((DSStateMachine *)this)->mRetries = 0; mLocAdapter->requestATL(ID, AGPS_TYPE_SUPL); break; case RSRC_GRANTED: - ((LocApiAdapter*)mLocAdapter)->atlOpenStatus(ID, 1, + mLocAdapter->atlOpenStatus(ID, 1, NULL, AGPS_APN_BEARER_INVALID, AGPS_TYPE_INVALID); diff --git a/loc_api/libloc_api_50001/loc_eng_agps.h b/loc_api/libloc_api_50001/loc_eng_agps.h index 93980f3c..055d955b 100644 --- a/loc_api/libloc_api_50001/loc_eng_agps.h +++ b/loc_api/libloc_api_50001/loc_eng_agps.h @@ -35,10 +35,11 @@ #include #include #include +#include +#include #include -#include -#include "loc_eng_msg.h" #include +#include // forward declaration class AgpsStateMachine; @@ -62,7 +63,7 @@ typedef enum { //DS Callback struct typedef struct { - LocApiAdapter *mAdapter; + LocEngAdapter *mAdapter; AGpsStatusValue action; }dsCbData; @@ -249,12 +250,12 @@ public: class DSStateMachine : public AgpsStateMachine { static const unsigned char MAX_START_DATA_CALL_RETRIES; static const unsigned int DATA_CALL_RETRY_DELAY_MSEC; - LocApiAdapter* mLocAdapter; + LocEngAdapter* mLocAdapter; unsigned char mRetries; public: DSStateMachine(servicerType type, - void *cb_func, - LocApiAdapter* adapterHandle); + void *cb_func, + LocEngAdapter* adapterHandle); int sendRsrcRequest(AGpsStatusValue action) const; void onRsrcEvent(AgpsRsrcStatus event); void retryCallback(); @@ -297,40 +298,40 @@ struct Subscriber { // BITSubscriber, created with requests from BIT daemon struct BITSubscriber : public Subscriber { + char mIPv6Addr[16]; + inline BITSubscriber(const AgpsStateMachine* stateMachine, unsigned int ipv4, char* ipv6) : Subscriber(ipv4, stateMachine) { if (NULL == ipv6) { - ipv6Addr[0] = NULL; + mIPv6Addr[0] = 0; } else { - memcpy(ipv6Addr, ipv6, sizeof(ipv6Addr)); + memcpy(mIPv6Addr, ipv6, sizeof(mIPv6Addr)); } } virtual bool notifyRsrcStatus(Notification ¬ification); inline virtual void setIPAddresses(uint32_t &v4, char* v6) - { v4 = ID; memcpy(v6, ipv6Addr, sizeof(ipv6Addr)); } + { v4 = ID; memcpy(v6, mIPv6Addr, sizeof(mIPv6Addr)); } virtual Subscriber* clone() { - return new BITSubscriber(mStateMachine, ID, ipv6Addr); + return new BITSubscriber(mStateMachine, ID, mIPv6Addr); } virtual bool equals(const Subscriber *s) const; inline virtual ~BITSubscriber(){} -private: - char ipv6Addr[16]; }; // ATLSubscriber, created with requests from ATL struct ATLSubscriber : public Subscriber { - const LocApiAdapter* mLocAdapter; + const LocEngAdapter* mLocAdapter; const bool mBackwardCompatibleMode; inline ATLSubscriber(const int id, const AgpsStateMachine* stateMachine, - const LocApiAdapter* adapter, + const LocEngAdapter* adapter, const bool compatibleMode) : Subscriber(id, stateMachine), mLocAdapter(adapter), mBackwardCompatibleMode(compatibleMode){} diff --git a/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp b/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp index 8176ab43..edd53f21 100644 --- a/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp +++ b/loc_api/libloc_api_50001/loc_eng_dmn_conn_handler.cpp @@ -49,24 +49,24 @@ int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, } if (NULL != loc_api_handle) { - loc_if_req_type_e_type type; + AGpsExtType type; switch (pmsg->cmsg.cmsg_if_request.type) { case IF_REQUEST_TYPE_SUPL: { LOC_LOGD("IF_REQUEST_TYPE_SUPL"); - type = LOC_ENG_IF_REQUEST_TYPE_SUPL; + type = AGPS_TYPE_SUPL; break; } case IF_REQUEST_TYPE_WIFI: { LOC_LOGD("IF_REQUEST_TYPE_WIFI"); - type = LOC_ENG_IF_REQUEST_TYPE_WIFI; + type = AGPS_TYPE_WIFI; break; } case IF_REQUEST_TYPE_ANY: { LOC_LOGD("IF_REQUEST_TYPE_ANY"); - type = LOC_ENG_IF_REQUEST_TYPE_ANY; + type = AGPS_TYPE_ANY; break; } default: @@ -79,48 +79,52 @@ int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, case IF_REQUEST_SENDER_ID_QUIPC: { LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC"); - loc_eng_msg_request_wifi *msg( - new loc_eng_msg_request_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); break; } case IF_REQUEST_SENDER_ID_MSAPM: { LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPM"); - loc_eng_msg_request_wifi *msg( - new loc_eng_msg_request_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); break; } case IF_REQUEST_SENDER_ID_MSAPU: { LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPU"); - loc_eng_msg_request_wifi *msg( - new loc_eng_msg_request_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + true); + msg->send(); break; } case IF_REQUEST_SENDER_ID_GPSONE_DAEMON: { LOC_LOGD("IF_REQUEST_SENDER_ID_GPSONE_DAEMON"); - loc_eng_msg_request_bit *msg( - new loc_eng_msg_request_bit(loc_api_handle, - type, - pmsg->cmsg.cmsg_if_request.ipv4_addr, - (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelBIT* msg = + new LocEngReqRelBIT(loc_api_handle, + type, + pmsg->cmsg.cmsg_if_request.ipv4_addr, + (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr, + true); + msg->send(); break; } default: @@ -141,24 +145,24 @@ int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, { LOC_LOGD("%s:%d]\n", __func__, __LINE__); #ifndef DEBUG_DMN_LOC_API - loc_if_req_type_e_type type; + AGpsExtType type; switch (pmsg->cmsg.cmsg_if_request.type) { case IF_REQUEST_TYPE_SUPL: { LOC_LOGD("IF_REQUEST_TYPE_SUPL"); - type = LOC_ENG_IF_REQUEST_TYPE_SUPL; + type = AGPS_TYPE_SUPL; break; } case IF_REQUEST_TYPE_WIFI: { LOC_LOGD("IF_REQUEST_TYPE_WIFI"); - type = LOC_ENG_IF_REQUEST_TYPE_WIFI; + type = AGPS_TYPE_WIFI; break; } case IF_REQUEST_TYPE_ANY: { LOC_LOGD("IF_REQUEST_TYPE_ANY"); - type = LOC_ENG_IF_REQUEST_TYPE_ANY; + type = AGPS_TYPE_ANY; break; } default: @@ -171,48 +175,52 @@ int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, case IF_REQUEST_SENDER_ID_QUIPC: { LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC"); - loc_eng_msg_release_wifi *msg( - new loc_eng_msg_release_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); break; } case IF_REQUEST_SENDER_ID_MSAPM: { LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPM"); - loc_eng_msg_release_wifi *msg( - new loc_eng_msg_release_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); break; } case IF_REQUEST_SENDER_ID_MSAPU: { LOC_LOGD("IF_REQUEST_SENDER_ID_MSAPU"); - loc_eng_msg_release_wifi *msg( - new loc_eng_msg_release_wifi(loc_api_handle, - type, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, - (char*)pmsg->cmsg.cmsg_if_request.ssid, - (char*)pmsg->cmsg.cmsg_if_request.password)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelWifi* msg = + new LocEngReqRelWifi(loc_api_handle, + type, + LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, + (char*)pmsg->cmsg.cmsg_if_request.ssid, + (char*)pmsg->cmsg.cmsg_if_request.password, + false); + msg->send(); break; } case IF_REQUEST_SENDER_ID_GPSONE_DAEMON: { LOC_LOGD("IF_REQUEST_SENDER_ID_GPSONE_DAEMON"); - loc_eng_msg_release_bit *msg( - new loc_eng_msg_release_bit(loc_api_handle, - type, - pmsg->cmsg.cmsg_if_request.ipv4_addr, - (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr)); - loc_eng_msg_sender(loc_api_handle, msg); + LocEngReqRelBIT* msg = + new LocEngReqRelBIT(loc_api_handle, + type, + pmsg->cmsg.cmsg_if_request.ipv4_addr, + (char*)pmsg->cmsg.cmsg_if_request.ipv6_addr, + false); + msg->send(); break; } default: diff --git a/loc_api/libloc_api_50001/loc_eng_log.cpp b/loc_api/libloc_api_50001/loc_eng_log.cpp index 877566ed..8c494337 100644 --- a/loc_api/libloc_api_50001/loc_eng_log.cpp +++ b/loc_api/libloc_api_50001/loc_eng_log.cpp @@ -30,31 +30,10 @@ #define LOG_NDDEBUG 0 #define LOG_TAG "LocSvc_eng" -#include "hardware/gps.h" #include "loc_log.h" #include "loc_eng_log.h" #include "loc_eng_msg_id.h" -/* GPS status names */ -static loc_name_val_s_type gps_status_name[] = -{ - NAME_VAL( GPS_STATUS_NONE ), - NAME_VAL( GPS_STATUS_SESSION_BEGIN ), - NAME_VAL( GPS_STATUS_SESSION_END ), - NAME_VAL( GPS_STATUS_ENGINE_ON ), - NAME_VAL( GPS_STATUS_ENGINE_OFF ), -}; -static int gps_status_num = sizeof(gps_status_name) / sizeof(loc_name_val_s_type); - -/* Find Android GPS status name */ -const char* loc_get_gps_status_name(GpsStatusValue gps_status) -{ - return loc_get_name_from_val(gps_status_name, gps_status_num, - (long) gps_status); -} - - - static loc_name_val_s_type loc_eng_msgs[] = { NAME_VAL( LOC_ENG_MSG_QUIT ), @@ -111,183 +90,3 @@ const char* loc_get_msg_name(int id) -static loc_name_val_s_type loc_eng_position_modes[] = -{ - NAME_VAL( LOC_POSITION_MODE_STANDALONE ), - NAME_VAL( LOC_POSITION_MODE_MS_BASED ), - NAME_VAL( LOC_POSITION_MODE_MS_ASSISTED ), - NAME_VAL( LOC_POSITION_MODE_RESERVED_1 ), - NAME_VAL( LOC_POSITION_MODE_RESERVED_2 ), - NAME_VAL( LOC_POSITION_MODE_RESERVED_3 ), - NAME_VAL( LOC_POSITION_MODE_RESERVED_4 ), - NAME_VAL( LOC_POSITION_MODE_RESERVED_5 ) -}; -static int loc_eng_position_mode_num = sizeof(loc_eng_position_modes) / sizeof(loc_name_val_s_type); - -const char* loc_get_position_mode_name(GpsPositionMode mode) -{ - return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode); -} - - - -static loc_name_val_s_type loc_eng_position_recurrences[] = -{ - NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ), - NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE ) -}; -static int loc_eng_position_recurrence_num = sizeof(loc_eng_position_recurrences) / sizeof(loc_name_val_s_type); - -const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur) -{ - return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur); -} - - - -static loc_name_val_s_type loc_eng_aiding_data_bits[] = -{ - NAME_VAL( GPS_DELETE_EPHEMERIS ), - NAME_VAL( GPS_DELETE_ALMANAC ), - NAME_VAL( GPS_DELETE_POSITION ), - NAME_VAL( GPS_DELETE_TIME ), - NAME_VAL( GPS_DELETE_IONO ), - NAME_VAL( GPS_DELETE_UTC ), - NAME_VAL( GPS_DELETE_HEALTH ), - NAME_VAL( GPS_DELETE_SVDIR ), - NAME_VAL( GPS_DELETE_SVSTEER ), - NAME_VAL( GPS_DELETE_SADATA ), - NAME_VAL( GPS_DELETE_RTI ), - NAME_VAL( GPS_DELETE_CELLDB_INFO ), - NAME_VAL( GPS_DELETE_ALMANAC_CORR ), - NAME_VAL( GPS_DELETE_FREQ_BIAS_EST ), - NAME_VAL( GPS_DELETE_EPHEMERIS_GLO ), - NAME_VAL( GPS_DELETE_ALMANAC_GLO ), - NAME_VAL( GPS_DELETE_SVDIR_GLO ), - NAME_VAL( GPS_DELETE_SVSTEER_GLO ), - NAME_VAL( GPS_DELETE_ALMANAC_CORR_GLO ), - NAME_VAL( GPS_DELETE_TIME_GPS ), - NAME_VAL( GPS_DELETE_TIME_GLO ) -}; -static int loc_eng_aiding_data_bit_num = sizeof(loc_eng_aiding_data_bits) / sizeof(loc_name_val_s_type); - -const char* loc_get_aiding_data_mask_names(GpsAidingData data) -{ - return NULL; -} - - -static loc_name_val_s_type loc_eng_agps_types[] = -{ - NAME_VAL( AGPS_TYPE_INVALID ), - NAME_VAL( AGPS_TYPE_ANY ), - NAME_VAL( AGPS_TYPE_SUPL ), - NAME_VAL( AGPS_TYPE_C2K ), - NAME_VAL( AGPS_TYPE_WWAN_ANY ) -}; -static int loc_eng_agps_type_num = sizeof(loc_eng_agps_types) / sizeof(loc_name_val_s_type); - -const char* loc_get_agps_type_name(AGpsType type) -{ - return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type); -} - - -static loc_name_val_s_type loc_eng_ni_types[] = -{ - NAME_VAL( GPS_NI_TYPE_VOICE ), - NAME_VAL( GPS_NI_TYPE_UMTS_SUPL ), - NAME_VAL( GPS_NI_TYPE_UMTS_CTRL_PLANE ) -}; -static int loc_eng_ni_type_num = sizeof(loc_eng_ni_types) / sizeof(loc_name_val_s_type); - -const char* loc_get_ni_type_name(GpsNiType type) -{ - return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type); -} - - -static loc_name_val_s_type loc_eng_ni_responses[] = -{ - NAME_VAL( GPS_NI_RESPONSE_ACCEPT ), - NAME_VAL( GPS_NI_RESPONSE_DENY ), - NAME_VAL( GPS_NI_RESPONSE_DENY ) -}; -static int loc_eng_ni_reponse_num = sizeof(loc_eng_ni_responses) / sizeof(loc_name_val_s_type); - -const char* loc_get_ni_response_name(GpsUserResponseType response) -{ - return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response); -} - - -static loc_name_val_s_type loc_eng_ni_encodings[] = -{ - NAME_VAL( GPS_ENC_NONE ), - NAME_VAL( GPS_ENC_SUPL_GSM_DEFAULT ), - NAME_VAL( GPS_ENC_SUPL_UTF8 ), - NAME_VAL( GPS_ENC_SUPL_UCS2 ), - NAME_VAL( GPS_ENC_UNKNOWN ) -}; -static int loc_eng_ni_encoding_num = sizeof(loc_eng_ni_encodings) / sizeof(loc_name_val_s_type); - -const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding) -{ - return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding); -} - -static loc_name_val_s_type loc_eng_agps_bears[] = -{ - NAME_VAL( AGPS_APN_BEARER_INVALID ), - NAME_VAL( AGPS_APN_BEARER_IPV4 ), - NAME_VAL( AGPS_APN_BEARER_IPV4 ), - NAME_VAL( AGPS_APN_BEARER_IPV4V6 ) -}; -static int loc_eng_agps_bears_num = sizeof(loc_eng_agps_bears) / sizeof(loc_name_val_s_type); - -const char* loc_get_agps_bear_name(AGpsBearerType bearer) -{ - return loc_get_name_from_val(loc_eng_agps_bears, loc_eng_agps_bears_num, (long) bearer); -} - -static loc_name_val_s_type loc_eng_server_types[] = -{ - NAME_VAL( LOC_AGPS_CDMA_PDE_SERVER ), - NAME_VAL( LOC_AGPS_CUSTOM_PDE_SERVER ), - NAME_VAL( LOC_AGPS_MPC_SERVER ), - NAME_VAL( LOC_AGPS_SUPL_SERVER ) -}; -static int loc_eng_server_types_num = sizeof(loc_eng_server_types) / sizeof(loc_name_val_s_type); - -const char* loc_get_server_type_name(LocServerType type) -{ - return loc_get_name_from_val(loc_eng_server_types, loc_eng_server_types_num, (long) type); -} - -static loc_name_val_s_type loc_eng_position_sess_status_types[] = -{ - NAME_VAL( LOC_SESS_SUCCESS ), - NAME_VAL( LOC_SESS_INTERMEDIATE ), - NAME_VAL( LOC_SESS_FAILURE ) -}; -static int loc_eng_position_sess_status_num = sizeof(loc_eng_position_sess_status_types) / sizeof(loc_name_val_s_type); - -const char* loc_get_position_sess_status_name(enum loc_sess_status status) -{ - return loc_get_name_from_val(loc_eng_position_sess_status_types, loc_eng_position_sess_status_num, (long) status); -} - -static loc_name_val_s_type loc_eng_agps_status_names[] = -{ - NAME_VAL( GPS_REQUEST_AGPS_DATA_CONN ), - NAME_VAL( GPS_RELEASE_AGPS_DATA_CONN ), - NAME_VAL( GPS_AGPS_DATA_CONNECTED ), - NAME_VAL( GPS_AGPS_DATA_CONN_DONE ), - NAME_VAL( GPS_AGPS_DATA_CONN_FAILED ) -}; -static int loc_eng_agps_status_num = sizeof(loc_eng_agps_status_names) / sizeof(loc_name_val_s_type); - -const char* loc_get_agps_status_name(AGpsStatusValue status) -{ - return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status); -} diff --git a/loc_api/libloc_api_50001/loc_eng_log.h b/loc_api/libloc_api_50001/loc_eng_log.h index 95a672fd..ec1b7353 100644 --- a/loc_api/libloc_api_50001/loc_eng_log.h +++ b/loc_api/libloc_api_50001/loc_eng_log.h @@ -36,22 +36,8 @@ extern "C" #endif #include -#include -#include -const char* loc_get_gps_status_name(GpsStatusValue gps_status); const char* loc_get_msg_name(int id); -const char* loc_get_position_mode_name(GpsPositionMode mode); -const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur); -const char* loc_get_aiding_data_mask_names(GpsAidingData data); -const char* loc_get_agps_type_name(AGpsType type); -const char* loc_get_ni_type_name(GpsNiType type); -const char* loc_get_ni_response_name(GpsUserResponseType response); -const char* loc_get_ni_encoding_name(GpsNiEncodingType encoding); -const char* loc_get_agps_bear_name(AGpsBearerType bear); -const char* loc_get_server_type_name(LocServerType type); -const char* loc_get_position_sess_status_name(enum loc_sess_status status); -const char* loc_get_agps_status_name(AGpsStatusValue status); #ifdef __cplusplus } diff --git a/loc_api/libloc_api_50001/loc_eng_msg.cpp b/loc_api/libloc_api_50001/loc_eng_msg.cpp deleted file mode 100644 index a296dce3..00000000 --- a/loc_api/libloc_api_50001/loc_eng_msg.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* Copyright (c) 2011, 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 "loc_eng_msg.h" -#include "loc_eng_dmn_conn_glue_msg.h" - -#ifdef _ANDROID_ - -#define LOC_ENG_MSG_REQ_Q_PATH "/data/misc/gpsone_d/loc_eng_msg_req_q" - -#else - -#define LOC_ENG_MSG_REQ_Q_PATH "/tmp/loc_eng_msg_req_q" - -#endif - -int loc_eng_msgget(int * p_req_msgq) -{ - * p_req_msgq = loc_eng_dmn_conn_glue_msgget(LOC_ENG_MSG_REQ_Q_PATH, O_RDWR); - return 0; -} - -int loc_eng_msgremove(int req_msgq) -{ - loc_eng_dmn_conn_glue_piperemove(LOC_ENG_MSG_REQ_Q_PATH, req_msgq); - return 0; -} - -int loc_eng_msgsnd(int msgqid, void * msgp) -{ - int ret = loc_eng_dmn_conn_glue_pipewrite(msgqid, msgp, sizeof(void*)); - return ret; -} - -int loc_eng_msgsnd_raw(int msgqid, void * msgp, unsigned int msgsz) -{ - int result; - - struct msgbuf * pmsg = (struct msgbuf *) msgp; - - if (msgsz < sizeof(struct msgbuf)) { - LOC_LOGE("%s:%d] msgbuf is too small %d\n", __func__, __LINE__, msgsz); - return -1; - } - - pmsg->msgsz = msgsz; - - result = loc_eng_dmn_conn_glue_pipewrite(msgqid, msgp, msgsz); - if (result != (int) msgsz) { - LOC_LOGE("%s:%d] pipe broken %d, msgsz = %d\n", __func__, __LINE__, result, (int) msgsz); - return -1; - } - return result; -} - -int loc_eng_msgrcv(int msgqid, void ** msgp) -{ - int ret = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, sizeof(void*)); - return ret; -} - -int loc_eng_msgrcv_raw(int msgqid, void *msgp, unsigned int msgsz) -{ - int result; - struct msgbuf * pmsg = (struct msgbuf *) msgp; - - if (msgsz < sizeof(struct msgbuf)) { - LOC_LOGE("%s:%d] msgbuf is too small %d\n", __func__, __LINE__, msgsz); - return -1; - } - - result = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, sizeof(struct msgbuf)); - if (result != sizeof(struct msgbuf)) { - LOC_LOGE("%s:%d] pipe broken %d\n", __func__, __LINE__, result); - return -1; - } - - if (msgsz < pmsg->msgsz) { - LOC_LOGE("%s:%d] msgbuf is too small %d < %d\n", __func__, __LINE__, (int) msgsz, (int) pmsg->msgsz); - return -1; - } - - if (pmsg->msgsz > sizeof(struct msgbuf)) { - /* there is msg body */ - msgp += sizeof(struct msgbuf); - - result = loc_eng_dmn_conn_glue_piperead(msgqid, msgp, pmsg->msgsz - sizeof(struct msgbuf)); - - if (result != (int) (pmsg->msgsz - sizeof(struct msgbuf))) { - LOC_LOGE("%s:%d] pipe broken %d, msgid = %p, msgsz = %d\n", __func__, __LINE__, result, - (pmsg->msgid), (int) pmsg->msgsz); - return -1; - } - } - - return pmsg->msgsz; -} - -int loc_eng_msgflush(int msgqid) -{ - return loc_eng_dmn_conn_glue_msgflush(msgqid); -} - -int loc_eng_msgunblock(int msgqid) -{ - return loc_eng_dmn_conn_glue_pipeunblock(msgqid); -} diff --git a/loc_api/libloc_api_50001/loc_eng_msg.h b/loc_api/libloc_api_50001/loc_eng_msg.h index 709f65c9..39b0de52 100644 --- a/loc_api/libloc_api_50001/loc_eng_msg.h +++ b/loc_api/libloc_api_50001/loc_eng_msg.h @@ -31,13 +31,15 @@ #include -#include +#include #include #include -#include "log_util.h" -#include "loc.h" +#include #include -#include "loc_eng_msg_id.h" +#include +#include +#include +#include #ifndef SSID_BUF_SIZE #define SSID_BUF_SIZE (32+1) @@ -53,113 +55,7 @@ extern "C" { #endif /* __cplusplus */ -struct LocPosMode -{ - LocPositionMode mode; - GpsPositionRecurrence recurrence; - uint32_t min_interval; - uint32_t preferred_accuracy; - uint32_t preferred_time; - char credentials[14]; - char provider[8]; - LocPosMode(LocPositionMode m, GpsPositionRecurrence recr, - uint32_t gap, uint32_t accu, uint32_t time, - const char* cred, const char* prov) : - mode(m), recurrence(recr), - min_interval(gap < MIN_POSSIBLE_FIX_INTERVAL ? MIN_POSSIBLE_FIX_INTERVAL : gap), - preferred_accuracy(accu), preferred_time(time) { - memset(credentials, 0, sizeof(credentials)); - memset(provider, 0, sizeof(provider)); - if (NULL != cred) { - memcpy(credentials, cred, sizeof(credentials)-1); - } - if (NULL != prov) { - memcpy(provider, prov, sizeof(provider)-1); - } - } - - LocPosMode() : - mode(LOC_POSITION_MODE_MS_BASED), recurrence(GPS_POSITION_RECURRENCE_PERIODIC), - min_interval(MIN_POSSIBLE_FIX_INTERVAL), preferred_accuracy(50), preferred_time(120000) { - memset(credentials, 0, sizeof(credentials)); - memset(provider, 0, sizeof(provider)); - } - - inline bool equals(const LocPosMode &anotherMode) const - { - return anotherMode.mode == mode && - anotherMode.recurrence == recurrence && - anotherMode.min_interval == min_interval && - anotherMode.preferred_accuracy == preferred_accuracy && - anotherMode.preferred_time == preferred_time && - !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) && - !strncmp(anotherMode.provider, provider, sizeof(provider)-1); - } - - inline void logv() const - { - LOC_LOGV ("Position mode: %s\n Position recurrence: %s\n min interval: %d\n preferred accuracy: %d\n preferred time: %d\n credentials: %s provider: %s", - loc_get_position_mode_name(mode), - loc_get_position_recurrence_name(recurrence), - min_interval, - preferred_accuracy, - preferred_time, - credentials, - provider); - } -}; - -/** Flags to indicate which values are valid in a GpsLocationExtended. */ -typedef uint16_t GpsLocationExtendedFlags; -/** GpsLocationExtended has valid pdop, hdop, vdop. */ -#define GPS_LOCATION_EXTENDED_HAS_DOP 0x0001 -/** GpsLocationExtended has valid altitude mean sea level. */ -#define GPS_LOCATION_EXTENDED_HAS_ALTITUDE_MEAN_SEA_LEVEL 0x0002 -/** UlpLocation has valid magnetic deviation. */ -#define GPS_LOCATION_EXTENDED_HAS_MAG_DEV 0x0004 -/** UlpLocation has valid mode indicator. */ -#define GPS_LOCATION_EXTENDED_HAS_MODE_IND 0x0008 -/** GpsLocationExtended has valid vertical uncertainty */ -#define GPS_LOCATION_EXTENDED_HAS_VERT_UNC 0x0010 -/** GpsLocationExtended has valid speed uncertainty */ -#define GPS_LOCATION_EXTENDED_HAS_SPEED_UNC 0x0020 - -/** Represents gps location extended. */ -typedef struct { - /** set to sizeof(GpsLocationExtended) */ - size_t size; - /** Contains GpsLocationExtendedFlags bits. */ - uint16_t flags; - /** Contains the Altitude wrt mean sea level */ - float altitudeMeanSeaLevel; - /** Contains Position Dilusion of Precision. */ - float pdop; - /** Contains Horizontal Dilusion of Precision. */ - float hdop; - /** Contains Vertical Dilusion of Precision. */ - float vdop; - /** Contains Magnetic Deviation. */ - float magneticDeviation; - /** vertical uncertainty in meters */ - float vert_unc; - /** speed uncertainty in m/s */ - float speed_unc; -} GpsLocationExtended; - -typedef enum { - LOC_ENG_IF_REQUEST_TYPE_SUPL = 0, - LOC_ENG_IF_REQUEST_TYPE_WIFI, - LOC_ENG_IF_REQUEST_TYPE_ANY -} loc_if_req_type_e_type; - -typedef enum { - LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC = 0, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM, - LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU, - LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, - LOC_ENG_IF_REQUEST_SENDER_ID_MODEM, - LOC_ENG_IF_REQUEST_SENDER_ID_UNKNOWN -} loc_if_req_sender_id_e_type; +using namespace loc_core; struct loc_eng_msg { const void* owner; @@ -176,153 +72,6 @@ struct loc_eng_msg { } }; -struct loc_eng_msg_a_glonass_protocol : public loc_eng_msg { - const unsigned long a_glonass_protocol; - inline loc_eng_msg_a_glonass_protocol(void* instance, unsigned long protocol) : - loc_eng_msg(instance, LOC_ENG_MSG_A_GLONASS_PROTOCOL), - a_glonass_protocol(protocol) - { - LOC_LOGV("A-GLONASS protocol: 0x%lx", protocol); - } -}; - -struct loc_eng_msg_suple_version : public loc_eng_msg { - const int supl_version; - inline loc_eng_msg_suple_version(void* instance, int version) : - loc_eng_msg(instance, LOC_ENG_MSG_SUPL_VERSION), - supl_version(version) - { - LOC_LOGV("SUPL Version: %d", version); - } -}; - -struct loc_eng_msg_lpp_config : public loc_eng_msg { - const int lpp_config; - inline loc_eng_msg_lpp_config(void *instance, int profile) : - loc_eng_msg(instance, LOC_ENG_MSG_LPP_CONFIG), - lpp_config(profile) - { - LOC_LOGV("lpp profile: %d", profile); - } -}; - -struct loc_eng_msg_ext_power_config : public loc_eng_msg { - const int isBatteryCharging; - inline loc_eng_msg_ext_power_config(void* instance, int isBattCharging) : - loc_eng_msg(instance, LOC_ENG_MSG_EXT_POWER_CONFIG), - isBatteryCharging(isBattCharging) - { - LOC_LOGV("isBatteryCharging: %d", isBatteryCharging); - } -}; - -struct loc_eng_msg_sensor_control_config : public loc_eng_msg { - const int sensorsDisabled; - inline loc_eng_msg_sensor_control_config(void* instance, int disabled) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_SENSOR_CONTROL_CONFIG), - sensorsDisabled(disabled) - { - LOC_LOGV("Sensors Disabled: %d", disabled); - } -}; - -struct loc_eng_msg_sensor_properties : public loc_eng_msg { - const bool gyroBiasVarianceRandomWalk_valid; - const float gyroBiasVarianceRandomWalk; - const bool accelRandomWalk_valid; - const float accelRandomWalk; - const bool angleRandomWalk_valid; - const float angleRandomWalk; - const bool rateRandomWalk_valid; - const float rateRandomWalk; - const bool velocityRandomWalk_valid; - const float velocityRandomWalk; - inline loc_eng_msg_sensor_properties(void* instance, bool gyroBiasRandomWalk_valid, float gyroBiasRandomWalk, - bool accelRandomWalk_valid, float accelRandomWalk, - bool angleRandomWalk_valid, float angleRandomWalk, - bool rateRandomWalk_valid, float rateRandomWalk, - bool velocityRandomWalk_valid, float velocityRandomWalk) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_SENSOR_PROPERTIES), - gyroBiasVarianceRandomWalk_valid(gyroBiasRandomWalk_valid), - gyroBiasVarianceRandomWalk(gyroBiasRandomWalk), - accelRandomWalk_valid(accelRandomWalk_valid), - accelRandomWalk(accelRandomWalk), - angleRandomWalk_valid(angleRandomWalk_valid), - angleRandomWalk(angleRandomWalk), - rateRandomWalk_valid(rateRandomWalk_valid), - rateRandomWalk(rateRandomWalk), - velocityRandomWalk_valid(velocityRandomWalk_valid), - velocityRandomWalk(velocityRandomWalk) - { - LOC_LOGV("Sensor properties validity, Gyro Random walk: %d Accel Random Walk: %d " - "Angle Random Walk: %d Rate Random Walk: %d " - "Velocity Random Walk: %d", - gyroBiasRandomWalk_valid, - accelRandomWalk_valid, - angleRandomWalk_valid, - rateRandomWalk_valid, - velocityRandomWalk_valid - ); - LOC_LOGV("Sensor properties, Gyro Random walk: %f Accel Random Walk: %f " - "Angle Random Walk: %f Rate Random Walk: %f " - "Velocity Random Walk: %f", - gyroBiasRandomWalk, - accelRandomWalk, - angleRandomWalk, - rateRandomWalk, - velocityRandomWalk - ); - } -}; - -struct loc_eng_msg_sensor_perf_control_config : public loc_eng_msg { - const int controlMode; - const int accelSamplesPerBatch; - const int accelBatchesPerSec; - const int gyroSamplesPerBatch; - const int gyroBatchesPerSec; - const int accelSamplesPerBatchHigh; - const int accelBatchesPerSecHigh; - const int gyroSamplesPerBatchHigh; - const int gyroBatchesPerSecHigh; - const int algorithmConfig; - inline loc_eng_msg_sensor_perf_control_config(void* instance, int controlMode, - int accelSamplesPerBatch, int accelBatchesPerSec, - int gyroSamplesPerBatch, int gyroBatchesPerSec, - int accelSamplesPerBatchHigh, int accelBatchesPerSecHigh, - int gyroSamplesPerBatchHigh, int gyroBatchesPerSecHigh, - int algorithmConfig) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_SENSOR_PERF_CONTROL_CONFIG), - controlMode(controlMode), - accelSamplesPerBatch(accelSamplesPerBatch), - accelBatchesPerSec(accelBatchesPerSec), - gyroSamplesPerBatch(gyroSamplesPerBatch), - gyroBatchesPerSec(gyroBatchesPerSec), - accelSamplesPerBatchHigh(accelSamplesPerBatchHigh), - accelBatchesPerSecHigh(accelBatchesPerSecHigh), - gyroSamplesPerBatchHigh(gyroSamplesPerBatchHigh), - gyroBatchesPerSecHigh(gyroBatchesPerSecHigh), - algorithmConfig(algorithmConfig) - { - LOC_LOGV("Sensor Perf Control Config (performanceControlMode)(%u) " - "accel(#smp,#batches) (%u,%u) gyro(#smp,#batches) (%u,%u), " - "accel_high(#smp,#batches) (%u,%u) gyro_high(#smp,#batches) (%u,%u), " - "algorithmConfig(%u)\n", - controlMode, - accelSamplesPerBatch, - accelBatchesPerSec, - gyroSamplesPerBatch, - gyroBatchesPerSec, - accelSamplesPerBatchHigh, - accelBatchesPerSecHigh, - gyroSamplesPerBatchHigh, - gyroBatchesPerSecHigh, - algorithmConfig - ); - } -}; - - struct loc_eng_msg_position_mode : public loc_eng_msg { const LocPosMode pMode; inline loc_eng_msg_position_mode(void* instance, @@ -334,45 +83,6 @@ struct loc_eng_msg_position_mode : public loc_eng_msg { } }; -struct loc_eng_msg_set_time : public loc_eng_msg { - const GpsUtcTime time; - const int64_t timeReference; - const int uncertainty; - inline loc_eng_msg_set_time(void* instance, - GpsUtcTime t, - int64_t tf, - int unc) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_TIME), - time(t), timeReference(tf), uncertainty(unc) - { - LOC_LOGV("time: %lld\n timeReference: %lld\n uncertainty: %d", - time, timeReference, uncertainty); - } -}; - -struct loc_eng_msg_inject_location : public loc_eng_msg { - const double latitude; - const double longitude; - const float accuracy; - inline loc_eng_msg_inject_location(void* instance, double lat, - double longi, float accur) : - loc_eng_msg(instance, LOC_ENG_MSG_INJECT_LOCATION), - latitude(lat), longitude(longi), accuracy(accur) - { - LOC_LOGV("latitude: %f\n longitude: %f\n accuracy: %f", - latitude, longitude, accuracy); - } -}; - -struct loc_eng_msg_delete_aiding_data : public loc_eng_msg { - const GpsAidingData type; - inline loc_eng_msg_delete_aiding_data(void* instance, GpsAidingData data) : - loc_eng_msg(instance, LOC_ENG_MSG_DELETE_AIDING_DATA), type(data) - { - LOC_LOGV("aiding data msak %d", type); - } -}; - struct loc_eng_msg_report_position : public loc_eng_msg { const UlpLocation location; const GpsLocationExtended locationExtended; @@ -427,438 +137,232 @@ struct loc_eng_msg_report_sv : public loc_eng_msg { } }; -struct loc_eng_msg_report_status : public loc_eng_msg { - const GpsStatusValue status; - inline loc_eng_msg_report_status(void* instance, GpsStatusValue engineStatus) : - loc_eng_msg(instance, LOC_ENG_MSG_REPORT_STATUS), status(engineStatus) - { - LOC_LOGV("status: %s", loc_get_gps_status_name(status)); - } -}; -struct loc_eng_msg_report_nmea : public loc_eng_msg { - char* const nmea; - const int length; - inline loc_eng_msg_report_nmea(void* instance, - const char* data, - int len) : - loc_eng_msg(instance, LOC_ENG_MSG_REPORT_NMEA), - nmea(new char[len]), length(len) - { - memcpy((void*)nmea, (void*)data, len); - LOC_LOGV("length: %d\n nmea: %p - %c%c%c", - length, nmea, nmea[3], nmea[4], nmea[5]); - } - inline ~loc_eng_msg_report_nmea() - { - delete[] nmea; - } -}; - -struct loc_eng_msg_report_xtra_server : public loc_eng_msg { - char *server1; - char *server2; - char *server3; - inline loc_eng_msg_report_xtra_server(void *instance, - const char *url1, - const char *url2, - const char *url3, - const int maxlength) : - loc_eng_msg(instance, LOC_ENG_MSG_REPORT_XTRA_SERVER), - server1(new char[maxlength+1]), server2(new char[maxlength+1]), server3(new char[maxlength+1]) - { - strlcpy(server1, url1, maxlength); - strlcpy(server2, url2, maxlength); - strlcpy(server3, url3, maxlength); - - LOC_LOGV("maxlength: %d\n server1: %s\n server2: %s\n server3: %s\n", - maxlength, server1, server2, server3); - } - inline ~loc_eng_msg_report_xtra_server() - { - delete[] server1; - delete[] server2; - delete[] server3; - } -}; - -struct loc_eng_msg_request_bit : public loc_eng_msg { - const loc_if_req_type_e_type ifType; - const int ipv4Addr; - char* const ipv6Addr; - inline loc_eng_msg_request_bit(void* instance, - loc_if_req_type_e_type type, - int ipv4, - char* ipv6) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_BIT), - ifType(type), ipv4Addr(ipv4), - ipv6Addr(NULL == ipv6 ? NULL : new char[16]) - { - if (NULL != ipv6Addr) - memcpy(ipv6Addr, ipv6, 16); - LOC_LOGV("ifType: %d, ipv4: %d.%d.%d.%d, ipv6: %s", ifType, - (unsigned char)(ipv4>>24), - (unsigned char)(ipv4>>16), - (unsigned char)(ipv4>>8), - (unsigned char)ipv4, - NULL != ipv6Addr ? ipv6Addr : ""); - } - - inline ~loc_eng_msg_request_bit() - { - if (NULL != ipv6Addr) { - delete[] ipv6Addr; - } - } -}; - -struct loc_eng_msg_request_wifi : public loc_eng_msg { - const loc_if_req_type_e_type ifType; - const loc_if_req_sender_id_e_type senderId; - char* const ssid; - char* const password; - inline loc_eng_msg_request_wifi(void* instance, - loc_if_req_type_e_type type, - loc_if_req_sender_id_e_type sender_id, - char* s, - char* p) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_WIFI), - ifType(type), senderId(sender_id), - ssid(NULL == s ? NULL : new char[SSID_BUF_SIZE]), - password(NULL == p ? NULL : new char[SSID_BUF_SIZE]) - { - if (NULL != ssid) - strlcpy(ssid, s, SSID_BUF_SIZE); - if (NULL != password) - strlcpy(password, p, SSID_BUF_SIZE); - LOC_LOGV("ifType: %d, senderId: %d, ssid: %s, password: %s", - ifType, - senderId, - NULL != ssid ? ssid : "", - NULL != password ? password : ""); - } - - inline ~loc_eng_msg_request_wifi() - { - if (NULL != ssid) { - delete[] ssid; - } - if (NULL != password) { - delete[] password; - } - } -}; - -struct loc_eng_msg_release_bit : public loc_eng_msg { - const loc_if_req_type_e_type ifType; - const int ipv4Addr; - char* const ipv6Addr; - inline loc_eng_msg_release_bit(void* instance, - loc_if_req_type_e_type type, - int ipv4, - char* ipv6) : - loc_eng_msg(instance, LOC_ENG_MSG_RELEASE_BIT), - ifType(type), ipv4Addr(ipv4), - ipv6Addr(NULL == ipv6 ? NULL : new char[16]) - { - if (NULL != ipv6Addr) - memcpy(ipv6Addr, ipv6, 16); - LOC_LOGV("ifType: %d, ipv4: %d.%d.%d.%d, ipv6: %s", ifType, - (unsigned char)(ipv4>>24), - (unsigned char)(ipv4>>16), - (unsigned char)(ipv4>>8), - (unsigned char)ipv4, - NULL != ipv6Addr ? ipv6Addr : ""); - } - - inline ~loc_eng_msg_release_bit() - { - if (NULL != ipv6Addr) { - delete[] ipv6Addr; - } - } -}; - -struct loc_eng_msg_release_wifi : public loc_eng_msg { - const loc_if_req_type_e_type ifType; - const loc_if_req_sender_id_e_type senderId; - char* const ssid; - char* const password; - inline loc_eng_msg_release_wifi(void* instance, - loc_if_req_type_e_type type, - loc_if_req_sender_id_e_type sender_id, - char* s, - char* p) : - loc_eng_msg(instance, LOC_ENG_MSG_RELEASE_WIFI), - ifType(type), senderId(sender_id), - ssid(NULL == s ? NULL : new char[SSID_BUF_SIZE]), - password(NULL == p ? NULL : new char[SSID_BUF_SIZE]) - { - if (NULL != s) - strlcpy(ssid, s, SSID_BUF_SIZE); - if (NULL != p) - strlcpy(password, p, SSID_BUF_SIZE); - LOC_LOGV("ifType: %d, senderId: %d, ssid: %s, password: %s", - ifType, - senderId, - NULL != ssid ? ssid : "", - NULL != password ? password : ""); - } - - inline ~loc_eng_msg_release_wifi() - { - if (NULL != ssid) { - delete[] ssid; - } - if (NULL != password) { - delete[] password; - } - } -}; - -struct loc_eng_msg_request_atl : public loc_eng_msg { - const int handle; - const AGpsType type; - inline loc_eng_msg_request_atl(void* instance, int hndl, - AGpsType agps_type) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_ATL), - handle(hndl), type(agps_type) - { - LOC_LOGV("handle: %d\n agps type: %s", - handle, - loc_get_agps_type_name(type)); - } -}; - -struct loc_eng_msg_request_supl_es : public loc_eng_msg { - const int handle; - inline loc_eng_msg_request_supl_es(void* instance, int hndl) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_SUPL_ES), - handle(hndl) - { - LOC_LOGV("handle: %d\n", handle); - } -}; - -struct loc_eng_msg_close_data_call: public loc_eng_msg { - inline loc_eng_msg_close_data_call(void *instance) : - loc_eng_msg(instance, LOC_ENG_MSG_CLOSE_DATA_CALL) - { - LOC_LOGV("%s:%d]Close data call: ", __func__, __LINE__); - } -}; -struct loc_eng_msg_release_atl : public loc_eng_msg { - const int handle; - inline loc_eng_msg_release_atl(void* instance, int hndl) : - loc_eng_msg(instance, LOC_ENG_MSG_RELEASE_ATL), handle(hndl) - { - LOC_LOGV("handle: %d", handle); - } -}; - -struct loc_eng_msg_request_ni : public loc_eng_msg { - const GpsNiNotification notify; - const void *passThroughData; - inline loc_eng_msg_request_ni(void* instance, - GpsNiNotification ¬if, const void* data) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_NI), - notify(notif), passThroughData(data) - { - LOC_LOGV("id: %d\n type: %s\n flags: %d\n time out: %d\n default response: %s\n requestor id encoding: %s\n text encoding: %s\n passThroughData: %p", - notify.notification_id, - loc_get_ni_type_name(notify.ni_type), - notify.notify_flags, - notify.timeout, - loc_get_ni_response_name(notify.default_response), - loc_get_ni_encoding_name(notify.requestor_id_encoding), - loc_get_ni_encoding_name(notify.text_encoding), - passThroughData); - } -}; - -struct loc_eng_msg_inform_ni_response : public loc_eng_msg { - const GpsUserResponseType response; - const void *passThroughData; - inline loc_eng_msg_inform_ni_response(void* instance, - GpsUserResponseType resp, - const void* data) : - loc_eng_msg(instance, LOC_ENG_MSG_INFORM_NI_RESPONSE), - response(resp), passThroughData(data) - { - LOC_LOGV("response: %s\n passThroughData: %p", - loc_get_ni_response_name(response), - passThroughData); - } - inline ~loc_eng_msg_inform_ni_response() - { - // this is a bit weird since passThroughData is not - // allocated by this class. But there is no better way. - // passThroughData actually won't be NULL here. - // But better safer than sorry. - if (NULL != passThroughData) { - free((void*)passThroughData); - } - } -}; - -struct loc_eng_msg_set_apn : public loc_eng_msg { - char* const apn; - inline loc_eng_msg_set_apn(void* instance, const char* name, int len) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_APN), - apn(new char[len+1]) - { - memcpy((void*)apn, (void*)name, len); - apn[len] = 0; - LOC_LOGV("apn: %s", apn); - } - inline ~loc_eng_msg_set_apn() - { - delete[] apn; - } +struct LocEngPositionMode : public LocMsg { + LocEngAdapter* mAdapter; + const LocPosMode mPosMode; + LocEngPositionMode(LocEngAdapter* adapter, + LocPosMode &mode); + virtual void proc() const; + virtual void log() const; + void send() const; }; - -struct loc_eng_msg_set_server_ipv4 : public loc_eng_msg { - const unsigned int nl_addr; - const int port; - const LocServerType serverType; - inline loc_eng_msg_set_server_ipv4(void* instance, - unsigned int ip, - int p, - LocServerType type) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_SERVER_IPV4), - nl_addr(ip), port(p), serverType(type) - { - LOC_LOGV("addr: %x\n , port: %d\n type: %s", nl_addr, port, loc_get_server_type_name(serverType)); - } +struct LocEngStartFix : public LocMsg { + loc_eng_data_s_type* mLocEng; + LocEngStartFix(loc_eng_data_s_type* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; }; - -struct loc_eng_msg_set_server_url : public loc_eng_msg { - const int len; - char* const url; - inline loc_eng_msg_set_server_url(void* instance, - const char* urlString, - int url_len) : - loc_eng_msg(instance, LOC_ENG_MSG_SET_SERVER_URL), - len(url_len), url(new char[len+1]) - { - memcpy((void*)url, (void*)urlString, url_len); - url[len] = 0; - LOC_LOGV("url: %s", url); - } - inline ~loc_eng_msg_set_server_url() - { - delete[] url; - } +struct LocEngStopFix : public LocMsg { + loc_eng_data_s_type* mLocEng; + LocEngStopFix(loc_eng_data_s_type* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; }; -struct loc_eng_msg_inject_xtra_data : public loc_eng_msg { - char* const data; - const int length; - inline loc_eng_msg_inject_xtra_data(void* instance, char* d, int l) : - loc_eng_msg(instance, LOC_ENG_MSG_INJECT_XTRA_DATA), - data(new char[l]), length(l) - { - memcpy((void*)data, (void*)d, l); - LOC_LOGV("length: %d\n data: %p", length, data); - } - inline ~loc_eng_msg_inject_xtra_data() - { - delete[] data; - } +struct LocEngReportPosition : public LocMsg { + void* mLocEng; + const UlpLocation mLocation; + const GpsLocationExtended mLocationExtended; + const void* mLocationExt; + const enum loc_sess_status mStatus; + const LocPosTechMask mTechMask; + LocEngReportPosition(void* locEng, + UlpLocation &loc, + GpsLocationExtended &locExtended, + void* locExt, + enum loc_sess_status st, + LocPosTechMask technology); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; }; -struct loc_eng_msg_request_xtra_server : public loc_eng_msg { - inline loc_eng_msg_request_xtra_server(void *instance) : - loc_eng_msg(instance, LOC_ENG_MSG_REQUEST_XTRA_SERVER) - { - - } +struct LocEngReportSv : public LocMsg { + void* mLocEng; + const GpsSvStatus mSvStatus; + const GpsLocationExtended mLocationExtended; + const void* mSvExt; + LocEngReportSv(void* locEng, + GpsSvStatus &sv, + GpsLocationExtended &locExtended, + void* svExtended); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; }; -struct loc_eng_msg_atl_open_success : public loc_eng_msg { - const AGpsType agpsType; - const int length; - char* const apn; - const AGpsBearerType bearerType; - inline loc_eng_msg_atl_open_success(void* instance, - AGpsType atype, - const char* name, - int len, - AGpsBearerType btype) : - loc_eng_msg(instance, LOC_ENG_MSG_ATL_OPEN_SUCCESS), - agpsType(atype), length(len), - apn(new char[len+1]), bearerType(btype) - { - memcpy((void*)apn, (void*)name, len); - apn[len] = 0; - LOC_LOGV("agps type: %s\n apn: %s\n bearer type: %s", - loc_get_agps_type_name(agpsType), - apn, - loc_get_agps_bear_name(bearerType)); - } - inline ~loc_eng_msg_atl_open_success() - { - delete[] apn; - } +struct LocEngReportStatus : public LocMsg { + void* mLocEng; + const GpsStatusValue mStatus; + LocEngReportStatus(void* locEng, + GpsStatusValue engineStatus); + virtual void proc() const; + void locallog() const; + virtual void log() const; }; -struct loc_eng_msg_atl_open_failed : public loc_eng_msg { - const AGpsStatusValue agpsType; - inline loc_eng_msg_atl_open_failed(void* instance, - AGpsStatusValue atype) : - loc_eng_msg(instance, LOC_ENG_MSG_ATL_OPEN_FAILED), - agpsType(atype) +struct LocEngReportNmea : public LocMsg { + void* mLocEng; + char* const mNmea; + const int mLen; + LocEngReportNmea(void* locEng, + const char* data, int len); + inline virtual ~LocEngReportNmea() { - LOC_LOGV("agps type %s", - loc_get_agps_type_name(agpsType)); + delete[] mNmea; } + virtual void proc() const; + void locallog() const; + virtual void log() const; }; -struct loc_eng_msg_atl_closed : public loc_eng_msg { - const AGpsType agpsType; - inline loc_eng_msg_atl_closed(void* instance, - AGpsType atype) : - loc_eng_msg(instance, LOC_ENG_MSG_ATL_CLOSED), - agpsType(atype) +struct LocEngReportXtraServer : public LocMsg { + void* mLocEng; + int mMaxLen; + char *mServers; + LocEngReportXtraServer(void* locEng, + const char *url1, const char *url2, + const char *url3, const int maxlength); + inline virtual ~LocEngReportXtraServer() { - LOC_LOGV("agps type %s", - loc_get_agps_type_name(agpsType)); + delete[] mServers; } + virtual void proc() const; + void locallog() const; + virtual void log() const; }; -struct loc_eng_msg_set_data_enable : public loc_eng_msg { - const int enable; - char* const apn; - const int length; - inline loc_eng_msg_set_data_enable(void* instance, - const char* name, - int len, - int yes) : - loc_eng_msg(instance, LOC_ENG_MSG_ENABLE_DATA), - enable(yes), apn(new char[len+1]), length(len) - { - memcpy((void*)apn, (void*)name, len); - apn[len] = 0; - LOC_LOGV("apn: %s\n enable: %d", apn, enable); - } - inline ~loc_eng_msg_set_data_enable() - { - delete[] apn; - } +struct LocEngSuplEsOpened : public LocMsg { + void* mLocEng; + LocEngSuplEsOpened(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngSuplEsClosed : public LocMsg { + void* mLocEng; + LocEngSuplEsClosed(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestSuplEs : public LocMsg { + void* mLocEng; + const int mID; + LocEngRequestSuplEs(void* locEng, int id); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestATL : public LocMsg { + void* mLocEng; + const int mID; + const AGpsExtType mType; + LocEngRequestATL(void* locEng, int id, + AGpsExtType agps_type); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReleaseATL : public LocMsg { + void* mLocEng; + const int mID; + LocEngReleaseATL(void* locEng, int id); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngReqRelBIT : public LocMsg { + void* mLocEng; + const AGpsExtType mType; + const int mIPv4Addr; + char* const mIPv6Addr; + const bool mIsReq; + LocEngReqRelBIT(void* instance, AGpsExtType type, + int ipv4, char* ipv6, bool isReq); + virtual ~LocEngReqRelBIT(); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngReqRelWifi : public LocMsg { + void* mLocEng; + const AGpsExtType mType; + const loc_if_req_sender_id_e_type mSenderId; + char* const mSSID; + char* const mPassword; + const bool mIsReq; + LocEngReqRelWifi(void* locEng, AGpsExtType type, + loc_if_req_sender_id_e_type sender_id, + char* s, char* p, bool isReq); + virtual ~LocEngReqRelWifi(); + virtual void proc() const; + void locallog() const; + virtual void log() const; + void send() const; +}; + +struct LocEngRequestXtra : public LocMsg { + void* mLocEng; + LocEngRequestXtra(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestTime : public LocMsg { + void* mLocEng; + LocEngRequestTime(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngRequestNi : public LocMsg { + void* mLocEng; + const GpsNiNotification mNotify; + const void *mPayload; + LocEngRequestNi(void* locEng, + GpsNiNotification ¬if, + const void* data); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngDown : public LocMsg { + void* mLocEng; + LocEngDown(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; +}; + +struct LocEngUp : public LocMsg { + void* mLocEng; + LocEngUp(void* locEng); + virtual void proc() const; + void locallog() const; + virtual void log() const; }; -void loc_eng_msg_sender(void* loc_eng_data_p, void* msg); -int loc_eng_msgget(int * p_req_msgq); -int loc_eng_msgremove(int req_msgq); -int loc_eng_msgsnd(int msgqid, void * msgp); -int loc_eng_msgrcv(int msgqid, void ** msgp); -int loc_eng_msgsnd_raw(int msgqid, void * msgp, unsigned int msgsz); -int loc_eng_msgrcv_raw(int msgqid, void *msgp, unsigned int msgsz); -int loc_eng_msgflush(int msgqid); -int loc_eng_msgunblock(int msgqid); #ifdef __cplusplus } diff --git a/loc_api/libloc_api_50001/loc_eng_ni.cpp b/loc_api/libloc_api_50001/loc_eng_ni.cpp index e9ba91d0..f017cab6 100644 --- a/loc_api/libloc_api_50001/loc_eng_ni.cpp +++ b/loc_api/libloc_api_50001/loc_eng_ni.cpp @@ -39,11 +39,15 @@ #include #include #include +#include #include #include "log_util.h" #include "platform_lib_includes.h" + +using namespace loc_core; + /*============================================================================= * * DATA DECLARATION @@ -57,6 +61,42 @@ *============================================================================*/ static void* ni_thread_proc(void *args); +struct LocEngInformNiResponse : public LocMsg { + LocEngAdapter* mAdapter; + const GpsUserResponseType mResponse; + const void *mPayload; + inline LocEngInformNiResponse(LocEngAdapter* adapter, + GpsUserResponseType resp, + const void* data) : + LocMsg(), mAdapter(adapter), + mResponse(resp), mPayload(data) + { + locallog(); + } + inline ~LocEngInformNiResponse() + { + // this is a bit weird since mPayload is not + // allocated by this class. But there is no better way. + // mPayload actually won't be NULL here. + free((void*)mPayload); + } + inline virtual void proc() const + { + mAdapter->informNiResponse(mResponse, mPayload); + } + inline void locallog() const + { + LOC_LOGV("LocEngInformNiResponse - " + "response: %s\n mPayload: %p", + loc_get_ni_response_name(mResponse), + mPayload); + } + inline virtual void log() const + { + locallog(); + } +}; + /*=========================================================================== FUNCTION loc_eng_ni_request_handler @@ -179,15 +219,15 @@ static void* ni_thread_proc(void *args) loc_eng_ni_data_p->respRecvd = FALSE; /* Reset the user response flag for the next session*/ // adding this check to support modem restart, in which case, we need the thread - // to exit without calling sending data to loc_eng_msg_q. We made sure that - // rawRequest is NULL in loc_eng_ni_reset_on_engine_restart() - loc_eng_msg_inform_ni_response *msg = NULL; + // to exit without calling sending data. We made sure that rawRequest is NULL in + // loc_eng_ni_reset_on_engine_restart() + LocEngAdapter* adapter = loc_eng_data_p->adapter; + LocEngInformNiResponse *msg = NULL; if (NULL != loc_eng_ni_data_p->rawRequest) { - loc_eng_data_s_type *loc_eng_data_p = (loc_eng_data_s_type*)args; - msg = new loc_eng_msg_inform_ni_response(loc_eng_data_p, - loc_eng_ni_data_p->resp, - loc_eng_ni_data_p->rawRequest); + msg = new LocEngInformNiResponse(adapter, + loc_eng_ni_data_p->resp, + loc_eng_ni_data_p->rawRequest); loc_eng_ni_data_p->rawRequest = NULL; } pthread_mutex_unlock(&loc_eng_ni_data_p->tLock); @@ -196,7 +236,7 @@ static void* ni_thread_proc(void *args) loc_eng_ni_data_p->reqID++; if (NULL != msg) { - loc_eng_msg_sender(loc_eng_data_p, msg); + adapter->sendMsg(msg); } EXIT_LOG(%s, VOID_RET); diff --git a/loc_api/libloc_api_50001/loc_eng_nmea.cpp b/loc_api/libloc_api_50001/loc_eng_nmea.cpp index c4be2ab8..f5f746b2 100644 --- a/loc_api/libloc_api_50001/loc_eng_nmea.cpp +++ b/loc_api/libloc_api_50001/loc_eng_nmea.cpp @@ -259,7 +259,7 @@ void loc_eng_nmea_generate_pos(loc_eng_data_s_type *loc_eng_data_p, if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix - else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->client_handle->getPositionMode().mode) + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous else length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential @@ -412,7 +412,7 @@ void loc_eng_nmea_generate_pos(loc_eng_data_s_type *loc_eng_data_p, if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) length = snprintf(pMarker, lengthRemaining, "%c", 'N'); // N means no fix - else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->client_handle->getPositionMode().mode) + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) length = snprintf(pMarker, lengthRemaining, "%c", 'A'); // A means autonomous else length = snprintf(pMarker, lengthRemaining, "%c", 'D'); // D means differential @@ -490,7 +490,7 @@ void loc_eng_nmea_generate_pos(loc_eng_data_s_type *loc_eng_data_p, char gpsQuality; if (!(location.gpsLocation.flags & GPS_LOCATION_HAS_LAT_LONG)) gpsQuality = '0'; // 0 means no fix - else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->client_handle->getPositionMode().mode) + else if (LOC_POSITION_MODE_STANDALONE == loc_eng_data_p->adapter->getPositionMode().mode) gpsQuality = '1'; // 1 means GPS fix else gpsQuality = '2'; // 2 means DGPS fix diff --git a/loc_api/libloc_api_50001/loc_eng_xtra.cpp b/loc_api/libloc_api_50001/loc_eng_xtra.cpp index 5c030b0b..45822867 100644 --- a/loc_api/libloc_api_50001/loc_eng_xtra.cpp +++ b/loc_api/libloc_api_50001/loc_eng_xtra.cpp @@ -31,10 +31,57 @@ #define LOG_TAG "LocSvc_eng" #include -#include +#include #include "log_util.h" #include "platform_lib_includes.h" +using namespace loc_core; + +struct LocEngRequestXtraServer : public LocMsg { + LocEngAdapter* mAdapter; + inline LocEngRequestXtraServer(LocEngAdapter* adapter) : + LocMsg(), mAdapter(adapter) + { + locallog(); + } + inline virtual void proc() const { + mAdapter->requestXtraServer(); + } + inline void locallog() const { + LOC_LOGV("LocEngRequestXtraServer"); + } + inline virtual void log() const { + locallog(); + } +}; + +struct LocEngInjectXtraData : public LocMsg { + LocEngAdapter* mAdapter; + char* mData; + const int mLen; + inline LocEngInjectXtraData(LocEngAdapter* adapter, + char* data, int len): + LocMsg(), mAdapter(adapter), + mData(new char[len]), mLen(len) + { + memcpy((void*)mData, (void*)data, len); + locallog(); + } + inline ~LocEngInjectXtraData() + { + delete[] mData; + } + inline virtual void proc() const { + mAdapter->setXtraData(mData, mLen); + } + inline void locallog() const { + LOC_LOGV("length: %d\n data: %p", mLen, mData); + } + inline virtual void log() const { + locallog(); + } +}; + /*=========================================================================== FUNCTION loc_eng_xtra_init @@ -89,9 +136,8 @@ SIDE EFFECTS int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data, char* data, int length) { - loc_eng_msg_inject_xtra_data *msg(new loc_eng_msg_inject_xtra_data(&loc_eng_data, - data, length)); - loc_eng_msg_sender(&loc_eng_data, msg); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngInjectXtraData(adapter, data, length)); return 0; } @@ -113,12 +159,8 @@ SIDE EFFECTS ===========================================================================*/ int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data) { - loc_eng_msg_request_xtra_server *msg(new loc_eng_msg_request_xtra_server(&loc_eng_data)); - - if (NULL == msg) - return -1; - - loc_eng_msg_sender(&loc_eng_data, msg); + LocEngAdapter* adapter = loc_eng_data.adapter; + adapter->sendMsg(new LocEngRequestXtraServer(adapter)); return 0;