Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (C) 2008 The Android Open Source Project |
michael@0 | 3 | * |
michael@0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 5 | * you may not use this file except in compliance with the License. |
michael@0 | 6 | * You may obtain a copy of the License at |
michael@0 | 7 | * |
michael@0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 9 | * |
michael@0 | 10 | * Unless required by applicable law or agreed to in writing, software |
michael@0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 13 | * See the License for the specific language governing permissions and |
michael@0 | 14 | * limitations under the License. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | #ifndef ANDROID_IBINDER_H |
michael@0 | 18 | #define ANDROID_IBINDER_H |
michael@0 | 19 | |
michael@0 | 20 | #include <utils/Errors.h> |
michael@0 | 21 | #include <utils/RefBase.h> |
michael@0 | 22 | #include <utils/String16.h> |
michael@0 | 23 | #include <utils/Vector.h> |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | #define B_PACK_CHARS(c1, c2, c3, c4) \ |
michael@0 | 27 | ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4)) |
michael@0 | 28 | |
michael@0 | 29 | // --------------------------------------------------------------------------- |
michael@0 | 30 | namespace android { |
michael@0 | 31 | |
michael@0 | 32 | class BBinder; |
michael@0 | 33 | class BpBinder; |
michael@0 | 34 | class IInterface; |
michael@0 | 35 | class Parcel; |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Base class and low-level protocol for a remotable object. |
michael@0 | 39 | * You can derive from this class to create an object for which other |
michael@0 | 40 | * processes can hold references to it. Communication between processes |
michael@0 | 41 | * (method calls, property get and set) is down through a low-level |
michael@0 | 42 | * protocol implemented on top of the transact() API. |
michael@0 | 43 | */ |
michael@0 | 44 | class IBinder : public virtual RefBase |
michael@0 | 45 | { |
michael@0 | 46 | public: |
michael@0 | 47 | enum { |
michael@0 | 48 | FIRST_CALL_TRANSACTION = 0x00000001, |
michael@0 | 49 | LAST_CALL_TRANSACTION = 0x00ffffff, |
michael@0 | 50 | |
michael@0 | 51 | PING_TRANSACTION = B_PACK_CHARS('_','P','N','G'), |
michael@0 | 52 | DUMP_TRANSACTION = B_PACK_CHARS('_','D','M','P'), |
michael@0 | 53 | INTERFACE_TRANSACTION = B_PACK_CHARS('_', 'N', 'T', 'F'), |
michael@0 | 54 | |
michael@0 | 55 | // Corresponds to TF_ONE_WAY -- an asynchronous call. |
michael@0 | 56 | FLAG_ONEWAY = 0x00000001 |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | IBinder(); |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Check if this IBinder implements the interface named by |
michael@0 | 63 | * @a descriptor. If it does, the base pointer to it is returned, |
michael@0 | 64 | * which you can safely static_cast<> to the concrete C++ interface. |
michael@0 | 65 | */ |
michael@0 | 66 | virtual sp<IInterface> queryLocalInterface(const String16& descriptor); |
michael@0 | 67 | |
michael@0 | 68 | /** |
michael@0 | 69 | * Return the canonical name of the interface provided by this IBinder |
michael@0 | 70 | * object. |
michael@0 | 71 | */ |
michael@0 | 72 | virtual const String16& getInterfaceDescriptor() const = 0; |
michael@0 | 73 | |
michael@0 | 74 | virtual bool isBinderAlive() const = 0; |
michael@0 | 75 | virtual status_t pingBinder() = 0; |
michael@0 | 76 | virtual status_t dump(int fd, const Vector<String16>& args) = 0; |
michael@0 | 77 | |
michael@0 | 78 | virtual status_t transact( uint32_t code, |
michael@0 | 79 | const Parcel& data, |
michael@0 | 80 | Parcel* reply, |
michael@0 | 81 | uint32_t flags = 0) = 0; |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * This method allows you to add data that is transported through |
michael@0 | 85 | * IPC along with your IBinder pointer. When implementing a Binder |
michael@0 | 86 | * object, override it to write your desired data in to @a outData. |
michael@0 | 87 | * You can then call getConstantData() on your IBinder to retrieve |
michael@0 | 88 | * that data, from any process. You MUST return the number of bytes |
michael@0 | 89 | * written in to the parcel (including padding). |
michael@0 | 90 | */ |
michael@0 | 91 | class DeathRecipient : public virtual RefBase |
michael@0 | 92 | { |
michael@0 | 93 | public: |
michael@0 | 94 | virtual void binderDied(const wp<IBinder>& who) = 0; |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | /** |
michael@0 | 98 | * Register the @a recipient for a notification if this binder |
michael@0 | 99 | * goes away. If this binder object unexpectedly goes away |
michael@0 | 100 | * (typically because its hosting process has been killed), |
michael@0 | 101 | * then DeathRecipient::binderDied() will be called with a referene |
michael@0 | 102 | * to this. |
michael@0 | 103 | * |
michael@0 | 104 | * The @a cookie is optional -- if non-NULL, it should be a |
michael@0 | 105 | * memory address that you own (that is, you know it is unique). |
michael@0 | 106 | * |
michael@0 | 107 | * @note You will only receive death notifications for remote binders, |
michael@0 | 108 | * as local binders by definition can't die without you dying as well. |
michael@0 | 109 | * Trying to use this function on a local binder will result in an |
michael@0 | 110 | * INVALID_OPERATION code being returned and nothing happening. |
michael@0 | 111 | * |
michael@0 | 112 | * @note This link always holds a weak reference to its recipient. |
michael@0 | 113 | * |
michael@0 | 114 | * @note You will only receive a weak reference to the dead |
michael@0 | 115 | * binder. You should not try to promote this to a strong reference. |
michael@0 | 116 | * (Nor should you need to, as there is nothing useful you can |
michael@0 | 117 | * directly do with it now that it has passed on.) |
michael@0 | 118 | */ |
michael@0 | 119 | virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, |
michael@0 | 120 | void* cookie = NULL, |
michael@0 | 121 | uint32_t flags = 0) = 0; |
michael@0 | 122 | |
michael@0 | 123 | /** |
michael@0 | 124 | * Remove a previously registered death notification. |
michael@0 | 125 | * The @a recipient will no longer be called if this object |
michael@0 | 126 | * dies. The @a cookie is optional. If non-NULL, you can |
michael@0 | 127 | * supply a NULL @a recipient, and the recipient previously |
michael@0 | 128 | * added with that cookie will be unlinked. |
michael@0 | 129 | */ |
michael@0 | 130 | virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, |
michael@0 | 131 | void* cookie = NULL, |
michael@0 | 132 | uint32_t flags = 0, |
michael@0 | 133 | wp<DeathRecipient>* outRecipient = NULL) = 0; |
michael@0 | 134 | |
michael@0 | 135 | virtual bool checkSubclass(const void* subclassID) const; |
michael@0 | 136 | |
michael@0 | 137 | typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie); |
michael@0 | 138 | |
michael@0 | 139 | virtual void attachObject( const void* objectID, |
michael@0 | 140 | void* object, |
michael@0 | 141 | void* cleanupCookie, |
michael@0 | 142 | object_cleanup_func func) = 0; |
michael@0 | 143 | virtual void* findObject(const void* objectID) const = 0; |
michael@0 | 144 | virtual void detachObject(const void* objectID) = 0; |
michael@0 | 145 | |
michael@0 | 146 | virtual BBinder* localBinder(); |
michael@0 | 147 | virtual BpBinder* remoteBinder(); |
michael@0 | 148 | |
michael@0 | 149 | protected: |
michael@0 | 150 | virtual ~IBinder(); |
michael@0 | 151 | |
michael@0 | 152 | private: |
michael@0 | 153 | }; |
michael@0 | 154 | |
michael@0 | 155 | }; // namespace android |
michael@0 | 156 | |
michael@0 | 157 | // --------------------------------------------------------------------------- |
michael@0 | 158 | |
michael@0 | 159 | #endif // ANDROID_IBINDER_H |