Back to index

lightning-sunbird  0.9+nobinonly
nsJavaXPTCStub.h
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 Java XPCOM Bindings.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * IBM Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2005
00019  * IBM Corporation. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Javier Pedemonte (jhpedemonte@gmail.com)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * 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 #ifndef _nsJavaXPTCStub_h_
00039 #define _nsJavaXPTCStub_h_
00040 
00041 #include "xptcall.h"
00042 #include "jni.h"
00043 #include "nsVoidArray.h"
00044 #include "nsIInterfaceInfo.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsWeakReference.h"
00047 #include "nsJavaXPTCStubWeakRef.h"
00048 
00049 
00050 #define NS_JAVAXPTCSTUB_IID \
00051 {0x88dd8130, 0xebe6, 0x4431, {0x9d, 0xa7, 0xe6, 0xb7, 0x54, 0x74, 0xfb, 0x21}}
00052 
00053 class nsJavaXPTCStub : public nsXPTCStubBase,
00054                        public nsSupportsWeakReference
00055 {
00056   friend class nsJavaXPTCStubWeakRef;
00057 
00058 public:
00059   NS_DECL_ISUPPORTS
00060   NS_DECL_NSISUPPORTSWEAKREFERENCE
00061   NS_DEFINE_STATIC_IID_ACCESSOR(NS_JAVAXPTCSTUB_IID)
00062 
00063   nsJavaXPTCStub(jobject aJavaObject, nsIInterfaceInfo *aIInfo);
00064 
00065   virtual ~nsJavaXPTCStub();
00066 
00067   // return a refcounted pointer to the InterfaceInfo for this object
00068   // NOTE: on some platforms this MUST not fail or we crash!
00069   NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo **aInfo);
00070 
00071   // call this method and return result
00072   NS_IMETHOD CallMethod(PRUint16 aMethodIndex,
00073                         const nsXPTMethodInfo *aInfo,
00074                         nsXPTCMiniVariant *aParams);
00075 
00076   // getter for mJavaObject
00077   jobject GetJavaObject();
00078 
00079   // Deletes the strong global ref for the Java object, so it can be garbage
00080   // collected if necessary.  See DestroyXPTCMappingEnum().
00081   void DeleteStrongRef();
00082 
00083 private:
00084   NS_IMETHOD_(nsrefcnt) AddRefInternal();
00085   NS_IMETHOD_(nsrefcnt) ReleaseInternal();
00086 
00087   // Deletes this object and its members.  Called by ReleaseInternal() and
00088   // ReleaseWeakRef().
00089   void Destroy();
00090 
00091   // When a nsJavaXPTCStubWeakRef associated with this object is released, it
00092   // calls this function to let this object know that there is one less weak
00093   // ref.  If there are no more weakrefs referencing this object, and no one
00094   // holds a strong ref, then this function takes care of deleting the object.
00095   void ReleaseWeakRef();
00096 
00097   // returns a weak reference to a child supporting the specified interface
00098   nsJavaXPTCStub * FindStubSupportingIID(const nsID &aIID);
00099 
00100   // returns true if this stub supports the specified interface
00101   PRBool SupportsIID(const nsID &aIID);
00102 
00103   nsresult SetupJavaParams(const nsXPTParamInfo &aParamInfo,
00104                            const nsXPTMethodInfo* aMethodInfo,
00105                            PRUint16 aMethodIndex,
00106                            nsXPTCMiniVariant* aDispatchParams,
00107                            nsXPTCMiniVariant &aVariant,
00108                            jvalue &aJValue, nsACString &aMethodSig);
00109   nsresult GetRetvalSig(const nsXPTParamInfo* aParamInfo,
00110                         const nsXPTMethodInfo* aMethodInfo,
00111                         PRUint16 aMethodIndex,
00112                         nsXPTCMiniVariant* aDispatchParams,
00113                         nsACString &aRetvalSig);
00114   nsresult FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
00115                               const nsXPTMethodInfo* aMethodInfo,
00116                               PRUint16 aMethodIndex,
00117                               nsXPTCMiniVariant* aDispatchParams,
00118                               nsXPTCMiniVariant &aVariant,
00119                               jvalue &aJValue);
00120   nsresult SetXPCOMRetval();
00121 
00122   jobject                     mJavaWeakRef;
00123   jobject                     mJavaStrongRef;
00124   jint                        mJavaRefHashCode;
00125   nsCOMPtr<nsIInterfaceInfo>  mIInfo;
00126 
00127   nsVoidArray     mChildren; // weak references (cleared by the children)
00128   nsJavaXPTCStub *mMaster;   // strong reference
00129 
00130   nsAutoRefCnt    mWeakRefCnt;  // count for number of associated weak refs
00131 };
00132 
00133 #endif // _nsJavaXPTCStub_h_