Adding thread proxy support to Net Module Notification.

General cleanup
This commit is contained in:
dougt%netscape.com 1999-08-18 09:32:26 +00:00
Родитель 07dc620ff9
Коммит f18b0e74f6
6 изменённых файлов: 120 добавлений и 116 удалений

Просмотреть файл

@ -24,6 +24,7 @@
interface nsIEventQueue; interface nsIEventQueue;
interface nsINetModRegEntry; interface nsINetModRegEntry;
interface nsINetNotify;
%{ C++ %{ C++
// {F126BD90-1472-11d3-A15A-0050041CAF44} // {F126BD90-1472-11d3-A15A-0050041CAF44}
@ -32,11 +33,11 @@ interface nsINetModRegEntry;
%} %}
[scriptable, uuid(9F482BD0-1476-11d3-A15A-0050041CAF44)] [scriptable, uuid(9F482BD0-1476-11d3-A15A-0050041CAF44)]
interface nsINetModRegEntry : nsISupports { interface nsINetModRegEntry : nsISupports
readonly attribute nsINetNotify mNotify; {
readonly attribute nsIEventQueue mEventQ; readonly attribute nsINetNotify SyncProxy;
readonly attribute string mTopic; readonly attribute nsINetNotify AsyncProxy;
readonly attribute nsCIDPtr mCID; readonly attribute string Topic;
boolean Equals(in nsINetModRegEntry aEntry); boolean Equals(in nsINetModRegEntry aEntry);
}; };

Просмотреть файл

