sanders: gps: switch to LA.UM.6.6.r1-04300-89xx.0 branch

This commit is contained in:
Vachounet
2017-11-22 20:38:49 +01:00
committed by therootlord
parent 3ffdc23017
commit 1f8198a460
162 changed files with 22237 additions and 11732 deletions

View File

@@ -57,6 +57,11 @@ TARGET_USES_64_BIT_BINDER := true
# Asserts
TARGET_OTA_ASSERT_DEVICE := sanders,sanders_retail
# GPS
TARGET_NO_RPC := true
USE_DEVICE_SPECIFIC_GPS := true
BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := $(TARGET_BOARD_PLATFORM)
# Init
TARGET_INIT_VENDOR_LIB := libinit_sanders
TARGET_RECOVERY_DEVICE_MODULES := libinit_sanders

View File

@@ -118,12 +118,12 @@ PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/configs/camera/vfwconfig.json:system/etc/camera/vfwconfig.json
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/gps/etc/flp.conf:system/etc/flp.conf \
$(LOCAL_PATH)/gps/etc/gps.conf:system/etc/gps.conf \
$(LOCAL_PATH)/gps/etc/izat.conf:system/etc/izat.conf \
$(LOCAL_PATH)/gps/etc/lowi.conf:system/etc/lowi.conf \
$(LOCAL_PATH)/gps/etc/sap.conf:system/etc/sap.conf \
$(LOCAL_PATH)/gps/etc/xtwifi.conf:system/etc/xtwifi.conf
$(LOCAL_PATH)/gps/etc/flp.conf:system/vendor/etc/flp.conf \
$(LOCAL_PATH)/gps/etc/gps.conf:system/vendor/etc/gps.conf \
$(LOCAL_PATH)/gps/etc/izat.conf:system/vendor/etc/izat.conf \
$(LOCAL_PATH)/gps/etc/lowi.conf:system/vendor/etc/lowi.conf \
$(LOCAL_PATH)/gps/etc/sap.conf:system/vendor/etc/sap.conf \
$(LOCAL_PATH)/gps/etc/xtwifi.conf:system/vendor/etc/xtwifi.conf
# LineageActions
PRODUCT_PACKAGES += \
@@ -177,9 +177,12 @@ PRODUCT_PACKAGES += \
# GPS
PRODUCT_PACKAGES += \
libgnsspps \
gps.msm8953 \
libshims_get_process_name
libgps.utils \
gps.default \
libgnss \
liblocation_api \
android.hardware.gnss@1.0-impl-qti \
libloc_api-rpc-qc
# HIDL
PRODUCT_COPY_FILES += \

View File

@@ -1,19 +1,5 @@
#
# Copyright (C) 2017 The LineageOS 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.
#
ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),)
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles,$(LOCAL_PATH))
include $(call all-makefiles-under,$(LOCAL_PATH))
endif

10
gps/Makefile.am Normal file
View File

@@ -0,0 +1,10 @@
# Makefile.am - Automake script for gps loc_api
#
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = core location gnss
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = loc-hal.pc
EXTRA_DIST = $(pkgconfig_DATA)

185
gps/android/AGnss.cpp Normal file
View File

@@ -0,0 +1,185 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_AGnssInterface"
#include <log_util.h>
#include "Gnss.h"
#include "AGnss.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
sp<IAGnssCallback> AGnss::sAGnssCbIface = nullptr;
AGnss::AGnss(Gnss* gnss) : mGnss(gnss) {
}
void AGnss::agnssStatusIpV4Cb(AGnssExtStatusIpV4 status){
IAGnssCallback::AGnssStatusIpV4 st = {};
switch (status.type) {
case LOC_AGPS_TYPE_SUPL:
st.type = IAGnssCallback::AGnssType::TYPE_SUPL;
break;
case LOC_AGPS_TYPE_C2K:
st.type = IAGnssCallback::AGnssType::TYPE_C2K;
break;
default:
LOC_LOGE("invalid type: %d", status.type);
return;
}
switch (status.status) {
case LOC_GPS_REQUEST_AGPS_DATA_CONN:
st.status = IAGnssCallback::AGnssStatusValue::REQUEST_AGNSS_DATA_CONN;
break;
case LOC_GPS_RELEASE_AGPS_DATA_CONN:
st.status = IAGnssCallback::AGnssStatusValue::RELEASE_AGNSS_DATA_CONN;
break;
case LOC_GPS_AGPS_DATA_CONNECTED:
st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONNECTED;
break;
case LOC_GPS_AGPS_DATA_CONN_DONE:
st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_DONE;
break;
case LOC_GPS_AGPS_DATA_CONN_FAILED:
st.status = IAGnssCallback::AGnssStatusValue::AGNSS_DATA_CONN_FAILED;
break;
default:
LOC_LOGE("invalid status: %d", status.status);
return;
}
st.ipV4Addr = status.ipV4Addr;
sAGnssCbIface->agnssStatusIpV4Cb(st);
}
Return<void> AGnss::setCallback(const sp<IAGnssCallback>& callback) {
if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
LOC_LOGE("Null GNSS interface");
return Void();
}
// Save the interface
sAGnssCbIface = callback;
AgpsCbInfo cbInfo = {};
cbInfo.statusV4Cb = (void*)agnssStatusIpV4Cb;
cbInfo.cbPriority = AGPS_CB_PRIORITY_LOW;
mGnss->getGnssInterface()->agpsInit(cbInfo);
return Void();
}
Return<bool> AGnss::dataConnClosed() {
if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
LOC_LOGE("Null GNSS interface");
return false;
}
mGnss->getGnssInterface()->agpsDataConnClosed(LOC_AGPS_TYPE_SUPL);
return true;
}
Return<bool> AGnss::dataConnFailed() {
if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
LOC_LOGE("Null GNSS interface");
return false;
}
mGnss->getGnssInterface()->agpsDataConnFailed(LOC_AGPS_TYPE_SUPL);
return true;
}
Return<bool> AGnss::dataConnOpen(const hidl_string& apn,
IAGnss::ApnIpType apnIpType) {
if(mGnss == nullptr || mGnss->getGnssInterface() == nullptr){
LOC_LOGE("Null GNSS interface");
return false;
}
/* Validate */
if(apn.empty()){
LOC_LOGE("Invalid APN");
return false;
}
LOC_LOGD("dataConnOpen APN name = [%s]", apn.c_str());
AGpsBearerType bearerType;
switch (apnIpType) {
case IAGnss::ApnIpType::IPV4:
bearerType = AGPS_APN_BEARER_IPV4;
break;
case IAGnss::ApnIpType::IPV6:
bearerType = AGPS_APN_BEARER_IPV6;
break;
case IAGnss::ApnIpType::IPV4V6:
bearerType = AGPS_APN_BEARER_IPV4V6;
break;
default:
bearerType = AGPS_APN_BEARER_IPV4;
break;
}
mGnss->getGnssInterface()->agpsDataConnOpen(
LOC_AGPS_TYPE_SUPL, apn.c_str(), apn.size(), (int)bearerType);
return true;
}
Return<bool> AGnss::setServer(IAGnssCallback::AGnssType type,
const hidl_string& hostname,
int32_t port) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
config.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
if (type == IAGnssCallback::AGnssType::TYPE_SUPL) {
config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_SUPL;
} else if (type == IAGnssCallback::AGnssType::TYPE_C2K) {
config.assistanceServer.type = GNSS_ASSISTANCE_TYPE_C2K;
} else {
LOC_LOGE("%s]: invalid AGnssType: %d", __FUNCTION__, static_cast<int>(type));
return false;
}
config.assistanceServer.hostName = strdup(hostname.c_str());
config.assistanceServer.port = port;
return mGnss->updateConfiguration(config);
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

77
gps/android/AGnss.h Normal file
View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H
#define ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H
#include <android/hardware/gnss/1.0/IAGnss.h>
#include <hidl/Status.h>
#include <gps_extended_c.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IAGnss;
using ::android::hardware::gnss::V1_0::IAGnssCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
struct Gnss;
struct AGnss : public IAGnss {
AGnss(Gnss* gnss);
~AGnss() = default;
/*
* Methods from ::android::hardware::gnss::V1_0::IAGnss interface follow.
* These declarations were generated from IAGnss.hal.
*/
Return<void> setCallback(const sp<IAGnssCallback>& callback) override;
Return<bool> dataConnClosed() override;
Return<bool> dataConnFailed() override;
Return<bool> dataConnOpen(const hidl_string& apn,
IAGnss::ApnIpType apnIpType) override;
Return<bool> setServer(IAGnssCallback::AGnssType type,
const hidl_string& hostname, int32_t port) override;
/* Data call setup callback passed down to GNSS HAL implementation */
static void agnssStatusIpV4Cb(AGnssExtStatusIpV4 status);
private:
Gnss* mGnss = nullptr;
static sp<IAGnssCallback> sAGnssCbIface;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_AGNSS_H

63
gps/android/AGnssRil.cpp Normal file
View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc__AGnssRilInterface"
#include <log_util.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sstream>
#include <string>
#include "Gnss.h"
#include "AGnssRil.h"
typedef void* (getLocationInterface)();
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
AGnssRil::AGnssRil(Gnss* gnss) : mGnss(gnss) {
ENTRY_LOG_CALLFLOW();
}
AGnssRil::~AGnssRil() {
ENTRY_LOG_CALLFLOW();
}
Return<bool> AGnssRil::updateNetworkState(bool connected, NetworkType type, bool /*roaming*/) {
ENTRY_LOG_CALLFLOW();
// for XTRA
if (nullptr != mGnss && ( nullptr != mGnss->getGnssInterface() )) {
mGnss->getGnssInterface()->updateConnectionStatus(connected, (uint8_t)type);
}
return true;
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

83
gps/android/AGnssRil.h Normal file
View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_
#define ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_
#include <android/hardware/gnss/1.0/IAGnssRil.h>
#include <hidl/Status.h>
#include <location_interface.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IAGnssRil;
using ::android::hardware::gnss::V1_0::IAGnssRilCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
struct Gnss;
/*
* Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface Layer interface
* allows the GNSS chipset to request radio interface layer information from Android platform.
* Examples of such information are reference location, unique subscriber ID, phone number string
* and network availability changes. Also contains wrapper methods to allow methods from
* IAGnssiRilCallback interface to be passed into the conventional implementation of the GNSS HAL.
*/
struct AGnssRil : public IAGnssRil {
AGnssRil(Gnss* gnss);
~AGnssRil();
/*
* Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow.
* These declarations were generated from IAGnssRil.hal.
*/
Return<void> setCallback(const sp<IAGnssRilCallback>& /*callback*/) override {
return Void();
}
Return<void> setRefLocation(const IAGnssRil::AGnssRefLocation& /*agnssReflocation*/) override {
return Void();
}
Return<bool> setSetId(IAGnssRil::SetIDType /*type*/, const hidl_string& /*setid*/) override {
return false;
}
Return<bool> updateNetworkAvailability(bool /*available*/,
const hidl_string& /*apn*/) override {
return false;
}
Return<bool> updateNetworkState(bool connected, NetworkType type, bool roaming) override;
private:
Gnss* mGnss = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_0_AGNSSRIL_H_

92
gps/android/Android.mk Normal file
View File

@@ -0,0 +1,92 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.gnss@1.0-impl-qti
LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_SRC_FILES := \
AGnss.cpp \
Gnss.cpp \
GnssBatching.cpp \
GnssGeofencing.cpp \
GnssMeasurement.cpp \
GnssNi.cpp \
GnssConfiguration.cpp \
GnssDebug.cpp \
AGnssRil.cpp
LOCAL_SRC_FILES += \
location_api/LocationUtil.cpp \
location_api/GnssAPIClient.cpp \
location_api/GeofenceAPIClient.cpp \
location_api/BatchingAPIClient.cpp \
location_api/MeasurementAPIClient.cpp \
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH)/location_api
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_core_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_SHARED_LIBRARIES := \
liblog \
libhidlbase \
libhidltransport \
libhwbinder \
libutils \
android.hardware.gnss@1.0 \
LOCAL_SHARED_LIBRARIES += \
libloc_core \
libgps.utils \
libdl \
libloc_pla \
liblocation_api \
LOCAL_CFLAGS += $(GNSS_CFLAGS)
include $(BUILD_SHARED_LIBRARY)
BUILD_GNSS_HIDL_SERVICE := true
ifneq ($(BOARD_VENDOR_QCOM_LOC_PDK_FEATURE_SET), true)
ifneq ($(LW_FEATURE_SET),true)
BUILD_GNSS_HIDL_SERVICE := false
endif # LW_FEATURE_SET
endif # BOARD_VENDOR_QCOM_LOC_PDK_FEATURE_SET
ifeq ($(BUILD_GNSS_HIDL_SERVICE), true)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.gnss@1.0-service-qti
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_EXECUTABLES)
LOCAL_MODULE_RELATIVE_PATH := hw
LOCAL_INIT_RC := android.hardware.gnss@1.0-service-qti.rc
LOCAL_SRC_FILES := \
service.cpp \
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH)/location_api
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_core_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_SHARED_LIBRARIES := \
liblog \
libcutils \
libdl \
libbase \
libutils \
LOCAL_SHARED_LIBRARIES += \
libhwbinder \
libhidlbase \
libhidltransport \
android.hardware.gnss@1.0 \
LOCAL_CFLAGS += $(GNSS_CFLAGS)
include $(BUILD_EXECUTABLE)
endif # BUILD_GNSS_HIDL_SERVICE

338
gps/android/Gnss.cpp Normal file
View File

@@ -0,0 +1,338 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssInterface"
#include <log_util.h>
#include <dlfcn.h>
#include "Gnss.h"
typedef void* (getLocationInterface)();
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void Gnss::GnssDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) {
LOC_LOGE("%s] service died. cookie: %llu, who: %p",
__FUNCTION__, static_cast<unsigned long long>(cookie), &who);
if (mGnss != nullptr) {
mGnss->stop();
mGnss->cleanup();
}
}
Gnss::Gnss() {
ENTRY_LOG_CALLFLOW();
// clear pending GnssConfig
memset(&mPendingConfig, 0, sizeof(GnssConfig));
mGnssDeathRecipient = new GnssDeathRecipient(this);
}
Gnss::~Gnss() {
ENTRY_LOG_CALLFLOW();
if (mApi != nullptr) {
delete mApi;
mApi = nullptr;
}
}
GnssAPIClient* Gnss::getApi() {
if (mApi == nullptr && (mGnssCbIface != nullptr || mGnssNiCbIface != nullptr)) {
mApi = new GnssAPIClient(mGnssCbIface, mGnssNiCbIface);
if (mApi == nullptr) {
LOC_LOGE("%s] faild to create GnssAPIClient", __FUNCTION__);
return mApi;
}
if (mPendingConfig.size == sizeof(GnssConfig)) {
// we have pending GnssConfig
mApi->gnssConfigurationUpdate(mPendingConfig);
// clear size to invalid mPendingConfig
mPendingConfig.size = 0;
if (mPendingConfig.assistanceServer.hostName != nullptr) {
free((void*)mPendingConfig.assistanceServer.hostName);
}
}
}
if (mApi == nullptr) {
LOC_LOGW("%s] GnssAPIClient is not ready", __FUNCTION__);
}
return mApi;
}
GnssInterface* Gnss::getGnssInterface() {
static bool getGnssInterfaceFailed = false;
if (nullptr == mGnssInterface && !getGnssInterfaceFailed) {
LOC_LOGD("%s]: loading libgnss.so::getGnssInterface ...", __func__);
getLocationInterface* getter = NULL;
const char *error = NULL;
dlerror();
void *handle = dlopen("libgnss.so", RTLD_NOW);
if (NULL == handle || (error = dlerror()) != NULL) {
LOC_LOGW("dlopen for libgnss.so failed, error = %s", error);
} else {
getter = (getLocationInterface*)dlsym(handle, "getGnssInterface");
if ((error = dlerror()) != NULL) {
LOC_LOGW("dlsym for libgnss.so::getGnssInterface failed, error = %s", error);
getter = NULL;
}
}
if (NULL == getter) {
getGnssInterfaceFailed = true;
} else {
mGnssInterface = (GnssInterface*)(*getter)();
}
}
return mGnssInterface;
}
Return<bool> Gnss::setCallback(const sp<IGnssCallback>& callback) {
ENTRY_LOG_CALLFLOW();
if (mGnssCbIface != nullptr) {
mGnssCbIface->unlinkToDeath(mGnssDeathRecipient);
}
mGnssCbIface = callback;
if (mGnssCbIface != nullptr) {
mGnssCbIface->linkToDeath(mGnssDeathRecipient, 0 /*cookie*/);
}
GnssAPIClient* api = getApi();
if (api != nullptr) {
api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
api->gnssEnable(LOCATION_TECHNOLOGY_TYPE_GNSS);
api->requestCapabilities();
}
return true;
}
Return<bool> Gnss::setGnssNiCb(const sp<IGnssNiCallback>& callback) {
ENTRY_LOG_CALLFLOW();
mGnssNiCbIface = callback;
GnssAPIClient* api = getApi();
if (api != nullptr) {
api->gnssUpdateCallbacks(mGnssCbIface, mGnssNiCbIface);
}
return true;
}
Return<bool> Gnss::updateConfiguration(GnssConfig& gnssConfig) {
ENTRY_LOG_CALLFLOW();
GnssAPIClient* api = getApi();
if (api) {
api->gnssConfigurationUpdate(gnssConfig);
} else if (gnssConfig.flags != 0) {
// api is not ready yet, update mPendingConfig with gnssConfig
mPendingConfig.size = sizeof(GnssConfig);
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
mPendingConfig.gpsLock = gnssConfig.gpsLock;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
mPendingConfig.suplVersion = gnssConfig.suplVersion;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT;
mPendingConfig.assistanceServer.size = sizeof(GnssConfigSetAssistanceServer);
mPendingConfig.assistanceServer.type = gnssConfig.assistanceServer.type;
if (mPendingConfig.assistanceServer.hostName != nullptr) {
free((void*)mPendingConfig.assistanceServer.hostName);
mPendingConfig.assistanceServer.hostName =
strdup(gnssConfig.assistanceServer.hostName);
}
mPendingConfig.assistanceServer.port = gnssConfig.assistanceServer.port;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
mPendingConfig.lppProfile = gnssConfig.lppProfile;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT;
mPendingConfig.lppeControlPlaneMask = gnssConfig.lppeControlPlaneMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT;
mPendingConfig.lppeUserPlaneMask = gnssConfig.lppeUserPlaneMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
mPendingConfig.aGlonassPositionProtocolMask = gnssConfig.aGlonassPositionProtocolMask;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
mPendingConfig.emergencyPdnForEmergencySupl = gnssConfig.emergencyPdnForEmergencySupl;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
mPendingConfig.suplEmergencyServices = gnssConfig.suplEmergencyServices;
}
if (gnssConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
mPendingConfig.flags |= GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
mPendingConfig.suplModeMask = gnssConfig.suplModeMask;
}
}
return true;
}
Return<bool> Gnss::start() {
ENTRY_LOG_CALLFLOW();
bool retVal = false;
GnssAPIClient* api = getApi();
if (api) {
retVal = api->gnssStart();
}
return retVal;
}
Return<bool> Gnss::stop() {
ENTRY_LOG_CALLFLOW();
bool retVal = false;
GnssAPIClient* api = getApi();
if (api) {
retVal = api->gnssStop();
}
return retVal;
}
Return<void> Gnss::cleanup() {
ENTRY_LOG_CALLFLOW();
if (mApi != nullptr) {
mApi->gnssDisable();
}
return Void();
}
Return<bool> Gnss::injectLocation(double latitudeDegrees,
double longitudeDegrees,
float accuracyMeters) {
ENTRY_LOG_CALLFLOW();
GnssInterface* gnssInterface = getGnssInterface();
if (nullptr != gnssInterface) {
gnssInterface->injectLocation(latitudeDegrees, longitudeDegrees, accuracyMeters);
return true;
} else {
return false;
}
}
Return<bool> Gnss::injectTime(int64_t timeMs, int64_t timeReferenceMs,
int32_t uncertaintyMs) {
ENTRY_LOG_CALLFLOW();
GnssInterface* gnssInterface = getGnssInterface();
if (nullptr != gnssInterface) {
gnssInterface->injectTime(timeMs, timeReferenceMs, uncertaintyMs);
return true;
} else {
return false;
}
}
Return<void> Gnss::deleteAidingData(IGnss::GnssAidingData aidingDataFlags) {
ENTRY_LOG_CALLFLOW();
GnssAPIClient* api = getApi();
if (api) {
api->gnssDeleteAidingData(aidingDataFlags);
}
return Void();
}
Return<bool> Gnss::setPositionMode(IGnss::GnssPositionMode mode,
IGnss::GnssPositionRecurrence recurrence,
uint32_t minIntervalMs,
uint32_t preferredAccuracyMeters,
uint32_t preferredTimeMs) {
ENTRY_LOG_CALLFLOW();
bool retVal = false;
GnssAPIClient* api = getApi();
if (api) {
retVal = api->gnssSetPositionMode(mode, recurrence, minIntervalMs,
preferredAccuracyMeters, preferredTimeMs);
}
return retVal;
}
Return<sp<IAGnss>> Gnss::getExtensionAGnss() {
ENTRY_LOG_CALLFLOW();
mAGnssIface = new AGnss(this);
return mAGnssIface;
}
Return<sp<IGnssNi>> Gnss::getExtensionGnssNi() {
ENTRY_LOG_CALLFLOW();
mGnssNi = new GnssNi(this);
return mGnssNi;
}
Return<sp<IGnssMeasurement>> Gnss::getExtensionGnssMeasurement() {
ENTRY_LOG_CALLFLOW();
mGnssMeasurement = new GnssMeasurement();
return mGnssMeasurement;
}
Return<sp<IGnssConfiguration>> Gnss::getExtensionGnssConfiguration() {
ENTRY_LOG_CALLFLOW();
mGnssConfig = new GnssConfiguration(this);
return mGnssConfig;
}
Return<sp<IGnssGeofencing>> Gnss::getExtensionGnssGeofencing() {
ENTRY_LOG_CALLFLOW();
mGnssGeofencingIface = new GnssGeofencing();
return mGnssGeofencingIface;
}
Return<sp<IGnssBatching>> Gnss::getExtensionGnssBatching() {
mGnssBatching = new GnssBatching();
return mGnssBatching;
}
Return<sp<IGnssDebug>> Gnss::getExtensionGnssDebug() {
ENTRY_LOG_CALLFLOW();
mGnssDebug = new GnssDebug(this);
return mGnssDebug;
}
Return<sp<IAGnssRil>> Gnss::getExtensionAGnssRil() {
mGnssRil = new AGnssRil(this);
return mGnssRil;
}
IGnss* HIDL_FETCH_IGnss(const char* hal) {
ENTRY_LOG_CALLFLOW();
IGnss* iface = nullptr;
iface = new Gnss();
if (iface == nullptr) {
LOC_LOGE("%s]: failed to get %s", __FUNCTION__, hal);
}
return iface;
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

149
gps/android/Gnss.h Normal file
View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSS_H
#include <AGnss.h>
#include <AGnssRil.h>
#include <GnssBatching.h>
#include <GnssConfiguration.h>
#include <GnssGeofencing.h>
#include <GnssMeasurement.h>
#include <GnssNi.h>
#include <GnssDebug.h>
#include <android/hardware/gnss/1.0/IGnss.h>
#include <hidl/Status.h>
#include <GnssAPIClient.h>
#include <location_interface.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
struct Gnss : public IGnss {
Gnss();
~Gnss();
// registerAsService will call interfaceChain to determine the version of service
/* comment this out until we know really how to manipulate hidl version
using interfaceChain_cb = std::function<
void(const ::android::hardware::hidl_vec<::android::hardware::hidl_string>& descriptors)>;
virtual ::android::hardware::Return<void> interfaceChain(interfaceChain_cb _hidl_cb) override {
_hidl_cb({
"android.hardware.gnss@1.1::IGnss",
::android::hidl::base::V1_0::IBase::descriptor,
});
return ::android::hardware::Void();
}
*/
/*
* Methods from ::android::hardware::gnss::V1_0::IGnss follow.
* These declarations were generated from Gnss.hal.
*/
Return<bool> setCallback(const sp<IGnssCallback>& callback) override;
Return<bool> start() override;
Return<bool> stop() override;
Return<void> cleanup() override;
Return<bool> injectLocation(double latitudeDegrees,
double longitudeDegrees,
float accuracyMeters) override;
Return<bool> injectTime(int64_t timeMs,
int64_t timeReferenceMs,
int32_t uncertaintyMs) override;
Return<void> deleteAidingData(IGnss::GnssAidingData aidingDataFlags) override;
Return<bool> setPositionMode(IGnss::GnssPositionMode mode,
IGnss::GnssPositionRecurrence recurrence,
uint32_t minIntervalMs,
uint32_t preferredAccuracyMeters,
uint32_t preferredTimeMs) override;
Return<sp<IAGnss>> getExtensionAGnss() override;
Return<sp<IGnssNi>> getExtensionGnssNi() override;
Return<sp<IGnssMeasurement>> getExtensionGnssMeasurement() override;
Return<sp<IGnssConfiguration>> getExtensionGnssConfiguration() override;
Return<sp<IGnssGeofencing>> getExtensionGnssGeofencing() override;
Return<sp<IGnssBatching>> getExtensionGnssBatching() override;
Return<sp<IAGnssRil>> getExtensionAGnssRil() override;
inline Return<sp<IGnssNavigationMessage>> getExtensionGnssNavigationMessage() override {
return nullptr;
}
inline Return<sp<IGnssXtra>> getExtensionXtra() override {
return nullptr;
}
Return<sp<IGnssDebug>> getExtensionGnssDebug() override;
// These methods are not part of the IGnss base class.
GnssAPIClient* getApi();
Return<bool> setGnssNiCb(const sp<IGnssNiCallback>& niCb);
Return<bool> updateConfiguration(GnssConfig& gnssConfig);
GnssInterface* getGnssInterface();
private:
struct GnssDeathRecipient : hidl_death_recipient {
GnssDeathRecipient(sp<Gnss> gnss) : mGnss(gnss) {
}
~GnssDeathRecipient() = default;
virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
sp<Gnss> mGnss;
};
private:
sp<GnssDeathRecipient> mGnssDeathRecipient = nullptr;
sp<AGnss> mAGnssIface = nullptr;
sp<GnssNi> mGnssNi = nullptr;
sp<GnssMeasurement> mGnssMeasurement = nullptr;
sp<GnssConfiguration> mGnssConfig = nullptr;
sp<GnssGeofencing> mGnssGeofencingIface = nullptr;
sp<GnssBatching> mGnssBatching = nullptr;
sp<IGnssDebug> mGnssDebug = nullptr;
sp<AGnssRil> mGnssRil = nullptr;
GnssAPIClient* mApi = nullptr;
sp<IGnssCallback> mGnssCbIface = nullptr;
sp<IGnssNiCallback> mGnssNiCbIface = nullptr;
GnssConfig mPendingConfig;
GnssInterface* mGnssInterface = nullptr;
};
extern "C" IGnss* HIDL_FETCH_IGnss(const char* name);
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSS_H

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssBatchingInterface"
#include <log_util.h>
#include <BatchingAPIClient.h>
#include "GnssBatching.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void GnssBatching::GnssBatchingDeathRecipient::serviceDied(
uint64_t cookie, const wp<IBase>& who) {
LOC_LOGE("%s] service died. cookie: %llu, who: %p",
__FUNCTION__, static_cast<unsigned long long>(cookie), &who);
if (mGnssBatching != nullptr) {
mGnssBatching->stop();
mGnssBatching->cleanup();
}
}
GnssBatching::GnssBatching() : mApi(nullptr) {
mGnssBatchingDeathRecipient = new GnssBatchingDeathRecipient(this);
}
GnssBatching::~GnssBatching() {
if (mApi != nullptr) {
delete mApi;
mApi = nullptr;
}
}
// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
Return<bool> GnssBatching::init(const sp<IGnssBatchingCallback>& callback) {
if (mApi != nullptr) {
LOC_LOGD("%s]: mApi is NOT nullptr, delete it first", __FUNCTION__);
delete mApi;
mApi = nullptr;
}
mApi = new BatchingAPIClient(callback);
if (mApi == nullptr) {
LOC_LOGE("%s]: failed to create mApi", __FUNCTION__);
return false;
}
if (mGnssBatchingCbIface != nullptr) {
mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient);
}
mGnssBatchingCbIface = callback;
if (mGnssBatchingCbIface != nullptr) {
mGnssBatchingCbIface->linkToDeath(mGnssBatchingDeathRecipient, 0 /*cookie*/);
}
return true;
}
Return<uint16_t> GnssBatching::getBatchSize() {
uint16_t ret = 0;
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
ret = mApi->getBatchSize();
}
return ret;
}
Return<bool> GnssBatching::start(const IGnssBatching::Options& options) {
bool ret = false;
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
ret = mApi->startSession(options);
}
return ret;
}
Return<void> GnssBatching::flush() {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
mApi->flushBatchedLocations();
}
return Void();
}
Return<bool> GnssBatching::stop() {
bool ret = false;
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
ret = mApi->stopSession();
}
return ret;
}
Return<void> GnssBatching::cleanup() {
if (mGnssBatchingCbIface != nullptr) {
mGnssBatchingCbIface->unlinkToDeath(mGnssBatchingDeathRecipient);
}
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H
#include <android/hardware/gnss/1.0/IGnssBatching.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssBatching;
using ::android::hardware::gnss::V1_0::IGnssBatchingCallback;
using ::android::hidl::base::V1_0::IBase;
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::sp;
class BatchingAPIClient;
struct GnssBatching : public IGnssBatching {
GnssBatching();
~GnssBatching();
// Methods from ::android::hardware::gnss::V1_0::IGnssBatching follow.
Return<bool> init(const sp<IGnssBatchingCallback>& callback) override;
Return<uint16_t> getBatchSize() override;
Return<bool> start(const IGnssBatching::Options& options ) override;
Return<void> flush() override;
Return<bool> stop() override;
Return<void> cleanup() override;
private:
struct GnssBatchingDeathRecipient : hidl_death_recipient {
GnssBatchingDeathRecipient(sp<GnssBatching> gnssBatching) :
mGnssBatching(gnssBatching) {
}
~GnssBatchingDeathRecipient() = default;
virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
sp<GnssBatching> mGnssBatching;
};
private:
sp<GnssBatchingDeathRecipient> mGnssBatchingDeathRecipient = nullptr;
sp<IGnssBatchingCallback> mGnssBatchingCbIface = nullptr;
BatchingAPIClient* mApi = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSBATCHING_H

View File

@@ -0,0 +1,227 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssConfigurationInterface"
#include <log_util.h>
#include "Gnss.h"
#include "GnssConfiguration.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
}
// Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
config.suplEmergencyServices = (enabled ?
GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES :
GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO);
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
switch (version) {
case 0x00020002:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
break;
case 0x00020000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
break;
case 0x00010000:
config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
break;
default:
LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
return false;
break;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
switch (mode) {
case 0:
config.suplModeMask = 0; // STANDALONE ONLY
break;
case 1:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
break;
case 2:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
case 3:
config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
break;
default:
LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
return false;
break;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfile) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
switch (lppProfile) {
case 0:
config.lppProfile = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE;
break;
case 1:
config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE;
break;
case 2:
config.lppProfile = GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE;
break;
case 3:
config.lppProfile = GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE;
break;
default:
LOC_LOGE("%s]: invalid lppProfile: %d.", __FUNCTION__, lppProfile);
return false;
break;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
if (protocol & (1<<0)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
}
if (protocol & (1<<1)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
}
if (protocol & (1<<2)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
}
if (protocol & (1<<3)) {
config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
switch (lock) {
case 0:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE;
break;
case 1:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO;
break;
case 2:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_NI;
break;
case 3:
config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
break;
default:
LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock);
return false;
break;
}
return mGnss->updateConfiguration(config);
}
Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return false;
}
GnssConfig config;
memset(&config, 0, sizeof(GnssConfig));
config.size = sizeof(GnssConfig);
config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
config.emergencyPdnForEmergencySupl = (enabled ?
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
return mGnss->updateConfiguration(config);
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H
#include <android/hardware/gnss/1.0/IGnssConfiguration.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssConfiguration;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
/*
* Interface for passing GNSS configuration info from platform to HAL.
*/
struct Gnss;
struct GnssConfiguration : public IGnssConfiguration {
GnssConfiguration(Gnss* gnss);
~GnssConfiguration() = default;
/*
* Methods from ::android::hardware::gnss::V1_0::IGnssConfiguration follow.
* These declarations were generated from IGnssConfiguration.hal.
*/
Return<bool> setSuplVersion(uint32_t version) override;
Return<bool> setSuplMode(uint8_t mode) override;
Return<bool> setSuplEs(bool enabled) override;
Return<bool> setLppProfile(uint8_t lppProfile) override;
Return<bool> setGlonassPositioningProtocol(uint8_t protocol) override;
Return<bool> setEmergencySuplPdn(bool enable) override;
Return<bool> setGpsLock(uint8_t lock) override;
private:
Gnss* mGnss = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSCONFIGURATION_H

143
gps/android/GnssDebug.cpp Normal file
View File

@@ -0,0 +1,143 @@
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssDebugInterface"
#include <log/log.h>
#include <log_util.h>
#include "Gnss.h"
#include "GnssDebug.h"
#include "LocationUtil.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::hidl_vec;
#define GNSS_DEBUG_UNKNOWN_UTC_TIME (1483228800000ULL) // 1/1/2017 00:00 GMT
#define GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC (1.57783680E17) // 5 years in ns
GnssDebug::GnssDebug(Gnss* gnss) : mGnss(gnss)
{
}
/*
* This methods requests position, time and satellite ephemeris debug information
* from the HAL.
*
* @return void
*/
Return<void> GnssDebug::getDebugData(getDebugData_cb _hidl_cb)
{
LOC_LOGD("%s]: ", __func__);
DebugData data = { };
if((nullptr == mGnss) || (nullptr == mGnss->getGnssInterface())){
LOC_LOGE("GnssDebug - Null GNSS interface");
_hidl_cb(data);
return Void();
}
// get debug report snapshot via hal interface
GnssDebugReport reports = { };
mGnss->getGnssInterface()->getDebugReport(reports);
// location block
if (reports.mLocation.mValid) {
data.position.valid = true;
data.position.latitudeDegrees = reports.mLocation.mLocation.latitude;
data.position.longitudeDegrees = reports.mLocation.mLocation.longitude;
data.position.altitudeMeters = reports.mLocation.mLocation.altitude;
data.position.speedMetersPerSec =
(double)(reports.mLocation.mLocation.speed);
data.position.bearingDegrees =
(double)(reports.mLocation.mLocation.bearing);
data.position.horizontalAccuracyMeters =
(double)(reports.mLocation.mLocation.accuracy);
data.position.verticalAccuracyMeters =
reports.mLocation.verticalAccuracyMeters;
data.position.speedAccuracyMetersPerSecond =
reports.mLocation.speedAccuracyMetersPerSecond;
data.position.bearingAccuracyDegrees =
reports.mLocation.bearingAccuracyDegrees;
timeval tv_now, tv_report;
tv_report.tv_sec = reports.mLocation.mUtcReported.tv_sec;
tv_report.tv_usec = reports.mLocation.mUtcReported.tv_nsec / 1000ULL;
gettimeofday(&tv_now, NULL);
data.position.ageSeconds =
(tv_now.tv_sec - tv_report.tv_sec) +
(float)((tv_now.tv_usec - tv_report.tv_usec)) / 1000000;
}
else {
data.position.valid = false;
}
// time block
if (reports.mTime.mValid) {
data.time.timeEstimate = reports.mTime.timeEstimate;
data.time.timeUncertaintyNs = reports.mTime.timeUncertaintyNs;
data.time.frequencyUncertaintyNsPerSec =
reports.mTime.frequencyUncertaintyNsPerSec;
}
else {
data.time.timeEstimate = GNSS_DEBUG_UNKNOWN_UTC_TIME;
data.time.timeUncertaintyNs = (float)(GNSS_DEBUG_UNKNOWN_UTC_TIME_UNC);
data.time.frequencyUncertaintyNsPerSec = 0;
}
// satellite data block
SatelliteData s = { };
std::vector<SatelliteData> s_array = { };
for (uint32_t i=0; i<reports.mSatelliteInfo.size(); i++) {
memset(&s, 0, sizeof(s));
s.svid = reports.mSatelliteInfo[i].svid;
convertGnssConstellationType(
reports.mSatelliteInfo[i].constellation, s.constellation);
convertGnssEphemerisType(
reports.mSatelliteInfo[i].mEphemerisType, s.ephemerisType);
convertGnssEphemerisSource(
reports.mSatelliteInfo[i].mEphemerisSource, s.ephemerisSource);
convertGnssEphemerisHealth(
reports.mSatelliteInfo[i].mEphemerisHealth, s.ephemerisHealth);
s.ephemerisAgeSeconds =
reports.mSatelliteInfo[i].ephemerisAgeSeconds;
s.serverPredictionIsAvailable =
reports.mSatelliteInfo[i].serverPredictionIsAvailable;
s.serverPredictionAgeSeconds =
reports.mSatelliteInfo[i].serverPredictionAgeSeconds;
s_array.push_back(s);
}
data.satelliteDataArray = s_array;
// callback HIDL with collected debug data
_hidl_cb(data);
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

59
gps/android/GnssDebug.h Normal file
View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSDEBUG_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSDEBUG_H
#include <android/hardware/gnss/1.0/IGnssDebug.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssDebug;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
/* Interface for GNSS Debug support. */
struct Gnss;
struct GnssDebug : public IGnssDebug {
GnssDebug(Gnss* gnss);
~GnssDebug() {};
/*
* Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow.
* These declarations were generated from IGnssDebug.hal.
*/
Return<void> getDebugData(getDebugData_cb _hidl_cb) override;
private:
Gnss* mGnss = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSDEBUG_H

View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "GnssHal_GnssGeofencing"
#include <log_util.h>
#include <GeofenceAPIClient.h>
#include "GnssGeofencing.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void GnssGeofencing::GnssGeofencingDeathRecipient::serviceDied(
uint64_t cookie, const wp<IBase>& who) {
LOC_LOGE("%s] service died. cookie: %llu, who: %p",
__FUNCTION__, static_cast<unsigned long long>(cookie), &who);
if (mGnssGeofencing != nullptr) {
mGnssGeofencing->removeAllGeofences();
}
}
GnssGeofencing::GnssGeofencing() : mApi(nullptr) {
mGnssGeofencingDeathRecipient = new GnssGeofencingDeathRecipient(this);
}
GnssGeofencing::~GnssGeofencing() {
if (mApi != nullptr) {
delete mApi;
mApi = nullptr;
}
}
// Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
Return<void> GnssGeofencing::setCallback(const sp<IGnssGeofenceCallback>& callback) {
if (mApi != nullptr) {
LOC_LOGE("%s]: mApi is NOT nullptr", __FUNCTION__);
return Void();
}
mApi = new GeofenceAPIClient(callback);
if (mApi == nullptr) {
LOC_LOGE("%s]: failed to create mApi", __FUNCTION__);
}
if (mGnssGeofencingCbIface != nullptr) {
mGnssGeofencingCbIface->unlinkToDeath(mGnssGeofencingDeathRecipient);
}
mGnssGeofencingCbIface = callback;
if (mGnssGeofencingCbIface != nullptr) {
mGnssGeofencingCbIface->linkToDeath(mGnssGeofencingDeathRecipient, 0 /*cookie*/);
}
return Void();
}
Return<void> GnssGeofencing::addGeofence(
int32_t geofenceId,
double latitudeDegrees,
double longitudeDegrees,
double radiusMeters,
IGnssGeofenceCallback::GeofenceTransition lastTransition,
int32_t monitorTransitions,
uint32_t notificationResponsivenessMs,
uint32_t unknownTimerMs) {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
mApi->geofenceAdd(
geofenceId,
latitudeDegrees,
longitudeDegrees,
radiusMeters,
static_cast<int32_t>(lastTransition),
monitorTransitions,
notificationResponsivenessMs,
unknownTimerMs);
}
return Void();
}
Return<void> GnssGeofencing::pauseGeofence(int32_t geofenceId) {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
mApi->geofencePause(geofenceId);
}
return Void();
}
Return<void> GnssGeofencing::resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
mApi->geofenceResume(geofenceId, monitorTransitions);
}
return Void();
}
Return<void> GnssGeofencing::removeGeofence(int32_t geofenceId) {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
} else {
mApi->geofenceRemove(geofenceId);
}
return Void();
}
Return<void> GnssGeofencing::removeAllGeofences() {
if (mApi == nullptr) {
LOC_LOGD("%s]: mApi is nullptr, do nothing", __FUNCTION__);
} else {
mApi->geofenceRemoveAll();
}
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
#include <android/hardware/gnss/1.0/IGnssGeofencing.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback;
using ::android::hardware::gnss::V1_0::IGnssGeofencing;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
class GeofenceAPIClient;
struct GnssGeofencing : public IGnssGeofencing {
GnssGeofencing();
~GnssGeofencing();
/*
* Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
* These declarations were generated from IGnssGeofencing.hal.
*/
Return<void> setCallback(const sp<IGnssGeofenceCallback>& callback) override;
Return<void> addGeofence(int32_t geofenceId,
double latitudeDegrees,
double longitudeDegrees,
double radiusMeters,
IGnssGeofenceCallback::GeofenceTransition lastTransition,
int32_t monitorTransitions,
uint32_t notificationResponsivenessMs,
uint32_t unknownTimerMs) override;
Return<void> pauseGeofence(int32_t geofenceId) override;
Return<void> resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override;
Return<void> removeGeofence(int32_t geofenceId) override;
private:
// This method is not part of the IGnss base class.
// It is called by GnssGeofencingDeathRecipient to remove all geofences added so far.
Return<void> removeAllGeofences();
private:
struct GnssGeofencingDeathRecipient : hidl_death_recipient {
GnssGeofencingDeathRecipient(sp<GnssGeofencing> gnssGeofencing) :
mGnssGeofencing(gnssGeofencing) {
}
~GnssGeofencingDeathRecipient() = default;
virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
sp<GnssGeofencing> mGnssGeofencing;
};
private:
sp<GnssGeofencingDeathRecipient> mGnssGeofencingDeathRecipient = nullptr;
sp<IGnssGeofenceCallback> mGnssGeofencingCbIface = nullptr;
GeofenceAPIClient* mApi = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssMeasurementInterface"
#include <log_util.h>
#include <MeasurementAPIClient.h>
#include "GnssMeasurement.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied(
uint64_t cookie, const wp<IBase>& who) {
LOC_LOGE("%s] service died. cookie: %llu, who: %p",
__FUNCTION__, static_cast<unsigned long long>(cookie), &who);
if (mGnssMeasurement != nullptr) {
mGnssMeasurement->close();
}
}
GnssMeasurement::GnssMeasurement() {
mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this);
mApi = new MeasurementAPIClient();
}
GnssMeasurement::~GnssMeasurement() {
if (mApi) {
delete mApi;
mApi = nullptr;
}
}
// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow.
Return<IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
const sp<IGnssMeasurementCallback>& callback) {
Return<IGnssMeasurement::GnssMeasurementStatus> ret =
IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC;
if (mGnssMeasurementCbIface != nullptr) {
LOC_LOGE("%s]: GnssMeasurementCallback is already set", __FUNCTION__);
return IGnssMeasurement::GnssMeasurementStatus::ERROR_ALREADY_INIT;
}
if (callback == nullptr) {
LOC_LOGE("%s]: callback is nullptr", __FUNCTION__);
return ret;
}
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
return ret;
}
mGnssMeasurementCbIface = callback;
mGnssMeasurementCbIface->linkToDeath(mGnssMeasurementDeathRecipient, 0 /*cookie*/);
return mApi->measurementSetCallback(callback);
}
Return<void> GnssMeasurement::close() {
if (mApi == nullptr) {
LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
return Void();
}
if (mGnssMeasurementCbIface != nullptr) {
mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient);
mGnssMeasurementCbIface = nullptr;
}
mApi->measurementClose();
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H
#include <android/hardware/gnss/1.0/IGnssMeasurement.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssMeasurement;
using ::android::hardware::gnss::V1_0::IGnssMeasurementCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
class MeasurementAPIClient;
struct GnssMeasurement : public IGnssMeasurement {
GnssMeasurement();
~GnssMeasurement();
/*
* Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow.
* These declarations were generated from IGnssMeasurement.hal.
*/
Return<GnssMeasurementStatus> setCallback(
const sp<IGnssMeasurementCallback>& callback) override;
Return<void> close() override;
private:
struct GnssMeasurementDeathRecipient : hidl_death_recipient {
GnssMeasurementDeathRecipient(sp<GnssMeasurement> gnssMeasurement) :
mGnssMeasurement(gnssMeasurement) {
}
~GnssMeasurementDeathRecipient() = default;
virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
sp<GnssMeasurement> mGnssMeasurement;
};
private:
sp<GnssMeasurementDeathRecipient> mGnssMeasurementDeathRecipient = nullptr;
sp<IGnssMeasurementCallback> mGnssMeasurementCbIface = nullptr;
MeasurementAPIClient* mApi;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSMEASUREMENT_H

85
gps/android/GnssNi.cpp Normal file
View File

@@ -0,0 +1,85 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "LocSvc_GnssNiInterface"
#include <log_util.h>
#include "Gnss.h"
#include "GnssNi.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) {
LOC_LOGE("%s] service died. cookie: %llu, who: %p",
__FUNCTION__, static_cast<unsigned long long>(cookie), &who);
// we do nothing here
// Gnss::GnssDeathRecipient will stop the session
}
GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) {
mGnssNiDeathRecipient = new GnssNiDeathRecipient(this);
}
// Methods from ::android::hardware::gnss::V1_0::IGnssNi follow.
Return<void> GnssNi::setCallback(const sp<IGnssNiCallback>& callback) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return Void();
}
mGnss->setGnssNiCb(callback);
if (mGnssNiCbIface != nullptr) {
mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient);
}
mGnssNiCbIface = callback;
if (mGnssNiCbIface != nullptr) {
mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/);
}
return Void();
}
Return<void> GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) {
if (mGnss == nullptr) {
LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
return Void();
}
GnssAPIClient* api = mGnss->getApi();
if (api == nullptr) {
LOC_LOGE("%s]: api is nullptr", __FUNCTION__);
return Void();
}
api->gnssNiRespond(notifId, userResponse);
return Void();
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

75
gps/android/GnssNi.h Normal file
View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H
#define ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H
#include <android/hardware/gnss/1.0/IGnssNi.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssNi;
using ::android::hardware::gnss::V1_0::IGnssNiCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
struct Gnss;
struct GnssNi : public IGnssNi {
GnssNi(Gnss* gnss);
~GnssNi() = default;
/*
* Methods from ::android::hardware::gnss::V1_0::IGnssNi follow.
* These declarations were generated from IGnssNi.hal.
*/
Return<void> setCallback(const sp<IGnssNiCallback>& callback) override;
Return<void> respond(int32_t notifId,
IGnssNiCallback::GnssUserResponseType userResponse) override;
private:
struct GnssNiDeathRecipient : hidl_death_recipient {
GnssNiDeathRecipient(sp<GnssNi> gnssNi) : mGnssNi(gnssNi) {
}
~GnssNiDeathRecipient() = default;
virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
sp<GnssNi> mGnssNi;
};
private:
sp<GnssNiDeathRecipient> mGnssNiDeathRecipient = nullptr;
sp<IGnssNiCallback> mGnssNiCbIface = nullptr;
Gnss* mGnss = nullptr;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSNI_H

View File

@@ -0,0 +1,4 @@
service gnss_service /vendor/bin/hw/android.hardware.gnss@1.0-service-qti
class main
user gps
group system gps radio

View File

@@ -0,0 +1,191 @@
/* Copyright (c) 2017, 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_NDEBUG 0
#define LOG_TAG "LocSvc_BatchingAPIClient"
#include <log_util.h>
#include <loc_cfg.h>
#include "LocationUtil.h"
#include "BatchingAPIClient.h"
#include "limits.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out,
LocationCapabilitiesMask mask);
BatchingAPIClient::BatchingAPIClient(const sp<IGnssBatchingCallback>& callback) :
LocationAPIClientBase(),
mGnssBatchingCbIface(callback),
mDefaultId(UINT_MAX),
mLocationCapabilitiesMask(0)
{
LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
locationCallbacks.trackingCb = nullptr;
locationCallbacks.batchingCb = nullptr;
if (mGnssBatchingCbIface != nullptr) {
locationCallbacks.batchingCb = [this](size_t count, Location* location,
BatchingOptions batchOptions) {
onBatchingCb(count, location, batchOptions);
};
}
locationCallbacks.geofenceBreachCb = nullptr;
locationCallbacks.geofenceStatusCb = nullptr;
locationCallbacks.gnssLocationInfoCb = nullptr;
locationCallbacks.gnssNiCb = nullptr;
locationCallbacks.gnssSvCb = nullptr;
locationCallbacks.gnssNmeaCb = nullptr;
locationCallbacks.gnssMeasurementsCb = nullptr;
locAPISetCallbacks(locationCallbacks);
}
BatchingAPIClient::~BatchingAPIClient()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
}
int BatchingAPIClient::getBatchSize()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
return locAPIGetBatchSize();
}
int BatchingAPIClient::startSession(const IGnssBatching::Options& opts)
{
LOC_LOGD("%s]: (%lld %d)", __FUNCTION__,
static_cast<long long>(opts.periodNanos), static_cast<uint8_t>(opts.flags));
int retVal = -1;
LocationOptions options;
convertBatchOption(opts, options, mLocationCapabilitiesMask);
uint32_t mode = 0;
if (opts.flags == static_cast<uint8_t>(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) {
mode = SESSION_MODE_ON_FULL;
}
if (locAPIStartSession(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) {
retVal = 1;
}
return retVal;
}
int BatchingAPIClient::updateSessionOptions(const IGnssBatching::Options& opts)
{
LOC_LOGD("%s]: (%lld %d)", __FUNCTION__,
static_cast<long long>(opts.periodNanos), static_cast<uint8_t>(opts.flags));
int retVal = -1;
LocationOptions options;
convertBatchOption(opts, options, mLocationCapabilitiesMask);
uint32_t mode = 0;
if (opts.flags == static_cast<uint8_t>(IGnssBatching::Flag::WAKEUP_ON_FIFO_FULL)) {
mode = SESSION_MODE_ON_FULL;
}
if (locAPIUpdateSessionOptions(mDefaultId, mode, options) == LOCATION_ERROR_SUCCESS) {
retVal = 1;
}
return retVal;
}
int BatchingAPIClient::stopSession()
{
LOC_LOGD("%s]: ", __FUNCTION__);
int retVal = -1;
if (locAPIStopSession(mDefaultId) == LOCATION_ERROR_SUCCESS) {
retVal = 1;
}
return retVal;
}
void BatchingAPIClient::getBatchedLocation(int last_n_locations)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, last_n_locations);
locAPIGetBatchedLocations(mDefaultId, last_n_locations);
}
void BatchingAPIClient::flushBatchedLocations()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
locAPIGetBatchedLocations(mDefaultId, SIZE_MAX);
}
void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
{
LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
mLocationCapabilitiesMask = capabilitiesMask;
}
void BatchingAPIClient::onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions)
{
LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count);
if (mGnssBatchingCbIface != nullptr && count > 0) {
hidl_vec<GnssLocation> locationVec;
locationVec.resize(count);
for (size_t i = 0; i < count; i++) {
convertGnssLocation(location[i], locationVec[i]);
}
auto r = mGnssBatchingCbIface->gnssLocationBatchCb(locationVec);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssLocationBatchCb description=%s",
__func__, r.description().c_str());
}
}
}
static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out,
LocationCapabilitiesMask mask)
{
memset(&out, 0, sizeof(LocationOptions));
out.size = sizeof(LocationOptions);
out.minInterval = (uint32_t)(in.periodNanos / 1000000L);
out.minDistance = 0;
out.mode = GNSS_SUPL_MODE_STANDALONE;
if (mask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
out.mode = GNSS_SUPL_MODE_MSA;
if (mask & LOCATION_CAPABILITIES_GNSS_MSB_BIT)
out.mode = GNSS_SUPL_MODE_MSB;
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,75 @@
/* Copyright (c) 2017, 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 BATCHING_API_CLINET_H
#define BATCHING_API_CLINET_H
#include <android/hardware/gnss/1.0/IGnssBatching.h>
#include <android/hardware/gnss/1.0/IGnssBatchingCallback.h>
#include <pthread.h>
#include <LocationAPIClientBase.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
class BatchingAPIClient : public LocationAPIClientBase
{
public:
BatchingAPIClient(const sp<IGnssBatchingCallback>& callback);
~BatchingAPIClient();
int getBatchSize();
int startSession(const IGnssBatching::Options& options);
int updateSessionOptions(const IGnssBatching::Options& options);
int stopSession();
void getBatchedLocation(int last_n_locations);
void flushBatchedLocations();
inline LocationCapabilitiesMask getCapabilities() { return mLocationCapabilitiesMask; }
// callbacks
void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
void onBatchingCb(size_t count, Location* location, BatchingOptions batchOptions) final;
private:
sp<IGnssBatchingCallback> mGnssBatchingCbIface;
uint32_t mDefaultId;
int mBatchSize;
LocationCapabilitiesMask mLocationCapabilitiesMask;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // BATCHING_API_CLINET_H

View File

@@ -0,0 +1,273 @@
/* Copyright (c) 2017, 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_NDEBUG 0
#define LOG_TAG "LocSvc_GeofenceApiClient"
#include <log_util.h>
#include <loc_cfg.h>
#include "LocationUtil.h"
#include "GeofenceAPIClient.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
GeofenceAPIClient::GeofenceAPIClient(const sp<IGnssGeofenceCallback>& callback) :
LocationAPIClientBase(),
mGnssGeofencingCbIface(callback)
{
LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
locationCallbacks.trackingCb = nullptr;
locationCallbacks.batchingCb = nullptr;
locationCallbacks.geofenceBreachCb = nullptr;
if (mGnssGeofencingCbIface != nullptr) {
locationCallbacks.geofenceBreachCb =
[this](GeofenceBreachNotification geofenceBreachNotification) {
onGeofenceBreachCb(geofenceBreachNotification);
};
locationCallbacks.geofenceStatusCb =
[this](GeofenceStatusNotification geofenceStatusNotification) {
onGeofenceStatusCb(geofenceStatusNotification);
};
}
locationCallbacks.gnssLocationInfoCb = nullptr;
locationCallbacks.gnssNiCb = nullptr;
locationCallbacks.gnssSvCb = nullptr;
locationCallbacks.gnssNmeaCb = nullptr;
locationCallbacks.gnssMeasurementsCb = nullptr;
locAPISetCallbacks(locationCallbacks);
}
void GeofenceAPIClient::geofenceAdd(uint32_t geofence_id, double latitude, double longitude,
double radius_meters, int32_t last_transition, int32_t monitor_transitions,
uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms)
{
LOC_LOGD("%s]: (%d %f %f %f %d %d %d %d)", __FUNCTION__,
geofence_id, latitude, longitude, radius_meters,
last_transition, monitor_transitions, notification_responsiveness_ms, unknown_timer_ms);
GeofenceOption options;
memset(&options, 0, sizeof(GeofenceOption));
options.size = sizeof(GeofenceOption);
if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED)
options.breachTypeMask |= GEOFENCE_BREACH_ENTER_BIT;
if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED)
options.breachTypeMask |= GEOFENCE_BREACH_EXIT_BIT;
options.responsiveness = notification_responsiveness_ms;
GeofenceInfo data;
data.size = sizeof(GeofenceInfo);
data.latitude = latitude;
data.longitude = longitude;
data.radius = radius_meters;
LocationError err = (LocationError)locAPIAddGeofences(1, &geofence_id, &options, &data);
if (LOCATION_ERROR_SUCCESS != err) {
onAddGeofencesCb(1, &err, &geofence_id);
}
}
void GeofenceAPIClient::geofencePause(uint32_t geofence_id)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id);
locAPIPauseGeofences(1, &geofence_id);
}
void GeofenceAPIClient::geofenceResume(uint32_t geofence_id, int32_t monitor_transitions)
{
LOC_LOGD("%s]: (%d %d)", __FUNCTION__, geofence_id, monitor_transitions);
GeofenceBreachTypeMask mask = 0;
if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::ENTERED)
mask |= GEOFENCE_BREACH_ENTER_BIT;
if (monitor_transitions & IGnssGeofenceCallback::GeofenceTransition::EXITED)
mask |= GEOFENCE_BREACH_EXIT_BIT;
locAPIResumeGeofences(1, &geofence_id, &mask);
}
void GeofenceAPIClient::geofenceRemove(uint32_t geofence_id)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, geofence_id);
locAPIRemoveGeofences(1, &geofence_id);
}
void GeofenceAPIClient::geofenceRemoveAll()
{
LOC_LOGD("%s]", __FUNCTION__);
// TODO locAPIRemoveAllGeofences();
}
// callbacks
void GeofenceAPIClient::onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification)
{
LOC_LOGD("%s]: (%zu)", __FUNCTION__, geofenceBreachNotification.count);
if (mGnssGeofencingCbIface != nullptr) {
for (size_t i = 0; i < geofenceBreachNotification.count; i++) {
GnssLocation gnssLocation;
convertGnssLocation(geofenceBreachNotification.location, gnssLocation);
IGnssGeofenceCallback::GeofenceTransition transition;
if (geofenceBreachNotification.type == GEOFENCE_BREACH_ENTER)
transition = IGnssGeofenceCallback::GeofenceTransition::ENTERED;
else if (geofenceBreachNotification.type == GEOFENCE_BREACH_EXIT)
transition = IGnssGeofenceCallback::GeofenceTransition::EXITED;
else {
// continue with other breach if transition is
// nether GPS_GEOFENCE_ENTERED nor GPS_GEOFENCE_EXITED
continue;
}
auto r = mGnssGeofencingCbIface->gnssGeofenceTransitionCb(
geofenceBreachNotification.ids[i], gnssLocation, transition,
static_cast<GnssUtcTime>(geofenceBreachNotification.timestamp));
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofenceTransitionCb description=%s",
__func__, r.description().c_str());
}
}
}
}
void GeofenceAPIClient::onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, geofenceStatusNotification.available);
if (mGnssGeofencingCbIface != nullptr) {
IGnssGeofenceCallback::GeofenceAvailability status =
IGnssGeofenceCallback::GeofenceAvailability::UNAVAILABLE;
if (geofenceStatusNotification.available == GEOFENCE_STATUS_AVAILABILE_YES) {
status = IGnssGeofenceCallback::GeofenceAvailability::AVAILABLE;
}
GnssLocation gnssLocation;
memset(&gnssLocation, 0, sizeof(GnssLocation));
auto r = mGnssGeofencingCbIface->gnssGeofenceStatusCb(status, gnssLocation);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofenceStatusCb description=%s",
__func__, r.description().c_str());
}
}
}
void GeofenceAPIClient::onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
{
LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
if (mGnssGeofencingCbIface != nullptr) {
for (size_t i = 0; i < count; i++) {
IGnssGeofenceCallback::GeofenceStatus status =
IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
if (errors[i] == LOCATION_ERROR_SUCCESS)
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
else if (errors[i] == LOCATION_ERROR_ID_EXISTS)
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_EXISTS;
auto r = mGnssGeofencingCbIface->gnssGeofenceAddCb(ids[i], status);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofenceAddCb description=%s",
__func__, r.description().c_str());
}
}
}
}
void GeofenceAPIClient::onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
{
LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
if (mGnssGeofencingCbIface != nullptr) {
for (size_t i = 0; i < count; i++) {
IGnssGeofenceCallback::GeofenceStatus status =
IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
if (errors[i] == LOCATION_ERROR_SUCCESS)
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
auto r = mGnssGeofencingCbIface->gnssGeofenceRemoveCb(ids[i], status);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofenceRemoveCb description=%s",
__func__, r.description().c_str());
}
}
}
}
void GeofenceAPIClient::onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
{
LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
if (mGnssGeofencingCbIface != nullptr) {
for (size_t i = 0; i < count; i++) {
IGnssGeofenceCallback::GeofenceStatus status =
IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
if (errors[i] == LOCATION_ERROR_SUCCESS)
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
auto r = mGnssGeofencingCbIface->gnssGeofencePauseCb(ids[i], status);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofencePauseCb description=%s",
__func__, r.description().c_str());
}
}
}
}
void GeofenceAPIClient::onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids)
{
LOC_LOGD("%s]: (%zu)", __FUNCTION__, count);
if (mGnssGeofencingCbIface != nullptr) {
for (size_t i = 0; i < count; i++) {
IGnssGeofenceCallback::GeofenceStatus status =
IGnssGeofenceCallback::GeofenceStatus::ERROR_GENERIC;
if (errors[i] == LOCATION_ERROR_SUCCESS)
status = IGnssGeofenceCallback::GeofenceStatus::OPERATION_SUCCESS;
else if (errors[i] == LOCATION_ERROR_ID_UNKNOWN)
status = IGnssGeofenceCallback::GeofenceStatus::ERROR_ID_UNKNOWN;
auto r = mGnssGeofencingCbIface->gnssGeofenceResumeCb(ids[i], status);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssGeofenceResumeCb description=%s",
__func__, r.description().c_str());
}
}
}
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,76 @@
/* Copyright (c) 2017, 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 GEOFENCE_API_CLINET_H
#define GEOFENCE_API_CLINET_H
#include <android/hardware/gnss/1.0/IGnssGeofenceCallback.h>
#include <LocationAPIClientBase.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::sp;
class GeofenceAPIClient : public LocationAPIClientBase
{
public:
GeofenceAPIClient(const sp<IGnssGeofenceCallback>& callback);
virtual ~GeofenceAPIClient() = default;
void geofenceAdd(uint32_t geofence_id, double latitude, double longitude,
double radius_meters, int32_t last_transition, int32_t monitor_transitions,
uint32_t notification_responsiveness_ms, uint32_t unknown_timer_ms);
void geofencePause(uint32_t geofence_id);
void geofenceResume(uint32_t geofence_id, int32_t monitor_transitions);
void geofenceRemove(uint32_t geofence_id);
void geofenceRemoveAll();
// callbacks
void onGeofenceBreachCb(GeofenceBreachNotification geofenceBreachNotification) final;
void onGeofenceStatusCb(GeofenceStatusNotification geofenceStatusNotification) final;
void onAddGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
void onRemoveGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
void onPauseGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
void onResumeGeofencesCb(size_t count, LocationError* errors, uint32_t* ids) final;
private:
sp<IGnssGeofenceCallback> mGnssGeofencingCbIface;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // GEOFENCE_API_CLINET_H

View File

@@ -0,0 +1,498 @@
/* Copyright (c) 2017, 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_NDEBUG 0
#define LOG_TAG "LocSvc_GnssAPIClient"
#include <log_util.h>
#include <loc_cfg.h>
#include "LocationUtil.h"
#include "GnssAPIClient.h"
#include <LocDualContext.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out);
GnssAPIClient::GnssAPIClient(const sp<IGnssCallback>& gpsCb,
const sp<IGnssNiCallback>& niCb) :
LocationAPIClientBase(),
mGnssCbIface(nullptr),
mGnssNiCbIface(nullptr),
mControlClient(new LocationAPIControlClient()),
mLocationCapabilitiesMask(0),
mLocationCapabilitiesCached(false)
{
LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
// set default LocationOptions.
memset(&mLocationOptions, 0, sizeof(LocationOptions));
mLocationOptions.size = sizeof(LocationOptions);
mLocationOptions.minInterval = 1000;
mLocationOptions.minDistance = 0;
mLocationOptions.mode = GNSS_SUPL_MODE_STANDALONE;
gnssUpdateCallbacks(gpsCb, niCb);
}
GnssAPIClient::~GnssAPIClient()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
if (mControlClient) {
delete mControlClient;
mControlClient = nullptr;
}
}
// for GpsInterface
void GnssAPIClient::gnssUpdateCallbacks(const sp<IGnssCallback>& gpsCb,
const sp<IGnssNiCallback>& niCb)
{
LOC_LOGD("%s]: (%p %p)", __FUNCTION__, &gpsCb, &niCb);
mGnssCbIface = gpsCb;
mGnssNiCbIface = niCb;
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
locationCallbacks.trackingCb = nullptr;
if (mGnssCbIface != nullptr) {
locationCallbacks.trackingCb = [this](Location location) {
onTrackingCb(location);
};
}
locationCallbacks.batchingCb = nullptr;
locationCallbacks.geofenceBreachCb = nullptr;
locationCallbacks.geofenceStatusCb = nullptr;
locationCallbacks.gnssLocationInfoCb = nullptr;
locationCallbacks.gnssNiCb = nullptr;
loc_core::ContextBase* context =
loc_core::LocDualContext::getLocFgContext(
NULL, NULL,
loc_core::LocDualContext::mLocationHalName, false);
if (mGnssNiCbIface != nullptr && !context->hasAgpsExtendedCapabilities()) {
LOC_LOGD("Registering NI CB");
locationCallbacks.gnssNiCb = [this](uint32_t id, GnssNiNotification gnssNiNotification) {
onGnssNiCb(id, gnssNiNotification);
};
}
locationCallbacks.gnssSvCb = nullptr;
if (mGnssCbIface != nullptr) {
locationCallbacks.gnssSvCb = [this](GnssSvNotification gnssSvNotification) {
onGnssSvCb(gnssSvNotification);
};
}
locationCallbacks.gnssNmeaCb = nullptr;
if (mGnssCbIface != nullptr) {
locationCallbacks.gnssNmeaCb = [this](GnssNmeaNotification gnssNmeaNotification) {
onGnssNmeaCb(gnssNmeaNotification);
};
}
locationCallbacks.gnssMeasurementsCb = nullptr;
locAPISetCallbacks(locationCallbacks);
}
bool GnssAPIClient::gnssStart()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
bool retVal = true;
locAPIStartTracking(mLocationOptions);
return retVal;
}
bool GnssAPIClient::gnssStop()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
bool retVal = true;
locAPIStopTracking();
return retVal;
}
bool GnssAPIClient::gnssSetPositionMode(IGnss::GnssPositionMode mode,
IGnss::GnssPositionRecurrence recurrence, uint32_t minIntervalMs,
uint32_t preferredAccuracyMeters, uint32_t preferredTimeMs)
{
LOC_LOGD("%s]: (%d %d %d %d %d)", __FUNCTION__,
(int)mode, recurrence, minIntervalMs, preferredAccuracyMeters, preferredTimeMs);
bool retVal = true;
memset(&mLocationOptions, 0, sizeof(LocationOptions));
mLocationOptions.size = sizeof(LocationOptions);
mLocationOptions.minInterval = minIntervalMs;
mLocationOptions.minDistance = preferredAccuracyMeters;
if (mode == IGnss::GnssPositionMode::STANDALONE)
mLocationOptions.mode = GNSS_SUPL_MODE_STANDALONE;
else if (mode == IGnss::GnssPositionMode::MS_BASED)
mLocationOptions.mode = GNSS_SUPL_MODE_MSB;
else if (mode == IGnss::GnssPositionMode::MS_ASSISTED)
mLocationOptions.mode = GNSS_SUPL_MODE_MSA;
else {
LOC_LOGD("%s]: invalid GnssPositionMode: %d", __FUNCTION__, (int)mode);
retVal = false;
}
locAPIUpdateTrackingOptions(mLocationOptions);
return retVal;
}
// for GpsNiInterface
void GnssAPIClient::gnssNiRespond(int32_t notifId,
IGnssNiCallback::GnssUserResponseType userResponse)
{
LOC_LOGD("%s]: (%d %d)", __FUNCTION__, notifId, static_cast<int>(userResponse));
GnssNiResponse data = GNSS_NI_RESPONSE_IGNORE;
if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT)
data = GNSS_NI_RESPONSE_ACCEPT;
else if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY)
data = GNSS_NI_RESPONSE_DENY;
else if (userResponse == IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP)
data = GNSS_NI_RESPONSE_NO_RESPONSE;
else {
LOC_LOGD("%s]: invalid GnssUserResponseType: %d", __FUNCTION__, (int)userResponse);
return;
}
locAPIGnssNiResponse(notifId, data);
}
// these apis using LocationAPIControlClient
void GnssAPIClient::gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags)
{
LOC_LOGD("%s]: (%02hx)", __FUNCTION__, aidingDataFlags);
if (mControlClient == nullptr) {
return;
}
GnssAidingData data;
memset(&data, 0, sizeof (GnssAidingData));
data.sv.svTypeMask = GNSS_AIDING_DATA_SV_TYPE_GPS_BIT |
GNSS_AIDING_DATA_SV_TYPE_GLONASS_BIT |
GNSS_AIDING_DATA_SV_TYPE_QZSS_BIT |
GNSS_AIDING_DATA_SV_TYPE_BEIDOU_BIT |
GNSS_AIDING_DATA_SV_TYPE_GALILEO_BIT;
if (aidingDataFlags == IGnss::GnssAidingData::DELETE_ALL)
data.deleteAll = true;
else {
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_EPHEMERIS)
data.sv.svMask |= GNSS_AIDING_DATA_SV_EPHEMERIS_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_ALMANAC)
data.sv.svMask |= GNSS_AIDING_DATA_SV_ALMANAC_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_POSITION)
data.common.mask |= GNSS_AIDING_DATA_COMMON_POSITION_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_TIME)
data.common.mask |= GNSS_AIDING_DATA_COMMON_TIME_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_IONO)
data.sv.svMask |= GNSS_AIDING_DATA_SV_IONOSPHERE_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_UTC)
data.common.mask |= GNSS_AIDING_DATA_COMMON_UTC_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_HEALTH)
data.sv.svMask |= GNSS_AIDING_DATA_SV_HEALTH_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVDIR)
data.sv.svMask |= GNSS_AIDING_DATA_SV_DIRECTION_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SVSTEER)
data.sv.svMask |= GNSS_AIDING_DATA_SV_STEER_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_SADATA)
data.sv.svMask |= GNSS_AIDING_DATA_SV_SA_DATA_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_RTI)
data.common.mask |= GNSS_AIDING_DATA_COMMON_RTI_BIT;
if (aidingDataFlags & IGnss::GnssAidingData::DELETE_CELLDB_INFO)
data.common.mask |= GNSS_AIDING_DATA_COMMON_CELLDB_BIT;
}
mControlClient->locAPIGnssDeleteAidingData(data);
}
void GnssAPIClient::gnssEnable(LocationTechnologyType techType)
{
LOC_LOGD("%s]: (%0d)", __FUNCTION__, techType);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIEnable(techType);
}
void GnssAPIClient::gnssDisable()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIDisable();
}
void GnssAPIClient::gnssConfigurationUpdate(const GnssConfig& gnssConfig)
{
LOC_LOGD("%s]: (%02x)", __FUNCTION__, gnssConfig.flags);
if (mControlClient == nullptr) {
return;
}
mControlClient->locAPIGnssUpdateConfig(gnssConfig);
}
void GnssAPIClient::requestCapabilities() {
// only send capablities if it's already cached, otherwise the first time LocationAPI
// is initialized, capabilities will be sent by LocationAPI
if (mLocationCapabilitiesCached) {
onCapabilitiesCb(mLocationCapabilitiesMask);
}
}
// callbacks
void GnssAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask)
{
LOC_LOGD("%s]: (%02x)", __FUNCTION__, capabilitiesMask);
mLocationCapabilitiesMask = capabilitiesMask;
mLocationCapabilitiesCached = true;
if (mGnssCbIface != nullptr) {
uint32_t data = 0;
if ((capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_TRACKING_BIT) ||
(capabilitiesMask & LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT) ||
(capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT) ||
(capabilitiesMask & LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT))
data |= IGnssCallback::Capabilities::SCHEDULING;
if (capabilitiesMask & LOCATION_CAPABILITIES_GEOFENCE_BIT)
data |= IGnssCallback::Capabilities::GEOFENCING;
if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT)
data |= IGnssCallback::Capabilities::MEASUREMENTS;
if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSB_BIT)
data |= IGnssCallback::Capabilities::MSB;
if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MSA_BIT)
data |= IGnssCallback::Capabilities::MSA;
auto r = mGnssCbIface->gnssSetCapabilitesCb(data);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssSetCapabilitesCb description=%s",
__func__, r.description().c_str());
}
}
if (mGnssCbIface != nullptr) {
IGnssCallback::GnssSystemInfo gnssInfo;
if (capabilitiesMask & LOCATION_CAPABILITIES_DEBUG_NMEA_BIT) {
gnssInfo.yearOfHw = 2017;
} else if (capabilitiesMask & LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT) {
gnssInfo.yearOfHw = 2016;
} else {
gnssInfo.yearOfHw = 2015;
}
LOC_LOGV("%s:%d] set_system_info_cb (%d)", __FUNCTION__, __LINE__, gnssInfo.yearOfHw);
auto r = mGnssCbIface->gnssSetSystemInfoCb(gnssInfo);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssSetSystemInfoCb description=%s",
__func__, r.description().c_str());
}
}
}
void GnssAPIClient::onTrackingCb(Location location)
{
LOC_LOGD("%s]: (flags: %02x)", __FUNCTION__, location.flags);
if (mGnssCbIface != nullptr) {
GnssLocation gnssLocation;
convertGnssLocation(location, gnssLocation);
auto r = mGnssCbIface->gnssLocationCb(gnssLocation);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssLocationCb description=%s",
__func__, r.description().c_str());
}
}
}
void GnssAPIClient::onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification)
{
LOC_LOGD("%s]: (id: %d)", __FUNCTION__, id);
if (mGnssNiCbIface == nullptr) {
LOC_LOGE("%s]: mGnssNiCbIface is nullptr", __FUNCTION__);
return;
}
IGnssNiCallback::GnssNiNotification notificationGnss = {};
notificationGnss.notificationId = id;
if (gnssNiNotification.type == GNSS_NI_TYPE_VOICE)
notificationGnss.niType = IGnssNiCallback::GnssNiType::VOICE;
else if (gnssNiNotification.type == GNSS_NI_TYPE_SUPL)
notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_SUPL;
else if (gnssNiNotification.type == GNSS_NI_TYPE_CONTROL_PLANE)
notificationGnss.niType = IGnssNiCallback::GnssNiType::UMTS_CTRL_PLANE;
else if (gnssNiNotification.type == GNSS_NI_TYPE_EMERGENCY_SUPL)
notificationGnss.niType = IGnssNiCallback::GnssNiType::EMERGENCY_SUPL;
if (gnssNiNotification.options & GNSS_NI_OPTIONS_NOTIFICATION_BIT)
notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_NOTIFY;
if (gnssNiNotification.options & GNSS_NI_OPTIONS_VERIFICATION_BIT)
notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::NEED_VERIFY;
if (gnssNiNotification.options & GNSS_NI_OPTIONS_PRIVACY_OVERRIDE_BIT)
notificationGnss.notifyFlags |= IGnssNiCallback::GnssNiNotifyFlags::PRIVACY_OVERRIDE;
notificationGnss.timeoutSec = gnssNiNotification.timeout;
if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_ACCEPT)
notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_ACCEPT;
else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_DENY)
notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_DENY;
else if (gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_NO_RESPONSE ||
gnssNiNotification.timeoutResponse == GNSS_NI_RESPONSE_IGNORE)
notificationGnss.defaultResponse = IGnssNiCallback::GnssUserResponseType::RESPONSE_NORESP;
notificationGnss.requestorId = gnssNiNotification.requestor;
notificationGnss.notificationMessage = gnssNiNotification.message;
if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_NONE)
notificationGnss.requestorIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_NONE;
else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT)
notificationGnss.requestorIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT;
else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UTF8)
notificationGnss.requestorIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8;
else if (gnssNiNotification.requestorEncoding == GNSS_NI_ENCODING_TYPE_UCS2)
notificationGnss.requestorIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2;
if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_NONE)
notificationGnss.notificationIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_NONE;
else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_GSM_DEFAULT)
notificationGnss.notificationIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_GSM_DEFAULT;
else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UTF8)
notificationGnss.notificationIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UTF8;
else if (gnssNiNotification.messageEncoding == GNSS_NI_ENCODING_TYPE_UCS2)
notificationGnss.notificationIdEncoding =
IGnssNiCallback::GnssNiEncodingType::ENC_SUPL_UCS2;
mGnssNiCbIface->niNotifyCb(notificationGnss);
}
void GnssAPIClient::onGnssSvCb(GnssSvNotification gnssSvNotification)
{
LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, gnssSvNotification.count);
if (mGnssCbIface != nullptr) {
IGnssCallback::GnssSvStatus svStatus;
convertGnssSvStatus(gnssSvNotification, svStatus);
auto r = mGnssCbIface->gnssSvStatusCb(svStatus);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssSvStatusCb description=%s",
__func__, r.description().c_str());
}
}
}
void GnssAPIClient::onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification)
{
if (mGnssCbIface != nullptr) {
android::hardware::hidl_string nmeaString;
nmeaString.setToExternal(gnssNmeaNotification.nmea, gnssNmeaNotification.length);
auto r = mGnssCbIface->gnssNmeaCb(
static_cast<GnssUtcTime>(gnssNmeaNotification.timestamp), nmeaString);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssNmeaCb nmea=%s length=%zu description=%s", __func__,
gnssNmeaNotification.nmea, gnssNmeaNotification.length, r.description().c_str());
}
}
}
void GnssAPIClient::onStartTrackingCb(LocationError error)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
auto r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_ON);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssStatusCb ENGINE_ON description=%s",
__func__, r.description().c_str());
}
r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_BEGIN);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssStatusCb SESSION_BEGIN description=%s",
__func__, r.description().c_str());
}
}
}
void GnssAPIClient::onStopTrackingCb(LocationError error)
{
LOC_LOGD("%s]: (%d)", __FUNCTION__, error);
if (error == LOCATION_ERROR_SUCCESS && mGnssCbIface != nullptr) {
auto r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::SESSION_END);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssStatusCb SESSION_END description=%s",
__func__, r.description().c_str());
}
r = mGnssCbIface->gnssStatusCb(IGnssCallback::GnssStatusValue::ENGINE_OFF);
if (!r.isOk()) {
LOC_LOGE("%s] Error from gnssStatusCb ENGINE_OFF description=%s",
__func__, r.description().c_str());
}
}
}
static void convertGnssSvStatus(GnssSvNotification& in, IGnssCallback::GnssSvStatus& out)
{
memset(&out, 0, sizeof(IGnssCallback::GnssSvStatus));
out.numSvs = in.count;
if (out.numSvs > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
LOC_LOGW("%s]: Too many satellites %zd. Clamps to %d.",
__FUNCTION__, out.numSvs, GnssMax::SVS_COUNT);
out.numSvs = static_cast<uint32_t>(GnssMax::SVS_COUNT);
}
for (size_t i = 0; i < out.numSvs; i++) {
IGnssCallback::GnssSvInfo& info = out.gnssSvList[i];
info.svid = in.gnssSvs[i].svId;
convertGnssConstellationType(in.gnssSvs[i].type, info.constellation);
info.cN0Dbhz = in.gnssSvs[i].cN0Dbhz;
info.elevationDegrees = in.gnssSvs[i].elevation;
info.azimuthDegrees = in.gnssSvs[i].azimuth;
info.svFlag = static_cast<uint8_t>(IGnssCallback::GnssSvFlags::NONE);
if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_EPHEMER_BIT)
info.svFlag |= IGnssCallback::GnssSvFlags::HAS_EPHEMERIS_DATA;
if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_HAS_ALMANAC_BIT)
info.svFlag |= IGnssCallback::GnssSvFlags::HAS_ALMANAC_DATA;
if (in.gnssSvs[i].gnssSvOptionsMask & GNSS_SV_OPTIONS_USED_IN_FIX_BIT)
info.svFlag |= IGnssCallback::GnssSvFlags::USED_IN_FIX;
}
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,107 @@
/* Copyright (c) 2017, 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 GNSS_API_CLINET_H
#define GNSS_API_CLINET_H
#include <android/hardware/gnss/1.0/IGnss.h>
#include <android/hardware/gnss/1.0/IGnssCallback.h>
#include <android/hardware/gnss/1.0/IGnssNiCallback.h>
#include <LocationAPIClientBase.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::sp;
class GnssAPIClient : public LocationAPIClientBase
{
public:
GnssAPIClient(const sp<IGnssCallback>& gpsCb,
const sp<IGnssNiCallback>& niCb);
virtual ~GnssAPIClient();
GnssAPIClient(const GnssAPIClient&) = delete;
GnssAPIClient& operator=(const GnssAPIClient&) = delete;
// for GpsInterface
void gnssUpdateCallbacks(const sp<IGnssCallback>& gpsCb,
const sp<IGnssNiCallback>& niCb);
bool gnssStart();
bool gnssStop();
bool gnssSetPositionMode(IGnss::GnssPositionMode mode,
IGnss::GnssPositionRecurrence recurrence,
uint32_t minIntervalMs,
uint32_t preferredAccuracyMeters,
uint32_t preferredTimeMs);
// for GpsNiInterface
void gnssNiRespond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse);
// these apis using LocationAPIControlClient
void gnssDeleteAidingData(IGnss::GnssAidingData aidingDataFlags);
void gnssEnable(LocationTechnologyType techType);
void gnssDisable();
void gnssConfigurationUpdate(const GnssConfig& gnssConfig);
inline LocationCapabilitiesMask gnssGetCapabilities() const {
return mLocationCapabilitiesMask;
}
void requestCapabilities();
// callbacks we are interested in
void onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMask) final;
void onTrackingCb(Location location) final;
void onGnssNiCb(uint32_t id, GnssNiNotification gnssNiNotification) final;
void onGnssSvCb(GnssSvNotification gnssSvNotification) final;
void onGnssNmeaCb(GnssNmeaNotification gnssNmeaNotification) final;
void onStartTrackingCb(LocationError error) final;
void onStopTrackingCb(LocationError error) final;
private:
sp<IGnssCallback> mGnssCbIface;
sp<IGnssNiCallback> mGnssNiCbIface;
LocationAPIControlClient* mControlClient;
LocationCapabilitiesMask mLocationCapabilitiesMask;
bool mLocationCapabilitiesCached;
LocationOptions mLocationOptions;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // GNSS_API_CLINET_H

View File

@@ -0,0 +1,153 @@
/* Copyright (c) 2017, 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 <LocationUtil.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void convertGnssLocation(Location& in, GnssLocation& out)
{
memset(&out, 0, sizeof(GnssLocation));
if (in.flags & LOCATION_HAS_LAT_LONG_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_LAT_LONG;
if (in.flags & LOCATION_HAS_ALTITUDE_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_ALTITUDE;
if (in.flags & LOCATION_HAS_SPEED_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED;
if (in.flags & LOCATION_HAS_BEARING_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING;
if (in.flags & LOCATION_HAS_ACCURACY_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_HORIZONTAL_ACCURACY;
if (in.flags & LOCATION_HAS_VERTICAL_ACCURACY_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_VERTICAL_ACCURACY;
if (in.flags & LOCATION_HAS_SPEED_ACCURACY_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_SPEED_ACCURACY;
if (in.flags & LOCATION_HAS_BEARING_ACCURACY_BIT)
out.gnssLocationFlags |= GnssLocationFlags::HAS_BEARING_ACCURACY;
out.latitudeDegrees = in.latitude;
out.longitudeDegrees = in.longitude;
out.altitudeMeters = in.altitude;
out.speedMetersPerSec = in.speed;
out.bearingDegrees = in.bearing;
out.horizontalAccuracyMeters = in.accuracy;
out.verticalAccuracyMeters = in.verticalAccuracy;
out.speedAccuracyMetersPerSecond = in.speedAccuracy;
out.bearingAccuracyDegrees = in.bearingAccuracy;
out.timestamp = static_cast<GnssUtcTime>(in.timestamp);
}
void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out)
{
switch(in) {
case GNSS_SV_TYPE_GPS:
out = GnssConstellationType::GPS;
break;
case GNSS_SV_TYPE_SBAS:
out = GnssConstellationType::SBAS;
break;
case GNSS_SV_TYPE_GLONASS:
out = GnssConstellationType::GLONASS;
break;
case GNSS_SV_TYPE_QZSS:
out = GnssConstellationType::QZSS;
break;
case GNSS_SV_TYPE_BEIDOU:
out = GnssConstellationType::BEIDOU;
break;
case GNSS_SV_TYPE_GALILEO:
out = GnssConstellationType::GALILEO;
break;
case GNSS_SV_TYPE_UNKNOWN:
default:
out = GnssConstellationType::UNKNOWN;
break;
}
}
void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out)
{
switch(in) {
case GNSS_EPH_TYPE_EPHEMERIS:
out = GnssDebug::SatelliteEphemerisType::EPHEMERIS;
break;
case GNSS_EPH_TYPE_ALMANAC:
out = GnssDebug::SatelliteEphemerisType::ALMANAC_ONLY;
break;
case GNSS_EPH_TYPE_UNKNOWN:
default:
out = GnssDebug::SatelliteEphemerisType::NOT_AVAILABLE;
break;
}
}
void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out)
{
switch(in) {
case GNSS_EPH_SOURCE_DEMODULATED:
out = GnssDebug::SatelliteEphemerisSource::DEMODULATED;
break;
case GNSS_EPH_SOURCE_SUPL_PROVIDED:
out = GnssDebug::SatelliteEphemerisSource::SUPL_PROVIDED;
break;
case GNSS_EPH_SOURCE_OTHER_SERVER_PROVIDED:
out = GnssDebug::SatelliteEphemerisSource::OTHER_SERVER_PROVIDED;
break;
case GNSS_EPH_SOURCE_LOCAL:
case GNSS_EPH_SOURCE_UNKNOWN:
default:
out = GnssDebug::SatelliteEphemerisSource::OTHER;
break;
}
}
void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out)
{
switch(in) {
case GNSS_EPH_HEALTH_GOOD:
out = GnssDebug::SatelliteEphemerisHealth::GOOD;
break;
case GNSS_EPH_HEALTH_BAD:
out = GnssDebug::SatelliteEphemerisHealth::BAD;
break;
case GNSS_EPH_HEALTH_UNKNOWN:
default:
out = GnssDebug::SatelliteEphemerisHealth::UNKNOWN;
break;
}
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -9,7 +9,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundatoin, nor the names of its
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -24,22 +24,31 @@
* 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 _GNSSPPS_H
#define _GNSSPPS_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LOCATION_UTIL_H
#define LOCATION_UTIL_H
/* opens the device and fetches from PPS source */
int initPPS(char *devname);
/* updates the fine time stamp */
int getPPS(struct timespec *current_ts, struct timespec *current_boottime, struct timespec *last_boottime);
/* stops fetching and closes the device */
void deInitPPS();
#include <android/hardware/gnss/1.0/types.h>
#include <LocationAPI.h>
#include <GnssDebug.h>
#ifdef __cplusplus
}
#endif
#endif
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
void convertGnssLocation(Location& in, GnssLocation& out);
void convertGnssConstellationType(GnssSvType& in, GnssConstellationType& out);
void convertGnssEphemerisType(GnssEphemerisType& in, GnssDebug::SatelliteEphemerisType& out);
void convertGnssEphemerisSource(GnssEphemerisSource& in, GnssDebug::SatelliteEphemerisSource& out);
void convertGnssEphemerisHealth(GnssEphemerisHealth& in, GnssDebug::SatelliteEphemerisHealth& out);
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // LOCATION_UTIL_H

View File

@@ -0,0 +1,257 @@
/* Copyright (c) 2017, 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_NDEBUG 0
#define LOG_TAG "LocSvc_MeasurementAPIClient"
#include <log_util.h>
#include <loc_cfg.h>
#include "LocationUtil.h"
#include "MeasurementAPIClient.h"
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
static void convertGnssData(GnssMeasurementsNotification& in,
IGnssMeasurementCallback::GnssData& out);
static void convertGnssMeasurement(GnssMeasurementsData& in,
IGnssMeasurementCallback::GnssMeasurement& out);
static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out);
MeasurementAPIClient::MeasurementAPIClient() :
mGnssMeasurementCbIface(nullptr),
mTracking(false)
{
LOC_LOGD("%s]: ()", __FUNCTION__);
}
MeasurementAPIClient::~MeasurementAPIClient()
{
LOC_LOGD("%s]: ()", __FUNCTION__);
}
// for GpsInterface
Return<IGnssMeasurement::GnssMeasurementStatus>
MeasurementAPIClient::measurementSetCallback(const sp<IGnssMeasurementCallback>& callback)
{
LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback);
mGnssMeasurementCbIface = callback;
LocationCallbacks locationCallbacks;
memset(&locationCallbacks, 0, sizeof(LocationCallbacks));
locationCallbacks.size = sizeof(LocationCallbacks);
locationCallbacks.trackingCb = nullptr;
locationCallbacks.batchingCb = nullptr;
locationCallbacks.geofenceBreachCb = nullptr;
locationCallbacks.geofenceStatusCb = nullptr;
locationCallbacks.gnssLocationInfoCb = nullptr;
locationCallbacks.gnssNiCb = nullptr;
locationCallbacks.gnssSvCb = nullptr;
locationCallbacks.gnssNmeaCb = nullptr;
locationCallbacks.gnssMeasurementsCb = nullptr;
if (mGnssMeasurementCbIface != nullptr) {
locationCallbacks.gnssMeasurementsCb =
[this](GnssMeasurementsNotification gnssMeasurementsNotification) {
onGnssMeasurementsCb(gnssMeasurementsNotification);
};
}
locAPISetCallbacks(locationCallbacks);
LocationOptions options;
memset(&options, 0, sizeof(LocationOptions));
options.size = sizeof(LocationOptions);
options.minInterval = 1000;
options.mode = GNSS_SUPL_MODE_STANDALONE;
mTracking = true;
LOC_LOGD("%s]: start tracking session", __FUNCTION__);
locAPIStartTracking(options);
return IGnssMeasurement::GnssMeasurementStatus::SUCCESS;
}
// for GpsMeasurementInterface
void MeasurementAPIClient::measurementClose() {
LOC_LOGD("%s]: ()", __FUNCTION__);
mTracking = false;
locAPIStopTracking();
}
// callbacks
void MeasurementAPIClient::onGnssMeasurementsCb(
GnssMeasurementsNotification gnssMeasurementsNotification)
{
LOC_LOGD("%s]: (count: %zu active: %zu)",
__FUNCTION__, gnssMeasurementsNotification.count, mTracking);
if (mTracking) {
if (mGnssMeasurementCbIface != nullptr) {
IGnssMeasurementCallback::GnssData gnssData;
convertGnssData(gnssMeasurementsNotification, gnssData);
auto r = mGnssMeasurementCbIface->GnssMeasurementCb(gnssData);
if (!r.isOk()) {
LOC_LOGE("%s] Error from GnssMeasurementCb description=%s",
__func__, r.description().c_str());
}
}
}
}
static void convertGnssMeasurement(GnssMeasurementsData& in,
IGnssMeasurementCallback::GnssMeasurement& out)
{
memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssMeasurement));
if (in.flags & GNSS_MEASUREMENTS_DATA_SIGNAL_TO_NOISE_RATIO_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_SNR;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_FREQUENCY_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_FREQUENCY;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_CYCLES_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_CYCLES;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE;
if (in.flags & GNSS_MEASUREMENTS_DATA_CARRIER_PHASE_UNCERTAINTY_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_CARRIER_PHASE_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_DATA_AUTOMATIC_GAIN_CONTROL_BIT)
out.flags |= IGnssMeasurementCallback::GnssMeasurementFlags::HAS_AUTOMATIC_GAIN_CONTROL;
out.svid = in.svId;
convertGnssConstellationType(in.svType, out.constellation);
out.timeOffsetNs = in.timeOffsetNs;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_CODE_LOCK_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BIT_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BIT_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SUBFRAME_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SUBFRAME_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_TOW_DECODED_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_TOW_DECODED;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_MSEC_AMBIGUOUS_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_MSEC_AMBIGUOUS;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SYMBOL_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SYMBOL_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_STRING_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_STRING_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GLO_TOD_DECODED_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GLO_TOD_DECODED;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_BIT_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_BIT_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_BDS_D2_SUBFRAME_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_BDS_D2_SUBFRAME_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1BC_CODE_LOCK_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1BC_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1C_2ND_CODE_LOCK_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1C_2ND_CODE_LOCK;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_GAL_E1B_PAGE_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_GAL_E1B_PAGE_SYNC;
if (in.stateMask & GNSS_MEASUREMENTS_STATE_SBAS_SYNC_BIT)
out.state |= IGnssMeasurementCallback::GnssMeasurementState::STATE_SBAS_SYNC;
out.receivedSvTimeInNs = in.receivedSvTimeNs;
out.receivedSvTimeUncertaintyInNs = in.receivedSvTimeUncertaintyNs;
out.cN0DbHz = in.carrierToNoiseDbHz;
out.pseudorangeRateMps = in.pseudorangeRateMps;
out.pseudorangeRateUncertaintyMps = in.pseudorangeRateUncertaintyMps;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_VALID_BIT)
out.accumulatedDeltaRangeState |=
IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_VALID;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_RESET_BIT)
out.accumulatedDeltaRangeState |=
IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_RESET;
if (in.adrStateMask & GNSS_MEASUREMENTS_ACCUMULATED_DELTA_RANGE_STATE_CYCLE_SLIP_BIT)
out.accumulatedDeltaRangeState |=
IGnssMeasurementCallback::GnssAccumulatedDeltaRangeState::ADR_STATE_CYCLE_SLIP;
out.accumulatedDeltaRangeM = in.adrMeters;
out.accumulatedDeltaRangeUncertaintyM = in.adrUncertaintyMeters;
out.carrierFrequencyHz = in.carrierFrequencyHz;
out.carrierCycles = in.carrierCycles;
out.carrierPhase = in.carrierPhase;
out.carrierPhaseUncertainty = in.carrierPhaseUncertainty;
uint8_t indicator =
static_cast<uint8_t>(IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_UNKNOWN);
if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_PRESENT)
indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATOR_PRESENT;
if (in.multipathIndicator & GNSS_MEASUREMENTS_MULTIPATH_INDICATOR_NOT_PRESENT)
indicator |= IGnssMeasurementCallback::GnssMultipathIndicator::INDICATIOR_NOT_PRESENT;
out.multipathIndicator =
static_cast<IGnssMeasurementCallback::GnssMultipathIndicator>(indicator);
out.snrDb = in.signalToNoiseRatioDb;
out.agcLevelDb = in.agcLevelDb;
}
static void convertGnssClock(GnssMeasurementsClock& in, IGnssMeasurementCallback::GnssClock& out)
{
memset(&out, 0, sizeof(IGnssMeasurementCallback::GnssClock));
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_LEAP_SECOND_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_LEAP_SECOND;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_TIME_UNCERTAINTY_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_TIME_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_FULL_BIAS_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_FULL_BIAS;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_BIAS_UNCERTAINTY_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_BIAS_UNCERTAINTY;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT;
if (in.flags & GNSS_MEASUREMENTS_CLOCK_FLAGS_DRIFT_UNCERTAINTY_BIT)
out.gnssClockFlags |= IGnssMeasurementCallback::GnssClockFlags::HAS_DRIFT_UNCERTAINTY;
out.leapSecond = in.leapSecond;
out.timeNs = in.timeNs;
out.timeUncertaintyNs = in.timeUncertaintyNs;
out.fullBiasNs = in.fullBiasNs;
out.biasNs = in.biasNs;
out.biasUncertaintyNs = in.biasUncertaintyNs;
out.driftNsps = in.driftNsps;
out.driftUncertaintyNsps = in.driftUncertaintyNsps;
out.hwClockDiscontinuityCount = in.hwClockDiscontinuityCount;
}
static void convertGnssData(GnssMeasurementsNotification& in,
IGnssMeasurementCallback::GnssData& out)
{
out.measurementCount = in.count;
if (out.measurementCount > static_cast<uint32_t>(GnssMax::SVS_COUNT)) {
LOC_LOGW("%s]: Too many measurement %zd. Clamps to %d.",
__FUNCTION__, out.measurementCount, GnssMax::SVS_COUNT);
out.measurementCount = static_cast<uint32_t>(GnssMax::SVS_COUNT);
}
for (size_t i = 0; i < out.measurementCount; i++) {
convertGnssMeasurement(in.measurements[i], out.measurements[i]);
}
convertGnssClock(in.clock, out.clock);
}
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,75 @@
/* Copyright (c) 2017, 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 MEASUREMENT_API_CLINET_H
#define MEASUREMENT_API_CLINET_H
#include <android/hardware/gnss/1.0/IGnssMeasurement.h>
#include <android/hardware/gnss/1.0/IGnssMeasurementCallback.h>
#include <LocationAPIClientBase.h>
#include <hidl/Status.h>
namespace android {
namespace hardware {
namespace gnss {
namespace V1_0 {
namespace implementation {
using ::android::hardware::gnss::V1_0::IGnssMeasurement;
using ::android::sp;
class MeasurementAPIClient : public LocationAPIClientBase
{
public:
MeasurementAPIClient();
virtual ~MeasurementAPIClient();
MeasurementAPIClient(const MeasurementAPIClient&) = delete;
MeasurementAPIClient& operator=(const MeasurementAPIClient&) = delete;
// for GpsMeasurementInterface
Return<IGnssMeasurement::GnssMeasurementStatus> measurementSetCallback(
const sp<IGnssMeasurementCallback>& callback);
void measurementClose();
// callbacks we are interested in
void onGnssMeasurementsCb(GnssMeasurementsNotification gnssMeasurementsNotification) final;
private:
sp<IGnssMeasurementCallback> mGnssMeasurementCbIface;
bool mTracking;
};
} // namespace implementation
} // namespace V1_0
} // namespace gnss
} // namespace hardware
} // namespace android
#endif // MEASUREMENT_API_CLINET_H

31
gps/android/service.cpp Normal file
View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2017, The Linux Foundation. All rights reserved.
* Not a Contribution
*/
/*
* Copyright (C) 2016 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.
*/
#define LOG_TAG "android.hardware.gnss@1.0-service-qti"
#include <android/hardware/gnss/1.0/IGnss.h>
#include <hidl/LegacySupport.h>
using android::hardware::gnss::V1_0::IGnss;
using android::hardware::defaultPassthroughServiceImplementation;
int main() {
return defaultPassthroughServiceImplementation<IGnss>();
}

91
gps/configure.ac Normal file
View File

@@ -0,0 +1,91 @@
# configure.ac -- Autoconf script for gps loc_hal
#
# Process this file with autoconf to produce a configure script
# Requires autoconf tool later than 2.61
AC_PREREQ(2.61)
# Initialize the gps loc-hal package version 1.0.0
AC_INIT([loc-hal],1.0.0)
# Does not strictly follow GNU Coding standards
AM_INIT_AUTOMAKE([foreign])
# Disables auto rebuilding of configure, Makefile.ins
AM_MAINTAINER_MODE
# Verifies the --srcdir is correct by checking for the path
AC_CONFIG_SRCDIR([utils/loc_cfg.cpp])
# defines some macros variable to be included by source
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
AC_PROG_LIBTOOL
AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_AWK
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG
# Checks for libraries.
PKG_CHECK_MODULES([QMI], [qmi])
AC_SUBST([QMI_CFLAGS])
AC_SUBST([QMI_LIBS])
PKG_CHECK_MODULES([QMIF], [qmi-framework])
AC_SUBST([QMIF_CFLAGS])
AC_SUBST([QMIF_LIBS])
PKG_CHECK_MODULES([DATA], [data])
AC_SUBST([DATA_CFLAGS])
AC_SUBST([DATA_LIBS])
PKG_CHECK_MODULES([LOCPLA], [loc-pla])
AC_SUBST([LOCPLA_CFLAGS])
AC_SUBST([LOCPLA_LIBS])
PKG_CHECK_MODULES([GPSUTILS], [gps-utils])
AC_SUBST([GPSUTILS_CFLAGS])
AC_SUBST([GPSUTILS_LIBS])
AC_ARG_WITH([core_includes],
AC_HELP_STRING([--with-core-includes=@<:@dir@:>@],
[Specify the location of the core headers]),
[core_incdir=$withval],
with_core_includes=no)
if test "x$with_core_includes" != "xno"; then
CPPFLAGS="${CPPFLAGS} -I${core_incdir}"
fi
AC_SUBST([CPPFLAGS])
AC_ARG_WITH([glib],
AC_HELP_STRING([--with-glib],
[enable glib, building HLOS systems which use glib]))
if (test "x${with_glib}" = "xyes"); then
AC_DEFINE(ENABLE_USEGLIB, 1, [Define if HLOS systems uses glib])
PKG_CHECK_MODULES(GTHREAD, gthread-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GThread >= 2.16 is required))
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GLib >= 2.16 is required))
GLIB_CFLAGS="$GLIB_CFLAGS $GTHREAD_CFLAGS"
GLIB_LIBS="$GLIB_LIBS $GTHREAD_LIBS"
AC_SUBST(GLIB_CFLAGS)
AC_SUBST(GLIB_LIBS)
fi
AM_CONDITIONAL(USE_GLIB, test "x${with_glib}" = "xyes")
AC_CONFIG_FILES([ \
Makefile \
core/Makefile \
location/Makefile \
gnss/Makefile \
loc-hal.pc \
])
AC_OUTPUT

View File

@@ -1,3 +1,4 @@
ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),)
ifneq ($(BUILD_TINY_ANDROID),true)
LOCAL_PATH := $(call my-dir)
@@ -5,8 +6,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libloc_core
LOCAL_MODULE_OWNER := qcom
LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64
LOCAL_MODULE_TAGS := optional
ifeq ($(TARGET_DEVICE),apq8026_lw)
@@ -21,6 +22,7 @@ LOCAL_SHARED_LIBRARIES := \
libcutils \
libgps.utils \
libdl \
liblog \
libloc_pla
LOCAL_SRC_FILES += \
@@ -28,32 +30,40 @@ LOCAL_SRC_FILES += \
LocAdapterBase.cpp \
ContextBase.cpp \
LocDualContext.cpp \
loc_core_log.cpp
loc_core_log.cpp \
data-items/DataItemsFactoryProxy.cpp \
data-items/common/ClientIndex.cpp \
data-items/common/DataItemIndex.cpp \
data-items/common/IndexFactory.cpp \
SystemStatusOsObserver.cpp \
SystemStatus.cpp
LOCAL_CFLAGS += \
-fno-short-enums \
-D_ANDROID_
LOCAL_C_INCLUDES:= \
$(TARGET_OUT_HEADERS)/gps.utils \
$(TARGET_OUT_HEADERS)/libflp \
$(TARGET_OUT_HEADERS)/libloc_pla
$(LOCAL_PATH)/data-items \
$(LOCAL_PATH)/data-items/common \
$(LOCAL_PATH)/observer \
LOCAL_COPY_HEADERS_TO:= libloc_core/
LOCAL_COPY_HEADERS:= \
LocApiBase.h \
LocAdapterBase.h \
ContextBase.h \
LocDualContext.h \
LBSProxyBase.h \
UlpProxyBase.h \
gps_extended_c.h \
gps_extended.h \
loc_core_log.h \
LocAdapterProxyBase.h
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_PRELINK_MODULE := false
LOCAL_CFLAGS += $(GNSS_CFLAGS)
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libloc_core_headers
LOCAL_EXPORT_C_INCLUDE_DIRS := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/data-items \
$(LOCAL_PATH)/data-items/common \
$(LOCAL_PATH)/observer
include $(BUILD_HEADER_LIBRARY)
endif # not BUILD_TINY_ANDROID
endif # BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014,2016-2017 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
@@ -26,7 +26,7 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#define LOG_NDEBUG 0
#define LOG_TAG "LocSvc_CtxBase"
#include <dlfcn.h>
@@ -40,8 +40,114 @@
namespace loc_core {
loc_gps_cfg_s_type ContextBase::mGps_conf {0};
loc_sap_cfg_s_type ContextBase::mSap_conf {0};
loc_gps_cfg_s_type ContextBase::mGps_conf {};
loc_sap_cfg_s_type ContextBase::mSap_conf {};
const loc_param_s_type ContextBase::mGps_conf_table[] =
{
{"GPS_LOCK", &mGps_conf.GPS_LOCK, NULL, 'n'},
{"SUPL_VER", &mGps_conf.SUPL_VER, NULL, 'n'},
{"LPP_PROFILE", &mGps_conf.LPP_PROFILE, NULL, 'n'},
{"A_GLONASS_POS_PROTOCOL_SELECT", &mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT, NULL, 'n'},
{"LPPE_CP_TECHNOLOGY", &mGps_conf.LPPE_CP_TECHNOLOGY, NULL, 'n'},
{"LPPE_UP_TECHNOLOGY", &mGps_conf.LPPE_UP_TECHNOLOGY, NULL, 'n'},
{"AGPS_CERT_WRITABLE_MASK", &mGps_conf.AGPS_CERT_WRITABLE_MASK, NULL, 'n'},
{"SUPL_MODE", &mGps_conf.SUPL_MODE, NULL, 'n'},
{"SUPL_ES", &mGps_conf.SUPL_ES, NULL, 'n'},
{"INTERMEDIATE_POS", &mGps_conf.INTERMEDIATE_POS, NULL, 'n'},
{"ACCURACY_THRES", &mGps_conf.ACCURACY_THRES, NULL, 'n'},
{"NMEA_PROVIDER", &mGps_conf.NMEA_PROVIDER, NULL, 'n'},
{"CAPABILITIES", &mGps_conf.CAPABILITIES, NULL, 'n'},
{"XTRA_VERSION_CHECK", &mGps_conf.XTRA_VERSION_CHECK, NULL, 'n'},
{"XTRA_SERVER_1", &mGps_conf.XTRA_SERVER_1, NULL, 's'},
{"XTRA_SERVER_2", &mGps_conf.XTRA_SERVER_2, NULL, 's'},
{"XTRA_SERVER_3", &mGps_conf.XTRA_SERVER_3, NULL, 's'},
{"USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL", &mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL, NULL, 'n'},
{"AGPS_CONFIG_INJECT", &mGps_conf.AGPS_CONFIG_INJECT, NULL, 'n'},
{"EXTERNAL_DR_ENABLED", &mGps_conf.EXTERNAL_DR_ENABLED, NULL, 'n'},
};
const loc_param_s_type ContextBase::mSap_conf_table[] =
{
{"GYRO_BIAS_RANDOM_WALK", &mSap_conf.GYRO_BIAS_RANDOM_WALK, &mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID, 'f'},
{"ACCEL_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
{"ANGLE_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
{"RATE_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
{"VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY", &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY, &mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID, 'f'},
{"SENSOR_ACCEL_BATCHES_PER_SEC", &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC, NULL, 'n'},
{"SENSOR_ACCEL_SAMPLES_PER_BATCH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH, NULL, 'n'},
{"SENSOR_GYRO_BATCHES_PER_SEC", &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC, NULL, 'n'},
{"SENSOR_GYRO_SAMPLES_PER_BATCH", &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH, NULL, 'n'},
{"SENSOR_ACCEL_BATCHES_PER_SEC_HIGH", &mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH, NULL, 'n'},
{"SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH", &mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH, NULL, 'n'},
{"SENSOR_GYRO_BATCHES_PER_SEC_HIGH", &mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH, NULL, 'n'},
{"SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH", &mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH, NULL, 'n'},
{"SENSOR_CONTROL_MODE", &mSap_conf.SENSOR_CONTROL_MODE, NULL, 'n'},
{"SENSOR_USAGE", &mSap_conf.SENSOR_USAGE, NULL, 'n'},
{"SENSOR_ALGORITHM_CONFIG_MASK", &mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK, NULL, 'n'},
{"SENSOR_PROVIDER", &mSap_conf.SENSOR_PROVIDER, NULL, 'n'}
};
void ContextBase::readConfig()
{
/*Defaults for gps.conf*/
mGps_conf.INTERMEDIATE_POS = 0;
mGps_conf.ACCURACY_THRES = 0;
mGps_conf.NMEA_PROVIDER = 0;
mGps_conf.GPS_LOCK = 0;
mGps_conf.SUPL_VER = 0x10000;
mGps_conf.SUPL_MODE = 0x1;
mGps_conf.SUPL_ES = 0;
mGps_conf.CAPABILITIES = 0x7;
/* LTE Positioning Profile configuration is disable by default*/
mGps_conf.LPP_PROFILE = 0;
/*By default no positioning protocol is selected on A-GLONASS system*/
mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = 0;
/*XTRA version check is disabled by default*/
mGps_conf.XTRA_VERSION_CHECK=0;
/*Use emergency PDN by default*/
mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = 1;
/* By default no LPPe CP technology is enabled*/
mGps_conf.LPPE_CP_TECHNOLOGY = 0;
/* By default no LPPe UP technology is enabled*/
mGps_conf.LPPE_UP_TECHNOLOGY = 0;
/*Defaults for sap.conf*/
mSap_conf.GYRO_BIAS_RANDOM_WALK = 0;
mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC = 2;
mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH = 5;
mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC = 2;
mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH = 5;
mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH = 4;
mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH = 25;
mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH = 4;
mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH = 25;
mSap_conf.SENSOR_CONTROL_MODE = 0; /* AUTO */
mSap_conf.SENSOR_USAGE = 0; /* Enabled */
mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK = 0; /* INS Disabled = FALSE*/
/* Values MUST be set by OEMs in configuration for sensor-assisted
navigation to work. There are NO default values */
mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY = 0;
mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY = 0;
mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY = 0;
mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID = 0;
mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID = 0;
/* default provider is SSC */
mSap_conf.SENSOR_PROVIDER = 1;
/* None of the 10 slots for agps certificates are writable by default */
mGps_conf.AGPS_CERT_WRITABLE_MASK = 0;
/* inject supl config to modem with config values from config.xml or gps.conf, default 1 */
mGps_conf.AGPS_CONFIG_INJECT = 1;
UTIL_READ_CONF(LOC_PATH_GPS_CONF, mGps_conf_table);
UTIL_READ_CONF(LOC_PATH_SAP_CONF, mSap_conf_table);
}
uint32_t ContextBase::getCarrierCapabilities() {
#define carrierMSA (uint32_t)0x2
@@ -88,31 +194,35 @@ LocApiBase* ContextBase::createLocApi(LOC_API_ADAPTER_EVENT_MASK_T exMask)
{
LocApiBase* locApi = NULL;
if (NULL == (locApi = mLBSProxy->getLocApi(mMsgTask, exMask, this))) {
void *handle = NULL;
//try to see if LocApiV02 is present
if ((handle = dlopen("libloc_api_v02.so", RTLD_NOW)) != NULL) {
LOC_LOGD("%s:%d]: libloc_api_v02.so is present", __func__, __LINE__);
getLocApi_t* getter = (getLocApi_t*) dlsym(handle, "getLocApi");
if (getter != NULL) {
LOC_LOGD("%s:%d]: getter is not NULL for LocApiV02", __func__,
__LINE__);
locApi = (*getter)(mMsgTask, exMask, this);
}
}
// only RPC is the option now
else {
LOC_LOGD("%s:%d]: libloc_api_v02.so is NOT present. Trying RPC",
__func__, __LINE__);
handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW);
if (NULL != handle) {
// Check the target
if (TARGET_NO_GNSS != loc_get_target()){
if (NULL == (locApi = mLBSProxy->getLocApi(mMsgTask, exMask, this))) {
void *handle = NULL;
//try to see if LocApiV02 is present
if ((handle = dlopen("libloc_api_v02.so", RTLD_NOW)) != NULL) {
LOC_LOGD("%s:%d]: libloc_api_v02.so is present", __func__, __LINE__);
getLocApi_t* getter = (getLocApi_t*) dlsym(handle, "getLocApi");
if (NULL != getter) {
LOC_LOGD("%s:%d]: getter is not NULL in RPC", __func__,
if (getter != NULL) {
LOC_LOGD("%s:%d]: getter is not NULL for LocApiV02", __func__,
__LINE__);
locApi = (*getter)(mMsgTask, exMask, this);
}
}
// only RPC is the option now
else {
LOC_LOGD("%s:%d]: libloc_api_v02.so is NOT present. Trying RPC",
__func__, __LINE__);
handle = dlopen("libloc_api-rpc-qc.so", RTLD_NOW);
if (NULL != handle) {
getLocApi_t* getter = (getLocApi_t*) dlsym(handle, "getLocApi");
if (NULL != getter) {
LOC_LOGD("%s:%d]: getter is not NULL in RPC", __func__,
__LINE__);
locApi = (*getter)(mMsgTask, exMask, this);
}
}
}
}
}

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -34,6 +34,7 @@
#include <MsgTask.h>
#include <LocApiBase.h>
#include <LBSProxyBase.h>
#include <loc_cfg.h>
#define MAX_XTRA_SERVER_URL_LENGTH 256
@@ -105,6 +106,8 @@ class LocAdapterBase;
class ContextBase {
static LBSProxyBase* getLBSProxy(const char* libName);
LocApiBase* createLocApi(LOC_API_ADAPTER_EVENT_MASK_T excludedMask);
static const loc_param_s_type mGps_conf_table[];
static const loc_param_s_type mSap_conf_table[];
protected:
const LBSProxyBase* mLBSProxy;
const MsgTask* mMsgTask;
@@ -135,6 +138,7 @@ public:
static loc_gps_cfg_s_type mGps_conf;
static loc_sap_cfg_s_type mSap_conf;
void readConfig();
static uint32_t getCarrierCapabilities();
};

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2016-2017The 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
@@ -26,7 +26,7 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#define LOG_NDEBUG 0
#define LOG_TAG "LocSvc_LocAdapterBase"
#include <dlfcn.h>
@@ -50,6 +50,16 @@ LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask,
mLocApi->addAdapter(this);
}
uint32_t LocAdapterBase::mSessionIdCounter(1);
uint32_t LocAdapterBase::generateSessionId()
{
if (++mSessionIdCounter == 0xFFFFFFFF)
mSessionIdCounter = 1;
return mSessionIdCounter;
}
void LocAdapterBase::handleEngineUpEvent()
{
if (mLocAdapterProxyBase) {
@@ -65,46 +75,45 @@ void LocAdapterBase::handleEngineDownEvent()
}
void LocAdapterBase::
reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask) {
if (mLocAdapterProxyBase == NULL ||
!mLocAdapterProxyBase->reportPosition(location,
locationExtended,
status,
loc_technology_mask)) {
reportPositionEvent(const UlpLocation& location,
const GpsLocationExtended& locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask,
bool /*fromUlp*/) {
if (mLocAdapterProxyBase != NULL) {
mLocAdapterProxyBase->reportPositionEvent((UlpLocation&)location,
(GpsLocationExtended&)locationExtended,
status,
loc_technology_mask);
} else {
DEFAULT_IMPL()
}
}
void LocAdapterBase::
reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt)
reportSvEvent(const GnssSvNotification& /*svNotify*/, bool /*fromUlp*/)
DEFAULT_IMPL()
void LocAdapterBase::
reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet)
reportSvMeasurementEvent(GnssSvMeasurementSet &/*svMeasurementSet*/)
DEFAULT_IMPL()
void LocAdapterBase::
reportSvPolynomial(GnssSvPolynomial &svPolynomial)
reportSvPolynomialEvent(GnssSvPolynomial &/*svPolynomial*/)
DEFAULT_IMPL()
void LocAdapterBase::
reportStatus(GpsStatusValue status)
reportStatus(LocGpsStatusValue /*status*/)
DEFAULT_IMPL()
void LocAdapterBase::
reportNmea(const char* nmea, int length)
reportNmeaEvent(const char* /*nmea*/, size_t /*length*/, bool /*fromUlp*/)
DEFAULT_IMPL()
bool LocAdapterBase::
reportXtraServer(const char* url1, const char* url2,
const char* url3, const int maxlength)
reportXtraServer(const char* /*url1*/, const char* /*url2*/,
const char* /*url3*/, const int /*maxlength*/)
DEFAULT_IMPL(false)
bool LocAdapterBase::
@@ -120,15 +129,15 @@ bool LocAdapterBase::
DEFAULT_IMPL(false)
bool LocAdapterBase::
requestATL(int connHandle, AGpsType agps_type)
requestATL(int /*connHandle*/, LocAGpsType /*agps_type*/)
DEFAULT_IMPL(false)
bool LocAdapterBase::
releaseATL(int connHandle)
releaseATL(int /*connHandle*/)
DEFAULT_IMPL(false)
bool LocAdapterBase::
requestSuplES(int connHandle)
requestSuplES(int /*connHandle*/)
DEFAULT_IMPL(false)
bool LocAdapterBase::
@@ -140,10 +149,16 @@ bool LocAdapterBase::
DEFAULT_IMPL(false)
bool LocAdapterBase::
requestNiNotify(GpsNiNotification &notify, const void* data)
requestNiNotifyEvent(const GnssNiNotification &/*notify*/, const void* /*data*/)
DEFAULT_IMPL(false)
void LocAdapterBase::
reportGnssMeasurementData(GnssData &gnssMeasurementData)
reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& /*measurements*/,
int /*msInWeek*/)
DEFAULT_IMPL()
bool LocAdapterBase::
reportWwanZppFix(LocGpsLocation &/*zppLoc*/)
DEFAULT_IMPL(false)
} // namespace loc_core

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014,2016 The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2016-2017 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
@@ -32,19 +32,39 @@
#include <gps_extended.h>
#include <UlpProxyBase.h>
#include <ContextBase.h>
#include <LocationAPI.h>
#include <map>
typedef struct LocationSessionKey {
LocationAPI* client;
uint32_t id;
inline LocationSessionKey(LocationAPI* _client, uint32_t _id) :
client(_client), id(_id) {}
} LocationSessionKey;
inline bool operator <(LocationSessionKey const& left, LocationSessionKey const& right) {
return left.id < right.id || (left.id == right.id && left.client < right.client);
}
inline bool operator ==(LocationSessionKey const& left, LocationSessionKey const& right) {
return left.id == right.id && left.client == right.client;
}
inline bool operator !=(LocationSessionKey const& left, LocationSessionKey const& right) {
return left.id != right.id || left.client != right.client;
}
typedef std::map<LocationSessionKey, LocationOptions> LocationSessionMap;
namespace loc_core {
class LocAdapterProxyBase;
class LocAdapterBase {
private:
static uint32_t mSessionIdCounter;
protected:
LOC_API_ADAPTER_EVENT_MASK_T mEvtMask;
ContextBase* mContext;
LocApiBase* mLocApi;
LocAdapterProxyBase* mLocAdapterProxyBase;
const MsgTask* mMsgTask;
inline LocAdapterBase(const MsgTask* msgTask) :
mEvtMask(0), mContext(NULL), mLocApi(NULL),
mLocAdapterProxyBase(NULL), mMsgTask(msgTask) {}
@@ -70,11 +90,19 @@ public:
}
inline void updateEvtMask(LOC_API_ADAPTER_EVENT_MASK_T event,
loc_registration_mask_status isEnabled)
loc_registration_mask_status status)
{
mEvtMask =
isEnabled == LOC_REGISTRATION_MASK_ENABLED ? (mEvtMask|event):(mEvtMask&~event);
switch(status) {
case (LOC_REGISTRATION_MASK_ENABLED):
mEvtMask = mEvtMask | event;
break;
case (LOC_REGISTRATION_MASK_DISABLED):
mEvtMask = mEvtMask &~ event;
break;
case (LOC_REGISTRATION_MASK_SET):
mEvtMask = event;
break;
}
mLocApi->updateEvtMask();
}
@@ -82,48 +110,49 @@ public:
return mLocApi->isFeatureSupported(featureVal);
}
uint32_t generateSessionId();
// This will be overridden by the individual adapters
// if necessary.
inline virtual void setUlpProxy(UlpProxyBase* ulp) {
inline virtual void setUlpProxyCommand(UlpProxyBase* ulp) {
(void)ulp;
}
virtual void handleEngineUpEvent();
virtual void handleEngineDownEvent();
inline virtual void setPositionModeInt(LocPosMode& posMode) {
inline virtual void setPositionModeCommand(LocPosMode& posMode) {
(void)posMode;
}
virtual void startFixInt() {}
virtual void stopFixInt() {}
virtual void getZppInt() {}
virtual void reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask);
virtual void reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt);
virtual void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
virtual void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
virtual void reportStatus(GpsStatusValue status);
virtual void reportNmea(const char* nmea, int length);
virtual void startTrackingCommand() {}
virtual void stopTrackingCommand() {}
virtual void getZppCommand() {}
virtual void reportPositionEvent(const UlpLocation& location,
const GpsLocationExtended& locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask,
bool fromUlp=false);
virtual void reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp=false);
virtual void reportNmeaEvent(const char* nmea, size_t length, bool fromUlp=false);
virtual void reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet);
virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
virtual void reportStatus(LocGpsStatusValue status);
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 requestATL(int connHandle, LocAGpsType agps_type);
virtual bool releaseATL(int connHandle);
virtual bool requestSuplES(int connHandle);
virtual bool reportDataCallOpened();
virtual bool reportDataCallClosed();
virtual bool requestNiNotify(GpsNiNotification &notify,
const void* data);
virtual bool requestNiNotifyEvent(const GnssNiNotification &notify, const void* data);
inline virtual bool isInSession() { return false; }
ContextBase* getContext() const { return mContext; }
virtual void reportGnssMeasurementData(GnssData &gnssMeasurementData);
virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements,
int msInWeek);
virtual bool reportWwanZppFix(LocGpsLocation &zppLoc);
};
} // namespace loc_core

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2014 The Linux Foundation. All rights reserved.
/* Copyright (c) 2014, 2016-2017 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
@@ -51,22 +51,25 @@ protected:
mLocAdapterBase->updateEvtMask(event,isEnabled);
}
inline uint32_t generateSessionId() {
return mLocAdapterBase->generateSessionId();
}
public:
inline ContextBase* getContext() const {
return mLocAdapterBase->getContext();
}
inline virtual void handleEngineUpEvent() {};
inline virtual void handleEngineDownEvent() {};
inline virtual bool reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask) {
inline virtual void reportPositionEvent(UlpLocation &location,
GpsLocationExtended &locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask) {
(void)location;
(void)locationExtended;
(void)status;
(void)loc_technology_mask;
return false;
}
};

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014,2016 The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2016-2017 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
@@ -26,10 +26,11 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#define LOG_NDEBUG 0 //Define to enable LOGV
#define LOG_TAG "LocSvc_LocApiBase"
#include <dlfcn.h>
#include <inttypes.h>
#include <LocApiBase.h>
#include <LocAdapterBase.h>
#include <platform_lib_log_util.h>
@@ -96,10 +97,10 @@ struct LocSsrMsg : public LocMsg {
mLocApi->close();
mLocApi->open(mLocApi->getEvtMask());
}
inline void locallog() {
inline void locallog() const {
LOC_LOGV("LocSsrMsg");
}
inline virtual void log() {
inline virtual void log() const {
locallog();
}
};
@@ -116,11 +117,11 @@ struct LocOpenMsg : public LocMsg {
inline virtual void proc() const {
mLocApi->open(mMask);
}
inline void locallog() {
inline void locallog() const {
LOC_LOGV("%s:%d]: LocOpen Mask: %x\n",
__func__, __LINE__, mMask);
}
inline virtual void log() {
inline virtual void log() const {
locallog();
}
};
@@ -128,8 +129,8 @@ struct LocOpenMsg : public LocMsg {
LocApiBase::LocApiBase(const MsgTask* msgTask,
LOC_API_ADAPTER_EVENT_MASK_T excludedMask,
ContextBase* context) :
mExcludedMask(excludedMask), mMsgTask(msgTask),
mMask(0), mSupportedMsg(0), mContext(context)
mMsgTask(msgTask), mContext(context), mSupportedMsg(0),
mMask(0), mExcludedMask(excludedMask)
{
memset(mLocAdapters, 0, sizeof(mLocAdapters));
memset(mFeaturesSupported, 0, sizeof(mFeaturesSupported));
@@ -227,65 +228,70 @@ void LocApiBase::handleEngineDownEvent()
TO_ALL_LOCADAPTERS(mLocAdapters[i]->handleEngineDownEvent());
}
void LocApiBase::reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
void LocApiBase::reportPosition(UlpLocation& location,
GpsLocationExtended& locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask)
{
// print the location info before delivering
LOC_LOGV("flags: %d\n source: %d\n latitude: %f\n longitude: %f\n "
LOC_LOGD("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",
"timestamp: %" PRId64 "\n rawDataSize: %d\n rawData: %p\n "
"Session status: %d\n Technology mask: %u\n "
"SV used in fix (gps/glo/bds/gal/qzss) : \
(%" PRIx64 "/%" PRIx64 "/%" PRIx64 "/%" PRIx64 "/%" PRIx64 ")",
location.gpsLocation.flags, location.position_source,
location.gpsLocation.latitude, location.gpsLocation.longitude,
location.gpsLocation.altitude, location.gpsLocation.speed,
location.gpsLocation.bearing, location.gpsLocation.accuracy,
location.gpsLocation.timestamp, location.rawDataSize,
location.rawData, status, loc_technology_mask);
location.rawData, status, loc_technology_mask,
locationExtended.gnss_sv_used_ids.gps_sv_used_ids_mask,
locationExtended.gnss_sv_used_ids.glo_sv_used_ids_mask,
locationExtended.gnss_sv_used_ids.bds_sv_used_ids_mask,
locationExtended.gnss_sv_used_ids.gal_sv_used_ids_mask,
locationExtended.gnss_sv_used_ids.qzss_sv_used_ids_mask);
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(
mLocAdapters[i]->reportPosition(location,
locationExtended,
locationExt,
status,
loc_technology_mask)
mLocAdapters[i]->reportPositionEvent(location, locationExtended,
status, loc_technology_mask)
);
}
void LocApiBase::reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt)
void LocApiBase::reportWwanZppFix(LocGpsLocation &zppLoc)
{
// loop through adapters, and deliver to the first handling adapter.
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportWwanZppFix(zppLoc));
}
void LocApiBase::reportSv(GnssSvNotification& svNotify)
{
const char* constellationString[] = { "Unknown", "GPS", "SBAS", "GLONASS",
"QZSS", "BEIDOU", "GALILEO" };
// print the SV info before delivering
LOC_LOGV("num sv: %d\n"
LOC_LOGV("num sv: %zu\n"
" sv: constellation svid cN0"
" elevation azimuth flags",
svStatus.num_svs);
for (int i = 0; i < svStatus.num_svs && i < GNSS_MAX_SVS; i++) {
if (svStatus.gnss_sv_list[i].constellation >
svNotify.count);
for (size_t i = 0; i < svNotify.count && i < LOC_GNSS_MAX_SVS; i++) {
if (svNotify.gnssSvs[i].type >
sizeof(constellationString) / sizeof(constellationString[0]) - 1) {
svStatus.gnss_sv_list[i].constellation = 0;
svNotify.gnssSvs[i].type = GNSS_SV_TYPE_UNKNOWN;
}
LOC_LOGV(" %03d: %*s %02d %f %f %f 0x%02X",
LOC_LOGV(" %03zu: %*s %02d %f %f %f 0x%02X",
i,
13,
constellationString[svStatus.gnss_sv_list[i].constellation],
svStatus.gnss_sv_list[i].svid,
svStatus.gnss_sv_list[i].c_n0_dbhz,
svStatus.gnss_sv_list[i].elevation,
svStatus.gnss_sv_list[i].azimuth,
svStatus.gnss_sv_list[i].flags);
constellationString[svNotify.gnssSvs[i].type],
svNotify.gnssSvs[i].svId,
svNotify.gnssSvs[i].cN0Dbhz,
svNotify.gnssSvs[i].elevation,
svNotify.gnssSvs[i].azimuth,
svNotify.gnssSvs[i].gnssSvOptionsMask);
}
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(
mLocAdapters[i]->reportSv(svStatus,
locationExtended,
svExt)
mLocAdapters[i]->reportSvEvent(svNotify)
);
}
@@ -293,7 +299,7 @@ void LocApiBase::reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet)
{
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(
mLocAdapters[i]->reportSvMeasurement(svMeasurementSet)
mLocAdapters[i]->reportSvMeasurementEvent(svMeasurementSet)
);
}
@@ -301,11 +307,11 @@ void LocApiBase::reportSvPolynomial(GnssSvPolynomial &svPolynomial)
{
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(
mLocAdapters[i]->reportSvPolynomial(svPolynomial)
mLocAdapters[i]->reportSvPolynomialEvent(svPolynomial)
);
}
void LocApiBase::reportStatus(GpsStatusValue status)
void LocApiBase::reportStatus(LocGpsStatusValue status)
{
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportStatus(status));
@@ -314,7 +320,7 @@ void LocApiBase::reportStatus(GpsStatusValue 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));
TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportNmeaEvent(nmea, length));
}
void LocApiBase::reportXtraServer(const char* url1, const char* url2,
@@ -343,7 +349,7 @@ void LocApiBase::requestLocation()
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestLocation());
}
void LocApiBase::requestATL(int connHandle, AGpsType agps_type)
void LocApiBase::requestATL(int connHandle, LocAGpsType agps_type)
{
// loop through adapters, and deliver to the first handling adapter.
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestATL(connHandle, agps_type));
@@ -373,10 +379,10 @@ void LocApiBase::reportDataCallClosed()
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->reportDataCallClosed());
}
void LocApiBase::requestNiNotify(GpsNiNotification &notify, const void* data)
void LocApiBase::requestNiNotify(GnssNiNotification &notify, const void* data)
{
// loop through adapters, and deliver to the first handling adapter.
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotify(notify, data));
TO_1ST_HANDLING_LOCADAPTERS(mLocAdapters[i]->requestNiNotifyEvent(notify, data));
}
void LocApiBase::saveSupportedMsgList(uint64_t supportedMsgList)
@@ -395,14 +401,15 @@ void* LocApiBase :: getSibling()
LocApiProxyBase* LocApiBase :: getLocApiProxy()
DEFAULT_IMPL(NULL)
void LocApiBase::reportGnssMeasurementData(GnssData &gnssMeasurementData)
void LocApiBase::reportGnssMeasurementData(GnssMeasurementsNotification& measurements,
int msInWeek)
{
// loop through adapters, and deliver to all adapters.
TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementData(gnssMeasurementData));
TO_ALL_LOCADAPTERS(mLocAdapters[i]->reportGnssMeasurementDataEvent(measurements, msInWeek));
}
enum loc_api_adapter_err LocApiBase::
open(LOC_API_ADAPTER_EVENT_MASK_T mask)
open(LOC_API_ADAPTER_EVENT_MASK_T /*mask*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
@@ -410,35 +417,35 @@ enum loc_api_adapter_err LocApiBase::
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
startFix(const LocPosMode& posMode)
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)
LocationError LocApiBase::
deleteAidingData(const GnssAidingData& /*data*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
deleteAidingData(GpsAidingData f)
enableData(int /*enable*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
enableData(int enable)
setAPN(char* /*apn*/, int /*len*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setAPN(char* apn, int len)
injectPosition(double /*latitude*/, double /*longitude*/, float /*accuracy*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
injectPosition(double latitude, double longitude, float accuracy)
setTime(LocGpsUtcTime /*time*/, int64_t /*timeReference*/, int /*uncertainty*/)
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)
setXtraData(char* /*data*/, int /*length*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
@@ -446,104 +453,108 @@ enum loc_api_adapter_err LocApiBase::
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)
atlOpenStatus(int /*handle*/, int /*is_succ*/, char* /*apn*/,
AGpsBearerType /*bear*/, LocAGpsType /*agpsType*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
atlCloseStatus(int handle, int is_succ)
atlCloseStatus(int /*handle*/, int /*is_succ*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setPositionMode(const LocPosMode& posMode)
setPositionMode(const LocPosMode& /*posMode*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
LocationError LocApiBase::
setServer(const char* /*url*/, int /*len*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
LocationError LocApiBase::
setServer(unsigned int /*ip*/, int /*port*/, LocServerType /*type*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
LocationError LocApiBase::
informNiResponse(GnssNiResponse /*userResponse*/, const void* /*passThroughData*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
LocationError LocApiBase::
setSUPLVersion(GnssConfigSuplVersion /*version*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setNMEATypes (uint32_t /*typesMask*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
LocationError LocApiBase::
setLPPConfig(GnssConfigLppProfile /*profile*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setSensorControlConfig(int /*sensorUsage*/,
int /*sensorProvider*/)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setServer(const char* url, int len)
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::
setServer(unsigned int ip, int port,
LocServerType type)
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)
LocationError LocApiBase::
setAGLONASSProtocol(GnssConfigAGlonassPositionProtocolMask /*aGlonassProtocol*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
LocationError LocApiBase::
setLPPeProtocolCp(GnssConfigLppeControlPlaneMask /*lppeCP*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
LocationError LocApiBase::
setLPPeProtocolUp(GnssConfigLppeUserPlaneMask /*lppeUP*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
getWwanZppFix()
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::
setNMEATypes (uint32_t typesMask)
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,
int sensorProvider)
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::
setAGLONASSProtocol(unsigned long aGlonassProtocol)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
getWwanZppFix(GpsLocation& zppLoc)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
enum loc_api_adapter_err LocApiBase::
getBestAvailableZppFix(GpsLocation& zppLoc)
getBestAvailableZppFix(LocGpsLocation& zppLoc)
{
memset(&zppLoc, 0, sizeof(zppLoc));
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
}
enum loc_api_adapter_err LocApiBase::
getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask)
getBestAvailableZppFix(LocGpsLocation & zppLoc, GpsLocationExtended & locationExtended,
LocPosTechMask & tech_mask)
{
memset(&zppLoc, 0, sizeof(zppLoc));
memset(&tech_mask, 0, sizeof(tech_mask));
memset(&locationExtended, 0, sizeof (locationExtended));
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
}
int LocApiBase::
initDataServiceClient()
initDataServiceClient(bool /*isDueToSsr*/)
DEFAULT_IMPL(-1)
int LocApiBase::
@@ -558,23 +569,27 @@ void LocApiBase::
closeDataCall()
DEFAULT_IMPL()
int LocApiBase::
setGpsLock(LOC_GPS_LOCK_MASK lock)
DEFAULT_IMPL(-1)
void LocApiBase::
releaseDataServiceClient()
DEFAULT_IMPL()
LocationError LocApiBase::
setGpsLock(GnssConfigGpsLock /*lock*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
void LocApiBase::
installAGpsCert(const DerEncodedCertificate* pData,
size_t length,
uint32_t slotBitMask)
installAGpsCert(const LocDerEncodedCertificate* /*pData*/,
size_t /*length*/,
uint32_t /*slotBitMask*/)
DEFAULT_IMPL()
int LocApiBase::
getGpsLock()
DEFAULT_IMPL(-1)
enum loc_api_adapter_err LocApiBase::
setXtraVersionCheck(enum xtra_version_check check)
DEFAULT_IMPL(LOC_API_ADAPTER_ERR_SUCCESS)
LocationError LocApiBase::
setXtraVersionCheck(uint32_t /*check*/)
DEFAULT_IMPL(LOCATION_ERROR_SUCCESS)
bool LocApiBase::
gnssConstellationConfig()

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014, 2016 The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2016-2017 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
@@ -32,6 +32,7 @@
#include <stddef.h>
#include <ctype.h>
#include <gps_extended.h>
#include <LocationAPI.h>
#include <MsgTask.h>
#include <platform_lib_log_util.h>
@@ -102,40 +103,37 @@ public:
inline void sendMsg(const LocMsg* msg) const {
mMsgTask->sendMsg(msg);
}
void addAdapter(LocAdapterBase* adapter);
void removeAdapter(LocAdapterBase* adapter);
// upward calls
void handleEngineUpEvent();
void handleEngineDownEvent();
void reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
void reportPosition(UlpLocation& location,
GpsLocationExtended& locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask =
LOC_POS_TECH_MASK_DEFAULT);
void reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt);
void reportSv(GnssSvNotification& svNotify);
void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
void reportStatus(GpsStatusValue status);
void reportStatus(LocGpsStatusValue status);
void reportNmea(const char* nmea, int length);
void reportXtraServer(const char* url1, const char* url2,
const char* url3, const int maxlength);
void requestXtraData();
void requestTime();
void requestLocation();
void requestATL(int connHandle, AGpsType agps_type);
void requestATL(int connHandle, LocAGpsType agps_type);
void releaseATL(int connHandle);
void requestSuplES(int connHandle);
void reportDataCallOpened();
void reportDataCallClosed();
void requestNiNotify(GpsNiNotification &notify, const void* data);
void requestNiNotify(GnssNiNotification &notify, const void* data);
void saveSupportedMsgList(uint64_t supportedMsgList);
void reportGnssMeasurementData(GnssData &gnssMeasurementData);
void reportGnssMeasurementData(GnssMeasurementsNotification& measurements, int msInWeek);
void saveSupportedFeatureList(uint8_t *featureList);
void reportWwanZppFix(LocGpsLocation &zppLoc);
// downward calls
// All below functions are to be defined by adapter specific modules:
@@ -147,8 +145,8 @@ public:
startFix(const LocPosMode& posMode);
virtual enum loc_api_adapter_err
stopFix();
virtual enum loc_api_adapter_err
deleteAidingData(GpsAidingData f);
virtual LocationError
deleteAidingData(const GnssAidingData& data);
virtual enum loc_api_adapter_err
enableData(int enable);
virtual enum loc_api_adapter_err
@@ -156,30 +154,28 @@ public:
virtual enum loc_api_adapter_err
injectPosition(double latitude, double longitude, float accuracy);
virtual enum loc_api_adapter_err
setTime(GpsUtcTime time, int64_t timeReference, int uncertainty);
setTime(LocGpsUtcTime time, int64_t timeReference, int uncertainty);
virtual enum loc_api_adapter_err
setXtraData(char* data, int length);
virtual enum loc_api_adapter_err
requestXtraServer();
virtual enum loc_api_adapter_err
atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, AGpsType agpsType);
atlOpenStatus(int handle, int is_succ, char* apn, AGpsBearerType bear, LocAGpsType agpsType);
virtual enum loc_api_adapter_err
atlCloseStatus(int handle, int is_succ);
virtual enum loc_api_adapter_err
setPositionMode(const LocPosMode& posMode);
virtual enum loc_api_adapter_err
virtual LocationError
setServer(const char* url, int len);
virtual enum loc_api_adapter_err
virtual LocationError
setServer(unsigned int ip, int port,
LocServerType type);
virtual enum loc_api_adapter_err
informNiResponse(GpsUserResponseType userResponse, const void* passThroughData);
virtual enum loc_api_adapter_err
setSUPLVersion(uint32_t version);
virtual LocationError
informNiResponse(GnssNiResponse userResponse, const void* passThroughData);
virtual LocationError setSUPLVersion(GnssConfigSuplVersion version);
virtual enum loc_api_adapter_err
setNMEATypes (uint32_t typesMask);
virtual enum loc_api_adapter_err
setLPPConfig(uint32_t profile);
virtual LocationError setLPPConfig(GnssConfigLppProfile profile);
virtual enum loc_api_adapter_err
setSensorControlConfig(int sensorUsage, int sensorProvider);
virtual enum loc_api_adapter_err
@@ -204,21 +200,23 @@ public:
int gyroSamplesPerBatchHigh,
int gyroBatchesPerSecHigh,
int algorithmConfig);
virtual LocationError
setAGLONASSProtocol(GnssConfigAGlonassPositionProtocolMask aGlonassProtocol);
virtual LocationError setLPPeProtocolCp(GnssConfigLppeControlPlaneMask lppeCP);
virtual LocationError setLPPeProtocolUp(GnssConfigLppeUserPlaneMask lppeUP);
virtual enum loc_api_adapter_err
setAGLONASSProtocol(unsigned long aGlonassProtocol);
getWwanZppFix();
virtual enum loc_api_adapter_err
setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP);
getBestAvailableZppFix(LocGpsLocation & zppLoc);
virtual enum loc_api_adapter_err
getWwanZppFix(GpsLocation & zppLoc);
virtual enum loc_api_adapter_err
getBestAvailableZppFix(GpsLocation & zppLoc);
virtual enum loc_api_adapter_err
getBestAvailableZppFix(GpsLocation & zppLoc, LocPosTechMask & tech_mask);
virtual int initDataServiceClient();
getBestAvailableZppFix(LocGpsLocation & zppLoc, GpsLocationExtended & locationExtended,
LocPosTechMask & tech_mask);
virtual int initDataServiceClient(bool isDueToSsr);
virtual int openAndStartDataCall();
virtual void stopDataCall();
virtual void closeDataCall();
virtual void installAGpsCert(const DerEncodedCertificate* pData,
virtual void releaseDataServiceClient();
virtual void installAGpsCert(const LocDerEncodedCertificate* pData,
size_t length,
uint32_t slotBitMask);
inline virtual void setInSession(bool inSession) {
@@ -236,15 +234,10 @@ public:
return (messageChecker & mSupportedMsg) == messageChecker;
}
}
void updateEvtMask();
/*Values for lock
1 = Do not lock any position sessions
2 = Lock MI position sessions
3 = Lock MT position sessions
4 = Lock all position sessions
*/
virtual int setGpsLock(LOC_GPS_LOCK_MASK lock);
virtual LocationError setGpsLock(GnssConfigGpsLock lock);
/*
Returns
Current value of GPS Lock on success
@@ -252,8 +245,7 @@ public:
*/
virtual int getGpsLock(void);
virtual enum loc_api_adapter_err setXtraVersionCheck(enum xtra_version_check check);
virtual LocationError setXtraVersionCheck(uint32_t check);
/*
Check if the modem support the service
*/

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2016-2017 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
@@ -26,7 +26,7 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define LOG_NDDEBUG 0
#define LOG_NDEBUG 0
#define LOG_TAG "LocSvc_DualCtx"
#include <cutils/sched_policy.h>
@@ -44,8 +44,7 @@ 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_SATELLITE_REPORT |
LOC_API_ADAPTER_BIT_NMEA_1HZ_REPORT |
LOC_API_ADAPTER_BIT_NMEA_POSITION_REPORT |
LOC_API_ADAPTER_BIT_IOCTL_REPORT |

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2014, 2017 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are

61
gps/core/Makefile.am Normal file
View File

@@ -0,0 +1,61 @@
AM_CFLAGS = -I./ \
-I../utils \
-I../location \
$(LOCPLA_CFLAGS) \
$(GPSUTILS_CFLAGS) \
-I$(WORKSPACE)/gps-noship/flp \
-D__func__=__PRETTY_FUNCTION__ \
-fno-short-enums \
-std=c++11
libloc_core_la_h_sources = \
LocApiBase.h \
LocAdapterBase.h \
ContextBase.h \
LocDualContext.h \
LBSProxyBase.h \
UlpProxyBase.h \
loc_core_log.h \
LocAdapterProxyBase.h \
data-items/DataItemId.h \
data-items/IDataItemCore.h \
observer/IDataItemObserver.h \
observer/IDataItemSubscription.h \
observer/IFrameworkActionReq.h \
observer/IOsObserver.h \
SystemStatusOsObserver.h \
SystemStatus.h
libloc_core_la_c_sources = \
LocApiBase.cpp \
LocAdapterBase.cpp \
ContextBase.cpp \
LocDualContext.cpp \
loc_core_log.cpp \
data-items/DataItemsFactoryProxy.cpp \
data-items/common/ClientIndex.cpp \
data-items/common/DataItemIndex.cpp \
data-items/common/IndexFactory.cpp \
SystemStatusOsObserver.cpp \
SystemStatus.cpp
library_includedir = $(pkgincludedir)/core
library_include_HEADERS = $(libloc_core_la_h_sources)
libloc_core_la_SOURCES = $(libloc_core_la_c_sources)
if USE_GLIB
libloc_core_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
libloc_core_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
libloc_core_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
libloc_core_la_CFLAGS = $(AM_CFLAGS)
libloc_core_la_LDFLAGS = -Wl,-z,defs -lpthread -shared -version-info 1:0:0
libloc_core_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
endif
libloc_core_la_LIBADD = -lstdc++ -ldl $(LOCPLA_LIBS) $(GPSUTILS_LIBS)
#Create and Install libraries
lib_LTLIBRARIES = libloc_core.la

1788
gps/core/SystemStatus.cpp Normal file

File diff suppressed because it is too large Load Diff

644
gps/core/SystemStatus.h Normal file
View File

@@ -0,0 +1,644 @@
/* Copyright (c) 2017, 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 __SYSTEM_STATUS__
#define __SYSTEM_STATUS__
#include <stdint.h>
#include <string>
#include <vector>
#include <platform_lib_log_util.h>
#include <MsgTask.h>
#include <IDataItemCore.h>
#include <IOsObserver.h>
#include <SystemStatusOsObserver.h>
#include <gps_extended_c.h>
#define GPS_MIN (1) //1-32
#define SBAS_MIN (33)
#define GLO_MIN (65) //65-88
#define QZSS_MIN (193) //193-197
#define BDS_MIN (201) //201-237
#define GAL_MIN (301) //301-336
#define GPS_NUM (32)
#define SBAS_NUM (32)
#define GLO_NUM (24)
#define QZSS_NUM (5)
#define BDS_NUM (37)
#define GAL_NUM (36)
#define SV_ALL_NUM (GPS_NUM+GLO_NUM+QZSS_NUM+BDS_NUM+GAL_NUM) //=134
namespace loc_core
{
/******************************************************************************
SystemStatus report data structure
******************************************************************************/
class SystemStatusItemBase
{
public:
timespec mUtcTime; // UTC timestamp when this info was last updated
timespec mUtcReported; // UTC timestamp when this info was reported
SystemStatusItemBase() {
timeval tv;
gettimeofday(&tv, NULL);
mUtcTime.tv_sec = tv.tv_sec;
mUtcTime.tv_nsec = tv.tv_usec *1000ULL;
mUtcReported = mUtcTime;
};
virtual ~SystemStatusItemBase() { };
virtual void dump(void) { };
};
class SystemStatusLocation : public SystemStatusItemBase
{
public:
bool mValid;
UlpLocation mLocation;
GpsLocationExtended mLocationEx;
inline SystemStatusLocation() :
mValid(false) {}
inline SystemStatusLocation(const UlpLocation& location,
const GpsLocationExtended& locationEx) :
mValid(true),
mLocation(location),
mLocationEx(locationEx) { }
bool equals(SystemStatusLocation& peer);
void dump(void);
};
class SystemStatusPQWM1;
class SystemStatusTimeAndClock : public SystemStatusItemBase
{
public:
uint16_t mGpsWeek;
uint32_t mGpsTowMs;
uint8_t mTimeValid;
uint8_t mTimeSource;
int32_t mTimeUnc;
int32_t mClockFreqBias;
int32_t mClockFreqBiasUnc;
int32_t mLeapSeconds;
int32_t mLeapSecUnc;
inline SystemStatusTimeAndClock() :
mGpsWeek(0),
mGpsTowMs(0),
mTimeValid(0),
mTimeSource(0),
mTimeUnc(0),
mClockFreqBias(0),
mClockFreqBiasUnc(0),
mLeapSeconds(0),
mLeapSecUnc(0) {}
inline SystemStatusTimeAndClock(const SystemStatusPQWM1& nmea);
bool equals(SystemStatusTimeAndClock& peer);
void dump(void);
};
class SystemStatusXoState : public SystemStatusItemBase
{
public:
uint8_t mXoState;
inline SystemStatusXoState() :
mXoState(0) {}
inline SystemStatusXoState(const SystemStatusPQWM1& nmea);
bool equals(SystemStatusXoState& peer);
void dump(void);
};
class SystemStatusRfAndParams : public SystemStatusItemBase
{
public:
int32_t mPgaGain;
uint32_t mGpsBpAmpI;
uint32_t mGpsBpAmpQ;
uint32_t mAdcI;
uint32_t mAdcQ;
uint32_t mJammerGps;
uint32_t mJammerGlo;
uint32_t mJammerBds;
uint32_t mJammerGal;
double mAgcGps;
double mAgcGlo;
double mAgcBds;
double mAgcGal;
inline SystemStatusRfAndParams() :
mPgaGain(0),
mGpsBpAmpI(0),
mGpsBpAmpQ(0),
mAdcI(0),
mAdcQ(0),
mJammerGps(0),
mJammerGlo(0),
mJammerBds(0),
mJammerGal(0),
mAgcGps(0),
mAgcGlo(0),
mAgcBds(0),
mAgcGal(0) {}
inline SystemStatusRfAndParams(const SystemStatusPQWM1& nmea);
bool equals(SystemStatusRfAndParams& peer);
void dump(void);
};
class SystemStatusErrRecovery : public SystemStatusItemBase
{
public:
uint32_t mRecErrorRecovery;
inline SystemStatusErrRecovery() :
mRecErrorRecovery(0) {};
inline SystemStatusErrRecovery(const SystemStatusPQWM1& nmea);
bool equals(SystemStatusErrRecovery& peer);
void dump(void);
};
class SystemStatusPQWP1;
class SystemStatusInjectedPosition : public SystemStatusItemBase
{
public:
uint8_t mEpiValidity;
float mEpiLat;
float mEpiLon;
float mEpiAlt;
float mEpiHepe;
float mEpiAltUnc;
uint8_t mEpiSrc;
inline SystemStatusInjectedPosition() :
mEpiValidity(0),
mEpiLat(0),
mEpiLon(0),
mEpiAlt(0),
mEpiHepe(0),
mEpiAltUnc(0),
mEpiSrc(0) {}
inline SystemStatusInjectedPosition(const SystemStatusPQWP1& nmea);
bool equals(SystemStatusInjectedPosition& peer);
void dump(void);
};
class SystemStatusPQWP2;
class SystemStatusBestPosition : public SystemStatusItemBase
{
public:
bool mValid;
float mBestLat;
float mBestLon;
float mBestAlt;
float mBestHepe;
float mBestAltUnc;
inline SystemStatusBestPosition() :
mValid(false),
mBestLat(0),
mBestLon(0),
mBestAlt(0),
mBestHepe(0),
mBestAltUnc(0) {}
inline SystemStatusBestPosition(const SystemStatusPQWP2& nmea);
bool equals(SystemStatusBestPosition& peer);
void dump(void);
};
class SystemStatusPQWP3;
class SystemStatusXtra : public SystemStatusItemBase
{
public:
uint8_t mXtraValidMask;
uint32_t mGpsXtraAge;
uint32_t mGloXtraAge;
uint32_t mBdsXtraAge;
uint32_t mGalXtraAge;
uint32_t mQzssXtraAge;
uint32_t mGpsXtraValid;
uint32_t mGloXtraValid;
uint64_t mBdsXtraValid;
uint64_t mGalXtraValid;
uint8_t mQzssXtraValid;
inline SystemStatusXtra() :
mXtraValidMask(0),
mGpsXtraAge(0),
mGloXtraAge(0),
mBdsXtraAge(0),
mGalXtraAge(0),
mQzssXtraAge(0),
mGpsXtraValid(0),
mGloXtraValid(0),
mBdsXtraValid(0ULL),
mGalXtraValid(0ULL),
mQzssXtraValid(0) {}
inline SystemStatusXtra(const SystemStatusPQWP3& nmea);
bool equals(SystemStatusXtra& peer);
void dump(void);
};
class SystemStatusPQWP4;
class SystemStatusEphemeris : public SystemStatusItemBase
{
public:
uint32_t mGpsEpheValid;
uint32_t mGloEpheValid;
uint64_t mBdsEpheValid;
uint64_t mGalEpheValid;
uint8_t mQzssEpheValid;
inline SystemStatusEphemeris() :
mGpsEpheValid(0),
mGloEpheValid(0),
mBdsEpheValid(0ULL),
mGalEpheValid(0ULL),
mQzssEpheValid(0) {}
inline SystemStatusEphemeris(const SystemStatusPQWP4& nmea);
bool equals(SystemStatusEphemeris& peer);
void dump(void);
};
class SystemStatusPQWP5;
class SystemStatusSvHealth : public SystemStatusItemBase
{
public:
uint32_t mGpsUnknownMask;
uint32_t mGloUnknownMask;
uint64_t mBdsUnknownMask;
uint64_t mGalUnknownMask;
uint8_t mQzssUnknownMask;
uint32_t mGpsGoodMask;
uint32_t mGloGoodMask;
uint64_t mBdsGoodMask;
uint64_t mGalGoodMask;
uint8_t mQzssGoodMask;
uint32_t mGpsBadMask;
uint32_t mGloBadMask;
uint64_t mBdsBadMask;
uint64_t mGalBadMask;
uint8_t mQzssBadMask;
inline SystemStatusSvHealth() :
mGpsUnknownMask(0),
mGloUnknownMask(0),
mBdsUnknownMask(0ULL),
mGalUnknownMask(0ULL),
mQzssUnknownMask(0),
mGpsGoodMask(0),
mGloGoodMask(0),
mBdsGoodMask(0ULL),
mGalGoodMask(0ULL),
mQzssGoodMask(0),
mGpsBadMask(0),
mGloBadMask(0),
mBdsBadMask(0ULL),
mGalBadMask(0ULL),
mQzssBadMask(0) {}
inline SystemStatusSvHealth(const SystemStatusPQWP5& nmea);
bool equals(SystemStatusSvHealth& peer);
void dump(void);
};
class SystemStatusPQWP6;
class SystemStatusPdr : public SystemStatusItemBase
{
public:
uint32_t mFixInfoMask;
inline SystemStatusPdr() :
mFixInfoMask(0) {}
inline SystemStatusPdr(const SystemStatusPQWP6& nmea);
bool equals(SystemStatusPdr& peer);
void dump(void);
};
class SystemStatusPQWP7;
struct SystemStatusNav
{
GnssEphemerisType mType;
GnssEphemerisSource mSource;
int32_t mAgeSec;
};
class SystemStatusNavData : public SystemStatusItemBase
{
public:
SystemStatusNav mNav[SV_ALL_NUM];
inline SystemStatusNavData() {
for (uint32_t i=0; i<SV_ALL_NUM; i++) {
mNav[i].mType = GNSS_EPH_TYPE_UNKNOWN;
mNav[i].mSource = GNSS_EPH_SOURCE_UNKNOWN;
mNav[i].mAgeSec = 0;
}
}
inline SystemStatusNavData(const SystemStatusPQWP7& nmea);
bool equals(SystemStatusNavData& peer);
void dump(void);
};
class SystemStatusPQWS1;
class SystemStatusPositionFailure : public SystemStatusItemBase
{
public:
uint32_t mFixInfoMask;
uint32_t mHepeLimit;
inline SystemStatusPositionFailure() :
mFixInfoMask(0),
mHepeLimit(0) {}
inline SystemStatusPositionFailure(const SystemStatusPQWS1& nmea);
bool equals(SystemStatusPositionFailure& peer);
void dump(void);
};
/******************************************************************************
SystemStatus report data structure - from DataItem observer
******************************************************************************/
class SystemStatusGpsState : public SystemStatusItemBase, public IDataItemCore
{
public:
inline SystemStatusGpsState() :
mEnabled(false) {}
inline SystemStatusGpsState(bool enabled) :
mEnabled(enabled) {}
bool mEnabled;
inline bool equals(SystemStatusGpsState& peer) {
return (mEnabled == peer.mEnabled);
}
inline void dump(void) {
LOC_LOGD("GpsState: state=%u", mEnabled);
}
inline DataItemId getId() {
return GPSSTATE_DATA_ITEM_ID;
}
inline void stringify(string& valueStr) {
valueStr.clear();
valueStr += "GpsState: enabled=";
valueStr += to_string(mEnabled);
}
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
SystemStatusGpsState* gpsstate = static_cast<SystemStatusGpsState*>(src);
mEnabled = gpsstate->mEnabled;
if (dataItemCopied) {
*dataItemCopied = true;
}
return 1;
}
};
class SystemStatusNetworkInfo : public SystemStatusItemBase, public IDataItemCore
{
public:
inline SystemStatusNetworkInfo() :
mType(0),
mTypeName(""),
mSubTypeName(""),
mAvailable(false),
mConnected(false),
mRoaming(false) {}
inline SystemStatusNetworkInfo(
uint32_t type,
std::string typeName,
std::string subTypeName,
bool available,
bool connected,
bool roaming) :
mType(type),
mTypeName(typeName),
mSubTypeName(subTypeName),
mAvailable(available),
mConnected(connected),
mRoaming(roaming) {}
uint32_t mType;
std::string mTypeName;
std::string mSubTypeName;
bool mAvailable;
bool mConnected;
bool mRoaming;
inline bool equals(SystemStatusNetworkInfo& peer) {
if ((mType != peer.mType) ||
(mTypeName != peer.mTypeName) ||
(mSubTypeName != peer.mSubTypeName) ||
(mAvailable != peer.mAvailable) ||
(mConnected != peer.mConnected) ||
(mRoaming != peer.mRoaming)) {
return false;
}
return true;
}
inline void dump(void) {
LOC_LOGD("NetworkInfo: type=%u connected=%u", mType, mConnected);
}
inline DataItemId getId() {
return NETWORKINFO_DATA_ITEM_ID;
}
inline void stringify(string& /*valueStr*/) { }
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
SystemStatusNetworkInfo* networkinfo = static_cast<SystemStatusNetworkInfo*>(src);
mType = networkinfo->mType;
mTypeName = networkinfo->mTypeName;
mSubTypeName = networkinfo->mSubTypeName;
mAvailable = networkinfo->mAvailable;
mConnected = networkinfo->mConnected;
mRoaming = networkinfo->mRoaming;
if (dataItemCopied) {
*dataItemCopied = true;
}
return 1;
}
};
class SystemStatusTac : public SystemStatusItemBase, public IDataItemCore
{
public:
inline SystemStatusTac() :
mValue("") {}
inline SystemStatusTac(std::string value) :
mValue(value) {}
std::string mValue;
inline bool equals(SystemStatusTac& peer) {
return (mValue == peer.mValue);
}
inline void dump(void) {
LOC_LOGD("Tac: value=%s", mValue.c_str());
}
inline DataItemId getId() {
return TAC_DATA_ITEM_ID;
}
inline void stringify(string& /*valueStr*/) { }
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
SystemStatusTac* tac = static_cast<SystemStatusTac*>(src);
mValue = tac->mValue;
if (dataItemCopied) {
*dataItemCopied = true;
}
return 1;
}
};
class SystemStatusMccMnc : public SystemStatusItemBase, public IDataItemCore
{
public:
inline SystemStatusMccMnc() :
mValue("") {}
inline SystemStatusMccMnc(std::string value) :
mValue(value) {}
std::string mValue;
inline bool equals(SystemStatusMccMnc& peer) {
return (mValue == peer.mValue);
}
inline void dump(void) {
LOC_LOGD("TacMccMnc value=%s", mValue.c_str());
}
inline DataItemId getId() {
return MCCMNC_DATA_ITEM_ID;
}
inline void stringify(string& /*valueStr*/) { }
inline int32_t copy(IDataItemCore* src, bool* dataItemCopied = nullptr) {
SystemStatusMccMnc* mccmnc = static_cast<SystemStatusMccMnc*>(src);
mValue = mccmnc->mValue;
if (dataItemCopied) {
*dataItemCopied = true;
}
return 1;
}
};
/******************************************************************************
SystemStatusReports
******************************************************************************/
class SystemStatusReports
{
public:
// from QMI_LOC indication
std::vector<SystemStatusLocation> mLocation;
// from ME debug NMEA
std::vector<SystemStatusTimeAndClock> mTimeAndClock;
std::vector<SystemStatusXoState> mXoState;
std::vector<SystemStatusRfAndParams> mRfAndParams;
std::vector<SystemStatusErrRecovery> mErrRecovery;
// from PE debug NMEA
std::vector<SystemStatusInjectedPosition> mInjectedPosition;
std::vector<SystemStatusBestPosition> mBestPosition;
std::vector<SystemStatusXtra> mXtra;
std::vector<SystemStatusEphemeris> mEphemeris;
std::vector<SystemStatusSvHealth> mSvHealth;
std::vector<SystemStatusPdr> mPdr;
std::vector<SystemStatusNavData> mNavData;
// from SM debug NMEA
std::vector<SystemStatusPositionFailure> mPositionFailure;
// from dataitems observer
std::vector<SystemStatusGpsState> mGpsState;
std::vector<SystemStatusNetworkInfo> mNetworkInfo;
std::vector<SystemStatusTac> mTac;
std::vector<SystemStatusMccMnc> mMccMnc;
};
/******************************************************************************
SystemStatus
******************************************************************************/
class SystemStatus
{
private:
static SystemStatus *mInstance;
SystemStatusOsObserver mSysStatusObsvr;
// ctor
SystemStatus(const MsgTask* msgTask);
// dtor
inline ~SystemStatus() {}
// Data members
static pthread_mutex_t mMutexSystemStatus;
static const uint32_t maxLocation = 5;
static const uint32_t maxTimeAndClock = 5;
static const uint32_t maxXoState = 5;
static const uint32_t maxRfAndParams = 5;
static const uint32_t maxErrRecovery = 5;
static const uint32_t maxInjectedPosition = 5;
static const uint32_t maxBestPosition = 5;
static const uint32_t maxXtra = 5;
static const uint32_t maxEphemeris = 5;
static const uint32_t maxSvHealth = 5;
static const uint32_t maxPdr = 5;
static const uint32_t maxNavData = 5;
static const uint32_t maxPositionFailure = 5;
static const uint32_t maxGpsState = 5;
static const uint32_t maxNetworkInfo = 5;
static const uint32_t maxTac = 5;
static const uint32_t maxMccMnc = 5;
SystemStatusReports mCache;
bool mConnected;
bool setLocation(const UlpLocation& location);
bool setTimeAndCLock(const SystemStatusPQWM1& nmea);
bool setXoState(const SystemStatusPQWM1& nmea);
bool setRfAndParams(const SystemStatusPQWM1& nmea);
bool setErrRecovery(const SystemStatusPQWM1& nmea);
bool setInjectedPosition(const SystemStatusPQWP1& nmea);
bool setBestPosition(const SystemStatusPQWP2& nmea);
bool setXtra(const SystemStatusPQWP3& nmea);
bool setEphemeris(const SystemStatusPQWP4& nmea);
bool setSvHealth(const SystemStatusPQWP5& nmea);
bool setPdr(const SystemStatusPQWP6& nmea);
bool setNavData(const SystemStatusPQWP7& nmea);
bool setPositionFailure(const SystemStatusPQWS1& nmea);
bool setNetworkInfo(IDataItemCore* dataitem);
public:
// Static methods
static SystemStatus* getInstance(const MsgTask* msgTask);
static void destroyInstance();
IOsObserver* getOsObserver();
// Helpers
bool eventPosition(const UlpLocation& location,const GpsLocationExtended& locationEx);
bool eventDataItemNotify(IDataItemCore* dataitem);
bool setNmeaString(const char *data, uint32_t len);
bool getReport(SystemStatusReports& reports, bool isLatestonly = false) const;
bool setDefaultReport(void);
bool eventConnectionStatus(bool connected, uint8_t type);
};
} // namespace loc_core
#endif //__SYSTEM_STATUS__

View File

@@ -0,0 +1,593 @@
/* Copyright (c) 2015-2017, 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_TAG "LocSvc_SystemStatusOsObserver"
#include <algorithm>
#include <SystemStatus.h>
#include <SystemStatusOsObserver.h>
#include <IDataItemCore.h>
#include <IClientIndex.h>
#include <IDataItemIndex.h>
#include <IndexFactory.h>
#include <DataItemsFactoryProxy.h>
namespace loc_core
{
SystemStatusOsObserver::SystemStatusOsObserver(const MsgTask* msgTask) :
mAddress("SystemStatusOsObserver"),
mClientIndex(IndexFactory<IDataItemObserver*, DataItemId> :: createClientIndex()),
mDataItemIndex(IndexFactory<IDataItemObserver*, DataItemId> :: createDataItemIndex())
{
mContext.mMsgTask = msgTask;
}
SystemStatusOsObserver::~SystemStatusOsObserver()
{
// Close data-item library handle
DataItemsFactoryProxy::closeDataItemLibraryHandle();
// Destroy cache
for (auto each : mDataItemCache) {
if (nullptr != each.second) {
delete each.second;
}
}
mDataItemCache.clear();
delete mClientIndex;
delete mDataItemIndex;
}
void SystemStatusOsObserver::setSubscriptionObj(IDataItemSubscription* subscriptionObj)
{
mContext.mSubscriptionObj = subscriptionObj;
LOC_LOGD("Request cache size - Subscribe:%zu RequestData:%zu",
mSubscribeReqCache.size(), mReqDataCache.size());
// we have received the subscription object. process cached requests
// process - subscribe request cache
for (auto each : mSubscribeReqCache) {
subscribe(each.second, each.first);
}
// process - requestData request cache
for (auto each : mReqDataCache) {
requestData(each.second, each.first);
}
}
// Helper to cache requests subscribe and requestData till subscription obj is obtained
void SystemStatusOsObserver::cacheObserverRequest(ObserverReqCache& reqCache,
const list<DataItemId>& l, IDataItemObserver* client)
{
ObserverReqCache::iterator dicIter = reqCache.find(client);
if (dicIter != reqCache.end()) {
// found
list<DataItemId> difference(0);
set_difference(l.begin(), l.end(),
dicIter->second.begin(), dicIter->second.end(),
inserter(difference, difference.begin()));
if (!difference.empty()) {
difference.sort();
dicIter->second.merge(difference);
dicIter->second.unique();
}
}
else {
// not found
reqCache[client] = l;
}
}
/******************************************************************************
IDataItemSubscription Overrides
******************************************************************************/
void SystemStatusOsObserver::subscribe(
const list<DataItemId>& l, IDataItemObserver* client)
{
if (nullptr == mContext.mSubscriptionObj) {
LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__);
cacheObserverRequest(mSubscribeReqCache, l, client);
return;
}
struct HandleSubscribeReq : public LocMsg {
HandleSubscribeReq(SystemStatusOsObserver* parent,
const list<DataItemId>& l, IDataItemObserver* client) :
mParent(parent), mClient(client), mDataItemList(l) {}
virtual ~HandleSubscribeReq() {}
void proc() const {
if (mDataItemList.empty()) {
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
return;
}
// Handle First Response
list<DataItemId> pendingFirstResponseList(0);
mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList);
// Do not send first response for only pendingFirstResponseList,
// instead send for all the data items (present in the cache) that
// have been subscribed for each time.
mParent->sendFirstResponse(mDataItemList, mClient);
list<DataItemId> yetToSubscribeDataItemsList(0);
mParent->mDataItemIndex->add(mClient, mDataItemList, yetToSubscribeDataItemsList);
// Send subscription list to framework
if (!yetToSubscribeDataItemsList.empty()) {
mParent->mContext.mSubscriptionObj->subscribe(yetToSubscribeDataItemsList, mParent);
LOC_LOGD("Subscribe Request sent to framework for the following");
mParent->logMe(yetToSubscribeDataItemsList);
}
}
SystemStatusOsObserver* mParent;
IDataItemObserver* mClient;
const list<DataItemId> mDataItemList;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleSubscribeReq(this, l, client));
}
void SystemStatusOsObserver::updateSubscription(
const list<DataItemId>& l, IDataItemObserver* client)
{
if (nullptr == mContext.mSubscriptionObj) {
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
return;
}
struct HandleUpdateSubscriptionReq : public LocMsg {
HandleUpdateSubscriptionReq(SystemStatusOsObserver* parent,
const list<DataItemId>& l, IDataItemObserver* client) :
mParent(parent), mClient(client), mDataItemList(l) {}
virtual ~HandleUpdateSubscriptionReq() {}
void proc() const {
if (mDataItemList.empty()) {
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
return;
}
list<DataItemId> currentlySubscribedList(0);
mParent->mClientIndex->getSubscribedList(mClient, currentlySubscribedList);
list<DataItemId> removeDataItemList(0);
set_difference(currentlySubscribedList.begin(), currentlySubscribedList.end(),
mDataItemList.begin(), mDataItemList.end(),
inserter(removeDataItemList,removeDataItemList.begin()));
// Handle First Response
list<DataItemId> pendingFirstResponseList(0);
mParent->mClientIndex->add(mClient, mDataItemList, pendingFirstResponseList);
// Send First Response
mParent->sendFirstResponse(pendingFirstResponseList, mClient);
list<DataItemId> yetToSubscribeDataItemsList(0);
mParent->mDataItemIndex->add(
mClient, mDataItemList, yetToSubscribeDataItemsList);
// Send subscription list to framework
if (!yetToSubscribeDataItemsList.empty()) {
mParent->mContext.mSubscriptionObj->subscribe(
yetToSubscribeDataItemsList, mParent);
LOC_LOGD("Subscribe Request sent to framework for the following");
mParent->logMe(yetToSubscribeDataItemsList);
}
list<DataItemId> unsubscribeList(0);
list<DataItemId> unused(0);
mParent->mClientIndex->remove(mClient, removeDataItemList, unused);
if (!mParent->mClientIndex->isSubscribedClient(mClient)) {
mParent->mDataItemIndex->remove(
list<IDataItemObserver*> (1,mClient), unsubscribeList);
}
if (!unsubscribeList.empty()) {
// Send unsubscribe to framework
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
LOC_LOGD("Unsubscribe Request sent to framework for the following");
mParent->logMe(unsubscribeList);
}
}
SystemStatusOsObserver* mParent;
IDataItemObserver* mClient;
const list<DataItemId> mDataItemList;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleUpdateSubscriptionReq(this, l, client));
}
void SystemStatusOsObserver::requestData(
const list<DataItemId>& l, IDataItemObserver* client)
{
if (nullptr == mContext.mSubscriptionObj) {
LOC_LOGD("%s]: Subscription object is NULL. Caching requests", __func__);
cacheObserverRequest(mReqDataCache, l, client);
return;
}
struct HandleRequestData : public LocMsg {
HandleRequestData(SystemStatusOsObserver* parent,
const list<DataItemId>& l, IDataItemObserver* client) :
mParent(parent), mClient(client), mDataItemList(l) {}
virtual ~HandleRequestData() {}
void proc() const {
if (mDataItemList.empty()) {
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
return;
}
list<DataItemId> yetToSubscribeDataItemsList(0);
mParent->mClientIndex->add(
mClient, mDataItemList, yetToSubscribeDataItemsList);
mParent->mDataItemIndex->add(
mClient, mDataItemList, yetToSubscribeDataItemsList);
// Send subscription list to framework
if (!mDataItemList.empty()) {
mParent->mContext.mSubscriptionObj->requestData(mDataItemList, mParent);
LOC_LOGD("Subscribe Request sent to framework for the following");
mParent->logMe(yetToSubscribeDataItemsList);
}
}
SystemStatusOsObserver* mParent;
IDataItemObserver* mClient;
const list<DataItemId> mDataItemList;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleRequestData(this, l, client));
}
void SystemStatusOsObserver::unsubscribe(
const list<DataItemId>& l, IDataItemObserver* client)
{
if (nullptr == mContext.mSubscriptionObj) {
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
return;
}
struct HandleUnsubscribeReq : public LocMsg {
HandleUnsubscribeReq(SystemStatusOsObserver* parent,
const list<DataItemId>& l, IDataItemObserver* client) :
mParent(parent), mClient(client), mDataItemList(l) {}
virtual ~HandleUnsubscribeReq() {}
void proc() const {
if (mDataItemList.empty()) {
LOC_LOGV("mDataItemList is empty. Nothing to do. Exiting");
return;
}
list<DataItemId> unsubscribeList(0);
list<DataItemId> unused(0);
mParent->mClientIndex->remove(mClient, mDataItemList, unused);
for (auto each : mDataItemList) {
list<IDataItemObserver*> clientListSubs(0);
list<IDataItemObserver*> clientListOut(0);
mParent->mDataItemIndex->remove(
each, list<IDataItemObserver*> (1,mClient), clientListOut);
// check if there are any other subscribed client for this data item id
mParent->mDataItemIndex->getListOfSubscribedClients(each, clientListSubs);
if (clientListSubs.empty())
{
LOC_LOGD("Client list subscribed is empty for dataitem - %d", each);
unsubscribeList.push_back(each);
}
}
if (!unsubscribeList.empty()) {
// Send unsubscribe to framework
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
LOC_LOGD("Unsubscribe Request sent to framework for the following data items");
mParent->logMe(unsubscribeList);
}
}
SystemStatusOsObserver* mParent;
IDataItemObserver* mClient;
const list<DataItemId> mDataItemList;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeReq(this, l, client));
}
void SystemStatusOsObserver::unsubscribeAll(IDataItemObserver* client)
{
if (nullptr == mContext.mSubscriptionObj) {
LOC_LOGE("%s:%d]: Subscription object is NULL", __func__, __LINE__);
return;
}
struct HandleUnsubscribeAllReq : public LocMsg {
HandleUnsubscribeAllReq(SystemStatusOsObserver* parent,
IDataItemObserver* client) :
mParent(parent), mClient(client) {}
virtual ~HandleUnsubscribeAllReq() {}
void proc() const {
list<IDataItemObserver*> clients(1, mClient);
list<DataItemId> unsubscribeList(0);
if(0 == mParent->mClientIndex->remove(mClient)) {
return;
}
mParent->mDataItemIndex->remove(clients, unsubscribeList);
if (!unsubscribeList.empty()) {
// Send unsubscribe to framework
mParent->mContext.mSubscriptionObj->unsubscribe(unsubscribeList, mParent);
LOC_LOGD("Unsubscribe Request sent to framework for the following data items");
mParent->logMe(unsubscribeList);
}
}
SystemStatusOsObserver* mParent;
IDataItemObserver* mClient;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleUnsubscribeAllReq(this, client));
}
/******************************************************************************
IDataItemObserver Overrides
******************************************************************************/
void SystemStatusOsObserver::notify(const list<IDataItemCore*>& dlist)
{
list<IDataItemCore*> dataItemList(0);
for (auto each : dlist) {
string dv;
each->stringify(dv);
LOC_LOGD("notify: DataItem In Value:%s", dv.c_str());
IDataItemCore* di = DataItemsFactoryProxy::createNewDataItem(each->getId());
if (nullptr == di) {
LOC_LOGE("Unable to create dataitem:%d", each->getId());
return;
}
// Copy contents into the newly created data item
di->copy(each);
dataItemList.push_back(di);
// Request systemstatus to record this dataitem in its cache
SystemStatus* systemstatus = SystemStatus::getInstance(mContext.mMsgTask);
if(nullptr != systemstatus) {
systemstatus->eventDataItemNotify(di);
}
}
struct HandleNotify : public LocMsg {
HandleNotify(SystemStatusOsObserver* parent, const list<IDataItemCore*>& l) :
mParent(parent), mDList(l) {}
virtual ~HandleNotify() {
for (auto each : mDList) {
delete each;
}
}
void proc() const {
// Update Cache with received data items and prepare
// list of data items to be sent.
list<DataItemId> dataItemIdsToBeSent(0);
for (auto item : mDList) {
bool dataItemUpdated = false;
mParent->updateCache(item, dataItemUpdated);
if (dataItemUpdated) {
dataItemIdsToBeSent.push_back(item->getId());
}
}
// Send data item to all subscribed clients
list<IDataItemObserver*> clientList(0);
for (auto each : dataItemIdsToBeSent) {
list<IDataItemObserver*> clients(0);
mParent->mDataItemIndex->getListOfSubscribedClients(each, clients);
for (auto each_cient: clients) {
clientList.push_back(each_cient);
}
}
clientList.unique();
for (auto client : clientList) {
list<DataItemId> dataItemIdsSubscribedByThisClient(0);
list<DataItemId> dataItemIdsToBeSentForThisClient(0);
mParent->mClientIndex->getSubscribedList(
client, dataItemIdsSubscribedByThisClient);
dataItemIdsSubscribedByThisClient.sort();
dataItemIdsToBeSent.sort();
set_intersection(dataItemIdsToBeSent.begin(),
dataItemIdsToBeSent.end(),
dataItemIdsSubscribedByThisClient.begin(),
dataItemIdsSubscribedByThisClient.end(),
inserter(dataItemIdsToBeSentForThisClient,
dataItemIdsToBeSentForThisClient.begin()));
mParent->sendCachedDataItems(dataItemIdsToBeSentForThisClient, client);
dataItemIdsSubscribedByThisClient.clear();
dataItemIdsToBeSentForThisClient.clear();
}
}
SystemStatusOsObserver* mParent;
const list<IDataItemCore*> mDList;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleNotify(this, dataItemList));
}
/******************************************************************************
IFrameworkActionReq Overrides
******************************************************************************/
void SystemStatusOsObserver::turnOn(DataItemId dit, int timeOut)
{
if (nullptr == mContext.mFrameworkActionReqObj) {
LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__);
return;
}
// Check if data item exists in mActiveRequestCount
map<DataItemId, int>::iterator citer = mActiveRequestCount.find(dit);
if (citer == mActiveRequestCount.end()) {
// Data item not found in map
// Add reference count as 1 and add dataitem to map
pair<DataItemId, int> cpair(dit, 1);
mActiveRequestCount.insert(cpair);
LOC_LOGD("Sending turnOn request");
// Send action turn on to framework
struct HandleTurnOnMsg : public LocMsg {
HandleTurnOnMsg(IFrameworkActionReq* framework,
DataItemId dit, int timeOut) :
mFrameworkActionReqObj(framework), mDataItemId(dit), mTimeOut(timeOut) {}
virtual ~HandleTurnOnMsg() {}
void proc() const {
mFrameworkActionReqObj->turnOn(mDataItemId, mTimeOut);
}
IFrameworkActionReq* mFrameworkActionReqObj;
DataItemId mDataItemId;
int mTimeOut;
};
mContext.mMsgTask->sendMsg(new (nothrow) HandleTurnOnMsg(this, dit, timeOut));
}
else {
// Found in map, update reference count
citer->second++;
LOC_LOGD("turnOn - Data item:%d Num_refs:%d", dit, citer->second);
}
}
void SystemStatusOsObserver::turnOff(DataItemId dit)
{
if (nullptr == mContext.mFrameworkActionReqObj) {
LOC_LOGE("%s:%d]: Framework action request object is NULL", __func__, __LINE__);
return;
}
// Check if data item exists in mActiveRequestCount
map<DataItemId, int>::iterator citer = mActiveRequestCount.find(dit);
if (citer != mActiveRequestCount.end()) {
// found
citer->second--;
LOC_LOGD("turnOff - Data item:%d Remaining:%d", dit, citer->second);
if(citer->second == 0) {
// if this was last reference, remove item from map and turn off module
mActiveRequestCount.erase(citer);
// Send action turn off to framework
struct HandleTurnOffMsg : public LocMsg {
HandleTurnOffMsg(IFrameworkActionReq* framework, DataItemId dit) :
mFrameworkActionReqObj(framework), mDataItemId(dit) {}
virtual ~HandleTurnOffMsg() {}
void proc() const {
mFrameworkActionReqObj->turnOff(mDataItemId);
}
IFrameworkActionReq* mFrameworkActionReqObj;
DataItemId mDataItemId;
};
mContext.mMsgTask->sendMsg(
new (nothrow) HandleTurnOffMsg(mContext.mFrameworkActionReqObj, dit));
}
}
}
/******************************************************************************
Helpers
******************************************************************************/
void SystemStatusOsObserver::sendFirstResponse(
const list<DataItemId>& l, IDataItemObserver* to)
{
if (l.empty()) {
LOC_LOGV("list is empty. Nothing to do. Exiting");
return;
}
string clientName;
to->getName(clientName);
list<IDataItemCore*> dataItems(0);
for (auto each : l) {
map<DataItemId, IDataItemCore*>::const_iterator citer = mDataItemCache.find(each);
if (citer != mDataItemCache.end()) {
string dv;
citer->second->stringify(dv);
LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str());
dataItems.push_back(citer->second);
}
}
if (dataItems.empty()) {
LOC_LOGV("No items to notify. Nothing to do. Exiting");
return;
}
to->notify(dataItems);
}
void SystemStatusOsObserver::sendCachedDataItems(
const list<DataItemId>& l, IDataItemObserver* to)
{
string clientName;
to->getName(clientName);
list<IDataItemCore*> dataItems(0);
for (auto each : l) {
string dv;
IDataItemCore* di = mDataItemCache[each];
di->stringify(dv);
LOC_LOGI("DataItem: %s >> %s", dv.c_str(), clientName.c_str());
dataItems.push_back(di);
}
to->notify(dataItems);
}
void SystemStatusOsObserver::updateCache(IDataItemCore* d, bool& dataItemUpdated)
{
if (nullptr == d) {
return;
}
// Check if data item exists in cache
map<DataItemId, IDataItemCore*>::iterator citer =
mDataItemCache.find(d->getId());
if (citer == mDataItemCache.end()) {
// New data item; not found in cache
IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(d->getId());
if (nullptr == dataitem) {
return;
}
// Copy the contents of the data item
dataitem->copy(d);
pair<DataItemId, IDataItemCore*> cpair(d->getId(), dataitem);
// Insert in mDataItemCache
mDataItemCache.insert(cpair);
dataItemUpdated = true;
}
else {
// Found in cache; Update cache if necessary
if(0 == citer->second->copy(d, &dataItemUpdated)) {
return;
}
}
if (dataItemUpdated) {
LOC_LOGV("DataItem:%d updated:%d", d->getId(), dataItemUpdated);
}
}
} // namespace loc_core

View File

@@ -0,0 +1,135 @@
/* Copyright (c) 2015-2017, 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 __SYSTEM_STATUS_OSOBSERVER__
#define __SYSTEM_STATUS_OSOBSERVER__
#include <cinttypes>
#include <string>
#include <list>
#include <map>
#include <new>
#include <vector>
#include <MsgTask.h>
#include <DataItemId.h>
#include <IOsObserver.h>
#include <platform_lib_log_util.h>
namespace loc_core
{
/******************************************************************************
SystemStatusOsObserver
******************************************************************************/
using namespace std;
// Forward Declarations
class IDataItemCore;
template<typename CT, typename DIT> class IClientIndex;
template<typename CT, typename DIT> class IDataItemIndex;
struct SystemContext {
IDataItemSubscription* mSubscriptionObj;
IFrameworkActionReq* mFrameworkActionReqObj;
const MsgTask* mMsgTask;
inline SystemContext() :
mSubscriptionObj(NULL),
mFrameworkActionReqObj(NULL),
mMsgTask(NULL) {}
};
typedef map<IDataItemObserver*, list<DataItemId>> ObserverReqCache;
// Clients wanting to get data from OS/Framework would need to
// subscribe with OSObserver using IDataItemSubscription interface.
// Such clients would need to implement IDataItemObserver interface
// to receive data when it becomes available.
class SystemStatusOsObserver : public IOsObserver {
public:
// ctor
SystemStatusOsObserver(const MsgTask* msgTask);
// dtor
~SystemStatusOsObserver();
// To set the subscription object
virtual void setSubscriptionObj(IDataItemSubscription* subscriptionObj);
// To set the framework action request object
inline void setFrameworkActionReqObj(IFrameworkActionReq* frameworkActionReqObj) {
mContext.mFrameworkActionReqObj = frameworkActionReqObj;
}
// IDataItemSubscription Overrides
virtual void subscribe(const list<DataItemId>& l, IDataItemObserver* client);
virtual void updateSubscription(const list<DataItemId>& l, IDataItemObserver* client);
virtual void requestData(const list<DataItemId>& l, IDataItemObserver* client);
virtual void unsubscribe(const list<DataItemId>& l, IDataItemObserver* client);
virtual void unsubscribeAll(IDataItemObserver* client);
// IDataItemObserver Overrides
virtual void notify(const list<IDataItemCore*>& dlist);
inline virtual void getName(string& name) {
name = mAddress;
}
// IFrameworkActionReq Overrides
virtual void turnOn(DataItemId dit, int timeOut = 0);
virtual void turnOff(DataItemId dit);
private:
SystemContext mContext;
const string mAddress;
IClientIndex<IDataItemObserver*, DataItemId>* mClientIndex;
IDataItemIndex<IDataItemObserver*, DataItemId>* mDataItemIndex;
map<DataItemId, IDataItemCore*> mDataItemCache;
map<DataItemId, int> mActiveRequestCount;
// Cache the subscribe and requestData till subscription obj is obtained
ObserverReqCache mSubscribeReqCache;
ObserverReqCache mReqDataCache;
void cacheObserverRequest(ObserverReqCache& reqCache,
const list<DataItemId>& l, IDataItemObserver* client);
// Helpers
void sendFirstResponse(const list<DataItemId>& l, IDataItemObserver* to);
void sendCachedDataItems(const list<DataItemId>& l, IDataItemObserver* to);
void updateCache(IDataItemCore* d, bool& dataItemUpdated);
inline void logMe(const list<DataItemId>& l) {
for (auto id : l) {
LOC_LOGD("DataItem %d", id);
}
}
};
} // namespace loc_core
#endif //__SYSTEM_STATUS__

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -30,9 +30,7 @@
#define ULP_PROXY_BASE_H
#include <gps_extended.h>
struct FlpExtLocation_s;
struct FlpExtBatchOptions;
#include <LocationAPI.h>
namespace loc_core {
@@ -54,24 +52,18 @@ public:
return false;
}
inline virtual bool reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
inline virtual bool reportPosition(const UlpLocation &location,
const GpsLocationExtended &locationExtended,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask) {
(void)location;
(void)locationExtended;
(void)locationExt;
(void)status;
(void)loc_technology_mask;
return false;
}
inline virtual bool reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt) {
(void)svStatus;
(void)locationExtended;
(void)svExt;
inline virtual bool reportSv(const GnssSvNotification& svNotify) {
(void)svNotify;
return false;
}
inline virtual bool reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet) {
@@ -84,7 +76,7 @@ public:
(void)svPolynomial;
return false;
}
inline virtual bool reportStatus(GpsStatusValue status) {
inline virtual bool reportStatus(LocGpsStatusValue status) {
(void)status;
return false;
@@ -97,24 +89,34 @@ public:
(void)capabilities;
}
inline virtual bool reportBatchingSession(FlpExtBatchOptions &options,
bool active) {
(void)options;
(void)active;
inline virtual bool reportBatchingSession(const LocationOptions& options, bool active)
{
(void)options;
(void)active;
return false;
}
inline virtual bool reportPositions(const UlpLocation* ulpLocations,
const GpsLocationExtended* extendedLocations,
const uint32_t* techMasks,
const size_t count)
{
(void)ulpLocations;
(void)extendedLocations;
(void)techMasks;
(void)count;
return false;
}
inline virtual bool reportPositions(const struct FlpExtLocation_s* locations,
int32_t number_of_locations) {
(void)locations;
(void)number_of_locations;
return false;
}
inline virtual bool reportDeleteAidingData(GpsAidingData aidingData)
inline virtual bool reportDeleteAidingData(LocGpsAidingData aidingData)
{
(void)aidingData;
return false;
}
inline virtual bool reportNmea(const char* nmea, int length)
{
(void)nmea;
(void)length;
return false;
}
};
} // namespace loc_core

View File

@@ -0,0 +1,73 @@
/* Copyright (c) 2015-2017 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 __DATAITEMID_H__
#define __DATAITEMID_H__
/**
* Enumeration of Data Item types
* When add/remove/update changes are made to Data Items, this file needs to be updated
* accordingly
*/
typedef enum e_DataItemId {
INVALID_DATA_ITEM_ID = -1,
// 0 - 4
AIRPLANEMODE_DATA_ITEM_ID,
ENH_DATA_ITEM_ID,
GPSSTATE_DATA_ITEM_ID,
NLPSTATUS_DATA_ITEM_ID,
WIFIHARDWARESTATE_DATA_ITEM_ID,
// 5 - 9
NETWORKINFO_DATA_ITEM_ID,
RILVERSION_DATA_ITEM_ID,
RILSERVICEINFO_DATA_ITEM_ID,
RILCELLINFO_DATA_ITEM_ID,
SERVICESTATUS_DATA_ITEM_ID,
// 10 - 14
MODEL_DATA_ITEM_ID,
MANUFACTURER_DATA_ITEM_ID,
VOICECALL_DATA_ITEM,
ASSISTED_GPS_DATA_ITEM_ID,
SCREEN_STATE_DATA_ITEM_ID,
// 15 - 19
POWER_CONNECTED_STATE_DATA_ITEM_ID,
TIMEZONE_CHANGE_DATA_ITEM_ID,
TIME_CHANGE_DATA_ITEM_ID,
WIFI_SUPPLICANT_STATUS_DATA_ITEM_ID,
SHUTDOWN_STATE_DATA_ITEM_ID,
// 20 - 24
TAC_DATA_ITEM_ID,
MCCMNC_DATA_ITEM_ID,
BTLE_SCAN_DATA_ITEM_ID,
BT_SCAN_DATA_ITEM_ID,
OEM_GTP_UPLOAD_TRIGGER_READY_ITEM_ID,
MAX_DATA_ITEM_ID
} DataItemId;
#endif // #ifndef __DATAITEMID_H__

View File

@@ -0,0 +1,99 @@
/* Copyright (c) 2017, 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_TAG "DataItemsFactoryProxy"
#include <dlfcn.h>
#include <DataItemId.h>
#include <IDataItemCore.h>
#include <DataItemsFactoryProxy.h>
#include <platform_lib_log_util.h>
namespace loc_core
{
void* DataItemsFactoryProxy::dataItemLibHandle = NULL;
get_concrete_data_item_fn* DataItemsFactoryProxy::getConcreteDIFunc = NULL;
IDataItemCore* DataItemsFactoryProxy::createNewDataItem(DataItemId id)
{
IDataItemCore *mydi = nullptr;
if (NULL != getConcreteDIFunc) {
mydi = (*getConcreteDIFunc)(id);
}
else {
// first call to this function, symbol not yet loaded
if (NULL == dataItemLibHandle) {
LOC_LOGD("Loaded library %s",DATA_ITEMS_LIB_NAME);
dataItemLibHandle = dlopen(DATA_ITEMS_LIB_NAME, RTLD_NOW);
if (NULL == dataItemLibHandle) {
// dlopen failed.
const char * err = dlerror();
if (NULL == err)
{
err = "Unknown";
}
LOC_LOGE("%s:%d]: failed to load library %s; error=%s",
__func__, __LINE__, DATA_ITEMS_LIB_NAME, err);
}
}
// load sym - if dlopen handle is obtained and symbol is not yet obtained
if (NULL != dataItemLibHandle) {
getConcreteDIFunc = (get_concrete_data_item_fn * )
dlsym(dataItemLibHandle, DATA_ITEMS_GET_CONCRETE_DI);
if (NULL != getConcreteDIFunc) {
LOC_LOGD("Loaded function %s : %x",DATA_ITEMS_GET_CONCRETE_DI,getConcreteDIFunc);
mydi = (*getConcreteDIFunc)(id);
}
else {
// dlysm failed.
const char * err = dlerror();
if (NULL == err)
{
err = "Unknown";
}
LOC_LOGE("%s:%d]: failed to find symbol %s; error=%s",
__func__, __LINE__, DATA_ITEMS_GET_CONCRETE_DI, err);
}
}
}
return mydi;
}
void DataItemsFactoryProxy::closeDataItemLibraryHandle()
{
if (NULL != dataItemLibHandle) {
dlclose(dataItemLibHandle);
dataItemLibHandle = NULL;
}
}
} // namespace loc_core

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2017, 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,9 +27,29 @@
*
*/
#define LOG_NDDEBUG 0
#define LOG_TAG "LocSvc_eng"
#ifndef __DATAITEMFACTORYBASE__
#define __DATAITEMFACTORYBASE__
#include "loc_log.h"
#include "loc_eng_log.h"
#include <DataItemId.h>
#include <IDataItemCore.h>
namespace loc_core
{
#define DATA_ITEMS_LIB_NAME "libdataitems.so"
#define DATA_ITEMS_GET_CONCRETE_DI "getConcreteDataItem"
typedef IDataItemCore * (get_concrete_data_item_fn)(DataItemId);
class DataItemsFactoryProxy {
public:
static IDataItemCore* createNewDataItem(DataItemId id);
static void closeDataItemLibraryHandle();
static void *dataItemLibHandle;
static get_concrete_data_item_fn *getConcreteDIFunc;
};
} // namespace loc_core
#endif //__DATAITEMFACTORYBASE__

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2012,2014 The Linux Foundation. All rights reserved.
/* Copyright (c) 2015, 2017 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
@@ -26,34 +26,57 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_DATA_SERVER_H
#define LOC_ENG_DATA_SERVER_H
#include "loc_eng_dmn_conn_thread_helper.h"
#ifndef __IDATAITEMCORE_H__
#define __IDATAITEMCORE_H__
#ifdef _ANDROID_
#include <string>
#include <DataItemId.h>
#define GPSONE_LOC_API_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_q"
#define GPSONE_LOC_API_RESP_Q_PATH "/data/misc/location/gpsone_d/gpsone_loc_api_resp_q"
#define QUIPC_CTRL_Q_PATH "/data/misc/location/gpsone_d/quipc_ctrl_q"
#define MSAPM_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapm_ctrl_q"
#define MSAPU_CTRL_Q_PATH "/data/misc/location/gpsone_d/msapu_ctrl_q"
namespace loc_core {
#else
using namespace std;
#define GPSONE_LOC_API_Q_PATH "/tmp/gpsone_loc_api_q"
#define GPSONE_LOC_API_RESP_Q_PATH "/tmp/gpsone_loc_api_resp_q"
#define QUIPC_CTRL_Q_PATH "/tmp/quipc_ctrl_q"
#define MSAPM_CTRL_Q_PATH "/tmp/msapm_ctrl_q"
#define MSAPU_CTRL_Q_PATH "/tmp/msapu_ctrl_q"
/**
* @brief IDataItemCore interface.
* @details IDataItemCore interface.
*
*/
class IDataItemCore {
public:
/**
* @brief Gets Data item id.
* @details Gets Data item id.
* @return Data item id.
*/
virtual DataItemId getId () = 0;
#endif
/**
* @brief Stringify.
* @details Stringify.
*
* @param valueStr Reference to string.
*/
virtual void stringify (string & valueStr) = 0;
int loc_eng_dmn_conn_loc_api_server_launch(thelper_create_thread create_thread_cb,
const char * loc_api_q_path, const char * ctrl_q_path, void *agps_handle);
int loc_eng_dmn_conn_loc_api_server_unblock(void);
int loc_eng_dmn_conn_loc_api_server_join(void);
int loc_eng_dmn_conn_loc_api_server_data_conn(int, int);
/**
* @brief copy.
* @details copy.
*
* @param src Where to copy from.
* @param dataItemCopied Boolean flag indicated whether or not copied.
*
* @return Zero for success or non zero for failure.
*/
virtual int32_t copy (IDataItemCore * src, bool *dataItemCopied = nullptr) = 0;
#endif /* LOC_ENG_DATA_SERVER_H */
/**
* @brief Destructor.
* @details Destructor.
*/
virtual ~IDataItemCore () {}
};
} // namespace loc_core
#endif // __IDATAITEMCORE_H__

View File

@@ -0,0 +1,171 @@
/* Copyright (c) 2015, 2017 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 <algorithm>
#include <iterator>
#include <string>
#include <platform_lib_log_util.h>
#include <ClientIndex.h>
#include <IDataItemObserver.h>
#include <DataItemId.h>
using namespace std;
using namespace loc_core;
template <typename CT, typename DIT>
inline ClientIndex <CT,DIT> :: ClientIndex () {}
template <typename CT, typename DIT>
inline ClientIndex <CT,DIT> :: ~ClientIndex () {}
template <typename CT, typename DIT>
bool ClientIndex <CT,DIT> :: isSubscribedClient (CT client) {
bool result = false;
ENTRY_LOG ();
typename map < CT, list <DIT> > :: iterator it =
mDataItemsPerClientMap.find (client);
if (it != mDataItemsPerClientMap.end ()) {
result = true;
}
EXIT_LOG_WITH_ERROR ("%d",result);
return result;
}
template <typename CT, typename DIT>
void ClientIndex <CT,DIT> :: getSubscribedList (CT client, list <DIT> & out) {
ENTRY_LOG ();
typename map < CT, list <DIT> > :: iterator it =
mDataItemsPerClientMap.find (client);
if (it != mDataItemsPerClientMap.end ()) {
out = it->second;
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
int ClientIndex <CT,DIT> :: remove (CT client) {
int result = 0;
ENTRY_LOG ();
mDataItemsPerClientMap.erase (client);
EXIT_LOG_WITH_ERROR ("%d",result);
return result;
}
template <typename CT, typename DIT>
void ClientIndex <CT,DIT> :: remove (const list <DIT> & r, list <CT> & out) {
ENTRY_LOG ();
typename map < CT, list <DIT> > :: iterator dicIter =
mDataItemsPerClientMap.begin ();
while (dicIter != mDataItemsPerClientMap.end()) {
typename list <DIT> :: const_iterator it = r.begin ();
for (; it != r.end (); ++it) {
typename list <DIT> :: iterator iter =
find (dicIter->second.begin (), dicIter->second.end (), *it);
if (iter != dicIter->second.end ()) {
dicIter->second.erase (iter);
}
}
if (dicIter->second.empty ()) {
out.push_back (dicIter->first);
// Post-increment operator increases the iterator but returns the
// prevous one that will be invalidated by erase()
mDataItemsPerClientMap.erase (dicIter++);
} else {
++dicIter;
}
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
void ClientIndex <CT,DIT> :: remove
(
CT client,
const list <DIT> & r,
list <DIT> & out
)
{
ENTRY_LOG ();
typename map < CT, list <DIT> > :: iterator dicIter =
mDataItemsPerClientMap.find (client);
if (dicIter != mDataItemsPerClientMap.end ()) {
set_intersection (dicIter->second.begin (), dicIter->second.end (),
r.begin (), r.end (),
inserter (out,out.begin ()));
if (!out.empty ()) {
typename list <DIT> :: iterator it = out.begin ();
for (; it != out.end (); ++it) {
dicIter->second.erase (find (dicIter->second.begin (),
dicIter->second.end (),
*it));
}
}
if (dicIter->second.empty ()) {
mDataItemsPerClientMap.erase (dicIter);
EXIT_LOG_WITH_ERROR ("%d",0);
}
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
void ClientIndex <CT,DIT> :: add
(
CT client,
const list <DIT> & l,
list <DIT> & out
)
{
ENTRY_LOG ();
list <DIT> difference;
typename map < CT, list <DIT> > :: iterator dicIter =
mDataItemsPerClientMap.find (client);
if (dicIter != mDataItemsPerClientMap.end ()) {
set_difference (l.begin (), l.end (),
dicIter->second.begin (), dicIter->second.end (),
inserter (difference,difference.begin ()));
if (!difference.empty ()) {
difference.sort ();
out = difference;
dicIter->second.merge (difference);
dicIter->second.unique ();
}
} else {
out = l;
pair < CT, list <DIT> > dicnpair (client, out);
mDataItemsPerClientMap.insert (dicnpair);
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
// Explicit instantiation must occur in same namespace where class is defined
namespace loc_core
{
template class ClientIndex <IDataItemObserver *, DataItemId>;
template class ClientIndex <string, DataItemId>;
}

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015, 2017 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -9,7 +9,7 @@
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,26 +26,45 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef LOC_ENG_DMN_CONN_GLUE_MSG_H
#define LOC_ENG_DMN_CONN_GLUE_MSG_H
#ifndef __CLIENTINDEX_H__
#define __CLIENTINDEX_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <list>
#include <map>
#include <IClientIndex.h>
using loc_core::IClientIndex;
#include <linux/types.h>
#include "loc_eng_dmn_conn_glue_pipe.h"
namespace loc_core
{
int loc_eng_dmn_conn_glue_msgget(const char * q_path, int mode);
int loc_eng_dmn_conn_glue_msgremove(const char * q_path, int msgqid);
int loc_eng_dmn_conn_glue_msgsnd(int msgqid, const void * msgp, size_t msgsz);
int loc_eng_dmn_conn_glue_msgrcv(int msgqid, void *msgp, size_t msgsz);
int loc_eng_dmn_conn_glue_msgflush(int msgqid);
int loc_eng_dmn_conn_glue_msgunblock(int msgqid);
template <typename CT, typename DIT>
#ifdef __cplusplus
}
#endif /* __cplusplus */
class ClientIndex : public IClientIndex <CT, DIT> {
#endif /* LOC_ENG_DMN_CONN_GLUE_MSG_H */
public:
ClientIndex ();
~ClientIndex ();
bool isSubscribedClient (CT client);
void getSubscribedList (CT client, std :: list <DIT> & out);
int remove (CT client);
void remove (const std :: list <DIT> & r, std :: list <CT> & out);
void remove (CT client, const std :: list <DIT> & r, std :: list <DIT> & out);
void add (CT client, const std :: list <DIT> & l, std :: list <DIT> & out);
private:
//Data members
std :: map < CT , std :: list <DIT> > mDataItemsPerClientMap;
};
} // namespace loc_core
#endif // #ifndef __CLIENTINDEX_H__

View File

@@ -0,0 +1,202 @@
/* Copyright (c) 2015, 2017 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 <string>
#include <algorithm>
#include <iterator>
#include <DataItemIndex.h>
#include <platform_lib_log_util.h>
#include <IDataItemObserver.h>
#include <DataItemId.h>
using namespace std;
using namespace loc_core;
template <typename CT, typename DIT>
inline DataItemIndex <CT,DIT> :: DataItemIndex () {}
template <typename CT, typename DIT>
inline DataItemIndex <CT,DIT> :: ~DataItemIndex () {}
template <typename CT, typename DIT>
void DataItemIndex <CT,DIT> :: getListOfSubscribedClients
(
DIT id,
list <CT> & out
)
{
typename map < DIT, list <CT> > :: iterator cdiIter =
mClientsPerDataItemMap.find (id);
if (cdiIter != mClientsPerDataItemMap.end ()) {
out = cdiIter->second;
}
}
template <typename CT, typename DIT>
int DataItemIndex <CT,DIT> :: remove (DIT id) {
int result = 0;
ENTRY_LOG ();
mClientsPerDataItemMap.erase (id);
EXIT_LOG_WITH_ERROR ("%d",result);
return result;
}
template <typename CT, typename DIT>
void DataItemIndex <CT,DIT> :: remove (const list <CT> & r, list <DIT> & out) {
ENTRY_LOG ();
typename map < DIT, list <CT> > :: iterator cdiIter =
mClientsPerDataItemMap.begin ();
while (cdiIter != mClientsPerDataItemMap.end()) {
typename list <CT> :: const_iterator it = r.begin ();
for (; it != r.end (); ++it) {
typename list <CT> :: iterator iter =
find
(
cdiIter->second.begin (),
cdiIter->second.end (),
*it
);
if (iter != cdiIter->second.end ()) {
cdiIter->second.erase (iter);
}
}
if (cdiIter->second.empty ()) {
out.push_back (cdiIter->first);
// Post-increment operator increases the iterator but returns the
// prevous one that will be invalidated by erase()
mClientsPerDataItemMap.erase (cdiIter++);
} else {
++cdiIter;
}
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
void DataItemIndex <CT,DIT> :: remove
(
DIT id,
const list <CT> & r,
list <CT> & out
)
{
ENTRY_LOG ();
typename map < DIT, list <CT> > :: iterator cdiIter =
mClientsPerDataItemMap.find (id);
if (cdiIter != mClientsPerDataItemMap.end ()) {
set_intersection (cdiIter->second.begin (), cdiIter->second.end (),
r.begin (), r.end (),
inserter (out, out.begin ()));
if (!out.empty ()) {
typename list <CT> :: iterator it = out.begin ();
for (; it != out.end (); ++it) {
cdiIter->second.erase (find (cdiIter->second.begin (),
cdiIter->second.end (),
*it));
}
}
if (cdiIter->second.empty ()) {
mClientsPerDataItemMap.erase (cdiIter);
EXIT_LOG_WITH_ERROR ("%d",0);
}
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
void DataItemIndex <CT,DIT> :: add
(
DIT id,
const list <CT> & l,
list <CT> & out
)
{
ENTRY_LOG ();
list <CT> difference;
typename map < DIT, list <CT> > :: iterator cdiIter =
mClientsPerDataItemMap.find (id);
if (cdiIter != mClientsPerDataItemMap.end ()) {
set_difference (l.begin (), l.end (),
cdiIter->second.begin (), cdiIter->second.end (),
inserter (difference, difference.begin ()));
if (!difference.empty ()) {
difference.sort ();
out = difference;
cdiIter->second.merge (difference);
}
} else {
out = l;
pair < DIT, list <CT> > cndipair (id, out);
mClientsPerDataItemMap.insert (cndipair);
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
template <typename CT, typename DIT>
void DataItemIndex <CT,DIT> :: add
(
CT client,
const list <DIT> & l,
list <DIT> & out
)
{
ENTRY_LOG ();
typename map < DIT, list <CT> > :: iterator cdiIter;
typename list <DIT> :: const_iterator it = l.begin ();
for (; it != l.end (); ++it) {
cdiIter = mClientsPerDataItemMap.find (*it);
if (cdiIter == mClientsPerDataItemMap.end ()) {
out.push_back (*it);
pair < DIT, list <CT> > cndiPair (*it, list <CT> (1, client));
mClientsPerDataItemMap.insert (cndiPair);
} else {
typename list<CT> :: iterator clientIter =
find
(
cdiIter->second.begin (),
cdiIter->second.end (),
client
);
if (clientIter == cdiIter->second.end()) {
cdiIter->second.push_back (client);
}
}
}
EXIT_LOG_WITH_ERROR ("%d",0);
}
// Explicit instantiation must occur in same namespace where class is defined
namespace loc_core
{
template class DataItemIndex <IDataItemObserver *, DataItemId>;
template class DataItemIndex <string, DataItemId>;
}

View File

@@ -0,0 +1,70 @@
/* Copyright (c) 2015, 2017 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 __DATAITEMINDEX_H__
#define __DATAITEMINDEX_H__
#include <list>
#include <map>
#include <IDataItemIndex.h>
using loc_core::IDataItemIndex;
namespace loc_core
{
template <typename CT, typename DIT>
class DataItemIndex : public IDataItemIndex <CT, DIT> {
public:
DataItemIndex ();
~DataItemIndex ();
void getListOfSubscribedClients (DIT id, std :: list <CT> & out);
int remove (DIT id);
void remove (const std :: list <CT> & r, std :: list <DIT> & out);
void remove (DIT id, const std :: list <CT> & r, std :: list <CT> & out);
void add (DIT id, const std :: list <CT> & l, std :: list <CT> & out);
void add (CT client, const std :: list <DIT> & l, std :: list <DIT> & out);
private:
std :: map < DIT, std :: list <CT> > mClientsPerDataItemMap;
};
} // namespace loc_core
#endif // #ifndef __DATAITEMINDEX_H__

View File

@@ -0,0 +1,83 @@
/* Copyright (c) 2015, 2017 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 __ICLIENTINDEX_H__
#define __ICLIENTINDEX_H__
#include <list>
namespace loc_core
{
template <typename CT, typename DIT>
class IClientIndex {
public:
// Checks if client is subscribed
virtual bool isSubscribedClient (CT client) = 0;
// gets subscription list
virtual void getSubscribedList (CT client, std :: list <DIT> & out) = 0;
// removes an entry
virtual int remove (CT client) = 0;
// removes std :: list of data items and returns a list of clients
// removed if any.
virtual void remove
(
const std :: list <DIT> & r,
std :: list <CT> & out
) = 0;
// removes list of data items indexed by client and returns list
// of data items removed if any.
virtual void remove
(
CT client,
const std :: list <DIT> & r,
std :: list <DIT> & out
) = 0;
// adds/modifies entry in map and returns new data items added.
virtual void add
(
CT client,
const std :: list <DIT> & l,
std :: list <DIT> & out
) = 0;
// dtor
virtual ~IClientIndex () {}
};
} // namespace loc_core
#endif // #ifndef __ICLIENTINDEX_H__

View File

@@ -0,0 +1,94 @@
/* Copyright (c) 2015, 2017 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 __IDATAITEMINDEX_H__
#define __IDATAITEMINDEX_H__
#include <list>
namespace loc_core
{
template <typename CT, typename DIT>
class IDataItemIndex {
public:
// gets std :: list of subscribed clients
virtual void getListOfSubscribedClients
(
DIT id,
std :: list <CT> & out
) = 0;
// removes an entry from
virtual int remove (DIT id) = 0;
// removes list of clients and returns a list of data items
// removed if any.
virtual void remove
(
const std :: list <CT> & r,
std :: list <DIT> & out
) = 0;
// removes list of clients indexed by data item and returns list of
// clients removed if any.
virtual void remove
(
DIT id,
const std :: list <CT> & r,
std :: list <CT> & out
) = 0;
// adds/modifies entry and returns new clients added
virtual void add
(
DIT id,
const std :: list <CT> & l,
std :: list <CT> & out
) = 0;
// adds/modifies entry and returns yet to subscribe list of data items
virtual void add
(
CT client,
const std :: list <DIT> & l,
std :: list <DIT> & out
) = 0;
// dtor
virtual ~IDataItemIndex () {}
};
} // namespace loc_core
#endif // #ifndef __IDATAITEMINDEX_H__

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011,2014 The Linux Foundation. All rights reserved.
/* Copyright (c) 2015, 2017 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,41 +27,38 @@
*
*/
#ifndef __LOC_H__
#define __LOC_H__
#include <string>
#include <IndexFactory.h>
#include <IClientIndex.h>
#include <ClientIndex.h>
#include <IDataItemIndex.h>
#include <DataItemIndex.h>
#include <IDataItemObserver.h>
#include <DataItemId.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
using namespace std;
using loc_core::IClientIndex;
using loc_core::IDataItemIndex;
using loc_core::IDataItemObserver;
using namespace loc_core;
#include <ctype.h>
#include <hardware/gps.h>
#include <gps_extended.h>
#define XTRA_DATA_MAX_SIZE 100000 /*bytes*/
typedef void (*loc_location_cb_ext) (UlpLocation* location, void* locExt);
typedef void (*loc_sv_status_cb_ext) (GpsSvStatus* sv_status, void* svExt);
typedef void* (*loc_ext_parser)(void* data);
typedef struct {
loc_location_cb_ext location_cb;
gps_status_callback status_cb;
loc_sv_status_cb_ext sv_status_cb;
gps_nmea_callback nmea_cb;
gps_set_capabilities set_capabilities_cb;
gps_acquire_wakelock acquire_wakelock_cb;
gps_release_wakelock release_wakelock_cb;
gps_create_thread create_thread_cb;
loc_ext_parser location_ext_parser;
loc_ext_parser sv_ext_parser;
gps_request_utc_time request_utc_time_cb;
gnss_set_system_info set_system_info_cb;
gnss_sv_status_callback gnss_sv_status_cb;
} LocCallbacks;
#ifdef __cplusplus
template <typename CT, typename DIT>
inline IClientIndex <CT, DIT> * IndexFactory <CT, DIT> :: createClientIndex
()
{
return new (nothrow) ClientIndex <CT, DIT> ();
}
#endif /* __cplusplus */
#endif //__LOC_H__
template <typename CT, typename DIT>
inline IDataItemIndex <CT, DIT> * IndexFactory <CT, DIT> :: createDataItemIndex
()
{
return new (nothrow) DataItemIndex <CT, DIT> ();
}
// Explicit instantiation must occur in same namespace where class is defined
namespace loc_core
{
template class IndexFactory <IDataItemObserver *, DataItemId>;
template class IndexFactory <string, DataItemId>;
}

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2015, 2017 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,18 +27,22 @@
*
*/
#ifndef LOC_ENG_LOG_H
#define LOC_ENG_LOG_H
#ifndef __INDEXFACTORY_H__
#define __INDEXFACTORY_H__
#ifdef __cplusplus
extern "C"
#include <IClientIndex.h>
#include <IDataItemIndex.h>
namespace loc_core
{
#endif
template <typename CT, typename DIT>
class IndexFactory {
#include <ctype.h>
public:
static IClientIndex <CT, DIT> * createClientIndex ();
static IDataItemIndex <CT, DIT> * createDataItemIndex ();
};
#ifdef __cplusplus
}
#endif
} // namespace loc_core
#endif /* LOC_ENG_LOG_H */
#endif // #ifndef __INDEXFACTORY_H__

View File

@@ -27,7 +27,7 @@
*
*/
#define LOG_NDDEBUG 0
#define LOG_NDEBUG 0
#define LOG_TAG "LocSvc_core_log"
#include <loc_log.h>
@@ -51,16 +51,16 @@ void LocPosMode::logv() const
/* GPS status names */
static const 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 ),
NAME_VAL( LOC_GPS_STATUS_NONE ),
NAME_VAL( LOC_GPS_STATUS_SESSION_BEGIN ),
NAME_VAL( LOC_GPS_STATUS_SESSION_END ),
NAME_VAL( LOC_GPS_STATUS_ENGINE_ON ),
NAME_VAL( LOC_GPS_STATUS_ENGINE_OFF ),
};
static const 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)
const char* loc_get_gps_status_name(LocGpsStatusValue gps_status)
{
return loc_get_name_from_val(gps_status_name, gps_status_num,
(long) gps_status);
@@ -81,7 +81,7 @@ static const loc_name_val_s_type loc_eng_position_modes[] =
};
static const 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)
const char* loc_get_position_mode_name(LocGpsPositionMode mode)
{
return loc_get_name_from_val(loc_eng_position_modes, loc_eng_position_mode_num, (long) mode);
}
@@ -90,12 +90,12 @@ const char* loc_get_position_mode_name(GpsPositionMode mode)
static const loc_name_val_s_type loc_eng_position_recurrences[] =
{
NAME_VAL( GPS_POSITION_RECURRENCE_PERIODIC ),
NAME_VAL( GPS_POSITION_RECURRENCE_SINGLE )
NAME_VAL( LOC_GPS_POSITION_RECURRENCE_PERIODIC ),
NAME_VAL( LOC_GPS_POSITION_RECURRENCE_SINGLE )
};
static const 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)
const char* loc_get_position_recurrence_name(LocGpsPositionRecurrence recur)
{
return loc_get_name_from_val(loc_eng_position_recurrences, loc_eng_position_recurrence_num, (long) recur);
}
@@ -104,23 +104,23 @@ const char* loc_get_position_recurrence_name(GpsPositionRecurrence recur)
static const 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_ALL)
NAME_VAL( LOC_GPS_DELETE_EPHEMERIS ),
NAME_VAL( LOC_GPS_DELETE_ALMANAC ),
NAME_VAL( LOC_GPS_DELETE_POSITION ),
NAME_VAL( LOC_GPS_DELETE_TIME ),
NAME_VAL( LOC_GPS_DELETE_IONO ),
NAME_VAL( LOC_GPS_DELETE_UTC ),
NAME_VAL( LOC_GPS_DELETE_HEALTH ),
NAME_VAL( LOC_GPS_DELETE_SVDIR ),
NAME_VAL( LOC_GPS_DELETE_SVSTEER ),
NAME_VAL( LOC_GPS_DELETE_SADATA ),
NAME_VAL( LOC_GPS_DELETE_RTI ),
NAME_VAL( LOC_GPS_DELETE_CELLDB_INFO ),
NAME_VAL( LOC_GPS_DELETE_ALL)
};
static const 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)
const char* loc_get_aiding_data_mask_names(LocGpsAidingData /*data*/)
{
return NULL;
}
@@ -128,15 +128,15 @@ const char* loc_get_aiding_data_mask_names(GpsAidingData data)
static const 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 )
NAME_VAL( LOC_AGPS_TYPE_INVALID ),
NAME_VAL( LOC_AGPS_TYPE_ANY ),
NAME_VAL( LOC_AGPS_TYPE_SUPL ),
NAME_VAL( LOC_AGPS_TYPE_C2K ),
NAME_VAL( LOC_AGPS_TYPE_WWAN_ANY )
};
static const 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)
const char* loc_get_agps_type_name(LocAGpsType type)
{
return loc_get_name_from_val(loc_eng_agps_types, loc_eng_agps_type_num, (long) type);
}
@@ -144,14 +144,14 @@ const char* loc_get_agps_type_name(AGpsType type)
static const 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 ),
NAME_VAL( GPS_NI_TYPE_EMERGENCY_SUPL )
NAME_VAL( LOC_GPS_NI_TYPE_VOICE ),
NAME_VAL( LOC_GPS_NI_TYPE_UMTS_SUPL ),
NAME_VAL( LOC_GPS_NI_TYPE_UMTS_CTRL_PLANE ),
NAME_VAL( LOC_GPS_NI_TYPE_EMERGENCY_SUPL )
};
static const 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)
const char* loc_get_ni_type_name(LocGpsNiType type)
{
return loc_get_name_from_val(loc_eng_ni_types, loc_eng_ni_type_num, (long) type);
}
@@ -159,13 +159,13 @@ const char* loc_get_ni_type_name(GpsNiType type)
static const 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 )
NAME_VAL( LOC_GPS_NI_RESPONSE_ACCEPT ),
NAME_VAL( LOC_GPS_NI_RESPONSE_DENY ),
NAME_VAL( LOC_GPS_NI_RESPONSE_DENY )
};
static const 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)
const char* loc_get_ni_response_name(LocGpsUserResponseType response)
{
return loc_get_name_from_val(loc_eng_ni_responses, loc_eng_ni_reponse_num, (long) response);
}
@@ -173,15 +173,15 @@ const char* loc_get_ni_response_name(GpsUserResponseType response)
static const 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 )
NAME_VAL( LOC_GPS_ENC_NONE ),
NAME_VAL( LOC_GPS_ENC_SUPL_GSM_DEFAULT ),
NAME_VAL( LOC_GPS_ENC_SUPL_UTF8 ),
NAME_VAL( LOC_GPS_ENC_SUPL_UCS2 ),
NAME_VAL( LOC_GPS_ENC_UNKNOWN )
};
static const 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)
const char* loc_get_ni_encoding_name(LocGpsNiEncodingType encoding)
{
return loc_get_name_from_val(loc_eng_ni_encodings, loc_eng_ni_encoding_num, (long) encoding);
}
@@ -229,15 +229,15 @@ const char* loc_get_position_sess_status_name(enum loc_sess_status status)
static const 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 )
NAME_VAL( LOC_GPS_REQUEST_AGPS_DATA_CONN ),
NAME_VAL( LOC_GPS_RELEASE_AGPS_DATA_CONN ),
NAME_VAL( LOC_GPS_AGPS_DATA_CONNECTED ),
NAME_VAL( LOC_GPS_AGPS_DATA_CONN_DONE ),
NAME_VAL( LOC_GPS_AGPS_DATA_CONN_FAILED )
};
static const 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)
const char* loc_get_agps_status_name(LocAGpsStatusValue status)
{
return loc_get_name_from_val(loc_eng_agps_status_names, loc_eng_agps_status_num, (long) status);
}

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2011-2013, 2016-2017 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -30,26 +30,26 @@
#ifndef LOC_CORE_LOG_H
#define LOC_CORE_LOG_H
#include <ctype.h>
#include <gps_extended.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include <ctype.h>
#include <gps_extended.h>
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_gps_status_name(LocGpsStatusValue gps_status);
const char* loc_get_position_mode_name(LocGpsPositionMode mode);
const char* loc_get_position_recurrence_name(LocGpsPositionRecurrence recur);
const char* loc_get_aiding_data_mask_names(LocGpsAidingData data);
const char* loc_get_agps_type_name(LocAGpsType type);
const char* loc_get_ni_type_name(LocGpsNiType type);
const char* loc_get_ni_response_name(LocGpsUserResponseType response);
const char* loc_get_ni_encoding_name(LocGpsNiEncodingType 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);
const char* loc_get_agps_status_name(LocAGpsStatusValue status);
#ifdef __cplusplus
}

View File

@@ -0,0 +1,76 @@
/* Copyright (c) 2015, 2017 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 __IDATAITEMOBSERVER_H__
#define __IDATAITEMOBSERVER_H__
#include <list>
#include <string>
using namespace std;
namespace loc_core
{
class IDataItemCore;
/**
* @brief IDataItemObserver interface
* @details IDataItemObserver interface;
* In OS dependent code this type serves as a handle to an OS independent instance of this interface.
*/
class IDataItemObserver {
public:
/**
* @brief Gets name of Data Item Observer
* @details Gets name of Data Item Observer
*
* @param name reference to name of Data Item Observer
*/
virtual void getName (string & name) = 0;
/**
* @brief Notify updated values of Data Items
* @details Notifys updated values of Data items
*
* @param dlist List of updated data items
*/
virtual void notify (const std :: list <IDataItemCore *> & dlist) = 0;
/**
* @brief Destructor
* @details Destructor
*/
virtual ~IDataItemObserver () {}
};
} // namespace loc_core
#endif // #ifndef __IDATAITEMOBSERVER_H__

View File

@@ -0,0 +1,129 @@
/* Copyright (c) 2015, 2017 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 __IDATAITEMSUBSCRIPTION_H__
#define __IDATAITEMSUBSCRIPTION_H__
#include <list>
#include <DataItemId.h>
namespace loc_core
{
class IDataItemObserver;
/**
* @brief IDataItemSubscription interface
* @details IDataItemSubscription interface;
* Defines an interface for operations such as subscribe,
* unsubscribe data items by their IDs.
* Must be implemented by OS dependent code.
*/
class IDataItemSubscription {
public:
/**
* @brief Subscribe for data items by their IDs
* @details Subscribe for data items by their IDs;
* An IDataItemObserver implementer invokes this method to subscribe
* for a list of DataItems by passing in their Ids.
* A symbolic invocation of this method in the following order
* subscribe ( {1,2,3}, &obj), subscribe ( {2,3,4,5}, &obj)
* where the numbers enclosed in braces indicate a list of data item Ids
* will cause this class implementer to update its subscription list for
* &obj to only contain the following Data Item Ids 1,2,3,4,5.
*
* @param l List of DataItemId
* @param o Pointer to an instance of IDataItemObserver
*/
virtual void subscribe (const std :: list <DataItemId> & l, IDataItemObserver * o = NULL) = 0;
/**
* @brief Update subscription for Data items
* @details Update subscription for Data items;
* An IDataItemObserver implementer invokes this method to update their
* subscription for a list of DataItems by passing in their Ids
* A symbolic invocation of this method in the following order
* updateSubscription ( {1,2,3}, &obj),updateSubscription ( {2,3,4,5}, &obj)
* where the numbers enclosed in braces indicate a list of data item Ids
* will cause this class implementer to update its subscription list for
* &obj to only contain the following Data Item Ids 2,3,4,5.
* Note that this method may or may not be called.
*
* @param l List of DataItemId
* @param o Pointer to an instance of IDataItemObserver
*/
virtual void updateSubscription (const std :: list <DataItemId> & l, IDataItemObserver * o = NULL) = 0;
/**
* @brief Request Data
* @details Request Data
*
* @param l List of DataItemId
* @param o Pointer to an instance of IDataItemObserver
*/
virtual void requestData (const std :: list <DataItemId> & l, IDataItemObserver * o = NULL) = 0;
/**
* @brief Unsubscribe Data items
* @details Unsubscrbe Data items;
* An IDataItemObserver implementer invokes this method to unsubscribe their
* subscription for a list of DataItems by passing in their Ids
* Suppose this class implementor has a currently active subscription list
* containing 1,2,3,4,5,6,7 for &obj then a symbolic invocation of this
* method in the following order
* unsubscribe ( {1,2,3}, &obj), unsubscribe ( {1,2,3,4}, &obj),
* unsubscribe ( {7}, &obj)
* where the numbers enclosed in braces indicate a list of data item Ids
* will cause this class implementer to update its subscription list for
* &obj to only contain the following data item id 5,6.
*
* @param l List of DataItemId
* @param o Pointer to an instance of IDataItemObserver
*/
virtual void unsubscribe (const std :: list <DataItemId> & l, IDataItemObserver * o = NULL) = 0;
/**
* @brief Unsubscribe all data items
* @details Unsubscribe all data items
*
* @param o Pointer to an instance of IDataItemObserver
*/
virtual void unsubscribeAll (IDataItemObserver * o = NULL) = 0;
/**
* @brief Destructor
* @details Destructor
*/
virtual ~IDataItemSubscription () {}
};
} // namespace loc_core
#endif // #ifndef __IDATAITEMSUBSCRIPTION_H__

View File

@@ -0,0 +1,83 @@
/* Copyright (c) 2017 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 __IFRAMEWORKACTIONREQ_H__
#define __IFRAMEWORKACTIONREQ_H__
#include <DataItemId.h>
namespace loc_core
{
/**
* @brief IFrameworkActionReq interface
* @details IFrameworkActionReq interface;
* Defines an interface for operations such as turnOn, turnOff a
* framework module described by the data item. Framework module
* could be bluetooth, wifi etc.
* Must be implemented by OS dependent code.
*
*/
class IFrameworkActionReq {
public:
/**
* @brief Turn on the framework module described by the data item.
* @details Turn on the framework module described by the data item;
* An IFrameworkActionReq implementer invokes this method to
* turn on the framework module described by the data item.
* Framework module could be bluetooth, wifi etc.
*
* @param dit DataItemId
* @param timeout Timeout after which to turn off the framework module.
*/
virtual void turnOn (DataItemId dit, int timeOut = 0) = 0;
/**
* @brief Turn off the framework module described by the data item.
* @details Turn off the framework module described by the data item;
* An IFrameworkActionReq implementer invokes this method to
* turn off the framework module described by the data item.
* Framework module could be bluetooth, wifi etc.
*
* @param dit DataItemId
*/
virtual void turnOff (DataItemId dit) = 0;
/**
* @brief Destructor
* @details Destructor
*/
virtual ~IFrameworkActionReq () {}
};
} // namespace loc_core
#endif // #ifndef __IFRAMEWORKACTIONREQ_H__

View File

@@ -0,0 +1,103 @@
/* Copyright (c) 2017, 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 __IOSOBSERVER_H__
#define __IOSOBSERVER_H__
#include <list>
#include <string>
#include <IDataItemObserver.h>
#include <IDataItemSubscription.h>
#include <IFrameworkActionReq.h>
using namespace std;
namespace loc_core
{
/**
* @brief IOsObserver interface
* @details IOsObserver interface;
* In OS dependent code this type serves as a handle to
* an OS independent instance of this interface.
*/
class IOsObserver :
public IDataItemObserver,
public IDataItemSubscription,
public IFrameworkActionReq {
public:
// To set the subscription object
virtual void setSubscriptionObj(IDataItemSubscription *subscriptionObj) = 0;
// To set the framework action request object
virtual void setFrameworkActionReqObj(IFrameworkActionReq *frameworkActionReqObj) = 0;
// IDataItemObserver Overrides
inline virtual void getName (string & /*name*/) {}
inline virtual void notify (const std::list <IDataItemCore *> & /*dlist*/) {}
// IDataItemSubscription Overrides
inline virtual void subscribe
(
const std :: list <DataItemId> & /*l*/,
IDataItemObserver * /*client*/
){}
inline virtual void updateSubscription
(
const std :: list <DataItemId> & /*l*/,
IDataItemObserver * /*client*/
){}
inline virtual void requestData
(
const std :: list <DataItemId> & /*l*/,
IDataItemObserver * /*client*/
){}
inline virtual void unsubscribe
(
const std :: list <DataItemId> & /*l*/,
IDataItemObserver * /*client*/
){}
inline virtual void unsubscribeAll (IDataItemObserver * /*client*/){}
// IFrameworkActionReq Overrides
inline virtual void turnOn (DataItemId /*dit*/, int /*timeOut*/){}
inline virtual void turnOff (DataItemId /*dit*/) {}
/**
* @brief Destructor
* @details Destructor
*/
virtual ~IOsObserver () {}
};
} // namespace loc_core
#endif // #ifndef __IOSOBSERVER_H__

912
gps/gnss/Agps.cpp Normal file
View File

@@ -0,0 +1,912 @@
/* Copyright (c) 2012-2017, 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_TAG "LocSvc_Agps"
#include <Agps.h>
#include <platform_lib_includes.h>
#include <ContextBase.h>
#include <loc_timer.h>
/* --------------------------------------------------------------------
* AGPS State Machine Methods
* -------------------------------------------------------------------*/
void AgpsStateMachine::processAgpsEvent(AgpsEvent event){
LOC_LOGD("processAgpsEvent(): SM %p, Event %d, State %d",
this, event, mState);
switch (event) {
case AGPS_EVENT_SUBSCRIBE:
processAgpsEventSubscribe();
break;
case AGPS_EVENT_UNSUBSCRIBE:
processAgpsEventUnsubscribe();
break;
case AGPS_EVENT_GRANTED:
processAgpsEventGranted();
break;
case AGPS_EVENT_RELEASED:
processAgpsEventReleased();
break;
case AGPS_EVENT_DENIED:
processAgpsEventDenied();
break;
default:
LOC_LOGE("Invalid Loc Agps Event");
}
}
void AgpsStateMachine::processAgpsEventSubscribe(){
switch (mState) {
case AGPS_STATE_RELEASED:
/* Add subscriber to list
* No notifications until we get RSRC_GRANTED */
addSubscriber(mCurrentSubscriber);
/* Send data request
* The if condition below is added so that if the data call setup
* fails for DS State Machine, we want to retry in released state.
* for Agps State Machine, sendRsrcRequest() will always return
* success. */
if (requestOrReleaseDataConn(true) == 0) {
// If data request successful, move to pending state
transitionState(AGPS_STATE_PENDING);
}
break;
case AGPS_STATE_PENDING:
/* Already requested for data connection,
* do nothing until we get RSRC_GRANTED event;
* Just add this subscriber to the list, for notifications */
addSubscriber(mCurrentSubscriber);
break;
case AGPS_STATE_ACQUIRED:
/* We already have the data connection setup,
* Notify current subscriber with GRANTED event,
* And add it to the subscriber list for further notifications. */
notifyEventToSubscriber(AGPS_EVENT_GRANTED, mCurrentSubscriber, false);
addSubscriber(mCurrentSubscriber);
break;
case AGPS_STATE_RELEASING:
addSubscriber(mCurrentSubscriber);
break;
default:
LOC_LOGE("Invalid state: %d", mState);
}
}
void AgpsStateMachine::processAgpsEventUnsubscribe(){
switch (mState) {
case AGPS_STATE_RELEASED:
notifyEventToSubscriber(
AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, false);
break;
case AGPS_STATE_PENDING:
case AGPS_STATE_ACQUIRED:
/* If the subscriber wishes to wait for connection close,
* before being removed from list, move to inactive state
* and notify */
if (mCurrentSubscriber->mWaitForCloseComplete) {
mCurrentSubscriber->mIsInactive = true;
}
else {
/* Notify only current subscriber and then delete it from
* subscriberList */
notifyEventToSubscriber(
AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true);
}
/* If no subscribers in list, release data connection */
if (mSubscriberList.empty()) {
transitionState(AGPS_STATE_RELEASED);
requestOrReleaseDataConn(false);
}
/* Some subscribers in list, but all inactive;
* Release data connection */
else if(!anyActiveSubscribers()) {
transitionState(AGPS_STATE_RELEASING);
requestOrReleaseDataConn(false);
}
break;
case AGPS_STATE_RELEASING:
/* If the subscriber wishes to wait for connection close,
* before being removed from list, move to inactive state
* and notify */
if (mCurrentSubscriber->mWaitForCloseComplete) {
mCurrentSubscriber->mIsInactive = true;
}
else {
/* Notify only current subscriber and then delete it from
* subscriberList */
notifyEventToSubscriber(
AGPS_EVENT_UNSUBSCRIBE, mCurrentSubscriber, true);
}
/* If no subscribers in list, just move the state.
* Request for releasing data connection should already have been
* sent */
if (mSubscriberList.empty()) {
transitionState(AGPS_STATE_RELEASED);
}
break;
default:
LOC_LOGE("Invalid state: %d", mState);
}
}
void AgpsStateMachine::processAgpsEventGranted(){
switch (mState) {
case AGPS_STATE_RELEASED:
case AGPS_STATE_ACQUIRED:
case AGPS_STATE_RELEASING:
LOC_LOGE("Unexpected event GRANTED in state %d", mState);
break;
case AGPS_STATE_PENDING:
// Move to acquired state
transitionState(AGPS_STATE_ACQUIRED);
notifyAllSubscribers(
AGPS_EVENT_GRANTED, false,
AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS);
break;
default:
LOC_LOGE("Invalid state: %d", mState);
}
}
void AgpsStateMachine::processAgpsEventReleased(){
switch (mState) {
case AGPS_STATE_RELEASED:
/* Subscriber list should be empty if we are in released state */
if (!mSubscriberList.empty()) {
LOC_LOGE("Unexpected event RELEASED in RELEASED state");
}
break;
case AGPS_STATE_ACQUIRED:
/* Force release received */
LOC_LOGW("Force RELEASED event in ACQUIRED state");
transitionState(AGPS_STATE_RELEASED);
notifyAllSubscribers(
AGPS_EVENT_RELEASED, true,
AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS);
break;
case AGPS_STATE_RELEASING:
/* Notify all inactive subscribers about the event */
notifyAllSubscribers(
AGPS_EVENT_RELEASED, true,
AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS);
/* If we have active subscribers now, they must be waiting for
* data conn setup */
if (anyActiveSubscribers()) {
transitionState(AGPS_STATE_PENDING);
requestOrReleaseDataConn(true);
}
/* No active subscribers, move to released state */
else {
transitionState(AGPS_STATE_RELEASED);
}
break;
case AGPS_STATE_PENDING:
/* NOOP */
break;
default:
LOC_LOGE("Invalid state: %d", mState);
}
}
void AgpsStateMachine::processAgpsEventDenied(){
switch (mState) {
case AGPS_STATE_RELEASED:
LOC_LOGE("Unexpected event DENIED in state %d", mState);
break;
case AGPS_STATE_ACQUIRED:
/* NOOP */
break;
case AGPS_STATE_RELEASING:
/* Notify all inactive subscribers about the event */
notifyAllSubscribers(
AGPS_EVENT_RELEASED, true,
AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS);
/* If we have active subscribers now, they must be waiting for
* data conn setup */
if (anyActiveSubscribers()) {
transitionState(AGPS_STATE_PENDING);
requestOrReleaseDataConn(true);
}
/* No active subscribers, move to released state */
else {
transitionState(AGPS_STATE_RELEASED);
}
break;
case AGPS_STATE_PENDING:
transitionState(AGPS_STATE_RELEASED);
notifyAllSubscribers(
AGPS_EVENT_DENIED, true,
AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS);
break;
default:
LOC_LOGE("Invalid state: %d", mState);
}
}
/* Request or Release data connection
* bool request :
* true = Request data connection
* false = Release data connection */
int AgpsStateMachine::requestOrReleaseDataConn(bool request){
AGnssExtStatusIpV4 nifRequest;
memset(&nifRequest, 0, sizeof(nifRequest));
nifRequest.type = mAgpsType;
if (request) {
LOC_LOGD("AGPS Data Conn Request");
nifRequest.status = LOC_GPS_REQUEST_AGPS_DATA_CONN;
}
else{
LOC_LOGD("AGPS Data Conn Release");
nifRequest.status = LOC_GPS_RELEASE_AGPS_DATA_CONN;
}
mAgpsManager->mFrameworkStatusV4Cb(nifRequest);
return 0;
}
void AgpsStateMachine::notifyAllSubscribers(
AgpsEvent event, bool deleteSubscriberPostNotify,
AgpsNotificationType notificationType){
LOC_LOGD("notifyAllSubscribers(): "
"SM %p, Event %d Delete %d Notification Type %d",
this, event, deleteSubscriberPostNotify, notificationType);
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
while ( it != mSubscriberList.end() ) {
AgpsSubscriber* subscriber = *it;
if (notificationType == AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS ||
(notificationType == AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS &&
subscriber->mIsInactive) ||
(notificationType == AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS &&
!subscriber->mIsInactive)) {
/* Deleting via this call would require another traversal
* through subscriber list, inefficient; hence pass in false*/
notifyEventToSubscriber(event, subscriber, false);
if (deleteSubscriberPostNotify) {
it = mSubscriberList.erase(it);
delete subscriber;
} else {
it++;
}
} else {
it++;
}
}
}
void AgpsStateMachine::notifyEventToSubscriber(
AgpsEvent event, AgpsSubscriber* subscriberToNotify,
bool deleteSubscriberPostNotify) {
LOC_LOGD("notifyEventToSubscriber(): "
"SM %p, Event %d Subscriber %p Delete %d",
this, event, subscriberToNotify, deleteSubscriberPostNotify);
switch (event) {
case AGPS_EVENT_GRANTED:
mAgpsManager->mAtlOpenStatusCb(
subscriberToNotify->mConnHandle, 1, getAPN(),
getBearer(), mAgpsType);
break;
case AGPS_EVENT_DENIED:
mAgpsManager->mAtlOpenStatusCb(
subscriberToNotify->mConnHandle, 0, getAPN(),
getBearer(), mAgpsType);
break;
case AGPS_EVENT_UNSUBSCRIBE:
case AGPS_EVENT_RELEASED:
mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1);
break;
default:
LOC_LOGE("Invalid event %d", event);
}
/* Search this subscriber in list and delete */
if (deleteSubscriberPostNotify) {
deleteSubscriber(subscriberToNotify);
}
}
void AgpsStateMachine::transitionState(AgpsState newState){
LOC_LOGD("transitionState(): SM %p, old %d, new %d",
this, mState, newState);
mState = newState;
// notify state transitions to all subscribers ?
}
void AgpsStateMachine::addSubscriber(AgpsSubscriber* subscriberToAdd){
LOC_LOGD("addSubscriber(): SM %p, Subscriber %p",
this, subscriberToAdd);
// Check if subscriber is already present in the current list
// If not, then add
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
for (; it != mSubscriberList.end(); it++) {
AgpsSubscriber* subscriber = *it;
if (subscriber->equals(subscriberToAdd)) {
LOC_LOGE("Subscriber already in list");
return;
}
}
AgpsSubscriber* cloned = subscriberToAdd->clone();
LOC_LOGD("addSubscriber(): cloned subscriber: %p", cloned);
mSubscriberList.push_back(cloned);
}
void AgpsStateMachine::deleteSubscriber(AgpsSubscriber* subscriberToDelete){
LOC_LOGD("deleteSubscriber(): SM %p, Subscriber %p",
this, subscriberToDelete);
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
while ( it != mSubscriberList.end() ) {
AgpsSubscriber* subscriber = *it;
if (subscriber && subscriber->equals(subscriberToDelete)) {
it = mSubscriberList.erase(it);
delete subscriber;
} else {
it++;
}
}
}
bool AgpsStateMachine::anyActiveSubscribers(){
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
for (; it != mSubscriberList.end(); it++) {
AgpsSubscriber* subscriber = *it;
if (!subscriber->mIsInactive) {
return true;
}
}
return false;
}
void AgpsStateMachine::setAPN(char* apn, unsigned int len){
if (NULL != mAPN) {
delete mAPN;
}
if (apn == NULL || len <= 0) {
LOC_LOGD("Invalid apn len (%d) or null apn", len);
mAPN = NULL;
mAPNLen = 0;
}
if (NULL != apn) {
mAPN = new char[len+1];
if (NULL != mAPN) {
memcpy(mAPN, apn, len);
mAPN[len] = '\0';
mAPNLen = len;
}
}
}
AgpsSubscriber* AgpsStateMachine::getSubscriber(int connHandle){
/* Go over the subscriber list */
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
for (; it != mSubscriberList.end(); it++) {
AgpsSubscriber* subscriber = *it;
if (subscriber->mConnHandle == connHandle) {
return subscriber;
}
}
/* Not found, return NULL */
return NULL;
}
AgpsSubscriber* AgpsStateMachine::getFirstSubscriber(bool isInactive){
/* Go over the subscriber list */
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
for (; it != mSubscriberList.end(); it++) {
AgpsSubscriber* subscriber = *it;
if(subscriber->mIsInactive == isInactive) {
return subscriber;
}
}
/* Not found, return NULL */
return NULL;
}
void AgpsStateMachine::dropAllSubscribers(){
LOC_LOGD("dropAllSubscribers(): SM %p", this);
/* Go over the subscriber list */
std::list<AgpsSubscriber*>::const_iterator it = mSubscriberList.begin();
while ( it != mSubscriberList.end() ) {
AgpsSubscriber* subscriber = *it;
it = mSubscriberList.erase(it);
delete subscriber;
}
}
/* --------------------------------------------------------------------
* DS State Machine Methods
* -------------------------------------------------------------------*/
const int DSStateMachine::MAX_START_DATA_CALL_RETRIES = 4;
const int DSStateMachine::DATA_CALL_RETRY_DELAY_MSEC = 500;
/* Overridden method
* DS SM needs to handle one scenario differently */
void DSStateMachine::processAgpsEvent(AgpsEvent event) {
LOC_LOGD("DSStateMachine::processAgpsEvent() %d", event);
/* DS Client call setup APIs don't return failure/closure separately.
* Hence we receive RELEASED event in both cases.
* If we are in pending, we should consider RELEASED as DENIED */
if (event == AGPS_EVENT_RELEASED && mState == AGPS_STATE_PENDING) {
LOC_LOGD("Translating RELEASED to DENIED event");
event = AGPS_EVENT_DENIED;
}
/* Redirect process to base class */
AgpsStateMachine::processAgpsEvent(event);
}
/* Timer Callback
* For the retry timer started in case of DS Client call setup failure */
void delay_callback(void *callbackData, int result)
{
LOC_LOGD("delay_callback(): cbData %p", callbackData);
(void)result;
if (callbackData == NULL) {
LOC_LOGE("delay_callback(): NULL argument received !");
return;
}
DSStateMachine* dsStateMachine = (DSStateMachine *)callbackData;
dsStateMachine->retryCallback();
}
/* Invoked from Timer Callback
* For the retry timer started in case of DS Client call setup failure */
void DSStateMachine :: retryCallback()
{
LOC_LOGD("DSStateMachine::retryCallback()");
/* Request SUPL ES
* There must be at least one active subscriber in list */
AgpsSubscriber* subscriber = getFirstSubscriber(false);
if (subscriber == NULL) {
LOC_LOGE("No active subscriber for DS Client call setup");
return;
}
/* Send message to retry */
mAgpsManager->mSendMsgToAdapterQueueFn(
new AgpsMsgRequestATL(
mAgpsManager, subscriber->mConnHandle,
LOC_AGPS_TYPE_SUPL_ES));
}
/* Overridden method
* Request or Release data connection
* bool request :
* true = Request data connection
* false = Release data connection */
int DSStateMachine::requestOrReleaseDataConn(bool request){
LOC_LOGD("DSStateMachine::requestOrReleaseDataConn(): "
"request %d", request);
/* Release data connection required ? */
if (!request && mAgpsManager->mDSClientStopDataCallFn) {
mAgpsManager->mDSClientStopDataCallFn();
LOC_LOGD("DS Client release data call request sent !");
return 0;
}
/* Setup data connection request
* There must be at least one active subscriber in list */
AgpsSubscriber* subscriber = getFirstSubscriber(false);
if (subscriber == NULL) {
LOC_LOGE("No active subscriber for DS Client call setup");
return -1;
}
/* DS Client Fn registered ? */
if (!mAgpsManager->mDSClientOpenAndStartDataCallFn) {
LOC_LOGE("DS Client start fn not registered, fallback to SUPL ATL");
notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
return -1;
}
/* Setup the call */
int ret = mAgpsManager->mDSClientOpenAndStartDataCallFn();
/* Check if data call start failed */
switch (ret) {
case LOC_API_ADAPTER_ERR_ENGINE_BUSY:
LOC_LOGE("DS Client open call failed, err: %d", ret);
mRetries++;
if (mRetries > MAX_START_DATA_CALL_RETRIES) {
LOC_LOGE("DS Client call retries exhausted, "
"falling back to normal SUPL ATL");
notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
}
/* Retry DS Client call setup after some delay */
else if(loc_timer_start(
DATA_CALL_RETRY_DELAY_MSEC, delay_callback, this)) {
LOC_LOGE("Error: Could not start delay thread\n");
return -1;
}
break;
case LOC_API_ADAPTER_ERR_UNSUPPORTED:
LOC_LOGE("No emergency profile found. Fall back to normal SUPL ATL");
notifyEventToSubscriber(AGPS_EVENT_DENIED, subscriber, false);
break;
case LOC_API_ADAPTER_ERR_SUCCESS:
LOC_LOGD("Request to start data call sent");
break;
default:
LOC_LOGE("Unrecognized return value: %d", ret);
}
return ret;
}
void DSStateMachine::notifyEventToSubscriber(
AgpsEvent event, AgpsSubscriber* subscriberToNotify,
bool deleteSubscriberPostNotify) {
LOC_LOGD("DSStateMachine::notifyEventToSubscriber(): "
"SM %p, Event %d Subscriber %p Delete %d",
this, event, subscriberToNotify, deleteSubscriberPostNotify);
switch (event) {
case AGPS_EVENT_GRANTED:
mAgpsManager->mAtlOpenStatusCb(
subscriberToNotify->mConnHandle, 1, NULL,
AGPS_APN_BEARER_INVALID, LOC_AGPS_TYPE_SUPL_ES);
break;
case AGPS_EVENT_DENIED:
/* Now try with regular SUPL
* We need to send request via message queue */
mRetries = 0;
mAgpsManager->mSendMsgToAdapterQueueFn(
new AgpsMsgRequestATL(
mAgpsManager, subscriberToNotify->mConnHandle,
LOC_AGPS_TYPE_SUPL));
break;
case AGPS_EVENT_UNSUBSCRIBE:
mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1);
break;
case AGPS_EVENT_RELEASED:
mAgpsManager->mDSClientCloseDataCallFn();
mAgpsManager->mAtlCloseStatusCb(subscriberToNotify->mConnHandle, 1);
break;
default:
LOC_LOGE("Invalid event %d", event);
}
/* Search this subscriber in list and delete */
if (deleteSubscriberPostNotify) {
deleteSubscriber(subscriberToNotify);
}
}
/* --------------------------------------------------------------------
* Loc AGPS Manager Methods
* -------------------------------------------------------------------*/
/* CREATE AGPS STATE MACHINES
* Must be invoked in Msg Handler context */
void AgpsManager::createAgpsStateMachines() {
LOC_LOGD("AgpsManager::createAgpsStateMachines");
bool agpsCapable =
((loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSA) ||
(loc_core::ContextBase::mGps_conf.CAPABILITIES & LOC_GPS_CAPABILITY_MSB));
if (NULL == mInternetNif) {
mInternetNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_WWAN_ANY);
LOC_LOGD("Internet NIF: %p", mInternetNif);
}
if (agpsCapable) {
if (NULL == mAgnssNif) {
mAgnssNif = new AgpsStateMachine(this, LOC_AGPS_TYPE_SUPL);
LOC_LOGD("AGNSS NIF: %p", mAgnssNif);
}
if (NULL == mDsNif &&
loc_core::ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
if(!mDSClientInitFn){
LOC_LOGE("DS Client Init Fn not registered !");
return;
}
if (mDSClientInitFn(false) != 0) {
LOC_LOGE("Failed to init data service client");
return;
}
mDsNif = new DSStateMachine(this);
LOC_LOGD("DS NIF: %p", mDsNif);
}
}
}
AgpsStateMachine* AgpsManager::getAgpsStateMachine(AGpsExtType agpsType) {
LOC_LOGD("AgpsManager::getAgpsStateMachine(): agpsType %d", agpsType);
switch (agpsType) {
case LOC_AGPS_TYPE_INVALID:
case LOC_AGPS_TYPE_SUPL:
if (mAgnssNif == NULL) {
LOC_LOGE("NULL AGNSS NIF !");
}
return mAgnssNif;
case LOC_AGPS_TYPE_SUPL_ES:
if (loc_core::ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
if (mDsNif == NULL) {
createAgpsStateMachines();
}
return mDsNif;
} else {
return mAgnssNif;
}
default:
return mInternetNif;
}
LOC_LOGE("No SM found !");
return NULL;
}
void AgpsManager::requestATL(int connHandle, AGpsExtType agpsType){
LOC_LOGD("AgpsManager::requestATL(): connHandle %d, agpsType %d",
connHandle, agpsType);
AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
if (sm == NULL) {
LOC_LOGE("No AGPS State Machine for agpsType: %d", agpsType);
mAtlOpenStatusCb(
connHandle, 0, NULL, AGPS_APN_BEARER_INVALID, agpsType);
return;
}
/* Invoke AGPS SM processing */
AgpsSubscriber subscriber(connHandle, false, false);
sm->setCurrentSubscriber(&subscriber);
/* If DS State Machine, wait for close complete */
if (agpsType == LOC_AGPS_TYPE_SUPL_ES) {
subscriber.mWaitForCloseComplete = true;
}
/* Send subscriber event */
sm->processAgpsEvent(AGPS_EVENT_SUBSCRIBE);
}
void AgpsManager::releaseATL(int connHandle){
LOC_LOGD("AgpsManager::releaseATL(): connHandle %d", connHandle);
/* First find the subscriber with specified handle.
* We need to search in all state machines. */
AgpsStateMachine* sm = NULL;
AgpsSubscriber* subscriber = NULL;
if (mAgnssNif &&
(subscriber = mAgnssNif->getSubscriber(connHandle)) != NULL) {
sm = mAgnssNif;
}
else if (mInternetNif &&
(subscriber = mInternetNif->getSubscriber(connHandle)) != NULL) {
sm = mInternetNif;
}
else if (mDsNif &&
(subscriber = mDsNif->getSubscriber(connHandle)) != NULL) {
sm = mDsNif;
}
if (sm == NULL) {
LOC_LOGE("Subscriber with connHandle %d not found in any SM",
connHandle);
mAtlCloseStatusCb(connHandle, 0);
return;
}
/* Now send unsubscribe event */
sm->setCurrentSubscriber(subscriber);
sm->processAgpsEvent(AGPS_EVENT_UNSUBSCRIBE);
}
void AgpsManager::reportDataCallOpened(){
LOC_LOGD("AgpsManager::reportDataCallOpened");
if (mDsNif) {
mDsNif->processAgpsEvent(AGPS_EVENT_GRANTED);
}
}
void AgpsManager::reportDataCallClosed(){
LOC_LOGD("AgpsManager::reportDataCallClosed");
if (mDsNif) {
mDsNif->processAgpsEvent(AGPS_EVENT_RELEASED);
}
}
void AgpsManager::reportAtlOpenSuccess(
AGpsExtType agpsType, char* apnName, int apnLen,
AGpsBearerType bearerType){
LOC_LOGD("AgpsManager::reportAtlOpenSuccess(): "
"AgpsType %d, APN [%s], Len %d, BearerType %d",
agpsType, apnName, apnLen, bearerType);
/* Find the state machine instance */
AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
/* Set bearer and apn info in state machine instance */
sm->setBearer(bearerType);
sm->setAPN(apnName, apnLen);
/* Send GRANTED event to state machine */
sm->processAgpsEvent(AGPS_EVENT_GRANTED);
}
void AgpsManager::reportAtlOpenFailed(AGpsExtType agpsType){
LOC_LOGD("AgpsManager::reportAtlOpenFailed(): AgpsType %d", agpsType);
/* Fetch SM and send DENIED event */
AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
sm->processAgpsEvent(AGPS_EVENT_DENIED);
}
void AgpsManager::reportAtlClosed(AGpsExtType agpsType){
LOC_LOGD("AgpsManager::reportAtlClosed(): AgpsType %d", agpsType);
/* Fetch SM and send RELEASED event */
AgpsStateMachine* sm = getAgpsStateMachine(agpsType);
sm->processAgpsEvent(AGPS_EVENT_RELEASED);
}
void AgpsManager::handleModemSSR(){
LOC_LOGD("AgpsManager::handleModemSSR");
/* Drop subscribers from all state machines */
if (mAgnssNif) {
mAgnssNif->dropAllSubscribers();
}
if (mInternetNif) {
mInternetNif->dropAllSubscribers();
}
if (mDsNif) {
mDsNif->dropAllSubscribers();
}
// reinitialize DS client in SSR mode
if (loc_core::ContextBase::mGps_conf.
USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
mDSClientStopDataCallFn();
mDSClientCloseDataCallFn();
mDSClientReleaseFn();
mDSClientInitFn(true);
}
}

383
gps/gnss/Agps.h Normal file
View File

@@ -0,0 +1,383 @@
/* Copyright (c) 2012-2017, 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 AGPS_H
#define AGPS_H
#include <functional>
#include <list>
#include <MsgTask.h>
#include <gps_extended_c.h>
#include <platform_lib_log_util.h>
/* ATL callback function pointers
* Passed in by Adapter to AgpsManager */
typedef std::function<void(
int handle, int isSuccess, char* apn,
AGpsBearerType bearerType, AGpsExtType agpsType)> AgpsAtlOpenStatusCb;
typedef std::function<void(int handle, int isSuccess)> AgpsAtlCloseStatusCb;
/* DS Client control APIs
* Passed in by Adapter to AgpsManager */
typedef std::function<int(bool isDueToSSR)> AgpsDSClientInitFn;
typedef std::function<int()> AgpsDSClientOpenAndStartDataCallFn;
typedef std::function<void()> AgpsDSClientStopDataCallFn;
typedef std::function<void()> AgpsDSClientCloseDataCallFn;
typedef std::function<void()> AgpsDSClientReleaseFn;
/* Post message to adapter's message queue */
typedef std::function<void(LocMsg* msg)> SendMsgToAdapterMsgQueueFn;
/* AGPS States */
typedef enum {
AGPS_STATE_INVALID = 0,
AGPS_STATE_RELEASED,
AGPS_STATE_PENDING,
AGPS_STATE_ACQUIRED,
AGPS_STATE_RELEASING
} AgpsState;
typedef enum {
AGPS_EVENT_INVALID = 0,
AGPS_EVENT_SUBSCRIBE,
AGPS_EVENT_UNSUBSCRIBE,
AGPS_EVENT_GRANTED,
AGPS_EVENT_RELEASED,
AGPS_EVENT_DENIED
} AgpsEvent;
/* Notification Types sent to subscribers */
typedef enum {
AGPS_NOTIFICATION_TYPE_INVALID = 0,
/* Meant for all subscribers, either active or inactive */
AGPS_NOTIFICATION_TYPE_FOR_ALL_SUBSCRIBERS,
/* Meant for only inactive subscribers */
AGPS_NOTIFICATION_TYPE_FOR_INACTIVE_SUBSCRIBERS,
/* Meant for only active subscribers */
AGPS_NOTIFICATION_TYPE_FOR_ACTIVE_SUBSCRIBERS
} AgpsNotificationType;
/* Classes in this header */
class AgpsSubscriber;
class AgpsManager;
class AgpsStateMachine;
class DSStateMachine;
/* SUBSCRIBER
* Each Subscriber instance corresponds to one AGPS request,
* received by the AGPS state machine */
class AgpsSubscriber {
public:
int mConnHandle;
/* Does this subscriber wait for data call close complete,
* before being notified ATL close ?
* While waiting for data call close, subscriber will be in
* inactive state. */
bool mWaitForCloseComplete;
bool mIsInactive;
inline AgpsSubscriber(
int connHandle, bool waitForCloseComplete, bool isInactive) :
mConnHandle(connHandle),
mWaitForCloseComplete(waitForCloseComplete),
mIsInactive(isInactive) {}
inline virtual ~AgpsSubscriber() {}
inline virtual bool equals(const AgpsSubscriber *s) const
{ return (mConnHandle == s->mConnHandle); }
inline virtual AgpsSubscriber* clone()
{ return new AgpsSubscriber(
mConnHandle, mWaitForCloseComplete, mIsInactive); }
};
/* AGPS STATE MACHINE */
class AgpsStateMachine {
protected:
/* AGPS Manager instance, from where this state machine is created */
AgpsManager* mAgpsManager;
/* List of all subscribers for this State Machine.
* Once a subscriber is notified for ATL open/close status,
* it is deleted */
std::list<AgpsSubscriber*> mSubscriberList;
/* Current subscriber, whose request this State Machine is
* currently processing */
AgpsSubscriber* mCurrentSubscriber;
/* Current state for this state machine */
AgpsState mState;
private:
/* AGPS Type for this state machine
LOC_AGPS_TYPE_ANY 0
LOC_AGPS_TYPE_SUPL 1
LOC_AGPS_TYPE_WWAN_ANY 3
LOC_AGPS_TYPE_SUPL_ES 5 */
AGpsExtType mAgpsType;
/* APN and IP Type info for AGPS Call */
char* mAPN;
unsigned int mAPNLen;
AGpsBearerType mBearer;
public:
/* CONSTRUCTOR */
AgpsStateMachine(AgpsManager* agpsManager, AGpsExtType agpsType):
mAgpsManager(agpsManager), mSubscriberList(),
mCurrentSubscriber(NULL), mState(AGPS_STATE_RELEASED),
mAgpsType(agpsType), mAPN(NULL), mAPNLen(0),
mBearer(AGPS_APN_BEARER_INVALID) {};
virtual ~AgpsStateMachine() { if(NULL != mAPN) delete[] mAPN; };
/* Getter/Setter methods */
void setAPN(char* apn, unsigned int len);
inline char* getAPN() const { return (char*)mAPN; }
inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; }
inline AGpsBearerType getBearer() const { return mBearer; }
inline AGpsExtType getType() const { return mAgpsType; }
inline void setCurrentSubscriber(AgpsSubscriber* subscriber)
{ mCurrentSubscriber = subscriber; }
/* Fetch subscriber with specified handle */
AgpsSubscriber* getSubscriber(int connHandle);
/* Fetch first active or inactive subscriber in list
* isInactive = true : fetch first inactive subscriber
* isInactive = false : fetch first active subscriber */
AgpsSubscriber* getFirstSubscriber(bool isInactive);
/* Process LOC AGPS Event being passed in
* onRsrcEvent */
virtual void processAgpsEvent(AgpsEvent event);
/* Drop all subscribers, in case of Modem SSR */
void dropAllSubscribers();
protected:
/* Remove the specified subscriber from list if present.
* Also delete the subscriber instance. */
void deleteSubscriber(AgpsSubscriber* subscriber);
private:
/* Send call setup request to framework
* sendRsrcRequest(LOC_GPS_REQUEST_AGPS_DATA_CONN)
* sendRsrcRequest(LOC_GPS_RELEASE_AGPS_DATA_CONN) */
virtual int requestOrReleaseDataConn(bool request);
/* Individual event processing methods */
void processAgpsEventSubscribe();
void processAgpsEventUnsubscribe();
void processAgpsEventGranted();
void processAgpsEventReleased();
void processAgpsEventDenied();
/* Clone the passed in subscriber and add to the subscriber list
* if not already present */
void addSubscriber(AgpsSubscriber* subscriber);
/* Notify subscribers about AGPS events */
void notifyAllSubscribers(
AgpsEvent event, bool deleteSubscriberPostNotify,
AgpsNotificationType notificationType);
virtual void notifyEventToSubscriber(
AgpsEvent event, AgpsSubscriber* subscriber,
bool deleteSubscriberPostNotify);
/* Do we have any subscribers in active state */
bool anyActiveSubscribers();
/* Transition state */
void transitionState(AgpsState newState);
};
/* DS STATE MACHINE */
class DSStateMachine : public AgpsStateMachine {
private:
static const int MAX_START_DATA_CALL_RETRIES;
static const int DATA_CALL_RETRY_DELAY_MSEC;
int mRetries;
public:
/* CONSTRUCTOR */
DSStateMachine(AgpsManager* agpsManager):
AgpsStateMachine(agpsManager, LOC_AGPS_TYPE_SUPL_ES), mRetries(0) {}
/* Overridden method
* DS SM needs to handle one event differently */
void processAgpsEvent(AgpsEvent event);
/* Retry callback, used in case call failure */
void retryCallback();
private:
/* Overridden method, different functionality for DS SM
* Send call setup request to framework
* sendRsrcRequest(LOC_GPS_REQUEST_AGPS_DATA_CONN)
* sendRsrcRequest(LOC_GPS_RELEASE_AGPS_DATA_CONN) */
int requestOrReleaseDataConn(bool request);
/* Overridden method, different functionality for DS SM */
void notifyEventToSubscriber(
AgpsEvent event, AgpsSubscriber* subscriber,
bool deleteSubscriberPostNotify);
};
/* LOC AGPS MANAGER */
class AgpsManager {
friend class AgpsStateMachine;
friend class DSStateMachine;
public:
/* CONSTRUCTOR */
AgpsManager():
mFrameworkStatusV4Cb(NULL),
mAtlOpenStatusCb(), mAtlCloseStatusCb(),
mDSClientInitFn(), mDSClientOpenAndStartDataCallFn(),
mDSClientStopDataCallFn(), mDSClientCloseDataCallFn(), mDSClientReleaseFn(),
mSendMsgToAdapterQueueFn(),
mAgnssNif(NULL), mInternetNif(NULL), mDsNif(NULL) {}
/* Register callbacks */
void registerCallbacks(
AgnssStatusIpV4Cb frameworkStatusV4Cb,
AgpsAtlOpenStatusCb atlOpenStatusCb,
AgpsAtlCloseStatusCb atlCloseStatusCb,
AgpsDSClientInitFn dsClientInitFn,
AgpsDSClientOpenAndStartDataCallFn dsClientOpenAndStartDataCallFn,
AgpsDSClientStopDataCallFn dsClientStopDataCallFn,
AgpsDSClientCloseDataCallFn dsClientCloseDataCallFn,
AgpsDSClientReleaseFn dsClientReleaseFn,
SendMsgToAdapterMsgQueueFn sendMsgToAdapterQueueFn ){
mFrameworkStatusV4Cb = frameworkStatusV4Cb;
mAtlOpenStatusCb = atlOpenStatusCb;
mAtlCloseStatusCb = atlCloseStatusCb;
mDSClientInitFn = dsClientInitFn;
mDSClientOpenAndStartDataCallFn = dsClientOpenAndStartDataCallFn;
mDSClientStopDataCallFn = dsClientStopDataCallFn;
mDSClientCloseDataCallFn = dsClientCloseDataCallFn;
mDSClientReleaseFn = dsClientReleaseFn;
mSendMsgToAdapterQueueFn = sendMsgToAdapterQueueFn;
}
/* Create all AGPS state machines */
void createAgpsStateMachines();
/* Process incoming ATL requests */
void requestATL(int connHandle, AGpsExtType agpsType);
void releaseATL(int connHandle);
/* Process incoming DS Client data call events */
void reportDataCallOpened();
void reportDataCallClosed();
/* Process incoming framework data call events */
void reportAtlOpenSuccess(AGpsExtType agpsType, char* apnName, int apnLen,
AGpsBearerType bearerType);
void reportAtlOpenFailed(AGpsExtType agpsType);
void reportAtlClosed(AGpsExtType agpsType);
/* Handle Modem SSR */
void handleModemSSR();
protected:
AgnssStatusIpV4Cb mFrameworkStatusV4Cb;
AgpsAtlOpenStatusCb mAtlOpenStatusCb;
AgpsAtlCloseStatusCb mAtlCloseStatusCb;
AgpsDSClientInitFn mDSClientInitFn;
AgpsDSClientOpenAndStartDataCallFn mDSClientOpenAndStartDataCallFn;
AgpsDSClientStopDataCallFn mDSClientStopDataCallFn;
AgpsDSClientCloseDataCallFn mDSClientCloseDataCallFn;
AgpsDSClientReleaseFn mDSClientReleaseFn;
SendMsgToAdapterMsgQueueFn mSendMsgToAdapterQueueFn;
AgpsStateMachine* mAgnssNif;
AgpsStateMachine* mInternetNif;
AgpsStateMachine* mDsNif;
private:
/* Fetch state machine for handling request ATL call */
AgpsStateMachine* getAgpsStateMachine(AGpsExtType agpsType);
};
/* Request SUPL/INTERNET/SUPL_ES ATL
* This LocMsg is defined in this header since it has to be used from more
* than one place, other Agps LocMsg are restricted to GnssAdapter and
* declared inline */
struct AgpsMsgRequestATL: public LocMsg {
AgpsManager* mAgpsManager;
int mConnHandle;
AGpsExtType mAgpsType;
inline AgpsMsgRequestATL(AgpsManager* agpsManager, int connHandle,
AGpsExtType agpsType) :
LocMsg(), mAgpsManager(agpsManager), mConnHandle(connHandle), mAgpsType(
agpsType) {
LOC_LOGV("AgpsMsgRequestATL");
}
inline virtual void proc() const {
LOC_LOGV("AgpsMsgRequestATL::proc()");
mAgpsManager->requestATL(mConnHandle, mAgpsType);
}
};
namespace AgpsUtils {
AGpsBearerType ipTypeToBearerType(LocApnIpType ipType);
LocApnIpType bearerTypeToIpType(AGpsBearerType bearerType);
}
#endif /* AGPS_H */

47
gps/gnss/Android.mk Normal file
View File

@@ -0,0 +1,47 @@
ifneq ($(BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE),)
ifneq ($(BUILD_TINY_ANDROID),true)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libgnss
LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib
LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := \
libutils \
libcutils \
libdl \
liblog \
libloc_core \
libgps.utils
LOCAL_SRC_FILES += \
location_gnss.cpp \
GnssAdapter.cpp \
Agps.cpp \
XtraSystemStatusObserver.cpp
LOCAL_CFLAGS += \
-fno-short-enums \
ifeq ($(TARGET_BUILD_VARIANT),user)
LOCAL_CFLAGS += -DTARGET_BUILD_VARIANT_USER
endif
LOCAL_HEADER_LIBRARIES := \
libgps.utils_headers \
libloc_core_headers \
libloc_pla_headers \
liblocation_api_headers
LOCAL_CFLAGS += $(GNSS_CFLAGS)
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
endif # not BUILD_TINY_ANDROID
endif # BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE

3131
gps/gnss/GnssAdapter.cpp Normal file

File diff suppressed because it is too large Load Diff

287
gps/gnss/GnssAdapter.h Normal file
View File

@@ -0,0 +1,287 @@
/* Copyright (c) 2017, 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 GNSS_ADAPTER_H
#define GNSS_ADAPTER_H
#include <LocAdapterBase.h>
#include <LocDualContext.h>
#include <UlpProxyBase.h>
#include <LocationAPI.h>
#include <Agps.h>
#include <SystemStatus.h>
#include <XtraSystemStatusObserver.h>
#define MAX_URL_LEN 256
#define NMEA_SENTENCE_MAX_LENGTH 200
#define GLONASS_SV_ID_OFFSET 64
#define MAX_SATELLITES_IN_USE 12
#define LOC_NI_NO_RESPONSE_TIME 20
#define LOC_GPS_NI_RESPONSE_IGNORE 4
class GnssAdapter;
typedef struct {
pthread_t thread; /* NI thread */
uint32_t respTimeLeft; /* examine time for NI response */
bool respRecvd; /* NI User reponse received or not from Java layer*/
void* rawRequest;
uint32_t reqID; /* ID to check against response */
GnssNiResponse resp;
pthread_cond_t tCond;
pthread_mutex_t tLock;
GnssAdapter* adapter;
} NiSession;
typedef struct {
NiSession session; /* SUPL NI Session */
NiSession sessionEs; /* Emergency SUPL NI Session */
uint32_t reqIDCounter;
} NiData;
typedef enum {
NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA
NMEA_PROVIDER_MP // Modem Processor Provider of NMEA
} NmeaProviderType;
typedef struct {
GnssSvType svType;
const char* talker;
uint64_t mask;
uint32_t svIdOffset;
} NmeaSvMeta;
using namespace loc_core;
namespace loc_core {
class SystemStatus;
}
class GnssAdapter : public LocAdapterBase {
/* ==== ULP ============================================================================ */
UlpProxyBase* mUlpProxy;
/* ==== CLIENT ========================================================================= */
typedef std::map<LocationAPI*, LocationCallbacks> ClientDataMap;
ClientDataMap mClientData;
/* ==== TRACKING ======================================================================= */
LocationSessionMap mTrackingSessions;
LocPosMode mUlpPositionMode;
GnssSvUsedInPosition mGnssSvIdUsedInPosition;
bool mGnssSvIdUsedInPosAvail;
/* ==== CONTROL ======================================================================== */
LocationControlCallbacks mControlCallbacks;
uint32_t mPowerVoteId;
uint32_t mNmeaMask;
/* ==== NI ============================================================================= */
NiData mNiData;
/* ==== AGPS ========================================================*/
// This must be initialized via initAgps()
AgpsManager mAgpsManager;
AgpsCbInfo mAgpsCbInfo;
/* === SystemStatus ===================================================================== */
SystemStatus* mSystemStatus;
std::string mServerUrl;
XtraSystemStatusObserver mXtraObserver;
/*==== CONVERSION ===================================================================*/
static void convertOptions(LocPosMode& out, const LocationOptions& options);
static void convertLocation(Location& out, const LocGpsLocation& locGpsLocation,
const GpsLocationExtended& locationExtended,
const LocPosTechMask techMask);
static void convertLocationInfo(GnssLocationInfoNotification& out,
const GpsLocationExtended& locationExtended);
public:
GnssAdapter();
virtual inline ~GnssAdapter() { delete mUlpProxy; }
/* ==== SSR ============================================================================ */
/* ======== EVENTS ====(Called from QMI Thread)========================================= */
virtual void handleEngineUpEvent();
/* ======== UTILITIES ================================================================== */
void restartSessions();
/* ==== ULP ============================================================================ */
/* ======== COMMANDS ====(Called from ULP Thread)==================================== */
virtual void setUlpProxyCommand(UlpProxyBase* ulp);
/* ======== UTILITIES ================================================================== */
void setUlpProxy(UlpProxyBase* ulp);
inline UlpProxyBase* getUlpProxy() { return mUlpProxy; }
/* ==== CLIENT ========================================================================= */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
void addClientCommand(LocationAPI* client, const LocationCallbacks& callbacks);
void removeClientCommand(LocationAPI* client);
void requestCapabilitiesCommand(LocationAPI* client);
/* ======== UTILITIES ================================================================== */
void saveClient(LocationAPI* client, const LocationCallbacks& callbacks);
void eraseClient(LocationAPI* client);
void updateClientsEventMask();
void stopClientSessions(LocationAPI* client);
LocationCallbacks getClientCallbacks(LocationAPI* client);
LocationCapabilitiesMask getCapabilities();
void broadcastCapabilities(LocationCapabilitiesMask);
/* ==== TRACKING ======================================================================= */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
uint32_t startTrackingCommand(LocationAPI* client, LocationOptions& options);
void updateTrackingOptionsCommand(LocationAPI* client, uint32_t id, LocationOptions& options);
void stopTrackingCommand(LocationAPI* client, uint32_t id);
/* ======================(Called from ULP Thread)======================================= */
virtual void setPositionModeCommand(LocPosMode& locPosMode);
virtual void startTrackingCommand();
virtual void stopTrackingCommand();
virtual void getZppCommand();
/* ======== RESPONSES ================================================================== */
void reportResponse(LocationAPI* client, LocationError err, uint32_t sessionId);
/* ======== UTILITIES ================================================================== */
bool hasTrackingCallback(LocationAPI* client);
bool hasMeasurementsCallback(LocationAPI* client);
bool isTrackingSession(LocationAPI* client, uint32_t sessionId);
void saveTrackingSession(LocationAPI* client, uint32_t sessionId,
const LocationOptions& options);
void eraseTrackingSession(LocationAPI* client, uint32_t sessionId);
bool setUlpPositionMode(const LocPosMode& mode);
LocPosMode& getUlpPositionMode() { return mUlpPositionMode; }
LocationError startTrackingMultiplex(const LocationOptions& options);
LocationError startTracking(const LocationOptions& options);
LocationError stopTrackingMultiplex(LocationAPI* client, uint32_t id);
LocationError stopTracking();
LocationError updateTrackingMultiplex(LocationAPI* client, uint32_t id,
const LocationOptions& options);
/* ==== NI ============================================================================= */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
void gnssNiResponseCommand(LocationAPI* client, uint32_t id, GnssNiResponse response);
/* ======================(Called from NI Thread)======================================== */
void gnssNiResponseCommand(GnssNiResponse response, void* rawRequest);
/* ======== UTILITIES ================================================================== */
bool hasNiNotifyCallback(LocationAPI* client);
NiData& getNiData() { return mNiData; }
/* ==== CONTROL ======================================================================== */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
uint32_t enableCommand(LocationTechnologyType techType);
void disableCommand(uint32_t id);
void setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks);
void readConfigCommand();
void setConfigCommand();
uint32_t* gnssUpdateConfigCommand(GnssConfig config);
uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data);
void initDefaultAgpsCommand();
void initAgpsCommand(const AgpsCbInfo& cbInfo);
void dataConnOpenCommand(AGpsExtType agpsType,
const char* apnName, int apnLen, AGpsBearerType bearerType);
void dataConnClosedCommand(AGpsExtType agpsType);
void dataConnFailedCommand(AGpsExtType agpsType);
/* ======== RESPONSES ================================================================== */
void reportResponse(LocationError err, uint32_t sessionId);
void reportResponse(size_t count, LocationError* errs, uint32_t* ids);
/* ======== UTILITIES ================================================================== */
LocationControlCallbacks& getControlCallbacks() { return mControlCallbacks; }
void setControlCallbacks(const LocationControlCallbacks& controlCallbacks)
{ mControlCallbacks = controlCallbacks; }
void setPowerVoteId(uint32_t id) { mPowerVoteId = id; }
uint32_t getPowerVoteId() { return mPowerVoteId; }
bool resolveInAddress(const char* hostAddress, struct in_addr* inAddress);
virtual bool isInSession() { return !mTrackingSessions.empty(); }
void initDefaultAgps();
/* ==== REPORTS ======================================================================== */
/* ======== EVENTS ====(Called from QMI/ULP Thread)===================================== */
virtual void reportPositionEvent(const UlpLocation& ulpLocation,
const GpsLocationExtended& locationExtended,
enum loc_sess_status status,
LocPosTechMask techMask,
bool fromUlp=false);
virtual void reportSvEvent(const GnssSvNotification& svNotify, bool fromUlp=false);
virtual void reportNmeaEvent(const char* nmea, size_t length, bool fromUlp=false);
virtual bool requestNiNotifyEvent(const GnssNiNotification& notify, const void* data);
virtual void reportGnssMeasurementDataEvent(const GnssMeasurementsNotification& measurements,
int msInWeek);
virtual void reportSvMeasurementEvent(GnssSvMeasurementSet &svMeasurementSet);
virtual void reportSvPolynomialEvent(GnssSvPolynomial &svPolynomial);
virtual bool requestATL(int connHandle, LocAGpsType agps_type);
virtual bool releaseATL(int connHandle);
virtual bool requestSuplES(int connHandle);
virtual bool reportDataCallOpened();
virtual bool reportDataCallClosed();
/* ======== UTILITIES ================================================================= */
void reportPosition(const UlpLocation &ulpLocation,
const GpsLocationExtended &locationExtended,
enum loc_sess_status status,
LocPosTechMask techMask);
void reportSv(GnssSvNotification& svNotify);
void reportNmea(const char* nmea, size_t length);
bool requestNiNotify(const GnssNiNotification& notify, const void* data);
void reportGnssMeasurementData(const GnssMeasurementsNotification& measurements);
/*======== GNSSDEBUG ================================================================*/
bool getDebugReport(GnssDebugReport& report);
/* get AGC information from system status and fill it */
void getAgcInformation(GnssMeasurementsNotification& measurements, int msInWeek);
/*==== SYSTEM STATUS ================================================================*/
inline SystemStatus* getSystemStatus(void) { return mSystemStatus; }
std::string& getServerUrl(void) { return mServerUrl; }
void setServerUrl(const char* server) { mServerUrl.assign(server); }
/*==== CONVERSION ===================================================================*/
static uint32_t convertGpsLock(const GnssConfigGpsLock gpsLock);
static GnssConfigGpsLock convertGpsLock(const uint32_t gpsLock);
static uint32_t convertSuplVersion(const GnssConfigSuplVersion suplVersion);
static GnssConfigSuplVersion convertSuplVersion(const uint32_t suplVersion);
static uint32_t convertLppProfile(const GnssConfigLppProfile lppProfile);
static GnssConfigLppProfile convertLppProfile(const uint32_t lppProfile);
static uint32_t convertEP4ES(const GnssConfigEmergencyPdnForEmergencySupl);
static uint32_t convertSuplEs(const GnssConfigSuplEmergencyServices suplEmergencyServices);
static uint32_t convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask);
static GnssConfigLppeControlPlaneMask convertLppeCp(const uint32_t lppeControlPlaneMask);
static uint32_t convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask);
static GnssConfigLppeUserPlaneMask convertLppeUp(const uint32_t lppeUserPlaneMask);
static uint32_t convertAGloProt(const GnssConfigAGlonassPositionProtocolMask);
static uint32_t convertSuplMode(const GnssConfigSuplModeMask suplModeMask);
static void convertSatelliteInfo(std::vector<GnssDebugSatelliteInfo>& out,
const GnssSvType& in_constellation,
const SystemStatusReports& in);
void injectLocationCommand(double latitude, double longitude, float accuracy);
void injectTimeCommand(int64_t time, int64_t timeReference, int32_t uncertainty);
};
#endif //GNSS_ADAPTER_H

99
gps/gnss/Makefile.am Normal file
View File

@@ -0,0 +1,99 @@
AM_CFLAGS = \
$(LOCPLA_CFLAGS) \
$(LOCHAL_CFLAGS) \
-I./ \
-I../utils \
-I../core \
-I../location \
-std=c++11
libgnss_la_SOURCES = \
location_gnss.cpp \
GnssAdapter.cpp \
Agps.cpp
if USE_GLIB
libgnss_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) @GLIB_CFLAGS@
libgnss_la_LDFLAGS = -lstdc++ -lpthread @GLIB_LIBS@ -shared -avoid-version
libgnss_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
libgnss_la_CFLAGS = $(AM_CFLAGS)
libgnss_la_LDFLAGS = -lpthread -shared -version-info 1:0:0
libgnss_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS)
endif
libgnss_la_LIBADD = -lstdc++ $(LOCPLA_LIBS) $(LOCHAL_LIBS)
#Create and Install libraries
#lib_LTLIBRARIES = libgnss.la
#library_includedir = $(pkgincludedir)
#pkgconfigdir = $(libdir)/pkgconfig
#pkgconfig_DATA = location-api.pc
#EXTRA_DIST = $(pkgconfig_DATA)
libloc_ds_api_CFLAGS = \
$(QMIF_CFLAGS) \
$(QMI_CFLAGS) \
$(DATA_CFLAGS) \
$(GPSUTILS_CFLAGS) \
-I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api
libloc_ds_api_la_SOURCES = \
$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.c
if USE_GLIB
libloc_ds_api_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) @GLIB_CFLAGS@
libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic
libloc_ds_api_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_ds_api_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
libloc_ds_api_la_CFLAGS = $(AM_CFLAGS) $(libloc_ds_api_CFLAGS)
libloc_ds_api_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -Wl,--export-dynamic -shared -version-info 1:0:0
libloc_ds_api_la_LDFLAGS += -Wl,--export-dynamic
libloc_ds_api_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_ds_api_CFLAGS)
endif
libloc_ds_api_la_LIBADD = -lstdc++ $(QMIF_LIBS) -lqmiservices -ldsi_netctrl $(GPSUTILS_LIBS) $(LOCPLA_LIBS)
libloc_api_v02_CFLAGS = \
$(QMIF_CFLAGS) \
$(GPSUTILS_CFLAGS) \
-I$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api \
-I$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02
libloc_api_v02_la_SOURCES = \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.cpp \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.c \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.c \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.c \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.c
if USE_GLIB
libloc_api_v02_la_CFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) @GLIB_CFLAGS@
libloc_api_v02_la_LDFLAGS = -lstdc++ -g -Wl,-z,defs -lpthread @GLIB_LIBS@ -shared -version-info 1:0:0
libloc_api_v02_la_CPPFLAGS = -DUSE_GLIB $(AM_CFLAGS) $(libloc_api_v02_CFLAGS) $(AM_CPPFLAGS) @GLIB_CFLAGS@
else
libloc_api_v02_la_CFLAGS = $(AM_CFLAGS) $(libloc_api_v02_CFLAGS)
libloc_api_v02_la_LDFLAGS = -lstdc++ -Wl,-z,defs -lpthread -shared -version-info 1:0:0
libloc_api_v02_la_CPPFLAGS = $(AM_CFLAGS) $(AM_CPPFLAGS) $(libloc_api_v02_CFLAGS)
endif
libloc_api_v02_la_CXXFLAGS = -std=c++0x
libloc_api_v02_la_LIBADD = -lstdc++ -lqmi_cci -lqmi_common_so $(QMIF_LIBS) $(GPSUTILS_LIBS) $(LOCPLA_LIBS) ../core/libloc_core.la libloc_ds_api.la
library_include_HEADERS = \
$(WORKSPACE)/qcom-opensource/location/loc_api/ds_api/ds_client.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/location_service_v02.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_log.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_v02_client.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_api_sync_req.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/LocApiV02.h \
$(WORKSPACE)/qcom-opensource/location/loc_api/loc_api_v02/loc_util_log.h
library_includedir = $(pkgincludedir)
#Create and Install libraries
lib_LTLIBRARIES = libgnss.la libloc_ds_api.la libloc_api_v02.la

View File

@@ -0,0 +1,234 @@
/* Copyright (c) 2017, 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_TAG "LocSvc_XtraSystemStatusObs"
#include <sys/stat.h>
#include <sys/un.h>
#include <errno.h>
#include <ctype.h>
#include <cutils/properties.h>
#include <math.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string>
#include <loc_log.h>
#include <loc_nmea.h>
#include <SystemStatus.h>
#include <vector>
#include <sstream>
#include <XtraSystemStatusObserver.h>
#include <LocAdapterBase.h>
#include <DataItemId.h>
#include <DataItemsFactoryProxy.h>
using namespace loc_core;
#define XTRA_HAL_SOCKET_NAME "/data/vendor/location/xtra/socket_hal_xtra"
bool XtraSystemStatusObserver::updateLockStatus(uint32_t lock) {
stringstream ss;
ss << "gpslock";
ss << " " << lock;
ss << "\n"; // append seperator
return ( sendEvent(ss) );
}
bool XtraSystemStatusObserver::updateConnectionStatus(bool connected, uint32_t type) {
stringstream ss;
ss << "connection";
ss << " " << (connected ? "1" : "0");
ss << " " << (int)type;
ss << "\n"; // append seperator
return ( sendEvent(ss) );
}
bool XtraSystemStatusObserver::updateTac(const string& tac) {
stringstream ss;
ss << "tac";
ss << " " << tac.c_str();
ss << "\n"; // append seperator
return ( sendEvent(ss) );
}
bool XtraSystemStatusObserver::updateMccMnc(const string& mccmnc) {
stringstream ss;
ss << "mncmcc";
ss << " " << mccmnc.c_str();
ss << "\n"; // append seperator
return ( sendEvent(ss) );
}
bool XtraSystemStatusObserver::sendEvent(const stringstream& event) {
int socketFd = createSocket();
if (socketFd < 0) {
LOC_LOGe("XTRA unreachable. sending failed.");
return false;
}
const string& data = event.str();
int remain = data.length();
ssize_t sent = 0;
while (remain > 0 &&
(sent = ::send(socketFd, data.c_str() + (data.length() - remain),
remain, MSG_NOSIGNAL)) > 0) {
remain -= sent;
}
if (sent < 0) {
LOC_LOGe("sending error. reason:%s", strerror(errno));
}
closeSocket(socketFd);
return (remain == 0);
}
int XtraSystemStatusObserver::createSocket() {
int socketFd = -1;
if ((socketFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
LOC_LOGe("create socket error. reason:%s", strerror(errno));
} else {
const char* socketPath = XTRA_HAL_SOCKET_NAME ;
struct sockaddr_un addr = { .sun_family = AF_UNIX };
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", socketPath);
if (::connect(socketFd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
LOC_LOGe("cannot connect to XTRA. reason:%s", strerror(errno));
if (::close(socketFd)) {
LOC_LOGe("close socket error. reason:%s", strerror(errno));
}
socketFd = -1;
}
}
return socketFd;
}
void XtraSystemStatusObserver::closeSocket(const int socketFd) {
if (socketFd >= 0) {
if(::close(socketFd)) {
LOC_LOGe("close socket error. reason:%s", strerror(errno));
}
}
}
void XtraSystemStatusObserver::subscribe(bool yes)
{
// Subscription data list
list<DataItemId> subItemIdList;
subItemIdList.push_back(NETWORKINFO_DATA_ITEM_ID);
subItemIdList.push_back(MCCMNC_DATA_ITEM_ID);
if (yes) {
mSystemStatusObsrvr->subscribe(subItemIdList, this);
list<DataItemId> reqItemIdList;
reqItemIdList.push_back(TAC_DATA_ITEM_ID);
mSystemStatusObsrvr->requestData(reqItemIdList, this);
} else {
mSystemStatusObsrvr->unsubscribe(subItemIdList, this);
}
}
// IDataItemObserver overrides
void XtraSystemStatusObserver::getName(string& name)
{
name = "XtraSystemStatusObserver";
}
void XtraSystemStatusObserver::notify(const list<IDataItemCore*>& dlist)
{
struct handleOsObserverUpdateMsg : public LocMsg {
XtraSystemStatusObserver* mXtraSysStatObj;
list <IDataItemCore*> mDataItemList;
inline handleOsObserverUpdateMsg(XtraSystemStatusObserver* xtraSysStatObs,
const list<IDataItemCore*>& dataItemList) :
mXtraSysStatObj(xtraSysStatObs) {
for (auto eachItem : dataItemList) {
IDataItemCore* dataitem = DataItemsFactoryProxy::createNewDataItem(
eachItem->getId());
if (NULL == dataitem) {
break;
}
// Copy the contents of the data item
dataitem->copy(eachItem);
mDataItemList.push_back(dataitem);
}
}
inline ~handleOsObserverUpdateMsg() {
for (auto each : mDataItemList) {
delete each;
}
}
inline void proc() const {
for (auto each : mDataItemList) {
switch (each->getId())
{
case NETWORKINFO_DATA_ITEM_ID:
{
SystemStatusNetworkInfo* networkInfo =
reinterpret_cast<SystemStatusNetworkInfo*>(each);
mXtraSysStatObj->updateConnectionStatus(networkInfo->mConnected,
networkInfo->mType);
}
break;
case TAC_DATA_ITEM_ID:
{
SystemStatusTac* tac = reinterpret_cast<SystemStatusTac*>(each);
mXtraSysStatObj->updateTac(tac->mValue);
}
break;
case MCCMNC_DATA_ITEM_ID:
{
SystemStatusMccMnc* mccmnc = reinterpret_cast<SystemStatusMccMnc*>(each);
mXtraSysStatObj->updateMccMnc(mccmnc->mValue);
}
break;
default:
break;
}
}
}
};
mMsgTask->sendMsg(new (nothrow) handleOsObserverUpdateMsg(this, dlist));
}

View File

@@ -0,0 +1,71 @@
/* Copyright (c) 2017, 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 XTRA_SYSTEM_STATUS_OBS_H
#define XTRA_SYSTEM_STATUS_OBS_H
#include <cinttypes>
#include <MsgTask.h>
using namespace std;
using loc_core::IOsObserver;
using loc_core::IDataItemObserver;
using loc_core::IDataItemCore;
class XtraSystemStatusObserver : public IDataItemObserver {
public :
// constructor & destructor
inline XtraSystemStatusObserver(IOsObserver* sysStatObs, const MsgTask* msgTask):
mSystemStatusObsrvr(sysStatObs), mMsgTask(msgTask) {
subscribe(true);
}
inline XtraSystemStatusObserver() {};
inline virtual ~XtraSystemStatusObserver() { subscribe(false); }
// IDataItemObserver overrides
inline virtual void getName(string& name);
virtual void notify(const list<IDataItemCore*>& dlist);
bool updateLockStatus(uint32_t lock);
bool updateConnectionStatus(bool connected, uint32_t type);
bool updateTac(const string& tac);
bool updateMccMnc(const string& mccmnc);
inline const MsgTask* getMsgTask() { return mMsgTask; }
void subscribe(bool yes);
private:
int createSocket();
void closeSocket(const int32_t socketFd);
bool sendEvent(const stringstream& event);
IOsObserver* mSystemStatusObsrvr;
const MsgTask* mMsgTask;
};
#endif

258
gps/gnss/location_gnss.cpp Normal file
View File

@@ -0,0 +1,258 @@
/* Copyright (c) 2017, 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 "GnssAdapter.h"
#include "location_interface.h"
static GnssAdapter* gGnssAdapter = NULL;
static void initialize();
static void deinitialize();
static void addClient(LocationAPI* client, const LocationCallbacks& callbacks);
static void removeClient(LocationAPI* client);
static void requestCapabilities(LocationAPI* client);
static uint32_t startTracking(LocationAPI* client, LocationOptions& options);
static void updateTrackingOptions(LocationAPI* client, uint32_t id, LocationOptions& options);
static void stopTracking(LocationAPI* client, uint32_t id);
static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response);
static uint32_t gnssDeleteAidingData(GnssAidingData& data);
static void setControlCallbacks(LocationControlCallbacks& controlCallbacks);
static uint32_t enable(LocationTechnologyType techType);
static void disable(uint32_t id);
static uint32_t* gnssUpdateConfig(GnssConfig config);
static void injectLocation(double latitude, double longitude, float accuracy);
static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty);
static void agpsInit(const AgpsCbInfo& cbInfo);
static void agpsDataConnOpen(AGpsExtType agpsType, const char* apnName, int apnLen, int ipType);
static void agpsDataConnClosed(AGpsExtType agpsType);
static void agpsDataConnFailed(AGpsExtType agpsType);
static void getDebugReport(GnssDebugReport& report);
static void updateConnectionStatus(bool connected, uint8_t type);
static const GnssInterface gGnssInterface = {
sizeof(GnssInterface),
initialize,
deinitialize,
addClient,
removeClient,
requestCapabilities,
startTracking,
updateTrackingOptions,
stopTracking,
gnssNiResponse,
setControlCallbacks,
enable,
disable,
gnssUpdateConfig,
gnssDeleteAidingData,
injectLocation,
injectTime,
agpsInit,
agpsDataConnOpen,
agpsDataConnClosed,
agpsDataConnFailed,
getDebugReport,
updateConnectionStatus,
};
#ifndef DEBUG_X86
extern "C" const GnssInterface* getGnssInterface()
#else
const GnssInterface* getGnssInterface()
#endif // DEBUG_X86
{
return &gGnssInterface;
}
static void initialize()
{
if (NULL == gGnssAdapter) {
gGnssAdapter = new GnssAdapter();
}
}
static void deinitialize()
{
if (NULL != gGnssAdapter) {
delete gGnssAdapter;
gGnssAdapter = NULL;
}
}
static void addClient(LocationAPI* client, const LocationCallbacks& callbacks)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->addClientCommand(client, callbacks);
}
}
static void removeClient(LocationAPI* client)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->removeClientCommand(client);
}
}
static void requestCapabilities(LocationAPI* client)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->requestCapabilitiesCommand(client);
}
}
static uint32_t startTracking(LocationAPI* client, LocationOptions& options)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->startTrackingCommand(client, options);
} else {
return 0;
}
}
static void updateTrackingOptions(LocationAPI* client, uint32_t id, LocationOptions& options)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->updateTrackingOptionsCommand(client, id, options);
}
}
static void stopTracking(LocationAPI* client, uint32_t id)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->stopTrackingCommand(client, id);
}
}
static void gnssNiResponse(LocationAPI* client, uint32_t id, GnssNiResponse response)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->gnssNiResponseCommand(client, id, response);
}
}
static void setControlCallbacks(LocationControlCallbacks& controlCallbacks)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->setControlCallbacksCommand(controlCallbacks);
}
}
static uint32_t enable(LocationTechnologyType techType)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->enableCommand(techType);
} else {
return 0;
}
}
static void disable(uint32_t id)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->disableCommand(id);
}
}
static uint32_t* gnssUpdateConfig(GnssConfig config)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->gnssUpdateConfigCommand(config);
} else {
return NULL;
}
}
static uint32_t gnssDeleteAidingData(GnssAidingData& data)
{
if (NULL != gGnssAdapter) {
return gGnssAdapter->gnssDeleteAidingDataCommand(data);
} else {
return 0;
}
}
static void injectLocation(double latitude, double longitude, float accuracy)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->injectLocationCommand(latitude, longitude, accuracy);
}
}
static void injectTime(int64_t time, int64_t timeReference, int32_t uncertainty)
{
if (NULL != gGnssAdapter) {
gGnssAdapter->injectTimeCommand(time, timeReference, uncertainty);
}
}
static void agpsInit(const AgpsCbInfo& cbInfo) {
if (NULL != gGnssAdapter) {
gGnssAdapter->initAgpsCommand(cbInfo);
}
}
static void agpsDataConnOpen(
AGpsExtType agpsType, const char* apnName, int apnLen, int ipType) {
if (NULL != gGnssAdapter) {
gGnssAdapter->dataConnOpenCommand(
agpsType, apnName, apnLen, (AGpsBearerType)ipType);
}
}
static void agpsDataConnClosed(AGpsExtType agpsType) {
if (NULL != gGnssAdapter) {
gGnssAdapter->dataConnClosedCommand(agpsType);
}
}
static void agpsDataConnFailed(AGpsExtType agpsType) {
if (NULL != gGnssAdapter) {
gGnssAdapter->dataConnFailedCommand(agpsType);
}
}
static void getDebugReport(GnssDebugReport& report) {
if (NULL != gGnssAdapter) {
gGnssAdapter->getDebugReport(report);
}
}
static void updateConnectionStatus(bool connected, uint8_t type) {
if (NULL != gGnssAdapter) {
gGnssAdapter->getSystemStatus()->eventConnectionStatus(connected, type);
}
}

View File

@@ -1,32 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libgnsspps
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := \
libutils \
libcutils \
libgps.utils \
liblog
LOCAL_SRC_FILES += \
gnsspps.c
LOCAL_CFLAGS += \
-fno-short-enums \
-D_ANDROID_
LOCAL_COPY_HEADERS_TO:= libgnsspps/
LOCAL_COPY_HEADERS:= \
gnsspps.h
## Includes
LOCAL_C_INCLUDES := \
$(TARGET_OUT_HEADERS)/gps.utils \
$(TARGET_OUT_HEADERS)/libloc_pla
include $(BUILD_SHARED_LIBRARY)

View File

@@ -1,194 +0,0 @@
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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 Foundatoin, 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 <platform_lib_log_util.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <timepps.h>
#include <linux/types.h>
//DRsync kernel timestamp
static struct timespec drsyncKernelTs = {0,0};
//DRsync userspace timestamp
static struct timespec drsyncUserTs = {0,0};
//flag to stop fetching timestamp
static int isActive = 0;
static pps_handle handle;
static pthread_mutex_t ts_lock;
/* checks the PPS source and opens it */
int check_device(char *path, pps_handle *handle)
{
int ret;
/* Try to find the source by using the supplied "path" name */
ret = open(path, O_RDWR);
if (ret < 0)
{
LOC_LOGV("%s:%d unable to open device %s", __func__, __LINE__, path);
return ret;
}
/* Open the PPS source */
ret = pps_create(ret, handle);
if (ret < 0)
{
LOC_LOGV( "%s:%d cannot create a PPS source from device %s", __func__, __LINE__, path);
return -1;
}
return 0;
}
/* fetches the timestamp from the PPS source */
int read_pps(pps_handle *handle)
{
struct timespec timeout;
pps_info infobuf;
int ret;
// 3sec timeout
timeout.tv_sec = 3;
timeout.tv_nsec = 0;
ret = pps_fetch(*handle, PPS_TSFMT_TSPEC, &infobuf,&timeout);
if (ret < 0 && ret !=-EINTR)
{
LOC_LOGV("%s:%d pps_fetch() error %d", __func__, __LINE__, ret);
return -1;
}
pthread_mutex_lock(&ts_lock);
drsyncKernelTs.tv_sec = infobuf.tv_sec;
drsyncKernelTs.tv_nsec = infobuf.tv_nsec;
ret = clock_gettime(CLOCK_BOOTTIME,&drsyncUserTs);
pthread_mutex_unlock(&ts_lock);
if(ret != 0)
{
LOC_LOGV("%s:%d clock_gettime() error",__func__,__LINE__);
}
return 0;
}
#ifdef __cplusplus
extern "C" {
#endif
/* infinitely calls read_pps() */
void *thread_handle(void *input)
{
int ret;
if(input != NULL)
{
LOC_LOGV("%s:%d Thread Input is present", __func__, __LINE__);
}
while(isActive)
{
ret = read_pps(&handle);
if (ret == -1 && errno != ETIMEDOUT )
{
LOC_LOGV("%s:%d Could not fetch PPS source", __func__, __LINE__);
}
}
return NULL;
}
/* opens the device and fetches from PPS source */
int initPPS(char *devname)
{
int ret,pid;
pthread_t thread;
isActive = 1;
ret = check_device(devname, &handle);
if (ret < 0)
{
LOC_LOGV("%s:%d Could not find PPS source", __func__, __LINE__);
return 0;
}
pthread_mutex_init(&ts_lock,NULL);
pid = pthread_create(&thread,NULL,&thread_handle,NULL);
if(pid != 0)
{
LOC_LOGV("%s:%d Could not create thread in InitPPS", __func__, __LINE__);
return 0;
}
return 1;
}
/* stops fetching and closes the device */
void deInitPPS()
{
pthread_mutex_lock(&ts_lock);
isActive = 0;
pthread_mutex_unlock(&ts_lock);
pthread_mutex_destroy(&ts_lock);
pps_destroy(handle);
}
/* retrieves DRsync kernel timestamp,DRsync userspace timestamp
and updates current timestamp */
/* Returns:
* 1. @Param out DRsync kernel timestamp
* 2. @Param out DRsync userspace timestamp
* 3. @Param out current timestamp
*/
int getPPS(struct timespec *fineKernelTs ,struct timespec *currentTs,
struct timespec *fineUserTs)
{
int ret;
pthread_mutex_lock(&ts_lock);
fineKernelTs->tv_sec = drsyncKernelTs.tv_sec;
fineKernelTs->tv_nsec = drsyncKernelTs.tv_nsec;
fineUserTs->tv_sec = drsyncUserTs.tv_sec;
fineUserTs->tv_nsec = drsyncUserTs.tv_nsec;
ret = clock_gettime(CLOCK_BOOTTIME,currentTs);
pthread_mutex_unlock(&ts_lock);
if(ret != 0)
{
LOC_LOGV("%s:%d clock_gettime() error",__func__,__LINE__);
return 0;
}
return 1;
}
#ifdef __cplusplus
}
#endif

View File

@@ -1,106 +0,0 @@
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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 Foundatoin, 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 <errno.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/pps.h>
#ifndef _TIMEPPS_H
#define _TIMEPPS_H
#ifdef __cplusplus
extern "C" {
#endif
/* time of assert event */
typedef struct timespec pps_info;
/* represents pps source */
typedef int pps_handle;
/* Open the PPS source */
static __inline int pps_create(int source, pps_handle *handle)
{
int ret;
struct pps_kparams dummy;
if (!handle)
{
errno = EINVAL;
return -1;
}
/* check if current device is valid pps */
ret = ioctl(source, PPS_GETPARAMS, &dummy);
if (ret)
{
errno = EOPNOTSUPP;
return -1;
}
*handle = source;
return 0;
}
/* close the pps source */
static __inline int pps_destroy(pps_handle handle)
{
return close(handle);
}
/*reads timestamp from pps device*/
static __inline int pps_fetch(pps_handle handle, const int tsformat,
pps_info *ppsinfobuf,
const struct timespec *timeout)
{
struct pps_fdata fdata;
int ret;
if (tsformat != PPS_TSFMT_TSPEC)
{
errno = EINVAL;
return -1;
}
if (timeout)
{
fdata.timeout.sec = timeout->tv_sec;
fdata.timeout.nsec = timeout->tv_nsec;
fdata.timeout.flags = ~PPS_TIME_INVALID;
}
else
{
fdata.timeout.flags = PPS_TIME_INVALID;
}
ret = ioctl(handle, PPS_FETCH, &fdata);
ppsinfobuf->tv_sec = fdata.info.assert_tu.sec;
ppsinfobuf->tv_nsec = fdata.info.assert_tu.nsec;
return ret;
}
#ifdef __cplusplus
}
#endif
#endif

10
gps/loc-hal.pc.in Normal file
View File

@@ -0,0 +1,10 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: loc-hal
Description: QTI GPS Loc HAL
Version: @VERSION
Libs: -L${libdir} -lloc_core -llocation_api -lgnss -lloc_ds_api -lloc_api_v02
Cflags: -I${includedir} -I${includedir}/loc-hal -I${includedir}/loc-hal/location -I${includedir}/loc-hal/gnss -I${includedir}/loc-hal/core

View File

@@ -1,3 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(call all-makefiles-under,$(LOCAL_PATH))

View File

@@ -1,111 +0,0 @@
ifneq ($(BUILD_TINY_ANDROID),true)
#Compile this library only for builds with the latest modem image
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libloc_eng
LOCAL_MODULE_OWNER := qcom
LOCAL_MODULE_TAGS := optional
LOCAL_SHARED_LIBRARIES := \
libutils \
libcutils \
libdl \
liblog \
libloc_core \
libgps.utils \
libloc_pla
LOCAL_SRC_FILES += \
loc_eng.cpp \
loc_eng_agps.cpp \
loc_eng_xtra.cpp \
loc_eng_ni.cpp \
loc_eng_log.cpp \
loc_eng_nmea.cpp \
LocEngAdapter.cpp
LOCAL_SRC_FILES += \
loc_eng_dmn_conn.cpp \
loc_eng_dmn_conn_handler.cpp \
loc_eng_dmn_conn_thread_helper.c \
loc_eng_dmn_conn_glue_msg.c \
loc_eng_dmn_conn_glue_pipe.c
LOCAL_CFLAGS += \
-fno-short-enums \
-D_ANDROID_
LOCAL_C_INCLUDES:= \
$(LOCAL_PATH) \
$(TARGET_OUT_HEADERS)/gps.utils \
$(TARGET_OUT_HEADERS)/libloc_core \
$(TARGET_OUT_HEADERS)/libflp \
$(TARGET_OUT_HEADERS)/libloc_pla
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_log.h
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gps.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE_OWNER := qcom
LOCAL_MODULE_TAGS := optional
## Libs
LOCAL_SHARED_LIBRARIES := \
libutils \
libcutils \
liblog \
libloc_eng \
libloc_core \
libgps.utils \
libdl \
libloc_pla
LOCAL_SRC_FILES += \
loc.cpp \
gps.c
LOCAL_CFLAGS += \
-fno-short-enums \
-D_ANDROID_ \
ifeq ($(TARGET_BUILD_VARIANT),user)
LOCAL_CFLAGS += -DTARGET_BUILD_VARIANT_USER
endif
ifeq ($(TARGET_USES_QCOM_BSP), true)
LOCAL_CFLAGS += -DTARGET_USES_QCOM_BSP
endif
## Includes
LOCAL_C_INCLUDES:= \
$(TARGET_OUT_HEADERS)/gps.utils \
$(TARGET_OUT_HEADERS)/libloc_core \
$(TARGET_OUT_HEADERS)/libflp \
$(TARGET_OUT_HEADERS)/libloc_pla
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_RELATIVE_PATH := hw
include $(BUILD_SHARED_LIBRARY)
endif # not BUILD_TINY_ANDROID

View File

@@ -1,598 +0,0 @@
/* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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_EngAdapter"
#include <sys/stat.h>
#include <errno.h>
#include <ctype.h>
#include <cutils/properties.h>
#include <LocEngAdapter.h>
#include "loc_eng_msg.h"
#include "loc_log.h"
#define CHIPSET_SERIAL_NUMBER_MAX_LEN 16
#define USER_AGENT_MAX_LEN 512
using namespace loc_core;
LocInternalAdapter::LocInternalAdapter(LocEngAdapter* adapter) :
LocAdapterBase(adapter->getMsgTask()),
mLocEngAdapter(adapter)
{
}
void LocInternalAdapter::setPositionModeInt(LocPosMode& posMode) {
sendMsg(new LocEngPositionMode(mLocEngAdapter, posMode));
}
void LocInternalAdapter::startFixInt() {
sendMsg(new LocEngStartFix(mLocEngAdapter));
}
void LocInternalAdapter::stopFixInt() {
sendMsg(new LocEngStopFix(mLocEngAdapter));
}
void LocInternalAdapter::getZppInt() {
sendMsg(new LocEngGetZpp(mLocEngAdapter));
}
LocEngAdapter::LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask,
void* owner, ContextBase* context,
LocThread::tCreate tCreator) :
LocAdapterBase(mask,
//Get the AFW context if VzW context has not already been intialized in
//loc_ext
context == NULL?
LocDualContext::getLocFgContext(tCreator,
NULL,
LocDualContext::mLocationHalName,
false)
:context),
mOwner(owner), mInternalAdapter(new LocInternalAdapter(this)),
mUlp(new UlpProxyBase()), mNavigating(false),
mSupportsAgpsRequests(false),
mSupportsPositionInjection(false),
mSupportsTimeInjection(false),
mPowerVote(0)
{
memset(&mFixCriteria, 0, sizeof(mFixCriteria));
mFixCriteria.mode = LOC_POSITION_MODE_INVALID;
LOC_LOGD("LocEngAdapter created");
}
inline
LocEngAdapter::~LocEngAdapter()
{
delete mInternalAdapter;
LOC_LOGV("LocEngAdapter deleted");
}
void LocEngAdapter::setXtraUserAgent() {
struct LocSetXtraUserAgent : public LocMsg {
const ContextBase* const mContext;
inline LocSetXtraUserAgent(ContextBase* context) :
LocMsg(), mContext(context) {
}
virtual void proc() const {
char release[PROPERTY_VALUE_MAX];
char manufacture[PROPERTY_VALUE_MAX];
char model[PROPERTY_VALUE_MAX];
char board[PROPERTY_VALUE_MAX];
char brand[PROPERTY_VALUE_MAX];
char chipsetsn[CHIPSET_SERIAL_NUMBER_MAX_LEN];
char userAgent[USER_AGENT_MAX_LEN];
const char defVal[] = "-";
property_get("ro.build.version.release", release, defVal);
property_get("ro.product.manufacturer", manufacture, defVal);
property_get("ro.product.model", model, defVal);
property_get("ro.product.board", board, defVal);
property_get("ro.product.brand", brand, defVal);
getChipsetSerialNo(chipsetsn, sizeof(chipsetsn), defVal);
encodeInPlace(release, PROPERTY_VALUE_MAX);
encodeInPlace(manufacture, PROPERTY_VALUE_MAX);
encodeInPlace(model, PROPERTY_VALUE_MAX);
encodeInPlace(board, PROPERTY_VALUE_MAX);
encodeInPlace(brand, PROPERTY_VALUE_MAX);
snprintf(userAgent, sizeof(userAgent), "A/%s/%s/%s/%s/-/QCX3/s%u/-/%s/-/%s/-/-/-",
release, manufacture, model, board,
mContext->getIzatDevId(), chipsetsn, brand);
for (int i = 0; i < sizeof(userAgent) && userAgent[i]; i++) {
if (' ' == userAgent[i]) userAgent[i] = '#';
}
saveUserAgentString(userAgent, strlen(userAgent));
LOC_LOGV("%s] UserAgent %s", __func__, userAgent);
}
void saveUserAgentString(const char* data, const int len) const {
const char XTRA_FOLDER[] = "/data/misc/location/xtra";
const char USER_AGENT_FILE[] = "/data/misc/location/xtra/useragent.txt";
if (data == NULL || len < 1) {
LOC_LOGE("%s:%d]: invalid input data = %p len = %d", __func__, __LINE__, data, len);
return;
}
struct stat s;
int err = stat(XTRA_FOLDER, &s);
if (err < 0) {
if (ENOENT == errno) {
if (mkdir(XTRA_FOLDER, 0700) < 0) {
LOC_LOGE("%s:%d]: make XTRA_FOLDER failed", __func__, __LINE__);
return;
}
} else {
LOC_LOGE("%s:%d]: XTRA_FOLDER invalid", __func__, __LINE__);
return;
}
}
FILE* file = fopen(USER_AGENT_FILE, "wt");
if (file == NULL) {
LOC_LOGE("%s:%d]: open USER_AGENT_FILE failed", __func__, __LINE__);
return;
}
size_t written = fwrite(data, 1, len, file);
fclose(file);
file = NULL;
// set file permission
chmod(USER_AGENT_FILE, 0600);
if (written != len) {
LOC_LOGE("%s:%d]: write USER_AGENT_FILE failed", __func__, __LINE__);
}
}
void getChipsetSerialNo(char buf[], int buflen, const char def[]) const {
const char SOC_SERIAL_NUMBER[] = "/sys/devices/soc0/serial_number";
FILE* file = fopen(SOC_SERIAL_NUMBER, "rt");
if (file == NULL) {
// use default upon unreadable file
strlcpy(buf, def, buflen);
} else {
size_t size = fread(buf, 1, buflen - 1, file);
if (size == 0) {
// use default upon empty file
strlcpy(buf, def, buflen);
} else {
buf[size] = '\0';
}
fclose(file);
// remove trailing spaces
size_t len = strlen(buf);
while (--len >= 0 && isspace(buf[len])) {
buf[len] = '\0';
}
}
return;
}
/**
* encode the given string value such that all separator characters ('/','+','|','%')
* in the string are repaced by their corresponding encodings (%2F","%2B","%7C", "%25")
*/
static void encodeInPlace(char value[], const int size) {
char buffer[size];
struct ENCODE {
const char ch;
const char *code;
};
const ENCODE encodings[] = { {'/', "%2F"}, {'+', "%2B"}, {'|', "%7C",}, {'%', "%25"} };
const int nencodings = (int)sizeof(encodings) / sizeof(encodings[0]);
int inpos = 0, outpos = 0;
while(value[inpos] != '\0' && outpos < size - 1) {
// check if escaped character
int escchar = 0;
while(escchar < nencodings && encodings[escchar].ch != value[inpos]) {
escchar++;
}
if (escchar == nencodings) {
// non escaped character
buffer[outpos++] = value[inpos++];
continue;
}
// escaped character
int codepos = 0;
#define NUM_CHARS_IN_CODE 3
if (outpos + NUM_CHARS_IN_CODE >= size) {
// skip last character if there is insufficient space
break;
}
while(outpos < size - 1 && codepos < NUM_CHARS_IN_CODE) {
buffer[outpos++] = encodings[escchar].code[codepos++];
}
inpos++;
}
// copy to ouput
value[outpos] = '\0';
while(--outpos >= 0) {
value[outpos] = buffer[outpos];
}
}
};
sendMsg(new LocSetXtraUserAgent(mContext));
}
void LocInternalAdapter::setUlpProxy(UlpProxyBase* ulp) {
struct LocSetUlpProxy : public LocMsg {
LocAdapterBase* mAdapter;
UlpProxyBase* mUlp;
inline LocSetUlpProxy(LocAdapterBase* adapter, UlpProxyBase* ulp) :
LocMsg(), mAdapter(adapter), mUlp(ulp) {
}
virtual void proc() const {
LOC_LOGV("%s] ulp %p adapter %p", __func__,
mUlp, mAdapter);
mAdapter->setUlpProxy(mUlp);
}
};
sendMsg(new LocSetUlpProxy(mLocEngAdapter, ulp));
}
void LocEngAdapter::setUlpProxy(UlpProxyBase* ulp)
{
if (ulp == mUlp) {
//This takes care of the case when double initalization happens
//and we get the same object back for UlpProxyBase . Do nothing
return;
}
LOC_LOGV("%s] %p", __func__, ulp);
if (NULL == ulp) {
LOC_LOGE("%s:%d]: ulp pointer is NULL", __func__, __LINE__);
ulp = new UlpProxyBase();
}
if (LOC_POSITION_MODE_INVALID != mUlp->mPosMode.mode) {
// need to send this mode and start msg to ULP
ulp->sendFixMode(mUlp->mPosMode);
}
if(mUlp->mFixSet) {
ulp->sendStartFix();
}
delete mUlp;
mUlp = ulp;
}
int LocEngAdapter::setGpsLockMsg(LOC_GPS_LOCK_MASK lockMask)
{
struct LocEngAdapterGpsLock : public LocMsg {
LocEngAdapter* mAdapter;
LOC_GPS_LOCK_MASK mLockMask;
inline LocEngAdapterGpsLock(LocEngAdapter* adapter, LOC_GPS_LOCK_MASK lockMask) :
LocMsg(), mAdapter(adapter), mLockMask(lockMask)
{
locallog();
}
inline virtual void proc() const {
mAdapter->setGpsLock(mLockMask);
}
inline void locallog() const {
LOC_LOGV("LocEngAdapterGpsLock - mLockMask: %x", mLockMask);
}
inline virtual void log() const {
locallog();
}
};
sendMsg(new LocEngAdapterGpsLock(this, lockMask));
return 0;
}
void LocEngAdapter::requestPowerVote()
{
if (getPowerVoteRight()) {
/* Power voting without engine lock:
* 101: vote down, 102-104 - vote up
* These codes are used not to confuse with actual engine lock
* functionality, that can't be used in SSR scenario, as it
* conflicts with initialization sequence.
*/
bool powerUp = getPowerVote();
LOC_LOGV("LocEngAdapterVotePower - Vote Power: %d", (int)powerUp);
setGpsLock(powerUp ? 103 : 101);
}
}
void LocInternalAdapter::reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask)
{
sendMsg(new LocEngReportPosition(mLocEngAdapter,
location,
locationExtended,
locationExt,
status,
loc_technology_mask));
}
void LocEngAdapter::reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask)
{
if (! mUlp->reportPosition(location,
locationExtended,
locationExt,
status,
loc_technology_mask )) {
mInternalAdapter->reportPosition(location,
locationExtended,
locationExt,
status,
loc_technology_mask);
}
}
void LocInternalAdapter::reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt){
sendMsg(new LocEngReportSv(mLocEngAdapter, svStatus,
locationExtended, svExt));
}
void LocEngAdapter::reportSv(GnssSvStatus &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 (! mUlp->reportSv(svStatus, locationExtended, svExt)) {
mInternalAdapter->reportSv(svStatus, locationExtended, svExt);
}
}
void LocEngAdapter::reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet)
{
// We send SvMeasurementSet to AmtProxy/ULPProxy to be forwarded as necessary.
if (! mUlp->reportSvMeasurement(svMeasurementSet)) {
//Send to Internal Adapter later if needed by LA
}
}
void LocEngAdapter::reportSvPolynomial(GnssSvPolynomial &svPolynomial)
{
// We send SvMeasurementSet to AmtProxy/ULPProxy to be forwarded as necessary.
if (! mUlp->reportSvPolynomial(svPolynomial)) {
//Send to Internal Adapter later if needed by LA
}
}
void LocEngAdapter::setInSession(bool inSession)
{
mNavigating = inSession;
mLocApi->setInSession(inSession);
if (!mNavigating) {
mFixCriteria.mode = LOC_POSITION_MODE_INVALID;
}
}
void LocInternalAdapter::reportStatus(GpsStatusValue status)
{
sendMsg(new LocEngReportStatus(mLocEngAdapter, status));
}
void LocEngAdapter::reportStatus(GpsStatusValue status)
{
if (!mUlp->reportStatus(status)) {
mInternalAdapter->reportStatus(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 (mSupportsAgpsRequests) {
sendMsg(new LocEngReportXtraServer(mOwner, url1,
url2, url3, maxlength));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::requestATL(int connHandle, AGpsType agps_type)
{
if (mSupportsAgpsRequests) {
sendMsg(new LocEngRequestATL(mOwner,
connHandle, agps_type));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::releaseATL(int connHandle)
{
if (mSupportsAgpsRequests) {
sendMsg(new LocEngReleaseATL(mOwner, connHandle));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::requestXtraData()
{
if (mSupportsAgpsRequests) {
sendMsg(new LocEngRequestXtra(mOwner));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::requestTime()
{
if (mSupportsAgpsRequests) {
sendMsg(new LocEngRequestTime(mOwner));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::requestNiNotify(GpsNiNotification &notif, const void* data)
{
if (mSupportsAgpsRequests) {
notif.size = sizeof(notif);
notif.timeout = LOC_NI_NO_RESPONSE_TIME;
sendMsg(new LocEngRequestNi(mOwner, notif, data));
}
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::requestSuplES(int connHandle)
{
if (mSupportsAgpsRequests)
sendMsg(new LocEngRequestSuplEs(mOwner, connHandle));
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::reportDataCallOpened()
{
if(mSupportsAgpsRequests)
sendMsg(new LocEngSuplEsOpened(mOwner));
return mSupportsAgpsRequests;
}
inline
bool LocEngAdapter::reportDataCallClosed()
{
if(mSupportsAgpsRequests)
sendMsg(new LocEngSuplEsClosed(mOwner));
return mSupportsAgpsRequests;
}
inline
void LocEngAdapter::handleEngineDownEvent()
{
sendMsg(new LocEngDown(mOwner));
}
inline
void LocEngAdapter::handleEngineUpEvent()
{
sendMsg(new LocEngUp(mOwner));
}
enum loc_api_adapter_err LocEngAdapter::setTime(GpsUtcTime time,
int64_t timeReference,
int uncertainty)
{
loc_api_adapter_err result = LOC_API_ADAPTER_ERR_SUCCESS;
LOC_LOGD("%s:%d]: mSupportsTimeInjection is %d",
__func__, __LINE__, mSupportsTimeInjection);
if (mSupportsTimeInjection) {
LOC_LOGD("%s:%d]: Injecting time", __func__, __LINE__);
result = mLocApi->setTime(time, timeReference, uncertainty);
}
return result;
}
enum loc_api_adapter_err LocEngAdapter::setXtraVersionCheck(int check)
{
enum loc_api_adapter_err ret;
ENTRY_LOG();
enum xtra_version_check eCheck;
switch (check) {
case 0:
eCheck = DISABLED;
break;
case 1:
eCheck = AUTO;
break;
case 2:
eCheck = XTRA2;
break;
case 3:
eCheck = XTRA3;
break;
default:
eCheck = DISABLED;
}
ret = mLocApi->setXtraVersionCheck(eCheck);
EXIT_LOG(%d, ret);
return ret;
}
void LocEngAdapter::reportGnssMeasurementData(GnssData &gnssMeasurementData)
{
sendMsg(new LocEngReportGnssMeasurement(mOwner,
gnssMeasurementData));
}
/*
Set Gnss Constellation Config
*/
bool LocEngAdapter::gnssConstellationConfig()
{
LOC_LOGD("entering %s", __func__);
bool result = false;
result = mLocApi->gnssConstellationConfig();
return result;
}

View File

@@ -1,355 +0,0 @@
/* Copyright (c) 2011-2016, 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 <ctype.h>
#include <hardware/gps.h>
#include <loc.h>
#include <loc_eng_log.h>
#include <LocAdapterBase.h>
#include <LocDualContext.h>
#include <UlpProxyBase.h>
#include <platform_lib_includes.h>
#define MAX_URL_LEN 256
using namespace loc_core;
class LocEngAdapter;
class LocInternalAdapter : public LocAdapterBase {
LocEngAdapter* mLocEngAdapter;
public:
LocInternalAdapter(LocEngAdapter* adapter);
virtual void reportPosition(UlpLocation &location,
GpsLocationExtended &locationExtended,
void* locationExt,
enum loc_sess_status status,
LocPosTechMask loc_technology_mask);
virtual void reportSv(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt);
virtual void reportStatus(GpsStatusValue status);
virtual void setPositionModeInt(LocPosMode& posMode);
virtual void startFixInt();
virtual void stopFixInt();
virtual void getZppInt();
virtual void setUlpProxy(UlpProxyBase* ulp);
};
typedef void (*loc_msg_sender)(void* loc_eng_data_p, void* msgp);
class LocEngAdapter : public LocAdapterBase {
void* mOwner;
LocInternalAdapter* mInternalAdapter;
UlpProxyBase* mUlp;
LocPosMode mFixCriteria;
bool mNavigating;
// mPowerVote is encoded as
// mPowerVote & 0x20 -- powerVoteRight
// mPowerVote & 0x10 -- power On / Off
unsigned int mPowerVote;
static const unsigned int POWER_VOTE_RIGHT = 0x20;
static const unsigned int POWER_VOTE_VALUE = 0x10;
public:
bool mSupportsAgpsRequests;
bool mSupportsPositionInjection;
bool mSupportsTimeInjection;
GnssSystemInfo mGnssInfo;
LocEngAdapter(LOC_API_ADAPTER_EVENT_MASK_T mask,
void* owner, ContextBase* context,
LocThread::tCreate tCreator);
virtual ~LocEngAdapter();
virtual void setUlpProxy(UlpProxyBase* ulp);
void setXtraUserAgent();
inline void requestUlp(unsigned long capabilities) {
mContext->requestUlp(mInternalAdapter, capabilities);
}
inline LocInternalAdapter* getInternalAdapter() { return mInternalAdapter; }
inline UlpProxyBase* getUlpProxy() { return mUlp; }
inline void* getOwner() { return mOwner; }
inline bool hasAgpsExtendedCapabilities() {
return mContext->hasAgpsExtendedCapabilities();
}
inline bool hasCPIExtendedCapabilities() {
return mContext->hasCPIExtendedCapabilities();
}
inline bool hasNativeXtraClient() {
return mContext->hasNativeXtraClient();
}
inline const MsgTask* getMsgTask() { return mMsgTask; }
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
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
setNMEATypes (uint32_t typesMask)
{
return mLocApi->setNMEATypes(typesMask);
}
inline enum loc_api_adapter_err
setLPPConfig(uint32_t profile)
{
return mLocApi->setLPPConfig(profile);
}
inline enum loc_api_adapter_err
setSensorControlConfig(int sensorUsage, int sensorProvider)
{
return mLocApi->setSensorControlConfig(sensorUsage, sensorProvider);
}
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
setAGLONASSProtocol(unsigned long aGlonassProtocol)
{
return mLocApi->setAGLONASSProtocol(aGlonassProtocol);
}
inline virtual enum loc_api_adapter_err
setLPPeProtocol(unsigned long lppeCP, unsigned long lppeUP)
{
return mLocApi->setLPPeProtocol(lppeCP, lppeUP);
}
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();
}
inline enum loc_api_adapter_err
getZpp(GpsLocation &zppLoc, LocPosTechMask &tech_mask)
{
return mLocApi->getBestAvailableZppFix(zppLoc, tech_mask);
}
enum loc_api_adapter_err setTime(GpsUtcTime time,
int64_t timeReference,
int uncertainty);
enum loc_api_adapter_err setXtraVersionCheck(int check);
inline virtual void installAGpsCert(const DerEncodedCertificate* pData,
size_t length,
uint32_t slotBitMask)
{
mLocApi->installAGpsCert(pData, length, slotBitMask);
}
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(GnssSvStatus &svStatus,
GpsLocationExtended &locationExtended,
void* svExt);
virtual void reportSvMeasurement(GnssSvMeasurementSet &svMeasurementSet);
virtual void reportSvPolynomial(GnssSvPolynomial &svPolynomial);
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 &notify, const void* data);
virtual bool requestSuplES(int connHandle);
virtual bool reportDataCallOpened();
virtual bool reportDataCallClosed();
virtual void reportGnssMeasurementData(GnssData &gnssMeasurementData);
inline const LocPosMode& getPositionMode() const
{return mFixCriteria;}
inline virtual bool isInSession()
{ return mNavigating; }
void setInSession(bool inSession);
// Permit/prohibit power voting
inline void setPowerVoteRight(bool powerVoteRight) {
mPowerVote = powerVoteRight ? (mPowerVote | POWER_VOTE_RIGHT) :
(mPowerVote & ~POWER_VOTE_RIGHT);
}
inline bool getPowerVoteRight() const {
return (mPowerVote & POWER_VOTE_RIGHT) != 0 ;
}
// Set the power voting up/down and do actual operation if permitted
inline void setPowerVote(bool powerOn) {
mPowerVote = powerOn ? (mPowerVote | POWER_VOTE_VALUE) :
(mPowerVote & ~POWER_VOTE_VALUE);
requestPowerVote();
mContext->modemPowerVote(powerOn);
}
inline bool getPowerVote() const {
return (mPowerVote & POWER_VOTE_VALUE) != 0 ;
}
// Do power voting according to last settings if permitted
void requestPowerVote();
/*Values for lock
1 = Do not lock any position sessions
2 = Lock MI position sessions
3 = Lock MT position sessions
4 = Lock all position sessions
*/
inline int setGpsLock(LOC_GPS_LOCK_MASK lock)
{
return mLocApi->setGpsLock(lock);
}
int setGpsLockMsg(LOC_GPS_LOCK_MASK lock);
/*
Returns
Current value of GPS lock on success
-1 on failure
*/
inline int getGpsLock()
{
return mLocApi->getGpsLock();
}
/*
Set Gnss Constellation Config
*/
bool gnssConstellationConfig();
};
#endif //LOC_API_ENG_ADAPTER_H

View File

@@ -1,73 +0,0 @@
/* Copyright (c) 2011,2015 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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 <hardware/gps.h>
#include <stdlib.h>
#include <string.h>
extern const GpsInterface* get_gps_interface();
const GpsInterface* gps__get_gps_interface(struct gps_device_t* dev)
{
return get_gps_interface();
}
static int open_gps(const struct hw_module_t* module, char const* name,
struct hw_device_t** device)
{
struct gps_device_t *dev = (struct gps_device_t *) malloc(sizeof(struct gps_device_t));
if(dev == NULL)
return -1;
memset(dev, 0, sizeof(*dev));
dev->common.tag = HARDWARE_DEVICE_TAG;
dev->common.version = 0;
dev->common.module = (struct hw_module_t*)module;
dev->get_gps_interface = gps__get_gps_interface;
*device = (struct hw_device_t*)dev;
return 0;
}
static struct hw_module_methods_t gps_module_methods = {
.open = open_gps
};
struct hw_module_t HAL_MODULE_INFO_SYM = {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = 1,
.hal_api_version = 0,
.id = GPS_HARDWARE_MODULE_ID,
.name = "loc_api GPS Module",
.author = "Qualcomm USA, Inc.",
.methods = &gps_module_methods,
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,210 +0,0 @@
/* Copyright (c) 2009-2014, 2016 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_H
#define LOC_ENG_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Uncomment to keep all LOG messages (LOGD, LOGI, LOGV, etc.)
#define MAX_NUM_ATL_CONNECTIONS 2
// Define boolean type to be used by libgps on loc api module
typedef unsigned char boolean;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#include <loc.h>
#include <loc_eng_xtra.h>
#include <loc_eng_ni.h>
#include <loc_eng_agps.h>
#include <loc_cfg.h>
#include <loc_log.h>
#include <loc_eng_agps.h>
#include <LocEngAdapter.h>
// The data connection minimal open time
#define DATA_OPEN_MIN_TIME 1 /* sec */
// The system sees GPS engine turns off after inactive for this period of time
#define GPS_AUTO_OFF_TIME 2 /* secs */
#define SUCCESS TRUE
#define FAILURE FALSE
#define INVALID_ATL_CONNECTION_HANDLE -1
#define gps_conf ContextBase::mGps_conf
#define sap_conf ContextBase::mSap_conf
enum loc_nmea_provider_e_type {
NMEA_PROVIDER_AP = 0, // Application Processor Provider of NMEA
NMEA_PROVIDER_MP // Modem Processor Provider of NMEA
};
enum loc_mute_session_e_type {
LOC_MUTE_SESS_NONE = 0,
LOC_MUTE_SESS_WAIT,
LOC_MUTE_SESS_IN_SESSION
};
// Module data
typedef struct loc_eng_data_s
{
LocEngAdapter *adapter;
loc_location_cb_ext location_cb;
gps_status_callback status_cb;
loc_sv_status_cb_ext sv_status_cb;
agps_status_extended agps_status_cb;
gps_nmea_callback nmea_cb;
loc_ni_notify_callback ni_notify_cb;
gps_set_capabilities set_capabilities_cb;
gps_acquire_wakelock acquire_wakelock_cb;
gps_release_wakelock release_wakelock_cb;
gps_request_utc_time request_utc_time_cb;
gnss_set_system_info set_system_info_cb;
gnss_sv_status_callback gnss_sv_status_cb;
gnss_measurement_callback gnss_measurement_cb;
boolean intermediateFix;
AGpsStatusValue agps_status;
loc_eng_xtra_data_s_type xtra_module_data;
loc_eng_ni_data_s_type loc_eng_ni_data;
// AGPS state machines
AgpsStateMachine* agnss_nif;
AgpsStateMachine* internet_nif;
//State machine for Data Services
AgpsStateMachine* ds_nif;
// GPS engine status
GpsStatusValue engine_status;
GpsStatusValue fix_session_status;
// Aiding data information to be deleted, aiding data can only be deleted when GPS engine is off
GpsAidingData aiding_data_for_deletion;
// For muting session broadcast
loc_mute_session_e_type mute_session_state;
// For nmea generation
boolean generateNmea;
uint32_t gps_used_mask;
uint32_t glo_used_mask;
float hdop;
float pdop;
float vdop;
// Address buffers, for addressing setting before init
int supl_host_set;
char supl_host_buf[101];
int supl_port_buf;
int c2k_host_set;
char c2k_host_buf[101];
int c2k_port_buf;
int mpc_host_set;
char mpc_host_buf[101];
int mpc_port_buf;
loc_ext_parser location_ext_parser;
loc_ext_parser sv_ext_parser;
} loc_eng_data_s_type;
//loc_eng functions
int loc_eng_init(loc_eng_data_s_type &loc_eng_data,
LocCallbacks* callbacks,
LOC_API_ADAPTER_EVENT_MASK_T event,
ContextBase* context);
int loc_eng_start(loc_eng_data_s_type &loc_eng_data);
int loc_eng_stop(loc_eng_data_s_type &loc_eng_data);
void loc_eng_cleanup(loc_eng_data_s_type &loc_eng_data);
int loc_eng_inject_time(loc_eng_data_s_type &loc_eng_data,
GpsUtcTime time, int64_t timeReference,
int uncertainty);
int loc_eng_inject_location(loc_eng_data_s_type &loc_eng_data,
double latitude, double longitude,
float accuracy);
void loc_eng_delete_aiding_data(loc_eng_data_s_type &loc_eng_data,
GpsAidingData f);
int loc_eng_set_position_mode(loc_eng_data_s_type &loc_eng_data,
LocPosMode &params);
const void* loc_eng_get_extension(loc_eng_data_s_type &loc_eng_data,
const char* name);
int loc_eng_set_server_proxy(loc_eng_data_s_type &loc_eng_data,
LocServerType type, const char *hostname, int port);
void loc_eng_mute_one_session(loc_eng_data_s_type &loc_eng_data);
int loc_eng_read_config(void);
//loc_eng_agps functions
void loc_eng_agps_init(loc_eng_data_s_type &loc_eng_data,
AGpsExtCallbacks* callbacks);
int loc_eng_agps_open(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType,
const char* apn, AGpsBearerType bearerType);
int loc_eng_agps_closed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType);
int loc_eng_agps_open_failed(loc_eng_data_s_type &loc_eng_data, AGpsExtType agpsType);
void loc_eng_agps_ril_update_network_availability(loc_eng_data_s_type &loc_eng_data,
int avaiable, const char* apn);
int loc_eng_agps_install_certificates(loc_eng_data_s_type &loc_eng_data,
const DerEncodedCertificate* certificates,
size_t length);
//loc_eng_xtra functions
int loc_eng_xtra_init (loc_eng_data_s_type &loc_eng_data,
GpsXtraExtCallbacks* callbacks);
int loc_eng_xtra_inject_data(loc_eng_data_s_type &loc_eng_data,
char* data, int length);
int loc_eng_xtra_request_server(loc_eng_data_s_type &loc_eng_data);
void loc_eng_xtra_version_check(loc_eng_data_s_type &loc_eng_data, int check);
//loc_eng_ni functions
extern void loc_eng_ni_init(loc_eng_data_s_type &loc_eng_data,
GpsNiExtCallbacks *callbacks);
extern void loc_eng_ni_respond(loc_eng_data_s_type &loc_eng_data,
int notif_id, GpsUserResponseType user_response);
extern void loc_eng_ni_request_handler(loc_eng_data_s_type &loc_eng_data,
const GpsNiNotification *notif,
const void* passThrough);
extern void loc_eng_ni_reset_on_engine_restart(loc_eng_data_s_type &loc_eng_data);
void loc_eng_configuration_update (loc_eng_data_s_type &loc_eng_data,
const char* config_data, int32_t length);
int loc_eng_gps_measurement_init(loc_eng_data_s_type &loc_eng_data,
GpsMeasurementCallbacks* callbacks);
void loc_eng_gps_measurement_close(loc_eng_data_s_type &loc_eng_data);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif // LOC_ENG_H

View File

@@ -1,969 +0,0 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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_eng"
#include <loc_eng_agps.h>
#include <loc_eng_log.h>
#include <platform_lib_includes.h>
#include <loc_eng_dmn_conn_handler.h>
#include <loc_eng_dmn_conn.h>
#include <sys/time.h>
//======================================================================
// C callbacks
//======================================================================
// This is given to linked_list_add as the dealloc callback
// data -- an instance of Subscriber
static void deleteObj(void* data)
{
delete (Subscriber*)data;
}
// This is given to linked_list_search() as the comparison callback
// when the state manchine needs to process for particular subscriber
// fromCaller -- caller provides this obj
// fromList -- linked_list_search() function take this one from list
static bool hasSubscriber(void* fromCaller, void* fromList)
{
Notification* notification = (Notification*)fromCaller;
Subscriber* s1 = (Subscriber*)fromList;
return s1->forMe(*notification);
}
// This is gvien to linked_list_search() to notify subscriber objs
// when the state machine needs to inform all subscribers of resource
// status changes, e.g. when resource is GRANTED.
// fromCaller -- caller provides this ptr to a Notification obj.
// fromList -- linked_list_search() function take this one from list
static bool notifySubscriber(void* fromCaller, void* fromList)
{
Notification* notification = (Notification*)fromCaller;
Subscriber* s1 = (Subscriber*)fromList;
// we notify every subscriber indiscriminatively
// each subscriber decides if this notification is interesting.
return s1->notifyRsrcStatus(*notification) &&
// if we do not want to delete the subscriber from the
// the list, we must set this to false so this function
// returns false
notification->postNotifyDelete;
}
//======================================================================
// Notification
//======================================================================
const int Notification::BROADCAST_ALL = 0x80000000;
const int Notification::BROADCAST_ACTIVE = 0x80000001;
const int Notification::BROADCAST_INACTIVE = 0x80000002;
const unsigned char DSStateMachine::MAX_START_DATA_CALL_RETRIES = 4;
const unsigned int DSStateMachine::DATA_CALL_RETRY_DELAY_MSEC = 500;
//======================================================================
// Subscriber: BITSubscriber / ATLSubscriber / WIFISubscriber
//======================================================================
bool Subscriber::forMe(Notification &notification)
{
if (NULL != notification.rcver) {
return equals(notification.rcver);
} else {
return Notification::BROADCAST_ALL == notification.groupID ||
(Notification::BROADCAST_ACTIVE == notification.groupID &&
!isInactive()) ||
(Notification::BROADCAST_INACTIVE == notification.groupID &&
isInactive());
}
}
bool BITSubscriber::equals(const Subscriber *s) const
{
BITSubscriber* bitS = (BITSubscriber*)s;
return (ID == bitS->ID &&
(INADDR_NONE != (unsigned int)ID ||
0 == strncmp(mIPv6Addr, bitS->mIPv6Addr, sizeof(mIPv6Addr))));
}
bool BITSubscriber::notifyRsrcStatus(Notification &notification)
{
bool notify = forMe(notification);
if (notify) {
switch(notification.rsrcStatus)
{
case RSRC_UNSUBSCRIBE:
case RSRC_RELEASED:
loc_eng_dmn_conn_loc_api_server_data_conn(
LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
GPSONE_LOC_API_IF_RELEASE_SUCCESS);
break;
case RSRC_DENIED:
loc_eng_dmn_conn_loc_api_server_data_conn(
LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
GPSONE_LOC_API_IF_FAILURE);
break;
case RSRC_GRANTED:
loc_eng_dmn_conn_loc_api_server_data_conn(
LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
GPSONE_LOC_API_IF_REQUEST_SUCCESS);
break;
default:
notify = false;
}
}
return notify;
}
bool ATLSubscriber::notifyRsrcStatus(Notification &notification)
{
bool notify = forMe(notification);
if (notify) {
switch(notification.rsrcStatus)
{
case RSRC_UNSUBSCRIBE:
case RSRC_RELEASED:
((LocEngAdapter*)mLocAdapter)->atlCloseStatus(ID, 1);
break;
case RSRC_DENIED:
{
AGpsExtType type = mBackwardCompatibleMode ?
AGPS_TYPE_INVALID : mStateMachine->getType();
((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 0,
(char*)mStateMachine->getAPN(),
mStateMachine->getBearer(),
type);
}
break;
case RSRC_GRANTED:
{
AGpsExtType type = mBackwardCompatibleMode ?
AGPS_TYPE_INVALID : mStateMachine->getType();
((LocEngAdapter*)mLocAdapter)->atlOpenStatus(ID, 1,
(char*)mStateMachine->getAPN(),
mStateMachine->getBearer(),
type);
}
break;
default:
notify = false;
}
}
return notify;
}
bool WIFISubscriber::notifyRsrcStatus(Notification &notification)
{
bool notify = forMe(notification);
if (notify) {
switch(notification.rsrcStatus)
{
case RSRC_UNSUBSCRIBE:
break;
case RSRC_RELEASED:
loc_eng_dmn_conn_loc_api_server_data_conn(
senderId,
GPSONE_LOC_API_IF_RELEASE_SUCCESS);
break;
case RSRC_DENIED:
loc_eng_dmn_conn_loc_api_server_data_conn(
senderId,
GPSONE_LOC_API_IF_FAILURE);
break;
case RSRC_GRANTED:
loc_eng_dmn_conn_loc_api_server_data_conn(
senderId,
GPSONE_LOC_API_IF_REQUEST_SUCCESS);
break;
default:
notify = false;
}
}
return notify;
}
bool DSSubscriber::notifyRsrcStatus(Notification &notification)
{
bool notify = forMe(notification);
LOC_LOGD("DSSubscriber::notifyRsrcStatus. notify:%d \n",(int)(notify));
if(notify) {
switch(notification.rsrcStatus) {
case RSRC_UNSUBSCRIBE:
case RSRC_RELEASED:
case RSRC_DENIED:
case RSRC_GRANTED:
((DSStateMachine *)mStateMachine)->informStatus(notification.rsrcStatus, ID);
break;
default:
notify = false;
}
}
return notify;
}
void DSSubscriber :: setInactive()
{
mIsInactive = true;
((DSStateMachine *)mStateMachine)->informStatus(RSRC_UNSUBSCRIBE, ID);
}
//======================================================================
// AgpsState: AgpsReleasedState / AgpsPendingState / AgpsAcquiredState
//======================================================================
// AgpsReleasedState
class AgpsReleasedState : public AgpsState
{
friend class AgpsStateMachine;
inline AgpsReleasedState(AgpsStateMachine* stateMachine) :
AgpsState(stateMachine)
{ mReleasedState = this; }
inline ~AgpsReleasedState() {}
public:
virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data);
inline virtual char* whoami() {return (char*)"AgpsReleasedState";}
};
AgpsState* AgpsReleasedState::onRsrcEvent(AgpsRsrcStatus event, void* data)
{
LOC_LOGD("AgpsReleasedState::onRsrcEvent; event:%d\n", (int)event);
if (mStateMachine->hasSubscribers()) {
LOC_LOGE("Error: %s subscriber list not empty!!!", whoami());
// I don't know how to recover from it. I am adding this rather
// for debugging purpose.
}
AgpsState* nextState = this;
switch (event)
{
case RSRC_SUBSCRIBE:
{
// no notification until we get RSRC_GRANTED
// but we need to add subscriber to the list
mStateMachine->addSubscriber((Subscriber*)data);
// request from connecivity service for NIF
//The if condition is added so that if the data call setup fails
//for DS State Machine, we want to retry in released state.
//for AGps State Machine, sendRsrcRequest() will always return success
if(!mStateMachine->sendRsrcRequest(GPS_REQUEST_AGPS_DATA_CONN)) {
// move the state to PENDING
nextState = mPendingState;
}
}
break;
case RSRC_UNSUBSCRIBE:
{
// the list should really be empty, nothing to remove.
// but we might as well just tell the client it is
// unsubscribed. False tolerance, right?
Subscriber* subscriber = (Subscriber*) data;
Notification notification(subscriber, event, false);
subscriber->notifyRsrcStatus(notification);
}
// break;
case RSRC_GRANTED:
case RSRC_RELEASED:
case RSRC_DENIED:
default:
LOC_LOGW("%s: unrecognized event %d", whoami(), event);
// no state change.
break;
}
LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d",
whoami(), nextState->whoami(), event);
return nextState;
}
// AgpsPendingState
class AgpsPendingState : public AgpsState
{
friend class AgpsStateMachine;
inline AgpsPendingState(AgpsStateMachine* stateMachine) :
AgpsState(stateMachine)
{ mPendingState = this; }
inline ~AgpsPendingState() {}
public:
virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data);
inline virtual char* whoami() {return (char*)"AgpsPendingState";}
};
AgpsState* AgpsPendingState::onRsrcEvent(AgpsRsrcStatus event, void* data)
{
AgpsState* nextState = this;;
LOC_LOGD("AgpsPendingState::onRsrcEvent; event:%d\n", (int)event);
switch (event)
{
case RSRC_SUBSCRIBE:
{
// already requested for NIF resource,
// do nothing until we get RSRC_GRANTED indication
// but we need to add subscriber to the list
mStateMachine->addSubscriber((Subscriber*)data);
// no state change.
}
break;
case RSRC_UNSUBSCRIBE:
{
Subscriber* subscriber = (Subscriber*) data;
if (subscriber->waitForCloseComplete()) {
subscriber->setInactive();
} else {
// auto notify this subscriber of the unsubscribe
Notification notification(subscriber, event, true);
mStateMachine->notifySubscribers(notification);
}
// now check if there is any subscribers left
if (!mStateMachine->hasSubscribers()) {
// no more subscribers, move to RELEASED state
nextState = mReleasedState;
// tell connecivity service we can release NIF
mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN);
} else if (!mStateMachine->hasActiveSubscribers()) {
// only inactive subscribers, move to RELEASING state
nextState = mReleasingState;
// tell connecivity service we can release NIF
mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN);
}
}
break;
case RSRC_GRANTED:
{
nextState = mAcquiredState;
Notification notification(Notification::BROADCAST_ACTIVE, event, false);
// notify all subscribers NIF resource GRANTED
// by setting false, we keep subscribers on the linked list
mStateMachine->notifySubscribers(notification);
}
break;
case RSRC_RELEASED:
// no state change.
// we are expecting either GRANTED or DENIED. Handling RELEASED
// may like break our state machine in race conditions.
break;
case RSRC_DENIED:
{
nextState = mReleasedState;
Notification notification(Notification::BROADCAST_ALL, event, true);
// notify all subscribers NIF resource RELEASED or DENIED
// by setting true, we remove subscribers from the linked list
mStateMachine->notifySubscribers(notification);
}
break;
default:
LOC_LOGE("%s: unrecognized event %d", whoami(), event);
// no state change.
}
LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d",
whoami(), nextState->whoami(), event);
return nextState;
}
class AgpsAcquiredState : public AgpsState
{
friend class AgpsStateMachine;
inline AgpsAcquiredState(AgpsStateMachine* stateMachine) :
AgpsState(stateMachine)
{ mAcquiredState = this; }
inline ~AgpsAcquiredState() {}
public:
virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data);
inline virtual char* whoami() { return (char*)"AgpsAcquiredState"; }
};
AgpsState* AgpsAcquiredState::onRsrcEvent(AgpsRsrcStatus event, void* data)
{
AgpsState* nextState = this;
LOC_LOGD("AgpsAcquiredState::onRsrcEvent; event:%d\n", (int)event);
switch (event)
{
case RSRC_SUBSCRIBE:
{
// we already have the NIF resource, simply notify subscriber
Subscriber* subscriber = (Subscriber*) data;
// we have rsrc in hand, so grant it right away
Notification notification(subscriber, RSRC_GRANTED, false);
subscriber->notifyRsrcStatus(notification);
// add subscriber to the list
mStateMachine->addSubscriber(subscriber);
// no state change.
}
break;
case RSRC_UNSUBSCRIBE:
{
Subscriber* subscriber = (Subscriber*) data;
if (subscriber->waitForCloseComplete()) {
subscriber->setInactive();
} else {
// auto notify this subscriber of the unsubscribe
Notification notification(subscriber, event, true);
mStateMachine->notifySubscribers(notification);
}
// now check if there is any subscribers left
if (!mStateMachine->hasSubscribers()) {
// no more subscribers, move to RELEASED state
nextState = mReleasedState;
// tell connecivity service we can release NIF
mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN);
} else if (!mStateMachine->hasActiveSubscribers()) {
// only inactive subscribers, move to RELEASING state
nextState = mReleasingState;
// tell connecivity service we can release NIF
mStateMachine->sendRsrcRequest(GPS_RELEASE_AGPS_DATA_CONN);
}
}
break;
case RSRC_GRANTED:
LOC_LOGW("%s: %d, RSRC_GRANTED already received", whoami(), event);
// no state change.
break;
case RSRC_RELEASED:
{
LOC_LOGW("%s: %d, a force rsrc release", whoami(), event);
nextState = mReleasedState;
Notification notification(Notification::BROADCAST_ALL, event, true);
// by setting true, we remove subscribers from the linked list
mStateMachine->notifySubscribers(notification);
}
break;
case RSRC_DENIED:
// no state change.
// we are expecting RELEASED. Handling DENIED
// may like break our state machine in race conditions.
break;
default:
LOC_LOGE("%s: unrecognized event %d", whoami(), event);
// no state change.
}
LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d",
whoami(), nextState->whoami(), event);
return nextState;
}
// AgpsPendingState
class AgpsReleasingState : public AgpsState
{
friend class AgpsStateMachine;
inline AgpsReleasingState(AgpsStateMachine* stateMachine) :
AgpsState(stateMachine)
{ mReleasingState = this; }
inline ~AgpsReleasingState() {}
public:
virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data);
inline virtual char* whoami() {return (char*)"AgpsReleasingState";}
};
AgpsState* AgpsReleasingState::onRsrcEvent(AgpsRsrcStatus event, void* data)
{
AgpsState* nextState = this;;
LOC_LOGD("AgpsReleasingState::onRsrcEvent; event:%d\n", (int)event);
switch (event)
{
case RSRC_SUBSCRIBE:
{
// already requested for NIF resource,
// do nothing until we get RSRC_GRANTED indication
// but we need to add subscriber to the list
mStateMachine->addSubscriber((Subscriber*)data);
// no state change.
}
break;
case RSRC_UNSUBSCRIBE:
{
Subscriber* subscriber = (Subscriber*) data;
if (subscriber->waitForCloseComplete()) {
subscriber->setInactive();
} else {
// auto notify this subscriber of the unsubscribe
Notification notification(subscriber, event, true);
mStateMachine->notifySubscribers(notification);
}
// now check if there is any subscribers left
if (!mStateMachine->hasSubscribers()) {
// no more subscribers, move to RELEASED state
nextState = mReleasedState;
}
}
break;
case RSRC_DENIED:
// A race condition subscriber unsubscribes before AFW denies resource.
case RSRC_RELEASED:
{
nextState = mAcquiredState;
Notification notification(Notification::BROADCAST_INACTIVE, event, true);
// notify all subscribers that are active NIF resource RELEASE
// by setting false, we keep subscribers on the linked list
mStateMachine->notifySubscribers(notification);
if (mStateMachine->hasActiveSubscribers()) {
nextState = mPendingState;
// request from connecivity service for NIF
mStateMachine->sendRsrcRequest(GPS_REQUEST_AGPS_DATA_CONN);
} else {
nextState = mReleasedState;
}
}
break;
case RSRC_GRANTED:
default:
LOC_LOGE("%s: unrecognized event %d", whoami(), event);
// no state change.
}
LOC_LOGD("onRsrcEvent, old state %s, new state %s, event %d",
whoami(), nextState->whoami(), event);
return nextState;
}
//======================================================================
//Servicer
//======================================================================
Servicer* Servicer :: getServicer(servicerType type, void *cb_func)
{
LOC_LOGD(" Enter getServicer type:%d\n", (int)type);
switch(type) {
case servicerTypeNoCbParam:
return (new Servicer(cb_func));
case servicerTypeExt:
return (new ExtServicer(cb_func));
case servicerTypeAgps:
return (new AGpsServicer(cb_func));
default:
return NULL;
}
}
int Servicer :: requestRsrc(void *cb_data)
{
callback();
return 0;
}
int ExtServicer :: requestRsrc(void *cb_data)
{
int ret=-1;
LOC_LOGD("Enter ExtServicer :: requestRsrc\n");
ret = callbackExt(cb_data);
LOC_LOGD("Exit ExtServicer :: requestRsrc\n");
return(ret);
}
int AGpsServicer :: requestRsrc(void *cb_data)
{
callbackAGps((AGpsStatus *)cb_data);
return 0;
}
//======================================================================
// AgpsStateMachine
//======================================================================
AgpsStateMachine::AgpsStateMachine(servicerType servType,
void *cb_func,
AGpsExtType type,
bool enforceSingleSubscriber) :
mStatePtr(new AgpsReleasedState(this)),mType(type),
mAPN(NULL),
mAPNLen(0),
mBearer(AGPS_APN_BEARER_INVALID),
mEnforceSingleSubscriber(enforceSingleSubscriber),
mServicer(Servicer :: getServicer(servType, (void *)cb_func))
{
linked_list_init(&mSubscribers);
// setting up mReleasedState
mStatePtr->mPendingState = new AgpsPendingState(this);
mStatePtr->mAcquiredState = new AgpsAcquiredState(this);
mStatePtr->mReleasingState = new AgpsReleasingState(this);
// setting up mAcquiredState
mStatePtr->mAcquiredState->mReleasedState = mStatePtr;
mStatePtr->mAcquiredState->mPendingState = mStatePtr->mPendingState;
mStatePtr->mAcquiredState->mReleasingState = mStatePtr->mReleasingState;
// setting up mPendingState
mStatePtr->mPendingState->mAcquiredState = mStatePtr->mAcquiredState;
mStatePtr->mPendingState->mReleasedState = mStatePtr;
mStatePtr->mPendingState->mReleasingState = mStatePtr->mReleasingState;
// setting up mReleasingState
mStatePtr->mReleasingState->mReleasedState = mStatePtr;
mStatePtr->mReleasingState->mPendingState = mStatePtr->mPendingState;
mStatePtr->mReleasingState->mAcquiredState = mStatePtr->mAcquiredState;
}
AgpsStateMachine::~AgpsStateMachine()
{
dropAllSubscribers();
// free the 3 states. We must read out all 3 pointers first.
// Otherwise we run the risk of getting pointers from already
// freed memory.
AgpsState* acquiredState = mStatePtr->mAcquiredState;
AgpsState* releasedState = mStatePtr->mReleasedState;
AgpsState* pendindState = mStatePtr->mPendingState;
AgpsState* releasingState = mStatePtr->mReleasingState;
delete acquiredState;
delete releasedState;
delete pendindState;
delete releasingState;
delete mServicer;
linked_list_destroy(&mSubscribers);
if (NULL != mAPN) {
delete[] mAPN;
mAPN = NULL;
}
}
void AgpsStateMachine::setAPN(const char* apn, unsigned int len)
{
if (NULL != mAPN) {
delete mAPN;
}
if (NULL != apn) {
mAPN = new char[len+1];
memcpy(mAPN, apn, len);
mAPN[len] = NULL;
mAPNLen = len;
} else {
mAPN = NULL;
mAPNLen = 0;
}
}
void AgpsStateMachine::onRsrcEvent(AgpsRsrcStatus event)
{
switch (event)
{
case RSRC_GRANTED:
case RSRC_RELEASED:
case RSRC_DENIED:
mStatePtr = mStatePtr->onRsrcEvent(event, NULL);
break;
default:
LOC_LOGW("AgpsStateMachine: unrecognized event %d", event);
break;
}
}
void AgpsStateMachine::notifySubscribers(Notification& notification) const
{
if (notification.postNotifyDelete) {
// just any non NULL value to get started
Subscriber* s = (Subscriber*)~0;
while (NULL != s) {
s = NULL;
// if the last param sets to true, _search will delete
// the node from the list for us. But the problem is
// once that is done, _search returns, leaving the
// rest of the list unprocessed. So we need a loop.
linked_list_search(mSubscribers, (void**)&s, notifySubscriber,
(void*)&notification, true);
delete s;
}
} else {
// no loop needed if it the last param sets to false, which
// mean nothing gets deleted from the list.
linked_list_search(mSubscribers, NULL, notifySubscriber,
(void*)&notification, false);
}
}
void AgpsStateMachine::addSubscriber(Subscriber* subscriber) const
{
Subscriber* s = NULL;
Notification notification((const Subscriber*)subscriber);
linked_list_search(mSubscribers, (void**)&s,
hasSubscriber, (void*)&notification, false);
if (NULL == s) {
linked_list_add(mSubscribers, subscriber->clone(), deleteObj);
}
}
int AgpsStateMachine::sendRsrcRequest(AGpsStatusValue action) const
{
Subscriber* s = NULL;
Notification notification(Notification::BROADCAST_ACTIVE);
linked_list_search(mSubscribers, (void**)&s, hasSubscriber,
(void*)&notification, false);
if ((NULL == s) == (GPS_RELEASE_AGPS_DATA_CONN == action)) {
AGpsExtStatus nifRequest;
nifRequest.size = sizeof(nifRequest);
nifRequest.type = mType;
nifRequest.status = action;
if (s == NULL) {
nifRequest.ipv4_addr = INADDR_NONE;
memset(&nifRequest.addr, 0, sizeof(nifRequest.addr));
nifRequest.ssid[0] = '\0';
nifRequest.password[0] = '\0';
} else {
s->setIPAddresses(nifRequest.addr);
s->setWifiInfo(nifRequest.ssid, nifRequest.password);
}
CALLBACK_LOG_CALLFLOW("agps_cb", %s, loc_get_agps_status_name(action));
mServicer->requestRsrc((void *)&nifRequest);
}
return 0;
}
void AgpsStateMachine::subscribeRsrc(Subscriber *subscriber)
{
if (mEnforceSingleSubscriber && hasSubscribers()) {
Notification notification(Notification::BROADCAST_ALL, RSRC_DENIED, true);
notifySubscriber(&notification, subscriber);
} else {
mStatePtr = mStatePtr->onRsrcEvent(RSRC_SUBSCRIBE, (void*)subscriber);
}
}
bool AgpsStateMachine::unsubscribeRsrc(Subscriber *subscriber)
{
Subscriber* s = NULL;
Notification notification((const Subscriber*)subscriber);
linked_list_search(mSubscribers, (void**)&s,
hasSubscriber, (void*)&notification, false);
if (NULL != s) {
mStatePtr = mStatePtr->onRsrcEvent(RSRC_UNSUBSCRIBE, (void*)s);
return true;
}
return false;
}
bool AgpsStateMachine::hasActiveSubscribers() const
{
Subscriber* s = NULL;
Notification notification(Notification::BROADCAST_ACTIVE);
linked_list_search(mSubscribers, (void**)&s,
hasSubscriber, (void*)&notification, false);
return NULL != s;
}
//======================================================================
// DSStateMachine
//======================================================================
void delay_callback(void *callbackData, int result)
{
if(callbackData) {
DSStateMachine *DSSMInstance = (DSStateMachine *)callbackData;
DSSMInstance->retryCallback();
}
else {
LOC_LOGE(" NULL argument received. Failing.\n");
goto err;
}
err:
return;
}
DSStateMachine :: DSStateMachine(servicerType type, void *cb_func,
LocEngAdapter* adapterHandle):
AgpsStateMachine(type, cb_func, AGPS_TYPE_INVALID,false),
mLocAdapter(adapterHandle)
{
LOC_LOGD("%s:%d]: New DSStateMachine\n", __func__, __LINE__);
mRetries = 0;
}
void DSStateMachine :: retryCallback(void)
{
DSSubscriber *subscriber = NULL;
Notification notification(Notification::BROADCAST_ACTIVE);
linked_list_search(mSubscribers, (void**)&subscriber, hasSubscriber,
(void*)&notification, false);
if(subscriber)
mLocAdapter->requestSuplES(subscriber->ID);
else
LOC_LOGE("DSStateMachine :: retryCallback: No subscriber found." \
"Cannot retry data call\n");
return;
}
int DSStateMachine :: sendRsrcRequest(AGpsStatusValue action) const
{
DSSubscriber* s = NULL;
dsCbData cbData;
int ret=-1;
int connHandle=-1;
LOC_LOGD("Enter DSStateMachine :: sendRsrcRequest\n");
Notification notification(Notification::BROADCAST_ACTIVE);
linked_list_search(mSubscribers, (void**)&s, hasSubscriber,
(void*)&notification, false);
if(s) {
connHandle = s->ID;
LOC_LOGD("DSStateMachine :: sendRsrcRequest - subscriber found\n");
}
else
LOC_LOGD("DSStateMachine :: sendRsrcRequest - No subscriber found\n");
cbData.action = action;
cbData.mAdapter = mLocAdapter;
ret = mServicer->requestRsrc((void *)&cbData);
//Only the request to start data call returns a success/failure
//The request to stop data call will always succeed
//Hence, the below block will only be executed when the
//request to start the data call fails
switch(ret) {
case LOC_API_ADAPTER_ERR_ENGINE_BUSY:
LOC_LOGD("DSStateMachine :: sendRsrcRequest - Failure returned: %d\n",ret);
((DSStateMachine *)this)->incRetries();
if(mRetries > MAX_START_DATA_CALL_RETRIES) {
LOC_LOGE(" Failed to start Data call. Fallback to normal ATL SUPL\n");
informStatus(RSRC_DENIED, connHandle);
}
else {
if(loc_timer_start(DATA_CALL_RETRY_DELAY_MSEC, delay_callback, (void *)this)) {
LOC_LOGE("Error: Could not start delay thread\n");
ret = -1;
goto err;
}
}
break;
case LOC_API_ADAPTER_ERR_UNSUPPORTED:
LOC_LOGE("No profile found for emergency call. Fallback to normal SUPL ATL\n");
informStatus(RSRC_DENIED, connHandle);
break;
case LOC_API_ADAPTER_ERR_SUCCESS:
LOC_LOGD("%s:%d]: Request to start data call sent\n", __func__, __LINE__);
break;
case -1:
//One of the ways this case can be encountered is if the callback function
//receives a null argument, it just exits with -1 error
LOC_LOGE("Error: Something went wrong somewhere. Falling back to normal SUPL ATL\n");
informStatus(RSRC_DENIED, connHandle);
break;
default:
LOC_LOGE("%s:%d]: Unrecognized return value\n", __func__, __LINE__);
}
err:
LOC_LOGD("EXIT DSStateMachine :: sendRsrcRequest; ret = %d\n", ret);
return ret;
}
void DSStateMachine :: onRsrcEvent(AgpsRsrcStatus event)
{
void* currState = (void *)mStatePtr;
LOC_LOGD("Enter DSStateMachine :: onRsrcEvent. event = %d\n", (int)event);
switch (event)
{
case RSRC_GRANTED:
LOC_LOGD("DSStateMachine :: onRsrcEvent RSRC_GRANTED\n");
mStatePtr = mStatePtr->onRsrcEvent(event, NULL);
break;
case RSRC_RELEASED:
LOC_LOGD("DSStateMachine :: onRsrcEvent RSRC_RELEASED\n");
mStatePtr = mStatePtr->onRsrcEvent(event, NULL);
//To handle the case where we get a RSRC_RELEASED in
//pending state, we translate that to a RSRC_DENIED state
//since the callback from DSI is either RSRC_GRANTED or RSRC_RELEASED
//for when the call is connected or disconnected respectively.
if((void *)mStatePtr != currState)
break;
else {
event = RSRC_DENIED;
LOC_LOGE(" Switching event to RSRC_DENIED\n");
}
case RSRC_DENIED:
mStatePtr = mStatePtr->onRsrcEvent(event, NULL);
break;
default:
LOC_LOGW("AgpsStateMachine: unrecognized event %d", event);
break;
}
LOC_LOGD("Exit DSStateMachine :: onRsrcEvent. event = %d\n", (int)event);
}
void DSStateMachine :: informStatus(AgpsRsrcStatus status, int ID) const
{
LOC_LOGD("DSStateMachine :: informStatus. Status=%d\n",(int)status);
switch(status) {
case RSRC_UNSUBSCRIBE:
mLocAdapter->atlCloseStatus(ID, 1);
break;
case RSRC_RELEASED:
mLocAdapter->closeDataCall();
break;
case RSRC_DENIED:
((DSStateMachine *)this)->mRetries = 0;
mLocAdapter->requestATL(ID, AGPS_TYPE_SUPL);
break;
case RSRC_GRANTED:
mLocAdapter->atlOpenStatus(ID, 1,
NULL,
AGPS_APN_BEARER_INVALID,
AGPS_TYPE_INVALID);
break;
default:
LOC_LOGW("DSStateMachine :: informStatus - unknown status");
}
return;
}

View File

@@ -1,435 +0,0 @@
/* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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_AGPS_H__
#define __LOC_ENG_AGPS_H__
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
#include <arpa/inet.h>
#include <hardware/gps.h>
#include <gps_extended.h>
#include <loc_core_log.h>
#include <linked_list.h>
#include <loc_timer.h>
#include <LocEngAdapter.h>
#include <platform_lib_includes.h>
#if defined(USE_GLIB) && !defined(OFF_TARGET)
#include <glib.h>
#endif /* USE_GLIB */
// forward declaration
class AgpsStateMachine;
struct Subscriber;
// NIF resource events
typedef enum {
RSRC_SUBSCRIBE,
RSRC_UNSUBSCRIBE,
RSRC_GRANTED,
RSRC_RELEASED,
RSRC_DENIED,
RSRC_STATUS_MAX
} AgpsRsrcStatus;
typedef enum {
servicerTypeNoCbParam,
servicerTypeAgps,
servicerTypeExt
}servicerType;
//DS Callback struct
typedef struct {
LocEngAdapter *mAdapter;
AGpsStatusValue action;
}dsCbData;
// information bundle for subscribers
struct Notification {
// goes to every subscriber
static const int BROADCAST_ALL;
// goes to every ACTIVE subscriber
static const int BROADCAST_ACTIVE;
// goes to every INACTIVE subscriber
static const int BROADCAST_INACTIVE;
// go to a specific subscriber
const Subscriber* rcver;
// broadcast
const int groupID;
// the new resource status event
const AgpsRsrcStatus rsrcStatus;
// should the subscriber be deleted after the notification
const bool postNotifyDelete;
// convenient constructor
inline Notification(const int broadcast,
const AgpsRsrcStatus status,
const bool deleteAfterwards) :
rcver(NULL), groupID(broadcast), rsrcStatus(status),
postNotifyDelete(deleteAfterwards) {}
// convenient constructor
inline Notification(const Subscriber* subscriber,
const AgpsRsrcStatus status,
const bool deleteAfterwards) :
rcver(subscriber), groupID(-1), rsrcStatus(status),
postNotifyDelete(deleteAfterwards) {}
// convenient constructor
inline Notification(const int broadcast) :
rcver(NULL), groupID(broadcast), rsrcStatus(RSRC_STATUS_MAX),
postNotifyDelete(false) {}
// convenient constructor
inline Notification(const Subscriber* subscriber) :
rcver(subscriber), groupID(-1), rsrcStatus(RSRC_STATUS_MAX),
postNotifyDelete(false) {}
};
class AgpsState {
// allows AgpsStateMachine to access private data
// no class members are public. We don't want
// anyone but state machine to use state.
friend class AgpsStateMachine;
friend class DSStateMachine;
// state transitions are done here.
// Each state implements its own transitions (of course).
inline virtual AgpsState* onRsrcEvent(AgpsRsrcStatus event, void* data) = 0;
protected:
// handle back to state machine
const AgpsStateMachine* mStateMachine;
// each state has pointers to all 3 states
// one of which is to itself.
AgpsState* mReleasedState;
AgpsState* mAcquiredState;
AgpsState* mPendingState;
AgpsState* mReleasingState;
inline AgpsState(const AgpsStateMachine *stateMachine) :
mStateMachine(stateMachine),
mReleasedState(NULL),
mAcquiredState(NULL),
mPendingState(NULL),
mReleasingState(NULL) {}
virtual ~AgpsState() {}
public:
// for logging purpose
inline virtual char* whoami() = 0;
};
class Servicer {
void (*callback)(void);
public:
static Servicer* getServicer(servicerType type, void *cb_func);
virtual int requestRsrc(void *cb_data);
Servicer() {}
Servicer(void *cb_func)
{ callback = (void(*)(void))(cb_func); }
virtual ~Servicer(){}
inline virtual char *whoami() {return (char*)"Servicer";}
};
class ExtServicer : public Servicer {
int (*callbackExt)(void *cb_data);
public:
int requestRsrc(void *cb_data);
ExtServicer() {}
ExtServicer(void *cb_func)
{ callbackExt = (int(*)(void *))(cb_func); }
virtual ~ExtServicer(){}
inline virtual char *whoami() {return (char*)"ExtServicer";}
};
class AGpsServicer : public Servicer {
void (*callbackAGps)(AGpsStatus* status);
public:
int requestRsrc(void *cb_data);
AGpsServicer() {}
AGpsServicer(void *cb_func)
{ callbackAGps = (void(*)(AGpsStatus *))(cb_func); }
virtual ~AGpsServicer(){}
inline virtual char *whoami() {return (char*)"AGpsServicer";}
};
class AgpsStateMachine {
protected:
// a linked list of subscribers.
void* mSubscribers;
//handle to whoever provides the service
Servicer *mServicer;
// allows AgpsState to access private data
// each state is really internal data to the
// state machine, so it should be able to
// access anything within the state machine.
friend class AgpsState;
// pointer to the current state.
AgpsState* mStatePtr;
private:
// NIF type: AGNSS or INTERNET.
const AGpsExtType mType;
// apn to the NIF. Each state machine tracks
// resource state of a particular NIF. For each
// NIF, there is also an active APN.
char* mAPN;
// for convenience, we don't do strlen each time.
unsigned int mAPNLen;
// bear
AGpsBearerType mBearer;
// ipv4 address for routing
bool mEnforceSingleSubscriber;
public:
AgpsStateMachine(servicerType servType, void *cb_func,
AGpsExtType type, bool enforceSingleSubscriber);
virtual ~AgpsStateMachine();
// self explanatory methods below
void setAPN(const char* apn, unsigned int len);
inline const char* getAPN() const { return (const char*)mAPN; }
inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; }
inline AGpsBearerType getBearer() const { return mBearer; }
inline AGpsExtType getType() const { return (AGpsExtType)mType; }
// someone, a ATL client or BIT, is asking for NIF
void subscribeRsrc(Subscriber *subscriber);
// someone, a ATL client or BIT, is done with NIF
bool unsubscribeRsrc(Subscriber *subscriber);
// add a subscriber in the linked list, if not already there.
void addSubscriber(Subscriber* subscriber) const;
virtual void onRsrcEvent(AgpsRsrcStatus event);
// put the data together and send the FW
virtual int sendRsrcRequest(AGpsStatusValue action) const;
//if list is empty, linked_list_empty returns 1
//else if list is not empty, returns 0
//so hasSubscribers() returns 1 if list is not empty
//and returns 0 if list is empty
inline bool hasSubscribers() const
{ return !linked_list_empty(mSubscribers); }
bool hasActiveSubscribers() const;
inline void dropAllSubscribers() const
{ linked_list_flush(mSubscribers); }
// private. Only a state gets to call this.
void notifySubscribers(Notification& notification) const;
};
class DSStateMachine : public AgpsStateMachine {
static const unsigned char MAX_START_DATA_CALL_RETRIES;
static const unsigned int DATA_CALL_RETRY_DELAY_MSEC;
LocEngAdapter* mLocAdapter;
unsigned char mRetries;
public:
DSStateMachine(servicerType type,
void *cb_func,
LocEngAdapter* adapterHandle);
int sendRsrcRequest(AGpsStatusValue action) const;
void onRsrcEvent(AgpsRsrcStatus event);
void retryCallback();
void informStatus(AgpsRsrcStatus status, int ID) const;
inline void incRetries() {mRetries++;}
inline virtual char *whoami() {return (char*)"DSStateMachine";}
};
// each subscriber is a AGPS client. In the case of ATL, there could be
// multiple clients from modem. In the case of BIT, there is only one
// cilent from BIT daemon.
struct Subscriber {
const uint32_t ID;
const AgpsStateMachine* mStateMachine;
inline Subscriber(const int id,
const AgpsStateMachine* stateMachine) :
ID(id), mStateMachine(stateMachine) {}
inline virtual ~Subscriber() {}
virtual void setIPAddresses(uint32_t &v4, char* v6) = 0;
virtual void setIPAddresses(struct sockaddr_storage& addr) = 0;
inline virtual void setWifiInfo(char* ssid, char* password)
{ ssid[0] = 0; password[0] = 0; }
inline virtual bool equals(const Subscriber *s) const
{ return ID == s->ID; }
// notifies a subscriber a new NIF resource status, usually
// either GRANTE, DENIED, or RELEASED
virtual bool notifyRsrcStatus(Notification &notification) = 0;
virtual bool waitForCloseComplete() { return false; }
virtual void setInactive() {}
virtual bool isInactive() { return false; }
virtual Subscriber* clone() = 0;
// checks if this notification is for me, i.e.
// either has my id, or has a broadcast id.
bool forMe(Notification &notification);
};
// 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) {
mIPv6Addr[0] = 0;
} else {
memcpy(mIPv6Addr, ipv6, sizeof(mIPv6Addr));
}
}
virtual bool notifyRsrcStatus(Notification &notification);
inline virtual void setIPAddresses(uint32_t &v4, char* v6)
{ v4 = ID; memcpy(v6, mIPv6Addr, sizeof(mIPv6Addr)); }
inline virtual void setIPAddresses(struct sockaddr_storage& addr)
{ addr.ss_family = AF_INET6;/*todo: convert mIPv6Addr into addr */ }
virtual Subscriber* clone()
{
return new BITSubscriber(mStateMachine, ID, mIPv6Addr);
}
virtual bool equals(const Subscriber *s) const;
inline virtual ~BITSubscriber(){}
};
// ATLSubscriber, created with requests from ATL
struct ATLSubscriber : public Subscriber {
const LocEngAdapter* mLocAdapter;
const bool mBackwardCompatibleMode;
inline ATLSubscriber(const int id,
const AgpsStateMachine* stateMachine,
const LocEngAdapter* adapter,
const bool compatibleMode) :
Subscriber(id, stateMachine), mLocAdapter(adapter),
mBackwardCompatibleMode(compatibleMode){}
virtual bool notifyRsrcStatus(Notification &notification);
inline virtual void setIPAddresses(uint32_t &v4, char* v6)
{ v4 = INADDR_NONE; v6[0] = 0; }
inline virtual void setIPAddresses(struct sockaddr_storage& addr)
{ addr.ss_family = AF_INET6; }
inline virtual Subscriber* clone()
{
return new ATLSubscriber(ID, mStateMachine, mLocAdapter,
mBackwardCompatibleMode);
}
inline virtual ~ATLSubscriber(){}
};
// WIFISubscriber, created with requests from MSAPM or QuIPC
struct WIFISubscriber : public Subscriber {
char * mSSID;
char * mPassword;
loc_if_req_sender_id_e_type senderId;
bool mIsInactive;
inline WIFISubscriber(const AgpsStateMachine* stateMachine,
char * ssid, char * password, loc_if_req_sender_id_e_type sender_id) :
Subscriber(sender_id, stateMachine),
mSSID(NULL == ssid ? NULL : new char[SSID_BUF_SIZE]),
mPassword(NULL == password ? NULL : new char[SSID_BUF_SIZE]),
senderId(sender_id)
{
if (NULL != mSSID)
strlcpy(mSSID, ssid, SSID_BUF_SIZE);
if (NULL != mPassword)
strlcpy(mPassword, password, SSID_BUF_SIZE);
mIsInactive = false;
}
virtual bool notifyRsrcStatus(Notification &notification);
inline virtual void setIPAddresses(uint32_t &v4, char* v6) {}
inline virtual void setIPAddresses(struct sockaddr_storage& addr)
{ addr.ss_family = AF_INET6; }
inline virtual void setWifiInfo(char* ssid, char* password)
{
if (NULL != mSSID)
strlcpy(ssid, mSSID, SSID_BUF_SIZE);
else
ssid[0] = '\0';
if (NULL != mPassword)
strlcpy(password, mPassword, SSID_BUF_SIZE);
else
password[0] = '\0';
}
inline virtual bool waitForCloseComplete() { return true; }
inline virtual void setInactive() { mIsInactive = true; }
inline virtual bool isInactive() { return mIsInactive; }
virtual Subscriber* clone()
{
return new WIFISubscriber(mStateMachine, mSSID, mPassword, senderId);
}
inline virtual ~WIFISubscriber(){}
};
struct DSSubscriber : public Subscriber {
bool mIsInactive;
inline DSSubscriber(const AgpsStateMachine *stateMachine,
const int id) :
Subscriber(id, stateMachine)
{
mIsInactive = false;
}
inline virtual void setIPAddresses(uint32_t &v4, char* v6) {}
inline virtual void setIPAddresses(struct sockaddr_storage& addr)
{ addr.ss_family = AF_INET6; }
virtual Subscriber* clone()
{return new DSSubscriber(mStateMachine, ID);}
virtual bool notifyRsrcStatus(Notification &notification);
inline virtual bool waitForCloseComplete() { return true; }
virtual void setInactive();
inline virtual bool isInactive()
{ return mIsInactive; }
inline virtual ~DSSubscriber(){}
inline virtual char *whoami() {return (char*)"DSSubscriber";}
};
#endif //__LOC_ENG_AGPS_H__

View File

@@ -1,269 +0,0 @@
/* Copyright (c) 2011-2012,2014 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/stat.h>
#include <fcntl.h>
#include <linux/types.h>
#include <unistd.h>
#include <errno.h>
#include <grp.h>
#include <sys/stat.h>
#include <platform_lib_includes.h>
#include "loc_eng_dmn_conn_glue_msg.h"
#include "loc_eng_dmn_conn_handler.h"
#include "loc_eng_dmn_conn.h"
#include "loc_eng_msg.h"
static int loc_api_server_msgqid;
static int loc_api_resp_msgqid;
static int quipc_msgqid;
static int msapm_msgqid;
static int msapu_msgqid;
static const char * global_loc_api_q_path = GPSONE_LOC_API_Q_PATH;
static const char * global_loc_api_resp_q_path = GPSONE_LOC_API_RESP_Q_PATH;
static const char * global_quipc_ctrl_q_path = QUIPC_CTRL_Q_PATH;
static const char * global_msapm_ctrl_q_path = MSAPM_CTRL_Q_PATH;
static const char * global_msapu_ctrl_q_path = MSAPU_CTRL_Q_PATH;
static int loc_api_server_proc_init(void *context)
{
loc_api_server_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_q_path, O_RDWR);
//change mode/group for the global_loc_api_q_path pipe
int result = chmod (global_loc_api_q_path, 0660);
if (result != 0)
{
LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_q_path, strerror(errno));
}
struct group * gps_group = getgrnam("gps");
if (gps_group != NULL)
{
result = chown (global_loc_api_q_path, -1, gps_group->gr_gid);
if (result != 0)
{
LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n",
global_loc_api_q_path, gps_group->gr_gid, result, strerror(errno));
}
}
else
{
LOC_LOGE("getgrnam for gps failed, error code = %d\n", errno);
}
loc_api_resp_msgqid = loc_eng_dmn_conn_glue_msgget(global_loc_api_resp_q_path, O_RDWR);
//change mode/group for the global_loc_api_resp_q_path pipe
result = chmod (global_loc_api_resp_q_path, 0660);
if (result != 0)
{
LOC_LOGE("failed to change mode for %s, error = %s\n", global_loc_api_resp_q_path, strerror(errno));
}
if (gps_group != NULL)
{
result = chown (global_loc_api_resp_q_path, -1, gps_group->gr_gid);
if (result != 0)
{
LOC_LOGE("chown for pipe failed, pipe %s, gid = %d, result = %d, error = %s\n",
global_loc_api_resp_q_path,
gps_group->gr_gid, result, strerror(errno));
}
}
quipc_msgqid = loc_eng_dmn_conn_glue_msgget(global_quipc_ctrl_q_path, O_RDWR);
msapm_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapm_ctrl_q_path , O_RDWR);
msapu_msgqid = loc_eng_dmn_conn_glue_msgget(global_msapu_ctrl_q_path , O_RDWR);
LOC_LOGD("%s:%d] loc_api_server_msgqid = %d\n", __func__, __LINE__, loc_api_server_msgqid);
return 0;
}
static int loc_api_server_proc_pre(void *context)
{
return 0;
}
static int loc_api_server_proc(void *context)
{
int length, sz;
int result = 0;
static int cnt = 0;
struct ctrl_msgbuf * p_cmsgbuf;
struct ctrl_msgbuf cmsg_resp;
sz = sizeof(struct ctrl_msgbuf) + 256;
p_cmsgbuf = (struct ctrl_msgbuf *) malloc(sz);
if (!p_cmsgbuf) {
LOC_LOGE("%s:%d] Out of memory\n", __func__, __LINE__);
return -1;
}
cnt ++;
LOC_LOGD("%s:%d] %d listening on %s...\n", __func__, __LINE__, cnt, (char *) context);
length = loc_eng_dmn_conn_glue_msgrcv(loc_api_server_msgqid, p_cmsgbuf, sz);
if (length <= 0) {
free(p_cmsgbuf);
LOC_LOGE("%s:%d] fail receiving msg from gpsone_daemon, retry later\n", __func__, __LINE__);
usleep(1000);
return -1;
}
LOC_LOGD("%s:%d] received ctrl_type = %d\n", __func__, __LINE__, p_cmsgbuf->ctrl_type);
switch(p_cmsgbuf->ctrl_type) {
case GPSONE_LOC_API_IF_REQUEST:
result = loc_eng_dmn_conn_loc_api_server_if_request_handler(p_cmsgbuf, length);
break;
case GPSONE_LOC_API_IF_RELEASE:
result = loc_eng_dmn_conn_loc_api_server_if_release_handler(p_cmsgbuf, length);
break;
case GPSONE_UNBLOCK:
LOC_LOGD("%s:%d] GPSONE_UNBLOCK\n", __func__, __LINE__);
break;
default:
LOC_LOGE("%s:%d] unsupported ctrl_type = %d\n",
__func__, __LINE__, p_cmsgbuf->ctrl_type);
break;
}
free(p_cmsgbuf);
return 0;
}
static int loc_api_server_proc_post(void *context)
{
LOC_LOGD("%s:%d]\n", __func__, __LINE__);
loc_eng_dmn_conn_glue_msgremove( global_loc_api_q_path, loc_api_server_msgqid);
loc_eng_dmn_conn_glue_msgremove( global_loc_api_resp_q_path, loc_api_resp_msgqid);
loc_eng_dmn_conn_glue_msgremove( global_quipc_ctrl_q_path, quipc_msgqid);
loc_eng_dmn_conn_glue_msgremove( global_msapm_ctrl_q_path, msapm_msgqid);
loc_eng_dmn_conn_glue_msgremove( global_msapu_ctrl_q_path, msapu_msgqid);
return 0;
}
static int loc_eng_dmn_conn_unblock_proc(void)
{
struct ctrl_msgbuf cmsgbuf;
cmsgbuf.ctrl_type = GPSONE_UNBLOCK;
LOC_LOGD("%s:%d]\n", __func__, __LINE__);
loc_eng_dmn_conn_glue_msgsnd(loc_api_server_msgqid, & cmsgbuf, sizeof(cmsgbuf));
return 0;
}
static struct loc_eng_dmn_conn_thelper thelper;
int loc_eng_dmn_conn_loc_api_server_launch(thelper_create_thread create_thread_cb,
const char * loc_api_q_path, const char * resp_q_path, void *agps_handle)
{
int result;
loc_api_handle = agps_handle;
if (loc_api_q_path) global_loc_api_q_path = loc_api_q_path;
if (resp_q_path) global_loc_api_resp_q_path = resp_q_path;
result = loc_eng_dmn_conn_launch_thelper( &thelper,
loc_api_server_proc_init,
loc_api_server_proc_pre,
loc_api_server_proc,
loc_api_server_proc_post,
create_thread_cb,
(char *) global_loc_api_q_path);
if (result != 0) {
LOC_LOGE("%s:%d]\n", __func__, __LINE__);
return -1;
}
return 0;
}
int loc_eng_dmn_conn_loc_api_server_unblock(void)
{
loc_eng_dmn_conn_unblock_thelper(&thelper);
loc_eng_dmn_conn_unblock_proc();
return 0;
}
int loc_eng_dmn_conn_loc_api_server_join(void)
{
loc_eng_dmn_conn_join_thelper(&thelper);
return 0;
}
int loc_eng_dmn_conn_loc_api_server_data_conn(int sender_id, int status) {
struct ctrl_msgbuf cmsgbuf;
LOC_LOGD("%s:%d] quipc_msgqid = %d\n", __func__, __LINE__, quipc_msgqid);
cmsgbuf.ctrl_type = GPSONE_LOC_API_RESPONSE;
cmsgbuf.cmsg.cmsg_response.result = status;
switch (sender_id) {
case LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC: {
LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_QUIPC", __func__, __LINE__);
if (loc_eng_dmn_conn_glue_msgsnd(quipc_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) {
LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__);
return -1;
}
break;
}
case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM: {
LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPM", __func__, __LINE__);
if (loc_eng_dmn_conn_glue_msgsnd(msapm_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) {
LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__);
return -1;
}
break;
}
case LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU: {
LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_MSAPU", __func__, __LINE__);
if (loc_eng_dmn_conn_glue_msgsnd(msapu_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) {
LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__);
return -1;
}
break;
}
case LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON: {
LOC_LOGD("%s:%d] sender_id = LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON", __func__, __LINE__);
if (loc_eng_dmn_conn_glue_msgsnd(loc_api_resp_msgqid, & cmsgbuf, sizeof(struct ctrl_msgbuf)) < 0) {
LOC_LOGD("%s:%d] error! conn_glue_msgsnd failed\n", __func__, __LINE__);
return -1;
}
break;
}
default: {
LOC_LOGD("%s:%d] invalid sender ID!", __func__, __LINE__);
}
}
return 0;
}

View File

@@ -1,222 +0,0 @@
/* Copyright (c) 2011,2014 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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 <linux/stat.h>
#include <fcntl.h>
#include <linux/types.h>
#include <platform_lib_includes.h>
#include "loc_eng_dmn_conn_glue_msg.h"
#include "loc_eng_dmn_conn_handler.h"
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgget
DESCRIPTION
This function get a message queue
q_path - name path of the message queue
mode -
DEPENDENCIES
None
RETURN VALUE
message queue id
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgget(const char * q_path, int mode)
{
int msgqid;
msgqid = loc_eng_dmn_conn_glue_pipeget(q_path, mode);
return msgqid;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgremove
DESCRIPTION
remove a message queue
q_path - name path of the message queue
msgqid - message queue id
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgremove(const char * q_path, int msgqid)
{
int result;
result = loc_eng_dmn_conn_glue_piperemove(q_path, msgqid);
return result;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgsnd
DESCRIPTION
Send a message
msgqid - message queue id
msgp - pointer to the message to be sent
msgsz - size of the message
DEPENDENCIES
None
RETURN VALUE
number of bytes sent out or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgsnd(int msgqid, const void * msgp, size_t msgsz)
{
int result;
struct ctrl_msgbuf *pmsg = (struct ctrl_msgbuf *) msgp;
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;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgrcv
DESCRIPTION
receive a message
msgqid - message queue id
msgp - pointer to the buffer to hold the message
msgsz - size of the buffer
DEPENDENCIES
None
RETURN VALUE
number of bytes received or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgrcv(int msgqid, void *msgp, size_t msgbufsz)
{
int result;
struct ctrl_msgbuf *pmsg = (struct ctrl_msgbuf *) msgp;
result = loc_eng_dmn_conn_glue_piperead(msgqid, &(pmsg->msgsz), sizeof(pmsg->msgsz));
if (result != sizeof(pmsg->msgsz)) {
LOC_LOGE("%s:%d] pipe broken %d\n", __func__, __LINE__, result);
return -1;
}
if (msgbufsz < pmsg->msgsz) {
LOC_LOGE("%s:%d] msgbuf is too small %d < %d\n", __func__, __LINE__, (int) msgbufsz, (int) pmsg->msgsz);
return -1;
}
result = loc_eng_dmn_conn_glue_piperead(msgqid, (uint8_t *) msgp + sizeof(pmsg->msgsz), pmsg->msgsz - sizeof(pmsg->msgsz));
if (result != (int) (pmsg->msgsz - sizeof(pmsg->msgsz))) {
LOC_LOGE("%s:%d] pipe broken %d, msgsz = %d\n", __func__, __LINE__, result, (int) pmsg->msgsz);
return -1;
}
return pmsg->msgsz;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgunblock
DESCRIPTION
unblock a message queue
msgqid - message queue id
DEPENDENCIES
None
RETURN VALUE
0: success
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgunblock(int msgqid)
{
return loc_eng_dmn_conn_glue_pipeunblock(msgqid);
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_msgflush
DESCRIPTION
flush out the message in a queue
msgqid - message queue id
DEPENDENCIES
None
RETURN VALUE
number of bytes that are flushed out.
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_msgflush(int msgqid)
{
int length;
char buf[128];
do {
length = loc_eng_dmn_conn_glue_piperead(msgqid, buf, 128);
LOC_LOGD("%s:%d] %s\n", __func__, __LINE__, buf);
} while(length);
return length;
}

View File

@@ -1,215 +0,0 @@
/* Copyright (c) 2011-2012,2014 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* 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 <string.h>
#include <unistd.h>
#include <errno.h>
// #include <linux/stat.h>
#include <fcntl.h>
// #include <linux/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "loc_eng_dmn_conn_glue_pipe.h"
#include <platform_lib_includes.h>
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_pipeget
DESCRIPTION
create a named pipe.
pipe_name - pipe name path
mode - mode
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_pipeget(const char * pipe_name, int mode)
{
int fd;
int result;
LOC_LOGD("%s, mode = %d\n", pipe_name, mode);
result = mkfifo(pipe_name, 0660);
if ((result == -1) && (errno != EEXIST)) {
LOC_LOGE("failed: %s\n", strerror(errno));
return result;
}
// The mode in mkfifo is not honoured and does not provide the
// group permissions. Doing chmod to add group permissions.
result = chmod (pipe_name, 0660);
if (result != 0){
LOC_LOGE ("%s failed to change mode for %s, error = %s\n", __func__,
pipe_name, strerror(errno));
}
fd = open(pipe_name, mode);
if (fd <= 0)
{
LOC_LOGE("failed: %s\n", strerror(errno));
}
LOC_LOGD("fd = %d, %s\n", fd, pipe_name);
return fd;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_piperemove
DESCRIPTION
remove a pipe
pipe_name - pipe name path
fd - fd for the pipe
DEPENDENCIES
None
RETURN VALUE
0: success
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_piperemove(const char * pipe_name, int fd)
{
close(fd);
if (pipe_name != NULL) {
unlink(pipe_name);
LOC_LOGD("fd = %d, %s\n", fd, pipe_name);
}
return 0;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_pipewrite
DESCRIPTION
write to a pipe
fd - fd of a pipe
buf - buffer for the data to write
sz - size of the data in buffer
DEPENDENCIES
None
RETURN VALUE
number of bytes written or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_pipewrite(int fd, const void * buf, size_t sz)
{
int result;
result = write(fd, buf, sz);
/* @todo check for non EINTR & EAGAIN, shall not do select again, select_tut Law 7) */
/* LOC_LOGD("fd = %d, buf = 0x%lx, size = %d, result = %d\n", fd, (long) buf, (int) sz, (int) result); */
return result;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_piperead
DESCRIPTION
read from a pipe
fd - fd for the pipe
buf - buffer to hold the data read from pipe
sz - size of the buffer
DEPENDENCIES
None
RETURN VALUE
number of bytes read from pipe or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_piperead(int fd, void * buf, size_t sz)
{
int len;
len = read(fd, buf, sz);
/* @todo check for non EINTR & EAGAIN, shall not do select again, select_tut Law 7) */
/* LOC_LOGD("fd = %d, buf = 0x%lx, size = %d, len = %d\n", fd, (long) buf, (int) sz, len); */
return len;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_glue_pipeunblock
DESCRIPTION
unblock a pipe
fd - fd for the pipe
DEPENDENCIES
None
RETURN VALUE
0 for success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_glue_pipeunblock(int fd)
{
int result;
struct flock flock_v;
LOC_LOGD("\n");
// result = fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NDELAY);
flock_v.l_type = F_UNLCK;
flock_v.l_len = 32;
result = fcntl(fd, F_SETLK, &flock_v);
if (result < 0) {
LOC_LOGE("fcntl failure, %s\n", strerror(errno));
}
return result;
}

View File

@@ -1,50 +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.
*
*/
#ifndef LOC_ENG_DMN_CONN_GLUE_PIPE_H
#define LOC_ENG_DMN_CONN_GLUE_PIPE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <linux/types.h>
int loc_eng_dmn_conn_glue_pipeget(const char * pipe_name, int mode);
int loc_eng_dmn_conn_glue_piperemove(const char * pipe_name, int fd);
int loc_eng_dmn_conn_glue_pipewrite(int fd, const void * buf, size_t sz);
int loc_eng_dmn_conn_glue_piperead(int fd, void * buf, size_t sz);
int loc_eng_dmn_conn_glue_pipeflush(int fd);
int loc_eng_dmn_conn_glue_pipeunblock(int fd);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* LOC_ENG_DMN_CONN_GLUE_PIPE_H */

View File

@@ -1,236 +0,0 @@
/* Copyright (c) 2011-2012,2014 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation, nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <platform_lib_includes.h>
#include "loc_eng_msg.h"
#include "loc_eng_dmn_conn.h"
#include "loc_eng_dmn_conn_handler.h"
void* loc_api_handle = NULL;
int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, int len)
{
LOC_LOGD("%s:%d]\n", __func__, __LINE__);
#ifndef DEBUG_DMN_LOC_API
if (NULL == loc_api_handle) {
LOC_LOGE("%s:%d] NO agps data handle\n", __func__, __LINE__);
return 1;
}
if (NULL != loc_api_handle) {
AGpsExtType type;
switch (pmsg->cmsg.cmsg_if_request.type) {
case IF_REQUEST_TYPE_SUPL:
{
LOC_LOGD("IF_REQUEST_TYPE_SUPL");
type = AGPS_TYPE_SUPL;
break;
}
case IF_REQUEST_TYPE_WIFI:
{
LOC_LOGD("IF_REQUEST_TYPE_WIFI");
type = AGPS_TYPE_WIFI;
break;
}
case IF_REQUEST_TYPE_ANY:
{
LOC_LOGD("IF_REQUEST_TYPE_ANY");
type = AGPS_TYPE_ANY;
break;
}
default:
{
LOC_LOGD("invalid IF_REQUEST_TYPE!");
return -1;
}
}
switch (pmsg->cmsg.cmsg_if_request.sender_id) {
case IF_REQUEST_SENDER_ID_QUIPC:
{
LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC");
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");
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");
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");
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:
{
LOC_LOGD("invalid IF_REQUEST_SENDER_ID!");
return -1;
}
}
}
#else
loc_eng_dmn_conn_loc_api_server_data_conn(LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, GPSONE_LOC_API_IF_REQUEST_SUCCESS);
#endif
return 0;
}
int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, int len)
{
LOC_LOGD("%s:%d]\n", __func__, __LINE__);
#ifndef DEBUG_DMN_LOC_API
AGpsExtType type;
switch (pmsg->cmsg.cmsg_if_request.type) {
case IF_REQUEST_TYPE_SUPL:
{
LOC_LOGD("IF_REQUEST_TYPE_SUPL");
type = AGPS_TYPE_SUPL;
break;
}
case IF_REQUEST_TYPE_WIFI:
{
LOC_LOGD("IF_REQUEST_TYPE_WIFI");
type = AGPS_TYPE_WIFI;
break;
}
case IF_REQUEST_TYPE_ANY:
{
LOC_LOGD("IF_REQUEST_TYPE_ANY");
type = AGPS_TYPE_ANY;
break;
}
default:
{
LOC_LOGD("invalid IF_REQUEST_TYPE!");
return -1;
}
}
switch (pmsg->cmsg.cmsg_if_request.sender_id) {
case IF_REQUEST_SENDER_ID_QUIPC:
{
LOC_LOGD("IF_REQUEST_SENDER_ID_QUIPC");
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");
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");
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");
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:
{
LOC_LOGD("invalid IF_REQUEST_SENDER_ID!");
return -1;
}
}
#else
loc_eng_dmn_conn_loc_api_server_data_conn(LOC_ENG_IF_REQUEST_SENDER_ID_GPSONE_DAEMON, GPSONE_LOC_API_IF_RELEASE_SUCCESS);
#endif
return 0;
}

View File

@@ -1,106 +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.
*
*/
#ifndef LOC_ENG_DATA_SERVER_HANDLER
#define LOC_ENG_DATA_SERVER_HANDLER
#include <linux/types.h>
#include <arpa/inet.h>
//for SSID_BUF_SIZE
#include <hardware/gps.h>
#ifndef SSID_BUF_SIZE
#define SSID_BUF_SIZE (32+1)
#endif
enum {
/* 0x0 - 0xEF is reserved for daemon internal */
GPSONE_LOC_API_IF_REQUEST = 0xF0,
GPSONE_LOC_API_IF_RELEASE,
GPSONE_LOC_API_RESPONSE,
GPSONE_UNBLOCK,
};
enum {
GPSONE_LOC_API_IF_REQUEST_SUCCESS = 0xF0,
GPSONE_LOC_API_IF_RELEASE_SUCCESS,
GPSONE_LOC_API_IF_FAILURE,
};
struct ctrl_msg_response {
int result;
};
struct ctrl_msg_unblock {
int reserved;
};
typedef enum {
IF_REQUEST_TYPE_SUPL = 0,
IF_REQUEST_TYPE_WIFI,
IF_REQUEST_TYPE_ANY
} ctrl_if_req_type_e_type;
typedef enum {
IF_REQUEST_SENDER_ID_QUIPC = 0,
IF_REQUEST_SENDER_ID_MSAPM,
IF_REQUEST_SENDER_ID_MSAPU,
IF_REQUEST_SENDER_ID_GPSONE_DAEMON,
IF_REQUEST_SENDER_ID_MODEM
} ctrl_if_req_sender_id_e_type;
struct ctrl_msg_if_request {
ctrl_if_req_type_e_type type;
ctrl_if_req_sender_id_e_type sender_id;
unsigned long ipv4_addr;
unsigned char ipv6_addr[16];
char ssid[SSID_BUF_SIZE];
char password[SSID_BUF_SIZE];
};
/* do not change this structure */
struct ctrl_msgbuf {
size_t msgsz;
uint16_t reserved1;
uint32_t reserved2;
uint8_t ctrl_type;
union {
struct ctrl_msg_response cmsg_response;
struct ctrl_msg_unblock cmsg_unblock;
struct ctrl_msg_if_request cmsg_if_request;
} cmsg;
};
extern void* loc_api_handle;
int loc_eng_dmn_conn_loc_api_server_if_request_handler(struct ctrl_msgbuf *pmsg, int len);
int loc_eng_dmn_conn_loc_api_server_if_release_handler(struct ctrl_msgbuf *pmsg, int len);
#endif /* LOC_ENG_DATA_SERVER_HANDLER */

View File

@@ -1,398 +0,0 @@
/* Copyright (c) 2011,2014 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <platform_lib_includes.h>
#include "loc_eng_dmn_conn_thread_helper.h"
/*===========================================================================
FUNCTION thelper_signal_init
DESCRIPTION
This function will initialize the conditional variable resources.
thelper - thelper instance
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int thelper_signal_init(struct loc_eng_dmn_conn_thelper * thelper)
{
int result;
thelper->thread_exit = 0;
thelper->thread_ready = 0;
result = pthread_cond_init( &thelper->thread_cond, NULL);
if (result) {
return result;
}
result = pthread_mutex_init(&thelper->thread_mutex, NULL);
if (result) {
pthread_cond_destroy(&thelper->thread_cond);
}
return result;
}
/*===========================================================================
FUNCTION
DESCRIPTION
This function will destroy the conditional variable resources
thelper - pointer to thelper instance
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int thelper_signal_destroy(struct loc_eng_dmn_conn_thelper * thelper)
{
int result, ret_result = 0;
result = pthread_cond_destroy( &thelper->thread_cond);
if (result) {
ret_result = result;
}
result = pthread_mutex_destroy(&thelper->thread_mutex);
if (result) {
ret_result = result;
}
return ret_result;
}
/*===========================================================================
FUNCTION thelper_signal_wait
DESCRIPTION
This function will be blocked on the conditional variable until thelper_signal_ready
is called
thelper - pointer to thelper instance
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int thelper_signal_wait(struct loc_eng_dmn_conn_thelper * thelper)
{
int result = 0;
pthread_mutex_lock(&thelper->thread_mutex);
if (!thelper->thread_ready && !thelper->thread_exit) {
result = pthread_cond_wait(&thelper->thread_cond, &thelper->thread_mutex);
}
if (thelper->thread_exit) {
result = -1;
}
pthread_mutex_unlock(&thelper->thread_mutex);
return result;
}
/*===========================================================================
FUNCTION thelper_signal_ready
DESCRIPTION
This function will wake up the conditional variable
thelper - pointer to thelper instance
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int thelper_signal_ready(struct loc_eng_dmn_conn_thelper * thelper)
{
int result;
LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
pthread_mutex_lock(&thelper->thread_mutex);
thelper->thread_ready = 1;
result = pthread_cond_signal(&thelper->thread_cond);
pthread_mutex_unlock(&thelper->thread_mutex);
return result;
}
/*===========================================================================
FUNCTION thelper_signal_block
DESCRIPTION
This function will set the thread ready to 0 to block the thelper_signal_wait
thelper - pointer to thelper instance
DEPENDENCIES
None
RETURN VALUE
if thread_ready is set
SIDE EFFECTS
N/A
===========================================================================*/
int thelper_signal_block(struct loc_eng_dmn_conn_thelper * thelper)
{
int result = thelper->thread_ready;
LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
pthread_mutex_lock(&thelper->thread_mutex);
thelper->thread_ready = 0;
pthread_mutex_unlock(&thelper->thread_mutex);
return result;
}
/*===========================================================================
FUNCTION thelper_main
DESCRIPTION
This function is the main thread. It will be launched as a child thread
data - pointer to the instance
DEPENDENCIES
None
RETURN VALUE
NULL
SIDE EFFECTS
N/A
===========================================================================*/
static void * thelper_main(void *data)
{
int result = 0;
struct loc_eng_dmn_conn_thelper * thelper = (struct loc_eng_dmn_conn_thelper *) data;
if (thelper->thread_proc_init) {
result = thelper->thread_proc_init(thelper->thread_context);
if (result < 0) {
thelper->thread_exit = 1;
thelper_signal_ready(thelper);
LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper);
return NULL;
}
}
thelper_signal_ready(thelper);
if (thelper->thread_proc_pre) {
result = thelper->thread_proc_pre(thelper->thread_context);
if (result < 0) {
thelper->thread_exit = 1;
LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper);
return NULL;
}
}
do {
if (thelper->thread_proc) {
result = thelper->thread_proc(thelper->thread_context);
if (result < 0) {
thelper->thread_exit = 1;
LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper);
}
}
} while (thelper->thread_exit == 0);
if (thelper->thread_proc_post) {
result = thelper->thread_proc_post(thelper->thread_context);
}
if (result != 0) {
LOC_LOGE("%s:%d] error: 0x%lx\n", __func__, __LINE__, (long) thelper);
}
return NULL;
}
static void thelper_main_2(void *data)
{
thelper_main(data);
return;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_launch_thelper
DESCRIPTION
This function will initialize the thread context and launch the thelper_main
thelper - pointer to thelper instance
thread_proc_init - The initialization function pointer
thread_proc_pre - The function to call before task loop and after initialization
thread_proc - The task loop
thread_proc_post - The function to call after the task loop
context - the context for the above four functions
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_launch_thelper(struct loc_eng_dmn_conn_thelper * thelper,
int (*thread_proc_init) (void * context),
int (*thread_proc_pre) (void * context),
int (*thread_proc) (void * context),
int (*thread_proc_post) (void * context),
thelper_create_thread create_thread_cb,
void * context)
{
int result;
thelper_signal_init(thelper);
if (context) {
thelper->thread_context = context;
}
thelper->thread_proc_init = thread_proc_init;
thelper->thread_proc_pre = thread_proc_pre;
thelper->thread_proc = thread_proc;
thelper->thread_proc_post = thread_proc_post;
LOC_LOGD("%s:%d] 0x%lx call pthread_create\n", __func__, __LINE__, (long) thelper);
if (create_thread_cb) {
result = 0;
thelper->thread_id = create_thread_cb("loc_eng_dmn_conn",
thelper_main_2, (void *)thelper);
} else {
result = pthread_create(&thelper->thread_id, NULL,
thelper_main, (void *)thelper);
}
if (result != 0) {
LOC_LOGE("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
return -1;
}
LOC_LOGD("%s:%d] 0x%lx pthread_create done\n", __func__, __LINE__, (long) thelper);
thelper_signal_wait(thelper);
LOC_LOGD("%s:%d] 0x%lx pthread ready\n", __func__, __LINE__, (long) thelper);
return thelper->thread_exit;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_unblock_thelper
DESCRIPTION
This function unblocks thelper_main to release the thread
thelper - pointer to thelper instance
DEPENDENCIES
None
RETURN VALUE
0: success
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_unblock_thelper(struct loc_eng_dmn_conn_thelper * thelper)
{
LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
thelper->thread_exit = 1;
return 0;
}
/*===========================================================================
FUNCTION loc_eng_dmn_conn_join_thelper
thelper - pointer to thelper instance
DESCRIPTION
This function will wait for the thread of thelper_main to finish
DEPENDENCIES
None
RETURN VALUE
0: success or negative value for failure
SIDE EFFECTS
N/A
===========================================================================*/
int loc_eng_dmn_conn_join_thelper(struct loc_eng_dmn_conn_thelper * thelper)
{
int result;
LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
result = pthread_join(thelper->thread_id, NULL);
if (result != 0) {
LOC_LOGE("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
}
LOC_LOGD("%s:%d] 0x%lx\n", __func__, __LINE__, (long) thelper);
thelper_signal_destroy(thelper);
return result;
}

Some files were not shown because too many files have changed in this diff Show More