Back to index

lightning-sunbird  0.9+nobinonly
nsOS2VACLegacy.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 the Mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * InnoTek Systemberatung GmbH.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *    InnoTek Systemberatung GmbH / Knut St. Osmundsen
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /*
00040  * This module contains wrappers for a handful of XPCOM methods which someone
00041  * have been so kind as to link their plugins against. This module will only
00042  * provide the minimum of what necessary to make legacy plugins work with 
00043  * the GCC based mozilla. Luckily this only means the IBM oji JAVA plugins.
00044  *
00045  * Actually, I haven't seen npoji6 calling any of these yet.
00046  */
00047  
00048 /*******************************************************************************
00049 *   Defined Constants And Macros                                               *
00050 *******************************************************************************/
00052 /* @{ */
00054 #define VFT_VAC365          1
00055 
00056 #define VFTCALL             _Optlink
00057 
00058 #define VFTFIRST_DECL       unsigned    uFirst[2]
00059 #define VFTFIRST_VAL()      {0, 0},
00060 
00061 #define VFTDELTA_DECL(n)    unsigned    uDelta##n
00062 #define VFTDELTA_VAL()      0,
00063 
00066 /*******************************************************************************
00067 *   Header Files                                                               *
00068 *******************************************************************************/
00069 #include "nscore.h"
00070 #include "nsServiceManagerUtils.h"
00071 
00072  
00073 /*******************************************************************************
00074 *   Structures and Typedefs                                                    *
00075 *******************************************************************************/
00076 #ifndef __cplusplus
00077 typedef struct nsID 
00078 {
00079   PRUint32  m0;
00080   PRUint16  m1;
00081   PRUint16  m2;
00082   PRUint8   m3[8];
00083 } nsID, nsCID, nsIID;
00084 #define REFNSIID const nsIID *
00085 
00086 typedef PRUint32 nsrefcnt;
00087 #endif 
00088 
00089 
00093 typedef struct vftable_nsISupports
00094 {
00095     VFTFIRST_DECL;
00096     nsresult (*VFTCALL QueryInterface)(void *pvThis, REFNSIID aIID, void** aInstancePtr);
00097     VFTDELTA_DECL(QueryInterface);
00098     nsrefcnt (*VFTCALL AddRef)(void *pvThis);
00099     VFTDELTA_DECL(AddRef);
00100     nsrefcnt (*VFTCALL Release)(void *pvThis);
00101     VFTDELTA_DECL(Release);
00102 } VFTnsISupports;
00103 
00107 typedef struct vftable_nsGetServiceByCID_nsCOMPtr_helper
00108 {
00109     VFTFIRST_DECL;
00110     /* virtual nsresult operator()( const nsIID&, void** ) const; */
00111     nsresult (*VFTCALL __operator_paratheses)(void *pvThis, REFNSIID aIID, void** aInstancePtr);
00112     VFTDELTA_DECL(__operator_paratheses);
00113     void *   (*VFTCALL __destructor)(void *pvThis, unsigned __dtorFlags, unsigned __vtt);
00114     VFTDELTA_DECL(__destructor);
00115 } VFTnsGetServiceByCID_nsCOMPtr_helper;
00116 
00120 typedef struct vftable_nsQueryInterface_nsCOMPtr_helper
00121 {
00122     VFTFIRST_DECL;
00123     nsresult (*VFTCALL __operator_paratheses)(void *pvThis, REFNSIID aIID, void** aInstancePtr);
00124     VFTDELTA_DECL(__operator_paratheses);
00125 } VFTnsQueryInterface_nsCOMPtr_helper;
00126 
00127 
00128 
00129 
00133 typedef struct obj_nsISupports
00134 {
00135     VFTnsISupports     *pVFT;
00136 } obj_nsISupports;
00137 
00141 typedef struct obj_nsCOMPtr_base
00142 {
00143     obj_nsISupports    *mRawPtr;
00144 } obj_nsCOMPtr_base;
00145  
00149 typedef struct obj_nsGetServiceByCID_nsCOMPtr_helper
00150 {
00151     VFTnsGetServiceByCID_nsCOMPtr_helper   *pVFT;           /* ?? */
00152     nsID                                   *mCID;           /* const nsCID& */
00153     void                                   *mServiceManager;/* nsCOMPtr<nsIServiceManager> */
00154     nsresult                               *mErrorPtr;
00155 } obj_nsGetServiceByCID_nsCOMPtr_helper;
00156 
00160 typedef struct obj_nsQueryInterface_nsCOMPtr_helper
00161 {
00162     VFTnsQueryInterface_nsCOMPtr_helper    *pVFT;           /* ?? */
00163     obj_nsISupports                        *mRawPtr;        /* const nsCID& */
00164     nsresult                               *mErrorPtr;
00165 } obj_nsQueryInterface_nsCOMPtr_helper;
00166 
00167 
00168 
00169 
00220 extern "C" void * VFTCALL __dt__13nsCOMPtr_baseFv(void *pvThis, unsigned __dtorFlags)
00221 {
00222     obj_nsCOMPtr_base *pThis = (obj_nsCOMPtr_base*)pvThis;
00223 //asm("int $3");
00224     if (pThis->mRawPtr)
00225     {
00226         /* NSCAP_RELEASE(this, mRawPtr); */
00227         pThis->mRawPtr->pVFT->Release((char*)pThis->mRawPtr + pThis->mRawPtr->pVFT->uDeltaRelease);
00228     }
00229 
00230     /* 
00231      * Delete the object...
00232      * (As memtioned before we'll rather leak this.)
00233      */
00234     #if 0
00235     if (!(__dtorFlags & 1))
00236         __dl__FPv(this)
00237     #endif
00238 
00239     return pvThis;
00240 }
00241 
00243 extern "C" void * VFTCALL _dt__13nsCOMPtr_baseFv(void *pvThis, unsigned __dtorFlags)
00244 {
00245     return __dt__13nsCOMPtr_baseFv(pvThis, __dtorFlags);
00246 }
00247 
00248 
00249 
00409 extern "C" nsresult VFTCALL GSBC_COM__operator_paratheses(void *pvThis, REFNSIID aIID, void** aInstancePtr)
00410 {
00411     obj_nsGetServiceByCID_nsCOMPtr_helper *pThis = (obj_nsGetServiceByCID_nsCOMPtr_helper *)pvThis;
00412     nsresult status = NS_ERROR_FAILURE;
00413 //asm("int $3");
00414     
00415     /* For convenience we don't use mServiceManager here because it's a wrapped object. 
00416      * We ASSUME that there is only one service manager floating around.... 
00417      */
00418     nsCOMPtr<nsIServiceManager>     mgr;
00419     NS_GetServiceManager(getter_AddRefs(mgr));
00420     if (mgr)
00421         status = mgr->GetService(*pThis->mCID, aIID, (void**)aInstancePtr);
00422 
00423     if (NS_FAILED(status))
00424         *aInstancePtr = 0;
00425 
00426     if (pThis->mErrorPtr)
00427         *pThis->mErrorPtr = status;
00428     return status;
00429 }
00430 
00462 extern "C" void * VFTCALL GSBC_COM__destructor(void *pvThis, unsigned __dtorFlags, unsigned __vtt)
00463 {
00464     obj_nsGetServiceByCID_nsCOMPtr_helper *pThis = (obj_nsGetServiceByCID_nsCOMPtr_helper *)pvThis;
00465 //asm("int $3");
00466 
00467     /*
00468      * Because previously mentioned issues with VAC heaps, we'll  
00469      * not do anything in here.
00470      * (We will then skip destruction of all parents and such, but 
00471      *  I don't think that will hurt anyone.)
00472      */
00473     __dtorFlags = __dtorFlags;
00474     __vtt = __vtt;
00475     return pThis;
00476 }
00477 
00478 
00493 extern const VFTnsGetServiceByCID_nsCOMPtr_helper _vft17nsGetServiceByCID15nsCOMPtr_helper =
00494 {
00495     VFTFIRST_VAL()
00496     GSBC_COM__operator_paratheses,                          VFTDELTA_VAL()
00497     GSBC_COM__destructor,                                   VFTDELTA_VAL()
00498 };
00499 
00500 
00501 
00597 extern "C" nsresult VFTCALL QI_COM__operator_paratheses(void *pvThis, REFNSIID aIID, void** aInstancePtr)
00598 {
00599     obj_nsQueryInterface_nsCOMPtr_helper *pThis = (obj_nsQueryInterface_nsCOMPtr_helper *)pvThis;
00600     nsresult status = NS_ERROR_NULL_POINTER;
00601 //asm("int $3");
00602 
00603     if (pThis->mRawPtr)
00604     {
00605         status = pThis->mRawPtr->pVFT->QueryInterface(pThis->mRawPtr, aIID, aInstancePtr);
00606         /* don't care about warnings, do we? */
00607     }
00608     
00609     if (pThis->mErrorPtr)
00610         *pThis->mErrorPtr = status;
00611     return status;
00612 }
00613 
00614 
00615 
00628 extern const VFTnsQueryInterface_nsCOMPtr_helper _vft16nsQueryInterface15nsCOMPtr_helper = 
00629 {
00630     VFTFIRST_VAL()
00631     QI_COM__operator_paratheses,                          VFTDELTA_VAL()
00632 };
00633 
00657 extern "C" void VFTCALL assign_assuming_AddRef__13nsCOMPtr_baseFP11nsISupports(void *pvThis, obj_nsISupports *newPtr)
00658 {
00659     obj_nsCOMPtr_base  *pThis = (obj_nsCOMPtr_base *)pvThis;
00660     obj_nsISupports    *oldPtr;
00661      
00662     oldPtr = pThis->mRawPtr;
00663     pThis->mRawPtr = newPtr;
00664     if (oldPtr)
00665     {
00666         /* NSCAP_RELEASE(this, oldPtr); */
00667         pThis->mRawPtr->pVFT->Release(oldPtr + oldPtr->pVFT->uDeltaRelease);
00668     }
00669 }
00670 
00671 
00672 
00673 
00731 extern "C" void VFTCALL assign_from_helper__13nsCOMPtr_baseFRC15nsCOMPtr_helperRC4nsID(
00732     void *pvThis, void * helper, REFNSIID iid)
00733 {
00734     obj_nsCOMPtr_base  *pThis = (obj_nsCOMPtr_base *)pvThis;
00735     obj_nsISupports*    newRawPtr = NULL;
00736     nsresult            status = NS_ERROR_FAILURE;
00737 //asm("int $3");
00738 
00739     /* this may or may not be correct but the layout is the same. */
00740     obj_nsQueryInterface_nsCOMPtr_helper  * pHelper = (obj_nsQueryInterface_nsCOMPtr_helper*)helper;
00741 
00742     /* if ( NS_FAILED( helper(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) ) */
00743     status = pHelper->pVFT->__operator_paratheses((char*)pHelper + pHelper->pVFT->uDelta__operator_paratheses, 
00744                                                    iid, (void**)&newRawPtr);
00745     if (NS_FAILED(status))
00746         newRawPtr = 0;
00747 
00748     /* assign_assuming_AddRef(newRawPtr); */
00749     assign_assuming_AddRef__13nsCOMPtr_baseFP11nsISupports(pThis, newRawPtr);
00750 }
00751 
00752 
00753