The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 20 | #include <atomic> |
Hans Boehm | 3effaba | 2014-08-12 22:56:00 +0000 | [diff] [blame] | 21 | #include <stdint.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/IBinder.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | |
| 27 | class BBinder : public IBinder |
| 28 | { |
| 29 | public: |
| 30 | BBinder(); |
| 31 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 32 | virtual const String16& getInterfaceDescriptor() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 74 | std::atomic<Extras*> mExtras; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | void* mReserved0; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // --------------------------------------------------------------------------- |
| 79 | |
| 80 | class BpRefBase : public virtual RefBase |
| 81 | { |
| 82 | protected: |
Chih-Hung Hsieh | e3ab0e8 | 2016-09-01 11:44:54 -0700 | [diff] [blame] | 83 | explicit BpRefBase(const sp<IBinder>& o); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 98 | std::atomic<int32_t> mState; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | }; // namespace android |
| 102 | |
| 103 | // --------------------------------------------------------------------------- |
| 104 | |
| 105 | #endif // ANDROID_BINDER_H |