Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Protected Attributes | Friends
JavaToXPTCStubMap Class Reference

Maps Java objects to their associated nsJavaXPTCStub. More...

#include <nsJavaXPCOMBindingUtils.h>

Collaboration diagram for JavaToXPTCStubMap:
Collaboration graph
[legend]

List of all members.

Classes

struct  Entry

Public Member Functions

 JavaToXPTCStubMap ()
 ~JavaToXPTCStubMap ()
nsresult Init ()
nsresult Destroy ()
nsresult Add (jint aJavaObjectHashCode, nsJavaXPTCStub *aProxy)
nsresult Find (jint aJavaObjectHashCode, const nsIID &aIID, nsJavaXPTCStub **aResult)
nsresult Remove (jint aJavaObjectHashCode)

Protected Attributes

PLDHashTablemHashTable

Friends

PLDHashOperator DestroyXPTCMappingEnum (PLDHashTable *aTable, PLDHashEntryHdr *aHeader, PRUint32 aNumber, void *aData)

Detailed Description

Maps Java objects to their associated nsJavaXPTCStub.

Definition at line 222 of file nsJavaXPCOMBindingUtils.h.


Constructor & Destructor Documentation

Definition at line 236 of file nsJavaXPCOMBindingUtils.h.

Definition at line 240 of file nsJavaXPCOMBindingUtils.h.

  {
    NS_ASSERTION(mHashTable == nsnull,
                 "MUST call Destroy() before deleting object");
  }

Member Function Documentation

nsresult JavaToXPTCStubMap::Add ( jint  aJavaObjectHashCode,
nsJavaXPTCStub aProxy 
)

Definition at line 698 of file nsJavaXPCOMBindingUtils.cpp.

{
  nsAutoLock lock(gJavaXPCOMLock);

  Entry* e = NS_STATIC_CAST(Entry*,
                            PL_DHashTableOperate(mHashTable,
                                           NS_INT32_TO_PTR(aJavaObjectHashCode),
                                           PL_DHASH_ADD));
  if (!e)
    return NS_ERROR_FAILURE;

  NS_ASSERTION(e->key == nsnull,
               "XPTCStub for given Java object already exists in hash table");
  e->key = aJavaObjectHashCode;
  e->xptcstub = aProxy;

#ifdef DEBUG_JAVAXPCOM
  nsIInterfaceInfo* iface_info;
  aProxy->GetInterfaceInfo(&iface_info);
  nsIID* iid;
  iface_info->GetInterfaceIID(&iid);
  char* iid_str = iid->ToString();
  LOG(("+ JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
       (PRUint32) aJavaObjectHashCode, (PRUint32) aProxy, iid_str));
  PR_Free(iid_str);
  nsMemory::Free(iid);
  NS_RELEASE(iface_info);
#endif
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 685 of file nsJavaXPCOMBindingUtils.cpp.

{
  // This is only called from FreeGlobals(), which already holds the lock.
  //  nsAutoLock lock(gJavaXPCOMLock);

  PL_DHashTableEnumerate(mHashTable, DestroyXPTCMappingEnum, nsnull);
  PL_DHashTableDestroy(mHashTable);
  mHashTable = nsnull;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult JavaToXPTCStubMap::Find ( jint  aJavaObjectHashCode,
const nsIID aIID,
nsJavaXPTCStub **  aResult 
)

Definition at line 730 of file nsJavaXPCOMBindingUtils.cpp.

{
  NS_PRECONDITION(aResult != nsnull, "null ptr");
  if (!aResult)
    return NS_ERROR_FAILURE;

  nsAutoLock lock(gJavaXPCOMLock);

  *aResult = nsnull;
  Entry* e = NS_STATIC_CAST(Entry*,
                            PL_DHashTableOperate(mHashTable,
                                           NS_INT32_TO_PTR(aJavaObjectHashCode),
                                           PL_DHASH_LOOKUP));

  if (PL_DHASH_ENTRY_IS_FREE(e))
    return NS_OK;

  nsresult rv = e->xptcstub->QueryInterface(aIID, (void**) aResult);

#ifdef DEBUG_JAVAXPCOM
  if (NS_SUCCEEDED(rv)) {
    char* iid_str = aIID.ToString();
    LOG(("< JavaToXPTCStubMap (Java=%08x | XPCOM=%08x | IID=%s)\n",
         (PRUint32) aJavaObjectHashCode, (PRUint32) *aResult, iid_str));
    PR_Free(iid_str);
  }
#endif

  // NS_NOINTERFACE is not an error condition
  if (rv == NS_NOINTERFACE)
    rv = NS_OK;
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 660 of file nsJavaXPCOMBindingUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult JavaToXPTCStubMap::Remove ( jint  aJavaObjectHashCode)

Definition at line 766 of file nsJavaXPCOMBindingUtils.cpp.

{
  PL_DHashTableOperate(mHashTable, NS_INT32_TO_PTR(aJavaObjectHashCode),
                       PL_DHASH_REMOVE);

#ifdef DEBUG_JAVAXPCOM
  LOG(("- JavaToXPTCStubMap (Java=%08x)\n", (PRUint32) aJavaObjectHashCode));
#endif

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

PLDHashOperator DestroyXPTCMappingEnum ( PLDHashTable aTable,
PLDHashEntryHdr aHeader,
PRUint32  aNumber,
void aData 
) [friend]

Definition at line 670 of file nsJavaXPCOMBindingUtils.cpp.

{
  JavaToXPTCStubMap::Entry* entry =
                             NS_STATIC_CAST(JavaToXPTCStubMap::Entry*, aHeader);

  // The XPTC stub will be released by the XPCOM side, if it hasn't been
  // already.  We just need to delete the Java global ref held by the XPTC stub,
  // so the Java garbage collector can handle the Java object when necessary.
  entry->xptcstub->DeleteStrongRef();

  return PL_DHASH_REMOVE;
}

Member Data Documentation

Definition at line 258 of file nsJavaXPCOMBindingUtils.h.


The documentation for this class was generated from the following files: