の実装remote
は簡単です:
class BpRefBase : public virtual RefBase
{
protected:
BpRefBase(const sp<IBinder>& o);
virtual ~BpRefBase();
virtual void onFirstRef();
virtual void onLastStrongRef(const void* id);
virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
inline IBinder* remote() { return mRemote; }
inline IBinder* remote() const { return mRemote; }
private:
BpRefBase(const BpRefBase& o);
BpRefBase& operator=(const BpRefBase& o);
IBinder* const mRemote;
RefBase::weakref_type* mRefs;
volatile int32_t mState;
};
はServiceManager
、登録されたすべてのサービスを管理します。その仕組みについては、既存の回答を確認してください。getService
からの場合、そのサービスを表すオブジェクトServiceManager
が返され、このオブジェクトが に配置されます。それがあなたのリモコンです。次に、それを使用して、実際の でバインダー トランザクションを開始できます。IBinder
IBinder
BpInterface
BpInterface
service(BnInterface)
template<typename INTERFACE>
class BpInterface : public INTERFACE, public BpRefBase
{
public:
BpInterface(const sp<IBinder>& remote);
protected:
virtual IBinder* onAsBinder();
};
すべておなじみBpXXX
のようBpCamera
に、BpCameraService
から拡張しBpInterface
ます。