Removing ProxyType so that I can do masking
Added new proxy type so that we bypass the Current Thread check. git-svn-id: svn://10.0.0.236/trunk@43487 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -24,43 +24,43 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// NS_WITH_PROXIED_SERVICE: macro to make using services that need to be proxied
|
// NS_WITH_PROXIED_SERVICE: macro to make using services that need to be proxied
|
||||||
// before using them easier.
|
// before using them easier.
|
||||||
// Now you can replace this:
|
// Now you can replace this:
|
||||||
// {
|
// {
|
||||||
// nsresult rv;
|
// nsresult rv;
|
||||||
// NS_WITH_SERVICE(nsIMyService, pIMyService, kMyServiceCID, &rv);
|
// NS_WITH_SERVICE(nsIMyService, pIMyService, kMyServiceCID, &rv);
|
||||||
// if(NS_FAILED(rv))
|
// if(NS_FAILED(rv))
|
||||||
// return;
|
// return;
|
||||||
// NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv);
|
// NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv);
|
||||||
// if(NS_FAILED(rv))
|
// if(NS_FAILED(rv))
|
||||||
// return;
|
// return;
|
||||||
// nsIMyService pIProxiedObject = NULL;
|
// nsIMyService pIProxiedObject = NULL;
|
||||||
// rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue,
|
// rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue,
|
||||||
// nsIMyService::GetIID(),
|
// nsIMyService::GetIID(),
|
||||||
// pIMyService, PROXY_SYNC,
|
// pIMyService, PROXY_SYNC,
|
||||||
// (void**)&pIProxiedObject);
|
// (void**)&pIProxiedObject);
|
||||||
// pIProxiedObject->DoIt(...); // Executed on same thread as pIProxyQueue
|
// pIProxiedObject->DoIt(...); // Executed on same thread as pIProxyQueue
|
||||||
// ...
|
// ...
|
||||||
// pIProxiedObject->Release(); // Must be done as not managed for you.
|
// pIProxiedObject->Release(); // Must be done as not managed for you.
|
||||||
// }
|
// }
|
||||||
// with this:
|
// with this:
|
||||||
// {
|
// {
|
||||||
// nsresult rv;
|
// nsresult rv;
|
||||||
// NS_WITH_PROXIED_SERVICE(nsIMyService, pIMyService, kMyServiceCID,
|
// NS_WITH_PROXIED_SERVICE(nsIMyService, pIMyService, kMyServiceCID,
|
||||||
// pIProxyQueue, &rv);
|
// pIProxyQueue, &rv);
|
||||||
// if(NS_FAILED(rv))
|
// if(NS_FAILED(rv))
|
||||||
// return;
|
// return;
|
||||||
// pIMyService->DoIt(...); // Executed on the same thread as pIProxyQueue
|
// pIMyService->DoIt(...); // Executed on the same thread as pIProxyQueue
|
||||||
// }
|
// }
|
||||||
// and the automatic destructor will take care of releasing the service and
|
// and the automatic destructor will take care of releasing the service and
|
||||||
// the proxied object for you.
|
// the proxied object for you.
|
||||||
//
|
//
|
||||||
// Note that this macro requires you to link with the xpcom DLL to pick up the
|
// Note that this macro requires you to link with the xpcom DLL to pick up the
|
||||||
// static member functions from nsServiceManager.
|
// static member functions from nsServiceManager.
|
||||||
|
|
||||||
#define NS_WITH_PROXIED_SERVICE(T, var, cid, Q, rvAddr) \
|
#define NS_WITH_PROXIED_SERVICE(T, var, cid, Q, rvAddr) \
|
||||||
nsProxiedService _serv##var(cid, T::GetIID(), Q, rvAddr); \
|
nsProxiedService _serv##var(cid, T::GetIID(), Q, rvAddr); \
|
||||||
T* var = (T*)(nsISupports*)_serv##var;
|
T* var = (T*)(nsISupports*)_serv##var;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// nsProxiedService
|
// nsProxiedService
|
||||||
@@ -69,60 +69,60 @@
|
|||||||
class nsProxiedService : public nsService
|
class nsProxiedService : public nsService
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
nsISupports* mProxiedService;
|
nsISupports* mProxiedService;
|
||||||
public:
|
public:
|
||||||
nsProxiedService(const nsCID &aClass, const nsIID &aIID,
|
nsProxiedService(const nsCID &aClass, const nsIID &aIID,
|
||||||
nsIEventQueue* pIProxyQueue, nsresult*rv): nsService(aClass, aIID, rv),
|
nsIEventQueue* pIProxyQueue, nsresult*rv): nsService(aClass, aIID, rv),
|
||||||
mProxiedService(nsnull)
|
mProxiedService(nsnull)
|
||||||
{
|
{
|
||||||
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
||||||
|
|
||||||
if(NS_FAILED(*rv))
|
if(NS_FAILED(*rv))
|
||||||
return;
|
return;
|
||||||
NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager,
|
NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager,
|
||||||
kProxyObjectManagerCID, rv);
|
kProxyObjectManagerCID, rv);
|
||||||
if(NS_FAILED(*rv))
|
if(NS_FAILED(*rv))
|
||||||
{
|
{
|
||||||
nsServiceManager::ReleaseService(mCID, mService);
|
nsServiceManager::ReleaseService(mCID, mService);
|
||||||
mService = nsnull;
|
mService = nsnull;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue,
|
*rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue,
|
||||||
aIID,
|
aIID,
|
||||||
mService,
|
mService,
|
||||||
PROXY_SYNC,
|
PROXY_SYNC,
|
||||||
(void**)&mProxiedService);
|
(void**)&mProxiedService);
|
||||||
if(NS_FAILED(*rv))
|
if(NS_FAILED(*rv))
|
||||||
{
|
{
|
||||||
nsServiceManager::ReleaseService(mCID, mService);
|
nsServiceManager::ReleaseService(mCID, mService);
|
||||||
mService = nsnull;
|
mService = nsnull;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~nsProxiedService()
|
~nsProxiedService()
|
||||||
{
|
{
|
||||||
if(mProxiedService)
|
if(mProxiedService)
|
||||||
NS_RELEASE(mProxiedService);
|
NS_RELEASE(mProxiedService);
|
||||||
// Base class will free mService
|
// Base class will free mService
|
||||||
}
|
}
|
||||||
|
|
||||||
nsISupports* operator->() const
|
nsISupports* operator->() const
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(mProxiedService != 0, "Your code should test the error result from the constructor.");
|
NS_PRECONDITION(mProxiedService != 0, "Your code should test the error result from the constructor.");
|
||||||
return mProxiedService;
|
return mProxiedService;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool operator==(const nsISupports* other)
|
PRBool operator==(const nsISupports* other)
|
||||||
{
|
{
|
||||||
return ((mProxiedService == other) || (mService == other));
|
return ((mProxiedService == other) || (mService == other));
|
||||||
}
|
}
|
||||||
|
|
||||||
operator nsISupports*() const
|
operator nsISupports*() const
|
||||||
{
|
{
|
||||||
return mProxiedService;
|
return mProxiedService;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,9 @@
|
|||||||
#include "xptcall.h"
|
#include "xptcall.h"
|
||||||
#include "xptinfo.h"
|
#include "xptinfo.h"
|
||||||
|
|
||||||
typedef enum
|
#define PROXY_SYNC 0x0001 // act just like a function call.
|
||||||
{
|
#define PROXY_ASYNC 0x0002 // fire and forget. This will return immediately and you will lose all return information.
|
||||||
PROXY_SYNC = 0, // act just like a function call.
|
#define PROXY_ALWAYS 0x0004 // ignore check to see if the eventQ is on the same thread as the caller, and alway return a proxied object.
|
||||||
PROXY_ASYNC // fire and forget. This will return immediately and you will lose all return information.
|
|
||||||
|
|
||||||
} ProxyType;
|
|
||||||
|
|
||||||
// WARNING about PROXY_ASYNC:
|
// WARNING about PROXY_ASYNC:
|
||||||
//
|
//
|
||||||
@@ -71,8 +68,8 @@ class nsProxyObject : public nsISupports
|
|||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
nsProxyObject();
|
nsProxyObject();
|
||||||
nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject);
|
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject);
|
||||||
nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
|
nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID);
|
||||||
|
|
||||||
virtual ~nsProxyObject();
|
virtual ~nsProxyObject();
|
||||||
|
|
||||||
@@ -80,7 +77,7 @@ class nsProxyObject : public nsISupports
|
|||||||
|
|
||||||
nsISupports* GetRealObject() const { return mRealObject; }
|
nsISupports* GetRealObject() const { return mRealObject; }
|
||||||
nsIEventQueue* GetQueue() const { return mDestQueue; }
|
nsIEventQueue* GetQueue() const { return mDestQueue; }
|
||||||
ProxyType GetProxyType() const { return mProxyType; }
|
PRInt32 GetProxyType() const { return mProxyType; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +98,7 @@ class nsProxyObject : public nsISupports
|
|||||||
nsIEventQueue *mDestQueue; /* destination queue */
|
nsIEventQueue *mDestQueue; /* destination queue */
|
||||||
nsISupports *mRealObject; /* the non-proxy object that this event is referring to */
|
nsISupports *mRealObject; /* the non-proxy object that this event is referring to */
|
||||||
PRBool mRealObjectOwned;
|
PRBool mRealObjectOwned;
|
||||||
ProxyType mProxyType;
|
PRInt32 mProxyType;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -91,14 +91,14 @@ public:
|
|||||||
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
nsISupports* aObj,
|
nsISupports* aObj,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
void** aProxyObject) = 0;
|
void** aProxyObject) = 0;
|
||||||
|
|
||||||
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
||||||
const nsCID &aClass,
|
const nsCID &aClass,
|
||||||
nsISupports *aDelegate,
|
nsISupports *aDelegate,
|
||||||
const nsIID &aIID,
|
const nsIID &aIID,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
void** aProxyObject) = 0;
|
void** aProxyObject) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ nsProxyObject::nsProxyObject()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject)
|
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
NS_ADDREF_THIS();
|
NS_ADDREF_THIS();
|
||||||
@@ -87,7 +87,7 @@ nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsIS
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID)
|
nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
NS_ADDREF_THIS();
|
NS_ADDREF_THIS();
|
||||||
@@ -187,7 +187,7 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||||||
EventHandler,
|
EventHandler,
|
||||||
DestroyHandler);
|
DestroyHandler);
|
||||||
|
|
||||||
if (mProxyType == PROXY_SYNC)
|
if (mProxyType & PROXY_SYNC)
|
||||||
{
|
{
|
||||||
mDestQueue->PostSynchronousEvent(event, nsnull);
|
mDestQueue->PostSynchronousEvent(event, nsnull);
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi
|
|||||||
mDestQueue->ExitMonitor();
|
mDestQueue->ExitMonitor();
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
else if (mProxyType == PROXY_ASYNC)
|
else if (mProxyType & PROXY_ASYNC)
|
||||||
{
|
{
|
||||||
mDestQueue->PostEvent(event);
|
mDestQueue->PostEvent(event);
|
||||||
mDestQueue->ExitMonitor();
|
mDestQueue->ExitMonitor();
|
||||||
@@ -305,7 +305,7 @@ void DestroyHandler(PLEvent *self)
|
|||||||
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self);
|
||||||
nsProxyObject* proxyObject = owner->GetProxyObject();
|
nsProxyObject* proxyObject = owner->GetProxyObject();
|
||||||
|
|
||||||
if (proxyObject->GetProxyType() == PROXY_ASYNC)
|
if (proxyObject->GetProxyType() & PROXY_ASYNC)
|
||||||
{
|
{
|
||||||
delete owner;
|
delete owner;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
nsProxyEventObject*
|
nsProxyEventObject*
|
||||||
nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
nsISupports *aObj,
|
nsISupports *aObj,
|
||||||
REFNSIID aIID)
|
REFNSIID aIID)
|
||||||
{
|
{
|
||||||
@@ -153,7 +153,7 @@ return_wrapper:
|
|||||||
|
|
||||||
|
|
||||||
nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue,
|
nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
nsISupports* aObj,
|
nsISupports* aObj,
|
||||||
nsProxyEventClass* aClass,
|
nsProxyEventClass* aClass,
|
||||||
nsProxyEventObject* root)
|
nsProxyEventObject* root)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
nsISupports *aObj,
|
nsISupports *aObj,
|
||||||
REFNSIID aIID);
|
REFNSIID aIID);
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
nsProxyEventObject(); // not implemented
|
nsProxyEventObject(); // not implemented
|
||||||
nsProxyEventObject(nsIEventQueue *destQueue,
|
nsProxyEventObject(nsIEventQueue *destQueue,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
nsISupports* aObj,
|
nsISupports* aObj,
|
||||||
nsProxyEventClass* aClass,
|
nsProxyEventClass* aClass,
|
||||||
nsProxyEventObject* root);
|
nsProxyEventObject* root);
|
||||||
@@ -139,14 +139,14 @@ public:
|
|||||||
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
||||||
REFNSIID aIID,
|
REFNSIID aIID,
|
||||||
nsISupports* aObj,
|
nsISupports* aObj,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
void** aProxyObject);
|
void** aProxyObject);
|
||||||
|
|
||||||
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue,
|
||||||
const nsCID &aClass,
|
const nsCID &aClass,
|
||||||
nsISupports *aDelegate,
|
nsISupports *aDelegate,
|
||||||
const nsIID &aIID,
|
const nsIID &aIID,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
void** aProxyObject);
|
void** aProxyObject);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ nsProxyObjectManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInst
|
|||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, ProxyType proxyType, void** aProxyObject)
|
nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, PRInt32 proxyType, void** aProxyObject)
|
||||||
{
|
{
|
||||||
nsIEventQueue *postQ = destQueue;
|
nsIEventQueue *postQ = destQueue;
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, ns
|
|||||||
|
|
||||||
// check to see if the eventQ is on our thread. If so, just return the real object.
|
// check to see if the eventQ is on our thread. If so, just return the real object.
|
||||||
|
|
||||||
if (postQ != nsnull && proxyType != PROXY_ASYNC)
|
if (postQ != nsnull && !(proxyType & PROXY_ASYNC) && !(proxyType & PROXY_ALWAYS))
|
||||||
{
|
{
|
||||||
PRBool aResult;
|
PRBool aResult;
|
||||||
postQ->IsQueueOnCurrentThread(&aResult);
|
postQ->IsQueueOnCurrentThread(&aResult);
|
||||||
@@ -198,7 +198,7 @@ nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue,
|
|||||||
const nsCID &aClass,
|
const nsCID &aClass,
|
||||||
nsISupports *aDelegate,
|
nsISupports *aDelegate,
|
||||||
const nsIID &aIID,
|
const nsIID &aIID,
|
||||||
ProxyType proxyType,
|
PRInt32 proxyType,
|
||||||
void** aProxyObject)
|
void** aProxyObject)
|
||||||
{
|
{
|
||||||
*aProxyObject = nsnull;
|
*aProxyObject = nsnull;
|
||||||
|
|||||||
Reference in New Issue
Block a user