diff options
author | Steven Moreland <smoreland@google.com> | 2018-10-08 14:30:42 -0700 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2018-10-08 15:09:21 -0700 |
commit | 8b4f48a76bed9afdddfd8f49a96f423816eee0e5 (patch) | |
tree | b375040c877e5d80ef988e83ed269b84ae1d9720 | |
parent | 8cdc1d07fee24c246cefba1504261c6032e9fa2e (diff) | |
download | native-8b4f48a76bed9afdddfd8f49a96f423816eee0e5.tar.gz |
libbinder_ndk: rename things according to convention
C++ wrapper namespace 'android' -> 'ndk'
AutoAIBinder -> SpAIBinder (to reflect usage, disambiguate with auto_ptr)
AutoA* -> ScopedA (to reflect usage, disambiguate with auto_ptr
Bug: 112664205
Test: atest android.binder.cts
Change-Id: I84b22572cd9ffcd4e6107337b83290f35d3ad4a7
3 files changed, 54 insertions, 50 deletions
diff --git a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h index 11b1e8eaf5..8855f142a9 100644 --- a/libs/binder/ndk/include_ndk/android/binder_auto_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_auto_utils.h @@ -34,39 +34,39 @@ #include <cstddef> -namespace android { +namespace ndk { /** * Represents one strong pointer to an AIBinder object. */ -class AutoAIBinder { +class SpAIBinder { public: /** * Takes ownership of one strong refcount of binder. */ - explicit AutoAIBinder(AIBinder* binder = nullptr) : mBinder(binder) {} + explicit SpAIBinder(AIBinder* binder = nullptr) : mBinder(binder) {} /** - * Convenience operator for implicitly constructing an AutoAIBinder from nullptr. This is not + * Convenience operator for implicitly constructing an SpAIBinder from nullptr. This is not * explicit because it is not taking ownership of anything. */ - AutoAIBinder(std::nullptr_t) : AutoAIBinder() {} + SpAIBinder(std::nullptr_t) : SpAIBinder() {} /** * This will delete the underlying object if it exists. See operator=. */ - AutoAIBinder(const AutoAIBinder& other) { *this = other; } + SpAIBinder(const SpAIBinder& other) { *this = other; } /** * This deletes the underlying object if it exists. See set. */ - ~AutoAIBinder() { set(nullptr); } + ~SpAIBinder() { set(nullptr); } /** * This takes ownership of a binder from another AIBinder object but it does not affect the * ownership of that other object. */ - AutoAIBinder& operator=(const AutoAIBinder& other) { + SpAIBinder& operator=(const SpAIBinder& other) { AIBinder_incStrong(other.mBinder); set(other.mBinder); return *this; @@ -82,7 +82,7 @@ public: /** * This returns the underlying binder object for transactions. If it is used to create another - * AutoAIBinder object, it should first be incremented. + * SpAIBinder object, it should first be incremented. */ AIBinder* get() const { return mBinder; } @@ -92,7 +92,7 @@ public: * ownership to the object that is put in here. * * Recommended use is like this: - * AutoAIBinder a; // will be nullptr + * SpAIBinder a; // will be nullptr * SomeInitFunction(a.getR()); // value is initialized with refcount * * Other usecases are discouraged. @@ -108,17 +108,17 @@ private: * This baseclass owns a single object, used to make various classes RAII. */ template <typename T, void (*Destroy)(T*)> -class AutoA { +class ScopedA { public: /** * Takes ownership of t. */ - explicit AutoA(T* t = nullptr) : mT(t) {} + explicit ScopedA(T* t = nullptr) : mT(t) {} /** * This deletes the underlying object if it exists. See set. */ - ~AutoA() { set(nullptr); } + ~ScopedA() { set(nullptr); } /** * Takes ownership of t. @@ -144,7 +144,7 @@ public: * ownership to the object that is put in here. * * Recommended use is like this: - * AutoA<T> a; // will be nullptr + * ScopedA<T> a; // will be nullptr * SomeInitFunction(a.getR()); // value is initialized with refcount * * Other usecases are discouraged. @@ -153,12 +153,12 @@ public: T** getR() { return &mT; } // copy-constructing, or move/copy assignment is disallowed - AutoA(const AutoA&) = delete; - AutoA& operator=(const AutoA&) = delete; - AutoA& operator=(AutoA&&) = delete; + ScopedA(const ScopedA&) = delete; + ScopedA& operator=(const ScopedA&) = delete; + ScopedA& operator=(ScopedA&&) = delete; // move-constructing is okay - AutoA(AutoA&&) = default; + ScopedA(ScopedA&&) = default; private: T* mT; @@ -167,27 +167,27 @@ private: /** * Convenience wrapper. See AParcel. */ -class AutoAParcel : public AutoA<AParcel, AParcel_delete> { +class ScopedAParcel : public ScopedA<AParcel, AParcel_delete> { public: /** * Takes ownership of a. */ - explicit AutoAParcel(AParcel* a = nullptr) : AutoA(a) {} - ~AutoAParcel() {} - AutoAParcel(AutoAParcel&&) = default; + explicit ScopedAParcel(AParcel* a = nullptr) : ScopedA(a) {} + ~ScopedAParcel() {} + ScopedAParcel(ScopedAParcel&&) = default; }; /** * Convenience wrapper. See AStatus. */ -class AutoAStatus : public AutoA<AStatus, AStatus_delete> { +class ScopedAStatus : public ScopedA<AStatus, AStatus_delete> { public: /** * Takes ownership of a. */ - explicit AutoAStatus(AStatus* a = nullptr) : AutoA(a) {} - ~AutoAStatus() {} - AutoAStatus(AutoAStatus&&) = default; + explicit ScopedAStatus(AStatus* a = nullptr) : ScopedA(a) {} + ~ScopedAStatus() {} + ScopedAStatus(ScopedAStatus&&) = default; /** * See AStatus_isOk. @@ -198,36 +198,36 @@ public: /** * Convenience wrapper. See AIBinder_DeathRecipient. */ -class AutoAIBinder_DeathRecipient - : public AutoA<AIBinder_DeathRecipient, AIBinder_DeathRecipient_delete> { +class ScopedAIBinder_DeathRecipient + : public ScopedA<AIBinder_DeathRecipient, AIBinder_DeathRecipient_delete> { public: /** * Takes ownership of a. */ - explicit AutoAIBinder_DeathRecipient(AIBinder_DeathRecipient* a = nullptr) : AutoA(a) {} - ~AutoAIBinder_DeathRecipient() {} - AutoAIBinder_DeathRecipient(AutoAIBinder_DeathRecipient&&) = default; + explicit ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient* a = nullptr) : ScopedA(a) {} + ~ScopedAIBinder_DeathRecipient() {} + ScopedAIBinder_DeathRecipient(ScopedAIBinder_DeathRecipient&&) = default; }; /** * Convenience wrapper. See AIBinder_Weak. */ -class AutoAIBinder_Weak : public AutoA<AIBinder_Weak, AIBinder_Weak_delete> { +class ScopedAIBinder_Weak : public ScopedA<AIBinder_Weak, AIBinder_Weak_delete> { public: /** * Takes ownership of a. */ - explicit AutoAIBinder_Weak(AIBinder_Weak* a = nullptr) : AutoA(a) {} - ~AutoAIBinder_Weak() {} - AutoAIBinder_Weak(AutoAIBinder_Weak&&) = default; + explicit ScopedAIBinder_Weak(AIBinder_Weak* a = nullptr) : ScopedA(a) {} + ~ScopedAIBinder_Weak() {} + ScopedAIBinder_Weak(ScopedAIBinder_Weak&&) = default; /** * See AIBinder_Weak_promote. */ - AutoAIBinder promote() { return AutoAIBinder(AIBinder_Weak_promote(get())); } + SpAIBinder promote() { return SpAIBinder(AIBinder_Weak_promote(get())); } }; -} // namespace android +} // namespace ndk #endif // __cplusplus diff --git a/libs/binder/ndk/include_ndk/android/binder_interface_utils.h b/libs/binder/ndk/include_ndk/android/binder_interface_utils.h index d7e1566010..f5c8bce8ae 100644 --- a/libs/binder/ndk/include_ndk/android/binder_interface_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_interface_utils.h @@ -35,7 +35,7 @@ #include <memory> #include <mutex> -namespace android { +namespace ndk { // analog using std::shared_ptr for RefBase-like semantics class SharedRefBase { @@ -68,7 +68,7 @@ public: virtual ~ICInterface() {} // This either returns the single existing implementation or creates a new implementation. - virtual AutoAIBinder asBinder() = 0; + virtual SpAIBinder asBinder() = 0; }; // wrapper analog to BnInterface @@ -78,36 +78,36 @@ public: BnCInterface() {} virtual ~BnCInterface() {} - AutoAIBinder asBinder() override; + SpAIBinder asBinder() override; protected: // This function should only be called by asBinder. Otherwise, there is a possibility of // multiple AIBinder* objects being created for the same instance of an object. - virtual AutoAIBinder createBinder() = 0; + virtual SpAIBinder createBinder() = 0; private: std::mutex mMutex; // for asBinder - AutoAIBinder_Weak mWeakBinder; + ScopedAIBinder_Weak mWeakBinder; }; // wrapper analog to BpInterfae template <typename INTERFACE> class BpCInterface : public INTERFACE { public: - BpCInterface(const AutoAIBinder& binder) : mBinder(binder) {} + BpCInterface(const SpAIBinder& binder) : mBinder(binder) {} virtual ~BpCInterface() {} - AutoAIBinder asBinder() override; + SpAIBinder asBinder() override; private: - AutoAIBinder mBinder; + SpAIBinder mBinder; }; template <typename INTERFACE> -AutoAIBinder BnCInterface<INTERFACE>::asBinder() { +SpAIBinder BnCInterface<INTERFACE>::asBinder() { std::lock_guard<std::mutex> l(mMutex); - AutoAIBinder binder; + SpAIBinder binder; if (mWeakBinder.get() != nullptr) { binder.set(AIBinder_Weak_promote(mWeakBinder.get())); } @@ -120,12 +120,12 @@ AutoAIBinder BnCInterface<INTERFACE>::asBinder() { } template <typename INTERFACE> -AutoAIBinder BpCInterface<INTERFACE>::asBinder() { +SpAIBinder BpCInterface<INTERFACE>::asBinder() { return mBinder; } -#endif // __cplusplus +} // namespace ndk -} // namespace android +#endif // __cplusplus /** @} */ diff --git a/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h b/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h index 7b261d6f98..d3e6caecd7 100644 --- a/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h +++ b/libs/binder/ndk/include_ndk/android/binder_parcel_utils.h @@ -32,6 +32,8 @@ #include <string> +namespace ndk { + /** * Takes a std::string and reallocates it to the specified length. For use with AParcel_readString. * See use below in AParcel_readString. @@ -66,6 +68,8 @@ static inline binder_status_t AParcel_readString(const AParcel* parcel, std::str &stringData); } +} // namespace ndk + #endif // __cplusplus /** @} */ |