Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke_mac.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; 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 #include "xptcprivate.h"
00041 
00042 #ifndef XP_MAC
00043 #error "This code is for Macintosh only"
00044 #endif
00045 
00046 extern "C" uint32
00047 invoke_count_words(PRUint32 paramCount, nsXPTCVariant* s)
00048 {
00049     PRUint32 result = 0;
00050     for(PRUint32 i = 0; i < paramCount; i++, s++)
00051     {
00052         if(s->IsPtrData())
00053         {
00054             result++;
00055             continue;
00056         }
00057         switch(s->type)
00058         {
00059         case nsXPTType::T_I8     :
00060         case nsXPTType::T_I16    :
00061         case nsXPTType::T_I32    :
00062             result++;
00063             break;
00064         case nsXPTType::T_I64    :
00065             result+=2;
00066             break;
00067         case nsXPTType::T_U8     :
00068         case nsXPTType::T_U16    :
00069         case nsXPTType::T_U32    :
00070             result++;
00071             break;
00072         case nsXPTType::T_U64    :
00073             result+=2;
00074             break;
00075         case nsXPTType::T_FLOAT  :
00076             result++;
00077             break;
00078         case nsXPTType::T_DOUBLE :
00079             result+=2;
00080             break;
00081         case nsXPTType::T_BOOL   :
00082         case nsXPTType::T_CHAR   :
00083         case nsXPTType::T_WCHAR  :
00084             result++;
00085             break;
00086         default:
00087             // all the others are plain pointer types
00088             result++;
00089             break;
00090         }
00091     }
00092     return result;
00093 }
00094 
00095 extern "C" void
00096 invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s, double *fprData)
00097 {
00098        PRUint32 fpCount = 0;
00099     for(PRUint32 i = 0; i < paramCount; i++, d++, s++)
00100     {
00101         if(s->IsPtrData())
00102         {
00103             *((void**)d) = s->ptr;
00104             continue;
00105         }
00106         switch(s->type)
00107         {
00108         case nsXPTType::T_I8     : *((PRInt32*) d) = s->val.i8;          break;
00109         case nsXPTType::T_I16    : *((PRInt32*) d) = s->val.i16;         break;
00110         case nsXPTType::T_I32    : *((PRInt32*) d) = s->val.i32;         break;
00111         case nsXPTType::T_I64    : *((PRInt64*) d) = s->val.i64; d++;    break;
00112         case nsXPTType::T_U8     : *((PRUint32*) d) = s->val.u8;          break;
00113         case nsXPTType::T_U16    : *((PRUint32*)d) = s->val.u16;         break;
00114         case nsXPTType::T_U32    : *((PRUint32*)d) = s->val.u32;         break;
00115         case nsXPTType::T_U64    : *((PRUint64*)d) = s->val.u64; d++;    break;
00116         case nsXPTType::T_FLOAT  : *((float*)   d) = s->val.f;
00117                                if (fpCount < 13)
00118                                     fprData[fpCount++] = s->val.f;
00119                                break;
00120         case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;
00121                                if (fpCount < 13)
00122                                    fprData[fpCount++] = s->val.d;
00123                                break;
00124         case nsXPTType::T_BOOL   : *((PRBool*)  d) = s->val.b;           break;
00125         case nsXPTType::T_CHAR   : *((PRInt32*)    d) = s->val.c;        break;
00126         case nsXPTType::T_WCHAR  : *((PRUint32*) d) = s->val.wc;         break;
00127         default:
00128             // all the others are plain pointer types
00129             *((void**)d) = s->val.p;
00130             break;
00131         }
00132     }
00133 }
00134 
00135 #pragma export on
00136 
00137 extern "C" nsresult _XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00138                    PRUint32 paramCount, nsXPTCVariant* params);
00139 
00140 extern "C"
00141 XPTC_PUBLIC_API(nsresult)
00142 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00143                    PRUint32 paramCount, nsXPTCVariant* params)
00144 {
00145     return _XPTC_InvokeByIndex(that, methodIndex, paramCount, params);
00146 }    
00147 
00148 #pragma export off