Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Member Functions | Private Attributes
XPCNativeSet Class Reference

#include <xpcprivate.h>

Collaboration diagram for XPCNativeSet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

JSBool FindMember (jsval name, XPCNativeMember **pMember, PRUint16 *pInterfaceIndex) const
JSBool FindMember (jsval name, XPCNativeMember **pMember, XPCNativeInterface **pInterface) const
JSBool FindMember (jsval name, XPCNativeMember **pMember, XPCNativeInterface **pInterface, XPCNativeSet *protoSet, JSBool *pIsLocal) const
JSBool HasInterface (XPCNativeInterface *aInterface) const
JSBool HasInterfaceWithAncestor (XPCNativeInterface *aInterface) const
XPCNativeInterfaceFindInterfaceWithIID (const nsIID &iid) const
XPCNativeInterfaceFindNamedInterface (jsval name) const
PRUint16 GetMemberCount () const
PRUint16 GetInterfaceCount () const
XPCNativeInterface ** GetInterfaceArray ()
XPCNativeInterfaceGetInterfaceAt (PRUint16 i)
JSBool MatchesSetUpToInterface (const XPCNativeSet *other, XPCNativeInterface *iface) const
void Mark ()
void MarkBeforeJSFinalize (JSContext *)
void AutoMark (JSContext *)
void Unmark ()
JSBool IsMarked () const
void DebugDump (PRInt16 depth)

Static Public Member Functions

static XPCNativeSetGetNewOrUsed (XPCCallContext &ccx, const nsIID *iid)
static XPCNativeSetGetNewOrUsed (XPCCallContext &ccx, nsIClassInfo *classInfo)
static XPCNativeSetGetNewOrUsed (XPCCallContext &ccx, XPCNativeSet *otherSet, XPCNativeInterface *newInterface, PRUint16 position)
static void ClearCacheEntryForClassInfo (nsIClassInfo *classInfo)
static void DestroyInstance (XPCNativeSet *inst)

Protected Member Functions

 XPCNativeSet ()
 ~XPCNativeSet ()
voidoperator new (size_t, void *p) CPP_THROW_NEW

Static Protected Member Functions

static XPCNativeSetNewInstance (XPCCallContext &ccx, XPCNativeInterface **array, PRUint16 count)
static XPCNativeSetNewInstanceMutate (XPCNativeSet *otherSet, XPCNativeInterface *newInterface, PRUint16 position)

Private Member Functions

void MarkSelfOnly ()

Private Attributes

PRUint16 mMemberCount
PRUint16 mInterfaceCount
XPCNativeInterfacemInterfaces [1]

Detailed Description

Definition at line 1341 of file xpcprivate.h.


Constructor & Destructor Documentation

XPCNativeSet::XPCNativeSet ( ) [inline, protected]

Definition at line 1414 of file xpcprivate.h.

Here is the caller graph for this function:

XPCNativeSet::~XPCNativeSet ( ) [inline, protected]

Definition at line 1415 of file xpcprivate.h.

Here is the caller graph for this function:


Member Function Documentation

Definition at line 1390 of file xpcprivate.h.

{}

Definition at line 707 of file xpcwrappednativeinfo.cpp.

