diff options
author | Bhavna Sharma <sbhavna@codeaurora.org> | 2019-01-24 16:18:38 -0800 |
---|---|---|
committer | Bhavna Sharma <sbhavna@codeaurora.org> | 2019-01-28 12:05:32 -0800 |
commit | 49c60ab27a04ab0f0f41b62181c5539b4e671842 (patch) | |
tree | d98fd89d7f8606b8eed503ca70deee5566c1add6 /location | |
parent | 47b591383b447b5c64e9e0ee706f1a4ca69c7d33 (diff) | |
download | gps-49c60ab27a04ab0f0f41b62181c5539b4e671842.tar.gz |
LocationAPI must also be freed on destroy call
LocationAPI object instance itself must also be freed when
destroy is called.
CRs-Fixed: 2388028
Change-Id: Ie6e1c34e126a10ea58076c0385aecd447233c7aa
Diffstat (limited to 'location')
-rw-r--r-- | location/LocationAPI.cpp | 22 | ||||
-rw-r--r-- | location/LocationAPI.h | 2 | ||||
-rw-r--r-- | location/LocationDataTypes.h | 7 |
3 files changed, 18 insertions, 13 deletions
diff --git a/location/LocationAPI.cpp b/location/LocationAPI.cpp index 4d859b3..e9f2ee4 100644 --- a/location/LocationAPI.cpp +++ b/location/LocationAPI.cpp @@ -37,13 +37,6 @@ typedef void* (getLocationInterface)(); -typedef uint16_t LocationAdapterTypeMask; -typedef enum { - LOCATION_ADAPTER_GNSS_TYPE_BIT = (1<<0), // adapter type is GNSS - LOCATION_ADAPTER_FLP_TYPE_BIT = (1<<1), // adapter type is FLP - LOCATION_ADAPTER_GEOFENCE_TYPE_BIT = (1<<2) // adapter type is geo fence -} LocationAdapterTypeBits; - typedef struct { // bit mask of the adpaters that we need to wait for the removeClientCompleteCallback // before we invoke the registered locationApiDestroyCompleteCallback @@ -129,14 +122,13 @@ static void* loadLocationInterface(const char* library, const char* name) } } -void onRemoveClientCompleteCb ( - LocationAPI* client, LocationAdapterTypeMask adapterType) +void LocationAPI::onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType) { bool invokeCallback = false; locationApiDestroyCompleteCallback destroyCompleteCb; LOC_LOGd("adatper type %x", adapterType); pthread_mutex_lock(&gDataMutex); - auto it = gData.destroyClientData.find(client); + auto it = gData.destroyClientData.find(this); if (it != gData.destroyClientData.end()) { it->second.waitAdapterMask &= ~adapterType; if (it->second.waitAdapterMask == 0) { @@ -151,22 +143,24 @@ void onRemoveClientCompleteCb ( LOC_LOGd("invoke client destroy cb"); (destroyCompleteCb) (); LOC_LOGd("finish invoke client destroy cb"); + + delete this; } } void onGnssRemoveClientCompleteCb (LocationAPI* client) { - onRemoveClientCompleteCb (client, LOCATION_ADAPTER_GNSS_TYPE_BIT); + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GNSS_TYPE_BIT); } void onFlpRemoveClientCompleteCb (LocationAPI* client) { - onRemoveClientCompleteCb (client, LOCATION_ADAPTER_FLP_TYPE_BIT); + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_FLP_TYPE_BIT); } void onGeofenceRemoveClientCompleteCb (LocationAPI* client) { - onRemoveClientCompleteCb (client, LOCATION_ADAPTER_GEOFENCE_TYPE_BIT); + client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GEOFENCE_TYPE_BIT); } LocationAPI* @@ -310,6 +304,7 @@ LocationAPI::destroy(locationApiDestroyCompleteCallback destroyCompleteCb) pthread_mutex_unlock(&gDataMutex); if (invokeDestroyCb == true) { (destroyCompleteCb) (); + delete this; } } @@ -321,6 +316,7 @@ LocationAPI::LocationAPI() // private destructor LocationAPI::~LocationAPI() { + LOC_LOGD("LOCATION API DESTRUCTOR"); } void diff --git a/location/LocationAPI.h b/location/LocationAPI.h index c270ef4..6f5987c 100644 --- a/location/LocationAPI.h +++ b/location/LocationAPI.h @@ -52,6 +52,8 @@ public: */ void destroy(locationApiDestroyCompleteCallback destroyCompleteCb=nullptr); + void onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType); + /* updates/changes the callbacks that will be called. mandatory callbacks must be present for callbacks to be successfully updated no return value */ diff --git a/location/LocationDataTypes.h b/location/LocationDataTypes.h index 61598be..1590b88 100644 --- a/location/LocationDataTypes.h +++ b/location/LocationDataTypes.h @@ -1277,6 +1277,13 @@ typedef std::function<void( typedef std::function<void( )> locationApiDestroyCompleteCallback; +typedef uint16_t LocationAdapterTypeMask; +typedef enum { + LOCATION_ADAPTER_GNSS_TYPE_BIT = (1<<0), // adapter type is GNSS + LOCATION_ADAPTER_FLP_TYPE_BIT = (1<<1), // adapter type is FLP + LOCATION_ADAPTER_GEOFENCE_TYPE_BIT = (1<<2) // adapter type is geo fence +} LocationAdapterTypeBits; + typedef struct { size_t size; // set to sizeof(LocationCallbacks) capabilitiesCallback capabilitiesCb; // mandatory |