@ -52,11 +52,10 @@ interface nsINetModuleMgr : nsISupports {
// //
// ARGUMENTS: // ARGUMENTS:
// aTopic: The internal component that the external module wants to monitor. // 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. // aNotify: The external module interface methods to be called when an event is fired.
// //
// RETURNS: nsresult // 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 // Unregister the external module. Removes the nsINetModuleMgr binding between
// internal component and external module. // internal component and external module.
@ -66,7 +65,7 @@ interface nsINetModuleMgr : nsISupports {
// aNotify: The external modules notification module. // aNotify: The external modules notification module.
// //
// RETURNS: nsresult // 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. // Enumerates all the registered modules for the specified topic.
// //

Просмотреть файл

@ -19,8 +19,15 @@
#include "nsNetModRegEntry.h" #include "nsNetModRegEntry.h"
#include "plstr.h" #include "plstr.h"
#include "nsIAllocator.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 //// nsISupports
////////////////////////////// //////////////////////////////
@ -32,92 +39,65 @@ NS_IMPL_ISUPPORTS(nsNetModRegEntry, nsCOMTypeInfo<nsINetModRegEntry>::GetIID());
////////////////////////////// //////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsNetModRegEntry::GetMNotify(nsINetNotify **aNotify) { nsNetModRegEntry::GetSyncProxy(nsINetNotify **aNotify) {
*aNotify = mNotify; *aNotify = mSyncProxy;
NS_ADDREF(*aNotify);
return NS_OK;
}
NS_IMETHODIMP
nsNetModRegEntry::GetAsyncProxy(nsINetNotify **aNotify) {
*aNotify = mAsyncProxy;
NS_ADDREF(*aNotify); NS_ADDREF(*aNotify);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNetModRegEntry::GetMEventQ(nsIEventQueue **aEventQ) { nsNetModRegEntry::GetTopic(char **topic)
*aEventQ = mEventQ; {
NS_ADDREF(*aEventQ); if (mTopic)
return NS_OK; {
*topic = (char *) nsAllocator::Clone(mTopic, nsCRT::strlen(mTopic) + 1);
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNetModRegEntry::GetMTopic(char **aTopic) { nsNetModRegEntry::Equals(nsINetModRegEntry* aEntry, PRBool *_retVal)
*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) {
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRBool retVal = PR_TRUE; *_retVal = PR_FALSE;
NS_ADDREF(aEntry); NS_ADDREF(aEntry);
char * topic = 0; char* topic;
nsINetNotify* notify = 0;
nsIEventQueue* eventQ = 0;
nsCID *cid = 0;
rv = aEntry->GetMTopic(&topic); rv = aEntry->GetTopic(&topic);
if (NS_FAILED(rv)) { if (NS_FAILED(rv))
retVal = PR_FALSE; return rv;
goto end;
}
if (PL_strcmp(topic, mTopic)) {
retVal = PR_FALSE;
goto end;
}
rv = aEntry->GetMNotify(&notify);
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:
if (topic) if (topic)
nsAllocator::Free(topic); nsAllocator::Free(topic);
NS_IF_RELEASE(notify);
NS_IF_RELEASE(eventQ); if (PL_strcmp(topic, mTopic))
*_retVal = retVal; return NS_OK;
NS_RELEASE(aEntry);
nsCOMPtr<nsIEventQueue> 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; return rv;
} }
@ -126,18 +106,41 @@ end:
//// nsNetModRegEntry //// nsNetModRegEntry
////////////////////////////// //////////////////////////////
nsNetModRegEntry::nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID) nsNetModRegEntry::nsNetModRegEntry(const char *aTopic,
: mEventQ(aEventQ), mNotify(aNotify) { nsINetNotify *aNotify,
nsresult *result)
{
NS_INIT_REFCNT(); NS_INIT_REFCNT();
mTopic = new char [PL_strlen(aTopic) + 1]; mTopic = new char [PL_strlen(aTopic) + 1];
PL_strcpy(mTopic, aTopic); PL_strcpy(mTopic, aTopic);
NS_ADDREF(mEventQ);
NS_ADDREF(mNotify); NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, result);
mCID = aCID;
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<nsINetNotify>::GetIID(),
aNotify,
PROXY_SYNC | PROXY_ALWAYS,
getter_AddRefs(mSyncProxy));
if (NS_FAILED(*result)) return;
*result = proxyManager->GetProxyObject( mEventQ,
nsCOMTypeInfo<nsINetNotify>::GetIID(),
aNotify,
PROXY_ASYNC | PROXY_ALWAYS,
getter_AddRefs(mAsyncProxy));
} }
nsNetModRegEntry::~nsNetModRegEntry() { nsNetModRegEntry::~nsNetModRegEntry()
{
delete [] mTopic; delete [] mTopic;
NS_RELEASE(mEventQ);
NS_RELEASE(mNotify);
} }

Просмотреть файл

@ -21,6 +21,7 @@
#include "nsINetModRegEntry.h" #include "nsINetModRegEntry.h"
#include "nsIEventQueue.h" #include "nsIEventQueue.h"
#include "nsCOMPtr.h"
class nsNetModRegEntry : public nsINetModRegEntry { class nsNetModRegEntry : public nsINetModRegEntry {
public: public:
@ -28,21 +29,20 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsINetModRegEntry // nsINetModRegEntry
NS_IMETHOD GetMNotify(nsINetNotify **aNotify); NS_IMETHOD GetSyncProxy(nsINetNotify * *aSyncProxy);
NS_IMETHOD GetMEventQ(nsIEventQueue **aEventQ); NS_IMETHOD GetAsyncProxy(nsINetNotify * *aAsyncProxy);
NS_IMETHOD GetMTopic(char **aTopic); NS_IMETHOD GetTopic(char * *aTopic);
NS_IMETHOD GetMCID(nsCID **aCID);
NS_IMETHOD Equals(nsINetModRegEntry* aEntry, PRBool *_retVal); NS_IMETHOD Equals(nsINetModRegEntry* aEntry, PRBool *_retVal);
// nsNetModRegEntry // nsNetModRegEntry
nsNetModRegEntry(const char *aTopic, nsIEventQueue *aEventQ, nsINetNotify *aNotify, nsCID aCID); nsNetModRegEntry(const char *aTopic, nsINetNotify *aNotify, nsresult *result);
virtual ~nsNetModRegEntry(); virtual ~nsNetModRegEntry();
char *mTopic; protected:
nsIEventQueue *mEventQ; char *mTopic;
nsINetNotify *mNotify; nsCOMPtr<nsINetNotify> mSyncProxy;
nsCID mCID; nsCOMPtr<nsINetNotify> mAsyncProxy;
nsCOMPtr<nsIEventQueue> mEventQ;
}; };
#endif //___nsNetModRegEntry_h___ #endif //___nsNetModRegEntry_h___

Просмотреть файл

@ -42,28 +42,30 @@ NS_IMPL_ISUPPORTS(nsNetModuleMgr, nsCOMTypeInfo<nsINetModuleMgr>::GetIID());
/////////////////////////////////// ///////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsNetModuleMgr::RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) { nsNetModuleMgr::RegisterModule(const char *aTopic, nsINetNotify *aNotify)
{
nsresult rv; nsresult rv;
PRUint32 cnt; PRUint32 cnt;
// XXX before registering an object for a particular topic // XXX before registering an object for a particular topic
// XXX QI the nsINetNotify interface passed in for the interfaces // XXX QI the nsINetNotify interface passed in for the interfaces
// XXX supported by the topic. // XXX supported by the topic.
PR_Lock(mLock); PR_Lock(mLock);
nsINetModRegEntry* newEntryI = nsnull; nsCOMPtr<nsINetModRegEntry> newEntryI;
nsNetModRegEntry *newEntry = nsNetModRegEntry *newEntry = new nsNetModRegEntry(aTopic, aNotify, &rv);
new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID);
if (!newEntry) if (!newEntry)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
rv = newEntry->QueryInterface(nsCOMTypeInfo<nsINetModRegEntry>::GetIID(), (void**)&newEntryI); if (NS_FAILED(rv)) return rv;
rv = newEntry->QueryInterface(nsCOMTypeInfo<nsINetModRegEntry>::GetIID(), getter_AddRefs(newEntryI));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Check for a previous registration // Check for a previous registration
mEntries->Count(&cnt); 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)); nsINetModRegEntry* curEntry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i));
PRBool same = PR_FALSE; PRBool same = PR_FALSE;
rv = newEntryI->Equals(curEntry, &same); rv = newEntryI->Equals(curEntry, &same);
@ -82,24 +84,24 @@ nsNetModuleMgr::RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, n
mEntries->AppendElement(NS_STATIC_CAST(nsISupports*, newEntryI)); mEntries->AppendElement(NS_STATIC_CAST(nsISupports*, newEntryI));
PR_Unlock(mLock); PR_Unlock(mLock);
NS_RELEASE(newEntryI);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsNetModuleMgr::UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID) { nsNetModuleMgr::UnregisterModule(const char *aTopic, nsINetNotify *aNotify)
{
PR_Lock(mLock); PR_Lock(mLock);
nsresult rv; nsresult rv;
PRUint32 cnt; PRUint32 cnt;
nsINetModRegEntry* tmpEntryI = nsnull; nsCOMPtr<nsINetModRegEntry> tmpEntryI;
nsNetModRegEntry *tmpEntry = nsNetModRegEntry *tmpEntry = new nsNetModRegEntry(aTopic, aNotify, &rv);
new nsNetModRegEntry(aTopic, aEventQueue, aNotify, *aCID);
if (!tmpEntry) if (!tmpEntry)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv)) return rv;
rv = tmpEntry->QueryInterface(nsCOMTypeInfo<nsINetModRegEntry>::GetIID(), (void**)&tmpEntryI); rv = tmpEntry->QueryInterface(nsCOMTypeInfo<nsINetModRegEntry>::GetIID(), getter_AddRefs(tmpEntryI));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
mEntries->Count(&cnt); mEntries->Count(&cnt);
@ -120,7 +122,6 @@ nsNetModuleMgr::UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue,
NS_RELEASE(curEntry); // ditch our ref to it NS_RELEASE(curEntry); // ditch our ref to it
} }
PR_Unlock(mLock); PR_Unlock(mLock);
NS_RELEASE(tmpEntryI);
return NS_OK; return NS_OK;
} }
@ -146,7 +147,7 @@ nsNetModuleMgr::EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnum
for (PRUint32 i = 0; i < cnt; i++) { for (PRUint32 i = 0; i < cnt; i++) {
nsINetModRegEntry *entry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i)); nsINetModRegEntry *entry = NS_STATIC_CAST(nsINetModRegEntry*, mEntries->ElementAt(i));
rv = entry->GetMTopic(&topic); rv = entry->GetTopic(&topic);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_RELEASE(topicEntries); NS_RELEASE(topicEntries);
NS_RELEASE(entry); NS_RELEASE(entry);

Просмотреть файл

@ -30,8 +30,8 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsINetModuleMgr // nsINetModuleMgr
NS_IMETHOD RegisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID); NS_IMETHOD RegisterModule(const char *aTopic, nsINetNotify *aNotify);
NS_IMETHOD UnregisterModule(const char *aTopic, nsIEventQueue *aEventQueue, nsINetNotify *aNotify, const nsCID * aCID); NS_IMETHOD UnregisterModule(const char *aTopic, nsINetNotify *aNotify);
NS_IMETHOD EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator); NS_IMETHOD EnumerateModules(const char *aTopic, nsISimpleEnumerator **aEnumerator);
// nsNetModuleMgr // nsNetModuleMgr