Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
XPCDispInterface Class Reference

IDispatch interface information. More...

#include <XPCDispPrivate.h>

Collaboration diagram for XPCDispInterface:
Collaboration graph
[legend]

List of all members.

Classes

class  Allocator
 Small utility to count members needed for XPConnect XPConnect has one entry for a property while IDispatch can have two Generally interfaces are small enough, that linear searching should be ok. More...
class  Member
 Member information. More...

Public Member Functions

JSObjectGetJSObject () const
 Returns the JSObject for the tearoff.
void SetJSObject (JSObject *jsobj)
 Sets the JSObject for the tearoff.
const MemberFindMember (jsval name) const
 Locates the member by name.
const MemberFindMemberCI (XPCCallContext &ccx, jsval name) const
 Looksup a member ignoring case TODO: We should look at performance issues concerning this.
const MemberGetMember (PRUint32 index)
 Returns a member via index.
PRUint32 GetMemberCount () const
 Returns the number of members.
void operator delete (void *p)
 Delete operator that frees up the memory allocated to the object.
 ~XPCDispInterface ()
 Cleans up the members.

Static Public Member Functions

static XPCDispInterfaceNewInstance (JSContext *cx, nsISupports *pIface)
 Creates a new instance of XPCDispInterface.

Private Member Functions

 XPCDispInterface (JSContext *cx, ITypeInfo *pTypeInfo, PRUint32 members)
 Initializes the object's members.
voidoperator new (size_t, PRUint32 members) CPP_THROW_NEW
 Allocates the memory for the object.
PRBool InspectIDispatch (JSContext *cx, ITypeInfo *pTypeInfo, PRUint32 members)
 Inspects the type information and stores it in this object.

Private Attributes

JSObjectmJSObject
 This stores the JSObject for the tearoff, since this object is stored as the JSObject * in the tearoff.
PRUint32 mMemberCount
Member mMembers [1]

Friends

class Allocator
 Friendship need to gain access to private operator new.

Detailed Description

IDispatch interface information.

This is used within the XPCWrappedNativeTearOff to collect and maintain information for a specific IDispatch interface. This is similar to XPCNativeInterface

Definition at line 687 of file XPCDispPrivate.h.


Constructor & Destructor Documentation

Cleans up the members.

Definition at line 349 of file XPCDispInlines.h.

{
    // Cleanup our members, the first gets cleaned up by the destructor
    // We have to cleanup the rest manually. These members are allocated
    // as part of the XPCIDispInterface object at the end
    for(PRUint32 index = 1; index < GetMemberCount(); ++index)
    {
        mMembers[index].~Member();
    }
}

Here is the call graph for this function:

XPCDispInterface::XPCDispInterface ( JSContext cx,
ITypeInfo *  pTypeInfo,
PRUint32  members 
) [inline, private]

Initializes the object's members.

Parameters:
cxa JS context
pTypeInfopointer to the type type information
membersnumber of members for the object

