| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2005 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_BPBINDER_H | 
 | 18 | #define ANDROID_BPBINDER_H | 
 | 19 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | #include <binder/IBinder.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/KeyedVector.h> | 
 | 22 | #include <utils/threads.h> | 
 | 23 |  | 
 | 24 | // --------------------------------------------------------------------------- | 
 | 25 | namespace android { | 
 | 26 |  | 
 | 27 | class BpBinder : public IBinder | 
 | 28 | { | 
 | 29 | public: | 
 | 30 |                         BpBinder(int32_t handle); | 
 | 31 |  | 
 | 32 |     inline  int32_t     handle() const { return mHandle; } | 
 | 33 |  | 
| Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 34 |     virtual const String16&    getInterfaceDescriptor() const; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |     virtual bool        isBinderAlive() const; | 
 | 36 |     virtual status_t    pingBinder(); | 
 | 37 |     virtual status_t    dump(int fd, const Vector<String16>& args); | 
 | 38 |  | 
 | 39 |     virtual status_t    transact(   uint32_t code, | 
 | 40 |                                     const Parcel& data, | 
 | 41 |                                     Parcel* reply, | 
 | 42 |                                     uint32_t flags = 0); | 
 | 43 |  | 
 | 44 |     virtual status_t    linkToDeath(const sp<DeathRecipient>& recipient, | 
 | 45 |                                     void* cookie = NULL, | 
 | 46 |                                     uint32_t flags = 0); | 
 | 47 |     virtual status_t    unlinkToDeath(  const wp<DeathRecipient>& recipient, | 
 | 48 |                                         void* cookie = NULL, | 
 | 49 |                                         uint32_t flags = 0, | 
 | 50 |                                         wp<DeathRecipient>* outRecipient = NULL); | 
 | 51 |  | 
 | 52 |     virtual void        attachObject(   const void* objectID, | 
 | 53 |                                         void* object, | 
 | 54 |                                         void* cleanupCookie, | 
 | 55 |                                         object_cleanup_func func); | 
 | 56 |     virtual void*       findObject(const void* objectID) const; | 
 | 57 |     virtual void        detachObject(const void* objectID); | 
 | 58 |  | 
 | 59 |     virtual BpBinder*   remoteBinder(); | 
 | 60 |  | 
 | 61 |             status_t    setConstantData(const void* data, size_t size); | 
 | 62 |             void        sendObituary(); | 
 | 63 |  | 
 | 64 |     class ObjectManager | 
 | 65 |     { | 
 | 66 |     public: | 
 | 67 |                     ObjectManager(); | 
 | 68 |                     ~ObjectManager(); | 
 | 69 |  | 
 | 70 |         void        attach( const void* objectID, | 
 | 71 |                             void* object, | 
 | 72 |                             void* cleanupCookie, | 
 | 73 |                             IBinder::object_cleanup_func func); | 
 | 74 |         void*       find(const void* objectID) const; | 
 | 75 |         void        detach(const void* objectID); | 
 | 76 |  | 
 | 77 |         void        kill(); | 
 | 78 |  | 
 | 79 |     private: | 
 | 80 |                     ObjectManager(const ObjectManager&); | 
 | 81 |         ObjectManager& operator=(const ObjectManager&); | 
 | 82 |  | 
 | 83 |         struct entry_t | 
 | 84 |         { | 
 | 85 |             void* object; | 
 | 86 |             void* cleanupCookie; | 
 | 87 |             IBinder::object_cleanup_func func; | 
 | 88 |         }; | 
 | 89 |  | 
 | 90 |         KeyedVector<const void*, entry_t> mObjects; | 
 | 91 |     }; | 
 | 92 |  | 
 | 93 | protected: | 
 | 94 |     virtual             ~BpBinder(); | 
 | 95 |     virtual void        onFirstRef(); | 
 | 96 |     virtual void        onLastStrongRef(const void* id); | 
 | 97 |     virtual bool        onIncStrongAttempted(uint32_t flags, const void* id); | 
 | 98 |  | 
 | 99 | private: | 
 | 100 |     const   int32_t             mHandle; | 
 | 101 |  | 
 | 102 |     struct Obituary { | 
 | 103 |         wp<DeathRecipient> recipient; | 
 | 104 |         void* cookie; | 
 | 105 |         uint32_t flags; | 
 | 106 |     }; | 
 | 107 |  | 
 | 108 |             void                reportOneDeath(const Obituary& obit); | 
| Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 109 |             bool                isDescriptorCached() const; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 |  | 
 | 111 |     mutable Mutex               mLock; | 
 | 112 |             volatile int32_t    mAlive; | 
 | 113 |             volatile int32_t    mObitsSent; | 
 | 114 |             Vector<Obituary>*   mObituaries; | 
 | 115 |             ObjectManager       mObjects; | 
 | 116 |             Parcel*             mConstantData; | 
| Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 117 |     mutable String16            mDescriptorCache; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | }; | 
 | 119 |  | 
 | 120 | }; // namespace android | 
 | 121 |  | 
 | 122 | // --------------------------------------------------------------------------- | 
 | 123 |  | 
 | 124 | #endif // ANDROID_BPBINDER_H |