summaryrefslogtreecommitdiff
path: root/location/LocationAPIClientBase.cpp
diff options
context:
space:
mode:
authorDante Russo <drusso@codeaurora.org>2017-10-03 14:38:42 -0700
committerDante Russo <drusso@codeaurora.org>2017-10-10 14:56:34 -0700
commit34ce2a68730afc925438ba191514db7b10432821 (patch)
tree0fb8863219740282cf08d729e98b3eba53021731 /location/LocationAPIClientBase.cpp
parent39526894cfaafab8b9fc6714956c4f6df0bcc329 (diff)
downloadgps-34ce2a68730afc925438ba191514db7b10432821.tar.gz
Fix support for batching without batch full event
Additional fixes: -fix issue where if StartTracking or StartBatching fails at QMI LOC layer, then the session is stuck and Tracking or Batching cannot be stoped or started again. -fix getBatchedLocation API to return an error if the id given is not valid, as caller will not get a response callback in this case. CRs-fixed 2118838 Change-Id: I389fc862836450f0081f6394c971b33614373841
Diffstat (limited to 'location/LocationAPIClientBase.cpp')
-rw-r--r--location/LocationAPIClientBase.cpp66
1 files changed, 34 insertions, 32 deletions
diff --git a/location/LocationAPIClientBase.cpp b/location/LocationAPIClientBase.cpp
index 4aa1ccb..50b4b83 100644
--- a/location/LocationAPIClientBase.cpp
+++ b/location/LocationAPIClientBase.cpp
@@ -393,14 +393,20 @@ uint32_t LocationAPIClientBase::locAPIStartSession(uint32_t id, uint32_t session
trackingSession = mLocationAPI->startTracking(locationOptions);
LOC_LOGI("%s:%d] start new session: %d", __FUNCTION__, __LINE__, trackingSession);
mRequestQueues[REQUEST_SESSION].push(new StartTrackingRequest(*this));
- } else if ((sessionMode == SESSION_MODE_ON_FULL) ||
- (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED)) {
+ } else {
// Fill in the batch mode
BatchingOptions batchOptions = {};
batchOptions.size = sizeof(BatchingOptions);
- batchOptions.batchingMode = BATCHING_MODE_ROUTINE;
- if (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED) {
+ switch (sessionMode) {
+ case SESSION_MODE_ON_FULL:
+ batchOptions.batchingMode = BATCHING_MODE_ROUTINE;
+ break;
+ case SESSION_MODE_ON_TRIP_COMPLETED:
batchOptions.batchingMode = BATCHING_MODE_TRIP;
+ break;
+ default:
+ batchOptions.batchingMode = BATCHING_MODE_NO_AUTO_REPORT;
+ break;
}
batchingSession = mLocationAPI->startBatching(locationOptions, batchOptions);
@@ -409,8 +415,7 @@ uint32_t LocationAPIClientBase::locAPIStartSession(uint32_t id, uint32_t session
mRequestQueues[REQUEST_SESSION].push(new StartBatchingRequest(*this));
}
- uint32_t session = ((sessionMode == SESSION_MODE_ON_FULL ||
- (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED)) ?
+ uint32_t session = ((sessionMode != SESSION_MODE_ON_FIX) ?
batchingSession : trackingSession);
SessionEntity entity;
@@ -445,12 +450,9 @@ uint32_t LocationAPIClientBase::locAPIStopSession(uint32_t id)
if (sMode == SESSION_MODE_ON_FIX) {
mRequestQueues[REQUEST_SESSION].push(new StopTrackingRequest(*this));
mLocationAPI->stopTracking(trackingSession);
- } else if ((sMode == SESSION_MODE_ON_FULL) ||
- (sMode == SESSION_MODE_ON_TRIP_COMPLETED)) {
+ } else {
mRequestQueues[REQUEST_SESSION].push(new StopBatchingRequest(*this));
mLocationAPI->stopBatching(batchingSession);
- } else {
- LOC_LOGE("%s:%d] unknown mode %d.", __FUNCTION__, __LINE__, sMode);
}
retVal = LOCATION_ERROR_SUCCESS;
@@ -484,8 +486,7 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
mRequestQueues[REQUEST_SESSION].push(new UpdateTrackingOptionsRequest(*this));
if (sMode == SESSION_MODE_ON_FIX) {
mLocationAPI->updateTrackingOptions(trackingSession, options);
- } else if ((sMode == SESSION_MODE_ON_FULL) ||
- (sMode == SESSION_MODE_ON_TRIP_COMPLETED)) {
+ } else {
// stop batching
// batchingSession will be removed from mSessionBiDict soon,
// so we don't need to add a new request to mRequestQueues[REQUEST_SESSION].
@@ -497,19 +498,23 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
trackingSession = mLocationAPI->startTracking(options);
LOC_LOGI("%s:%d] start new session: %d",
__FUNCTION__, __LINE__, trackingSession);
- } else {
- LOC_LOGE("%s:%d] unknown mode %d", __FUNCTION__, __LINE__, sMode);
}
- } else if ((sessionMode == SESSION_MODE_ON_FULL) ||
- (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED)) {
+ } else {
// we only add an UpdateBatchingOptionsRequest to mRequestQueues[REQUEST_SESSION],
// even if this update request will stop tracking and then start batching.
mRequestQueues[REQUEST_SESSION].push(new UpdateBatchingOptionsRequest(*this));
BatchingOptions batchOptions = {};
batchOptions.size = sizeof(BatchingOptions);
- batchOptions.batchingMode = BATCHING_MODE_ROUTINE;
- if (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED) {
- batchOptions.batchingMode = BATCHING_MODE_TRIP;
+ switch (sessionMode) {
+ case SESSION_MODE_ON_FULL:
+ batchOptions.batchingMode = BATCHING_MODE_ROUTINE;
+ break;
+ case SESSION_MODE_ON_TRIP_COMPLETED:
+ batchOptions.batchingMode = BATCHING_MODE_TRIP;
+ break;
+ default:
+ batchOptions.batchingMode = BATCHING_MODE_NO_AUTO_REPORT;
+ break;
}
if (sMode == SESSION_MODE_ON_FIX) {
@@ -524,19 +529,13 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
LOC_LOGI("%s:%d] start new session: %d",
__FUNCTION__, __LINE__, batchingSession);
mRequestQueues[REQUEST_SESSION].setSession(batchingSession);
- } else if ((sMode == SESSION_MODE_ON_FULL) ||
- (sMode == SESSION_MODE_ON_TRIP_COMPLETED)) {
- mLocationAPI->updateBatchingOptions(batchingSession, options, batchOptions);
} else {
- LOC_LOGE("%s:%d] unknown mode %d", __FUNCTION__, __LINE__, sMode);
+ mLocationAPI->updateBatchingOptions(batchingSession, options, batchOptions);
}
- } else {
- LOC_LOGE("%s:%d] unknown mode %d.", __FUNCTION__, __LINE__, sessionMode);
}
- uint32_t session = ((sessionMode == SESSION_MODE_ON_FULL) ||
- (sessionMode == SESSION_MODE_ON_TRIP_COMPLETED) ?
+ uint32_t session = ((sessionMode != SESSION_MODE_ON_FIX) ?
batchingSession : trackingSession);
entity.trackingSession = trackingSession;
@@ -556,22 +555,25 @@ uint32_t LocationAPIClientBase::locAPIUpdateSessionOptions(uint32_t id, uint32_t
return retVal;
}
-void LocationAPIClientBase::locAPIGetBatchedLocations(uint32_t id, size_t count)
+uint32_t LocationAPIClientBase::locAPIGetBatchedLocations(uint32_t id, size_t count)
{
+ uint32_t retVal = LOCATION_ERROR_GENERAL_FAILURE;
pthread_mutex_lock(&mMutex);
if (mLocationAPI) {
- uint32_t session = 0;
- session = mRequestQueues[REQUEST_SESSION].getSession();
- if (session > 0) {
+ if (mSessionBiDict.hasId(id)) {
SessionEntity entity = mSessionBiDict.getExtById(id);
uint32_t batchingSession = entity.batchingSession;
mRequestQueues[REQUEST_SESSION].push(new GetBatchedLocationsRequest(*this));
mLocationAPI->getBatchedLocations(batchingSession, count);
+ retVal = LOCATION_ERROR_SUCCESS;
} else {
- LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, session);
+ retVal = LOCATION_ERROR_ID_UNKNOWN;
+ LOC_LOGE("%s:%d] invalid session: %d.", __FUNCTION__, __LINE__, id);
}
}
pthread_mutex_unlock(&mMutex);
+
+ return retVal;
}
uint32_t LocationAPIClientBase::locAPIAddGeofences(