Merge "LocationAPI must also be freed on destroy call"
This commit is contained in:
commit
9d6d95d096
3 changed files with 18 additions and 13 deletions
|
@ -37,13 +37,6 @@
|
||||||
|
|
||||||
typedef void* (getLocationInterface)();
|
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 {
|
typedef struct {
|
||||||
// bit mask of the adpaters that we need to wait for the removeClientCompleteCallback
|
// bit mask of the adpaters that we need to wait for the removeClientCompleteCallback
|
||||||
// before we invoke the registered locationApiDestroyCompleteCallback
|
// before we invoke the registered locationApiDestroyCompleteCallback
|
||||||
|
@ -129,14 +122,13 @@ static void* loadLocationInterface(const char* library, const char* name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onRemoveClientCompleteCb (
|
void LocationAPI::onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType)
|
||||||
LocationAPI* client, LocationAdapterTypeMask adapterType)
|
|
||||||
{
|
{
|
||||||
bool invokeCallback = false;
|
bool invokeCallback = false;
|
||||||
locationApiDestroyCompleteCallback destroyCompleteCb;
|
locationApiDestroyCompleteCallback destroyCompleteCb;
|
||||||
LOC_LOGd("adatper type %x", adapterType);
|
LOC_LOGd("adatper type %x", adapterType);
|
||||||
pthread_mutex_lock(&gDataMutex);
|
pthread_mutex_lock(&gDataMutex);
|
||||||
auto it = gData.destroyClientData.find(client);
|
auto it = gData.destroyClientData.find(this);
|
||||||
if (it != gData.destroyClientData.end()) {
|
if (it != gData.destroyClientData.end()) {
|
||||||
it->second.waitAdapterMask &= ~adapterType;
|
it->second.waitAdapterMask &= ~adapterType;
|
||||||
if (it->second.waitAdapterMask == 0) {
|
if (it->second.waitAdapterMask == 0) {
|
||||||
|
@ -151,22 +143,24 @@ void onRemoveClientCompleteCb (
|
||||||
LOC_LOGd("invoke client destroy cb");
|
LOC_LOGd("invoke client destroy cb");
|
||||||
(destroyCompleteCb) ();
|
(destroyCompleteCb) ();
|
||||||
LOC_LOGd("finish invoke client destroy cb");
|
LOC_LOGd("finish invoke client destroy cb");
|
||||||
|
|
||||||
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onGnssRemoveClientCompleteCb (LocationAPI* client)
|
void onGnssRemoveClientCompleteCb (LocationAPI* client)
|
||||||
{
|
{
|
||||||
onRemoveClientCompleteCb (client, LOCATION_ADAPTER_GNSS_TYPE_BIT);
|
client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GNSS_TYPE_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFlpRemoveClientCompleteCb (LocationAPI* client)
|
void onFlpRemoveClientCompleteCb (LocationAPI* client)
|
||||||
{
|
{
|
||||||
onRemoveClientCompleteCb (client, LOCATION_ADAPTER_FLP_TYPE_BIT);
|
client->onRemoveClientCompleteCb (LOCATION_ADAPTER_FLP_TYPE_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onGeofenceRemoveClientCompleteCb (LocationAPI* client)
|
void onGeofenceRemoveClientCompleteCb (LocationAPI* client)
|
||||||
{
|
{
|
||||||
onRemoveClientCompleteCb (client, LOCATION_ADAPTER_GEOFENCE_TYPE_BIT);
|
client->onRemoveClientCompleteCb (LOCATION_ADAPTER_GEOFENCE_TYPE_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationAPI*
|
LocationAPI*
|
||||||
|
@ -310,6 +304,7 @@ LocationAPI::destroy(locationApiDestroyCompleteCallback destroyCompleteCb)
|
||||||
pthread_mutex_unlock(&gDataMutex);
|
pthread_mutex_unlock(&gDataMutex);
|
||||||
if (invokeDestroyCb == true) {
|
if (invokeDestroyCb == true) {
|
||||||
(destroyCompleteCb) ();
|
(destroyCompleteCb) ();
|
||||||
|
delete this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,6 +316,7 @@ LocationAPI::LocationAPI()
|
||||||
// private destructor
|
// private destructor
|
||||||
LocationAPI::~LocationAPI()
|
LocationAPI::~LocationAPI()
|
||||||
{
|
{
|
||||||
|
LOC_LOGD("LOCATION API DESTRUCTOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -52,6 +52,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void destroy(locationApiDestroyCompleteCallback destroyCompleteCb=nullptr);
|
void destroy(locationApiDestroyCompleteCallback destroyCompleteCb=nullptr);
|
||||||
|
|
||||||
|
void onRemoveClientCompleteCb (LocationAdapterTypeMask adapterType);
|
||||||
|
|
||||||
/* updates/changes the callbacks that will be called.
|
/* updates/changes the callbacks that will be called.
|
||||||
mandatory callbacks must be present for callbacks to be successfully updated
|
mandatory callbacks must be present for callbacks to be successfully updated
|
||||||
no return value */
|
no return value */
|
||||||
|
|
|
@ -1277,6 +1277,13 @@ typedef std::function<void(
|
||||||
typedef std::function<void(
|
typedef std::function<void(
|
||||||
)> locationApiDestroyCompleteCallback;
|
)> 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 {
|
typedef struct {
|
||||||
size_t size; // set to sizeof(LocationCallbacks)
|
size_t size; // set to sizeof(LocationCallbacks)
|
||||||
capabilitiesCallback capabilitiesCb; // mandatory
|
capabilitiesCallback capabilitiesCb; // mandatory
|
||||||
|
|
Loading…
Reference in a new issue