{
    XPCJSRuntime* rt;
    ClassInfo2NativeSetMap* map;
    
    if(nsnull != (rt = nsXPConnect::GetRuntime()) && 
       nsnull != (map = rt->GetClassInfo2NativeSetMap()))
    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        map->Remove(classInfo);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 892 of file xpcwrappednativeinfo.cpp.

{
#ifdef DEBUG
    depth--;
    XPC_LOG_ALWAYS(("XPCNativeSet @ %x", this));
        XPC_LOG_INDENT();

        XPC_LOG_ALWAYS(("mInterfaceCount of %d", mInterfaceCount));
        if(depth)
        {
            for(PRUint16 i = 0; i < mInterfaceCount; i++)
                mInterfaces[i]->DebugDump(depth);
        }
        XPC_LOG_ALWAYS(("mMemberCount of %d", mMemberCount));
        XPC_LOG_OUTDENT();
#endif
}

Definition at line 885 of file xpcwrappednativeinfo.cpp.

{
    inst->~XPCNativeSet();
    delete [] (char*) inst;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 494 of file xpcinlines.h.

{
    XPCNativeInterface* const * pp = mInterfaces;

    for(int i = (int) mInterfaceCount; i > 0; i--, pp++)
    {
        XPCNativeInterface* iface = *pp;

        if(iface->GetIID()->Equals(iid))
            return iface;
    }
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool XPCNativeSet::FindMember ( jsval  name,
XPCNativeMember **  pMember,
PRUint16 pInterfaceIndex 
) const [inline]

Definition at line 402 of file xpcinlines.h.

{
    XPCNativeInterface* const * iface;
    int count = (int) mInterfaceCount;
    int i;

    // look for interface names first

    for(i = 0, iface = mInterfaces; i < count; i++, iface++)
    {
        if(name == (*iface)->GetName())
        {
            if(pMember)
                *pMember = nsnull;
            if(pInterfaceIndex)
                *pInterfaceIndex = (PRUint16) i;
            return JS_TRUE;
        }
    }

    // look for method names
    for(i = 0, iface = mInterfaces; i < count; i++, iface++)
    {
        XPCNativeMember* member = (*iface)->FindMember(name);
        if(member)
        {
            if(pMember)
                *pMember = member;
            if(pInterfaceIndex)
                *pInterfaceIndex = (PRUint16) i;
            return JS_TRUE;
        }
    }
    return JS_FALSE;
}

Here is the caller graph for this function:

JSBool XPCNativeSet::FindMember ( jsval  name,
XPCNativeMember **  pMember,
XPCNativeInterface **  pInterface 
) const [inline]

Definition at line 440 of file xpcinlines.h.

{
    PRUint16 index;
    if(!FindMember(name, pMember, &index))
        return JS_FALSE;
    *pInterface = mInterfaces[index];
    return JS_TRUE;
}

Here is the call graph for this function:

JSBool XPCNativeSet::FindMember ( jsval  name,
XPCNativeMember **  pMember,
XPCNativeInterface **  pInterface,
XPCNativeSet protoSet,
JSBool pIsLocal 
) const [inline]

Definition at line 451 of file xpcinlines.h.

{
    XPCNativeMember* Member;
    XPCNativeInterface* Interface;
    XPCNativeMember* protoMember;

    if(!FindMember(name, &Member, &Interface))
        return JS_FALSE;

    *pMember = Member;
    *pInterface = Interface;

    *pIsLocal =
        !Member ||
        !protoSet ||
        (protoSet != this &&
         !protoSet->MatchesSetUpToInterface(this, Interface) &&
          (!protoSet->FindMember(name, &protoMember, (PRUint16*)nsnull) ||
           protoMember != Member));

    return JS_TRUE;
}

Here is the call graph for this function:

Definition at line 479 of file xpcinlines.h.

{
    XPCNativeInterface* const * pp = mInterfaces;

    for(int i = (int) mInterfaceCount; i > 0; i--, pp++)
    {
        XPCNativeInterface* iface = *pp;

        if(name == iface->GetName())
            return iface;
    }
    return nsnull;
}

Here is the call graph for this function:

Definition at line 1376 of file xpcprivate.h.

{return mInterfaces;}

Here is the caller graph for this function:

Definition at line 1378 of file xpcprivate.h.

        {NS_ASSERTION(i < mInterfaceCount, "bad index"); return mInterfaces[i];}

Here is the caller graph for this function:

Definition at line 1374 of file xpcprivate.h.

        {NS_ASSERTION(!IsMarked(), "bad"); return mInterfaceCount;}

Here is the caller graph for this function:

Definition at line 1373 of file xpcprivate.h.

{return mMemberCount;}

Here is the caller graph for this function:

Definition at line 532 of file xpcwrappednativeinfo.cpp.

{
    AutoMarkingNativeSetPtr set(ccx);

    AutoMarkingNativeInterfacePtr iface(ccx);
    iface = XPCNativeInterface::GetNewOrUsed(ccx, iid);
    if(!iface)
        return nsnull;

    XPCNativeSetKey key(nsnull, iface, 0);

    XPCJSRuntime* rt = ccx.GetRuntime();
    NativeSetMap* map = rt->GetNativeSetMap();
    if(!map)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        set = map->Find(&key);
    }

    if(set)
        return set;

    // hacky way to get a XPCNativeInterface** using the AutoPtr
    XPCNativeInterface* temp[] = {iface}; 
    set = NewInstance(ccx, temp, 1);
    if(!set)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeSet* set2 = map->Add(&key, set);
        if(!set2)
        {
            NS_ERROR("failed to add our set!");
            DestroyInstance(set);
            set = nsnull;
        }
        else if(set2 != set)
        {
            DestroyInstance(set);
            set = set2;
        }
    }

    return set;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XPCNativeSet * XPCNativeSet::GetNewOrUsed ( XPCCallContext ccx,
nsIClassInfo classInfo 
) [static]

Definition at line 583 of file xpcwrappednativeinfo.cpp.

{
    AutoMarkingNativeSetPtr set(ccx);
    XPCJSRuntime* rt = ccx.GetRuntime();

    ClassInfo2NativeSetMap* map = rt->GetClassInfo2NativeSetMap();
    if(!map)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        set = map->Find(classInfo);
    }

    if(set)
        return set;

    nsIID** iidArray = nsnull;
    AutoMarkingNativeInterfacePtrArrayPtr interfaceArray(ccx);
    PRUint32 iidCount = 0;

    if(NS_FAILED(classInfo->GetInterfaces(&iidCount, &iidArray)))
    {
        // Note: I'm making it OK for this call to fail so that one can add
        // nsIClassInfo to classes implemented in script without requiring this
        // method to be implemented.

        // Make sure these are set correctly...
        iidArray = nsnull;
        iidCount = 0;
    }

    NS_ASSERTION((iidCount && iidArray) || !(iidCount || iidArray), "GetInterfaces returned bad array");

    // !!! from here on we only exit through the 'out' label !!!

    if(iidCount)
    {
        AutoMarkingNativeInterfacePtrArrayPtr
            arr(ccx, new XPCNativeInterface*[iidCount], iidCount, PR_TRUE);
        if (!arr)
            goto out;

        interfaceArray = arr;

        XPCNativeInterface** currentInterface = interfaceArray;
        nsIID**              currentIID = iidArray;
        PRUint16             interfaceCount = 0;

        for(PRUint32 i = 0; i < iidCount; i++)
        {
            nsIID* iid = *(currentIID++);
            if (!iid) {
                NS_ERROR("Null found in classinfo interface list");
                continue;
            }

            XPCNativeInterface* iface =
                XPCNativeInterface::GetNewOrUsed(ccx, iid);

            if(!iface)
            {
                // XXX warn here
                continue;
            }

            *(currentInterface++) = iface;
            interfaceCount++;
        }

        if(interfaceCount)
        {
            set = NewInstance(ccx, interfaceArray, interfaceCount);
            if(set)
            {
                NativeSetMap* map2 = rt->GetNativeSetMap();
                if(!map2)
                    goto out;

                XPCNativeSetKey key(set, nsnull, 0);

                {   // scoped lock
                    XPCAutoLock lock(rt->GetMapLock());
                    XPCNativeSet* set2 = map2->Add(&key, set);
                    if(!set2)
                    {
                        NS_ERROR("failed to add our set!");
                        DestroyInstance(set);
                        set = nsnull;
                        goto out;
                    }
                    if(set2 != set)
                    {
                        DestroyInstance(set);
                        set = set2;
                    }
                }
            }
        }
        else
            set = GetNewOrUsed(ccx, &NS_GET_IID(nsISupports));
    }
    else
        set = GetNewOrUsed(ccx, &NS_GET_IID(nsISupports));

    if(set)
    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeSet* set2 = map->Add(classInfo, set);
        NS_ASSERTION(set2, "failed to add our set!");
        NS_ASSERTION(set2 == set, "hashtables inconsistent!");
    }

out:
    if(iidArray)
        NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(iidCount, iidArray);
    if(interfaceArray)
        delete [] interfaceArray.get();

    return set;
}

