Back to index

lightning-sunbird  0.9+nobinonly
xptcall.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* Public declarations for xptcall. */
00039 
00040 #ifndef xptcall_h___
00041 #define xptcall_h___
00042 
00043 #include "prtypes.h"
00044 #include "nscore.h"
00045 #include "nsISupports.h"
00046 #include "xpt_struct.h"
00047 #include "xptinfo.h"
00048 #include "nsIInterfaceInfo.h"
00049 
00050 /***************************************************************************/
00051 /*
00052  * The linkage of XPTC API functions differs depending on whether the file is
00053  * used within the XPTC library or not.  Any source file within the XPTC
00054  * library should define EXPORT_XPTC_API whereas any client of the library
00055  * should not.
00056  */
00057 #ifdef EXPORT_XPTC_API
00058 # define XPTC_PUBLIC_API(t)   PR_IMPLEMENT(t)
00059 # define XPTC_PUBLIC_DATA(t)  PR_IMPLEMENT_DATA(t)
00060 # define XPTC_EXPORT          NS_EXPORT
00061 #else
00062 # define XPTC_PUBLIC_API(t)   NS_IMPORT t
00063 # define XPTC_PUBLIC_DATA(t)  NS_IMPORT t
00064 # define XPTC_EXPORT          NS_IMPORT
00065 #endif
00066 #define XPTC_FRIEND_API(t)    XPTC_PUBLIC_API(t)
00067 #define XPTC_FRIEND_DATA(t)   XPTC_PUBLIC_DATA(t)
00068 /***************************************************************************/
00069 
00070 struct nsXPTCMiniVariant
00071 {
00072 // No ctors or dtors so that we can use arrays of these on the stack
00073 // with no penalty.
00074     union
00075     {
00076         PRInt8    i8;
00077         PRInt16   i16;
00078         PRInt32   i32;
00079         PRInt64   i64;
00080         PRUint8   u8;
00081         PRUint16  u16;
00082         PRUint32  u32;
00083         PRUint64  u64;
00084         float     f;
00085         double    d;
00086         PRBool    b;
00087         char      c;
00088         PRUnichar wc;
00089         void*     p;
00090     } val;
00091 };
00092 
00093 struct nsXPTCVariant : public nsXPTCMiniVariant
00094 {
00095 // No ctors or dtors so that we can use arrays of these on the stack
00096 // with no penalty.
00097 
00098     // inherits 'val' here
00099     void*     ptr;
00100     nsXPTType type;
00101     PRUint8   flags;
00102 
00103     enum
00104     {
00105         // these are bitflags!
00106         PTR_IS_DATA    = 0x1,  // ptr points to 'real' data in val
00107         VAL_IS_ALLOCD  = 0x2,  // val.p holds alloc'd ptr that must be freed
00108         VAL_IS_IFACE   = 0x4,  // val.p holds interface ptr that must be released
00109         VAL_IS_ARRAY   = 0x8,  // val.p holds a pointer to an array needing cleanup
00110         VAL_IS_DOMSTR  = 0x10, // val.p holds a pointer to domstring needing cleanup
00111         VAL_IS_UTF8STR = 0x20, // val.p holds a pointer to utf8string needing cleanup
00112         VAL_IS_CSTR    = 0x40  // val.p holds a pointer to cstring needing cleanup        
00113     };
00114 
00115     void ClearFlags()         {flags = 0;}
00116     void SetPtrIsData()       {flags |= PTR_IS_DATA;}
00117     void SetValIsAllocated()  {flags |= VAL_IS_ALLOCD;}
00118     void SetValIsInterface()  {flags |= VAL_IS_IFACE;}
00119     void SetValIsArray()      {flags |= VAL_IS_ARRAY;}
00120     void SetValIsDOMString()  {flags |= VAL_IS_DOMSTR;}
00121     void SetValIsUTF8String() {flags |= VAL_IS_UTF8STR;}
00122     void SetValIsCString()    {flags |= VAL_IS_CSTR;}    
00123 
00124     PRBool IsPtrData()       const  {return 0 != (flags & PTR_IS_DATA);}
00125     PRBool IsValAllocated()  const  {return 0 != (flags & VAL_IS_ALLOCD);}
00126     PRBool IsValInterface()  const  {return 0 != (flags & VAL_IS_IFACE);}
00127     PRBool IsValArray()      const  {return 0 != (flags & VAL_IS_ARRAY);}
00128     PRBool IsValDOMString()  const  {return 0 != (flags & VAL_IS_DOMSTR);}
00129     PRBool IsValUTF8String() const  {return 0 != (flags & VAL_IS_UTF8STR);}
00130     PRBool IsValCString()    const  {return 0 != (flags & VAL_IS_CSTR);}    
00131 
00132     void Init(const nsXPTCMiniVariant& mv, const nsXPTType& t, PRUint8 f)
00133     {
00134         type = t;
00135         flags = f;
00136 
00137         if(f & PTR_IS_DATA)
00138         {
00139             ptr = mv.val.p;
00140             val.p = nsnull;
00141         }
00142         else
00143         {
00144             ptr = nsnull;
00145             switch(t.TagPart()) {
00146               case nsXPTType::T_I8:                val.i8  = mv.val.i8;  break;
00147               case nsXPTType::T_I16:               val.i16 = mv.val.i16; break;
00148               case nsXPTType::T_I32:               val.i32 = mv.val.i32; break;
00149               case nsXPTType::T_I64:               val.i64 = mv.val.i64; break;
00150               case nsXPTType::T_U8:                val.u8  = mv.val.u8;  break;
00151               case nsXPTType::T_U16:               val.u16 = mv.val.u16; break;
00152               case nsXPTType::T_U32:               val.u32 = mv.val.u32; break;
00153               case nsXPTType::T_U64:               val.u64 = mv.val.u64; break;
00154               case nsXPTType::T_FLOAT:             val.f   = mv.val.f;   break;
00155               case nsXPTType::T_DOUBLE:            val.d   = mv.val.d;   break;
00156               case nsXPTType::T_BOOL:              val.b   = mv.val.b;   break;
00157               case nsXPTType::T_CHAR:              val.c   = mv.val.c;   break;
00158               case nsXPTType::T_WCHAR:             val.wc  = mv.val.wc;  break;
00159               case nsXPTType::T_VOID:              /* fall through */
00160               case nsXPTType::T_IID:               /* fall through */
00161               case nsXPTType::T_DOMSTRING:         /* fall through */
00162               case nsXPTType::T_CHAR_STR:          /* fall through */
00163               case nsXPTType::T_WCHAR_STR:         /* fall through */
00164               case nsXPTType::T_INTERFACE:         /* fall through */
00165               case nsXPTType::T_INTERFACE_IS:      /* fall through */
00166               case nsXPTType::T_ARRAY:             /* fall through */
00167               case nsXPTType::T_PSTRING_SIZE_IS:   /* fall through */
00168               case nsXPTType::T_PWSTRING_SIZE_IS:  /* fall through */
00169               case nsXPTType::T_UTF8STRING:        /* fall through */
00170               case nsXPTType::T_CSTRING:           /* fall through */              
00171               default:                             val.p   = mv.val.p;   break;
00172             }
00173         }
00174     }
00175 };
00176 
00177 /***************************************************************************/
00178 
00179 #undef  IMETHOD_VISIBILITY
00180 #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
00181 
00182 class XPTC_EXPORT nsXPTCStubBase : public nsISupports
00183 {
00184 public:
00185     // We are going to implement this to force the compiler to generate a 
00186     // vtbl for this class. Since this is overridden in the inheriting class
00187     // we expect it to never be called. 
00188     // *This is needed by the Irix implementation.*
00189     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00190 
00191     // Include generated vtbl stub declarations.
00192     // These are virtual and *also* implemented by this class..
00193 #include "xptcstubsdecl.inc"
00194 
00195     // The following methods must be provided by inheritor of this class.
00196 
00197     // return a refcounted pointer to the InterfaceInfo for this object
00198     // NOTE: on some platforms this MUST not fail or we crash!
00199     NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info) = 0;
00200 
00201     // call this method and return result
00202     NS_IMETHOD CallMethod(PRUint16 methodIndex,
00203                           const nsXPTMethodInfo* info,
00204                           nsXPTCMiniVariant* params) = 0;
00205 };
00206 
00207 #undef  IMETHOD_VISIBILITY
00208 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
00209 
00210 PR_BEGIN_EXTERN_C
00211 
00212 XPTC_PUBLIC_API(nsresult)
00213 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00214                    PRUint32 paramCount, nsXPTCVariant* params);
00215 
00216 // Used to force linking of these obj for the static library into the dll
00217 extern void xptc_dummy();
00218 extern void xptc_dummy2();
00219 
00220 PR_END_EXTERN_C
00221 
00222 #endif /* xptcall_h___ */