Maintain a uniq RequestQueue for Geofencing

Maintain a RequestQueue for Geofencing per LocationAPIClientBase instance.
The RequestQueue must be released when LocationAPIClientBase is destroyed.

Change-Id: Icceccdaae67883f8848dd2a95389b938058c5e5d
CRs-fixed: 2044463
This commit is contained in:
Baili Feng 2017-05-09 15:36:10 +08:00
parent 10ab9ccaaf
commit 1e0be88b94

View file

@ -34,6 +34,7 @@
#include "LocationAPIClientBase.h"
#define BATCHING_CONF_FILE "/etc/flp.conf"
#define GEOFENCE_SESSION_ID -1
LocationAPIClientBase::LocationAPIClientBase() :
mTrackingCallback(nullptr),
@ -405,15 +406,16 @@ uint32_t LocationAPIClientBase::locAPIAddGeofences(
if (mLocationAPI) {
pthread_mutex_lock(&mMutex);
RequestQueue* requests = mRequestQueues[REQUEST_GEOFENCE];
if (requests) {
delete requests;
if (!requests) {
// Create a new RequestQueue for Geofenceing if we've not had one.
// The RequestQueue will be released when LocationAPIClientBase is released.
requests = new RequestQueue(GEOFENCE_SESSION_ID);
mRequestQueues[REQUEST_GEOFENCE] = requests;
}
uint32_t* sessions = mLocationAPI->addGeofences(count, options, data);
if (sessions) {
LOC_LOGI("%s:%d] start new sessions: %p", __FUNCTION__, __LINE__, sessions);
requests = new RequestQueue(-1);
requests->push(new AddGeofencesRequest(*this));
mRequestQueues[REQUEST_GEOFENCE] = requests;
for (size_t i = 0; i < count; i++) {
mGeofenceBiDict.set(ids[i], sessions[i], options[i].breachTypeMask);