diff options
| author | 2021-11-02 04:37:38 +0000 | |
|---|---|---|
| committer | 2021-11-02 04:37:38 +0000 | |
| commit | c12c7e33a16fc6f05342421afd3f309917e1b196 (patch) | |
| tree | ad8457e676890694a150fd5a131c205bafbfa249 | |
| parent | c9e2a9c27e345a1e40760a6061291cc0d8b75cad (diff) | |
| parent | 83366aef6411b845a4e49c34128f9b5c7aac2857 (diff) | |
Merge "Support IMPLEMENT_META_INTERFACE for nested type" am: 676e9a9ede am: 83366aef64
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1876679
Change-Id: I113bd0c527d939cea02c04aecc5b5500de7daf29
| -rw-r--r-- | libs/binder/include/binder/IInterface.h | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/libs/binder/include/binder/IInterface.h b/libs/binder/include/binder/IInterface.h index ff90b30380..7d14315b01 100644 --- a/libs/binder/include/binder/IInterface.h +++ b/libs/binder/include/binder/IInterface.h @@ -129,48 +129,50 @@ public: \ #endif -#define DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(INTERFACE, NAME)\ - const ::android::StaticString16 \ - I##INTERFACE##_descriptor_static_str16(__IINTF_CONCAT(u, NAME));\ - const ::android::String16 I##INTERFACE::descriptor( \ - I##INTERFACE##_descriptor_static_str16); \ - const ::android::String16& \ - I##INTERFACE::getInterfaceDescriptor() const { \ - return I##INTERFACE::descriptor; \ - } \ - ::android::sp<I##INTERFACE> I##INTERFACE::asInterface( \ - const ::android::sp<::android::IBinder>& obj) \ - { \ - ::android::sp<I##INTERFACE> intr; \ - if (obj != nullptr) { \ - intr = ::android::sp<I##INTERFACE>::cast( \ - obj->queryLocalInterface(I##INTERFACE::descriptor)); \ - if (intr == nullptr) { \ - intr = ::android::sp<Bp##INTERFACE>::make(obj); \ - } \ - } \ - return intr; \ - } \ - std::unique_ptr<I##INTERFACE> I##INTERFACE::default_impl; \ - bool I##INTERFACE::setDefaultImpl(std::unique_ptr<I##INTERFACE> impl)\ - { \ - /* Only one user of this interface can use this function */ \ - /* at a time. This is a heuristic to detect if two different */ \ - /* users in the same process use this function. */ \ - assert(!I##INTERFACE::default_impl); \ - if (impl) { \ - I##INTERFACE::default_impl = std::move(impl); \ - return true; \ - } \ - return false; \ - } \ - const std::unique_ptr<I##INTERFACE>& I##INTERFACE::getDefaultImpl() \ - { \ - return I##INTERFACE::default_impl; \ - } \ - I##INTERFACE::I##INTERFACE() { } \ - I##INTERFACE::~I##INTERFACE() { } \ - +// Macro to be used by both IMPLEMENT_META_INTERFACE and IMPLEMENT_META_NESTED_INTERFACE +#define DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE0(ITYPE, INAME, BPTYPE) \ + const ::android::String16& ITYPE::getInterfaceDescriptor() const { return ITYPE::descriptor; } \ + ::android::sp<ITYPE> ITYPE::asInterface(const ::android::sp<::android::IBinder>& obj) { \ + ::android::sp<ITYPE> intr; \ + if (obj != nullptr) { \ + intr = ::android::sp<ITYPE>::cast(obj->queryLocalInterface(ITYPE::descriptor)); \ + if (intr == nullptr) { \ + intr = ::android::sp<BPTYPE>::make(obj); \ + } \ + } \ + return intr; \ + } \ + std::unique_ptr<ITYPE> ITYPE::default_impl; \ + bool ITYPE::setDefaultImpl(std::unique_ptr<ITYPE> impl) { \ + /* Only one user of this interface can use this function */ \ + /* at a time. This is a heuristic to detect if two different */ \ + /* users in the same process use this function. */ \ + assert(!ITYPE::default_impl); \ + if (impl) { \ + ITYPE::default_impl = std::move(impl); \ + return true; \ + } \ + return false; \ + } \ + const std::unique_ptr<ITYPE>& ITYPE::getDefaultImpl() { return ITYPE::default_impl; } \ + ITYPE::INAME() {} \ + ITYPE::~INAME() {} + +// Macro for an interface type. +#define DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(INTERFACE, NAME) \ + const ::android::StaticString16 I##INTERFACE##_descriptor_static_str16( \ + __IINTF_CONCAT(u, NAME)); \ + const ::android::String16 I##INTERFACE::descriptor(I##INTERFACE##_descriptor_static_str16); \ + DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE0(I##INTERFACE, I##INTERFACE, Bp##INTERFACE) + +// Macro for "nested" interface type. +// For example, +// class Parent .. { class INested .. { }; }; +// DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_NESTED_INTERFACE(Parent, Nested, "Parent.INested") +#define DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_NESTED_INTERFACE(PARENT, INTERFACE, NAME) \ + const ::android::String16 PARENT::I##INTERFACE::descriptor(NAME); \ + DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE0(PARENT::I##INTERFACE, I##INTERFACE, \ + PARENT::Bp##INTERFACE) #define CHECK_INTERFACE(interface, data, reply) \ do { \ |