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 protected: 60 virtual ~BHwBinder(); 61 62 virtual status_t onTransact( uint32_t code, 63 const Parcel& data, 64 Parcel* reply, 65 uint32_t flags = 0, 66 TransactCallback callback = nullptr); 67 int mSchedPolicy; // policy to run transaction from this node at 68 // priority [-20..19] for SCHED_NORMAL, [1..99] for SCHED_FIFO/RT 69 int mSchedPriority; 70 private: 71 BHwBinder(const BHwBinder& o); 72 BHwBinder& operator=(const BHwBinder& o); 73 74 class Extras; 75 76 std::atomic<Extras*> mExtras; 77 void* mReserved0; 78 }; 79 80 // --------------------------------------------------------------------------- 81 82 class BpHwRefBase : public virtual RefBase 83 { 84 protected: 85 BpHwRefBase(const sp<IBinder>& o); 86 virtual ~BpHwRefBase(); 87 virtual void onFirstRef(); 88 virtual void onLastStrongRef(const void* id); 89 virtual bool onIncStrongAttempted(uint32_t flags, const void* id); 90 remote()91 inline IBinder* remote() { return mRemote; } remote()92 inline IBinder* remote() const { return mRemote; } 93 94 private: 95 BpHwRefBase(const BpHwRefBase& o); 96 BpHwRefBase& operator=(const BpHwRefBase& o); 97 98 IBinder* const mRemote; 99 RefBase::weakref_type* mRefs; 100 std::atomic<int32_t> mState; 101 }; 102 103 }; // namespace hardware 104 }; // namespace android 105 106 // --------------------------------------------------------------------------- 107 108 #endif // ANDROID_HARDWARE_BINDER_H 109