1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_BINDER_H 18 #define ANDROID_BINDER_H 19 20 #include <atomic> 21 #include <stdint.h> 22 #include <binder/IBinder.h> 23 24 // --------------------------------------------------------------------------- 25 namespace android { 26 27 class BBinder : public IBinder 28 { 29 public: 30 BBinder(); 31 32 virtual const String16& getInterfaceDescriptor() const; 33 virtual bool isBinderAlive() const; 34 virtual status_t pingBinder(); 35 virtual status_t dump(int fd, const Vector<String16>& args); 36 37 virtual status_t transact( uint32_t code, 38 const Parcel& data, 39 Parcel* reply, 40 uint32_t flags = 0); 41 42 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, 43 void* cookie = NULL, 44 uint32_t flags = 0); 45 46 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, 47 void* cookie = NULL, 48 uint32_t flags = 0, 49 wp<DeathRecipient>* outRecipient = NULL); 50 51 virtual void attachObject( const void* objectID, 52 void* object, 53 void* cleanupCookie, 54 object_cleanup_func func); 55 virtual void* findObject(const void* objectID) const; 56 virtual void detachObject(const void* objectID); 57 58 virtual BBinder* localBinder(); 59 60 protected: 61 virtual ~BBinder(); 62 63 virtual status_t onTransact( uint32_t code, 64 const Parcel& data, 65 Parcel* reply, 66 uint32_t flags = 0); 67 68 private: 69 BBinder(const BBinder& o); 70 BBinder& operator=(const BBinder& o); 71 72 class Extras; 73 74 std::atomic<Extras*> mExtras; 75 void* mReserved0; 76 }; 77 78 // --------------------------------------------------------------------------- 79 80 class BpRefBase : public virtual RefBase 81 { 82 protected: 83 BpRefBase(const sp<IBinder>& o); 84 virtual ~BpRefBase(); 85 virtual void onFirstRef(); 86 virtual void onLastStrongRef(const void* id); 87 virtual bool onIncStrongAttempted(uint32_t flags, const void* id); 88 89 inline IBinder* remote() { return mRemote; } 90 inline IBinder* remote() const { return mRemote; } 91 92 private: 93 BpRefBase(const BpRefBase& o); 94 BpRefBase& operator=(const BpRefBase& o); 95 96 IBinder* const mRemote; 97 RefBase::weakref_type* mRefs; 98 std::atomic<int32_t> mState; 99 }; 100 101 }; // namespace android 102 103 // --------------------------------------------------------------------------- 104 105 #endif // ANDROID_BINDER_H 106