Definition at line 361 of file XPCDispInlines.h.

                                                     : mJSObject(nsnull)
{
    InspectIDispatch(cx, pTypeInfo, members);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Locates the member by name.

Parameters:
namethe name of the member to be returned
Returns:
pointer to the member found, nsnull if not found

Definition at line 313 of file XPCDispInlines.h.

{
    // Iterate backwards to save time
    const Member* member = mMembers + mMemberCount;
    while(member > mMembers)
    {
        --member;
        if(name == member->GetName())
        {
            return member;
        }
    }
    return nsnull;
}

Here is the call graph for this function:

Looksup a member ignoring case TODO: We should look at performance issues concerning this.

Parameters:
ccxA call context
nameThe name of the member
Returns:
A pointer to a member or nsnull if not found

Definition at line 301 of file XPCDispInterface.cpp.

{
    size_t nameLength;
    PRUnichar* sName = xpc_JSString2PRUnichar(ccx, name, &nameLength);
    if(!sName)
        return nsnull;
    // Iterate backwards over the members array (more efficient)
    const Member* member = mMembers + mMemberCount;
    while(member > mMembers)
    {
        --member;
        if(CaseInsensitiveCompare(ccx, sName, nameLength, member->GetName()))
        {
            return member;
        }
    }
    return nsnull;
}

Here is the call graph for this function:

Returns the JSObject for the tearoff.

Returns:
pointer to the JSObject
See also:
mJSObject

Definition at line 301 of file XPCDispInlines.h.

{
    return mJSObject;
}

Here is the caller graph for this function:

Returns a member via index.

Parameters:
indexthe index of the parameter
Returns:
reference to the member in the array

Definition at line 330 of file XPCDispInlines.h.

{ 
    NS_ASSERTION(index < mMemberCount, "invalid index");
    return mMembers[index]; 
}

Here is the caller graph for this function:

Returns the number of members.

Returns:
the number of members

Definition at line 337 of file XPCDispInlines.h.

{
    return mMemberCount;
}

Here is the caller graph for this function:

PRBool XPCDispInterface::InspectIDispatch ( JSContext cx,
ITypeInfo *  pTypeInfo,
PRUint32  members 
) [private]

Inspects the type information and stores it in this object.

Parameters:
cxa JS context
pTypeInfopointer to the type information for the object
membersnumber of members in the interface
Returns:
PR_TRUE if it worked, PR_FALSE if it didn't (usually out of memory)

Definition at line 220 of file XPCDispInterface.cpp.

{
    HRESULT hResult;

    XPCDispInterface::Member * pInfo = mMembers;
    mMemberCount = 0;
    for(PRUint32 index = 0; index < members; index++ )
    {
        FUNCDESC* pFuncDesc;
        hResult = pTypeInfo->GetFuncDesc(index, &pFuncDesc );
        if(FAILED(hResult))
            continue;
        if(IsReflectable(pFuncDesc))
        {
            switch(pFuncDesc->invkind)
            {
                case INVOKE_PROPERTYPUT:
                case INVOKE_PROPERTYPUTREF:
                case INVOKE_PROPERTYGET:
                {
                    XPCDispInterface::Member * pExisting = FindExistingMember(mMembers, pInfo, pFuncDesc->memid);
                    if(pExisting == pInfo)
                    {
                        if(InitializeMember(cx, pTypeInfo, pFuncDesc, pInfo))
                        {
                            ++pInfo;
                            ++mMemberCount;
                        }
                    }
                    else
                    {
                        ConvertInvokeKind(pFuncDesc->invkind, *pExisting);
                    }
                    if(pFuncDesc->invkind == INVOKE_PROPERTYGET)
                    {
                        pExisting->SetGetterFuncDesc(pFuncDesc);
                    }
                }
                break;
                case INVOKE_FUNC:
                {
                    if(InitializeMember(cx, pTypeInfo, pFuncDesc, pInfo))
                    {
                        ++pInfo;
                        ++mMemberCount;
                    }
                }
                break;
                default:
                    pTypeInfo->ReleaseFuncDesc(pFuncDesc);
                break;
            }
        }
        else
        {
            pTypeInfo->ReleaseFuncDesc(pFuncDesc);
        }
    }
    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

XPCDispInterface * XPCDispInterface::NewInstance ( JSContext cx,
nsISupports *  pIface 
) [static]

Creates a new instance of XPCDispInterface.

Parameters:
cxa JS Context
pIfacethe interface pointer to the object
Returns:
new instance of XPCDispInterface

Definition at line 113 of file XPCDispInterface.cpp.

{
    CComQIPtr<IDispatch> pDispatch(NS_REINTERPRET_CAST(IUnknown*,pIface));

    if(pDispatch)
    {
        unsigned int count;
        HRESULT hr = pDispatch->GetTypeInfoCount(&count);
        if(SUCCEEDED(hr) && count > 0)
        {
            CComPtr<ITypeInfo> pTypeInfo;
            hr = pDispatch->GetTypeInfo(0,LOCALE_SYSTEM_DEFAULT, &pTypeInfo);
            if(SUCCEEDED(hr))
            {
                Allocator allocator(cx, pTypeInfo);
                return allocator.Allocate();
            }
        }
    }
    return nsnull;
}

Here is the call graph for this function:

void XPCDispInterface::operator delete ( void p) [inline]

Delete operator that frees up the memory allocated to the object.

Parameters:
ppointer to the objects memory

Definition at line 343 of file XPCDispInlines.h.

{
    PR_Free(p);
}
void * XPCDispInterface::operator new ( size_t  ,
PRUint32  members 
) [inline, private]

Allocates the memory for the object.

Parameters:
membersnumber of members in this interface
Returns:
pointer to the memory for the object

Definition at line 368 of file XPCDispInlines.h.

{
    // Must allow for the member in XPCDispInterface
    if(!members)
        members = 1;
    // Calculate the size needed for the base XPCDispInterface and its members
    return PR_Malloc(sizeof(XPCDispInterface) + sizeof(Member) * (members - 1));
}

Sets the JSObject for the tearoff.

Parameters:
jsobjthe object being assigned
See also:
GetJSObject() const

Definition at line 307 of file XPCDispInlines.h.

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class Allocator [friend]

Friendship need to gain access to private operator new.

Definition at line 1055 of file XPCDispPrivate.h.


Member Data Documentation

This stores the JSObject for the tearoff, since this object is stored as the JSObject * in the tearoff.

Definition at line 982 of file XPCDispPrivate.h.

Definition at line 983 of file XPCDispPrivate.h.

Definition at line 984 of file XPCDispPrivate.h.


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