Back to index

lightning-sunbird  0.9+nobinonly
xptcstubsce.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Windows CE Refection Code.
00015  *
00016  * The Initial Developer of the Original Code is Doug Turner.
00017  * Portions created by the Initial Developer are Copyright (C) 2005
00018  * the Initial Developer. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPL"), or
00024  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00025  * in which case the provisions of the GPL or the LGPL are applicable instead
00026  * of those above. If you wish to allow use of your version of this file only
00027  * under the terms of either the GPL or the LGPL, and not to allow others to
00028  * use your version of this file under the terms of the MPL, indicate your
00029  * decision by deleting the provisions above and replace them with the notice
00030  * and other provisions required by the GPL or the LGPL. If you do not delete
00031  * the provisions above, a recipient may use your version of this file under
00032  * the terms of any one of the MPL, the GPL or the LGPL.
00033  *
00034  * ***** END LICENSE BLOCK ***** */
00035 
00036 /* Implement shared vtbl methods. */
00037 
00038 #include "xptcprivate.h"
00039 
00040 #ifndef WIN32
00041 #error "This code is for Win32 only"
00042 #endif
00043 
00044 extern "C" {
00045 
00046 
00047 nsresult __stdcall
00048 PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
00049 {
00050 #define PARAM_BUFFER_COUNT     16
00051 
00052        nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00053        nsXPTCMiniVariant* dispatchParams = NULL;
00054        nsIInterfaceInfo* iface_info = NULL;
00055        const nsXPTMethodInfo* info;
00056        PRUint8 paramCount;
00057        PRUint8 i;
00058        nsresult result = NS_ERROR_FAILURE;
00059 
00060        NS_ASSERTION(self,"no self");
00061 
00062        self->GetInterfaceInfo(&iface_info);
00063        NS_ASSERTION(iface_info,"no interface info");
00064 
00065        iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00066        NS_ASSERTION(info,"no interface info");
00067 
00068        paramCount = info->GetParamCount();
00069 
00070     // setup variant array pointer
00071        if(paramCount > PARAM_BUFFER_COUNT)
00072               dispatchParams = new nsXPTCMiniVariant[paramCount];
00073        else
00074               dispatchParams = paramBuffer;
00075        NS_ASSERTION(dispatchParams,"no place for params");
00076 
00077        PRUint32* ap = args;
00078        for(i = 0; i < paramCount; i++, ap++)
00079        {
00080               const nsXPTParamInfo& param = info->GetParam(i);
00081               const nsXPTType& type = param.GetType();
00082               nsXPTCMiniVariant* dp = &dispatchParams[i];
00083 
00084               if(param.IsOut() || !type.IsArithmetic())
00085               {
00086                      dp->val.p = (void*) *ap;
00087                      continue;
00088               }
00089        // else
00090               switch(type)
00091               {
00092                      case nsXPTType::T_I8     : dp->val.i8  = *((PRInt8*)  ap);       break;
00093                      case nsXPTType::T_I16    : dp->val.i16 = *((PRInt16*) ap);       break;
00094                      case nsXPTType::T_I32    : dp->val.i32 = *((PRInt32*) ap);       break;
00095                      case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00096                      case nsXPTType::T_U8     : dp->val.u8  = *((PRUint8*) ap);       break;
00097                      case nsXPTType::T_U16    : dp->val.u16 = *((PRUint16*)ap);       break;
00098                      case nsXPTType::T_U32    : dp->val.u32 = *((PRUint32*)ap);       break;
00099                      case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00100                      case nsXPTType::T_FLOAT  : dp->val.f   = *((float*)   ap);       break;
00101                      case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00102                      case nsXPTType::T_BOOL   : dp->val.b   = *((PRBool*)  ap);       break;
00103                      case nsXPTType::T_CHAR   : dp->val.c   = *((char*)    ap);       break;
00104                      case nsXPTType::T_WCHAR  : dp->val.wc  = *((wchar_t*) ap);       break;
00105                      default:
00106                             NS_ASSERTION(0, "bad type");
00107                             break;
00108               }
00109        }
00110 
00111        result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00112 
00113        NS_RELEASE(iface_info);
00114 
00115        if(dispatchParams != paramBuffer)
00116               delete [] dispatchParams;
00117 
00118        return result;
00119 }
00120 
00121   
00122 } // extern "C"
00123 
00124 
00125 
00126 // these macros get defined inside xptc_asm_ceppc.asm
00127 #define STUB_ENTRY(n)                               \
00128 nsresult __stdcall asmXPTCStubBase_Stub##n( void ); \
00129                                                     \
00130 XPTC_PUBLIC_API(nsresult)                           \
00131 __stdcall nsXPTCStubBase::Stub##n()                 \
00132 {                                                   \
00133        return asmXPTCStubBase_Stub##n();               \
00134 }                                                   \
00135 
00136 
00137 #define SENTINEL_ENTRY(n)                              \
00138 nsresult __stdcall nsXPTCStubBase::Sentinel##n()       \
00139 {                                                      \
00140     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00141     return NS_ERROR_NOT_IMPLEMENTED;                   \
00142 }                                                      \
00143 
00144 #include "xptcstubsdef.inc"
00145 
00146 
00147 
00148 void xptc_dummy()
00149 {
00150 }