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_HARDWARE_BINDER_H 18 #define ANDROID_HARDWARE_BINDER_H 19 20 #include <atomic> 21 #include <stdint.h> 22 #include <hwbinder/IBinder.h> 23 24 // --------------------------------------------------------------------------- 25 namespace android { 26 namespace hardware { 27 28 class BHwBinder : public IBinder 29 { 30 public: 31 BHwBinder(); 32 33 virtual status_t transact( uint32_t code, 34 const Parcel& data, 35 Parcel* reply, 36 uint32_t flags = 0, 37 TransactCallback callback = nullptr); 38 39 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, 40 void* cookie = nullptr, 41 uint32_t flags = 0); 42 43 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, 44 void* cookie = nullptr, 45 uint32_t flags = 0, 46 wp<DeathRecipient>* outRecipient = nullptr); 47 48 virtual void attachObject( const void* objectID, 49 void* object, 50 void* cleanupCookie, 51 object_cleanup_func func); 52 virtual void* findObject(const void* objectID) const; 53 virtual void detachObject(const void* objectID); 54 55 virtual BHwBinder* localBinder(); 56 57 int getMinSchedulingPolicy(); 58 int getMinSchedulingPriority(); 59 60 bool isRequestingSid(); 61 62 protected: 63 virtual ~BHwBinder(); 64 65 virtual status_t onTransact( uint32_t code, 66 const Parcel& data, 67 Parcel* reply, 68 uint32_t flags = 0, 69 TransactCallback callback = nullptr); 70 71 // This must be called before the object is sent to another process. Not thread safe. 72 void setRequestingSid(bool requestSid); 73 74 int mSchedPolicy; // policy to run transaction from this node at 75 // priority [-20..19] for SCHED_NORMAL, [1..99] for SCHED_FIFO/RT 76 int mSchedPriority; 77 private: 78 BHwBinder(const BHwBinder& o); 79 BHwBinder& operator=(const BHwBinder& o); 80 81 class Extras; 82 83 Extras* getOrCreateExtras(); 84 85 std::atomic<Extras*> mExtras; 86 void* mReserved0; 87 }; 88 89 // --------------------------------------------------------------------------- 90 91 class BpHwRefBase : public virtual RefBase 92 { 93 protected: 94 explicit BpHwRefBase(const sp<IBinder>& o); 95 virtual ~BpHwRefBase(); 96 virtual void onFirstRef(); 97 virtual void onLastStrongRef(const void* id); 98 virtual bool onIncStrongAttempted(uint32_t flags, const void* id); 99 100 public: remote()101 inline IBinder* remote() const { return mRemote; } 102 103 private: 104 BpHwRefBase(const BpHwRefBase& o); 105 BpHwRefBase& operator=(const BpHwRefBase& o); 106 107 IBinder* const mRemote; 108 RefBase::weakref_type* mRefs; 109 std::atomic<int32_t> mState; 110 }; 111 112 }; // namespace hardware 113 }; // namespace android 114 115 // --------------------------------------------------------------------------- 116 117 #endif // ANDROID_HARDWARE_BINDER_H 118