From e41bbebd461034641d647cfb08090a5190d40e47 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Fri, 4 Jun 1999 22:46:20 +0000 Subject: [PATCH] api change to nsIProxy* interfaces. You can no longer pass in straight PLEventQueues, you now need to pass in nsIEventQueue interfaces (see mozilla/xpcom/threads) git-svn-id: svn://10.0.0.236/trunk@33830 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/proxy/public/nsProxyEvent.h | 8 ++-- .../xpcom/proxy/public/nsProxyObjectManager.h | 6 +-- mozilla/xpcom/proxy/src/nsProxyEvent.cpp | 39 +++++------------ mozilla/xpcom/proxy/src/nsProxyEventClass.cpp | 4 +- .../xpcom/proxy/src/nsProxyEventObject.cpp | 4 +- mozilla/xpcom/proxy/src/nsProxyEventPrivate.h | 8 ++-- .../xpcom/proxy/src/nsProxyObjectManager.cpp | 6 +-- mozilla/xpcom/proxy/tests/proxytests.cpp | 43 +++++++++++++++---- 8 files changed, 60 insertions(+), 58 deletions(-) diff --git a/mozilla/xpcom/proxy/public/nsProxyEvent.h b/mozilla/xpcom/proxy/public/nsProxyEvent.h index 460adb0f84a..be0569378b8 100644 --- a/mozilla/xpcom/proxy/public/nsProxyEvent.h +++ b/mozilla/xpcom/proxy/public/nsProxyEvent.h @@ -71,8 +71,8 @@ class nsProxyObject : public nsISupports NS_DECL_ISUPPORTS nsProxyObject(); - nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject); - nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID); + nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject); + nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID); virtual ~nsProxyObject(); @@ -131,14 +131,14 @@ private: #define NS_DECL_PROXY(_class, _interface) \ public: \ - _class(PLEventQueue *, _interface *); \ + _class(nsIEventQueue *, _interface *); \ private: \ nsProxyObject mProxyObject;\ public: #define NS_IMPL_PROXY(_class, _interface)\ -_class::_class(PLEventQueue *eventQueue, _interface *realObject) \ +_class::_class(nsIEventQueue *eventQueue, _interface *realObject) \ : mProxyObject(eventQueue, realObject) \ {\ }\ diff --git a/mozilla/xpcom/proxy/public/nsProxyObjectManager.h b/mozilla/xpcom/proxy/public/nsProxyObjectManager.h index 89391139e04..71586e3e29b 100644 --- a/mozilla/xpcom/proxy/public/nsProxyObjectManager.h +++ b/mozilla/xpcom/proxy/public/nsProxyObjectManager.h @@ -22,10 +22,10 @@ #include "nscore.h" #include "nsISupports.h" #include "nsIFactory.h" +#include "nsIEventQueue.h" #include "nsHashtable.h" -#include "plevent.h" #include "xptcall.h" // defines nsXPTCVariant #include "nsProxyEvent.h" @@ -87,13 +87,13 @@ class nsIProxyObjectManager : public nsISupports { public: - NS_IMETHOD GetProxyObject(PLEventQueue *destQueue, + NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, ProxyType proxyType, void** aProxyObject) = 0; - NS_IMETHOD GetProxyObject(PLEventQueue *destQueue, + NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, diff --git a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp index 96616364ef5..0a92f6a1636 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEvent.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEvent.cpp @@ -52,8 +52,6 @@ nsProxyObjectCallInfo::~nsProxyObjectCallInfo() static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); NS_IMPL_ISUPPORTS(nsProxyObject, kISupportsIID) -static NS_DEFINE_IID(kIEventQIID, NS_IEVENTQUEUE_IID); - nsProxyObject::nsProxyObject() { NS_INIT_REFCNT(); @@ -66,7 +64,7 @@ nsProxyObject::nsProxyObject() } -nsProxyObject::nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject) +nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *realObject) { NS_INIT_REFCNT(); NS_ADDREF_THIS(); @@ -74,29 +72,23 @@ nsProxyObject::nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, nsISu mRealObjectOwned = PR_FALSE; mRealObject = realObject; mProxyType = proxyType; + mDestQueue = destQueue; - mRealObject->AddRef(); - - nsresult rv = nsComponentManager::CreateInstance(NS_EVENTQUEUE_PROGID, - nsnull, - kIEventQIID, - (void **)&mDestQueue); - - if (NS_SUCCEEDED(rv)) - { - mDestQueue->InitFromPLQueue(destQueue); - } - + NS_ADDREF(mRealObject); + NS_ADDREF(mDestQueue); } -nsProxyObject::nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID) +nsProxyObject::nsProxyObject(nsIEventQueue *destQueue, ProxyType proxyType, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID) { NS_INIT_REFCNT(); NS_ADDREF_THIS(); mRealObjectOwned = PR_TRUE; mProxyType = proxyType; + mDestQueue = destQueue; + + NS_ADDREF(mDestQueue); nsresult rv = nsComponentManager::CreateInstance(aClass, aDelegate, @@ -108,17 +100,6 @@ nsProxyObject::nsProxyObject(PLEventQueue *destQueue, ProxyType proxyType, const mRealObjectOwned = PR_FALSE; mRealObject = nsnull; } - - rv = nsComponentManager::CreateInstance(NS_EVENTQUEUE_PROGID, - nsnull, - kIEventQIID, - (void **)&mDestQueue); - - if (NS_SUCCEEDED(rv)) - { - mDestQueue->InitFromPLQueue(destQueue); - } - } nsProxyObject::~nsProxyObject() @@ -130,7 +111,7 @@ nsProxyObject::~nsProxyObject() if(mRealObject != nsnull) { if (!mRealObjectOwned) - mRealObject->Release(); + NS_RELEASE(mRealObject); else NS_RELEASE(mRealObject); } @@ -210,7 +191,7 @@ void DestroyHandler(PLEvent *self) } // decrement once since we increased it during the Post() - proxyObject->Release(); + NS_RELEASE(proxyObject); } void* EventHandler(PLEvent *self) diff --git a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp index 4de52ebbaaf..30ad5f197f5 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventClass.cpp @@ -201,9 +201,7 @@ nsProxyEventClass::CallQueryInterfaceOnProxy(nsProxyEventObject* self, REFNSIID if (rv == NS_OK) { - PLEventQueue* aEventQueue; - - self->GetQueue()->GetPLEventQueue(&aEventQueue); + nsIEventQueue* aEventQueue = self->GetQueue(); if (aEventQueue != nsnull) { diff --git a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp index 80088101c1b..d2728125fe0 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyEventObject.cpp @@ -36,7 +36,7 @@ nsProxyEventObject* -nsProxyEventObject::GetNewOrUsedProxy(PLEventQueue *destQueue, +nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *aObj, REFNSIID aIID) @@ -147,7 +147,7 @@ return_wrapper: -nsProxyEventObject::nsProxyEventObject(PLEventQueue *destQueue, +nsProxyEventObject::nsProxyEventObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports* aObj, nsProxyEventClass* aClass, diff --git a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h index a5b8b4f99ef..7e9bc57052e 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h +++ b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h @@ -83,7 +83,7 @@ public: nsXPTCMiniVariant* params); - static nsProxyEventObject* GetNewOrUsedProxy(PLEventQueue *destQueue, + static nsProxyEventObject* GetNewOrUsedProxy(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports *aObj, REFNSIID aIID); @@ -103,7 +103,7 @@ public: private: nsProxyEventObject(); // not implemented - nsProxyEventObject(PLEventQueue *destQueue, + nsProxyEventObject(nsIEventQueue *destQueue, ProxyType proxyType, nsISupports* aObj, nsProxyEventClass* aClass, @@ -131,13 +131,13 @@ public: NS_DECL_ISUPPORTS NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPROXYEVENT_MANAGER_IID); - NS_IMETHOD GetProxyObject(PLEventQueue *destQueue, + NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, ProxyType proxyType, void** aProxyObject); - NS_IMETHOD GetProxyObject(PLEventQueue *destQueue, + NS_IMETHOD GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index beb664a4084..b02565a5a48 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -27,8 +27,6 @@ #include "nsIServiceManager.h" #include "nsCOMPtr.h" -#include "plevent.h" - static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); @@ -136,7 +134,7 @@ nsProxyObjectManager::Create(nsISupports* outer, const nsIID& aIID, void* *aInst NS_IMETHODIMP -nsProxyObjectManager::GetProxyObject(PLEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, ProxyType proxyType, void** aProxyObject) +nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, REFNSIID aIID, nsISupports* aObj, ProxyType proxyType, void** aProxyObject) { *aProxyObject = nsnull; @@ -153,7 +151,7 @@ nsProxyObjectManager::GetProxyObject(PLEventQueue *destQueue, REFNSIID aIID, nsI NS_IMETHODIMP -nsProxyObjectManager::GetProxyObject(PLEventQueue *destQueue, +nsProxyObjectManager::GetProxyObject(nsIEventQueue *destQueue, const nsCID &aClass, nsISupports *aDelegate, const nsIID &aIID, diff --git a/mozilla/xpcom/proxy/tests/proxytests.cpp b/mozilla/xpcom/proxy/tests/proxytests.cpp index 4e39ecdf728..914424a16bc 100644 --- a/mozilla/xpcom/proxy/tests/proxytests.cpp +++ b/mozilla/xpcom/proxy/tests/proxytests.cpp @@ -66,7 +66,6 @@ class nsITestXPCFoo : public nsISupports { static NS_DEFINE_IID(kProxyObjectManagerIID, NS_IPROXYEVENT_MANAGER_IID); static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); - /***************************************************************************/ /* Setup nsIAllocator */ /***************************************************************************/ @@ -218,7 +217,7 @@ NS_IMETHODIMP nsTestXPCFoo2::Test2() typedef struct _ArgsStruct { - PLEventQueue* queue; + nsIEventQueue* queue; PRInt32 threadNumber; }ArgsStruct; @@ -359,30 +358,55 @@ static void PR_CALLBACK ProxyTest( void *arg ) TestCase_TwoClassesOneInterface(arg); // TestCase_2(arg); + NS_RELEASE( ((ArgsStruct*) arg)->queue); free((void*) arg); } -PLEventQueue *gEventQueue = nsnull; +#include "nsIEventQueueService.h" +static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); + + +nsIEventQueue *gEventQueue = nsnull; static void PR_CALLBACK EventLoop( void *arg ) { + nsresult rv; printf("Creating EventQueue...\n"); - gEventQueue = PL_CreateEventQueue("mainqueue", PR_GetCurrentThread()); + nsIEventQueue* eventQ; + NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ); + if (NS_FAILED(rv)) + rv = eventQService->CreateThreadEventQueue(); + if (NS_FAILED(rv)) + return; + else + rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ); + } + if (NS_FAILED(rv)) return; + + rv = eventQ->QueryInterface(nsIEventQueue::GetIID(), (void**)&gEventQueue); + if (NS_FAILED(rv)) return; printf("Looping for events.\n"); + + PLEvent* event = nsnull; while ( PR_SUCCESS == PR_Sleep( PR_MillisecondsToInterval(1)) ) { - PL_HandleEvent(PL_GetEvent(gEventQueue)); + rv = gEventQueue->GetEvent(&event); + if (NS_FAILED(rv)) + return; + gEventQueue->HandleEvent(event); } - PL_ProcessPendingEvents(gEventQueue); + gEventQueue->ProcessPendingEvents(); printf("Closing down Event Queue.\n"); - PL_DestroyEventQueue( gEventQueue ); - + delete gEventQueue; + gEventQueue = nsnull; printf("End looping for events.\n\n"); } @@ -412,7 +436,7 @@ main(int argc, char **argv) PR_Sleep(PR_MillisecondsToInterval(1000)); - PR_ASSERT(gEventQueue); // BAD BAD BAD. EVENT THREAD DID NOT CREATE QUEUE. This may be a timing issue, set the + NS_ASSERTION(gEventQueue, "no main event queue"); // BAD BAD BAD. EVENT THREAD DID NOT CREATE QUEUE. This may be a timing issue, set the // sleep about longer, and try again. printf("Spawn Threads:\n"); @@ -422,6 +446,7 @@ main(int argc, char **argv) ArgsStruct *args = (ArgsStruct *) malloc (sizeof(ArgsStruct)); args->queue = gEventQueue; + NS_ADDREF(args->queue); args->threadNumber = spawn; threads[spawn] = PR_CreateThread(PR_USER_THREAD,