diff options
Diffstat (limited to 'android/2.0/location_api/BatchingAPIClient.cpp')
-rw-r--r-- | android/2.0/location_api/BatchingAPIClient.cpp | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/android/2.0/location_api/BatchingAPIClient.cpp b/android/2.0/location_api/BatchingAPIClient.cpp index 48caee6..49cd18a 100644 --- a/android/2.0/location_api/BatchingAPIClient.cpp +++ b/android/2.0/location_api/BatchingAPIClient.cpp @@ -45,33 +45,60 @@ namespace gnss { namespace V2_0 { namespace implementation { -using ::android::hardware::gnss::V1_0::IGnssBatching; -using ::android::hardware::gnss::V1_0::IGnssBatchingCallback; -using ::android::hardware::gnss::V1_0::GnssLocation; +using ::android::hardware::gnss::V2_0::IGnssBatching; +using ::android::hardware::gnss::V2_0::IGnssBatchingCallback; +using ::android::hardware::gnss::V2_0::GnssLocation; static void convertBatchOption(const IGnssBatching::Options& in, LocationOptions& out, LocationCapabilitiesMask mask); -BatchingAPIClient::BatchingAPIClient(const sp<IGnssBatchingCallback>& callback) : +BatchingAPIClient::BatchingAPIClient(const sp<V1_0::IGnssBatchingCallback>& callback) : LocationAPIClientBase(), - mGnssBatchingCbIface(callback), + mGnssBatchingCbIface(nullptr), mDefaultId(UINT_MAX), - mLocationCapabilitiesMask(0) + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) { LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + gnssUpdateCallbacks(callback); +} + +BatchingAPIClient::BatchingAPIClient(const sp<V2_0::IGnssBatchingCallback>& callback) : + LocationAPIClientBase(), + mGnssBatchingCbIface(nullptr), + mDefaultId(UINT_MAX), + mLocationCapabilitiesMask(0), + mGnssBatchingCbIface_2_0(nullptr) +{ + LOC_LOGD("%s]: (%p)", __FUNCTION__, &callback); + + gnssUpdateCallbacks_2_0(callback); +} + +BatchingAPIClient::~BatchingAPIClient() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); +} + +int BatchingAPIClient::getBatchSize() +{ + LOC_LOGD("%s]: ()", __FUNCTION__); + return locAPIGetBatchSize(); +} + +void BatchingAPIClient::setCallbacks() +{ LocationCallbacks locationCallbacks; memset(&locationCallbacks, 0, sizeof(LocationCallbacks)); locationCallbacks.size = sizeof(LocationCallbacks); locationCallbacks.trackingCb = nullptr; locationCallbacks.batchingCb = nullptr; - if (mGnssBatchingCbIface != nullptr) { - locationCallbacks.batchingCb = [this](size_t count, Location* location, - BatchingOptions batchOptions) { - onBatchingCb(count, location, batchOptions); - }; - } + locationCallbacks.batchingCb = [this](size_t count, Location* location, + BatchingOptions batchOptions) { + onBatchingCb(count, location, batchOptions); + }; locationCallbacks.geofenceBreachCb = nullptr; locationCallbacks.geofenceStatusCb = nullptr; locationCallbacks.gnssLocationInfoCb = nullptr; @@ -83,15 +110,26 @@ BatchingAPIClient::BatchingAPIClient(const sp<IGnssBatchingCallback>& callback) locAPISetCallbacks(locationCallbacks); } -BatchingAPIClient::~BatchingAPIClient() +void BatchingAPIClient::gnssUpdateCallbacks(const sp<V1_0::IGnssBatchingCallback>& callback) { - LOC_LOGD("%s]: ()", __FUNCTION__); + mMutex.lock(); + mGnssBatchingCbIface = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface != nullptr) { + setCallbacks(); + } } -int BatchingAPIClient::getBatchSize() +void BatchingAPIClient::gnssUpdateCallbacks_2_0(const sp<V2_0::IGnssBatchingCallback>& callback) { - LOC_LOGD("%s]: ()", __FUNCTION__); - return locAPIGetBatchSize(); + mMutex.lock(); + mGnssBatchingCbIface_2_0 = callback; + mMutex.unlock(); + + if (mGnssBatchingCbIface_2_0 != nullptr) { + setCallbacks(); + } } int BatchingAPIClient::startSession(const IGnssBatching::Options& opts) @@ -160,16 +198,32 @@ void BatchingAPIClient::onCapabilitiesCb(LocationCapabilitiesMask capabilitiesMa void BatchingAPIClient::onBatchingCb(size_t count, Location* location, BatchingOptions /*batchOptions*/) { + mMutex.lock(); + auto gnssBatchingCbIface(mGnssBatchingCbIface); + auto gnssBatchingCbIface_2_0(mGnssBatchingCbIface_2_0); + mMutex.unlock(); + LOC_LOGD("%s]: (count: %zu)", __FUNCTION__, count); - if (mGnssBatchingCbIface != nullptr && count > 0) { - hidl_vec<GnssLocation> locationVec; + if (gnssBatchingCbIface_2_0 != nullptr && count > 0) { + hidl_vec<V2_0::GnssLocation> locationVec; + locationVec.resize(count); + for (size_t i = 0; i < count; i++) { + convertGnssLocation(location[i], locationVec[i]); + } + auto r = gnssBatchingCbIface_2_0->gnssLocationBatchCb(locationVec); + if (!r.isOk()) { + LOC_LOGE("%s] Error from gnssLocationBatchCb 2.0 description=%s", + __func__, r.description().c_str()); + } + } else if (gnssBatchingCbIface != nullptr && count > 0) { + hidl_vec<V1_0::GnssLocation> locationVec; locationVec.resize(count); for (size_t i = 0; i < count; i++) { convertGnssLocation(location[i], locationVec[i]); } - auto r = mGnssBatchingCbIface->gnssLocationBatchCb(locationVec); + auto r = gnssBatchingCbIface->gnssLocationBatchCb(locationVec); if (!r.isOk()) { - LOC_LOGE("%s] Error from gnssLocationBatchCb description=%s", + LOC_LOGE("%s] Error from gnssLocationBatchCb 1.0 description=%s", __func__, r.description().c_str()); } } |