From c894debbc83027d8e3b5c24a4fa5f6b5a7c0da32 Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Fri, 11 Dec 1998 01:03:12 +0000 Subject: [PATCH] fixing factory issues --- editor/base/editor.cpp | 23 +++++++++-------- editor/base/nsEditFactory.cpp | 47 +++++++++++++++++------------------ editor/base/nsEditFactory.h | 8 ++++-- editor/core/editor.cpp | 23 +++++++++-------- editor/core/nsEditFactory.cpp | 47 +++++++++++++++++------------------ editor/core/nsEditFactory.h | 8 ++++-- 6 files changed, 84 insertions(+), 72 deletions(-) diff --git a/editor/base/editor.cpp b/editor/base/editor.cpp index ee2e8758eda2..01440010ea83 100644 --- a/editor/base/editor.cpp +++ b/editor/base/editor.cpp @@ -25,20 +25,22 @@ #include "nsIDocument.h" #include "nsRepository.h" #include "nsEditFactory.h" +#include "nsEditorCID.h" static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); -static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); -static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); -static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); -static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); +static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); +static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID); //monitor for the editor @@ -73,7 +75,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory *aFactory = nsnull; - if (aClass.Equals(kIEditFactoryIID)) { + if (aClass.Equals(kEditorCID)) { return getEditFactory(aFactory); } return NS_NOINTERFACE; @@ -115,6 +117,7 @@ NSUnregisterSelf(const char *path) nsEditor::nsEditor() { //initialize member variables here + NS_INIT_REFCNT(); } diff --git a/editor/base/nsEditFactory.cpp b/editor/base/nsEditFactory.cpp index 3bdc2de27410..da5e63d2f3c4 100644 --- a/editor/base/nsEditFactory.cpp +++ b/editor/base/nsEditFactory.cpp @@ -20,12 +20,13 @@ #include "nsIEditor.h" #include "editor.h" #include "nsRepository.h" - +#include "nsEditorCID.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); +static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID); @@ -37,14 +38,12 @@ getEditFactory(nsIFactory **aFactory) nsresult result = NS_ERROR_FAILURE; if (!g_pNSIFactory) { - nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory)); - *aFactory = g_pNSIFactory; - NS_IF_ADDREF(*aFactory); + nsEditFactory *factory = new nsEditFactory(kEditorCID); + g_pNSIFactory = factory; if (factory) result = NS_OK; } - else - result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); + result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); PR_ExitMonitor(getEditorMonitor()); return result; } @@ -62,7 +61,7 @@ nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(kIFactoryIID) || aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*) this; - AddRef(); + AddRef(); return NS_OK; } return NS_NOINTERFACE; @@ -78,18 +77,23 @@ NS_IMPL_RELEASE(nsEditFactory) NS_METHOD nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - nsEditor *editor = nsnull; *aResult = nsnull; - + nsISupports *obj = nsnull; + if (!aResult) + return NS_ERROR_NULL_POINTER; if (aOuter && !aIID.Equals(kISupportsIID)) return NS_NOINTERFACE; // XXX right error? - editor = new nsEditor(); - if (editor->QueryInterface(aIID, - (void**)aResult) != NS_OK) { - // then we're trying get a interface other than nsISupports and - // nsIEditor - delete editor; - return NS_ERROR_FAILURE; + + + if (mCID.Equals(kEditorCID)) + obj = (nsISupports *)new nsEditor(); + //more class ids to support. here + + + if (NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) ) + { + delete obj; + return NS_NOINTERFACE; } return NS_OK; } @@ -107,20 +111,15 @@ nsEditFactory::LockFactory(PRBool aLock) //////////////////////////////////////////////////////////////////////////// // from nsEditFactory: -nsEditFactory::nsEditFactory(nsIFactory **aFactory) +nsEditFactory::nsEditFactory(const nsCID &aClass) +:mCID(aClass) { NS_INIT_REFCNT(); - nsresult err = NS_OK; - NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); - if (aFactory) - { - err = this->QueryInterface(kIFactoryIID, (void**)aFactory); - } } nsEditFactory::~nsEditFactory() { - nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway + nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway } diff --git a/editor/base/nsEditFactory.h b/editor/base/nsEditFactory.h index 73bfb3e2072b..1f7324944d19 100644 --- a/editor/base/nsEditFactory.h +++ b/editor/base/nsEditFactory.h @@ -20,7 +20,6 @@ #include "nsISupports.h" #include "nsIFactory.h" -class nsEditor; /* EditFactory that can make an editor @@ -56,8 +55,13 @@ public: virtual ~nsEditFactory(void); private: - nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface + nsEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface + + /** getEditFactory + * creates an edit factory other CSID supported friend functions here. + */ friend nsresult getEditFactory(nsIFactory **); + const nsCID &mCID; }; #endif //nsIEditFactory_h___ diff --git a/editor/core/editor.cpp b/editor/core/editor.cpp index ee2e8758eda2..01440010ea83 100644 --- a/editor/core/editor.cpp +++ b/editor/core/editor.cpp @@ -25,20 +25,22 @@ #include "nsIDocument.h" #include "nsRepository.h" #include "nsEditFactory.h" +#include "nsEditorCID.h" static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); -static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); -static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); -static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); -static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); -static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); +static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); +static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID); //monitor for the editor @@ -73,7 +75,7 @@ extern "C" NS_EXPORT nsresult NSGetFactory(const nsCID &aClass, nsIFactory *aFactory = nsnull; - if (aClass.Equals(kIEditFactoryIID)) { + if (aClass.Equals(kEditorCID)) { return getEditFactory(aFactory); } return NS_NOINTERFACE; @@ -115,6 +117,7 @@ NSUnregisterSelf(const char *path) nsEditor::nsEditor() { //initialize member variables here + NS_INIT_REFCNT(); } diff --git a/editor/core/nsEditFactory.cpp b/editor/core/nsEditFactory.cpp index 3bdc2de27410..da5e63d2f3c4 100644 --- a/editor/core/nsEditFactory.cpp +++ b/editor/core/nsEditFactory.cpp @@ -20,12 +20,13 @@ #include "nsIEditor.h" #include "editor.h" #include "nsRepository.h" - +#include "nsEditorCID.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); static NS_DEFINE_IID(kIEditorIID, NS_IEDITOR_IID); static NS_DEFINE_IID(kIEditFactoryIID, NS_IEDITORFACTORY_IID); +static NS_DEFINE_IID(kEditorCID, NS_EDITOR_CID); @@ -37,14 +38,12 @@ getEditFactory(nsIFactory **aFactory) nsresult result = NS_ERROR_FAILURE; if (!g_pNSIFactory) { - nsEditFactory *factory = new nsEditFactory(getter_AddRefs(g_pNSIFactory)); - *aFactory = g_pNSIFactory; - NS_IF_ADDREF(*aFactory); + nsEditFactory *factory = new nsEditFactory(kEditorCID); + g_pNSIFactory = factory; if (factory) result = NS_OK; } - else - result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); + result = g_pNSIFactory->QueryInterface(kIFactoryIID, (void **)aFactory); PR_ExitMonitor(getEditorMonitor()); return result; } @@ -62,7 +61,7 @@ nsEditFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr) if (aIID.Equals(kIFactoryIID) || aIID.Equals(kISupportsIID)) { *aInstancePtr = (void*) this; - AddRef(); + AddRef(); return NS_OK; } return NS_NOINTERFACE; @@ -78,18 +77,23 @@ NS_IMPL_RELEASE(nsEditFactory) NS_METHOD nsEditFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - nsEditor *editor = nsnull; *aResult = nsnull; - + nsISupports *obj = nsnull; + if (!aResult) + return NS_ERROR_NULL_POINTER; if (aOuter && !aIID.Equals(kISupportsIID)) return NS_NOINTERFACE; // XXX right error? - editor = new nsEditor(); - if (editor->QueryInterface(aIID, - (void**)aResult) != NS_OK) { - // then we're trying get a interface other than nsISupports and - // nsIEditor - delete editor; - return NS_ERROR_FAILURE; + + + if (mCID.Equals(kEditorCID)) + obj = (nsISupports *)new nsEditor(); + //more class ids to support. here + + + if (NS_FAILED(obj->QueryInterface(aIID, (void**)aResult)) ) + { + delete obj; + return NS_NOINTERFACE; } return NS_OK; } @@ -107,20 +111,15 @@ nsEditFactory::LockFactory(PRBool aLock) //////////////////////////////////////////////////////////////////////////// // from nsEditFactory: -nsEditFactory::nsEditFactory(nsIFactory **aFactory) +nsEditFactory::nsEditFactory(const nsCID &aClass) +:mCID(aClass) { NS_INIT_REFCNT(); - nsresult err = NS_OK; - NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); - if (aFactory) - { - err = this->QueryInterface(kIFactoryIID, (void**)aFactory); - } } nsEditFactory::~nsEditFactory() { - nsRepository::UnregisterFactory(kIEditFactoryIID, (nsIFactory *)this); //we are out of ref counts anyway + nsRepository::UnregisterFactory(mCID, (nsIFactory *)this); //we are out of ref counts anyway } diff --git a/editor/core/nsEditFactory.h b/editor/core/nsEditFactory.h index 73bfb3e2072b..1f7324944d19 100644 --- a/editor/core/nsEditFactory.h +++ b/editor/core/nsEditFactory.h @@ -20,7 +20,6 @@ #include "nsISupports.h" #include "nsIFactory.h" -class nsEditor; /* EditFactory that can make an editor @@ -56,8 +55,13 @@ public: virtual ~nsEditFactory(void); private: - nsEditFactory(nsIFactory **aFactory); //will fill the aFactory with the result from queryinterface + nsEditFactory(const nsCID &aClass); //will fill the aFactory with the result from queryinterface + + /** getEditFactory + * creates an edit factory other CSID supported friend functions here. + */ friend nsresult getEditFactory(nsIFactory **); + const nsCID &mCID; }; #endif //nsIEditFactory_h___