IInterface.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_INTERFACE_INTERFACE_H
00014 #define _SUPPORT_INTERFACE_INTERFACE_H
00015 
00021 #include <support/SupportDefs.h>
00022 #include <support/StaticValue.h>
00023 #include <support/Atom.h>
00024 
00025 #include <support/IBinder.h>
00026 
00027 #if _SUPPORTS_NAMESPACE
00028 namespace palmos {
00029 namespace support {
00030 #endif
00031 
00036 // Forward declare the core binder API (defined in IBinder.h).
00037 class SValue;
00038 class IBinder;
00039 
00040 /**************************************************************************************/
00041 
00043 class IInterface : virtual public SAtom
00044 {
00045 public:
00046     
00047                                 IInterface();
00048     
00049             sptr<IBinder>       AsBinder();
00050             sptr<const IBinder> AsBinder() const;
00051 
00052 protected:
00053     virtual                     ~IInterface();
00054 
00055     virtual sptr<IBinder>       AsBinderImpl();
00056     virtual sptr<const IBinder> AsBinderImpl() const;
00057 
00058     typedef sptr<IInterface>    (*instantiate_proxy_func)(const sptr<IBinder>& binder);
00059     
00060     static  sptr<IInterface>    ExecAsInterface(const sptr<IBinder>& binder,
00061                                                 const SValue& descriptor,
00062                                                 instantiate_proxy_func proxy_func,
00063                                                 status_t* out_error = NULL);
00064 
00065     static  sptr<IInterface>    ExecAsInterfaceNoInspect(const sptr<IBinder>& binder,
00066                                                          const SValue& descriptor,
00067                                                          instantiate_proxy_func proxy_func,
00068                                                          status_t* out_error = NULL);
00069 
00070 private:
00071                                 IInterface(const IInterface&);
00072 };
00073 
00074 
00075 /**************************************************************************************/
00076 
00078 template<class IFACE>
00079 sptr<IFACE>
00080 interface_cast(const sptr<IBinder> &b)
00081 {
00082     return IFACE::AsInterface(b);
00083 }
00084 
00086 template<class IFACE>
00087 sptr<IFACE>
00088 interface_cast(const SValue &v)
00089 {
00090     return IFACE::AsInterface(v);
00091 }
00092 
00093 
00094 /**************************************************************************************/
00095 
00097 
00099 #define B_DECLARE_META_INTERFACE(iname)                                                                     \
00100                                                                                                             \
00101         static  const BNS(::palmos::support::) SValue&                                                      \
00102             Descriptor();                                                                                   \
00103         static  BNS(::palmos::support::) sptr<I ## iname>                                                   \
00104             AsInterface(const BNS(::palmos::support::) sptr< BNS(::palmos::support::) IBinder> &o,          \
00105                         status_t* out_error = NULL);                                                        \
00106         static  BNS(::palmos::support::) sptr<I ## iname>                                                   \
00107             AsInterface(const BNS(::palmos::support::) SValue &v,                                           \
00108                         status_t* out_error = NULL);                                                        \
00109         static  BNS(::palmos::support::) sptr<I ## iname>                                                   \
00110             AsInterfaceNoInspect(const BNS(::palmos::support::) sptr< BNS(::palmos::support::) IBinder> &o, \
00111                                  status_t* out_error = NULL);                                               \
00112         static  BNS(::palmos::support::) sptr<I ## iname>                                                   \
00113             AsInterfaceNoInspect(const BNS(::palmos::support::) SValue &v,                                  \
00114                                  status_t* out_error = NULL);                                               \
00115 
00116 
00118 #if _SUPPORTS_NAMESPACE
00119 } } // namespace palmos::support
00120 #endif
00121 
00122 #endif /* _SUPPORT_INTERFACE_INTERFACE_H */