Merge "LocationAPI must also be freed on destroy call"

This commit is contained in:
qctecmdr Service 2019-01-29 11:07:09 -08:00 committed by Gerrit - the friendly Code Review server
commit 9d6d95d096
3 changed files with 18 additions and 13 deletions

View file

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

View file

@ -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 */

View file

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