Here is the call graph for this function:

XPCNativeSet * XPCNativeSet::GetNewOrUsed ( XPCCallContext ccx,
XPCNativeSet otherSet,
XPCNativeInterface newInterface,
PRUint16  position 
) [static]

Definition at line 722 of file xpcwrappednativeinfo.cpp.

{
    AutoMarkingNativeSetPtr set(ccx);
    XPCJSRuntime* rt = ccx.GetRuntime();
    NativeSetMap* map = rt->GetNativeSetMap();
    if(!map)
        return nsnull;

    XPCNativeSetKey key(otherSet, newInterface, position);

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        set = map->Find(&key);
    }

    if(set)
        return set;

    if(otherSet)
        set = NewInstanceMutate(otherSet, newInterface, position);
    else
        set = NewInstance(ccx, &newInterface, 1);

    if(!set)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeSet* set2 = map->Add(&key, set);
        if(!set2)
        {
            NS_ERROR("failed to add our set!");
            DestroyInstance(set);
            set = nsnull;
        }
        else if(set2 != set)
        {
            DestroyInstance(set);
            set = set2;
        }
    }

    return set;
}

Here is the call graph for this function:

JSBool XPCNativeSet::HasInterface ( XPCNativeInterface aInterface) const [inline]

Definition at line 509 of file xpcinlines.h.

