summaryrefslogtreecommitdiff
path: root/transport
diff options
context:
space:
mode:
authorAmos Bianchi <amosbianchi@google.com>2021-01-20 17:41:02 -0800
committerAmos Bianchi <amosbianchi@google.com>2021-01-20 17:41:02 -0800
commitfb9186324e1987ab59779bddc54266b0acdcf676 (patch)
tree01e0e205b545613821a687e63c8ac012415a7050 /transport
parent57341bb19f7782cefb3f762bad6601fbd635df5e (diff)
downloadlibhidl-fb9186324e1987ab59779bddc54266b0acdcf676.tar.gz
Change callback argument to boolean.
Bug: 176240491 Test: atest hidl_lazy_test Change-Id: If909f292288ecf0d521b0eaf93f5517fafaf3969
Diffstat (limited to 'transport')
-rw-r--r--transport/HidlLazyUtils.cpp39
-rw-r--r--transport/include/hidl/HidlLazyUtils.h11
2 files changed, 28 insertions, 22 deletions
diff --git a/transport/HidlLazyUtils.cpp b/transport/HidlLazyUtils.cpp
index ce37dd0..be7470f 100644
--- a/transport/HidlLazyUtils.cpp
+++ b/transport/HidlLazyUtils.cpp
@@ -40,8 +40,7 @@ class ClientCounterCallback : public ::android::hidl::manager::V1_2::IClientCall
void reRegister();
- void setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback);
+ void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
protected:
Return<void> onClients(const sp<IBase>& service, bool clients) override;
@@ -80,7 +79,12 @@ class ClientCounterCallback : public ::android::hidl::manager::V1_2::IClientCall
/**
* Callback for reporting the number of services with clients.
*/
- std::function<bool(int)> mActiveServicesCountCallback;
+ std::function<bool(bool)> mActiveServicesCallback;
+
+ /**
+ * Previous value passed to the active services callback.
+ */
+ std::optional<bool> mPreviousHasClients;
};
class LazyServiceRegistrarImpl {
@@ -91,8 +95,7 @@ class LazyServiceRegistrarImpl {
const std::string& name);
bool tryUnregister();
void reRegister();
- void setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback);
+ void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
private:
sp<ClientCounterCallback> mClientCallback;
@@ -166,8 +169,12 @@ Return<void> ClientCounterCallback::onClients(const sp<::android::hidl::base::V1
<< "/" << registered.name << " has clients: " << clients;
bool handledInCallback = false;
- if (mActiveServicesCountCallback != nullptr) {
- handledInCallback = mActiveServicesCountCallback(numWithClients);
+ if (mActiveServicesCallback != nullptr) {
+ bool hasClients = numWithClients != 0;
+ if (hasClients != mPreviousHasClients) {
+ handledInCallback = mActiveServicesCallback(hasClients);
+ mPreviousHasClients = hasClients;
+ }
}
// If there is no callback defined or the callback did not handle this
@@ -229,9 +236,9 @@ void ClientCounterCallback::tryShutdown() {
reRegister();
}
-void ClientCounterCallback::setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback) {
- mActiveServicesCountCallback = activeServicesCountCallback;
+void ClientCounterCallback::setActiveServicesCallback(
+ const std::function<bool(bool)>& activeServicesCallback) {
+ mActiveServicesCallback = activeServicesCallback;
}
status_t LazyServiceRegistrarImpl::registerService(
@@ -251,9 +258,9 @@ void LazyServiceRegistrarImpl::reRegister() {
mClientCallback->reRegister();
}
-void LazyServiceRegistrarImpl::setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback) {
- mClientCallback->setActiveServicesCountCallback(activeServicesCountCallback);
+void LazyServiceRegistrarImpl::setActiveServicesCallback(
+ const std::function<bool(bool)>& activeServicesCallback) {
+ mClientCallback->setActiveServicesCallback(activeServicesCallback);
}
} // namespace details
@@ -280,9 +287,9 @@ void LazyServiceRegistrar::reRegister() {
mImpl->reRegister();
}
-void LazyServiceRegistrar::setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback) {
- mImpl->setActiveServicesCountCallback(activeServicesCountCallback);
+void LazyServiceRegistrar::setActiveServicesCallback(
+ const std::function<bool(bool)>& activeServicesCallback) {
+ mImpl->setActiveServicesCallback(activeServicesCallback);
}
} // namespace hardware
diff --git a/transport/include/hidl/HidlLazyUtils.h b/transport/include/hidl/HidlLazyUtils.h
index 44fbcb2..427611b 100644
--- a/transport/include/hidl/HidlLazyUtils.h
+++ b/transport/include/hidl/HidlLazyUtils.h
@@ -44,10 +44,10 @@ class LazyServiceRegistrar {
status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
const std::string& name = "default");
/**
- * Set a callback that is executed when the total number of services with
- * clients changes.
- * The callback takes an argument, which is the number of registered
- * lazy HALs for this process which have clients.
+ * Set a callback that is invoked when the active HAL count (i.e. HALs with clients)
+ * registered with this process drops to zero (or becomes nonzero).
+ * The callback takes a boolean argument, which is 'true' if there is
+ * at least one HAL with clients.
*
* Callback return value:
* - false: Default behavior for lazy HALs (shut down the process if there
@@ -61,8 +61,7 @@ class LazyServiceRegistrar {
*
* This method should be called before 'registerService' to avoid races.
*/
- void setActiveServicesCountCallback(
- const std::function<bool(int)>& activeServicesCountCallback);
+ void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
/**
* Try to unregister all services previously registered with 'registerService'.