Back to index

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

#include <xpcprivate.h>

Collaboration diagram for XPCNativeInterface:
Collaboration graph
[legend]

List of all members.

Public Member Functions

nsIInterfaceInfoGetInterfaceInfo () const
jsval GetName () const
const nsIIDGetIID () const
const char * GetNameString () const
XPCNativeMemberFindMember (jsval name) const
JSBool HasAncestor (const nsIID *iid) const
const char * GetMemberName (XPCCallContext &ccx, const XPCNativeMember *member) const
PRUint16 GetMemberCount () const
XPCNativeMemberGetMemberAt (PRUint16 i)
void DealWithDyingGCThings (JSContext *cx, XPCJSRuntime *rt)
void DebugDump (PRInt16 depth)
void Mark ()
void Unmark ()
JSBool IsMarked () const
void MarkBeforeJSFinalize (JSContext *)
void AutoMark (JSContext *)

Static Public Member Functions

static XPCNativeInterfaceGetNewOrUsed (XPCCallContext &ccx, const nsIID *iid)
static XPCNativeInterfaceGetNewOrUsed (XPCCallContext &ccx, nsIInterfaceInfo *info)
static XPCNativeInterfaceGetNewOrUsed (XPCCallContext &ccx, const char *name)
static XPCNativeInterfaceGetISupports (XPCCallContext &ccx)
static void DestroyInstance (JSContext *cx, XPCJSRuntime *rt, XPCNativeInterface *inst)

Protected Member Functions

 XPCNativeInterface ()
 XPCNativeInterface (nsIInterfaceInfo *aInfo, jsval aName)
 ~XPCNativeInterface ()
voidoperator new (size_t, void *p) CPP_THROW_NEW
 XPCNativeInterface (const XPCNativeInterface &r)
XPCNativeInterfaceoperator= (const XPCNativeInterface &r)

Static Protected Member Functions

static XPCNativeInterfaceNewInstance (XPCCallContext &ccx, nsIInterfaceInfo *aInfo)

Private Attributes

nsCOMPtr< nsIInterfaceInfomInfo
jsval mName
PRUint16 mMemberCount
XPCNativeMember mMembers [1]

Detailed Description

Definition at line 1220 of file xpcprivate.h.


Constructor & Destructor Documentation

Here is the caller graph for this function:

XPCNativeInterface::XPCNativeInterface ( nsIInterfaceInfo aInfo,
jsval  aName 
) [inline, protected]

Definition at line 1271 of file xpcprivate.h.

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

Definition at line 1274 of file xpcprivate.h.

Here is the caller graph for this function:


Member Function Documentation

Definition at line 1261 of file xpcprivate.h.

{}

Definition at line 392 of file xpcinlines.h.

{
    XPCNativeMember* member = mMembers;
    for(int i = (int) mMemberCount; i > 0; i--, member++)
        member->DealWithDyingGCThings(cx, rt);
}

Here is the call graph for this function:

Definition at line 514 of file xpcwrappednativeinfo.cpp.

{
#ifdef DEBUG
    depth--;
    XPC_LOG_ALWAYS(("XPCNativeInterface @ %x", this));
        XPC_LOG_INDENT();
        XPC_LOG_ALWAYS(("name is %s", GetNameString()));
        XPC_LOG_ALWAYS(("mMemberCount is %d", mMemberCount));
        XPC_LOG_ALWAYS(("mInfo @ %x", mInfo.get()));
        XPC_LOG_OUTDENT();
#endif
}

Here is the call graph for this function:

Definition at line 499 of file xpcwrappednativeinfo.cpp.

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

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 374 of file xpcinlines.h.