{
    XPCNativeInterface* const * pp = mInterfaces;

    for(int i = (int) mInterfaceCount; i > 0; i--, pp++)
    {
        if(aInterface == *pp)
            return JS_TRUE;
    }
    return JS_FALSE;
}

Here is the caller graph for this function:

Definition at line 522 of file xpcinlines.h.

{
    const nsIID* iid = aInterface->GetIID();

    // We can safely skip the first interface which is *always* nsISupports.
    XPCNativeInterface* const * pp = mInterfaces+1;
    for(int i = (int) mInterfaceCount; i > 1; i--, pp++)
        if((*pp)->HasAncestor(iid))
            return JS_TRUE;

    // This is rare, so check last.
    if(iid == &NS_GET_IID(nsISupports))
        return PR_TRUE;

    return JS_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

JSBool XPCNativeSet::IsMarked ( ) const [inline]

Definition at line 1396 of file xpcprivate.h.

Here is the caller graph for this function:

void XPCNativeSet::Mark ( ) [inline]

Definition at line 559 of file xpcinlines.h.

{
    if(IsMarked())
        return;

    XPCNativeInterface* const * pp = mInterfaces;

    for(int i = (int) mInterfaceCount; i > 0; i--, pp++)
        (*pp)->Mark();

    MarkSelfOnly();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1389 of file xpcprivate.h.

{}
void XPCNativeSet::MarkSelfOnly ( ) [inline, private]

Definition at line 1393 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 540 of file xpcinlines.h.

{
    int count = JS_MIN((int)mInterfaceCount, (int)other->mInterfaceCount);

    XPCNativeInterface* const * pp1 = mInterfaces;
    XPCNativeInterface* const * pp2 = other->mInterfaces;

    for(int i = (int) count; i > 0; i--, pp1++, pp2++)
    {
        XPCNativeInterface* cur = (*pp1);
        if(cur != (*pp2))
            return JS_FALSE;
        if(cur == iface)
            return JS_TRUE;
    }
    return JS_FALSE;
}

Here is the caller graph for this function:

XPCNativeSet * XPCNativeSet::NewInstance ( XPCCallContext ccx,
XPCNativeInterface **  array,
PRUint16  count 
) [static, protected]

Definition at line 772 of file xpcwrappednativeinfo.cpp.

{
    XPCNativeSet* obj = nsnull;

    if(!array || !count)
        return nsnull;

    // We impose the invariant:
    // "All sets have exactly one nsISupports interface and it comes first."
    // This is the place where we impose that rule - even if given inputs
    // that don't exactly follow the rule.

    XPCNativeInterface* isup = XPCNativeInterface::GetISupports(ccx);
    PRUint16 slots = count+1;

    PRUint16 i;
    XPCNativeInterface** pcur;

    for(i = 0, pcur = array; i < count; i++, pcur++)
    {
        if(*pcur == isup)
            slots--;
    }

    // Use placement new to create an object with the right amount of space
    // to hold the members array
    int size = sizeof(XPCNativeSet);
    if(slots > 1)
        size += (slots - 1) * sizeof(XPCNativeInterface*);
    void* place = new char[size];
    if(place)
        obj = new(place) XPCNativeSet();

    if(obj)
    {
        // Stick the nsISupports in front and skip additional nsISupport(s)
        XPCNativeInterface** inp = array;
        XPCNativeInterface** outp = (XPCNativeInterface**) &obj->mInterfaces;
        PRUint16 memberCount = 1;   // for the one member in nsISupports

        *(outp++) = isup;

        for(i = 0; i < count; i++)
        {
            XPCNativeInterface* cur;

            if(isup == (cur = *(inp++)))
                continue;
            *(outp++) = cur;
            memberCount += cur->GetMemberCount();
        }
        obj->mMemberCount = memberCount;
        obj->mInterfaceCount = slots;
    }

    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XPCNativeSet * XPCNativeSet::NewInstanceMutate ( XPCNativeSet otherSet,
XPCNativeInterface newInterface,
PRUint16  position 
) [static, protected]

Definition at line 834 of file xpcwrappednativeinfo.cpp.

{
    XPCNativeSet* obj = nsnull;

    if(!newInterface)
        return nsnull;
    if(otherSet && position > otherSet->mInterfaceCount)
        return nsnull;

    // Use placement new to create an object with the right amount of space
    // to hold the members array
    int size = sizeof(XPCNativeSet);
    if(otherSet)
        size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
    void* place = new char[size];
    if(place)
        obj = new(place) XPCNativeSet();

    if(obj)
    {
        if(otherSet)
        {
            obj->mMemberCount = otherSet->GetMemberCount() +
                                newInterface->GetMemberCount();
            obj->mInterfaceCount = otherSet->mInterfaceCount + 1;

            XPCNativeInterface** src = otherSet->mInterfaces;
            XPCNativeInterface** dest = obj->mInterfaces;
            for(PRUint16 i = 0; i < obj->mInterfaceCount; i++)
            {
                if(i == position)
                    *dest++ = newInterface;
                else
                    *dest++ = *src++;
            }
        }
        else
        {
            obj->mMemberCount = newInterface->GetMemberCount();
            obj->mInterfaceCount = 1;
            obj->mInterfaces[0] = newInterface;
        }
    }

    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* XPCNativeSet::operator new ( size_t  ,
void p 
) [inline, protected]

Definition at line 1416 of file xpcprivate.h.

{return p;}
void XPCNativeSet::Unmark ( ) [inline]

Definition at line 1395 of file xpcprivate.h.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1420 of file xpcprivate.h.

Definition at line 1421 of file xpcprivate.h.

Definition at line 1419 of file xpcprivate.h.


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