diff --git a/loc_api/Android.mk b/loc_api/Android.mk index 7e09d5f9..bf5281ea 100755 --- a/loc_api/Android.mk +++ b/loc_api/Android.mk @@ -12,6 +12,8 @@ LOCAL_PATH := $(call my-dir) GPS_DIR_LIST := +ifeq (exists, $(shell test -d $(TOP)/vendor/qcom/proprietary/qmi-frameworks && echo exists)) + # add RPC dirs if RPC is available ifneq ($(TARGET_NO_RPC),true) @@ -25,6 +27,8 @@ GPS_DIR_LIST += $(LOCAL_PATH)/loc_api_v02/ endif #TARGET_NO_RPC +endif + GPS_DIR_LIST += $(LOCAL_PATH)/libloc_api_50001/ #call the subfolders 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/LocApiRpcAdapter.cpp index 53effc56..ec98bed2 100755 --- 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/LocApiRpcAdapter.cpp @@ -98,7 +98,7 @@ static void loc_rpc_global_cb(void* user, CLIENT* clnt, enum rpc_reset_event eve } -LocApiAdapter* getLocApiAdapter(LocEng &locEng) +extern "C" LocApiAdapter* getLocApiAdapter(LocEng &locEng) { return new LocApiRpcAdapter(locEng); } diff --git a/loc_api/libloc_api_50001/Android.mk b/loc_api/libloc_api_50001/Android.mk index 0a5a0a10..f37ca311 100755 --- a/loc_api/libloc_api_50001/Android.mk +++ b/loc_api/libloc_api_50001/Android.mk @@ -18,7 +18,8 @@ LOCAL_MODULE_TAGS := optional LOCAL_SHARED_LIBRARIES := \ libutils \ libcutils \ - libgps.utils + libgps.utils \ + libdl LOCAL_SRC_FILES += \ loc_eng_log.cpp \ @@ -78,13 +79,6 @@ LOCAL_SRC_FILES += \ loc_eng_dmn_conn_glue_msg.c \ loc_eng_dmn_conn_glue_pipe.c -## Check if RPC is not unsupported -ifneq ($(TARGET_NO_RPC),true) -LOCAL_SHARED_LIBRARIES += libloc_api-rpc-qc -else -LOCAL_SHARED_LIBRARIES += libloc_api_v02 -endif #TARGET_NO_RPC - LOCAL_CFLAGS += \ -fno-short-enums \ -D_ANDROID_ diff --git a/loc_api/libloc_api_50001/LocApiAdapter.cpp b/loc_api/libloc_api_50001/LocApiAdapter.cpp index e631642d..a6a1ed94 100755 --- a/loc_api/libloc_api_50001/LocApiAdapter.cpp +++ b/loc_api/libloc_api_50001/LocApiAdapter.cpp @@ -29,6 +29,7 @@ #define LOG_NDDEBUG 0 #define LOG_TAG "LocSvc_adapter" +#include #include #include "loc_eng_msg.h" #include "loc_log.h" @@ -66,6 +67,35 @@ 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) { + LOC_LOGI("%s: dlopen(libloc_api_v02.so) failed, trying to load libloc_api-rpc-qc.so", __FUNCTION__); + handle = dlopen ("libloc_api-rpc-qc.so", RTLD_NOW); + } + else + LOC_LOGE("%s: dlopen(libloc_api_v02.so) succeeded.", __FUNCTION__); + + if (!handle) { + LOC_LOGI("%s: dlopen(libloc_api-rpc-qc.so) failed, constructing LocApiAdapter", __FUNCTION__); + adapter = new LocApiAdapter(locEng); + } else { + getLocApiAdapter_t* getHandle = (getLocApiAdapter_t*)dlsym(handle, "getLocApiAdapter"); + if (!getHandle) { + LOC_LOGE("%s: dlsym(getLocApiAdapter) failed", __FUNCTION__); + return NULL; + } + adapter = (*getHandle)(locEng); + } + + return adapter; +} + int LocApiAdapter::hexcode(char *hexstring, int string_size, const char *data, int data_size) { diff --git a/loc_api/libloc_api_50001/LocApiAdapter.h b/loc_api/libloc_api_50001/LocApiAdapter.h index 033a034c..5e8a1da8 100755 --- a/loc_api/libloc_api_50001/LocApiAdapter.h +++ b/loc_api/libloc_api_50001/LocApiAdapter.h @@ -107,6 +107,8 @@ public: //LocApiAdapter(int q, reportCb_t[LOC_API_ADAPTER_EVENT_MAX] callbackTable); virtual ~LocApiAdapter(); + static LocApiAdapter* getLocApiAdapter(LocEng &locEng); + static int hexcode(char *hexstring, int string_size, const char *data, int data_size); static int decodeAddress(char *addr_string, int string_size, @@ -199,7 +201,8 @@ public: {LOC_LOGW("%s: default implementation invoked", __func__); return LOC_API_ADAPTER_ERR_SUCCESS;} }; -LocApiAdapter* getLocApiAdapter(LocEng &locEng); +extern "C" LocApiAdapter* getLocApiAdapter(LocEng &locEng); +typedef LocApiAdapter* (getLocApiAdapter_t)(LocEng&); #endif //LOC_API_RPC_ADAPTER_H diff --git a/loc_api/libloc_api_50001/loc_eng.cpp b/loc_api/libloc_api_50001/loc_eng.cpp index 137a7227..747268da 100644 --- a/loc_api/libloc_api_50001/loc_eng.cpp +++ b/loc_api/libloc_api_50001/loc_eng.cpp @@ -265,7 +265,7 @@ int loc_eng_init(loc_eng_data_s_type &loc_eng_data, LocCallbacks* callbacks, LocEng locEngHandle(&loc_eng_data, event, loc_eng_data.acquire_wakelock_cb, loc_eng_data.release_wakelock_cb, loc_eng_msg_sender, callbacks->location_ext_parser, callbacks->sv_ext_parser); - loc_eng_data.client_handle = getLocApiAdapter(locEngHandle); + loc_eng_data.client_handle = LocApiAdapter::getLocApiAdapter(locEngHandle); int ret_val =-1; if (NULL == loc_eng_data.client_handle) { diff --git a/loc_api/loc_api_v02/LocApiV02Adapter.cpp b/loc_api/loc_api_v02/LocApiV02Adapter.cpp index a60c4f79..cfb2265d 100755 --- a/loc_api/loc_api_v02/LocApiV02Adapter.cpp +++ b/loc_api/loc_api_v02/LocApiV02Adapter.cpp @@ -2053,7 +2053,7 @@ void LocApiV02Adapter :: errorCb(locClientHandleType handle, } /* return a Loc API adapter */ -LocApiAdapter* getLocApiAdapter(LocEng &locEng) +extern "C" LocApiAdapter* getLocApiAdapter(LocEng &locEng) { return(new LocApiV02Adapter(locEng)); }