From 1e0be88b948f3460b3b030a080f3083a1f893db7 Mon Sep 17 00:00:00 2001 From: Baili Feng Date: Tue, 9 May 2017 15:36:10 +0800 Subject: [PATCH] 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 --- location/LocationAPIClientBase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/location/LocationAPIClientBase.cpp b/location/LocationAPIClientBase.cpp index a160adc0..5078313b 100644 --- a/location/LocationAPIClientBase.cpp +++ b/location/LocationAPIClientBase.cpp @@ -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);