mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Templates in nsXPComFactory exorcism. Part I.
Replaced the template code with a NS_DEF_FACTORY. This is temporary. As soon as I can verify this works on windows and mac, ill remove the old code.
This commit is contained in:
parent
aa33bfc9fe
commit
8a849f863a
@ -812,11 +812,19 @@ HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource t
|
||||
|
||||
#include "nsXPComFactory.h"
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
NS_DEF_FACTORY(BookmarkDataSource,BookmarkDataSourceImpl)
|
||||
#endif
|
||||
|
||||
nsresult
|
||||
NS_NewRDFBookmarkDataSourceFactory(nsIFactory** aResult)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
nsIFactory* inst = new nsBookmarkDataSourceFactory;
|
||||
#else
|
||||
nsIFactory* inst = new nsFactory<BookmarkDataSourceImpl>();
|
||||
#endif
|
||||
if (NULL == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
|
@ -1777,6 +1777,17 @@ nsDocumentBindInfo::CancelRefreshURLTimers(void)
|
||||
*******************************************/
|
||||
static nsDocLoaderImpl* gServiceInstance = nsnull;
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
NS_DEF_FACTORY(DocLoaderServiceGen,nsDocLoaderImpl)
|
||||
|
||||
class nsDocLoaderServiceFactory : public nsDocLoaderServiceGenFactory
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#else
|
||||
class nsDocLoaderServiceFactory : public nsFactory<nsDocLoaderImpl>
|
||||
{
|
||||
public:
|
||||
@ -1784,6 +1795,7 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocLoaderServiceFactory::CreateInstance(nsISupports *aOuter,
|
||||
@ -1830,7 +1842,7 @@ done:
|
||||
}
|
||||
|
||||
|
||||
// Entry point to create nsEventQueueService factory instances...
|
||||
// Entry point to create nsDocLoaderService factory instances...
|
||||
|
||||
nsresult NS_NewDocLoaderServiceFactory(nsIFactory** aResult)
|
||||
{
|
||||
|
@ -1777,6 +1777,17 @@ nsDocumentBindInfo::CancelRefreshURLTimers(void)
|
||||
*******************************************/
|
||||
static nsDocLoaderImpl* gServiceInstance = nsnull;
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
NS_DEF_FACTORY(DocLoaderServiceGen,nsDocLoaderImpl)
|
||||
|
||||
class nsDocLoaderServiceFactory : public nsDocLoaderServiceGenFactory
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#else
|
||||
class nsDocLoaderServiceFactory : public nsFactory<nsDocLoaderImpl>
|
||||
{
|
||||
public:
|
||||
@ -1784,6 +1795,7 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocLoaderServiceFactory::CreateInstance(nsISupports *aOuter,
|
||||
@ -1830,7 +1842,7 @@ done:
|
||||
}
|
||||
|
||||
|
||||
// Entry point to create nsEventQueueService factory instances...
|
||||
// Entry point to create nsDocLoaderService factory instances...
|
||||
|
||||
nsresult NS_NewDocLoaderServiceFactory(nsIFactory** aResult)
|
||||
{
|
||||
|
@ -22,6 +22,148 @@
|
||||
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
* TEMPLATES_IN_nsXPComFactory_EXORCISM is a temporary hack until I can
|
||||
* verify that this works on windows and mac. -re
|
||||
*/
|
||||
#if defined(XP_UNIX)
|
||||
#define TEMPLATES_IN_nsXPComFactory_EXORCISM 1
|
||||
#endif
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
/*
|
||||
* This file contains a macro for the implementation of a simple XPCOM factory.
|
||||
*
|
||||
* To implement a factory for a given component, you need to declare the
|
||||
* factory class using the NS_DEF_FACTORY() macro.
|
||||
*
|
||||
* The first macro argument is the name for the factory.
|
||||
*
|
||||
* The second macro argument is a function (provided by you) which
|
||||
* can be called by your DLL's NSGetFactory(...) entry point.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* NS_DEF_FACTORY(SomeComponent,SomeComponentImpl)
|
||||
*
|
||||
* Declares:
|
||||
*
|
||||
* class nsSomeComponentFactory : public nsIFactory {};
|
||||
*
|
||||
* NOTE that the NS_DEF_FACTORY takes care of enforcing the "ns" prefix
|
||||
* and appending the "Factory" suffix to the given name.
|
||||
*
|
||||
* To use the new factory:
|
||||
*
|
||||
* nsresult NS_New_SomeComponent_Factory(nsIFactory** aResult)
|
||||
* {
|
||||
* nsresult rv = NS_OK;
|
||||
* nsIFactory* inst = new nsSomeComponentFactory;
|
||||
* if (NULL == inst) {
|
||||
* rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
* } else {
|
||||
* NS_ADDREF(inst);
|
||||
* }
|
||||
* *aResult = inst;
|
||||
* return rv;
|
||||
* }
|
||||
*
|
||||
* NOTE:
|
||||
* ----
|
||||
* The factories created by this macro are not thread-safe and do not
|
||||
* support aggregation.
|
||||
*
|
||||
*/
|
||||
#define NS_DEF_FACTORY(_name,_type) \
|
||||
class ns##_name##Factory : public nsIFactory \
|
||||
{ \
|
||||
public: \
|
||||
ns##_name##Factory() { NS_INIT_REFCNT(); } \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) AddRef (void) \
|
||||
{ \
|
||||
return ++mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
if (--mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
} \
|
||||
\
|
||||
*aInstancePtr = NULL; \
|
||||
\
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); \
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
if (aIID.Equals(kIFactoryIID)) { \
|
||||
*aInstancePtr = (void*) this; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kISupportsIID)) { \
|
||||
*aInstancePtr = (void*) ((nsISupports*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, \
|
||||
const nsIID &aIID, \
|
||||
void **aResult) \
|
||||
{ \
|
||||
nsresult rv; \
|
||||
\
|
||||
_type * inst; \
|
||||
\
|
||||
if (NULL == aResult) { \
|
||||
rv = NS_ERROR_NULL_POINTER; \
|
||||
goto done; \
|
||||
} \
|
||||
*aResult = NULL; \
|
||||
if (NULL != aOuter) { \
|
||||
rv = NS_ERROR_NO_AGGREGATION; \
|
||||
goto done; \
|
||||
} \
|
||||
\
|
||||
NS_NEWXPCOM(inst, _type); \
|
||||
if (NULL == inst) { \
|
||||
rv = NS_ERROR_OUT_OF_MEMORY; \
|
||||
goto done; \
|
||||
} \
|
||||
NS_ADDREF(inst); \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
NS_RELEASE(inst); \
|
||||
\
|
||||
done: \
|
||||
return rv; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD LockFactory(PRBool aLock) \
|
||||
{ \
|
||||
return NS_OK; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
protected: \
|
||||
virtual ~ns##_name##Factory() \
|
||||
{ \
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); \
|
||||
} \
|
||||
\
|
||||
nsrefcnt mRefCnt; \
|
||||
};
|
||||
#else
|
||||
/*
|
||||
* This file contains a templatized implementation of a simple XPCOM factory.
|
||||
*
|
||||
@ -148,6 +290,7 @@ protected:
|
||||
// Reference count variable used by nsISupports...
|
||||
nsrefcnt mRefCnt;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* nsXPComFactory_h__ */
|
||||
|
@ -22,6 +22,148 @@
|
||||
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
* TEMPLATES_IN_nsXPComFactory_EXORCISM is a temporary hack until I can
|
||||
* verify that this works on windows and mac. -re
|
||||
*/
|
||||
#if defined(XP_UNIX)
|
||||
#define TEMPLATES_IN_nsXPComFactory_EXORCISM 1
|
||||
#endif
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
/*
|
||||
* This file contains a macro for the implementation of a simple XPCOM factory.
|
||||
*
|
||||
* To implement a factory for a given component, you need to declare the
|
||||
* factory class using the NS_DEF_FACTORY() macro.
|
||||
*
|
||||
* The first macro argument is the name for the factory.
|
||||
*
|
||||
* The second macro argument is a function (provided by you) which
|
||||
* can be called by your DLL's NSGetFactory(...) entry point.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* NS_DEF_FACTORY(SomeComponent,SomeComponentImpl)
|
||||
*
|
||||
* Declares:
|
||||
*
|
||||
* class nsSomeComponentFactory : public nsIFactory {};
|
||||
*
|
||||
* NOTE that the NS_DEF_FACTORY takes care of enforcing the "ns" prefix
|
||||
* and appending the "Factory" suffix to the given name.
|
||||
*
|
||||
* To use the new factory:
|
||||
*
|
||||
* nsresult NS_New_SomeComponent_Factory(nsIFactory** aResult)
|
||||
* {
|
||||
* nsresult rv = NS_OK;
|
||||
* nsIFactory* inst = new nsSomeComponentFactory;
|
||||
* if (NULL == inst) {
|
||||
* rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
* } else {
|
||||
* NS_ADDREF(inst);
|
||||
* }
|
||||
* *aResult = inst;
|
||||
* return rv;
|
||||
* }
|
||||
*
|
||||
* NOTE:
|
||||
* ----
|
||||
* The factories created by this macro are not thread-safe and do not
|
||||
* support aggregation.
|
||||
*
|
||||
*/
|
||||
#define NS_DEF_FACTORY(_name,_type) \
|
||||
class ns##_name##Factory : public nsIFactory \
|
||||
{ \
|
||||
public: \
|
||||
ns##_name##Factory() { NS_INIT_REFCNT(); } \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) AddRef (void) \
|
||||
{ \
|
||||
return ++mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
if (--mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
} \
|
||||
\
|
||||
*aInstancePtr = NULL; \
|
||||
\
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); \
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
if (aIID.Equals(kIFactoryIID)) { \
|
||||
*aInstancePtr = (void*) this; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kISupportsIID)) { \
|
||||
*aInstancePtr = (void*) ((nsISupports*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, \
|
||||
const nsIID &aIID, \
|
||||
void **aResult) \
|
||||
{ \
|
||||
nsresult rv; \
|
||||
\
|
||||
_type * inst; \
|
||||
\
|
||||
if (NULL == aResult) { \
|
||||
rv = NS_ERROR_NULL_POINTER; \
|
||||
goto done; \
|
||||
} \
|
||||
*aResult = NULL; \
|
||||
if (NULL != aOuter) { \
|
||||
rv = NS_ERROR_NO_AGGREGATION; \
|
||||
goto done; \
|
||||
} \
|
||||
\
|
||||
NS_NEWXPCOM(inst, _type); \
|
||||
if (NULL == inst) { \
|
||||
rv = NS_ERROR_OUT_OF_MEMORY; \
|
||||
goto done; \
|
||||
} \
|
||||
NS_ADDREF(inst); \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
NS_RELEASE(inst); \
|
||||
\
|
||||
done: \
|
||||
return rv; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD LockFactory(PRBool aLock) \
|
||||
{ \
|
||||
return NS_OK; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
protected: \
|
||||
virtual ~ns##_name##Factory() \
|
||||
{ \
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); \
|
||||
} \
|
||||
\
|
||||
nsrefcnt mRefCnt; \
|
||||
};
|
||||
#else
|
||||
/*
|
||||
* This file contains a templatized implementation of a simple XPCOM factory.
|
||||
*
|
||||
@ -148,6 +290,7 @@ protected:
|
||||
// Reference count variable used by nsISupports...
|
||||
nsrefcnt mRefCnt;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* nsXPComFactory_h__ */
|
||||
|
@ -251,6 +251,18 @@ done:
|
||||
|
||||
static nsEventQueueServiceImpl* gServiceInstance = NULL;
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
NS_DEF_FACTORY(EventQueueServiceGen,nsEventQueueServiceImpl)
|
||||
|
||||
class nsEventQueueServiceFactory : public nsEventQueueServiceGenFactory
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
|
||||
#else
|
||||
class nsEventQueueServiceFactory : public nsFactory<nsEventQueueServiceImpl>
|
||||
{
|
||||
public:
|
||||
@ -258,6 +270,7 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEventQueueServiceFactory::CreateInstance(nsISupports *aOuter,
|
||||
|
@ -251,6 +251,18 @@ done:
|
||||
|
||||
static nsEventQueueServiceImpl* gServiceInstance = NULL;
|
||||
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
NS_DEF_FACTORY(EventQueueServiceGen,nsEventQueueServiceImpl)
|
||||
|
||||
class nsEventQueueServiceFactory : public nsEventQueueServiceGenFactory
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
|
||||
#else
|
||||
class nsEventQueueServiceFactory : public nsFactory<nsEventQueueServiceImpl>
|
||||
{
|
||||
public:
|
||||
@ -258,6 +270,7 @@ public:
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
};
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEventQueueServiceFactory::CreateInstance(nsISupports *aOuter,
|
||||
|
@ -351,11 +351,16 @@ NS_EXPORT nsresult NS_NewAppShellService(nsIAppShellService** aResult)
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Entry point to create nsAppShellService factory instances...
|
||||
NS_DEF_FACTORY(AppShellService,nsAppShellService)
|
||||
|
||||
nsresult NS_NewAppShellServiceFactory(nsIFactory** aResult)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
#if defined(TEMPLATES_IN_nsXPComFactory_EXORCISM)
|
||||
nsIFactory* inst = new nsAppShellServiceFactory;
|
||||
#else
|
||||
nsIFactory* inst = new nsFactory<nsAppShellService>();
|
||||
#endif
|
||||
if (nsnull == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user