RBinder.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_RBINDER_H_
00014 #define _SUPPORT_RBINDER_H_
00015 
00016 #include <support/Autobinder.h>
00017 #include <support/SupportDefs.h>
00018 #include <support/Binder.h>
00019 #include <support/Locker.h>
00020 
00021 #if _SUPPORTS_NAMESPACE
00022 namespace palmos {
00023 namespace osp {
00024 #endif
00025 
00026 #if _SUPPORTS_NAMESPACE
00027 using namespace palmos::support;
00028 #endif
00029 
00030 /**************************************************************************************/
00031 
00032 // Private link flags.
00033 enum {
00034     // Flag bits that will not be used when matching against unlink flags,
00035     // Note: deliberately does NOT include kIsALink.
00036     kPrivateLinkFlagMask    = 0x70000000,
00037 
00038     // This is used in LinkToDeath() for handling notifications to normal links.
00039     kIsALink                = 0x80000000,
00040     // Link is holding a ref on the BBinder.
00041     kLinkHasRef             = 0x40000000    
00042 };
00043 
00044 class BpBinder : public IBinder
00045 {
00046     public:
00047 
00048                                         BpBinder(int32_t handle);
00049         virtual                         ~BpBinder();
00050 
00051                 int32_t                 Handle() { return m_handle; };
00052 
00053         virtual SValue                  Inspect(const sptr<IBinder>& caller,
00054                                                 const SValue &which,
00055                                                 uint32_t flags = 0);
00056         virtual sptr<IInterface>    InterfaceFor(   const SValue &descriptor,
00057                                                     uint32_t flags = 0);
00058         virtual status_t                Link(   const sptr<IBinder>& target,
00059                                                 const SValue &bindings,
00060                                                 uint32_t flags = 0);
00061         virtual status_t                Unlink( const wptr<IBinder>& target,
00062                                                 const SValue &bindings,
00063                                                 uint32_t flags = 0);
00064         virtual status_t                Effect( const SValue &in,
00065                                                 const SValue &inBindings,
00066                                                 const SValue &outBindings,
00067                                                 SValue *out);
00068 
00069         virtual status_t                AutobinderPut(  const BAutobinderDef* def,
00070                                                         const void* value);
00071         virtual status_t                AutobinderGet(  const BAutobinderDef* def,
00072                                                         void* result);
00073         virtual status_t                AutobinderInvoke(   const BAutobinderDef* def,
00074                                                             void** params,
00075                                                             void* result);
00076 
00077 
00078         virtual status_t                Transact(   uint32_t code,
00079                                                     SParcel& data,
00080                                                     SParcel* reply = NULL,
00081                                                     uint32_t flags = 0);
00082         
00083         virtual status_t                LinkToDeath(    const sptr<BBinder>& target,
00084                                                         const SValue &method,
00085                                                         uint32_t flags = 0);
00086         virtual status_t                UnlinkToDeath(  const wptr<BBinder>& target,
00087                                                         const SValue &method,
00088                                                         uint32_t flags = 0);
00089 
00090                 void                    SendObituary();
00091 
00092         virtual bool                    IsBinderAlive() const;
00093         virtual status_t                PingBinder();
00094         
00095         virtual BBinder*                LocalBinder();
00096         virtual BpBinder*               RemoteBinder();
00097     
00098     protected:
00099 
00100         virtual void                    InitAtom();
00101         virtual status_t                FinishAtom(const void* id);
00102         virtual status_t                IncStrongAttempted(uint32_t flags, const void* id);
00103 
00104     private:
00105 
00106                 struct Obituary {
00107                     wptr<BBinder> target;
00108                     SValue method;
00109                     uint32_t flags;
00110                 };
00111 
00112                 void                    report_one_death(const Obituary& obit);
00113 
00114         const   int32_t                 m_handle;
00115 
00116                 SLocker                 m_lock;
00117                 SVector<Obituary>*      m_obituaries;
00118                 bool                    m_alive;
00119     // XXX : FIXME : HACK ALERT!
00120     friend class BProcess;
00121 };
00122 
00123 /**************************************************************************************/
00124 
00125 #if _SUPPORTS_NAMESPACE
00126 } } // namespace palmos::osp
00127 #endif
00128 
00129 #endif  /* _SUPPORT_BINDERIPC_H_ */