Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_alpha.cpp
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) 1998
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 /* Platform specific code to invoke XPCOM methods on native objects */
00039 
00040 /* contributed by bob meader <bob@guiduck.com> */
00041 
00042 #include "xptcprivate.h"
00043 
00044 extern "C" uint32
00045 invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00046 {
00047     return(paramCount*2);
00048 }
00049 
00050 extern "C" void
00051 invoke_copy_to_stack(PRUint64* d, PRUint32 paramCount,
00052                      nsXPTCVariant* s, PRUint64 *regs)
00053 {
00054 #define N_ARG_REGS       5       /* 6 regs minus 1 for "this" ptr */
00055 
00056     for (PRUint32 i = 0; i < paramCount; i++, s++)
00057     {
00058         if (s->IsPtrData()) {
00059             if (i < N_ARG_REGS)
00060                regs[i] = (PRUint32)s->ptr;
00061             else
00062                *((PRUint32*)d++) = (PRUint32)s->ptr;
00063             continue;
00064         }
00065         switch (s->type) {
00066         //
00067         // signed types first
00068         //
00069         case nsXPTType::T_I8:
00070            if (i < N_ARG_REGS)
00071               ((PRInt64*)regs)[i] = s->val.i8;
00072            else
00073               *((PRInt8 *)d++) = s->val.i8;
00074            break;
00075         case nsXPTType::T_I16:
00076            if (i < N_ARG_REGS)
00077               ((PRInt64*)regs)[i] = s->val.i16;
00078            else
00079               *((PRInt16 *)d++) = s->val.i16;
00080            break;
00081         case nsXPTType::T_I32:
00082            if (i < N_ARG_REGS)
00083               ((PRInt64*)regs)[i] = s->val.i32;
00084            else
00085               *((PRUint32*)d++) = s->val.i32;
00086            break;
00087         case nsXPTType::T_I64:
00088            if (i < N_ARG_REGS)
00089               ((PRInt64*)regs)[i] = s->val.i64;
00090            else
00091               *((PRInt64*)d++) = s->val.i64;
00092            break;
00093         //
00094         // unsigned types next
00095         //
00096         case nsXPTType::T_U8:
00097            if (i < N_ARG_REGS)
00098               regs[i] = s->val.u8;
00099            else
00100               *((PRUint8 *)d++) = s->val.u8;
00101            break;
00102         case nsXPTType::T_U16:
00103            if (i < N_ARG_REGS)
00104               regs[i] = s->val.u16;
00105            else
00106               *((PRUint16 *)d++) = s->val.u16;
00107            break;
00108         case nsXPTType::T_U32:
00109            if (i < N_ARG_REGS)
00110               regs[i] = s->val.u32;
00111            else
00112               *((PRUint32*)d++) = s->val.u32;
00113            break;
00114         case nsXPTType::T_U64:
00115            if (i < N_ARG_REGS)
00116               regs[i] = s->val.u64;
00117            else
00118               *((PRUint64*)d++) = s->val.u64;
00119            break;
00120         case nsXPTType::T_FLOAT:
00121            if (i < N_ARG_REGS)
00122               ((double*)regs)[i] = s->val.f;
00123            else
00124               *((float*)d++) = s->val.f;
00125            break;
00126         case nsXPTType::T_DOUBLE:
00127            if (i < N_ARG_REGS)
00128               ((double*)regs)[i] = s->val.d;
00129            else
00130               *((double*)d++) = s->val.d;
00131            break;
00132         case nsXPTType::T_BOOL:
00133            if (i < N_ARG_REGS)
00134               regs[i] = s->val.b;
00135            else
00136               *((PRBool*)d++) = s->val.b;
00137            break;
00138         case nsXPTType::T_CHAR:
00139            if (i < N_ARG_REGS)
00140               regs[i] = s->val.c;
00141            else
00142               *((char*)d++) = s->val.c;
00143            break;
00144         case nsXPTType::T_WCHAR:
00145            if (i < N_ARG_REGS)
00146               regs[i] = s->val.wc;
00147            else
00148               *((wchar_t*)d++) = s->val.wc;
00149            break;
00150         default:
00151            // all the others are plain pointer types
00152            if (i < N_ARG_REGS)
00153               regs[i] = (PRUint32)s->val.p;
00154            else
00155               *((PRUint32*)d++) = (PRUint32)s->val.p;
00156            break;
00157         }
00158     }
00159 }
00160 
00161 extern "C" nsresult XPTC__InvokebyIndex(nsISupports* that, PRUint32 methodIndex,
00162                    PRUint32 paramCount, nsXPTCVariant* params);
00163 
00164 extern "C"
00165 XPTC_PUBLIC_API(nsresult)
00166 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00167                    PRUint32 paramCount, nsXPTCVariant* params)
00168 {
00169     return XPTC__InvokebyIndex(that, methodIndex, paramCount, params);
00170 }
00171