2004-09-02 20:34:11 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Java XPCOM Bindings.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* IBM Corporation. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Javier Pedemonte (jhpedemonte@gmail.com)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsJavaXPTCStub.h"
|
|
|
|
#include "nsJavaWrapper.h"
|
|
|
|
#include "nsJavaXPCOMBindingUtils.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsIInterfaceInfoManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
|
|
|
|
|
|
|
|
nsJavaXPTCStub::nsJavaXPTCStub(JNIEnv* aJavaEnv, jobject aJavaObject,
|
2004-10-16 02:07:36 +04:00
|
|
|
nsIInterfaceInfo *aIInfo)
|
2004-09-02 20:34:11 +04:00
|
|
|
: mJavaEnv(aJavaEnv)
|
2005-02-25 00:53:46 +03:00
|
|
|
, mJavaStrongRef(nsnull)
|
2004-09-02 20:34:11 +04:00
|
|
|
, mIInfo(aIInfo)
|
2004-10-16 02:07:36 +04:00
|
|
|
, mMaster(nsnull)
|
2005-02-25 00:53:46 +03:00
|
|
|
, mWeakRefCnt(0)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
mJavaWeakRef = aJavaEnv->NewWeakGlobalRef(aJavaObject);
|
2004-10-07 19:11:34 +04:00
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
2005-02-25 00:53:46 +03:00
|
|
|
nsIID* iid;
|
|
|
|
mIInfo->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
LOG(("+ nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
|
2005-02-25 02:17:36 +03:00
|
|
|
(PRUint32) aJavaEnv->CallIntMethod(aJavaObject, hashCodeMID),
|
|
|
|
(PRUint32) this, iid_str));
|
2005-02-25 00:53:46 +03:00
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
2004-10-07 19:11:34 +04:00
|
|
|
#endif
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsJavaXPTCStub::~nsJavaXPTCStub()
|
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
|
2004-09-15 21:26:55 +04:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
2005-02-25 00:53:46 +03:00
|
|
|
nsJavaXPTCStub::AddRefInternal()
|
2004-09-15 21:26:55 +04:00
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
// If this is the first AddRef call, we create a strong global ref to the
|
|
|
|
// Java object to keep it from being garbage collected.
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
mJavaStrongRef = mJavaEnv->NewGlobalRef(mJavaWeakRef);
|
|
|
|
NS_ASSERTION(mJavaStrongRef != nsnull, "Failed to acquire strong ref");
|
|
|
|
}
|
2004-09-15 21:26:55 +04:00
|
|
|
|
|
|
|
// if this is the master interface
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
|
|
|
NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "nsJavaXPTCStub", sizeof(*this));
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
2005-02-25 00:53:46 +03:00
|
|
|
nsJavaXPTCStub::AddRef()
|
2004-09-15 21:26:55 +04:00
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM_REFCNT
|
|
|
|
nsIID* iid;
|
|
|
|
mIInfo->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) + 1;
|
|
|
|
LOG(("= nsJavaXPTCStub::AddRef (XPCOM=%08x | refcnt = %d | IID=%s)\n",
|
|
|
|
(int) this, refcnt, iid_str));
|
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsJavaXPTCStub* master = mMaster ? mMaster : this;
|
|
|
|
return master->AddRefInternal();
|
|
|
|
}
|
2004-09-15 21:26:55 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsJavaXPTCStub::ReleaseInternal()
|
|
|
|
{
|
2004-09-15 21:26:55 +04:00
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
|
|
NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
|
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "nsJavaXPTCStub");
|
|
|
|
if (mRefCnt == 0) {
|
2005-02-25 00:53:46 +03:00
|
|
|
// If we have a weak ref, we don't delete this object.
|
|
|
|
if (mWeakRefCnt == 0) {
|
|
|
|
mRefCnt = 1; /* stabilize */
|
|
|
|
Destroy();
|
|
|
|
|
|
|
|
// delete strong ref; allows Java object to be garbage collected
|
|
|
|
mJavaEnv->DeleteGlobalRef(mJavaStrongRef);
|
|
|
|
delete this;
|
|
|
|
} else {
|
|
|
|
// delete strong ref; allows Java object to be garbage collected
|
|
|
|
mJavaEnv->DeleteGlobalRef(mJavaStrongRef);
|
|
|
|
}
|
2004-09-15 21:26:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
NS_IMETHODIMP_(nsrefcnt)
|
|
|
|
nsJavaXPTCStub::Release()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_JAVAXPCOM_REFCNT
|
|
|
|
nsIID* iid;
|
|
|
|
mIInfo->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
int refcnt = PRInt32(mMaster ? mMaster->mRefCnt : mRefCnt) - 1;
|
|
|
|
LOG(("= nsJavaXPTCStub::Release (XPCOM=%08x | refcnt = %d | IID=%s)\n",
|
|
|
|
(int) this, refcnt, iid_str));
|
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsJavaXPTCStub* master = mMaster ? mMaster : this;
|
|
|
|
return master->ReleaseInternal();
|
|
|
|
}
|
|
|
|
|
2005-02-25 02:17:36 +03:00
|
|
|
void
|
|
|
|
nsJavaXPTCStub::Destroy()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
nsIID* iid;
|
|
|
|
mIInfo->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
jobject javaObject = mJavaEnv->NewLocalRef(mJavaWeakRef);
|
|
|
|
LOG(("- nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
|
|
|
|
(PRUint32) mJavaEnv->CallIntMethod(javaObject, hashCodeMID),
|
|
|
|
(PRUint32) this, iid_str));
|
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!mMaster) {
|
|
|
|
// delete each child stub
|
|
|
|
for (PRInt32 i = 0; i < mChildren.Count(); i++) {
|
|
|
|
delete (nsJavaXPTCStub*) mChildren[i];
|
|
|
|
}
|
|
|
|
|
2005-03-15 00:18:53 +03:00
|
|
|
if (gJavaXPCOMInitialized) {
|
2005-02-25 02:17:36 +03:00
|
|
|
gJavaToXPTCStubMap->Remove(mJavaEnv, mJavaStrongRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->DeleteWeakGlobalRef(mJavaWeakRef);
|
|
|
|
}
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
void
|
|
|
|
nsJavaXPTCStub::ReleaseWeakRef()
|
|
|
|
{
|
|
|
|
// if this is a child
|
|
|
|
if (mMaster)
|
|
|
|
return mMaster->ReleaseWeakRef();
|
|
|
|
|
|
|
|
--mWeakRefCnt;
|
|
|
|
|
|
|
|
// If there are no more associated weak refs, and no one else holds a strong
|
|
|
|
// ref to this object, then delete it.
|
|
|
|
if (mWeakRefCnt == 0 && mRefCnt == 0) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(nsJavaXPTCStub);
|
|
|
|
mRefCnt = 1; /* stabilize */
|
|
|
|
Destroy();
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-25 02:17:36 +03:00
|
|
|
void
|
|
|
|
nsJavaXPTCStub::DeleteStrongRef()
|
|
|
|
{
|
|
|
|
mJavaEnv->DeleteGlobalRef(mJavaStrongRef);
|
|
|
|
mJavaStrongRef = nsnull;
|
|
|
|
}
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJavaXPTCStub::QueryInterface(const nsID &aIID, void **aInstancePtr)
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("JavaStub::QueryInterface()\n"));
|
2005-01-12 20:59:01 +03:00
|
|
|
*aInstancePtr = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
nsJavaXPTCStub *master = mMaster ? mMaster : this;
|
|
|
|
|
2004-10-18 21:04:29 +04:00
|
|
|
// This helps us differentiate between the help classes.
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsJavaXPTCStub)))
|
|
|
|
{
|
|
|
|
*aInstancePtr = master;
|
|
|
|
NS_ADDREF(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
// always return the master stub for nsISupports
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsISupports)))
|
|
|
|
{
|
2004-10-18 21:04:29 +04:00
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsISupports*,
|
|
|
|
NS_STATIC_CAST(nsXPTCStubBase*, master));
|
2004-09-02 20:34:11 +04:00
|
|
|
NS_ADDREF(master);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-16 01:50:41 +04:00
|
|
|
// All Java objects support weak references
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsISupportsWeakReference)))
|
|
|
|
{
|
2004-10-18 21:04:29 +04:00
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsISupportsWeakReference*, master);
|
2004-09-16 01:50:41 +04:00
|
|
|
NS_ADDREF(master);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
// does any existing stub support the requested IID?
|
|
|
|
nsJavaXPTCStub *stub = master->FindStubSupportingIID(aIID);
|
|
|
|
if (stub)
|
|
|
|
{
|
|
|
|
*aInstancePtr = stub;
|
|
|
|
NS_ADDREF(stub);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query Java object
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("\tCalling Java object queryInterface\n"));
|
2005-02-25 00:53:46 +03:00
|
|
|
jobject javaObject = mJavaEnv->NewLocalRef(mJavaWeakRef);
|
|
|
|
|
2005-01-12 20:59:01 +03:00
|
|
|
jmethodID qiMID = 0;
|
2005-02-25 00:53:46 +03:00
|
|
|
jclass clazz = mJavaEnv->GetObjectClass(javaObject);
|
2005-01-12 20:59:01 +03:00
|
|
|
if (clazz) {
|
|
|
|
char* sig = "(Ljava/lang/String;)Lorg/mozilla/xpcom/nsISupports;";
|
|
|
|
qiMID = mJavaEnv->GetMethodID(clazz, "queryInterface", sig);
|
|
|
|
NS_ASSERTION(qiMID, "Failed to get queryInterface method ID");
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
if (qiMID == 0) {
|
2005-01-12 20:59:01 +03:00
|
|
|
mJavaEnv->ExceptionClear();
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct IID string
|
2005-01-14 03:09:49 +03:00
|
|
|
jstring iid_jstr = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
char* iid_str = aIID.ToString();
|
2005-01-13 19:30:19 +03:00
|
|
|
if (iid_str) {
|
2005-01-14 03:09:49 +03:00
|
|
|
iid_jstr = mJavaEnv->NewStringUTF(iid_str);
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!iid_str || !iid_jstr) {
|
|
|
|
mJavaEnv->ExceptionClear();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
PR_Free(iid_str);
|
|
|
|
|
2005-01-12 20:59:01 +03:00
|
|
|
// call queryInterface method
|
2005-02-25 00:53:46 +03:00
|
|
|
jobject obj = mJavaEnv->CallObjectMethod(javaObject, qiMID, iid_jstr);
|
2005-01-12 20:59:01 +03:00
|
|
|
if (mJavaEnv->ExceptionCheck()) {
|
|
|
|
mJavaEnv->ExceptionClear();
|
|
|
|
return NS_ERROR_FAILURE;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!obj)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
// Get interface info for new java object
|
|
|
|
nsCOMPtr<nsIInterfaceInfoManager> iim = XPTI_GetInterfaceInfoManager();
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> iinfo;
|
|
|
|
nsresult rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
stub = new nsJavaXPTCStub(mJavaEnv, obj, iinfo);
|
|
|
|
if (!stub)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// add stub to the master's list of children, so we can preserve
|
|
|
|
// symmetry in future QI calls. the master will delete each child
|
|
|
|
// when it is destroyed. the refcount of each child is bound to
|
|
|
|
// the refcount of the master. this is done to deal with code
|
|
|
|
// like this:
|
|
|
|
//
|
|
|
|
// nsCOMPtr<nsIBar> bar = ...;
|
|
|
|
// nsIFoo *foo;
|
|
|
|
// {
|
|
|
|
// nsCOMPtr<nsIFoo> temp = do_QueryInterface(bar);
|
|
|
|
// foo = temp;
|
|
|
|
// }
|
|
|
|
// foo->DoStuff();
|
|
|
|
//
|
|
|
|
// while this code is not valid XPCOM (since it is using |foo|
|
|
|
|
// after having called Release on it), such code is unfortunately
|
|
|
|
// very common in the mozilla codebase. the assumption this code
|
|
|
|
// is making is that so long as |bar| is alive, it should be valid
|
|
|
|
// to access |foo| even if the code doesn't own a strong reference
|
|
|
|
// to |foo|! clearly wrong, but we need to support it anyways.
|
|
|
|
|
|
|
|
stub->mMaster = master;
|
|
|
|
master->mChildren.AppendElement(stub);
|
|
|
|
|
|
|
|
*aInstancePtr = stub;
|
|
|
|
NS_ADDREF(stub);
|
|
|
|
return NS_OK;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsJavaXPTCStub::SupportsIID(const nsID &iid)
|
|
|
|
{
|
2004-10-07 02:31:13 +04:00
|
|
|
PRBool match;
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> iter = mIInfo;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(iter->IsIID(&iid, &match)) && match)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> parent;
|
|
|
|
iter->GetParent(getter_AddRefs(parent));
|
|
|
|
iter = parent;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2004-10-07 02:31:13 +04:00
|
|
|
while (iter != nsnull);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJavaXPTCStub *
|
|
|
|
nsJavaXPTCStub::FindStubSupportingIID(const nsID &iid)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mMaster == nsnull, "this is not a master stub");
|
|
|
|
|
|
|
|
if (SupportsIID(iid))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < mChildren.Count(); i++)
|
|
|
|
{
|
|
|
|
nsJavaXPTCStub *child = (nsJavaXPTCStub *) mChildren[i];
|
|
|
|
if (child->SupportsIID(iid))
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJavaXPTCStub::GetInterfaceInfo(nsIInterfaceInfo **aInfo)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*aInfo = mIInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJavaXPTCStub::CallMethod(PRUint16 aMethodIndex,
|
2005-01-12 20:36:11 +03:00
|
|
|
const nsXPTMethodInfo *aMethodInfo,
|
|
|
|
nsXPTCMiniVariant *aParams)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-02-23 23:19:55 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
2004-09-15 21:31:14 +04:00
|
|
|
const char* ifaceName;
|
|
|
|
mIInfo->GetNameShared(&ifaceName);
|
2005-02-25 00:53:46 +03:00
|
|
|
LOG(("---> (Java) %s::%s()\n", ifaceName, aMethodInfo->GetName()));
|
2004-09-15 21:31:14 +04:00
|
|
|
#endif
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2005-02-25 00:53:46 +03:00
|
|
|
jobject javaObject = mJavaEnv->NewLocalRef(mJavaWeakRef);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
nsCAutoString methodSig("(");
|
|
|
|
|
|
|
|
// Create jvalue array to hold Java params
|
|
|
|
PRUint8 paramCount = aMethodInfo->GetParamCount();
|
|
|
|
jvalue* java_params = nsnull;
|
|
|
|
const nsXPTParamInfo* retvalInfo = nsnull;
|
|
|
|
if (paramCount) {
|
|
|
|
java_params = new jvalue[paramCount];
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!java_params)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
|
|
|
|
{
|
|
|
|
const nsXPTParamInfo ¶mInfo = aMethodInfo->GetParam(i);
|
2004-10-27 00:30:01 +04:00
|
|
|
NS_ASSERTION(!paramInfo.IsDipper(), "Dipper!");
|
2004-09-02 20:34:11 +04:00
|
|
|
if (!paramInfo.IsRetval()) {
|
|
|
|
rv = SetupJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
|
|
|
|
aParams[i], java_params[i], methodSig);
|
|
|
|
} else {
|
|
|
|
retvalInfo = ¶mInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "SetupJavaParams failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish method signature
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-01-12 20:36:11 +03:00
|
|
|
methodSig.Append(')');
|
2004-09-02 20:34:11 +04:00
|
|
|
if (retvalInfo) {
|
|
|
|
nsCAutoString retvalSig;
|
|
|
|
rv = GetRetvalSig(retvalInfo, retvalSig);
|
|
|
|
methodSig.Append(retvalSig);
|
|
|
|
} else {
|
2005-01-12 20:36:11 +03:00
|
|
|
methodSig.Append('V');
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetRetvalSig failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Java method to call
|
|
|
|
jmethodID mid = nsnull;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-09-15 21:31:14 +04:00
|
|
|
nsCAutoString methodName;
|
|
|
|
if (aMethodInfo->IsGetter() || aMethodInfo->IsSetter()) {
|
|
|
|
if (aMethodInfo->IsGetter())
|
2005-01-12 20:36:11 +03:00
|
|
|
methodName.AppendLiteral("get");
|
2004-09-15 21:31:14 +04:00
|
|
|
else
|
2005-01-12 20:36:11 +03:00
|
|
|
methodName.AppendLiteral("set");
|
|
|
|
methodName.AppendASCII(aMethodInfo->GetName());
|
2004-09-15 21:31:14 +04:00
|
|
|
methodName.SetCharAt(toupper(methodName[3]), 3);
|
|
|
|
} else {
|
2005-01-12 20:36:11 +03:00
|
|
|
methodName.AppendASCII(aMethodInfo->GetName());
|
2004-09-15 21:31:14 +04:00
|
|
|
methodName.SetCharAt(tolower(methodName[0]), 0);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
jclass clazz = mJavaEnv->GetObjectClass(javaObject);
|
2004-09-02 20:34:11 +04:00
|
|
|
if (clazz)
|
|
|
|
mid = mJavaEnv->GetMethodID(clazz, methodName.get(), methodSig.get());
|
|
|
|
NS_ASSERTION(mid, "Failed to get requested method for Java object");
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!mid)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call method
|
|
|
|
jvalue retval;
|
2005-01-12 20:59:01 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2004-09-02 20:34:11 +04:00
|
|
|
if (!retvalInfo) {
|
2005-02-25 00:53:46 +03:00
|
|
|
mJavaEnv->CallVoidMethodA(javaObject, mid, java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
|
|
|
switch (retvalInfo->GetType().TagPart())
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.b = mJavaEnv->CallByteMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.s = mJavaEnv->CallShortMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.i = mJavaEnv->CallIntMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.f = mJavaEnv->CallFloatMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.d = mJavaEnv->CallDoubleMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.z = mJavaEnv->CallBooleanMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.c = mJavaEnv->CallCharMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.l = mJavaEnv->CallObjectMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
2004-09-16 02:59:42 +04:00
|
|
|
case nsXPTType::T_VOID:
|
2005-02-25 00:53:46 +03:00
|
|
|
retval.i = mJavaEnv->CallIntMethodA(javaObject, mid,
|
2004-10-07 19:11:34 +04:00
|
|
|
java_params);
|
2004-09-16 02:59:42 +04:00
|
|
|
break;
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("Unhandled retval type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for exception from called Java function
|
2005-01-12 20:59:01 +03:00
|
|
|
jthrowable exp = mJavaEnv->ExceptionOccurred();
|
|
|
|
if (exp) {
|
2004-09-02 20:34:11 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mJavaEnv->ExceptionDescribe();
|
|
|
|
#endif
|
2005-01-12 20:59:01 +03:00
|
|
|
|
|
|
|
// If the exception is an instance of XPCOMException, then get the
|
|
|
|
// nsresult from the exception instance. Else, default to
|
|
|
|
// NS_ERROR_FAILURE.
|
|
|
|
if (mJavaEnv->IsInstanceOf(exp, xpcomExceptionClass)) {
|
|
|
|
jfieldID fid;
|
|
|
|
fid = mJavaEnv->GetFieldID(xpcomExceptionClass, "errorcode", "J");
|
|
|
|
if (fid) {
|
|
|
|
rv = mJavaEnv->GetLongField(exp, fid);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(fid, "Couldn't get 'errorcode' field of XPCOMException");
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// Handle any 'inout', 'out' and 'retval' params
|
2004-09-02 20:34:11 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
for (PRUint8 i = 0; i < paramCount; i++)
|
|
|
|
{
|
|
|
|
const nsXPTParamInfo ¶mInfo = aMethodInfo->GetParam(i);
|
2005-01-13 19:30:19 +03:00
|
|
|
if (paramInfo.IsIn() && !paramInfo.IsOut()) // 'in'
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If param is null, then caller is not expecting an output value.
|
|
|
|
if (aParams[i].val.p == nsnull)
|
|
|
|
continue;
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
if (!paramInfo.IsRetval()) {
|
|
|
|
rv = FinalizeJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
|
|
|
|
aParams[i], java_params[i]);
|
|
|
|
} else {
|
|
|
|
rv = FinalizeJavaParams(paramInfo, aMethodInfo, aMethodIndex, aParams,
|
|
|
|
aParams[i], retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "FinalizeJavaParams/SetXPCOMRetval failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (java_params)
|
|
|
|
delete [] java_params;
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
LOG(("<--- (Java) %s::%s()\n", ifaceName, aMethodInfo->GetName()));
|
2005-01-12 20:59:01 +03:00
|
|
|
mJavaEnv->ExceptionClear();
|
2004-09-02 20:34:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
/**
|
|
|
|
* Handle 'in', 'inout', and 'out' params
|
|
|
|
*/
|
2004-09-02 20:34:11 +04:00
|
|
|
nsresult
|
|
|
|
nsJavaXPTCStub::SetupJavaParams(const nsXPTParamInfo &aParamInfo,
|
|
|
|
const nsXPTMethodInfo* aMethodInfo,
|
|
|
|
PRUint16 aMethodIndex,
|
|
|
|
nsXPTCMiniVariant* aDispatchParams,
|
|
|
|
nsXPTCMiniVariant &aVariant, jvalue &aJValue,
|
|
|
|
nsACString &aMethodSig)
|
|
|
|
{
|
2005-01-12 20:59:01 +03:00
|
|
|
nsresult rv = NS_OK;
|
2004-09-02 20:34:11 +04:00
|
|
|
const nsXPTType &type = aParamInfo.GetType();
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
PRUint8 tag = type.TagPart();
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.b = aVariant.val.u8;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('B');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jbyteArray array = mJavaEnv->NewByteArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetByteArrayRegion(array, 0, 1, (jbyte*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[B");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.s = aVariant.val.u16;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('S');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jshortArray array = mJavaEnv->NewShortArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetShortArrayRegion(array, 0, 1, (jshort*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[S");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.i = aVariant.val.u32;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('I');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jintArray array = mJavaEnv->NewIntArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetIntArrayRegion(array, 0, 1, (jint*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[I");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
|
|
|
case nsXPTType::T_U64:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.j = aVariant.val.u64;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('J');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jlongArray array = mJavaEnv->NewLongArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetLongArrayRegion(array, 0, 1, (jlong*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[J");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.f = aVariant.val.f;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('F');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jfloatArray array = mJavaEnv->NewFloatArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetFloatArrayRegion(array, 0, 1, (jfloat*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[F");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.d = aVariant.val.d;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('D');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jdoubleArray array = mJavaEnv->NewDoubleArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetDoubleArrayRegion(array, 0, 1,
|
|
|
|
(jdouble*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[D");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.z = aVariant.val.b;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('Z');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jbooleanArray array = mJavaEnv->NewBooleanArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetBooleanArrayRegion(array, 0, 1,
|
|
|
|
(jboolean*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Z");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
|
|
|
if (tag == nsXPTType::T_CHAR)
|
|
|
|
aJValue.c = aVariant.val.c;
|
|
|
|
else
|
|
|
|
aJValue.c = aVariant.val.wc;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('C');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jcharArray array = mJavaEnv->NewCharArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetCharArrayRegion(array, 0, 1, (jchar*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[C");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
{
|
2004-10-27 00:30:01 +04:00
|
|
|
void* ptr = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-10-27 00:30:01 +04:00
|
|
|
ptr = aVariant.val.p;
|
2005-01-13 19:30:19 +03:00
|
|
|
} else if (aVariant.val.p) { // 'inout' & 'out'
|
|
|
|
void** variant = NS_STATIC_CAST(void**, aVariant.val.p);
|
2004-10-27 00:30:01 +04:00
|
|
|
ptr = *variant;
|
|
|
|
}
|
|
|
|
|
2005-01-12 20:59:01 +03:00
|
|
|
jobject str;
|
2004-10-27 00:30:01 +04:00
|
|
|
if (ptr) {
|
2004-09-02 20:34:11 +04:00
|
|
|
if (tag == nsXPTType::T_CHAR_STR) {
|
2004-10-27 00:30:01 +04:00
|
|
|
str = mJavaEnv->NewStringUTF((const char*) ptr);
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2004-10-27 00:30:01 +04:00
|
|
|
const PRUnichar* buf = (const PRUnichar*) ptr;
|
2004-09-02 20:34:11 +04:00
|
|
|
str = mJavaEnv->NewString(buf, nsCRT::strlen(buf));
|
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
str = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.l = str;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("Ljava/lang/String;");
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
aJValue.l = mJavaEnv->NewObjectArray(1, stringClass, str);
|
|
|
|
if (aJValue.l == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Ljava/lang/String;");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
nsID* iid = nsnull;
|
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
|
|
|
iid = NS_STATIC_CAST(nsID*, aVariant.val.p);
|
|
|
|
} else if (aVariant.val.p) { // 'inout' & 'out'
|
|
|
|
nsID** variant = NS_STATIC_CAST(nsID**, aVariant.val.p);
|
|
|
|
iid = *variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject str;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (iid) {
|
|
|
|
char* iid_str = iid->ToString();
|
2005-01-13 19:30:19 +03:00
|
|
|
if (iid_str) {
|
|
|
|
str = mJavaEnv->NewStringUTF(iid_str);
|
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!iid_str || !str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
PR_Free(iid_str);
|
2005-01-13 19:30:19 +03:00
|
|
|
} else {
|
|
|
|
str = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.l = str;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("Ljava/lang/String;");
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
aJValue.l = mJavaEnv->NewObjectArray(1, stringClass, str);
|
|
|
|
if (aJValue.l == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Ljava/lang/String;");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
nsISupports* xpcom_obj = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2005-02-25 00:53:46 +03:00
|
|
|
xpcom_obj = NS_STATIC_CAST(nsISupports*, aVariant.val.p);
|
2005-01-13 19:30:19 +03:00
|
|
|
} else if (aVariant.val.p) { // 'inout' & 'out'
|
2005-02-25 00:53:46 +03:00
|
|
|
nsISupports** variant = NS_STATIC_CAST(nsISupports**, aVariant.val.p);
|
2005-01-13 19:30:19 +03:00
|
|
|
xpcom_obj = *variant;
|
|
|
|
}
|
|
|
|
|
2004-10-18 21:04:29 +04:00
|
|
|
jobject java_stub = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (xpcom_obj) {
|
2005-01-21 01:07:26 +03:00
|
|
|
nsID iid;
|
|
|
|
rv = GetIIDForMethodParam(mIInfo, aMethodInfo, aParamInfo, aMethodIndex,
|
|
|
|
aDispatchParams, PR_FALSE, iid);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-21 01:07:26 +03:00
|
|
|
// Get matching Java object for given xpcom object
|
2005-02-25 00:53:46 +03:00
|
|
|
rv = GetNewOrUsedJavaObject(mJavaEnv, xpcom_obj, iid, &java_stub,
|
|
|
|
nsnull);
|
2005-01-21 01:07:26 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.l = java_stub;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("Lorg/mozilla/xpcom/nsISupports;");
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
aJValue.l = mJavaEnv->NewObjectArray(1, nsISupportsClass, java_stub);
|
|
|
|
if (aJValue.l == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Lorg/mozilla/xpcom/nsISupports;");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
nsString* str = nsnull;
|
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
|
|
|
str = NS_STATIC_CAST(nsString*, aVariant.val.p);
|
|
|
|
} else if (aVariant.val.p) { // 'inout' & 'out'
|
|
|
|
nsString** variant = NS_STATIC_CAST(nsString**, aVariant.val.p);
|
|
|
|
str = *variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jstr;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (str) {
|
|
|
|
jstr = mJavaEnv->NewString(str->get(), str->Length());
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!jstr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
} else {
|
|
|
|
jstr = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.l = jstr;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("Ljava/lang/String;");
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
aJValue.l = mJavaEnv->NewObjectArray(1, stringClass, jstr);
|
|
|
|
if (aJValue.l == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Ljava/lang/String;");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
nsCString* str = nsnull;
|
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
|
|
|
str = NS_STATIC_CAST(nsCString*, aVariant.val.p);
|
|
|
|
} else if (aVariant.val.p) { // 'inout' & 'out'
|
|
|
|
nsCString** variant = NS_STATIC_CAST(nsCString**, aVariant.val.p);
|
|
|
|
str = *variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jstr;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (str) {
|
|
|
|
jstr = mJavaEnv->NewStringUTF(str->get());
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!jstr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
} else {
|
|
|
|
jstr = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aJValue.l = jstr;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("Ljava/lang/String;");
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
aJValue.l = mJavaEnv->NewObjectArray(1, stringClass, jstr);
|
|
|
|
if (aJValue.l == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[Ljava/lang/String;");
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-09-16 02:59:42 +04:00
|
|
|
// Pass the 'void*' address as an integer
|
2004-09-02 20:34:11 +04:00
|
|
|
case nsXPTType::T_VOID:
|
2004-09-16 02:59:42 +04:00
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsOut()) { // 'in'
|
2004-09-16 02:59:42 +04:00
|
|
|
aJValue.i = (jint) aVariant.val.p;
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.Append('I');
|
2005-01-13 19:30:19 +03:00
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
jintArray array = mJavaEnv->NewIntArray(1);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mJavaEnv->SetIntArrayRegion(array, 0, 1, (jint*) aVariant.val.p);
|
|
|
|
aJValue.l = array;
|
|
|
|
} else {
|
|
|
|
aJValue.l = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-12 20:36:11 +03:00
|
|
|
aMethodSig.AppendLiteral("[I");
|
2004-09-16 02:59:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
case nsXPTType::T_ARRAY:
|
|
|
|
NS_WARNING("array types are not yet supported");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_PSTRING_SIZE_IS:
|
|
|
|
case nsXPTType::T_PWSTRING_SIZE_IS:
|
|
|
|
default:
|
|
|
|
NS_WARNING("unexpected parameter type");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2005-01-12 20:59:01 +03:00
|
|
|
return rv;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJavaXPTCStub::GetRetvalSig(const nsXPTParamInfo* aParamInfo,
|
|
|
|
nsACString &aRetvalSig)
|
|
|
|
{
|
|
|
|
const nsXPTType &type = aParamInfo->GetType();
|
|
|
|
PRUint8 tag = type.TagPart();
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('B');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('S');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('I');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
|
|
|
case nsXPTType::T_U64:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('J');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('F');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('D');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('Z');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('C');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.AppendLiteral("Ljava/lang/String;");
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.AppendLiteral("Lorg/mozilla/xpcom/nsISupports;");
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_VOID:
|
2005-01-12 20:36:11 +03:00
|
|
|
aRetvalSig.Append('I');
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_ARRAY:
|
|
|
|
NS_WARNING("array types are not yet supported");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_PSTRING_SIZE_IS:
|
|
|
|
case nsXPTType::T_PWSTRING_SIZE_IS:
|
|
|
|
default:
|
|
|
|
NS_WARNING("unexpected parameter type");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
/**
|
|
|
|
* Handle 'inout', 'out', and 'retval' params
|
|
|
|
*/
|
2004-09-02 20:34:11 +04:00
|
|
|
nsresult
|
|
|
|
nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
|
|
|
|
const nsXPTMethodInfo* aMethodInfo,
|
|
|
|
PRUint16 aMethodIndex,
|
|
|
|
nsXPTCMiniVariant* aDispatchParams,
|
|
|
|
nsXPTCMiniVariant &aVariant, jvalue &aJValue)
|
|
|
|
{
|
2005-01-12 20:59:01 +03:00
|
|
|
nsresult rv = NS_OK;
|
2004-09-02 20:34:11 +04:00
|
|
|
const nsXPTType &type = aParamInfo.GetType();
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
PRUint8 tag = type.TagPart();
|
|
|
|
switch (tag)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRUint8 *) aVariant.val.p) = aJValue.b;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetByteArrayRegion((jbyteArray) aJValue.l, 0, 1,
|
|
|
|
(jbyte*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRUint16 *) aVariant.val.p) = aJValue.s;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetShortArrayRegion((jshortArray) aJValue.l, 0, 1,
|
|
|
|
(jshort*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRUint32 *) aVariant.val.p) = aJValue.i;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetIntArrayRegion((jintArray) aJValue.l, 0, 1,
|
|
|
|
(jint*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
|
|
|
case nsXPTType::T_U64:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRUint64 *) aVariant.val.p) = aJValue.j;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetLongArrayRegion((jlongArray) aJValue.l, 0, 1,
|
|
|
|
(jlong*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((float *) aVariant.val.p) = aJValue.f;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetFloatArrayRegion((jfloatArray) aJValue.l, 0, 1,
|
|
|
|
(jfloat*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((double *) aVariant.val.p) = aJValue.d;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetDoubleArrayRegion((jdoubleArray) aJValue.l, 0, 1,
|
|
|
|
(jdouble*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRBool *) aVariant.val.p) = aJValue.z;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetBooleanArrayRegion((jbooleanArray) aJValue.l, 0, 1,
|
|
|
|
(jboolean*) aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
if (type.TagPart() == nsXPTType::T_CHAR)
|
|
|
|
*((char *) aVariant.val.p) = aJValue.c;
|
|
|
|
else
|
|
|
|
*((PRUnichar *) aVariant.val.p) = aJValue.c;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
jchar* array = mJavaEnv->GetCharArrayElements((jcharArray) aJValue.l,
|
|
|
|
nsnull);
|
|
|
|
if (!array) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
if (type.TagPart() == nsXPTType::T_CHAR)
|
2005-01-13 19:30:19 +03:00
|
|
|
*((char *) aVariant.val.p) = array[0];
|
2004-09-02 20:34:11 +04:00
|
|
|
else
|
2005-01-13 19:30:19 +03:00
|
|
|
*((PRUnichar *) aVariant.val.p) = array[0];
|
|
|
|
|
|
|
|
mJavaEnv->ReleaseCharArrayElements((jcharArray) aJValue.l, array,
|
|
|
|
JNI_ABORT);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jstring str = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
str = (jstring) aJValue.l;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
str = (jstring)
|
|
|
|
mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
char** variant = NS_STATIC_CAST(char**, aVariant.val.p);
|
|
|
|
if (str) {
|
|
|
|
// Get string buffer
|
|
|
|
const char* char_ptr = mJavaEnv->GetStringUTFChars(str, nsnull);
|
|
|
|
if (!char_ptr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// If new string is different from one passed in, free old string
|
|
|
|
// and replace with new string.
|
|
|
|
if (aParamInfo.IsRetval() ||
|
|
|
|
*variant == nsnull || strcmp(*variant, char_ptr) != 0)
|
|
|
|
{
|
|
|
|
if (!aParamInfo.IsRetval() && *variant)
|
|
|
|
PR_Free(*variant);
|
|
|
|
|
|
|
|
*variant = strdup(char_ptr);
|
|
|
|
if (*variant == nsnull) {
|
2005-01-12 20:59:01 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2005-01-13 19:30:19 +03:00
|
|
|
// don't 'break'; fall through to release chars
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
|
|
|
|
// Release string buffer
|
|
|
|
mJavaEnv->ReleaseStringUTFChars(str, char_ptr);
|
|
|
|
} else {
|
|
|
|
// If we were passed in a string, delete it now, and set to null.
|
|
|
|
// (Only for 'inout' & 'out' params)
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
PR_Free(*variant);
|
|
|
|
}
|
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jstring str = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
str = (jstring) aJValue.l;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
str = (jstring)
|
|
|
|
mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar** variant = NS_STATIC_CAST(PRUnichar**, aVariant.val.p);
|
|
|
|
if (str) {
|
|
|
|
// Get string buffer
|
|
|
|
const jchar* wchar_ptr = mJavaEnv->GetStringChars(str, nsnull);
|
|
|
|
if (!wchar_ptr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// If new string is different from one passed in, free old string
|
|
|
|
// and replace with new string. We
|
|
|
|
if (aParamInfo.IsRetval() ||
|
|
|
|
*variant == nsnull || nsCRT::strcmp(*variant, wchar_ptr) != 0)
|
|
|
|
{
|
|
|
|
if (!aParamInfo.IsRetval() && *variant)
|
|
|
|
PR_Free(*variant);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
PRUint32 length = nsCRT::strlen(wchar_ptr);
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = (PRUnichar*) PR_Malloc((length + 1) * sizeof(PRUnichar));
|
|
|
|
if (*variant) {
|
|
|
|
memcpy(*variant, wchar_ptr, length * sizeof(PRUnichar));
|
|
|
|
(*variant)[length] = 0;
|
|
|
|
} else {
|
2005-01-12 20:59:01 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
2005-01-13 19:30:19 +03:00
|
|
|
// don't 'break'; fall through to release chars
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// Release string buffer
|
|
|
|
mJavaEnv->ReleaseStringChars(str, wchar_ptr);
|
|
|
|
} else {
|
|
|
|
// If we were passed in a string, delete it now, and set to null.
|
|
|
|
// (Only for 'inout' & 'out' params)
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
PR_Free(*variant);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jstring str = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
str = (jstring) aJValue.l;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
str = (jstring)
|
|
|
|
mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsID** variant = NS_STATIC_CAST(nsID**, aVariant.val.p);
|
|
|
|
if (str) {
|
|
|
|
// Get string buffer
|
|
|
|
const char* char_ptr = mJavaEnv->GetStringUTFChars(str, nsnull);
|
|
|
|
if (!char_ptr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsRetval() && *variant) {
|
|
|
|
// If we were given an nsID, set it to the new string
|
|
|
|
nsID* oldIID = *variant;
|
|
|
|
oldIID->Parse(char_ptr);
|
|
|
|
} else {
|
|
|
|
// If the argument that was passed in was null, then we need to
|
|
|
|
// create a new nsID.
|
|
|
|
nsID* newIID = new nsID;
|
|
|
|
if (newIID) {
|
|
|
|
newIID->Parse(char_ptr);
|
|
|
|
*variant = newIID;
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// don't 'break'; fall through to release chars
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// Release string buffer
|
|
|
|
mJavaEnv->ReleaseStringUTFChars(str, char_ptr);
|
|
|
|
} else {
|
|
|
|
// If we were passed in an nsID, delete it now, and set to null.
|
|
|
|
// (Free only 'inout' & 'out' params)
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
delete *variant;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jobject java_obj = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
java_obj = aJValue.l;
|
|
|
|
} else if (aJValue.l) { // 'inout' & 'out'
|
|
|
|
java_obj = mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsISupports** variant = NS_STATIC_CAST(nsISupports**, aVariant.val.p);
|
|
|
|
if (java_obj) {
|
|
|
|
// Get IID for this param
|
|
|
|
nsID iid;
|
|
|
|
rv = GetIIDForMethodParam(mIInfo, aMethodInfo, aParamInfo,
|
|
|
|
aMethodIndex, aDispatchParams,
|
|
|
|
PR_FALSE, iid);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
// If the requested interface is nsIWeakReference, then we look for or
|
|
|
|
// create a stub for the nsISupports interface. Then we create a weak
|
|
|
|
// reference from that stub.
|
|
|
|
PRBool isWeakRef;
|
|
|
|
if (iid.Equals(NS_GET_IID(nsIWeakReference))) {
|
|
|
|
isWeakRef = PR_TRUE;
|
|
|
|
iid = NS_GET_IID(nsISupports);
|
|
|
|
} else {
|
|
|
|
isWeakRef = PR_FALSE;
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
nsISupports* xpcom_obj;
|
|
|
|
PRBool isXPTCStub;
|
|
|
|
rv = GetNewOrUsedXPCOMObject(mJavaEnv, java_obj, iid, &xpcom_obj,
|
|
|
|
&isXPTCStub);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If the function expects a weak reference, then we need to
|
|
|
|
// create it here.
|
2005-01-13 19:30:19 +03:00
|
|
|
if (isWeakRef) {
|
2005-02-25 00:53:46 +03:00
|
|
|
if (isXPTCStub) {
|
|
|
|
nsJavaXPTCStub* stub = NS_STATIC_CAST(nsJavaXPTCStub*,
|
|
|
|
NS_STATIC_CAST(nsXPTCStubBase*,
|
|
|
|
xpcom_obj));
|
|
|
|
nsJavaXPTCStubWeakRef* weakref;
|
|
|
|
weakref = new nsJavaXPTCStubWeakRef(mJavaEnv, java_obj, stub);
|
|
|
|
if (!weakref) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-25 02:17:36 +03:00
|
|
|
NS_RELEASE(xpcom_obj);
|
2005-02-25 00:53:46 +03:00
|
|
|
xpcom_obj = weakref;
|
|
|
|
NS_ADDREF(xpcom_obj);
|
|
|
|
} else { // if is native XPCOM object
|
|
|
|
nsCOMPtr<nsISupportsWeakReference> supportsweak =
|
|
|
|
do_QueryInterface(xpcom_obj);
|
|
|
|
if (supportsweak) {
|
|
|
|
nsWeakPtr weakref;
|
|
|
|
supportsweak->GetWeakReference(getter_AddRefs(weakref));
|
2005-02-25 02:17:36 +03:00
|
|
|
NS_RELEASE(xpcom_obj);
|
2005-02-25 00:53:46 +03:00
|
|
|
xpcom_obj = weakref;
|
|
|
|
NS_ADDREF(xpcom_obj);
|
|
|
|
} else {
|
|
|
|
xpcom_obj = nsnull;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-02-25 00:53:46 +03:00
|
|
|
|
|
|
|
} else if (!isXPTCStub) { // if is native XPCOM object
|
|
|
|
xpcom_obj->Release();
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
// } else if (isXPTCStub) {
|
|
|
|
// nothing to do
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
NS_RELEASE(*variant);
|
|
|
|
}
|
2005-02-25 00:53:46 +03:00
|
|
|
*variant = xpcom_obj;
|
2005-01-13 19:30:19 +03:00
|
|
|
} else {
|
|
|
|
// If were passed in an object, release it now, and set to null.
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
NS_RELEASE(*variant);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jstring str = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
str = (jstring) aJValue.l;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
str = (jstring)
|
|
|
|
mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsString** variant = NS_STATIC_CAST(nsString**, aVariant.val.p);
|
|
|
|
if (str) {
|
|
|
|
// Get string buffer
|
|
|
|
const jchar* wchar_ptr = mJavaEnv->GetStringChars(str, nsnull);
|
|
|
|
if (!wchar_ptr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsRetval() && *variant) {
|
|
|
|
// If we were given an nsString, set it to the new string
|
|
|
|
nsString* string = *variant;
|
|
|
|
string->Assign(wchar_ptr);
|
|
|
|
} else {
|
|
|
|
// If the argument that was passed in was null, then we need to
|
|
|
|
// create a new nsID.
|
|
|
|
nsString* embedStr = new nsString(wchar_ptr);
|
|
|
|
if (embedStr) {
|
|
|
|
*variant = embedStr;
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// don't 'break'; fall through to release chars
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// release String buffer
|
|
|
|
mJavaEnv->ReleaseStringChars(str, wchar_ptr);
|
|
|
|
} else {
|
|
|
|
// If we were passed in a string, delete it now, and set to null.
|
|
|
|
// (Free only 'inout' & 'out' params)
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
delete *variant;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jstring str = nsnull;
|
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
str = (jstring) aJValue.l;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
str = (jstring)
|
|
|
|
mJavaEnv->GetObjectArrayElement((jobjectArray) aJValue.l, 0);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsCString** variant = NS_STATIC_CAST(nsCString**, aVariant.val.p);
|
|
|
|
if (str) {
|
|
|
|
// Get string buffer
|
|
|
|
const char* char_ptr = mJavaEnv->GetStringUTFChars(str, nsnull);
|
|
|
|
if (!char_ptr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!aParamInfo.IsRetval() && *variant) {
|
|
|
|
// If we were given an nsString, set it to the new string
|
|
|
|
nsCString* string = *variant;
|
|
|
|
string->Assign(char_ptr);
|
|
|
|
} else {
|
|
|
|
// If the argument that was passed in was null, then we need to
|
|
|
|
// create a new nsID.
|
|
|
|
nsCString* embedStr = new nsCString(char_ptr);
|
|
|
|
if (embedStr) {
|
|
|
|
*variant = embedStr;
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// don't 'break'; fall through to release chars
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// release String buffer
|
|
|
|
mJavaEnv->ReleaseStringUTFChars(str, char_ptr);
|
|
|
|
} else {
|
|
|
|
// If we were passed in a string, delete it now, and set to null.
|
|
|
|
// (Free only 'inout' & 'out' params)
|
|
|
|
if (*variant && !aParamInfo.IsRetval()) {
|
|
|
|
delete *variant;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
*variant = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_VOID:
|
2004-09-16 02:59:42 +04:00
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParamInfo.IsRetval()) { // 'retval'
|
|
|
|
*((PRUint32 *) aVariant.val.p) = aJValue.i;
|
|
|
|
} else { // 'inout' & 'out'
|
|
|
|
if (aJValue.l) {
|
|
|
|
mJavaEnv->GetIntArrayRegion((jintArray) aJValue.l, 0, 1,
|
|
|
|
(jint*) aVariant.val.p);
|
2004-09-16 02:59:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("unexpected parameter type");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2005-01-12 20:59:01 +03:00
|
|
|
return rv;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2004-09-16 01:50:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJavaXPTCStub::GetWeakReference(nsIWeakReference** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (mMaster)
|
|
|
|
return mMaster->GetWeakReference(aInstancePtr);
|
|
|
|
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("==> nsJavaXPTCStub::GetWeakReference()\n"));
|
2004-09-16 01:50:41 +04:00
|
|
|
|
|
|
|
if (!aInstancePtr)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
jobject javaObject = mJavaEnv->NewLocalRef(mJavaWeakRef);
|
2005-01-12 20:59:01 +03:00
|
|
|
nsJavaXPTCStubWeakRef* weakref;
|
2005-02-25 00:53:46 +03:00
|
|
|
weakref = new nsJavaXPTCStubWeakRef(mJavaEnv, javaObject, this);
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!weakref)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-09-16 01:50:41 +04:00
|
|
|
*aInstancePtr = weakref;
|
|
|
|
NS_ADDREF(*aInstancePtr);
|
2005-02-25 00:53:46 +03:00
|
|
|
++mWeakRefCnt;
|
2004-09-16 01:50:41 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-10-07 19:11:34 +04:00
|
|
|
jobject
|
|
|
|
nsJavaXPTCStub::GetJavaObject()
|
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
jobject javaObject = mJavaEnv->NewLocalRef(mJavaWeakRef);
|
|
|
|
|
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
nsIID* iid;
|
|
|
|
mIInfo->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
LOG(("< nsJavaXPTCStub (Java=%08x | XPCOM=%08x | IID=%s)\n",
|
2005-02-25 02:17:36 +03:00
|
|
|
(PRUint32) mJavaEnv->CallIntMethod(javaObject, hashCodeMID),
|
|
|
|
(PRUint32) this, iid_str));
|
2005-02-25 00:53:46 +03:00
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return javaObject;
|
2004-10-07 19:11:34 +04:00
|
|
|
}
|