Back to index

lightning-sunbird  0.9+nobinonly
xptcinvokece.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 Reflect
00015  *
00016  * The Initial Developer of the Original Code is John Wolfe
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 /* Platform specific code to invoke XPCOM methods on native objects */
00037 
00038 #include "xptcprivate.h"
00039 
00040 extern "C" nsresult
00041 asmXPTC_InvokeByIndex( nsISupports* that,
00042                        PRUint32 methodIndex,
00043                                       PRUint32 paramCount,
00044                                       nsXPTCVariant* params,
00045                                       PRUint32 pfn_CopyToStack,
00046                                       PRUint32 pfn_CountWords);  
00047 
00048 // NOTE: This does the actual copying into the stack - based upon the
00049 // pointer "d" -- which is placed at the lowest location on the block
00050 // of memory that has been allocated on the stack
00051 
00052 extern "C" static void
00053 invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
00054 {
00055   for(; paramCount > 0; paramCount--, d++, s++)
00056   {
00057     if(s->IsPtrData())
00058     {
00059       *((void**)d) = s->ptr;
00060       continue;
00061     }
00062     switch(s->type)
00063     {
00064       case nsXPTType::T_I8     : *((PRInt8*)  d) = s->val.i8;          break;
00065       case nsXPTType::T_I16    : *((PRInt16*) d) = s->val.i16;         break;
00066       case nsXPTType::T_I32    : *((PRInt32*) d) = s->val.i32;         break;
00067       case nsXPTType::T_I64    : *((PRInt64*) d) = s->val.i64; d++;    break;
00068       case nsXPTType::T_U8     : *((PRUint8*) d) = s->val.u8;          break;
00069       case nsXPTType::T_U16    : *((PRUint16*)d) = s->val.u16;         break;
00070       case nsXPTType::T_U32    : *((PRUint32*)d) = s->val.u32;         break;
00071       case nsXPTType::T_U64    : *((PRUint64*)d) = s->val.u64; d++;    break;
00072       case nsXPTType::T_FLOAT  : *((float*)   d) = s->val.f;           break;
00073       case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;    break;
00074       case nsXPTType::T_BOOL   : *((PRBool*)  d) = s->val.b;           break;
00075       case nsXPTType::T_CHAR   : *((char*)    d) = s->val.c;           break;
00076       case nsXPTType::T_WCHAR  : *((wchar_t*) d) = s->val.wc;          break;
00077       default:
00078         // all the others are plain pointer types
00079         *((void**)d) = s->val.p;
00080         break;
00081     }
00082   }
00083 }
00084 
00085 
00086 extern "C" static uint32
00087 invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00088 {
00089   uint32 nCnt = 0;
00090   
00091   for(; paramCount > 0; paramCount--, s++)
00092   {
00093     if(s->IsPtrData())
00094     {
00095       nCnt++;
00096       continue;
00097     }
00098     switch(s->type)
00099     {
00100       case nsXPTType::T_I64    : 
00101       case nsXPTType::T_U64    : 
00102       case nsXPTType::T_DOUBLE : 
00103         nCnt += 2;
00104         break;
00105         
00106       case nsXPTType::T_I8     : 
00107       case nsXPTType::T_I16    : 
00108       case nsXPTType::T_I32    : 
00109       case nsXPTType::T_U8     : 
00110       case nsXPTType::T_U16    : 
00111       case nsXPTType::T_U32    : 
00112       case nsXPTType::T_FLOAT  : 
00113       case nsXPTType::T_BOOL   : 
00114       case nsXPTType::T_CHAR   : 
00115       case nsXPTType::T_WCHAR  : 
00116       default:
00117         nCnt++;
00118         break;
00119     }
00120   }
00121   
00122   // 4 Bytes for everything that uses 4 bytes or less, 8 bytes for
00123   // everything else.
00124   return nCnt;
00125 }
00126 
00127 
00128 XPTC_PUBLIC_API(nsresult)
00129 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex, PRUint32 paramCount, nsXPTCVariant* params)
00130 {
00131   return asmXPTC_InvokeByIndex(that,
00132                                methodIndex,
00133                                paramCount,
00134                                params,
00135                                (PRUint32) &invoke_copy_to_stack,
00136                                (PRUint32) &invoke_count_words);
00137 }
00138 
00139 
00140 int g_xptcinvokece_marker;
00141