summaryrefslogtreecommitdiff
path: root/gnss
diff options
context:
space:
mode:
authorBhavna Sharma <sbhavna@codeaurora.org>2018-01-22 16:04:50 -0800
committerBhavna Sharma <sbhavna@codeaurora.org>2018-04-13 12:12:38 -0700
commitae28b2989853a4de970ecaf78855d4bd0c34e362 (patch)
tree172d428e4c456b229707a4251a187cfeaea60f27 /gnss
parent87c52f1f37b193dcb82500350e6c6efc4e41acac (diff)
downloadgps-ae28b2989853a4de970ecaf78855d4bd0c34e362.tar.gz
Addition of new LocApi thread
1. LocApiBase to create its own MsgTask thread to allow QMI calls to be made asynchronously. It shall no longer share the adapter's thread. 2. Implementation of new LocApiResponse classes for generic response type from LocApi layer to Adapter layers. 3. GnssAdapter modified to handle the asynchronous nature of LocApi calls. CRs-Fixed: 2218658 Change-Id: I6e401a89f16791ec144763ac5f070b7ee1dad931
Diffstat (limited to 'gnss')
-rw-r--r--gnss/Agps.cpp8
-rw-r--r--gnss/Agps.h3
-rw-r--r--gnss/GnssAdapter.cpp884
-rw-r--r--gnss/GnssAdapter.h25
-rw-r--r--gnss/Makefile.am2
5 files changed, 537 insertions, 385 deletions
diff --git a/gnss/Agps.cpp b/gnss/Agps.cpp
index 6ce0c34..d6a75ab 100644
--- a/gnss/Agps.cpp
+++ b/gnss/Agps.cpp
@@ -360,13 +360,13 @@ void AgpsStateMachine::notifyEventToSubscriber(
case AGPS_EVENT_GRANTED:
mAgpsManager->mAtlOpenStatusCb(
- subscriberToNotify->mConnHandle, 1, getAPN(),
+ subscriberToNotify->mConnHandle, 1, getAPN(), getAPNLen(),
getBearer(), mAgpsType);
break;
case AGPS_EVENT_DENIED:
mAgpsManager->mAtlOpenStatusCb(
- subscriberToNotify->mConnHandle, 0, getAPN(),
+ subscriberToNotify->mConnHandle, 0, getAPN(), getAPNLen(),
getBearer(), mAgpsType);
break;
@@ -661,7 +661,7 @@ void DSStateMachine::notifyEventToSubscriber(
case AGPS_EVENT_GRANTED:
mAgpsManager->mAtlOpenStatusCb(
- subscriberToNotify->mConnHandle, 1, NULL,
+ subscriberToNotify->mConnHandle, 1, NULL, 0,
AGPS_APN_BEARER_INVALID, LOC_AGPS_TYPE_SUPL_ES);
break;
@@ -778,7 +778,7 @@ void AgpsManager::requestATL(int connHandle, AGpsExtType agpsType){
LOC_LOGE("No AGPS State Machine for agpsType: %d", agpsType);
mAtlOpenStatusCb(
- connHandle, 0, NULL, AGPS_APN_BEARER_INVALID, agpsType);
+ connHandle, 0, NULL, 0, AGPS_APN_BEARER_INVALID, agpsType);
return;
}
diff --git a/gnss/Agps.h b/gnss/Agps.h
index 703a475..f9a54f8 100644
--- a/gnss/Agps.h
+++ b/gnss/Agps.h
@@ -40,7 +40,7 @@
/* ATL callback function pointers
* Passed in by Adapter to AgpsManager */
typedef std::function<void(
- int handle, int isSuccess, char* apn,
+ int handle, int isSuccess, char* apn, uint32_t apnLen,
AGpsBearerType bearerType, AGpsExtType agpsType)> AgpsAtlOpenStatusCb;
typedef std::function<void(int handle, int isSuccess)> AgpsAtlCloseStatusCb;
@@ -169,6 +169,7 @@ public:
/* Getter/Setter methods */
void setAPN(char* apn, unsigned int len);
inline char* getAPN() const { return (char*)mAPN; }
+ inline uint32_t getAPNLen() const { return mAPNLen; }
inline void setBearer(AGpsBearerType bearer) { mBearer = bearer; }
inline AGpsBearerType getBearer() const { return mBearer; }
inline AGpsExtType getType() const { return mAgpsType; }
diff --git a/gnss/GnssAdapter.cpp b/gnss/GnssAdapter.cpp
index f996ebe..91c88d6 100644
--- a/gnss/GnssAdapter.cpp
+++ b/gnss/GnssAdapter.cpp
@@ -92,11 +92,11 @@ GnssAdapter::GnssAdapter() :
/* Set ATL open/close callbacks */
AgpsAtlOpenStatusCb atlOpenStatusCb =
- [this](int handle, int isSuccess, char* apn,
+ [this](int handle, int isSuccess, char* apn, uint32_t apnLen,
AGpsBearerType bearerType, AGpsExtType agpsType) {
mLocApi->atlOpenStatus(
- handle, isSuccess, apn, bearerType, agpsType);
+ handle, isSuccess, apn, apnLen, bearerType, agpsType);
};
AgpsAtlCloseStatusCb atlCloseStatusCb =
[this](int handle, int isSuccess) {
@@ -146,7 +146,7 @@ GnssAdapter::GnssAdapter() :
dsClientCloseDataCallFn, dsClientReleaseFn, sendMsgFn);
readConfigCommand();
- setConfigCommand();
+ requestUlpCommand();
initDefaultAgpsCommand();
initEngHubProxyCommand();
}
@@ -415,20 +415,6 @@ GnssAdapter::convertSuplVersion(const GnssConfigSuplVersion suplVersion)
}
}
-inline GnssConfigSuplVersion
-GnssAdapter::convertSuplVersion(const uint32_t suplVersion)
-{
- switch (suplVersion) {
- case 0x00020000:
- return GNSS_CONFIG_SUPL_VERSION_2_0_0;
- case 0x00020002:
- return GNSS_CONFIG_SUPL_VERSION_2_0_2;
- case 0x00010000:
- default:
- return GNSS_CONFIG_SUPL_VERSION_1_0_0;
- }
-}
-
inline uint32_t
GnssAdapter::convertLppProfile(const GnssConfigLppProfile lppProfile)
{
@@ -445,22 +431,6 @@ GnssAdapter::convertLppProfile(const GnssConfigLppProfile lppProfile)
}
}
-inline GnssConfigLppProfile
-GnssAdapter::convertLppProfile(const uint32_t lppProfile)
-{
- switch (lppProfile) {
- case 1:
- return GNSS_CONFIG_LPP_PROFILE_USER_PLANE;
- case 2:
- return GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE;
- case 3:
- return GNSS_CONFIG_LPP_PROFILE_USER_PLANE_AND_CONTROL_PLANE;
- case 0:
- default:
- return GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE;
- }
-}
-
uint32_t
GnssAdapter::convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlaneMask)
{
@@ -480,26 +450,6 @@ GnssAdapter::convertLppeCp(const GnssConfigLppeControlPlaneMask lppeControlPlane
return mask;
}
-GnssConfigLppeControlPlaneMask
-GnssAdapter::convertLppeCp(const uint32_t lppeControlPlaneMask)
-{
- GnssConfigLppeControlPlaneMask mask = 0;
- if ((1<<0) & lppeControlPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_DBH_BIT;
- }
- if ((1<<1) & lppeControlPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_WLAN_AP_MEASUREMENTS_BIT;
- }
- if ((1<<2) & lppeControlPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_SRN_AP_MEASUREMENTS_BIT;
- }
- if ((1<<3) & lppeControlPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_CONTROL_PLANE_SENSOR_BARO_MEASUREMENTS_BIT;
- }
- return mask;
-}
-
-
uint32_t
GnssAdapter::convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask)
{
@@ -519,25 +469,6 @@ GnssAdapter::convertLppeUp(const GnssConfigLppeUserPlaneMask lppeUserPlaneMask)
return mask;
}
-GnssConfigLppeUserPlaneMask
-GnssAdapter::convertLppeUp(const uint32_t lppeUserPlaneMask)
-{
- GnssConfigLppeUserPlaneMask mask = 0;
- if ((1<<0) & lppeUserPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_USER_PLANE_DBH_BIT;
- }
- if ((1<<1) & lppeUserPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_USER_PLANE_WLAN_AP_MEASUREMENTS_BIT;
- }
- if ((1<<2) & lppeUserPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_USER_PLANE_SRN_AP_MEASUREMENTS_BIT;
- }
- if ((1<<3) & lppeUserPlaneMask) {
- mask |= GNSS_CONFIG_LPPE_USER_PLANE_SENSOR_BARO_MEASUREMENTS_BIT;
- }
- return mask;
-}
-
uint32_t
GnssAdapter::convertAGloProt(const GnssConfigAGlonassPositionProtocolMask aGloPositionProtocolMask)
{
@@ -594,27 +525,6 @@ GnssAdapter::convertSuplMode(const GnssConfigSuplModeMask suplModeMask)
return mask;
}
-bool
-GnssAdapter::resolveInAddress(const char* hostAddress, struct in_addr* inAddress)
-{
- bool ret = true;
-
- struct hostent* hp;
- hp = gethostbyname(hostAddress);
- if (hp != NULL) { /* DNS OK */
- memcpy(inAddress, hp->h_addr_list[0], hp->h_length);
- } else {
- /* Try IP representation */
- if (inet_aton(hostAddress, inAddress) == 0) {
- /* IP not valid */
- LOC_LOGE("%s]: DNS query on '%s' failed", __func__, hostAddress);
- ret = false;
- }
- }
-
- return ret;
-}
-
void
GnssAdapter::readConfigCommand()
{
@@ -640,17 +550,37 @@ GnssAdapter::readConfigCommand()
}
}
-LocationError
+void
+GnssAdapter::requestUlpCommand()
+{
+ LOC_LOGD("%s]: ", __func__);
+
+ struct MsgRequestUlp : public LocMsg {
+ GnssAdapter* mAdapter;
+ ContextBase& mContext;
+ inline MsgRequestUlp(GnssAdapter* adapter,
+ ContextBase& context) :
+ LocMsg(),
+ mAdapter(adapter),
+ mContext(context) {}
+ inline virtual void proc() const {
+ mContext.requestUlp((LocAdapterBase*)mAdapter, mContext.getCarrierCapabilities());
+ }
+ };
+
+ if (mContext != NULL) {
+ sendMsg(new MsgRequestUlp(this, *mContext));
+ }
+}
+
+void
GnssAdapter::setSuplHostServer(const char* server, int port)
{
- LocationError locErr = LOCATION_ERROR_SUCCESS;
if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
char serverUrl[MAX_URL_LEN] = {};
int32_t length = -1;
const char noHost[] = "NONE";
- locErr = LOCATION_ERROR_INVALID_PARAMETER;
-
if ((NULL == server) || (server[0] == 0) ||
(strncasecmp(noHost, server, sizeof(noHost)) == 0)) {
serverUrl[0] = NULL;
@@ -662,14 +592,8 @@ GnssAdapter::setSuplHostServer(const char* server, int port)
if (length >= 0 && strncasecmp(getServerUrl().c_str(),
serverUrl, sizeof(serverUrl)) != 0) {
setServerUrl(serverUrl);
- locErr = mLocApi->setServer(serverUrl, length);
- if (locErr != LOCATION_ERROR_SUCCESS) {
- LOC_LOGE("%s]:Error while setting SUPL_HOST server:%s",
- __func__, serverUrl);
- }
}
}
- return locErr;
}
void
@@ -680,68 +604,105 @@ GnssAdapter::setConfigCommand()
struct MsgSetConfig : public LocMsg {
GnssAdapter& mAdapter;
LocApiBase& mApi;
- inline MsgSetConfig(GnssAdapter& adapter,
- LocApiBase& api) :
+ inline MsgSetConfig(GnssAdapter& adapter, LocApiBase& api) :
LocMsg(),
mAdapter(adapter),
mApi(api) {}
inline virtual void proc() const {
- if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
- mApi.setSUPLVersion(mAdapter.convertSuplVersion(ContextBase::mGps_conf.SUPL_VER));
- mApi.setLPPConfig(mAdapter.convertLppProfile(ContextBase::mGps_conf.LPP_PROFILE));
- mApi.setAGLONASSProtocol(ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT);
- }
- mAdapter.setSuplHostServer(ContextBase::mGps_conf.SUPL_HOST,
- ContextBase::mGps_conf.SUPL_PORT);
- mApi.setSensorControlConfig(ContextBase::mSap_conf.SENSOR_USAGE,
- ContextBase::mSap_conf.SENSOR_PROVIDER);
- mApi.setLPPeProtocolCp(
- mAdapter.convertLppeCp(ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY));
- mApi.setLPPeProtocolUp(
- mAdapter.convertLppeUp(ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY));
// set nmea mask type
uint32_t mask = 0;
if (NMEA_PROVIDER_MP == ContextBase::mGps_conf.NMEA_PROVIDER) {
mask |= LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK;
}
- if (mApi.isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
+ if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
mask |= LOC_NMEA_MASK_DEBUG_V02;
}
- if (mask != 0) {
- mApi.setNMEATypes(mask);
- }
mAdapter.mNmeaMask= mask;
- mApi.setXtraVersionCheck(ContextBase::mGps_conf.XTRA_VERSION_CHECK);
- if (ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID ||
- ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
- ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
- ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
- ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) {
- mApi.setSensorProperties(
- ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK_VALID,
- ContextBase::mSap_conf.GYRO_BIAS_RANDOM_WALK,
- ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
- ContextBase::mSap_conf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY,
- ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
- ContextBase::mSap_conf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY,
- ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
- ContextBase::mSap_conf.RATE_RANDOM_WALK_SPECTRAL_DENSITY,
- ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
- ContextBase::mSap_conf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY);
- }
- mApi.setSensorPerfControlConfig(
- ContextBase::mSap_conf.SENSOR_CONTROL_MODE,
- ContextBase::mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH,
- ContextBase::mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC,
- ContextBase::mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH,
- ContextBase::mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC,
- ContextBase::mSap_conf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH,
- ContextBase::mSap_conf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH,
- ContextBase::mSap_conf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH,
- ContextBase::mSap_conf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH,
- ContextBase::mSap_conf.SENSOR_ALGORITHM_CONFIG_MASK);
+ std::string oldServerUrl = mAdapter.getServerUrl();
+ mAdapter.setSuplHostServer(ContextBase::mGps_conf.SUPL_HOST,
+ ContextBase::mGps_conf.SUPL_PORT);
+
+ // inject the configurations into modem
+ GnssAdapter& adapter = mAdapter;
+ loc_gps_cfg_s gpsConf = ContextBase::mGps_conf;
+ loc_sap_cfg_s_type sapConf = ContextBase::mSap_conf;
+
+ mApi.sendMsg(new LocApiMsg(
+ [&adapter, gpsConf, sapConf, oldServerUrl] () {
+
+ std::string serverUrl = adapter.getServerUrl();
+ int serverUrlLen = serverUrl.length();
+
+ if (gpsConf.AGPS_CONFIG_INJECT) {
+ adapter.mLocApi->setSUPLVersionSync(
+ adapter.mLocApi->convertSuplVersion(gpsConf.SUPL_VER));
+ adapter.mLocApi->setLPPConfigSync(
+ adapter.mLocApi->convertLppProfile(gpsConf.LPP_PROFILE));
+ adapter.mLocApi->setAGLONASSProtocolSync(
+ gpsConf.A_GLONASS_POS_PROTOCOL_SELECT);
+ }
+
+ if ((serverUrlLen !=0) && (oldServerUrl.compare(serverUrl) != 0)) {
+ LocationError locErr =
+ adapter.mLocApi->setServerSync(serverUrl.c_str(), serverUrlLen);
+ if (locErr != LOCATION_ERROR_SUCCESS) {
+ LOC_LOGE("%s]:Error while setting SUPL_HOST server:%s",
+ __func__, serverUrl.c_str());
+ }
+ }
+
+ adapter.mLocApi->setSensorControlConfigSync(sapConf.SENSOR_USAGE,
+ sapConf.SENSOR_PROVIDER);
+ adapter.mLocApi->setLPPeProtocolCpSync(
+ adapter.mLocApi->convertLppeCp(gpsConf.LPPE_CP_TECHNOLOGY));
+ adapter.mLocApi->setLPPeProtocolUpSync(
+ adapter.mLocApi->convertLppeUp(gpsConf.LPPE_UP_TECHNOLOGY));
+
+ // set nmea mask type
+ uint32_t mask = 0;
+ if (NMEA_PROVIDER_MP == gpsConf.NMEA_PROVIDER) {
+ mask |= LOC_NMEA_ALL_GENERAL_SUPPORTED_MASK;
+ }
+ if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
+ mask |= LOC_NMEA_MASK_DEBUG_V02;
+ }
+
+ if (mask != 0) {
+ adapter.mLocApi->setNMEATypesSync(mask);
+ }
+
+ adapter.mLocApi->setXtraVersionCheckSync(gpsConf.XTRA_VERSION_CHECK);
+ if (sapConf.GYRO_BIAS_RANDOM_WALK_VALID ||
+ sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+ sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+ sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID ||
+ sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID ) {
+ adapter.mLocApi->setSensorPropertiesSync(
+ sapConf.GYRO_BIAS_RANDOM_WALK_VALID,
+ sapConf.GYRO_BIAS_RANDOM_WALK,
+ sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+ sapConf.ACCEL_RANDOM_WALK_SPECTRAL_DENSITY,
+ sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+ sapConf.ANGLE_RANDOM_WALK_SPECTRAL_DENSITY,
+ sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+ sapConf.RATE_RANDOM_WALK_SPECTRAL_DENSITY,
+ sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY_VALID,
+ sapConf.VELOCITY_RANDOM_WALK_SPECTRAL_DENSITY);
+ }
+ adapter.mLocApi->setSensorPerfControlConfigSync(
+ sapConf.SENSOR_CONTROL_MODE,
+ sapConf.SENSOR_ACCEL_SAMPLES_PER_BATCH,
+ sapConf.SENSOR_ACCEL_BATCHES_PER_SEC,
+ sapConf.SENSOR_GYRO_SAMPLES_PER_BATCH,
+ sapConf.SENSOR_GYRO_BATCHES_PER_SEC,
+ sapConf.SENSOR_ACCEL_SAMPLES_PER_BATCH_HIGH,
+ sapConf.SENSOR_ACCEL_BATCHES_PER_SEC_HIGH,
+ sapConf.SENSOR_GYRO_SAMPLES_PER_BATCH_HIGH,
+ sapConf.SENSOR_GYRO_BATCHES_PER_SEC_HIGH,
+ sapConf.SENSOR_ALGORITHM_CONFIG_MASK);
+ } ));
}
};
@@ -783,8 +744,8 @@ GnssAdapter::gnssUpdateConfigCommand(GnssConfig config)
GnssAdapter& mAdapter;
LocApiBase& mApi;
GnssConfig mConfig;
- uint32_t* mIds;
size_t mCount;
+ uint32_t* mIds;
inline MsgGnssUpdateConfig(GnssAdapter& adapter,
LocApiBase& api,
GnssConfig config,
@@ -794,163 +755,260 @@ GnssAdapter::gnssUpdateConfigCommand(GnssConfig config)
mAdapter(adapter),
mApi(api),
mConfig(config),
- mIds(ids),
- mCount(count) {}
+ mCount(count),
+ mIds(ids) {}
inline virtual ~MsgGnssUpdateConfig()
{
- delete[] mIds;
+ delete [] mIds;
}
+
inline virtual void proc() const {
- LocationError* errs = new LocationError[mCount];
- LocationError err = LOCATION_ERROR_SUCCESS;
- uint32_t index = 0;
- if (errs == nullptr) {
- LOC_LOGE("%s] new allocation failed, fatal error.", __func__);
- return;
- }
+ GnssAdapter& adapter = mAdapter;
+ size_t countOfConfigs = mCount;
+ GnssConfig gnssConfigRequested = mConfig;
+ GnssConfig gnssConfigNeedEngineUpdate = mConfig;
+ std::string oldServerUrl = mAdapter.getServerUrl();
+
+ std::vector<uint32_t> sessionIds;
+ sessionIds.assign(mIds, mIds + mCount);
+ std::vector<LocationError> errs(mCount, LOCATION_ERROR_SUCCESS);
+ int index = 0;
- if (mConfig.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
- uint32_t newGpsLock = mAdapter.convertGpsLock(mConfig.gpsLock);
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
+ index++;
+ uint32_t newGpsLock = mAdapter.convertGpsLock(gnssConfigRequested.gpsLock);
ContextBase::mGps_conf.GPS_LOCK = newGpsLock;
- if (0 == mAdapter.getPowerVoteId()) {
- err = mApi.setGpsLock(mConfig.gpsLock);
- }
- if (index < mCount) {
- errs[index++] = err;
+ if (0 != mAdapter.getPowerVoteId()) {
+ gnssConfigNeedEngineUpdate.flags &= ~(GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
- uint32_t newSuplVersion = mAdapter.convertSuplVersion(mConfig.suplVersion);
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
+ index++;
+ uint32_t newSuplVersion =
+ mAdapter.convertSuplVersion(gnssConfigRequested.suplVersion);
if (newSuplVersion != ContextBase::mGps_conf.SUPL_VER &&
ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
ContextBase::mGps_conf.SUPL_VER = newSuplVersion;
- err = mApi.setSUPLVersion(mConfig.suplVersion);
} else {
- err = LOCATION_ERROR_SUCCESS;
- }
- if (index < mCount) {
- errs[index++] = err;
+ gnssConfigNeedEngineUpdate.flags &= ~(GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+ index++;
if (GNSS_ASSISTANCE_TYPE_SUPL == mConfig.assistanceServer.type) {
- err = mAdapter.setSuplHostServer(mConfig.assistanceServer.hostName,
- mConfig.assistanceServer.port);
- } else if (GNSS_ASSISTANCE_TYPE_C2K == mConfig.assistanceServer.type) {
- if (ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
- struct in_addr addr;
- if (!mAdapter.resolveInAddress(mConfig.assistanceServer.hostName,
- &addr)) {
- LOC_LOGE("%s]: hostName %s cannot be resolved",
- __func__, mConfig.assistanceServer.hostName);
- err = LOCATION_ERROR_INVALID_PARAMETER;
- } else {
- unsigned int ip = htonl(addr.s_addr);
- err = mApi.setServer(ip, mConfig.assistanceServer.port,
- LOC_AGPS_CDMA_PDE_SERVER);
- }
- } else {
- err = LOCATION_ERROR_SUCCESS;
- }
- } else {
+ mAdapter.setSuplHostServer(mConfig.assistanceServer.hostName,
+ mConfig.assistanceServer.port);
+ } else if (GNSS_ASSISTANCE_TYPE_C2K != mConfig.assistanceServer.type) {
LOC_LOGE("%s]: Not a valid gnss assistance type %u",
- __func__, mConfig.assistanceServer.type);
- err = LOCATION_ERROR_INVALID_PARAMETER;
- }
- if (index < mCount) {
- errs[index++] = err;
+ __func__, mConfig.assistanceServer.type);
+ errs.at(index) = LOCATION_ERROR_INVALID_PARAMETER;
+ gnssConfigNeedEngineUpdate.flags &=
+ ~(GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
- uint32_t newLppProfile = mAdapter.convertLppProfile(mConfig.lppProfile);
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
+ index++;
+ uint32_t newLppProfile = mAdapter.convertLppProfile(gnssConfigRequested.lppProfile);
if (newLppProfile != ContextBase::mGps_conf.LPP_PROFILE &&
ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
ContextBase::mGps_conf.LPP_PROFILE = newLppProfile;
- err = mApi.setLPPConfig(mConfig.lppProfile);
} else {
- err = LOCATION_ERROR_SUCCESS;
- }
- if (index < mCount) {
- errs[index++] = err;
+ gnssConfigNeedEngineUpdate.flags &= ~(GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+ index++;
uint32_t newLppeControlPlaneMask =
- mAdapter.convertLppeCp(mConfig.lppeControlPlaneMask);
+ mAdapter.convertLppeCp(gnssConfigRequested.lppeControlPlaneMask);
if (newLppeControlPlaneMask != ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY) {
ContextBase::mGps_conf.LPPE_CP_TECHNOLOGY = newLppeControlPlaneMask;
- err = mApi.setLPPeProtocolCp(mConfig.lppeControlPlaneMask);
} else {
- err = LOCATION_ERROR_SUCCESS;
- }
- if (index < mCount) {
- errs[index++] = err;
+ gnssConfigNeedEngineUpdate.flags &=
+ ~(GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+ index++;
uint32_t newLppeUserPlaneMask =
- mAdapter.convertLppeUp(mConfig.lppeUserPlaneMask);
+ mAdapter.convertLppeUp(gnssConfigRequested.lppeUserPlaneMask);
if (newLppeUserPlaneMask != ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY) {
ContextBase::mGps_conf.LPPE_UP_TECHNOLOGY = newLppeUserPlaneMask;
- err = mApi.setLPPeProtocolUp(mConfig.lppeUserPlaneMask);
} else {
- err = LOCATION_ERROR_SUCCESS;
- }
- if (index < mCount) {
- errs[index++] = err;
+ gnssConfigNeedEngineUpdate.flags &=
+ ~(GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT);
}
}
- if (mConfig.flags & GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+ if (gnssConfigRequested.flags &
+ GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+ index++;
uint32_t newAGloProtMask =
- mAdapter.convertAGloProt(mConfig.aGlonassPositionProtocolMask);
+ mAdapter.convertAGloProt(gnssConfigRequested.aGlonassPositionProtocolMask);
if (newAGloProtMask != ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT &&
ContextBase::mGps_conf.AGPS_CONFIG_INJECT) {
ContextBase::mGps_conf.A_GLONASS_POS_PROTOCOL_SELECT = newAGloProtMask;
- err = mApi.setAGLONASSProtocol(mConfig.aGlonassPositionProtocolMask);
} else {
- err = LOCATION_ERROR_SUCCESS;
- }
- if (index < mCount) {
- errs[index++] = err;
+ gnssConfigNeedEngineUpdate.flags &=
+ ~(GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT);
}
- }
- if (mConfig.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
- uint32_t newEP4ES = mAdapter.convertEP4ES(mConfig.emergencyPdnForEmergencySupl);
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT) {
+ index++;
+ uint32_t newEP4ES = mAdapter.convertEP4ES(
+ gnssConfigRequested.emergencyPdnForEmergencySupl);
if (newEP4ES != ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL) {
ContextBase::mGps_conf.USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL = newEP4ES;
}
- err = LOCATION_ERROR_SUCCESS;
- if (index < mCount) {
- errs[index++] = err;
- }
- }
- if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
- uint32_t newSuplEs = mAdapter.convertSuplEs(mConfig.suplEmergencyServices);
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT) {
+ index++;
+ uint32_t newSuplEs = mAdapter.convertSuplEs(
+ gnssConfigRequested.suplEmergencyServices);
if (newSuplEs != ContextBase::mGps_conf.SUPL_ES) {
ContextBase::mGps_conf.SUPL_ES = newSuplEs;
}
- err = LOCATION_ERROR_SUCCESS;
- if (index < mCount) {
- errs[index++] = err;
- }
- }
- if (mConfig.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
- uint32_t newSuplMode = mAdapter.convertSuplMode(mConfig.suplModeMask);
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_MODE_BIT) {
+ index++;
+ uint32_t newSuplMode = mAdapter.convertSuplMode(gnssConfigRequested.suplModeMask);
if (newSuplMode != ContextBase::mGps_conf.SUPL_MODE) {
ContextBase::mGps_conf.SUPL_MODE = newSuplMode;
mAdapter.getUlpProxy()->setCapabilities(
ContextBase::getCarrierCapabilities());
mAdapter.broadcastCapabilities(mAdapter.getCapabilities());
}
- err = LOCATION_ERROR_SUCCESS;
- if (index < mCount) {
- errs[index++] = err;
- }
}
- mAdapter.reportResponse(index, errs, mIds);
- delete[] errs;
+ LocApiCollectiveResponse *configCollectiveResponse = new LocApiCollectiveResponse(
+ *adapter.getContext(),
+ [&adapter, sessionIds, countOfConfigs] (std::vector<LocationError> errs) {
+
+ std::vector<uint32_t> ids(sessionIds);
+ adapter.reportResponse(countOfConfigs, errs.data(), ids.data());
+ });
+
+ mApi.sendMsg(new LocApiMsg(
+ [&adapter, gnssConfigRequested, gnssConfigNeedEngineUpdate,
+ countOfConfigs, configCollectiveResponse, errs, oldServerUrl] () {
+
+ size_t index = 0;
+ LocationError err = LOCATION_ERROR_SUCCESS;
+ std::vector<LocationError> errsList(errs);
+
+ std::string serverUrl = adapter.getServerUrl();
+ int serverUrlLen = serverUrl.length();
+
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
+ if (gnssConfigNeedEngineUpdate.flags & GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT) {
+ err = adapter.mLocApi->setGpsLockSync(gnssConfigRequested.gpsLock);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ if (gnssConfigRequested.flags &
+ GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_SET_ASSISTANCE_DATA_VALID_BIT) {
+ if (gnssConfigNeedEngineUpdate.assistanceServer.type ==
+ GNSS_ASSISTANCE_TYPE_SUPL) {
+ if ((serverUrlLen != 0) && (oldServerUrl.compare(serverUrl) !=0)) {
+ err = adapter.mLocApi->setServerSync(
+ serverUrl.c_str(), serverUrlLen);
+ errsList[index] = err;
+ }
+ } else if (gnssConfigNeedEngineUpdate.assistanceServer.type ==
+ GNSS_ASSISTANCE_TYPE_C2K) {
+ struct in_addr addr;
+ struct hostent* hp;
+ bool resolveAddrSuccess = true;
+
+ hp = gethostbyname(
+ gnssConfigNeedEngineUpdate.assistanceServer.hostName);
+ if (hp != NULL) { /* DNS OK */
+ memcpy(&addr, hp->h_addr_list[0], hp->h_length);
+ } else {
+ /* Try IP representation */
+ if (inet_aton(
+ gnssConfigNeedEngineUpdate.assistanceServer.hostName,
+ &addr) == 0) {
+ /* IP not valid */
+ LOC_LOGE("%s]: hostname '%s' cannot be resolved ",
+ __func__,
+ gnssConfigNeedEngineUpdate.assistanceServer.hostName);
+ errsList[index] = LOCATION_ERROR_INVALID_PARAMETER;
+ } else {
+ resolveAddrSuccess = false;
+ }
+ }
+
+ if (resolveAddrSuccess) {
+ unsigned int ip = htonl(addr.s_addr);
+ err = adapter.mLocApi->setServerSync(ip,
+ gnssConfigNeedEngineUpdate.assistanceServer.port,
+ LOC_AGPS_CDMA_PDE_SERVER);
+ errsList[index] = err;
+ }
+ }
+ }
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT) {
+ err = adapter.mLocApi->setSUPLVersionSync(gnssConfigRequested.suplVersion);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT) {
+ err = adapter.mLocApi->setLPPConfigSync(gnssConfigRequested.lppProfile);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_LPPE_CONTROL_PLANE_VALID_BIT) {
+ err = adapter.mLocApi->setLPPeProtocolCpSync(
+ gnssConfigRequested.lppeControlPlaneMask);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ if (gnssConfigRequested.flags & GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_LPPE_USER_PLANE_VALID_BIT) {
+ err = adapter.mLocApi->setLPPeProtocolUpSync(
+ gnssConfigRequested.lppeUserPlaneMask);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ if (gnssConfigRequested.flags &
+ GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+ index++;
+ if (gnssConfigNeedEngineUpdate.flags &
+ GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT) {
+ err = adapter.mLocApi->setAGLONASSProtocolSync(
+ gnssConfigRequested.aGlonassPositionProtocolMask);
+ if (index < countOfConfigs) {
+ errsList[index] = err;
+ }
+ }
+ }
+ configCollectiveResponse->returnToSender(errsList);
+ }));
}
};
@@ -963,6 +1021,13 @@ GnssAdapter::gnssUpdateConfigCommand(GnssConfig config)
return ids;
}
+void GnssAdapter::deleteAidingData(const GnssAidingData &data, uint32_t sessionId) {
+ mLocApi->deleteAidingData(data, new LocApiResponse(*getContext(),
+ [this, sessionId] (LocationError err) {
+ reportResponse(err, sessionId);
+ }));
+}
+
uint32_t
GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data)
{
@@ -971,22 +1036,18 @@ GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data)
struct MsgDeleteAidingData : public LocMsg {
GnssAdapter& mAdapter;
- LocApiBase& mApi;
uint32_t mSessionId;
GnssAidingData mData;
inline MsgDeleteAidingData(GnssAdapter& adapter,
- LocApiBase& api,
uint32_t sessionId,
GnssAidingData& data) :
LocMsg(),
mAdapter(adapter),
- mApi(api),
mSessionId(sessionId),
mData(data) {}
inline virtual void proc() const {
- LocationError err = LOCATION_ERROR_SUCCESS;
- err = mApi.deleteAidingData(mData);
- mAdapter.reportResponse(err, mSessionId);
+ mAdapter.deleteAidingData(mData, mSessionId);
+
SystemStatus* s = mAdapter.getSystemStatus();
if ((nullptr != s) && (mData.deleteAll)) {
s->setDefaultGnssEngineStates();
@@ -995,7 +1056,7 @@ GnssAdapter::gnssDeleteAidingDataCommand(GnssAidingData& data)
}
};
- sendMsg(new MsgDeleteAidingData(*this, *mLocApi, sessionId, data));
+ sendMsg(new MsgDeleteAidingData(*this, sessionId, data));
return sessionId;
}
@@ -1187,11 +1248,9 @@ GnssAdapter::stopClientSessions(LocationAPI* client)
LOC_LOGD("%s]: client %p", __func__, client);
for (auto it = mTrackingSessions.begin(); it != mTrackingSessions.end();) {
if (client == it->first.client) {
- LocationError err = stopTrackingMultiplex(it->first.client, it->first.id);
- if (LOCATION_ERROR_SUCCESS == err) {
- it = mTrackingSessions.erase(it);
- continue;
- }
+ stopTrackingMultiplex(it->first.client, it->first.id);
+ it = mTrackingSessions.erase(it);
+ continue;
}
++it; // increment only when not erasing an iterator
}
@@ -1244,18 +1303,23 @@ GnssAdapter::updateClientsEventMask()
void
GnssAdapter::handleEngineUpEvent()
{
- struct MsgRestartSessions : public LocMsg {
+ LOC_LOGD("%s]: ", __func__);
+
+ struct MsgHandleEngineUpEvent : public LocMsg {
GnssAdapter& mAdapter;
- inline MsgRestartSessions(GnssAdapter& adapter) :
+ inline MsgHandleEngineUpEvent(GnssAdapter& adapter) :
LocMsg(),
mAdapter(adapter) {}
virtual void proc() const {
+ mAdapter.broadcastCapabilities(mAdapter.getCapabilities());
+ // restart sessions
mAdapter.restartSessions();
}
};
+ readConfigCommand();
setConfigCommand();
- sendMsg(new MsgRestartSessions(*this));
+ sendMsg(new MsgHandleEngineUpEvent(*this));
}
void
@@ -1279,11 +1343,9 @@ GnssAdapter::restartSessions()
LocPosMode locPosMode = {};
convertOptions(locPosMode, smallestIntervalOptions);
- // inform engine hub of the fix mode and start session
- mEngHubProxy->gnssSetFixMode(locPosMode);
- mEngHubProxy->gnssStartFix();
-
- mLocApi->startFix(locPosMode);
+ mLocApi->startFix(locPosMode, new LocApiResponse(*getContext(),
+ [] (LocationError err) {}
+ ));
}
void
@@ -1306,12 +1368,14 @@ GnssAdapter::requestCapabilitiesCommand(LocationAPI* client)
return;
}
- LocationCapabilitiesMask mask = mAdapter.getCapabilities();
- callbacks.capabilitiesCb(mask);
+ LocationCapabilitiesMask mask = mAdapter.getCapabilities();
+ callbacks.capabilitiesCb(mask);
}
};
- sendMsg(new MsgRequestCapabilities(*this, client));
+ if (ContextBase::isEngineCapabilitiesKnown()) {
+ sendMsg(new MsgRequestCapabilities(*this, client));
+ }
}
LocationCapabilitiesMask
@@ -1329,22 +1393,20 @@ GnssAdapter::getCapabilities()
if (LOC_GPS_CAPABILITY_MSA & carrierCapabilities) {
mask |= LOCATION_CAPABILITIES_GNSS_MSA_BIT;
}
- if (mLocApi == nullptr)
- return mask;
- if (mLocApi->isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)) {
+ if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_LOCATION_BATCHING)) {
mask |= LOCATION_CAPABILITIES_TIME_BASED_BATCHING_BIT |
LOCATION_CAPABILITIES_DISTANCE_BASED_BATCHING_BIT;
}
- if (mLocApi->isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) {
+ if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_DISTANCE_BASE_TRACKING)) {
mask |= LOCATION_CAPABILITIES_DISTANCE_BASED_TRACKING_BIT;
}
- if (mLocApi->isMessageSupported(LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING)) {
+ if (ContextBase::isMessageSupported(LOC_API_ADAPTER_MESSAGE_OUTDOOR_TRIP_BATCHING)) {
mask |= LOCATION_CAPABILITIES_OUTDOOR_TRIP_BATCHING_BIT;
}
- if (mLocApi->gnssConstellationConfig()) {
+ if (ContextBase::gnssConstellationConfig()) {
mask |= LOCATION_CAPABILITIES_GNSS_MEASUREMENTS_BIT;
}
- if (mLocApi->isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
+ if (ContextBase::isFeatureSupported(LOC_SUPPORTED_FEATURE_DEBUG_NMEA_V02)) {
mask |= LOCATION_CAPABILITIES_DEBUG_NMEA_BIT;
}
return mask;
@@ -1353,9 +1415,9 @@ GnssAdapter::getCapabilities()
void
GnssAdapter::broadcastCapabilities(LocationCapabilitiesMask mask)
{
- for (auto it = mClientData.begin(); it != mClientData.end(); ++it) {
- if (nullptr != it->second.capabilitiesCb) {
- it->second.capabilitiesCb(mask);
+ for (auto clientData : mClientData) {
+ if (nullptr != clientData.second.capabilitiesCb) {
+ clientData.second.capabilitiesCb(mask);
}
}
}
@@ -1443,8 +1505,7 @@ GnssAdapter::reportResponse(LocationAPI* client, LocationError err, uint32_t ses
LOC_LOGD("%s]: client %p id %u err %u", __func__, client, sessionId, err);
auto it = mClientData.find(client);
- if (it != mClientData.end() &&
- it->second.responseCb != nullptr) {
+ if (it != mClientData.end() && it->second.responseCb != nullptr) {
it->second.responseCb(err, sessionId);
} else {
LOC_LOGW("%s]: client %p id %u not found in data", __func__, client, sessionId);
@@ -1522,12 +1583,14 @@ GnssAdapter::startTrackingCommand(LocationAPI* client, LocationOptions& options)
err = LOCATION_ERROR_INVALID_PARAMETER;
} else {
// Api doesn't support multiple clients for time based tracking, so mutiplex
- err = mAdapter.startTrackingMultiplex(mOptions);
- if (LOCATION_ERROR_SUCCESS == err) {
- mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+ bool reportToClientWithNoWait =
+ mAdapter.startTrackingMultiplex(mClient, mSessionId, mOptions);
+ mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+
+ if (reportToClientWithNoWait) {
+ mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId);
}
}
- mAdapter.reportResponse(mClient, err, mSessionId);
}
};
@@ -1536,13 +1599,14 @@ GnssAdapter::startTrackingCommand(LocationAPI* client, LocationOptions& options)
}
-LocationError
-GnssAdapter::startTrackingMultiplex(const LocationOptions& options)
+bool
+GnssAdapter::startTrackingMultiplex(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& options)
{
- LocationError err = LOCATION_ERROR_SUCCESS;
+ bool reportToClientWithNoWait = true;
if (mTrackingSessions.empty()) {
- err = startTracking(options);
+ reportToClientWithNoWait = startTracking(client, sessionId, options);
} else {
// get the LocationOptions that has the smallest interval, which should be the active one
LocationOptions smallestIntervalOptions = {}; // size is zero until set for the first time
@@ -1555,17 +1619,19 @@ GnssAdapter::startTrackingMultiplex(const LocationOptions& options)
// if new session's minInterval is smaller than any in other sessions
if (options.minInterval < smallestIntervalOptions.minInterval) {
// restart time based tracking with new options
- err = startTracking(options);
+ reportToClientWithNoWait = startTracking(client, sessionId, options);
}
}
- return err;
+ return reportToClientWithNoWait;
}
-LocationError
-GnssAdapter::startTracking(const LocationOptions& options)
+bool
+GnssAdapter::startTracking(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& options)
{
- LocationError err = LOCATION_ERROR_SUCCESS;
+ bool reportToClientWithNoWait = true;
+
LocPosMode locPosMode = {};
convertOptions(locPosMode, options);
if (!mUlpProxy->sendFixMode(locPosMode)) {
@@ -1576,17 +1642,56 @@ GnssAdapter::startTracking(const LocationOptions& options)
mEngHubProxy->gnssSetFixMode(locPosMode);
mEngHubProxy->gnssStartFix();
- loc_api_adapter_err apiErr = mLocApi->startFix(locPosMode);
- if (LOC_API_ADAPTER_ERR_SUCCESS == apiErr) {
- err = LOCATION_ERROR_SUCCESS;
- } else {
- err = LOCATION_ERROR_GENERAL_FAILURE;
- }
+ mLocApi->startFix(locPosMode, new LocApiResponse(*getContext(),
+ [this, client, sessionId] (LocationError err) {
+ if (LOCATION_ERROR_SUCCESS != err) {
+ eraseTrackingSession(client, sessionId);
+ }
+
+ reportResponse(client, err, sessionId);
+ }
+ ));
+
+ reportToClientWithNoWait = false;
+ }
+
+ return reportToClientWithNoWait;
+}
+
+bool
+GnssAdapter::updateTracking(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& updatedOptions, const LocationOptions& oldOptions)
+{
+ bool reportToClientWithNoWait = true;
+
+ LocPosMode locPosMode = {};
+ convertOptions(locPosMode, updatedOptions);
+ if (!mUlpProxy->sendFixMode(locPosMode)) {
+ // do nothing
}
+ if (!mUlpProxy->sendStartFix()) {
+ // inform engine hub that GNSS session is about to start
+ mEngHubProxy->gnssSetFixMode(locPosMode);
+ mEngHubProxy->gnssStartFix();
+
+ mLocApi->startFix(locPosMode, new LocApiResponse(*getContext(),
+ [this, client, sessionId, oldOptions] (LocationError err) {
+ if (LOCATION_ERROR_SUCCESS != err) {
+ // restore the old LocationOptions
+ saveTrackingSession(client, sessionId, oldOptions);
+ }
+
+ reportResponse(client, err, sessionId);
+ }
+ ));
- return err;
+ reportToClientWithNoWait = false;
+ }
+
+ return reportToClientWithNoWait;
}
+
void
GnssAdapter::setPositionModeCommand(LocPosMode& locPosMode)
{
@@ -1640,8 +1745,11 @@ GnssAdapter::startTrackingCommand()
// inform engine hub of the fix mode and start session
mAdapter.mEngHubProxy->gnssSetFixMode(ulpPositionMode);
mAdapter.mEngHubProxy->gnssStartFix();
- if (!mAdapter.isInSession()) {
- mApi.startFix(ulpPositionMode);
+ if (!mAdapter.isInSession()) {
+ LocPosMode& ulpPositionMode = mAdapter.getUlpPositionMode();
+ mApi.startFix(ulpPositionMode, new LocApiResponse(*mAdapter.getContext(),
+ [] (LocationError err) {}
+ ));
}
}
};
@@ -1680,12 +1788,14 @@ GnssAdapter::updateTrackingOptionsCommand(LocationAPI* client, uint32_t id,
err = LOCATION_ERROR_INVALID_PARAMETER;
} else {
// Api doesn't support multiple clients for time based tracking, so mutiplex
- err = mAdapter.updateTrackingMultiplex(mClient, mSessionId, mOptions);
- if (LOCATION_ERROR_SUCCESS == err) {
- mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+ bool reportToClientWithNoWait =
+ mAdapter.updateTrackingMultiplex(mClient, mSessionId, mOptions);
+ mAdapter.saveTrackingSession(mClient, mSessionId, mOptions);
+
+ if (reportToClientWithNoWait) {
+ mAdapter.reportResponse(mClient, err, mSessionId);
}
}
- mAdapter.reportResponse(mClient, err, mSessionId);
}
// we do not reportResponse for the case where there is no existing tracking session
// for the client and id being used, since updateTrackingCommand can be sent to both
@@ -1696,19 +1806,21 @@ GnssAdapter::updateTrackingOptionsCommand(LocationAPI* client, uint32_t id,
sendMsg(new MsgUpdateTracking(*this, *mLocApi, client, id, options));
}
-LocationError
+bool
GnssAdapter::updateTrackingMultiplex(LocationAPI* client, uint32_t id,
const LocationOptions& options)
{
- LocationError err = LOCATION_ERROR_SUCCESS;
+ bool reportToClientWithNoWait = true;
+
+ LocationSessionKey key(client, id);
+ // get the session we are updating
+ auto it = mTrackingSessions.find(key);
+ // cache the clients existing LocationOptions
+ LocationOptions oldOptions = it->second;
if (1 == mTrackingSessions.size()) {
- err = startTracking(options);
+ reportToClientWithNoWait = updateTracking(client, id, options, oldOptions);
} else {
- LocationSessionKey key(client, id);
-
- // get the session we are updating
- auto it = mTrackingSessions.find(key);
if (it != mTrackingSessions.end()) {
// find the smallest interval, other than the session we are updating
LocationOptions smallestIntervalOptions = {}; // size is 0 until set for the first time
@@ -1723,16 +1835,17 @@ GnssAdapter::updateTrackingMultiplex(LocationAPI* client, uint32_t id,
// if session we are updating has smaller interval then next smallest
if (options.minInterval < smallestIntervalOptions.minInterval) {
// restart time based tracking with the newly updated interval
- err = startTracking(options);
+ reportToClientWithNoWait = updateTracking(client, id, options, oldOptions);
// else if the session we are updating used to be the smallest
} else if (it->second.minInterval < smallestIntervalOptions.minInterval) {
// restart time based tracking with the next smallest
- err = startTracking(smallestIntervalOptions);
+ reportToClientWithNoWait = updateTracking(
+ client, id, smallestIntervalOptions, oldOptions);
}
}
}
- return err;
+ return reportToClientWithNoWait;
}
void
@@ -1756,31 +1869,31 @@ GnssAdapter::stopTrackingCommand(LocationAPI* client, uint32_t id)
mSessionId(sessionId) {}
inline virtual void proc() const {
if (mAdapter.isTrackingSession(mClient, mSessionId)) {
- LocationError err = LOCATION_ERROR_SUCCESS;
// Api doesn't support multiple clients for time based tracking, so mutiplex
- err = mAdapter.stopTrackingMultiplex(mClient, mSessionId);
- if (LOCATION_ERROR_SUCCESS == err) {
- mAdapter.eraseTrackingSession(mClient, mSessionId);
+ bool reportToClientWithNoWait =
+ mAdapter.stopTrackingMultiplex(mClient, mSessionId);
+ mAdapter.eraseTrackingSession(mClient, mSessionId);
+
+ if (reportToClientWithNoWait) {
+ mAdapter.reportResponse(mClient, LOCATION_ERROR_SUCCESS, mSessionId);
}
- mAdapter.reportResponse(mClient, err, mSessionId);
}
// we do not reportResponse for the case where there is no existing tracking session
// for the client and id being used, since stopTrackingCommand can be sent to both
// GnssAdapter & FlpAdapter by LocationAPI and we want to avoid incorrect error response
-
}
};
sendMsg(new MsgStopTracking(*this, *mLocApi, client, id));
}
-LocationError
+bool
GnssAdapter::stopTrackingMultiplex(LocationAPI* client, uint32_t id)
{
- LocationError err = LOCATION_ERROR_SUCCESS;
+ bool reportToClientWithNoWait = true;
if (1 == mTrackingSessions.size()) {
- err = stopTracking();
+ reportToClientWithNoWait = stopTracking(client, id);
} else {
LocationSessionKey key(client, id);
@@ -1800,31 +1913,32 @@ GnssAdapter::stopTrackingMultiplex(LocationAPI* client, uint32_t id)
// if session we are stopping has smaller interval then next smallest
if (it->second.minInterval < smallestIntervalOptions.minInterval) {
// restart time based tracking with next smallest interval
- err = startTracking(smallestIntervalOptions);
+ reportToClientWithNoWait = startTracking(client, id, smallestIntervalOptions);
}
}
}
- return err;
+ return reportToClientWithNoWait;
}
-LocationError
-GnssAdapter::stopTracking()
+bool
+GnssAdapter::stopTracking(LocationAPI* client, uint32_t id)
{
- LocationError err = LOCATION_ERROR_SUCCESS;
+ bool reportToClientWithNoWait = true;
+
if (!mUlpProxy->sendStopFix()) {
// inform engine hub that GNSS session has stopped
mEngHubProxy->gnssStopFix();
- loc_api_adapter_err apiErr = mLocApi->stopFix();
- if (LOC_API_ADAPTER_ERR_SUCCESS == apiErr) {
- err = LOCATION_ERROR_SUCCESS;
- } else {
- err = LOCATION_ERROR_GENERAL_FAILURE;
- }
+ mLocApi->stopFix(new LocApiResponse(*getContext(),
+ [this, client, id] (LocationError err) {
+ reportResponse(client, err, id);
+ }));
+
+ reportToClientWithNoWait = false;
}
- return err;
+ return reportToClientWithNoWait;
}
void
@@ -1849,7 +1963,9 @@ GnssAdapter::stopTrackingCommand()
mLocPosMode.mode = LOC_POSITION_MODE_INVALID;
mAdapter.setUlpPositionMode(mLocPosMode);
// don't need to multiplex because ULP will do that for us if it is present
- mApi.stopFix();
+ mApi.stopFix(new LocApiResponse(*mAdapter.getContext(),
+ [] (LocationError /* err*/) {}
+ ));
}
};
@@ -1870,24 +1986,12 @@ GnssAdapter::getZppCommand()
mAdapter(adapter),
mApi(api) {}
inline virtual void proc() const {
- UlpLocation location = {};
- LocPosTechMask techMask = LOC_POS_TECH_MASK_DEFAULT;
- GpsLocationExtended locationExtended = {};
- locationExtended.size = sizeof(locationExtended);
-
- mApi.getBestAvailableZppFix(location.gpsLocation, locationExtended,
- techMask);
- //Mark the location source as from ZPP
- location.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
- location.position_source = ULP_LOCATION_IS_FROM_ZPP;
-
- mAdapter.getUlpProxy()->reportPosition(location,
- locationExtended,
- LOC_SESS_SUCCESS,
- techMask);
+ mApi.getBestAvailableZppFix();
}
};
+ // TODO: we could avoid this extra context switch, as getBestAvailableZppFix
+ // will return asynchronously anyways.
sendMsg(new MsgGetZpp(*this, *mLocApi));
}
@@ -1971,28 +2075,28 @@ GnssAdapter::gnssNiResponseCommand(GnssNiResponse response, void* rawRequest)
LOC_LOGD("%s]: response %u", __func__, response);
struct MsgGnssNiResponse : public LocMsg {
+ GnssAdapter& mAdapter;
LocApiBase& mApi;
const GnssNiResponse mResponse;
const void* mPayload;
- inline MsgGnssNiResponse(LocApiBase& api,
+ inline MsgGnssNiResponse(GnssAdapter& adapter,
+ LocApiBase& api,
const GnssNiResponse response,
const void* rawRequest) :
LocMsg(),
+ mAdapter(adapter),
mApi(api),
mResponse(response),
mPayload(rawRequest) {}
inline virtual ~MsgGnssNiResponse() {
- // this is a bit weird since mPayload is not
- // allocated by this class. But there is no better way.
- // mPayload actually won't be NULL here.
- free((void*)mPayload);
}
inline virtual void proc() const {
+ const void *rawPayload = mPayload;
mApi.informNiResponse(mResponse, mPayload);
}
};
- sendMsg(new MsgGnssNiResponse(*mLocApi, response, rawRequest));
+ sendMsg(new MsgGnssNiResponse(*this, *mLocApi, response, rawRequest));
}
@@ -2029,7 +2133,11 @@ GnssAdapter::enableCommand(LocationTechnologyType techType)
} else {
mContext.modemPowerVote(true);
mAdapter.setPowerVoteId(mSessionId);
- mApi.setGpsLock(GNSS_CONFIG_GPS_LOCK_NONE);
+
+ mApi.sendMsg(new LocApiMsg([&mApi = mApi] () {
+ mApi.setGpsLockSync(GNSS_CONFIG_GPS_LOCK_NONE);
+ }));
+
mAdapter.mXtraObserver.updateLockStatus(
mAdapter.convertGpsLock(GNSS_CONFIG_GPS_LOCK_NONE));
}
@@ -2073,7 +2181,12 @@ GnssAdapter::disableCommand(uint32_t id)
} else {
mContext.modemPowerVote(false);
mAdapter.setPowerVoteId(0);
- mApi.setGpsLock(mAdapter.convertGpsLock(ContextBase::mGps_conf.GPS_LOCK));
+
+ GnssConfigGpsLock gpsLock =
+ mAdapter.convertGpsLock(ContextBase::mGps_conf.GPS_LOCK);
+ mApi.sendMsg(new LocApiMsg([&mApi = mApi,gpsLock] () {
+ mApi.setGpsLockSync(gpsLock);
+ }));
mAdapter.mXtraObserver.updateLockStatus(
mAdapter.convertGpsLock(ContextBase::mGps_conf.GPS_LOCK));
}
@@ -2810,6 +2923,41 @@ bool GnssAdapter::reportDataCallClosed(){
return true;
}
+bool GnssAdapter::reportZppBestAvailableFix(LocGpsLocation &zppLoc,
+ GpsLocationExtended &location_extended, LocPosTechMask tech_mask) {
+
+ struct MsgReportZpp : public LocMsg {
+ GnssAdapter& mAdapter;
+ UlpLocation mUlpLocation;
+ GpsLocationExtended mGpsLocationExtended;
+ LocPosTechMask mPosTechMask;
+
+ inline MsgReportZpp(GnssAdapter& adapter,
+ LocGpsLocation &zppLoc, GpsLocationExtended &location_extended,
+ LocPosTechMask tech_mask) :
+ LocMsg(),
+ mAdapter(adapter),
+ mGpsLocationExtended(location_extended),
+ mPosTechMask(tech_mask) {
+ mUlpLocation = {};
+ memcpy(&mUlpLocation.gpsLocation, &zppLoc, sizeof(LocGpsLocation));
+
+ //Mark the location source as from ZPP
+ mUlpLocation.gpsLocation.flags |= LOCATION_HAS_SOURCE_INFO;
+ mUlpLocation.position_source = ULP_LOCATION_IS_FROM_ZPP;
+ }
+ inline virtual void proc() const {
+ mAdapter.getUlpProxy()->reportPosition(mUlpLocation,
+ mGpsLocationExtended,
+ LOC_SESS_SUCCESS,
+ mPosTechMask);
+ }
+ };
+
+ sendMsg(new MsgReportZpp(*this, zppLoc, location_extended, tech_mask));
+ return true;
+}
+
void GnssAdapter::dataConnOpenCommand(
AGpsExtType agpsType,
const char* apnName, int apnLen, AGpsBearerType bearerType){
diff --git a/gnss/GnssAdapter.h b/gnss/GnssAdapter.h
index c1e1754..8d639fe 100644
--- a/gnss/GnssAdapter.h
+++ b/gnss/GnssAdapter.h
@@ -157,7 +157,7 @@ public:
LocationCallbacks getClientCallbacks(LocationAPI* client);
LocationCapabilitiesMask getCapabilities();
void broadcastCapabilities(LocationCapabilitiesMask);
- LocationError setSuplHostServer(const char* server, int port);
+ void setSuplHostServer(const char* server, int port);
/* ==== TRACKING ======================================================================= */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
@@ -180,12 +180,16 @@ public:
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,
+ bool startTrackingMultiplex(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& options);
+ bool startTracking(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& options);
+ bool stopTrackingMultiplex(LocationAPI* client, uint32_t id);
+ bool stopTracking(LocationAPI* client, uint32_t id);
+ bool updateTrackingMultiplex(LocationAPI* client, uint32_t id,
const LocationOptions& options);
+ bool updateTracking(LocationAPI* client, uint32_t sessionId,
+ const LocationOptions& updatedOptions, const LocationOptions& oldOptions);
/* ==== NI ============================================================================= */
/* ======== COMMANDS ====(Called from Client Thread)==================================== */
@@ -203,9 +207,11 @@ public:
void setControlCallbacksCommand(LocationControlCallbacks& controlCallbacks);
void readConfigCommand();
void setConfigCommand();
+ void requestUlpCommand();
void initEngHubProxyCommand();
uint32_t* gnssUpdateConfigCommand(GnssConfig config);
uint32_t gnssDeleteAidingDataCommand(GnssAidingData& data);
+ void deleteAidingData(const GnssAidingData &data, uint32_t sessionId);
void gnssUpdateXtraThrottleCommand(const bool enabled);
void initDefaultAgpsCommand();
@@ -224,7 +230,6 @@ public:
{ 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();
bool initEngHubProxy();
@@ -249,6 +254,8 @@ public:
virtual bool requestSuplES(int connHandle);
virtual bool reportDataCallOpened();
virtual bool reportDataCallClosed();
+ virtual bool reportZppBestAvailableFix(LocGpsLocation &zppLoc,
+ GpsLocationExtended &location_extended, LocPosTechMask tech_mask);
/* ======== UTILITIES ================================================================= */
bool needReport(const UlpLocation& ulpLocation,
@@ -276,15 +283,11 @@ public:
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,
diff --git a/gnss/Makefile.am b/gnss/Makefile.am
index 7ee6089..db20c15 100644
--- a/gnss/Makefile.am
+++ b/gnss/Makefile.am
@@ -7,7 +7,7 @@ AM_CFLAGS = \
-I../utils \
-I$(WORKSPACE)/hardware/qcom/gps/core/data-items \
-I../location \
- -std=c++11
+ -std=c++1y
libgnss_la_SOURCES = \
location_gnss.cpp \