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
parent 2df3b74a7b
commit 431a9eef50
6 changed files with 120 additions and 116 deletions

View File

@ -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);
};

View File

@ -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.
//

View File

@ -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<nsINetModRegEntry>::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(&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:
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<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;
}
@ -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<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;
NS_RELEASE(mEventQ);
NS_RELEASE(mNotify);
}

View File

@ -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<nsINetNotify> mSyncProxy;
nsCOMPtr<nsINetNotify> mAsyncProxy;
nsCOMPtr<nsIEventQueue> mEventQ;
};
#endif //___nsNetModRegEntry_h___

View File

@ -42,28 +42,30 @@ NS_IMPL_ISUPPORTS(nsNetModuleMgr, nsCOMTypeInfo<nsINetModuleMgr>::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<nsINetModRegEntry> newEntryI;
nsNetModRegEntry *newEntry = new nsNetModRegEntry(aTopic, aNotify, &rv);
if (!newEntry)
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;
// 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<nsINetModRegEntry> 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<nsINetModRegEntry>::GetIID(), (void**)&tmpEntryI);
rv = tmpEntry->QueryInterface(nsCOMTypeInfo<nsINetModRegEntry>::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);

View File

@ -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