Merge "Fix support for batching without batch full event"

This commit is contained in:
Linux Build Service Account 2017-10-13 00:03:56 -07:00 committed by Gerrit - the friendly Code Review server
commit 9f2a492534
3 changed files with 46 additions and 37 deletions

View file

@ -308,8 +308,9 @@ typedef enum {
} GnssSuplMode;
typedef enum {
BATCHING_MODE_ROUTINE = 0,
BATCHING_MODE_TRIP
BATCHING_MODE_ROUTINE = 0, // positions are reported when batched positions memory is full
BATCHING_MODE_TRIP, // positions are reported when a certain distance is covered
BATCHING_MODE_NO_AUTO_REPORT // no report of positions automatically, instead queried on demand
} BatchingMode;
typedef enum {

View file

@ -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(

View file

@ -195,7 +195,7 @@ public:
uint32_t locAPIStopSession(uint32_t id);
uint32_t locAPIUpdateSessionOptions(uint32_t id, uint32_t sessionMode,
LocationOptions& options);
void locAPIGetBatchedLocations(uint32_t id, size_t count);
uint32_t locAPIGetBatchedLocations(uint32_t id, size_t count);
uint32_t locAPIAddGeofences(size_t count, uint32_t* ids,
GeofenceOption* options, GeofenceInfo* data);
@ -381,7 +381,10 @@ private:
class StartTrackingRequest : public LocationAPIRequest {
public:
StartTrackingRequest(LocationAPIClientBase& API) : mAPI(API) {}
inline void onResponse(LocationError error, uint32_t /*id*/) {
inline void onResponse(LocationError error, uint32_t id) {
if (error != LOCATION_ERROR_SUCCESS) {
mAPI.removeSession(id);
}
mAPI.onStartTrackingCb(error);
}
LocationAPIClientBase& mAPI;
@ -411,7 +414,10 @@ private:
class StartBatchingRequest : public LocationAPIRequest {
public:
StartBatchingRequest(LocationAPIClientBase& API) : mAPI(API) {}
inline void onResponse(LocationError error, uint32_t /*id*/) {
inline void onResponse(LocationError error, uint32_t id) {
if (error != LOCATION_ERROR_SUCCESS) {
mAPI.removeSession(id);
}
mAPI.onStartBatchingCb(error);
}
LocationAPIClientBase& mAPI;