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 = NULL, 41 uint32_t flags = 0); 42 43 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, 44 void* cookie = NULL, 45 uint32_t flags = 0, 46 wp<DeathRecipient>* outRecipient = NULL); 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 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 remote()100 inline IBinder* remote() const { return mRemote; } 101 102 private: 103 BpHwRefBase(const BpHwRefBase& o); 104 BpHwRefBase& operator=(const BpHwRefBase& o); 105 106 IBinder* const mRemote; 107 RefBase::weakref_type* mRefs; 108 std::atomic<int32_t> mState; 109 }; 110 111 }; // namespace hardware 112 }; // namespace android 113 114 // --------------------------------------------------------------------------- 115 116 #endif // ANDROID_HARDWARE_BINDER_H 117