{
    const XPCNativeMember* member = mMembers;
    for(int i = (int) mMemberCount; i > 0; i--, member++)
        if(member->GetName() == name)
            return NS_CONST_CAST(XPCNativeMember*, member);
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const nsIID * XPCNativeInterface::GetIID ( ) const [inline]

Definition at line 360 of file xpcinlines.h.

{
    const nsIID* iid;
    return NS_SUCCEEDED(mInfo->GetIIDShared(&iid)) ? iid : nsnull;
}

Here is the caller graph for this function:

Definition at line 1231 of file xpcprivate.h.

{return mInfo.get();}

Here is the caller graph for this function:

Definition at line 315 of file xpcwrappednativeinfo.cpp.

{
    // XXX We should optimize this to cache this common XPCNativeInterface.
    return GetNewOrUsed(ccx, &NS_GET_IID(nsISupports));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1245 of file xpcprivate.h.

        {NS_ASSERTION(i < mMemberCount, "bad index"); return &mMembers[i];}

Here is the caller graph for this function:

Definition at line 1243 of file xpcprivate.h.

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

Here is the caller graph for this function:

Definition at line 507 of file xpcwrappednativeinfo.cpp.

{
    return JS_GetStringBytes(JSVAL_TO_STRING(member->GetName()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

jsval XPCNativeInterface::GetName ( ) const [inline]

Definition at line 1232 of file xpcprivate.h.

{return mName;}

Here is the caller graph for this function:

const char * XPCNativeInterface::GetNameString ( ) const [inline]

Definition at line 367 of file xpcinlines.h.

{
    const char* name;
    return NS_SUCCEEDED(mInfo->GetNameShared(&name)) ? name : nsnull;
}

Here is the caller graph for this function:

Definition at line 212 of file xpcwrappednativeinfo.cpp.

{
    AutoMarkingNativeInterfacePtr iface(ccx);
    XPCJSRuntime* rt = ccx.GetRuntime();

    IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();
    if(!map)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        iface = map->Find(*iid);
    }

    if(iface)
        return iface;

    nsCOMPtr<nsIInterfaceInfo> info;
    ccx.GetXPConnect()->GetInfoForIID(iid, getter_AddRefs(info));
    if(!info)
        return nsnull;

    iface = NewInstance(ccx, info);
    if(!iface)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeInterface* iface2 = map->Add(iface);
        if(!iface2)
        {
            NS_ERROR("failed to add our interface!");
            DestroyInstance(ccx, rt, iface);
            iface = nsnull;
        }
        else if(iface2 != iface)
        {
            DestroyInstance(ccx, rt, iface);
            iface = iface2;
        }
    }

    return iface;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 259 of file xpcwrappednativeinfo.cpp.

{
    AutoMarkingNativeInterfacePtr iface(ccx);

    const nsIID* iid;
    if(NS_FAILED(info->GetIIDShared(&iid)) || !iid)
        return nsnull;

    XPCJSRuntime* rt = ccx.GetRuntime();

    IID2NativeInterfaceMap* map = rt->GetIID2NativeInterfaceMap();
    if(!map)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        iface = map->Find(*iid);
    }

    if(iface)
        return iface;

    iface = NewInstance(ccx, info);
    if(!iface)
        return nsnull;

    {   // scoped lock
        XPCAutoLock lock(rt->GetMapLock());
        XPCNativeInterface* iface2 = map->Add(iface);
        if(!iface2)
        {
            NS_ERROR("failed to add our interface!");
            DestroyInstance(ccx, rt, iface);
            iface = nsnull;
        }
        else if(iface2 != iface)
        {
            DestroyInstance(ccx, rt, iface);
            iface = iface2;
        }
    }

    return iface;
}

Here is the call graph for this function:

Definition at line 306 of file xpcwrappednativeinfo.cpp.

Here is the call graph for this function:

Definition at line 384 of file xpcinlines.h.

{
    PRBool found = PR_FALSE;
    mInfo->HasAncestor(iid, &found);
    return found;
}

Definition at line 1256 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1254 of file xpcprivate.h.

Here is the caller graph for this function:

Definition at line 1260 of file xpcprivate.h.

{}

Definition at line 323 of file xpcwrappednativeinfo.cpp.

{
    static const PRUint16 MAX_LOCAL_MEMBER_COUNT = 16;
    XPCNativeMember local_members[MAX_LOCAL_MEMBER_COUNT];
    XPCNativeInterface* obj = nsnull;
    XPCNativeMember* members = nsnull;

    int i;
    JSBool failed = JS_FALSE;
    PRUint16 constCount;
    PRUint16 methodCount;
    PRUint16 totalCount;
    PRUint16 realTotalCount = 0;
    XPCNativeMember* cur;
    JSString*  str;
    jsval name;
    jsval interfaceName;

    // XXX Investigate lazy init? This is a problem given the
    // 'placement new' scheme - we need to at least know how big to make
    // the object. We might do a scan of methods to determine needed size,
    // then make our object, but avoid init'ing *any* members until asked?
    // Find out how often we create these objects w/o really looking at
    // (or using) the members.

    PRBool canScript;
    if(NS_FAILED(aInfo->IsScriptable(&canScript)) || !canScript)
        return nsnull;

    if(NS_FAILED(aInfo->GetMethodCount(&methodCount)) ||
       NS_FAILED(aInfo->GetConstantCount(&constCount)))
        return nsnull;

    // If the interface does not have nsISupports in its inheritance chain
    // then we know we can't reflect its methods. However, some interfaces that
    // are used just to reflect constants are declared this way. We need to
    // go ahead and build the thing. But, we'll ignore whatever methods it may
    // have.
    if(!nsXPConnect::IsISupportsDescendant(aInfo))
        methodCount = 0;

    totalCount = methodCount + constCount;

    if(totalCount > MAX_LOCAL_MEMBER_COUNT)
    {
        members = new XPCNativeMember[totalCount];
        if(!members)
            return nsnull;
    }
    else
    {
        members = local_members;
    }

    // NOTE: since getters and setters share a member, we might not use all
    // of the member objects.

    for(i = 0; i < methodCount; i++)
    {
        const nsXPTMethodInfo* info;
        if(NS_FAILED(aInfo->GetMethodInfo(i, &info)))
        {
            failed = JS_TRUE;
            break;
        }

        // don't reflect Addref or Release
        if(i == 1 || i == 2)
            continue;

        if(!XPCConvert::IsMethodReflectable(*info))
            continue;

        str = JS_InternString(ccx, info->GetName());
        if(!str)
        {
            NS_ASSERTION(0,"bad method name");
            failed = JS_TRUE;
            break;
        }
        name = STRING_TO_JSVAL(str);

        if(info->IsSetter())
        {
            NS_ASSERTION(realTotalCount,"bad setter");
            // Note: ASSUMES Getter/Setter pairs are next to each other
            // This is a rule of the typelib spec.
            cur = &members[realTotalCount-1];
            NS_ASSERTION(cur->GetName() == name,"bad setter");
            NS_ASSERTION(cur->IsReadOnlyAttribute(),"bad setter");
            NS_ASSERTION(cur->GetIndex() == i-1,"bad setter");
            cur->SetWritableAttribute();
        }
        else
        {
            // XXX need better way to find dups
            // NS_ASSERTION(!LookupMemberByID(name),"duplicate method name");
            cur = &members[realTotalCount++];
            cur->SetName(name);
            if(info->IsGetter())
                cur->SetReadOnlyAttribute(i);
            else
                cur->SetMethod(i);
        }
    }

    if(!failed)
    {
        for(i = 0; i < constCount; i++)
        {
            const nsXPTConstant* constant;
            if(NS_FAILED(aInfo->GetConstant(i, &constant)))
            {
                failed = JS_TRUE;
                break;
            }

            str = JS_InternString(ccx, constant->GetName());
            if(!str)
            {
                NS_ASSERTION(0,"bad constant name");
                failed = JS_TRUE;
                break;
            }
            name = STRING_TO_JSVAL(str);

            // XXX need better way to find dups
            //NS_ASSERTION(!LookupMemberByID(name),"duplicate method/constant name");

            cur = &members[realTotalCount++];
            cur->SetName(name);
            cur->SetConstant(i);
        }
    }

    if(!failed)
    {
        const char* bytes;
        if(NS_FAILED(aInfo->GetNameShared(&bytes)) || !bytes ||
           nsnull == (str = JS_InternString(ccx, bytes)))
        {
            failed = JS_TRUE;
        }
        interfaceName = STRING_TO_JSVAL(str);
    }

    if(!failed)
    {
        // Use placement new to create an object with the right amount of space
        // to hold the members array
        int size = sizeof(XPCNativeInterface);
        if(realTotalCount > 1)
            size += (realTotalCount - 1) * sizeof(XPCNativeMember);
        void* place = new char[size];
        if(place)
            obj = new(place) XPCNativeInterface(aInfo, interfaceName);

        if(obj)
        {
            obj->mMemberCount = realTotalCount;
            // copy valid members
            if(realTotalCount)
                memcpy(obj->mMembers, members,
                       realTotalCount * sizeof(XPCNativeMember));
        }
    }

    if(members && members != local_members)
        delete [] members;

    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1276 of file xpcprivate.h.

{return p;}
XPCNativeInterface& XPCNativeInterface::operator= ( const XPCNativeInterface r) [protected]

Definition at line 1255 of file xpcprivate.h.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1282 of file xpcprivate.h.

Definition at line 1284 of file xpcprivate.h.

Definition at line 1285 of file xpcprivate.h.

Definition at line 1283 of file xpcprivate.h.


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