Go to the documentation of this file.00001 #if !defined(HFILE_libbinder) && ANDROID_VER>=400
00002 #define HFILE_libbinder
00003
00004 #include "libutils.h"
00005
00006 namespace android {
00007
00008 class BBinder;
00009 class BpBinder;
00010 class IInterface;
00011 class Parcel;
00012 template <class TYPE> class Vector;
00013
00014
00015 class ProcessState : public virtual RefBase{
00016 public:
00017 static sp<ProcessState> self();
00018 void startThreadPool();
00019 };
00020
00021
00022 class IPCThreadState {
00023 public:
00024 static IPCThreadState* self();
00025 void joinThreadPool(bool isMain = true);
00026 };
00027
00028
00029 class IBinder : public virtual RefBase {
00030 public:
00031 class DeathRecipient : public virtual RefBase {
00032 public:
00033 virtual void binderDied(const wp<IBinder>& who) = 0;
00034 };
00035 typedef void (*object_cleanup_func)(const void* id, void* obj, void* cleanupCookie);
00036 IBinder();
00037 virtual sp<IInterface> queryLocalInterface(const String16& descriptor);
00038 virtual const String16& getInterfaceDescriptor() const = 0;
00039 virtual bool isBinderAlive() const = 0;
00040 virtual status_t pingBinder() = 0;
00041 virtual status_t dump(int fd, const Vector<String16>& args) = 0;
00042 virtual status_t transact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) = 0;
00043 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, void* cookie = NULL, uint32_t flags = 0) = 0;
00044 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, void* cookie = NULL, uint32_t flags = 0, wp<DeathRecipient>* outRecipient = NULL) = 0;
00045 virtual bool checkSubclass(const void* subclassID) const;
00046 virtual void attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) = 0;
00047 virtual void* findObject(const void* objectID) const = 0;
00048 virtual void detachObject(const void* objectID) = 0;
00049 virtual BBinder* localBinder();
00050 virtual BpBinder* remoteBinder();
00051 protected:
00052 virtual ~IBinder();
00053 };
00054
00055
00056 class BBinder : public IBinder {
00057 public:
00058 BBinder();
00059 virtual const String16& getInterfaceDescriptor() const;
00060 virtual bool isBinderAlive() const;
00061 virtual status_t pingBinder();
00062 virtual status_t dump(int fd, const Vector<String16>& args);
00063 virtual status_t transact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
00064 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, void* cookie = NULL, uint32_t flags = 0);
00065 virtual status_t unlinkToDeath(const wp<DeathRecipient>& recipient, void* cookie = NULL, uint32_t flags = 0, wp<DeathRecipient>* outRecipient = NULL);
00066 virtual void attachObject(const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func);
00067 virtual void* findObject(const void* objectID) const;
00068 virtual void detachObject(const void* objectID);
00069 virtual BBinder* localBinder();
00070 protected:
00071 virtual ~BBinder();
00072 virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
00073 private:
00074 void* mExtras;
00075 void* mReserved0;
00076 };
00077
00078
00079 class IInterface : public virtual RefBase {
00080 public:
00081 IInterface();
00082 protected:
00083 virtual ~IInterface();
00084 virtual IBinder* onAsBinder() = 0;
00085 };
00086
00087 template<typename INTERFACE> class BnInterface : public INTERFACE, public BBinder {
00088 public:
00089 virtual sp<IInterface> queryLocalInterface(const String16& _descriptor) { return (_descriptor == INTERFACE::getInterfaceDescriptor()) ? this : NULL; }
00090 virtual const String16& getInterfaceDescriptor() const { return INTERFACE::getInterfaceDescriptor(); }
00091 protected:
00092 virtual IBinder* onAsBinder() { return this; }
00093 };
00094
00095 class IServiceManager : public IInterface {
00096 public:
00097 virtual const String16& getInterfaceDescriptor() const;
00098 virtual ~IServiceManager();
00099
00100 virtual sp<IBinder> getService( const String16& name) const = 0;
00101 virtual sp<IBinder> checkService( const String16& name) const = 0;
00102 virtual status_t addService( ) = 0;
00103 virtual void listServices() = 0;
00104 };
00105
00106 sp<IServiceManager> defaultServiceManager();
00107
00108
00109 class Parcel {
00110 public:
00111 Parcel();
00112 ~Parcel();
00113 const uint8_t* data() const;
00114 size_t dataSize() const;
00115 size_t dataPosition() const;
00116 size_t dataAvail() const;
00117 size_t dataCapacity() const;
00118 status_t writeInterfaceToken(const String16& interface);
00119 status_t writeInt32(int32_t val);
00120 status_t writeStrongBinder(const sp<IBinder>& val);
00121 status_t read(void* outData, size_t len) const;
00122 const void* readInplace(size_t len) const;
00123 int32_t readInt32() const;
00124 private:
00125 char _data[sizeof(void*)*32];
00126 };
00127
00128 }
00129
00130 #endif //end of lib