diff --git a/mozilla/xpcom/proxy/public/nsProxiedService.h b/mozilla/xpcom/proxy/public/nsProxiedService.h index 6e92f3a7e01..b10cbfca9f9 100644 --- a/mozilla/xpcom/proxy/public/nsProxiedService.h +++ b/mozilla/xpcom/proxy/public/nsProxiedService.h @@ -24,43 +24,43 @@ //////////////////////////////////////////////////////////////////////////////// // 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: // { -// nsresult rv; -// NS_WITH_SERVICE(nsIMyService, pIMyService, kMyServiceCID, &rv); -// if(NS_FAILED(rv)) -// return; -// NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv); -// if(NS_FAILED(rv)) -// return; -// nsIMyService pIProxiedObject = NULL; -// rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue, -// nsIMyService::GetIID(), -// pIMyService, PROXY_SYNC, -// (void**)&pIProxiedObject); -// pIProxiedObject->DoIt(...); // Executed on same thread as pIProxyQueue -// ... -// pIProxiedObject->Release(); // Must be done as not managed for you. -// } -// with this: -// { -// nsresult rv; -// NS_WITH_PROXIED_SERVICE(nsIMyService, pIMyService, kMyServiceCID, -// pIProxyQueue, &rv); -// if(NS_FAILED(rv)) -// return; -// pIMyService->DoIt(...); // Executed on the same thread as pIProxyQueue -// } +// nsresult rv; +// NS_WITH_SERVICE(nsIMyService, pIMyService, kMyServiceCID, &rv); +// if(NS_FAILED(rv)) +// return; +// NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, kProxyObjectManagerCID, &rv); +// if(NS_FAILED(rv)) +// return; +// nsIMyService pIProxiedObject = NULL; +// rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue, +// nsIMyService::GetIID(), +// pIMyService, PROXY_SYNC, +// (void**)&pIProxiedObject); +// pIProxiedObject->DoIt(...); // Executed on same thread as pIProxyQueue +// ... +// pIProxiedObject->Release(); // Must be done as not managed for you. +// } +// with this: +// { +// nsresult rv; +// NS_WITH_PROXIED_SERVICE(nsIMyService, pIMyService, kMyServiceCID, +// pIProxyQueue, &rv); +// if(NS_FAILED(rv)) +// return; +// pIMyService->DoIt(...); // Executed on the same thread as pIProxyQueue +// } // and the automatic destructor will take care of releasing the service and // the proxied object for you. // // Note that this macro requires you to link with the xpcom DLL to pick up the // static member functions from nsServiceManager. -#define NS_WITH_PROXIED_SERVICE(T, var, cid, Q, rvAddr) \ - nsProxiedService _serv##var(cid, T::GetIID(), Q, rvAddr); \ - T* var = (T*)(nsISupports*)_serv##var; +#define NS_WITH_PROXIED_SERVICE(T, var, cid, Q, rvAddr) \ + nsProxiedService _serv##var(cid, T::GetIID(), Q, rvAddr); \ + T* var = (T*)(nsISupports*)_serv##var; //////////////////////////////////////////////////////////////////////////////// // nsProxiedService @@ -69,60 +69,60 @@ class nsProxiedService : public nsService { protected: - nsISupports* mProxiedService; + nsISupports* mProxiedService; public: nsProxiedService(const nsCID &aClass, const nsIID &aIID, - nsIEventQueue* pIProxyQueue, nsresult*rv): nsService(aClass, aIID, rv), - mProxiedService(nsnull) - { - static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); + nsIEventQueue* pIProxyQueue, nsresult*rv): nsService(aClass, aIID, rv), + mProxiedService(nsnull) + { + static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); - if(NS_FAILED(*rv)) - return; - NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, - kProxyObjectManagerCID, rv); - if(NS_FAILED(*rv)) - { - nsServiceManager::ReleaseService(mCID, mService); - mService = nsnull; - return; - } + if(NS_FAILED(*rv)) + return; + NS_WITH_SERVICE(nsIProxyObjectManager, pIProxyObjectManager, + kProxyObjectManagerCID, rv); + if(NS_FAILED(*rv)) + { + nsServiceManager::ReleaseService(mCID, mService); + mService = nsnull; + return; + } - *rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue, - aIID, - mService, - PROXY_SYNC, - (void**)&mProxiedService); - if(NS_FAILED(*rv)) - { - nsServiceManager::ReleaseService(mCID, mService); - mService = nsnull; - return; - } - } - - ~nsProxiedService() - { - if(mProxiedService) - NS_RELEASE(mProxiedService); - // Base class will free mService - } + *rv = pIProxyObjectManager->GetProxyObject(pIProxyQueue, + aIID, + mService, + PROXY_SYNC, + (void**)&mProxiedService); + if(NS_FAILED(*rv)) + { + nsServiceManager::ReleaseService(mCID, mService); + mService = nsnull; + return; + } + } + + ~nsProxiedService() + { + if(mProxiedService) + NS_RELEASE(mProxiedService); + // Base class will free mService + } - nsISupports* operator->() const - { - NS_PRECONDITION(mProxiedService != 0, "Your code should test the error result from the constructor."); - return mProxiedService; - } + nsISupports* operator->() const + { + NS_PRECONDITION(mProxiedService != 0, "Your code should test the error result from the constructor."); + return mProxiedService; + } - PRBool operator==(const nsISupports* other) - { - return ((mProxiedService == other) || (mService == other)); - } + PRBool operator==(const nsISupports* other) + { + return ((mProxiedService == other) || (mService == other)); + } - operator nsISupports*() const - { - return mProxiedService; - } + operator nsISupports*() const + { + return mProxiedService; + } }; diff --git a/mozilla/xpcom/proxy/public/nsProxyEvent.h b/mozilla/xpcom/proxy/public/nsProxyEvent.h index 72668f0dbf9..4e9ef3a9595 100644 --- a/mozilla/xpcom/proxy/public/nsProxyEvent.h +++ b/mozilla/xpcom/proxy/public/nsProxyEvent.h @@ -28,12 +28,9 @@ #include "xptcall.h" #include "xptinfo.h" -typedef enum -{ - PROXY_SYNC = 0, // act just like a function call. - PROXY_ASYNC // fire and forget. This will return immediately and you will lose all return information. - -} ProxyType; +#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. +#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. // WARNING about PROXY_ASYNC: // @@ -71,8 +68,8 @@ class nsProxyObject : public nsISupports NS_DECL_ISUPPORTS nsProxyObject(); - nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject); - nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID); + nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, nsISupports *realObject); + nsProxyObject(nsIEventQueue *destQueue, PRInt32 proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID); virtual ~nsProxyObject(); @@ -80,7 +77,7 @@ class nsProxyObject : public nsISupports nsISupports* GetRealObject() const { return mRealObject; } 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 */ nsISupports *mRealObject; /* the non-proxy object that this event is referring to */ PRBool mRealObjectOwned; - ProxyType mProxyType; + PRInt32 mProxyType; }; diff --git a/mozilla/xpcom/proxy/public/nsProxyObjectManager.h b/mozilla/xpcom/proxy/public/nsProxyObjectManager.h index 48903ef27a0..14c479770a0 100644 --- a/mozilla/xpcom/proxy/public/nsProxyObjectManager.h +++ b/mozilla/xpcom/proxy/public/nsProxyObjectManager.h @@ -91,14 +91,14 @@ public: NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, - ProxyType proxyType, + PRInt32 proxyType, void** aProxyObject) = 0; NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, - ProxyType proxyType, + PRInt32 proxyType, void** aProxyObject) = 0; }; diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index 5043a414da4..1cf02f9698f 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -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_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_ADDREF_THIS(); @@ -187,7 +187,7 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi EventHandler, DestroyHandler); - if (mProxyType == PROXY_SYNC) + if (mProxyType & PROXY_SYNC) { mDestQueue->PostSynchronousEvent(event, nsnull); @@ -203,7 +203,7 @@ nsProxyObject::Post( PRUint32 methodIndex, nsXPTMethodInfo *methodInfo, nsXPTCMi mDestQueue->ExitMonitor(); return rv; } - else if (mProxyType == PROXY_ASYNC) + else if (mProxyType & PROXY_ASYNC) { mDestQueue->PostEvent(event); mDestQueue->ExitMonitor(); @@ -305,7 +305,7 @@ void DestroyHandler(PLEvent *self) nsProxyObjectCallInfo* owner = (nsProxyObjectCallInfo*)PL_GetEventOwner(self); nsProxyObject* proxyObject = owner->GetProxyObject(); - if (proxyObject->GetProxyType() == PROXY_ASYNC) + if (proxyObject->GetProxyType() & PROXY_ASYNC) { delete owner; } diff --git a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp index 302b8837ce1..26f7b8d360c 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp @@ -37,7 +37,7 @@ nsProxyEventObject* nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, - ProxyType proxyType, + PRInt32 proxyType, nsISupports *aObj, REFNSIID aIID) { @@ -153,7 +153,7 @@ return_wrapper: nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue, - ProxyType proxyType, + PRInt32 proxyType, nsISupports* aObj, nsProxyEventClass* aClass, nsProxyEventObject* root) diff --git a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h index 848063b6f04..3b18970ecee 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h +++ b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h @@ -89,7 +89,7 @@ public: static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue, - ProxyType proxyType, + PRInt32 proxyType, nsISupports *aObj, REFNSIID aIID); @@ -109,7 +109,7 @@ public: private: nsProxyEventObject(); // not implemented nsProxyEventObject(nsIEventQueue *destQueue, - ProxyType proxyType, + PRInt32 proxyType, nsISupports* aObj, nsProxyEventClass* aClass, nsProxyEventObject* root); @@ -139,14 +139,14 @@ public: NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, - ProxyType proxyType, + PRInt32 proxyType, void** aProxyObject); NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, - ProxyType proxyType, + PRInt32 proxyType, void** aProxyObject); diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index 3749f89f7d0..ea5715ec9d6 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -137,7 +137,7 @@ nsProxyObjectManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInst 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; @@ -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. - if (postQ != nsnull && proxyType != PROXY_ASYNC) + if (postQ != nsnull && !(proxyType & PROXY_ASYNC) && !(proxyType & PROXY_ALWAYS)) { PRBool aResult; postQ->IsQueueOnCurrentThread(&aResult); @@ -198,7 +198,7 @@ nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, - ProxyType proxyType, + PRInt32 proxyType, void** aProxyObject) { *aProxyObject = nsnull;