Loading libs/binder/ndk/include_ndk/android/binder_interface_utils.h +26 −7 Original line number Original line Diff line number Diff line Loading @@ -37,12 +37,18 @@ namespace ndk { namespace ndk { // analog using std::shared_ptr for RefBase-like semantics /** * analog using std::shared_ptr for internally held refcount */ class SharedRefBase { class SharedRefBase { public: public: SharedRefBase() {} SharedRefBase() {} virtual ~SharedRefBase() {} virtual ~SharedRefBase() {} /** * A shared_ptr must be held to this object when this is called. This must be called once during * the lifetime of this object. */ std::shared_ptr<SharedRefBase> ref() { std::shared_ptr<SharedRefBase> ref() { std::shared_ptr<SharedRefBase> thiz = mThis.lock(); std::shared_ptr<SharedRefBase> thiz = mThis.lock(); Loading @@ -51,6 +57,9 @@ public: return thiz; return thiz; } } /** * Convenience method for a ref (see above) which automatically casts to the desired child type. */ template <typename CHILD> template <typename CHILD> std::shared_ptr<CHILD> ref() { std::shared_ptr<CHILD> ref() { return std::static_pointer_cast<CHILD>(ref()); return std::static_pointer_cast<CHILD>(ref()); Loading @@ -70,13 +79,17 @@ private: std::weak_ptr<SharedRefBase> mThis; std::weak_ptr<SharedRefBase> mThis; }; }; // wrapper analog to IInterface /** * wrapper analog to IInterface */ class ICInterface : public SharedRefBase { class ICInterface : public SharedRefBase { public: public: ICInterface() {} ICInterface() {} virtual ~ICInterface() {} virtual ~ICInterface() {} // This either returns the single existing implementation or creates a new implementation. /** * This either returns the single existing implementation or creates a new implementation. */ virtual SpAIBinder asBinder() = 0; virtual SpAIBinder asBinder() = 0; /** /** Loading @@ -86,7 +99,9 @@ public: virtual bool isRemote() = 0; virtual bool isRemote() = 0; }; }; // wrapper analog to BnInterface /** * implementation of IInterface for server (n = native) */ template <typename INTERFACE> template <typename INTERFACE> class BnCInterface : public INTERFACE { class BnCInterface : public INTERFACE { public: public: Loading @@ -98,8 +113,10 @@ public: bool isRemote() override { return true; } bool isRemote() override { return true; } protected: 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. * 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 SpAIBinder createBinder() = 0; virtual SpAIBinder createBinder() = 0; private: private: Loading @@ -107,7 +124,9 @@ private: ScopedAIBinder_Weak mWeakBinder; ScopedAIBinder_Weak mWeakBinder; }; }; // wrapper analog to BpInterfae /** * implementation of IInterface for client (p = proxy) */ template <typename INTERFACE> template <typename INTERFACE> class BpCInterface : public INTERFACE { class BpCInterface : public INTERFACE { public: public: Loading Loading
libs/binder/ndk/include_ndk/android/binder_interface_utils.h +26 −7 Original line number Original line Diff line number Diff line Loading @@ -37,12 +37,18 @@ namespace ndk { namespace ndk { // analog using std::shared_ptr for RefBase-like semantics /** * analog using std::shared_ptr for internally held refcount */ class SharedRefBase { class SharedRefBase { public: public: SharedRefBase() {} SharedRefBase() {} virtual ~SharedRefBase() {} virtual ~SharedRefBase() {} /** * A shared_ptr must be held to this object when this is called. This must be called once during * the lifetime of this object. */ std::shared_ptr<SharedRefBase> ref() { std::shared_ptr<SharedRefBase> ref() { std::shared_ptr<SharedRefBase> thiz = mThis.lock(); std::shared_ptr<SharedRefBase> thiz = mThis.lock(); Loading @@ -51,6 +57,9 @@ public: return thiz; return thiz; } } /** * Convenience method for a ref (see above) which automatically casts to the desired child type. */ template <typename CHILD> template <typename CHILD> std::shared_ptr<CHILD> ref() { std::shared_ptr<CHILD> ref() { return std::static_pointer_cast<CHILD>(ref()); return std::static_pointer_cast<CHILD>(ref()); Loading @@ -70,13 +79,17 @@ private: std::weak_ptr<SharedRefBase> mThis; std::weak_ptr<SharedRefBase> mThis; }; }; // wrapper analog to IInterface /** * wrapper analog to IInterface */ class ICInterface : public SharedRefBase { class ICInterface : public SharedRefBase { public: public: ICInterface() {} ICInterface() {} virtual ~ICInterface() {} virtual ~ICInterface() {} // This either returns the single existing implementation or creates a new implementation. /** * This either returns the single existing implementation or creates a new implementation. */ virtual SpAIBinder asBinder() = 0; virtual SpAIBinder asBinder() = 0; /** /** Loading @@ -86,7 +99,9 @@ public: virtual bool isRemote() = 0; virtual bool isRemote() = 0; }; }; // wrapper analog to BnInterface /** * implementation of IInterface for server (n = native) */ template <typename INTERFACE> template <typename INTERFACE> class BnCInterface : public INTERFACE { class BnCInterface : public INTERFACE { public: public: Loading @@ -98,8 +113,10 @@ public: bool isRemote() override { return true; } bool isRemote() override { return true; } protected: 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. * 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 SpAIBinder createBinder() = 0; virtual SpAIBinder createBinder() = 0; private: private: Loading @@ -107,7 +124,9 @@ private: ScopedAIBinder_Weak mWeakBinder; ScopedAIBinder_Weak mWeakBinder; }; }; // wrapper analog to BpInterfae /** * implementation of IInterface for client (p = proxy) */ template <typename INTERFACE> template <typename INTERFACE> class BpCInterface : public INTERFACE { class BpCInterface : public INTERFACE { public: public: Loading