libhidl: add withDefault
Shorthand way to provide default values for HIDL calls.
Fixes: 37088970
Test: libhidl_test
Change-Id: If91cfb774fa76314aeec334fbc2b18ea790912c4
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index a04cf77..9ee80ea 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -195,6 +195,9 @@
return mVal;
}
+ T withDefault(T t) {
+ return isOk() ? mVal : t;
+ }
};
template<typename T> class Return<sp<T>> : public details::return_status {
@@ -220,6 +223,10 @@
assertOk();
return mVal;
}
+
+ sp<T> withDefault(sp<T> t) {
+ return isOk() ? mVal : t;
+ }
};