Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes | Friends
nsProxyObject Class Reference

import "nsIProxyObjectManager.idl";

Collaboration diagram for nsProxyObject:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsProxyObject (nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject, nsIEventQueueService *eventQService)
 nsProxyObject (nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, nsIEventQueueService *eventQService)
void AddRef ()
void Release ()
 ~nsProxyObject ()
nsresult Post (PRUint32 methodIndex, nsXPTMethodInfo *info, nsXPTCMiniVariant *params, nsIInterfaceInfo *interfaceInfo)
nsresult PostAndWait (nsProxyObjectCallInfo *proxyInfo)
nsISupports * GetRealObject () const
nsIEventQueueGetQueue () const
PRInt32 GetProxyType () const
 nsProxyObject (nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject, nsIEventQueueService *eventQService)
 nsProxyObject (nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, nsIEventQueueService *eventQService)
void AddRef ()
void Release ()
 ~nsProxyObject ()
nsresult Post (PRUint32 methodIndex, nsXPTMethodInfo *info, nsXPTCMiniVariant *params, nsIInterfaceInfo *interfaceInfo)
nsresult PostAndWait (nsProxyObjectCallInfo *proxyInfo)
nsISupports * GetRealObject () const
nsIEventQueueGetQueue () const
PRInt32 GetProxyType () const

Private Member Functions

nsresult convertMiniVariantToVariant (nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant *params, nsXPTCVariant **fullParam, uint8 *paramCount)
nsresult convertMiniVariantToVariant (nsXPTMethodInfo *methodInfo, nsXPTCMiniVariant *params, nsXPTCVariant **fullParam, uint8 *paramCount)

Private Attributes

nsAutoRefCnt mRefCnt
PRInt32 mProxyType
nsCOMPtr< nsIEventQueuemDestQueue
nsCOMPtr< nsISupports > mRealObject
nsCOMPtr< nsIEventQueueServicemEventQService

Friends

class nsProxyEventObject

Detailed Description

Definition at line 91 of file nsIProxyObjectManager.idl.


Constructor & Destructor Documentation

nsProxyObject::nsProxyObject ( nsIEventQueue destQueue,
PRInt32  proxyType,
nsISupports *  realObject,
nsIEventQueueService eventQService 
)

Definition at line 270 of file nsProxyEvent.cpp.

{
    mEventQService = eventQService;

    mRealObject      = realObject;
    mDestQueue       = do_QueryInterface(destQueue);
    mProxyType       = proxyType;
}

Here is the call graph for this function:

nsProxyObject::nsProxyObject ( nsIEventQueue destQueue,
PRInt32  proxyType,
const nsCID aClass,
nsISupports *  aDelegate,
const nsIID aIID,
nsIEventQueueService eventQService 
)

Definition at line 281 of file nsProxyEvent.cpp.

{
    mEventQService = eventQService;

    nsCOMPtr<nsIComponentManager> compMgr;
    NS_GetComponentManager(getter_AddRefs(compMgr));
    compMgr->CreateInstance(aClass, 
                            aDelegate,
                            aIID,
                            getter_AddRefs(mRealObject));

    mDestQueue       = do_QueryInterface(destQueue);
    mProxyType       = proxyType;
}

Here is the call graph for this function:

Definition at line 297 of file nsProxyEvent.cpp.

{   
    // I am worried about order of destruction here.  
    // do not remove assignments.
    
    mRealObject = 0;
    mDestQueue  = 0;
}
nsProxyObject::nsProxyObject ( nsIEventQueue destQueue,
PRInt32  proxyType,
nsISupports *  realObject,
nsIEventQueueService eventQService 
)
nsProxyObject::nsProxyObject ( nsIEventQueue destQueue,
PRInt32  proxyType,
const nsCID aClass,
nsISupports *  aDelegate,
const nsIID aIID,
nsIEventQueueService eventQService 
)

Member Function Documentation

Definition at line 308 of file nsProxyEvent.cpp.

