Merge "Adding one level of context swith for Geofence_add"
diff --git a/geofence/GeofenceAdapter.cpp b/geofence/GeofenceAdapter.cpp
index b8746fb..e299589 100644
--- a/geofence/GeofenceAdapter.cpp
+++ b/geofence/GeofenceAdapter.cpp
@@ -242,30 +242,33 @@
                 if (NULL == mIds || NULL == mOptions || NULL == mInfos) {
                     errs[i] = LOCATION_ERROR_INVALID_PARAMETER;
                 } else {
-                    mApi.addGeofence(mIds[i],
-                             mOptions[i],
-                             mInfos[i],
-                             new LocApiResponseData<LocApiGeofenceData>(*mAdapter.getContext(),
-                                    [&mAdapter = mAdapter, mOptions = mOptions, mClient = mClient,
-                                    mCount = mCount, mIds = mIds, mInfos = mInfos, errs, i]
-                                    (LocationError err, LocApiGeofenceData data) {
-                        if (LOCATION_ERROR_SUCCESS == err) {
-                            mAdapter.saveGeofenceItem(mClient,
-                                                      mIds[i],
-                                                      data.hwId,
-                                                      mOptions[i],
-                                                      mInfos[i]);
-                        }
-                        errs[i] = err;
+                    mApi.addToCallQueue(new LocApiResponse(*mAdapter.getContext(),
+                            [&mAdapter = mAdapter, mCount = mCount, mClient = mClient,
+                            mOptions = mOptions, mInfos = mInfos, mIds = mIds, &mApi = mApi,
+                            errs, i] (LocationError err ) {
+                        mApi.addGeofence(mIds[i], mOptions[i], mInfos[i],
+                        new LocApiResponseData<LocApiGeofenceData>(*mAdapter.getContext(),
+                        [&mAdapter = mAdapter, mOptions = mOptions, mClient = mClient,
+                        mCount = mCount, mIds = mIds, mInfos = mInfos, errs, i]
+                        (LocationError err, LocApiGeofenceData data) {
+                            if (LOCATION_ERROR_SUCCESS == err) {
+                                mAdapter.saveGeofenceItem(mClient,
+                                mIds[i],
+                                data.hwId,
+                                mOptions[i],
+                                mInfos[i]);
+                            }
+                            errs[i] = err;
 
-                        // Send aggregated response on last item and cleanup
-                        if (i == mCount-1) {
-                            mAdapter.reportResponse(mClient, mCount, errs, mIds);
-                            delete[] errs;
-                            delete[] mIds;
-                            delete[] mOptions;
-                            delete[] mInfos;
-                        }
+                            // Send aggregated response on last item and cleanup
+                            if (i == mCount-1) {
+                                mAdapter.reportResponse(mClient, mCount, errs, mIds);
+                                delete[] errs;
+                                delete[] mIds;
+                                delete[] mOptions;
+                                delete[] mInfos;
+                            }
+                        }));
                     }));
                 }
             }
diff --git a/location/LocationAPIClientBase.h b/location/LocationAPIClientBase.h
index fddae60..098000c 100644
--- a/location/LocationAPIClientBase.h
+++ b/location/LocationAPIClientBase.h
@@ -488,6 +488,7 @@
             for (size_t i = 0; i < count; i++) {
                 ids[i] = mAPI.mGeofenceBiDict.getId(sessions[i]);
             }
+            LOC_LOGD("%s:]Returned geofence-id: %d in add geofence", __FUNCTION__, *ids);
             mAPI.onAddGeofencesCb(count, errors, ids);
             free(ids);
         }
@@ -505,6 +506,7 @@
                 for (size_t i = 0; i < count; i++) {
                     ids[i] = mRemovedGeofenceBiDict->getId(sessions[i]);
                 }
+                LOC_LOGD("%s:]Returned geofence-id: %d in remove geofence", __FUNCTION__, *ids);
                 mAPI.onRemoveGeofencesCb(count, errors, ids);
                 free(ids);
                 delete(mRemovedGeofenceBiDict);