From 0d0f9ec313d27c9d9cd234bc4b12bbc84f600fff Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Wed, 18 Aug 1999 09:32:26 +0000 Subject: [PATCH] Adding thread proxy support to Net Module Notification. General cleanup git-svn-id: svn://10.0.0.236/trunk@43488 18797224-902f-48f8-a5cc-f745e15eee43 --- .../netwerk/base/public/nsINetModRegEntry.idl | 11 +- .../netwerk/base/public/nsINetModuleMgr.idl | 5 +- mozilla/netwerk/base/src/nsNetModRegEntry.cpp | 161 +++++++++--------- mozilla/netwerk/base/src/nsNetModRegEntry.h | 20 +-- mozilla/netwerk/base/src/nsNetModuleMgr.cpp | 35 ++-- mozilla/netwerk/base/src/nsNetModuleMgr.h | 4 +- 6 files changed, 120 insertions(+), 116 deletions(-) diff --git a/mozilla/netwerk/base/public/nsINetModRegEntry.idl b/mozilla/netwerk/base/public/nsINetModRegEntry.idl index 1a198d02f82..bbc1ecf0a34 100644 --- a/mozilla/netwerk/base/public/nsINetModRegEntry.idl +++ b/mozilla/netwerk/base/public/nsINetModRegEntry.idl @@ -24,6 +24,7 @@ interface nsIEventQueue; interface nsINetModRegEntry; +interface nsINetNotify; %{ C++ // {F126BD90-1472-11d3-A15A-0050041CAF44} @@ -32,11 +33,11 @@ interface nsINetModRegEntry; %} [scriptable, uuid(9F482BD0-1476-11d3-A15A-0050041CAF44)] -interface nsINetModRegEntry : nsISupports { - readonly attribute nsINetNotify mNotify; - readonly attribute nsIEventQueue mEventQ; - readonly attribute string mTopic; - readonly attribute nsCIDPtr mCID; +interface nsINetModRegEntry : nsISupports +{ + readonly attribute nsINetNotify SyncProxy; + readonly attribute nsINetNotify AsyncProxy; + readonly attribute string Topic; boolean Equals(in nsINetModRegEntry aEntry); }; diff --git a/mozilla/netwerk/base/public/nsINetModuleMgr.idl b/mozilla/netwerk/base/public/nsINetModuleMgr.idl index 2a583a8222b..65c7152413e 100644 --- a/mozilla/netwerk/base/public/nsINetModuleMgr.idl +++ b/mozilla/netwerk/base/public/nsINetModuleMgr.idl @@ -52,11 +52,10 @@ interface nsINetModuleMgr : nsISupports { // // ARGUMENTS: // aTopic: The internal component that the external module wants to monitor. - // aEventQueue: The event queue to receive the events. // aNotify: The external module interface methods to be called when an event is fired. // // RETURNS: nsresult - void RegisterModule(in string aTopic, in nsIEventQueue aEventQueue, in nsINetNotify aNotify, in nsCIDPtr aCID); + void RegisterModule(in string aTopic, in nsINetNotify aNotify); // Unregister the external module. Removes the nsINetModuleMgr binding between // internal component and external module. @@ -66,7 +65,7 @@ interface nsINetModuleMgr : nsISupports { // aNotify: The external modules notification module. // // RETURNS: nsresult - void UnregisterModule(in string aTopic, in nsIEventQueue aEventQueue, in nsINetNotify aNotify, in nsCIDPtr aCID); + void UnregisterModule(in string aTopic, in nsINetNotify aNotify); // Enumerates all the registered modules for the specified topic. // diff --git a/mozilla/netwerk/base/src/nsNetModRegEntry.cpp b/mozilla/netwerk/base/src/nsNetModRegEntry.cpp index 9cc051c890e..a8e37860f0d 100644 --- a/mozilla/netwerk/base/src/nsNetModRegEntry.cpp +++ b/mozilla/netwerk/base/src/nsNetModRegEntry.cpp @@ -19,8 +19,15 @@ #include "nsNetModRegEntry.h" #include "plstr.h" #include "nsIAllocator.h" +#include "nsIServiceManager.h" +#include "nsIEventQueueService.h" +#include "nsProxyObjectManager.h" +static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); +static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); + + ////////////////////////////// //// nsISupports ////////////////////////////// @@ -32,92 +39,65 @@ NS_IMPL_ISUPPORTS(nsNetModRegEntry, nsCOMTypeInfo::GetIID()); ////////////////////////////// NS_IMETHODIMP -nsNetModRegEntry::GetMNotify(nsINetNotify **aNotify) { - *aNotify = mNotify; +nsNetModRegEntry::GetSyncProxy(nsINetNotify **aNotify) { + *aNotify = mSyncProxy; + NS_ADDREF(*aNotify); + return NS_OK; +} + + +NS_IMETHODIMP +nsNetModRegEntry::GetAsyncProxy(nsINetNotify **aNotify) { + *aNotify = mAsyncProxy; NS_ADDREF(*aNotify); return NS_OK; } NS_IMETHODIMP -nsNetModRegEntry::GetMEventQ(nsIEventQueue **aEventQ) { - *aEventQ = mEventQ; - NS_ADDREF(*aEventQ); - return NS_OK; +nsNetModRegEntry::GetTopic(char **topic) +{ + if (mTopic) + { + *topic = (char *) nsAllocator::Clone(mTopic, nsCRT::strlen(mTopic) + 1); + return NS_OK; + } + return NS_ERROR_NULL_POINTER; } NS_IMETHODIMP -nsNetModRegEntry::GetMTopic(char **aTopic) { - *aTopic = (char *)nsAllocator::Alloc(PL_strlen(mTopic) + 1); - if (!*aTopic) return NS_ERROR_OUT_OF_MEMORY; - PL_strcpy(*aTopic, mTopic); - return NS_OK; -} - -NS_IMETHODIMP -nsNetModRegEntry::GetMCID(nsCID **aMCID) { - *aMCID = &mCID; - return NS_OK; -} - -NS_IMETHODIMP -nsNetModRegEntry::Equals(nsINetModRegEntry* aEntry, PRBool *_retVal) { +nsNetModRegEntry::Equals(nsINetModRegEntry* aEntry, PRBool *_retVal) +{ nsresult rv = NS_OK; - PRBool retVal = PR_TRUE; + *_retVal = PR_FALSE; NS_ADDREF(aEntry); - char * topic = 0; - nsINetNotify* notify = 0; - nsIEventQueue* eventQ = 0; - nsCID *cid = 0; + char* topic; - rv = aEntry->GetMTopic(&topic); - if (NS_FAILED(rv)) { - retVal = PR_FALSE; - goto end; - } - if (PL_strcmp(topic, mTopic)) { - retVal = PR_FALSE; - goto end; - } - - rv = aEntry->GetMNotify(¬ify); - if (NS_FAILED(rv)) { - retVal = PR_FALSE; - goto end; - } - if (notify != mNotify) { - retVal = PR_FALSE; - goto end; - } - - rv = aEntry->GetMEventQ(&eventQ); - if (NS_FAILED(rv)) { - retVal = PR_FALSE; - goto end; - } - if (eventQ != mEventQ) { - retVal = PR_FALSE; - goto end; - } - - rv = aEntry->GetMCID(&cid); - if (NS_FAILED(rv)) { - retVal = PR_FALSE; - goto end; - } - if (!mCID.Equals(*cid)) { - retVal = PR_FALSE; - goto end; - } - -end: + rv = aEntry->GetTopic(&topic); + if (NS_FAILED(rv)) + return rv; + if (topic) nsAllocator::Free(topic); - NS_IF_RELEASE(notify); - NS_IF_RELEASE(eventQ); - *_retVal = retVal; - NS_RELEASE(aEntry); + + if (PL_strcmp(topic, mTopic)) + return NS_OK; + + nsCOMPtr entryEventQ; + NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv); + + if (NS_FAILED(rv)) + return rv; + + rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), getter_AddRefs(entryEventQ)); + + if (NS_FAILED(rv) || mEventQ != entryEventQ) + { + return rv; + } + + *_retVal = PR_TRUE; return rv; } @@ -126,18 +106,41 @@ end: //// nsNetModRegEntry ////////////////////////////// -nsNetModRegEntry::nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID) - : mEventQ(aEventQ), mNotify(aNotify) { +nsNetModRegEntry::nsNetModRegEntry(const char *aTopic, + nsINetNotify *aNotify, + nsresult *result) +{ NS_INIT_REFCNT(); mTopic = new char [PL_strlen(aTopic) + 1]; PL_strcpy(mTopic, aTopic); - NS_ADDREF(mEventQ); - NS_ADDREF(mNotify); - mCID = aCID; + + NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, result); + + if (NS_FAILED(*result)) return; + + *result = eventQService->GetThreadEventQueue(PR_CurrentThread(), getter_AddRefs(mEventQ)); + + if (NS_FAILED(*result)) return; + + NS_WITH_SERVICE( nsIProxyObjectManager, proxyManager, kProxyObjectManagerCID, result); + + if (NS_FAILED(*result)) return; + + *result = proxyManager->GetProxyObject( mEventQ, + nsCOMTypeInfo::GetIID(), + aNotify, + PROXY_SYNC | PROXY_ALWAYS, + getter_AddRefs(mSyncProxy)); + if (NS_FAILED(*result)) return; + + *result = proxyManager->GetProxyObject( mEventQ, + nsCOMTypeInfo::GetIID(), + aNotify, + PROXY_ASYNC | PROXY_ALWAYS, + getter_AddRefs(mAsyncProxy)); } -nsNetModRegEntry::~nsNetModRegEntry() { +nsNetModRegEntry::~nsNetModRegEntry() +{ delete [] mTopic; - NS_RELEASE(mEventQ); - NS_RELEASE(mNotify); } diff --git a/mozilla/netwerk/base/src/nsNetModRegEntry.h b/mozilla/netwerk/base/src/nsNetModRegEntry.h index c3f091f4db4..1b5112c7ffd 100644 --- a/mozilla/netwerk/base/src/nsNetModRegEntry.h +++ b/mozilla/netwerk/base/src/nsNetModRegEntry.h @@ -21,6 +21,7 @@ #include "nsINetModRegEntry.h" #include "nsIEventQueue.h" +#include "nsCOMPtr.h" class nsNetModRegEntry : public nsINetModRegEntry { public: @@ -28,21 +29,20 @@ public: NS_DECL_ISUPPORTS // nsINetModRegEntry - NS_IMETHOD GetMNotify(nsINetNotify **aNotify); - NS_IMETHOD GetMEventQ(nsIEventQueue **aEventQ); - NS_IMETHOD GetMTopic(char **aTopic); - NS_IMETHOD GetMCID(nsCID **aCID); - + NS_IMETHOD GetSyncProxy(nsINetNotify * *aSyncProxy); + NS_IMETHOD GetAsyncProxy(nsINetNotify * *aAsyncProxy); + NS_IMETHOD GetTopic(char * *aTopic); NS_IMETHOD Equals(nsINetModRegEntry* aEntry, PRBool *_retVal); // nsNetModRegEntry - nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID); + nsNetModRegEntry(const char *aTopic, nsINetNotify *aNotify, nsresult *result); virtual ~nsNetModRegEntry(); - char *mTopic; - nsIEventQueue *mEventQ; - nsINetNotify *mNotify; - nsCID mCID; +protected: + char *mTopic; + nsCOMPtr mSyncProxy; + nsCOMPtr mAsyncProxy; + nsCOMPtr mEventQ; }; #endif //___nsNetModRegEntry_h___ diff --git a/mozilla/netwerk/base/src/nsNetModuleMgr.cpp b/mozilla/netwerk/base/src/nsNetModuleMgr.cpp index 955ab403420..e898ed0a839 100644 --- a/mozilla/netwerk/base/src/nsNetModuleMgr.cpp +++ b/mozilla/netwerk/base/src/nsNetModuleMgr.cpp @@ -42,28 +42,30 @@ NS_IMPL_ISUPPORTS(nsNetModuleMgr, nsCOMTypeInfo::GetIID()); /////////////////////////////////// NS_IMETHODIMP -nsNetModuleMgr::RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) { +nsNetModuleMgr::RegisterModule(const char *aTopic, nsINetNotify *aNotify) +{ nsresult rv; PRUint32 cnt; - // XXX before registering an object for a particular topic // XXX QI the nsINetNotify interface passed in for the interfaces // XXX supported by the topic. PR_Lock(mLock); - nsINetModRegEntry* newEntryI = nsnull; - nsNetModRegEntry *newEntry = - new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID); + nsCOMPtr newEntryI; + nsNetModRegEntry *newEntry = new nsNetModRegEntry(aTopic, aNotify, &rv); if (!newEntry) return NS_ERROR_OUT_OF_MEMORY; - - rv = newEntry->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&newEntryI); + + if (NS_FAILED(rv)) return rv; + + rv = newEntry->QueryInterface(nsCOMTypeInfo::GetIID(), getter_AddRefs(newEntryI)); if (NS_FAILED(rv)) return rv; // Check for a previous registration mEntries->Count(&cnt); - for (PRUint32 i = 0; i < cnt; i++) { + for (PRUint32 i = 0; i < cnt; i++) + { nsINetModRegEntry* curEntry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i)); PRBool same = PR_FALSE; rv = newEntryI->Equals(curEntry, &same); @@ -82,24 +84,24 @@ nsNetModuleMgr::RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, n mEntries->AppendElement(NS_STATIC_CAST(nsISupports*, newEntryI)); PR_Unlock(mLock); - NS_RELEASE(newEntryI); return NS_OK; } NS_IMETHODIMP -nsNetModuleMgr::UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) { - +nsNetModuleMgr::UnregisterModule(const char *aTopic, nsINetNotify *aNotify) +{ PR_Lock(mLock); nsresult rv; PRUint32 cnt; - nsINetModRegEntry* tmpEntryI = nsnull; - nsNetModRegEntry *tmpEntry = - new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID); + nsCOMPtr tmpEntryI; + nsNetModRegEntry *tmpEntry = new nsNetModRegEntry(aTopic, aNotify, &rv); if (!tmpEntry) return NS_ERROR_OUT_OF_MEMORY; + + if (NS_FAILED(rv)) return rv; - rv = tmpEntry->QueryInterface(nsCOMTypeInfo::GetIID(), (void**)&tmpEntryI); + rv = tmpEntry->QueryInterface(nsCOMTypeInfo::GetIID(), getter_AddRefs(tmpEntryI)); if (NS_FAILED(rv)) return rv; mEntries->Count(&cnt); @@ -120,7 +122,6 @@ nsNetModuleMgr::UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, NS_RELEASE(curEntry); // ditch our ref to it } PR_Unlock(mLock); - NS_RELEASE(tmpEntryI); return NS_OK; } @@ -146,7 +147,7 @@ nsNetModuleMgr::EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnum for (PRUint32 i = 0; i < cnt; i++) { nsINetModRegEntry *entry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i)); - rv = entry->GetMTopic(&topic); + rv = entry->GetTopic(&topic); if (NS_FAILED(rv)) { NS_RELEASE(topicEntries); NS_RELEASE(entry); diff --git a/mozilla/netwerk/base/src/nsNetModuleMgr.h b/mozilla/netwerk/base/src/nsNetModuleMgr.h index ec12d0f1a90..1e4cd07c49d 100644 --- a/mozilla/netwerk/base/src/nsNetModuleMgr.h +++ b/mozilla/netwerk/base/src/nsNetModuleMgr.h @@ -30,8 +30,8 @@ public: NS_DECL_ISUPPORTS // nsINetModuleMgr - NS_IMETHOD RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID); - NS_IMETHOD UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID); + NS_IMETHOD RegisterModule(const char *aTopic, nsINetNotify *aNotify); + NS_IMETHOD UnregisterModule(const char *aTopic, nsINetNotify *aNotify); NS_IMETHOD EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator); // nsNetModuleMgr