{
  PR_AtomicIncrement((PRInt32 *)&mRefCnt);
  NS_LOG_ADDREF(this, mRefCnt, "nsProxyObject", sizeof(*this));
}

Here is the call graph for this function:

nsresult nsProxyObject::convertMiniVariantToVariant ( nsXPTMethodInfo methodInfo,
nsXPTCMiniVariant params,
nsXPTCVariant **  fullParam,
uint8 paramCount 
) [private]
nsresult nsProxyObject::convertMiniVariantToVariant ( nsXPTMethodInfo methodInfo,
nsXPTCMiniVariant params,
nsXPTCVariant **  fullParam,
uint8 paramCount 
) [private]

Definition at line 408 of file nsProxyEvent.cpp.

{
    uint8 paramCount = methodInfo->GetParamCount();
    *outParamCount = paramCount;
    *fullParam = nsnull;

    if (!paramCount) return NS_OK;
        
    *fullParam = (nsXPTCVariant*)malloc(sizeof(nsXPTCVariant) * paramCount);
    
    if (*fullParam == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
    
    for (int i = 0; i < paramCount; i++)
    {
        const nsXPTParamInfo& paramInfo = methodInfo->GetParam(i);
        if ((mProxyType & PROXY_ASYNC) && paramInfo.IsDipper())
        {
            NS_WARNING("Async proxying of out parameters is not supported"); 
            return NS_ERROR_PROXY_INVALID_OUT_PARAMETER;
        }
        uint8 flags = paramInfo.IsOut() ? nsXPTCVariant::PTR_IS_DATA : 0;
        (*fullParam)[i].Init(params[i], paramInfo.GetType(), flags);
    }
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file nsProxyEvent.h.

{ return mProxyType; }

Definition at line 112 of file nsIProxyObjectManager.idl.

Definition at line 110 of file nsProxyEvent.h.

{ return mDestQueue; }

Definition at line 111 of file nsIProxyObjectManager.idl.

nsISupports* nsProxyObject::GetRealObject ( ) const [inline]

Definition at line 109 of file nsProxyEvent.h.

{ return mRealObject; }
nsISupports* nsProxyObject::GetRealObject ( ) const [inline]

Definition at line 110 of file nsIProxyObjectManager.idl.

nsresult nsProxyObject::Post ( PRUint32  methodIndex,
nsXPTMethodInfo info,
nsXPTCMiniVariant params,
nsIInterfaceInfo interfaceInfo 
)
nsresult nsProxyObject::Post ( PRUint32  methodIndex,
nsXPTMethodInfo info,
nsXPTCMiniVariant params,
nsIInterfaceInfo interfaceInfo 
)

Definition at line 440 of file nsProxyEvent.cpp.

{
    nsresult rv = NS_OK; 

    if (! mDestQueue  || ! mRealObject)
        return NS_ERROR_OUT_OF_MEMORY;

    if (methodInfo->IsNotXPCOM())
        return NS_ERROR_PROXY_INVALID_IN_PARAMETER;
    
    nsXPTCVariant *fullParam;
    uint8 paramCount; 
    rv = convertMiniVariantToVariant(methodInfo, params, &fullParam, &paramCount);
    
    if (NS_FAILED(rv))
        return rv;

    PRBool callDirectly;

    // see if we should call into the method directly. Either it is a QI function call
    // (methodIndex == 0), or it is a sync proxy and this code is running on the same thread
    // as the destination event queue. 
    if ( (methodIndex == 0) ||
         (mProxyType & PROXY_SYNC && 
          NS_SUCCEEDED(mDestQueue->IsOnCurrentThread(&callDirectly)) &&
          callDirectly))
    {

        // invoke the magic of xptc...
        nsresult rv = XPTC_InvokeByIndex( mRealObject, 
                                          methodIndex,
                                          paramCount, 
                                          fullParam);
        
        if (fullParam) 
            free(fullParam);
        return rv;
    }

    PLEvent *event = PR_NEW(PLEvent);
    
    if (event == nsnull) {
        if (fullParam) 
            free(fullParam);
        return NS_ERROR_OUT_OF_MEMORY;   
    }

    nsProxyObjectCallInfo *proxyInfo = new nsProxyObjectCallInfo(this, 
                                                                 methodInfo, 
                                                                 methodIndex, 
                                                                 fullParam,   // will be deleted by ~()
                                                                 paramCount, 
                                                                 event);      // will be deleted by ~()
    
    if (proxyInfo == nsnull) {
        PR_DELETE(event);
        if (fullParam)
            free(fullParam);
        return NS_ERROR_OUT_OF_MEMORY;  
    }

    PL_InitEvent(event, 
                 proxyInfo,
                 EventHandler,
                 DestroyHandler);
   
    if (mProxyType & PROXY_SYNC)
    {
        rv = PostAndWait(proxyInfo);
        
        if (NS_SUCCEEDED(rv))
            rv = proxyInfo->GetResult();
        delete proxyInfo;
        return rv;
    }
    
    if (mProxyType & PROXY_ASYNC)
    {
        mDestQueue->PostEvent(event);
        return NS_OK;
    }
    return NS_ERROR_UNEXPECTED;
}

Here is the call graph for this function:

Definition at line 357 of file nsProxyEvent.cpp.

{
    if (proxyInfo == nsnull || mEventQService == nsnull) 
        return NS_ERROR_NULL_POINTER;
    
    PRBool eventLoopCreated = PR_FALSE;
    nsresult rv; 

    nsCOMPtr<nsIEventQueue> eventQ;
    rv = mEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
    if (NS_FAILED(rv))
    {
        rv = mEventQService->CreateMonitoredThreadEventQueue();
        eventLoopCreated = PR_TRUE;
        if (NS_FAILED(rv))
            return rv;
        
        rv = mEventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(eventQ));
    }

    if (NS_FAILED(rv))
        return rv;
    
    proxyInfo->SetCallersQueue(eventQ);

    PLEvent* event = proxyInfo->GetPLEvent();
    if (!event)
        return NS_ERROR_NULL_POINTER;
    
    mDestQueue->PostEvent(event);

    while (! proxyInfo->GetCompleted())
    {
        PLEvent *nextEvent;
        rv = eventQ->WaitForEvent(&nextEvent);
        if (NS_FAILED(rv)) break;
                
        eventQ->HandleEvent(nextEvent);
    }  

    if (eventLoopCreated)
    {
         mEventQService->DestroyThreadEventQueue();
         eventQ = 0;
    }
    
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 315 of file nsProxyEvent.cpp.

{
  NS_PRECONDITION(0 != mRefCnt, "dup release");             

  nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mRefCnt);
  NS_LOG_RELEASE(this, count, "nsProxyObject");

  if (count == 0)
  {
       mRefCnt = 1; /* stabilize */

       PRBool callDirectly;
       mDestQueue->IsOnCurrentThread(&callDirectly);

       if (callDirectly)
       {
           delete this;
           return;
       }

      // need to do something special here so that
      // the real object will always be deleted on
      // the correct thread..

       PLEvent *event = PR_NEW(PLEvent);
       if (event == nsnull)
       {
           NS_ASSERTION(0, "Could not create a plevent. Leaking nsProxyObject!");
           return;  // if this happens we are going to leak.
       }
       
       PL_InitEvent(event, 
                    this,
                    ProxyDestructorEventHandler,
                    ProxyDestructorDestroyHandler);  

       mDestQueue->PostEvent(event);
  }                          
}                

Here is the call graph for this function:


Friends And Related Function Documentation

Definition at line 114 of file nsIProxyObjectManager.idl.


Member Data Documentation

Definition at line 121 of file nsIProxyObjectManager.idl.

Definition at line 125 of file nsIProxyObjectManager.idl.

Definition at line 119 of file nsIProxyObjectManager.idl.

nsCOMPtr< nsISupports > nsProxyObject::mRealObject [private]

Definition at line 123 of file nsIProxyObjectManager.idl.

Definition at line 117 of file nsIProxyObjectManager.idl.


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