67699: all your nsIClassInfo is belong to us

- teach nsGenericFactory about nsIClassInfo, and nsIClassInfo.idl to the
  builds
- add a heaping serving of macro love for classes that want to support it
- convert many modules to use nsGenericModule the new way
- handful of warning and modeline fixes
- nsSample and some XPConnect test classes now have nsIClassInfo support for
  testing


git-svn-id: svn://10.0.0.236/trunk@89354 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shaver%mozilla.org
2001-03-12 20:43:02 +00:00
parent 3b60ed87ef
commit 823ae8572c
57 changed files with 1205 additions and 1786 deletions

View File

@@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file

View File

@@ -46,7 +46,8 @@
// This function is called at component registration time
static NS_METHOD nsAccessProxyRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath, const char *registryLocation, const char *componentType)
nsIFile *aPath, const char *registryLocation, const char *componentType,
const nsModuleComponentInfo *info)
{
// This function performs the extra step of installing us as
// an application component. This makes sure that we're

View File

@@ -59,7 +59,8 @@ nsresult nsCookieHTTPNotify::Create(nsISupports *aOuter, REFNSIID aIID, void **a
NS_METHOD nsCookieHTTPNotify::RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
// Register ourselves into the NS_CATEGORY_HTTP_STARTUP
nsresult rv;
@@ -76,7 +77,8 @@ NS_METHOD nsCookieHTTPNotify::RegisterProc(nsIComponentManager *aCompMgr,
NS_METHOD nsCookieHTTPNotify::UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation)
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv);

View File

@@ -35,6 +35,8 @@
#define NS_COOKIEHTTPNOTIFY_CONTRACTID "@mozilla.org/cookie-notifier;1"
#define NS_COOKIEHTTPNOTIFY_CLASSNAME "Cookie Notifier"
struct nsModuleComponentInfo; // forward declaration
class nsCookieHTTPNotify : public nsIHTTPNotify {
public:
@@ -56,10 +58,12 @@ public:
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType);
const char *componentType,
const nsModuleComponentInfo *info);
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation);
const char *registryLocation,
const nsModuleComponentInfo *info);
private:
nsCOMPtr<nsIAtom> mCookieHeader;

View File

@@ -180,7 +180,8 @@ static NS_METHOD
RegisterTransformiix(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
// get the registry
nsIRegistry* registry;

View File

@@ -219,7 +219,8 @@ static NS_METHOD
RegisterXMLExtras(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
// get the registry
nsIRegistry* registry;

View File

@@ -159,25 +159,6 @@ static NS_DEFINE_CID(kViewSourceDTDCID, NS_VIEWSOURCE_DTD_CID);
static NS_DEFINE_CID(kHTMLContentSinkStreamCID, NS_HTMLCONTENTSINKSTREAM_CID);
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
struct Components {
const char* mDescription;
const nsID* mCID;
};
static Components gComponents[] = {
{ "Parser", &kParserCID },
{ "Logging sink", &kLoggingSinkCID },
{ "Well formed DTD", &kWellFormedDTDCID },
{ "Navigator HTML DTD", &kNavDTDCID },
{ "OTHER DTD", &kCOtherDTDCID },
{ "Transitional DTD", &kCTransitionalDTDCID },
{ "ViewSource DTD", &kViewSourceDTDCID },
{ "HTML Content Sink Stream", &kHTMLContentSinkStreamCID },
{ "ParserService", &kParserServiceCID },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]));
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
NS_GENERIC_FACTORY_CONSTRUCTOR(CWellFormedDTD)
@@ -188,6 +169,21 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLContentSinkStream)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserService)
static nsModuleComponentInfo gComponents[] = {
{ "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
{ "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
{ "Well formed DTD", NS_WELLFORMEDDTD_CID, NULL, CWellFormedDTDConstructor },
{ "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
{ "OTHER DTD", NS_COTHER_DTD_CID, NULL, COtherDTDConstructor },
{ "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
CTransitionalDTDConstructor },
{ "ViewSource DTD", NS_VIEWSOURCE_DTD_CID, NULL, CViewSourceHTMLConstructor },
{ "HTML Content Sink Stream", NS_HTMLCONTENTSINKSTREAM_CID, NULL,
nsHTMLContentSinkStreamConstructor },
{ "ParserService", NS_PARSERSERVICE_CID, NULL, nsParserServiceConstructor }
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
//----------------------------------------------------------------------
class nsParserModule : public nsIModule {
@@ -205,20 +201,8 @@ protected:
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mParserFactory;
nsCOMPtr<nsIGenericFactory> mParserNodeFactory;
nsCOMPtr<nsIGenericFactory> mLoggingSinkFactory;
nsCOMPtr<nsIGenericFactory> mWellFormedDTDFactory;
nsCOMPtr<nsIGenericFactory> mNavHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mOtherHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mTransitionalHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mViewSourceHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mHTMLContentSinkStreamFactory;
nsCOMPtr<nsIGenericFactory> mParserServiceFactory;
};
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsParserModule::nsParserModule()
: mInitialized(PR_FALSE)
{
@@ -230,7 +214,7 @@ nsParserModule::~nsParserModule()
Shutdown();
}
NS_IMPL_ISUPPORTS(nsParserModule, kIModuleIID)
NS_IMPL_ISUPPORTS1(nsParserModule, nsIModule)
nsresult
nsParserModule::Initialize()
@@ -277,71 +261,11 @@ nsParserModule::GetClassObject(nsIComponentManager *aCompMgr,
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kParserCID)) {
if (!mParserFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mParserFactory),
&nsParserConstructor);
for (unsigned int i = 0; i < NUM_COMPONENTS; i++) {
if (aClass.Equals(gComponents[i].mCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), &gComponents[i]);
break;
}
fact = mParserFactory;
}
else if (aClass.Equals(kLoggingSinkCID)) {
if (!mLoggingSinkFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mLoggingSinkFactory),
&nsLoggingSinkConstructor);
}
fact = mLoggingSinkFactory;
}
else if (aClass.Equals(kWellFormedDTDCID)) {
if (!mWellFormedDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mWellFormedDTDFactory),
&CWellFormedDTDConstructor);
}
fact = mWellFormedDTDFactory;
}
else if (aClass.Equals(kNavDTDCID)) {
if (!mNavHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mNavHTMLDTDFactory),
&CNavDTDConstructor);
}
fact = mNavHTMLDTDFactory;
}
else if (aClass.Equals(kCOtherDTDCID)) {
if (!mOtherHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mOtherHTMLDTDFactory),
&COtherDTDConstructor);
}
fact = mOtherHTMLDTDFactory;
}
else if (aClass.Equals(kCTransitionalDTDCID)) {
if (!mTransitionalHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mTransitionalHTMLDTDFactory),
&CTransitionalDTDConstructor);
}
fact = mTransitionalHTMLDTDFactory;
}
else if (aClass.Equals(kViewSourceDTDCID)) {
if (!mViewSourceHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mViewSourceHTMLDTDFactory),
&CViewSourceHTMLConstructor);
}
fact = mViewSourceHTMLDTDFactory;
}
else if (aClass.Equals(kHTMLContentSinkStreamCID)) {
if (!mHTMLContentSinkStreamFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mHTMLContentSinkStreamFactory),
&nsHTMLContentSinkStreamConstructor);
}
fact = mHTMLContentSinkStreamFactory;
}
else if (aClass.Equals(kParserServiceCID)) {
if (!mParserServiceFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mParserServiceFactory),
&nsParserServiceConstructor);
}
fact = mParserServiceFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
}
if (fact) {
@@ -358,10 +282,9 @@ nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
nsModuleComponentInfo* cp = gComponents, *end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
nsnull, aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
@@ -380,10 +303,9 @@ nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
nsModuleComponentInfo* cp = gComponents, *end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to unregister %s component => %x\n",

View File

@@ -102,7 +102,8 @@ static NS_IMETHODIMP \
_InstanceClass##RegSelf (nsIComponentManager *aCompMgr, \
nsIFile *aPath, \
const char* registryLocation, \
const char* componentType) \
const char* componentType, \
const nsModuleComponentInfo *info) \
{ \
nsCID cid = _CID; \
return nsUConverterRegSelf( _From, _To, cid); \
@@ -110,7 +111,8 @@ _InstanceClass##RegSelf (nsIComponentManager *aCompMgr, \
static NS_IMETHODIMP \
_InstanceClass##UnRegSelf (nsIComponentManager *aCompMgr, \
nsIFile *aPath, \
const char* registryLocation) \
const char* registryLocation, \
const nsModuleComponentInfo *info) \
{ \
printf("UnRegSelf " _From " to " _To "converter not implement\n"); \
return NS_OK; \

View File

@@ -32,7 +32,7 @@ NS_DECLARE_ID(kMacRomanToUnicodeCID,
#define NS_MACROMANTOUNICODE_CONTRACTID "@mozilla.org/intl/unicode/decoder;1?charset=x-mac-roman"
//#define NS_ERROR_UCONV_NOMACROMANTOUNICODE \
//#define NS_ERROR_UCONV_NOMACROMANTOUNICODE
// NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)
//----------------------------------------------------------------------

View File

@@ -113,13 +113,92 @@ nsUConvModule::Shutdown()
{
}
//----------------------------------------
// This is a mid-range hack, in terms of ugliness.
//
// * shaver considers rewriting nsUConvModule.cpp
// <jag> shaver: don't do it, not today. Long term
//
// So blame jag.
struct Components {
nsModuleComponentInfo info;
const char* mCharsetSrc;
const char* mCharsetDest;
};
// The list of components we register
static Components gComponents[] = {
{ { "Charset Conversion Manager", NS_ICHARSETCONVERTERMANAGER_CID,
NS_CHARSETCONVERTERMANAGER_CONTRACTID, NS_NewCharsetConverterManager },
NULL, NULL, },
{ { "Unicode Decode Helper", NS_UNICODEDECODEHELPER_CID,
NS_UNICODEDECODEHELPER_CONTRACTID, NS_NewUnicodeDecodeHelper },
NULL, NULL, },
{ { "Unicode Encode Helper", NS_UNICODEENCODEHELPER_CID,
NS_UNICODEENCODEHELPER_CONTRACTID, NS_NewUnicodeEncodeHelper },
NULL, NULL, },
{ { "Platform Charset Information", NS_PLATFORMCHARSET_CID,
NS_PLATFORMCHARSET_CONTRACTID, NS_NewPlatformCharset },
NULL, NULL, },
{ { "Charset Alias Information", NS_CHARSETALIAS_CID,
NS_CHARSETALIAS_CONTRACTID, NS_NewCharsetAlias },
NULL, NULL, },
{ { NS_CHARSETMENU_PID, NS_CHARSETMENU_CID,
NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CHARSETMENU_PID,
NS_NewCharsetMenu},
NULL, NULL, },
{ { "Text To Sub URI Helper", NS_TEXTTOSUBURI_CID,
NS_ITEXTTOSUBURI_CONTRACTID, NS_NewTextToSubURI },
NULL, NULL, },
{ { "ISO-8859-1 To Unicode Converter", NS_ISO88591TOUNICODE_CID,
NS_ISO88591TOUNICODE_CONTRACTID, NS_NewISO88591ToUnicode },
"ISO-8859-1", "Unicode", },
{ { "windows-1252 To Unicode Converter", NS_CP1252TOUNICODE_CID,
NS_CP1252TOUNICODE_CONTRACTID, NS_NewCP1252ToUnicode },
"windows-1252", "Unicode", },
{ { "x-mac-roman To Unicode Converter", NS_MACROMANTOUNICODE_CID,
NS_MACROMANTOUNICODE_CONTRACTID, NS_NewMacRomanToUnicode },
"x-mac-roman", "Unicode", },
{ { "UTF-8 To Unicode Converter", NS_UTF8TOUNICODE_CID,
NS_UTF8TOUNICODE_CONTRACTID, NS_NewUTF8ToUnicode },
"UTF-8", "Unicode", },
{ { "Unicode To ISO-8859-1 Converter", NS_UNICODETOISO88591_CID,
NS_UNICODETOISO88591_CONTRACTID, NS_NewUnicodeToISO88591 },
"Unicode", "ISO-8859-1", },
{ { "Unicode To windows-1252 Converter", NS_UNICODETOCP1252_CID,
NS_UNICODETOCP1252_CONTRACTID, NS_NewUnicodeToCP1252 },
"Unicode", "windows-1252", },
{ { "Unicode To x-mac-roman Converter", NS_UNICODETOMACROMAN_CID,
NS_UNICODETOMACROMAN_CONTRACTID, NS_NewUnicodeToMacRoman },
"Unicode", "x-mac-roman", },
{ { "Unicode To UTF-8 Converter", NS_UNICODETOUTF8_CID,
NS_UNICODETOUTF8_CONTRACTID, NS_NewUnicodeToUTF8 },
"Unicode", "UTF-8", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsUConvModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
nsresult rv = NS_ERROR_UNEXPECTED;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
@@ -137,53 +216,11 @@ nsUConvModule::GetClassObject(nsIComponentManager *aCompMgr,
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kCharsetConverterManagerCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewCharsetConverterManager);
}
else if (aClass.Equals(kUnicodeDecodeHelperCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeDecodeHelper);
}
else if (aClass.Equals(kUnicodeEncodeHelperCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeEncodeHelper);
}
else if (aClass.Equals(kPlatformCharsetCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewPlatformCharset);
}
else if (aClass.Equals(kCharsetAliasCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewCharsetAlias);
}
else if (aClass.Equals(kCharsetMenuCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewCharsetMenu);
}
else if (aClass.Equals(kTextToSubURICID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewTextToSubURI);
}
else if (aClass.Equals(kISO88591ToUnicodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewISO88591ToUnicode);
}
else if (aClass.Equals(kCP1252ToUnicodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewCP1252ToUnicode);
}
else if (aClass.Equals(kMacRomanToUnicodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewMacRomanToUnicode);
}
else if (aClass.Equals(kUTF8ToUnicodeCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUTF8ToUnicode);
}
else if (aClass.Equals(kUnicodeToISO88591CID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeToISO88591);
}
else if (aClass.Equals(kUnicodeToCP1252CID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeToCP1252);
}
else if (aClass.Equals(kUnicodeToMacRomanCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeToMacRoman);
}
else if (aClass.Equals(kUnicodeToUTF8CID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), NS_NewUnicodeToUTF8);
}
else {
return NS_ERROR_FACTORY_NOT_REGISTERED;
for (unsigned int i = 0; i < NUM_COMPONENTS; i++) {
if (aClass.Equals(gComponents[i].info.mCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), &gComponents[i].info);
break;
}
}
if (fact) {
@@ -193,51 +230,6 @@ nsUConvModule::GetClassObject(nsIComponentManager *aCompMgr,
return rv;
}
//----------------------------------------
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
const char* mCharsetSrc;
const char* mCharsetDest;
};
// The list of components we register
static Components gComponents[] = {
{ "Charset Conversion Manager", &kCharsetConverterManagerCID,
NS_CHARSETCONVERTERMANAGER_CONTRACTID, NULL, NULL, },
{ "Unicode Decode Helper", &kUnicodeDecodeHelperCID,
NS_UNICODEDECODEHELPER_CONTRACTID, NULL, NULL, },
{ "Unicode Encode Helper", &kUnicodeEncodeHelperCID,
NS_UNICODEENCODEHELPER_CONTRACTID, NULL, NULL, },
{ "Platform Charset Information", &kPlatformCharsetCID,
NS_PLATFORMCHARSET_CONTRACTID, NULL, NULL, },
{ "Charset Alias Information", &kCharsetAliasCID,
NS_CHARSETALIAS_CONTRACTID, NULL, NULL, },
{ NS_CHARSETMENU_PID, &kCharsetMenuCID,
NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CHARSETMENU_PID, NULL, NULL, },
{ "Text To Sub URI Helper", &kTextToSubURICID,
NS_ITEXTTOSUBURI_CONTRACTID, NULL, NULL, },
{ "ISO-8859-1 To Unicode Converter", &kISO88591ToUnicodeCID,
NS_ISO88591TOUNICODE_CONTRACTID, "ISO-8859-1", "Unicode", },
{ "windows-1252 To Unicode Converter", &kCP1252ToUnicodeCID,
NS_CP1252TOUNICODE_CONTRACTID, "windows-1252", "Unicode", },
{ "x-mac-roman To Unicode Converter", &kMacRomanToUnicodeCID,
NS_MACROMANTOUNICODE_CONTRACTID, "x-mac-roman", "Unicode", },
{ "UTF-8 To Unicode Converter", &kUTF8ToUnicodeCID,
NS_UTF8TOUNICODE_CONTRACTID, "UTF-8", "Unicode", },
{ "Unicode To ISO-8859-1 Converter", &kUnicodeToISO88591CID,
NS_UNICODETOISO88591_CONTRACTID, "Unicode", "ISO-8859-1", },
{ "Unicode To windows-1252 Converter", &kUnicodeToCP1252CID,
NS_UNICODETOCP1252_CONTRACTID, "Unicode", "windows-1252", },
{ "Unicode To x-mac-roman Converter", &kUnicodeToMacRomanCID,
NS_UNICODETOMACROMAN_CONTRACTID, "Unicode", "x-mac-roman", },
{ "Unicode To UTF-8 Converter", &kUnicodeToUTF8CID,
NS_UNICODETOUTF8_CONTRACTID, "Unicode", "UTF-8", },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP
nsUConvModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
@@ -268,20 +260,20 @@ nsUConvModule::RegisterSelf(nsIComponentManager *aCompMgr,
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mContractID, aPath, PR_TRUE,
rv = aCompMgr->RegisterComponentSpec(cp->info.mCID, cp->info.mDescription,
cp->info.mContractID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsUConvModule: unable to register %s component => %x\n",
cp->mDescription, rv);
cp->info.mDescription, rv);
#endif
break;
}
// register Unicode converter component info here.
if (NULL != cp->mCharsetSrc) {
cid_string = cp->mCID->ToString();
cid_string = cp->info.mCID.ToString();
sprintf(buff, "%s/%s", "software/netscape/intl/uconv", cid_string);
nsCRT::free(cid_string);
@@ -306,7 +298,7 @@ nsUConvModule::RegisterSelf(nsIComponentManager *aCompMgr,
else {
#ifdef DEBUG
printf("nsUConvModule: unable to register %s component => %x\n",
cp->mDescription, rv);
cp->info.mDescription, rv);
#endif
}
@@ -327,11 +319,11 @@ nsUConvModule::UnregisterSelf(nsIComponentManager *aCompMgr,
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->info.mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsUConvModule: unable to unregister %s component => %x\n",
cp->mDescription, rv);
cp->info.mDescription, rv);
#endif
}
cp++;

View File

@@ -32,7 +32,7 @@ NS_DECLARE_ID(kUTF8ToUnicodeCID,
#define NS_UTF8TOUNICODE_CONTRACTID "@mozilla.org/intl/unicode/decoder;1?charset=UTF-8"
//#define NS_ERROR_UCONV_NOUTF8TOUNICODE \
//#define NS_ERROR_UCONV_NOUTF8TOUNICODE
// NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)
//----------------------------------------------------------------------

View File

@@ -32,7 +32,7 @@ NS_DECLARE_ID(kUnicodeToCP1252CID,
#define NS_UNICODETOCP1252_CONTRACTID "@mozilla.org/intl/unicode/encoder;1?charset=windows-1252"
//#define NS_ERROR_UCONV_NOUNICODETOCP1252 \
//#define NS_ERROR_UCONV_NOUNICODETOCP1252
// NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)
//----------------------------------------------------------------------

View File

@@ -31,7 +31,7 @@ NS_DECLARE_ID(kUnicodeToISO88591CID,
#define NS_UNICODETOISO88591_CONTRACTID "@mozilla.org/intl/unicode/encoder;1?charset=ISO-8859-1"
//#define NS_ERROR_UCONV_NOUNICODETOISO88591 \
//#define NS_ERROR_UCONV_NOUNICODETOISO88591
// NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)

View File

@@ -32,7 +32,7 @@ NS_DECLARE_ID(kUnicodeToUTF8CID,
#define NS_UNICODETOUTF8_CONTRACTID "@mozilla.org/intl/unicode/encoder;1?charset=UTF-8"
//#define NS_ERROR_UCONV_NOUNICODETOUTF8 \
//#define NS_ERROR_UCONV_NOUNICODETOUTF8
// NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_UCONV, 0x31)
//----------------------------------------------------------------------

View File

@@ -1125,7 +1125,8 @@ JSCLAutoContext::~JSCLAutoContext()
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
static NS_METHOD
RegisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType)
const char *registryLocation, const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
@@ -1139,7 +1140,8 @@ RegisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
static NS_METHOD
UnregisterJSLoader(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation)
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =

View File

@@ -51,7 +51,7 @@ private:
};
NS_IMPL_ISUPPORTS2(xpcTestCallJS, nsIXPCTestCallJS, nsIXPCScriptable);
NS_IMPL_ISUPPORTS2_CI(xpcTestCallJS, nsIXPCTestCallJS, nsIXPCScriptable);
XPC_IMPLEMENT_FORWARD_IXPCSCRIPTABLE(xpcTestCallJS);

View File

@@ -41,6 +41,9 @@
#include "nsIGenericFactory.h"
#include "nsCRT.h"
NS_DECL_CLASSINFO(xpcTestCallJS)
NS_DECL_CLASSINFO(xpcTestChild2)
// XXX contractids need to be standardized!
static nsModuleComponentInfo components[] = {
{nsnull, NS_ECHO_CID, "@mozilla.org/js/xpc/test/Echo;1", xpctest::ConstructEcho },
@@ -54,10 +57,10 @@ static nsModuleComponentInfo components[] = {
{nsnull, NS_XPCTESTOUT_CID, "@mozilla.org/js/xpc/test/Out;1", xpctest::ConstructXPCTestOut },
{nsnull, NS_XPCTESTINOUT_CID, "@mozilla.org/js/xpc/test/InOut;1", xpctest::ConstructXPCTestInOut },
{nsnull, NS_XPCTESTCONST_CID, "@mozilla.org/js/xpc/test/Const;1", xpctest::ConstructXPCTestConst },
{nsnull, NS_XPCTESTCALLJS_CID, "@mozilla.org/js/xpc/test/CallJS;1", xpctest::ConstructXPCTestCallJS },
{nsnull, NS_XPCTESTCALLJS_CID, "@mozilla.org/js/xpc/test/CallJS;1", xpctest::ConstructXPCTestCallJS, NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(xpcTestCallJS), NULL, &NS_CLASSINFO_NAME(xpcTestCallJS) },
{nsnull, NS_XPCTESTPARENTONE_CID, "@mozilla.org/js/xpc/test/ParentOne;1", xpctest::ConstructXPCTestParentOne },
{nsnull, NS_XPCTESTPARENTTWO_CID, "@mozilla.org/js/xpc/test/ParentTwo;1", xpctest::ConstructXPCTestParentTwo },
{nsnull, NS_XPCTESTCHILD2_CID, "@mozilla.org/js/xpc/test/Child2;1", xpctest::ConstructXPCTestChild2 },
{nsnull, NS_XPCTESTCHILD2_CID, "@mozilla.org/js/xpc/test/Child2;1", xpctest::ConstructXPCTestChild2, NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(xpcTestChild2), NULL, &NS_CLASSINFO_NAME(xpcTestChild2) },
{nsnull, NS_XPCTESTCHILD3_CID, "@mozilla.org/js/xpc/test/Child3;1", xpctest::ConstructXPCTestChild3 },
{nsnull, NS_XPCTESTCHILD4_CID, "@mozilla.org/js/xpc/test/Child4;1", xpctest::ConstructXPCTestChild4 },
{nsnull, NS_XPCTESTCHILD5_CID, "@mozilla.org/js/xpc/test/Child5;1", xpctest::ConstructXPCTestChild5 },

View File

@@ -181,7 +181,7 @@ private:
const char *name;
};
NS_IMPL_ISUPPORTS3(xpcTestChild2,nsIXPCTestChild2,nsIXPCTestParentOne,nsIXPCTestParentTwo);
NS_IMPL_ISUPPORTS3_CI(xpcTestChild2,nsIXPCTestChild2,nsIXPCTestParentOne,nsIXPCTestParentTwo);
xpcTestChild2 :: xpcTestChild2()
{

View File

@@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
@@ -101,6 +101,13 @@ void nsMsgDBModule::Shutdown()
mMsgRetentionSettingsFactory = null_nsCOMPtr();
}
static nsModuleComponentInfo
MailDbInfo = { NULL, NS_MAILDB_CID, NULL, nsMailDatabaseConstructor },
NewsDbInfo = { NULL, NS_NEWSDB_CID, NULL, nsNewsDatabaseConstructor },
ImapDbInfo = { NULL, NS_IMAPDB_CID, NULL, nsImapMailDatabaseConstructor },
MsgRetentionInfo = { NULL, NS_MSG_RETENTIONSETTINGS_CID, NULL,
nsMsgRetentionSettingsConstructor };
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP nsMsgDBModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
@@ -130,25 +137,29 @@ NS_IMETHODIMP nsMsgDBModule::GetClassObject(nsIComponentManager *aCompMgr,
if (aClass.Equals(kCMailDB))
{
if (!mMailDBFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMailDBFactory), &nsMailDatabaseConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(mMailDBFactory),
&MailDbInfo);
fact = mMailDBFactory;
}
else if (aClass.Equals(kCNewsDB))
{
if (!mNewsDBFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mNewsDBFactory), &nsNewsDatabaseConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(mNewsDBFactory),
&NewsDbInfo);
fact = mNewsDBFactory;
}
else if (aClass.Equals(kCImapDB))
{
if (!mImapDBFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapDBFactory), &nsImapMailDatabaseConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(mImapDBFactory),
&ImapDbInfo);
fact = mImapDBFactory;
}
else if (aClass.Equals(kCMsgRetentionSettings))
{
if (!mMsgRetentionSettingsFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMsgRetentionSettingsFactory), &nsMsgRetentionSettingsConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(mMsgRetentionSettingsFactory),
&MsgRetentionInfo);
fact = mMsgRetentionSettingsFactory;
}
if (fact)

View File

@@ -34,15 +34,6 @@
#include "nsImapProtocol.h"
#include "nsMsgImapCID.h"
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kCImapUrl, NS_IMAPURL_CID);
static NS_DEFINE_CID(kCImapProtocol, NS_IMAPPROTOCOL_CID);
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);
static NS_DEFINE_CID(kCImapIncomingServer, NS_IMAPINCOMINGSERVER_CID);
static NS_DEFINE_CID(kCImapService, NS_IMAPSERVICE_CID);
static NS_DEFINE_CID(kCImapResource, NS_IMAPRESOURCE_CID);
static NS_DEFINE_CID(kCImapMockChannel, NS_IMAPMOCKCHANNEL_CID);
// private factory declarations for each component we know how to produce
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsImapUrl, Initialize)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapProtocol)
@@ -52,249 +43,40 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMailFolder)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMockChannel)
// Module implementation for the sample library
class nsMsgImapModule : public nsIModule
{
public:
nsMsgImapModule();
virtual ~nsMsgImapModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mImapUrlFactory;
nsCOMPtr<nsIGenericFactory> mImapProtocolFactory;
nsCOMPtr<nsIGenericFactory> mImapHostSessionFactory;
nsCOMPtr<nsIGenericFactory> mImapIncomingServerFactory;
nsCOMPtr<nsIGenericFactory> mImapServiceFactory;
nsCOMPtr<nsIGenericFactory> mImapMailFolderFactory;
nsCOMPtr<nsIGenericFactory> mImapMockChannelFactory;
};
nsMsgImapModule::nsMsgImapModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsMsgImapModule::~nsMsgImapModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS1(nsMsgImapModule, nsIModule)
// Perform our one-time intialization for this module
nsresult nsMsgImapModule::Initialize()
{
if (mInitialized)
return NS_OK;
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void nsMsgImapModule::Shutdown()
{
// Release the factory object
mImapUrlFactory = null_nsCOMPtr();
mImapProtocolFactory = null_nsCOMPtr();
mImapHostSessionFactory = null_nsCOMPtr();
mImapIncomingServerFactory = null_nsCOMPtr();
mImapServiceFactory = null_nsCOMPtr();
mImapMailFolderFactory = null_nsCOMPtr();
mImapMockChannelFactory = null_nsCOMPtr();
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP nsMsgImapModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv = NS_OK;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj)
return NS_ERROR_INVALID_POINTER;
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized)
{
rv = Initialize();
if (NS_FAILED(rv)) // Initialization failed! yikes!
return rv;
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kCImapUrl))
{
if (!mImapUrlFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapUrlFactory), &nsImapUrlConstructor);
fact = mImapUrlFactory;
}
else if (aClass.Equals(kCImapProtocol))
{
if (!mImapProtocolFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapProtocolFactory), &nsImapProtocolConstructor);
fact = mImapProtocolFactory;
}
else if (aClass.Equals(kCImapHostSessionList))
{
if (!mImapHostSessionFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapHostSessionFactory), &nsIMAPHostSessionListConstructor);
fact = mImapHostSessionFactory;
}
else if (aClass.Equals(kCImapIncomingServer))
{
if (!mImapIncomingServerFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapIncomingServerFactory), &nsImapIncomingServerConstructor);
fact = mImapIncomingServerFactory;
}
else if (aClass.Equals(kCImapService))
{
if (!mImapServiceFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapServiceFactory), &nsImapServiceConstructor);
fact = mImapServiceFactory;
}
else if (aClass.Equals(kCImapResource))
{
if (!mImapMailFolderFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapMailFolderFactory), &nsImapMailFolderConstructor);
fact = mImapMailFolderFactory;
}
else if (aClass.Equals(kCImapMockChannel))
{
if (!mImapMockChannelFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mImapMockChannelFactory), &nsImapMockChannelConstructor);
fact = mImapMockChannelFactory;
}
if (fact)
rv = fact->QueryInterface(aIID, r_classObj);
return rv;
}
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
};
// The list of components we register
static Components gComponents[] = {
{ "Imap Url", &kCImapUrl,
nsnull },
{ "Imap Protocol Channel", &kCImapProtocol,
nsnull },
{ "Imap Mock Channel", &kCImapMockChannel,
nsnull },
{ "Imap Host Session List", &kCImapHostSessionList,
nsnull },
{ "Imap Incoming Server", &kCImapIncomingServer,
NS_IMAPINCOMINGSERVER_CONTRACTID },
{ "Mail/News Imap Resource Factory", &kCImapResource,
NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "imap" },
{ "Imap Service", &kCImapService,
"@mozilla.org/messenger/messageservice;1?type=imap_message" },
{ "Imap Service", &kCImapService,
"@mozilla.org/messenger/messageservice;1?type=imap"},
{ "Imap Protocol Handler", &kCImapService,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "imap"},
{ "Imap Protocol Handler", &kCImapService,
NS_IMAPPROTOCOLINFO_CONTRACTID},
static nsModuleComponentInfo gComponents[] = {
{ "IMAP URL", NS_IMAPURL_CID,
nsnull, nsImapUrlConstructor },
{ "IMAP Protocol Channel", NS_IMAPPROTOCOL_CID,
nsnull, nsImapProtocolConstructor },
{ "IMAP Mock Channel", NS_IMAPMOCKCHANNEL_CID,
nsnull, nsImapMockChannelConstructor },
{ "IMAP Host Session List", NS_IIMAPHOSTSESSIONLIST_CID,
nsnull, nsIMAPHostSessionListConstructor },
{ "IMAP Incoming Server", NS_IMAPINCOMINGSERVER_CID,
NS_IMAPINCOMINGSERVER_CONTRACTID, nsImapIncomingServerConstructor },
{ "Mail/News IMAP Resource Factory", NS_IMAPRESOURCE_CID,
NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX "imap",
nsImapMailFolderConstructor },
{ "IMAP Service", NS_IMAPSERVICE_CID,
"@mozilla.org/messenger/messageservice;1?type=imap_message",
nsImapServiceConstructor },
{ "IMAP Service", NS_IMAPSERVICE_CID,
"@mozilla.org/messenger/messageservice;1?type=imap",
nsImapServiceConstructor },
{ "IMAP Protocol Handler", NS_IMAPSERVICE_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "imap", nsImapServiceConstructor},
{ "IMAP Protocol Handler", NS_IMAPSERVICE_CID,
NS_IMAPPROTOCOLINFO_CONTRACTID, nsImapServiceConstructor }
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP nsMsgImapModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mContractID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv))
break;
cp++;
}
return rv;
}
NS_IMETHODIMP nsMsgImapModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
cp++;
}
return NS_OK;
}
NS_IMETHODIMP nsMsgImapModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload)
return NS_ERROR_INVALID_POINTER;
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsMsgImapModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* aPath,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsMsgImapModule: Module already created.");
// Create an initialize the imap module instance
nsMsgImapModule *module = new nsMsgImapModule();
if (!module)
return NS_ERROR_OUT_OF_MEMORY;
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = module->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv))
{
delete module;
module = nsnull;
}
gModule = module; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("IMAP factory", gComponents);

View File

@@ -38,9 +38,9 @@ static NS_DEFINE_CID(kEudoraImportCID, NS_EUDORAIMPORT_CID);
///////////////////////////////////////////////////////////////////////
NS_METHOD EudoraRegister(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
nsIFile *aPath, const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -67,7 +67,7 @@ static nsModuleComponentInfo components[] = {
NS_EUDORAIMPORT_CID,
"@mozilla.org/import/import-eudora;1",
nsEudoraImportConstructor,
&EudoraRegister,
EudoraRegister,
nsnull
}
};

View File

@@ -43,7 +43,8 @@ static NS_DEFINE_CID(kOEImportCID, NS_OEIMPORT_CID);
NS_METHOD OERegister(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -70,7 +71,7 @@ static nsModuleComponentInfo components[] = {
NS_OEIMPORT_CID,
"@mozilla.org/import/import-oe;1",
nsOEImportConstructor,
&OERegister,
OERegister,
nsnull
}
};

View File

@@ -43,9 +43,9 @@ static NS_DEFINE_CID(kOutlookImportCID, NS_OUTLOOKIMPORT_CID);
NS_METHOD OutlookRegister(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
nsIFile *aPath, const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -71,7 +71,7 @@ static nsModuleComponentInfo components[] = {
NS_OUTLOOKIMPORT_CID,
"@mozilla.org/import/import-outlook;1",
nsOutlookImportConstructor,
&OutlookRegister,
OutlookRegister,
nsnull
}
};

View File

@@ -38,9 +38,9 @@ static NS_DEFINE_CID(kTextImportCID, NS_TEXTIMPORT_CID);
NS_METHOD TextRegister(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
nsIFile *aPath, const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -67,7 +67,7 @@ static nsModuleComponentInfo components[] = {
NS_TEXTIMPORT_CID,
"@mozilla.org/import/import-text;1",
nsTextImportConstructor,
&TextRegister,
TextRegister,
nsnull
}
};

View File

@@ -44,23 +44,6 @@
#include "nsLocalStringBundle.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kMailboxUrlCID, NS_MAILBOXURL_CID);
static NS_DEFINE_CID(kMailboxParserCID, NS_MAILBOXPARSER_CID);
static NS_DEFINE_CID(kMailboxServiceCID, NS_MAILBOXSERVICE_CID);
static NS_DEFINE_CID(kLocalMailFolderResourceCID, NS_LOCALMAILFOLDERRESOURCE_CID);
static NS_DEFINE_CID(kPop3ServiceCID, NS_POP3SERVICE_CID);
#ifdef HAVE_MOVEMAIL
static NS_DEFINE_CID(kMovemailServiceCID, NS_MOVEMAILSERVICE_CID);
static NS_DEFINE_CID(kMovemailIncomingServerCID, NS_MOVEMAILINCOMINGSERVER_CID);
#endif /* HAVE_MOVEMAIL */
static NS_DEFINE_CID(kNoneServiceCID, NS_NONESERVICE_CID);
static NS_DEFINE_CID(kPop3UrlCID, NS_POP3URL_CID);
static NS_DEFINE_CID(kPop3IncomingServerCID, NS_POP3INCOMINGSERVER_CID);
static NS_DEFINE_CID(kNoIncomingServerCID, NS_NOINCOMINGSERVER_CID);
static NS_DEFINE_CID(kParseMailMsgStateCID, NS_PARSEMAILMSGSTATE_CID);
static NS_DEFINE_CID(kLocalStringServiceCID, NS_MSG_LOCALSTRINGSERVICE_CID);
// private factory declarations for each component we know how to produce
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMailboxUrl)
@@ -81,334 +64,77 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsMovemailIncomingServer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNoIncomingServer)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLocalStringService)
// Module implementation for the sample library
class nsMsgLocalModule : public nsIModule
{
public:
nsMsgLocalModule();
virtual ~nsMsgLocalModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mMailboxUrlFactory;
nsCOMPtr<nsIGenericFactory> mPop3UrlFactory;
nsCOMPtr<nsIGenericFactory> mMailboxParserFactory;
nsCOMPtr<nsIGenericFactory> mMailboxServiceFactory;
nsCOMPtr<nsIGenericFactory> mPop3ServiceFactory;
#ifdef HAVE_MOVEMAIL
nsCOMPtr<nsIGenericFactory> mMovemailServiceFactory;
#endif /* HAVE_MOVEMAIL */
nsCOMPtr<nsIGenericFactory> mNoneServiceFactory;
nsCOMPtr<nsIGenericFactory> mLocalMailFolderFactory;
nsCOMPtr<nsIGenericFactory> mParseMailMsgStateFactory;
nsCOMPtr<nsIGenericFactory> mPop3IncomingServerFactory;
#ifdef HAVE_MOVEMAIL
nsCOMPtr<nsIGenericFactory> mMovemailIncomingServerFactory;
#endif /* HAVE_MOVEMAIL */
nsCOMPtr<nsIGenericFactory> mNoIncomingServerFactory;
nsCOMPtr<nsIGenericFactory> mLocalStringBundleFactory;
};
nsMsgLocalModule::nsMsgLocalModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsMsgLocalModule::~nsMsgLocalModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS1(nsMsgLocalModule, nsIModule)
// Perform our one-time intialization for this module
nsresult nsMsgLocalModule::Initialize()
{
if (mInitialized)
return NS_OK;
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void nsMsgLocalModule::Shutdown()
{
// Release the factory object
mMailboxUrlFactory = null_nsCOMPtr();
mPop3UrlFactory = null_nsCOMPtr();
mMailboxParserFactory = null_nsCOMPtr();
mMailboxServiceFactory = null_nsCOMPtr();
mPop3ServiceFactory = null_nsCOMPtr();
#ifdef HAVE_MOVEMAIL
mMovemailServiceFactory = null_nsCOMPtr();
#endif /* HAVE_MOVEMAIL */
mNoneServiceFactory = null_nsCOMPtr();
mLocalMailFolderFactory = null_nsCOMPtr();
mParseMailMsgStateFactory = null_nsCOMPtr();
mPop3IncomingServerFactory = null_nsCOMPtr();
#ifdef HAVE_MOVEMAIL
mMovemailIncomingServerFactory = null_nsCOMPtr();
#endif /* HAVE_MOVEMAIL */
mNoIncomingServerFactory = null_nsCOMPtr();
mLocalStringBundleFactory = null_nsCOMPtr();
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP nsMsgLocalModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv = NS_OK;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj)
return NS_ERROR_INVALID_POINTER;
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized)
{
rv = Initialize();
if (NS_FAILED(rv)) // Initialization failed! yikes!
return rv;
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kMailboxUrlCID))
{
if (!mMailboxUrlFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMailboxUrlFactory), &nsMailboxUrlConstructor);
fact = mMailboxUrlFactory;
}
else if (aClass.Equals(kPop3UrlCID))
{
if (!mPop3UrlFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mPop3UrlFactory), &nsPop3URLConstructor);
fact = mPop3UrlFactory;
}
else if (aClass.Equals(kMailboxParserCID))
{
if (!mMailboxParserFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMailboxParserFactory), &nsMsgMailboxParserConstructor);
fact = mMailboxParserFactory;
}
else if (aClass.Equals(kMailboxServiceCID))
{
if (!mMailboxServiceFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMailboxServiceFactory), &nsMailboxServiceConstructor);
fact = mMailboxServiceFactory;
}
else if (aClass.Equals(kPop3ServiceCID))
{
if (!mPop3ServiceFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mPop3ServiceFactory), &nsPop3ServiceConstructor);
fact = mPop3ServiceFactory;
}
#ifdef HAVE_MOVEMAIL
else if (aClass.Equals(kMovemailServiceCID))
{
if (!mMovemailServiceFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMovemailServiceFactory), &nsMovemailServiceConstructor);
fact = mMovemailServiceFactory;
}
#endif /* HAVE_MOVEMAIL */
else if (aClass.Equals(kNoneServiceCID))
{
if (!mNoneServiceFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mNoneServiceFactory), &nsNoneServiceConstructor);
fact = mNoneServiceFactory;
}
else if (aClass.Equals(kLocalMailFolderResourceCID))
{
if (!mLocalMailFolderFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mLocalMailFolderFactory), &nsMsgLocalMailFolderConstructor);
fact = mLocalMailFolderFactory;
}
else if (aClass.Equals(kParseMailMsgStateCID))
{
if (!mParseMailMsgStateFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mParseMailMsgStateFactory), &nsParseMailMessageStateConstructor);
fact = mParseMailMsgStateFactory;
}
else if (aClass.Equals(kPop3IncomingServerCID))
{
if (!mPop3IncomingServerFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mPop3IncomingServerFactory), &nsPop3IncomingServerConstructor);
fact = mPop3IncomingServerFactory;
}
#ifdef HAVE_MOVEMAIL
else if (aClass.Equals(kMovemailIncomingServerCID))
{
if (!mMovemailIncomingServerFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMovemailIncomingServerFactory), &nsMovemailIncomingServerConstructor);
fact = mMovemailIncomingServerFactory;
}
#endif /* HAVE_MOVEMAIL */
else if (aClass.Equals(kNoIncomingServerCID))
{
if (!mNoIncomingServerFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mNoIncomingServerFactory), &nsNoIncomingServerConstructor);
fact = mNoIncomingServerFactory;
}
else if (aClass.Equals(kLocalStringServiceCID))
{
if (!mLocalStringBundleFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mLocalStringBundleFactory), &nsLocalStringServiceConstructor);
fact = mLocalStringBundleFactory;
}
if (fact)
rv = fact->QueryInterface(aIID, r_classObj);
return rv;
}
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
};
// The list of components we register
static Components gComponents[] = {
{ "Mailbox URL", &kMailboxUrlCID,
NS_MAILBOXURL_CONTRACTID },
{ "Mailbox Service", &kMailboxServiceCID,
NS_MAILBOXSERVICE_CONTRACTID1 },
{ "Mailbox Service", &kMailboxServiceCID,
NS_MAILBOXSERVICE_CONTRACTID2 },
{ "Mailbox Service", &kMailboxServiceCID,
NS_MAILBOXSERVICE_CONTRACTID3 },
{ "Mailbox Protocol Handler", &kMailboxServiceCID,
NS_MAILBOXSERVICE_CONTRACTID4 },
{ "Mailbox Parser", &kMailboxParserCID,
NS_MAILBOXPARSER_CONTRACTID },
{ "Pop3 URL", &kPop3UrlCID,
NS_POP3URL_CONTRACTID },
{ "Pop3 Service", &kPop3ServiceCID,
NS_POP3SERVICE_CONTRACTID1 },
{ "POP Protocol Handler", &kPop3ServiceCID,
NS_POP3SERVICE_CONTRACTID2 },
{ "None Service", &kNoneServiceCID,
NS_NONESERVICE_CONTRACTID },
static nsModuleComponentInfo gComponents[] = {
{ "Mailbox URL", NS_MAILBOXURL_CID,
NS_MAILBOXURL_CONTRACTID, nsMailboxUrlConstructor },
{ "Mailbox Service", NS_MAILBOXSERVICE_CID,
NS_MAILBOXSERVICE_CONTRACTID1, nsMailboxServiceConstructor },
{ "Mailbox Service", NS_MAILBOXSERVICE_CID,
NS_MAILBOXSERVICE_CONTRACTID2, nsMailboxServiceConstructor },
{ "Mailbox Service", NS_MAILBOXSERVICE_CID,
NS_MAILBOXSERVICE_CONTRACTID3, nsMailboxServiceConstructor },
{ "Mailbox Protocol Handler", NS_MAILBOXSERVICE_CID,
NS_MAILBOXSERVICE_CONTRACTID4, nsMailboxServiceConstructor },
{ "Mailbox Parser", NS_MAILBOXPARSER_CID,
NS_MAILBOXPARSER_CONTRACTID, nsMsgMailboxParserConstructor },
{ "Pop3 URL", NS_POP3URL_CID,
NS_POP3URL_CONTRACTID, nsPop3URLConstructor },
{ "Pop3 Service", NS_POP3SERVICE_CID,
NS_POP3SERVICE_CONTRACTID1, nsPop3ServiceConstructor },
{ "POP Protocol Handler", NS_POP3SERVICE_CID,
NS_POP3SERVICE_CONTRACTID2, nsPop3ServiceConstructor },
{ "None Service", NS_NONESERVICE_CID,
NS_NONESERVICE_CONTRACTID, nsNoneServiceConstructor },
#ifdef HAVE_MOVEMAIL
{ "Movemail Service", &kMovemailServiceCID,
NS_MOVEMAILSERVICE_CONTRACTID },
{ "Movemail Service", NS_MOVEMAILSERVICE_CID,
NS_MOVEMAILSERVICE_CONTRACTID, nsMovemailServiceConstructor },
#endif /* HAVE_MOVEMAIL */
{ "pop3 Protocol Information", &kPop3ServiceCID,
NS_POP3PROTOCOLINFO_CONTRACTID },
{ "none Protocol Information", &kNoneServiceCID,
NS_NONEPROTOCOLINFO_CONTRACTID },
{ "pop3 Protocol Information", NS_POP3SERVICE_CID,
NS_POP3PROTOCOLINFO_CONTRACTID, nsPop3ServiceConstructor },
{ "none Protocol Information", NS_NONESERVICE_CID,
NS_NONEPROTOCOLINFO_CONTRACTID, nsNoneServiceConstructor },
#ifdef HAVE_MOVEMAIL
{ "movemail Protocol Information", &kMovemailServiceCID,
NS_MOVEMAILPROTOCOLINFO_CONTRACTID },
{ "movemail Protocol Information", NS_MOVEMAILSERVICE_CID,
NS_MOVEMAILPROTOCOLINFO_CONTRACTID, nsMovemailServiceConstructor },
#endif /* HAVE_MOVEMAIL */
{ "Local Mail Folder Resource Factory", &kLocalMailFolderResourceCID,
NS_LOCALMAILFOLDERRESOURCE_CONTRACTID },
{ "Pop3 Incoming Server", &kPop3IncomingServerCID,
NS_POP3INCOMINGSERVER_CONTRACTID },
#ifdef HAVE_MOVEMAIL
{ "Movemail Incoming Server", &kMovemailIncomingServerCID,
NS_MOVEMAILINCOMINGSERVER_CONTRACTID },
{ "Local Mail Folder Resource Factory", NS_LOCALMAILFOLDERRESOURCE_CID,
NS_LOCALMAILFOLDERRESOURCE_CONTRACTID, nsMsgLocalMailFolderConstructor },
{ "Pop3 Incoming Server", NS_POP3INCOMINGSERVER_CID,
NS_POP3INCOMINGSERVER_CONTRACTID, nsPop3IncomingServerConstructor },
#ifdef HAVE_MOVEMAIL
{ "Movemail Incoming Server", NS_MOVEMAILINCOMINGSERVER_CID,
NS_MOVEMAILINCOMINGSERVER_CONTRACTID, nsMovemailIncomingServerConstructor },
#endif /* HAVE_MOVEMAIL */
{ "No Incoming Server", &kNoIncomingServerCID,
NS_NOINCOMINGSERVER_CONTRACTID },
{ "Parse MailMessage State", &kParseMailMsgStateCID,
NS_PARSEMAILMSGSTATE_CONTRACTID },
{ "Mailbox String Bundle Service", &kLocalStringServiceCID,
NS_MSG_MAILBOXSTRINGSERVICE_CONTRACTID },
{ "Pop String Bundle Service", &kLocalStringServiceCID,
NS_MSG_POPSTRINGSERVICE_CONTRACTID },
{ "No Incoming Server", NS_NOINCOMINGSERVER_CID,
NS_NOINCOMINGSERVER_CONTRACTID, nsNoIncomingServerConstructor },
{ "Parse MailMessage State", NS_PARSEMAILMSGSTATE_CID,
NS_PARSEMAILMSGSTATE_CONTRACTID, nsParseMailMessageStateConstructor },
{ "Mailbox String Bundle Service", NS_MSG_LOCALSTRINGSERVICE_CID,
NS_MSG_MAILBOXSTRINGSERVICE_CONTRACTID, nsLocalStringServiceConstructor },
{ "Pop String Bundle Service", NS_MSG_LOCALSTRINGSERVICE_CID,
NS_MSG_POPSTRINGSERVICE_CONTRACTID, nsLocalStringServiceConstructor },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP nsMsgLocalModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
NS_IMPL_NSGETMODULE("local mail services", gComponents);
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mContractID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv))
break;
cp++;
}
return rv;
}
NS_IMETHODIMP nsMsgLocalModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
cp++;
}
return NS_OK;
}
NS_IMETHODIMP nsMsgLocalModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload)
return NS_ERROR_INVALID_POINTER;
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsMsgLocalModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* aPath,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsMsgLocalModule: Module already created.");
// Create an initialize the imap module instance
nsMsgLocalModule *module = new nsMsgLocalModule();
if (!module)
return NS_ERROR_OUT_OF_MEMORY;
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = module->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv))
{
delete module;
module = nsnull;
}
gModule = module; // WARNING: Weak Reference
return rv;
}

View File

@@ -33,12 +33,6 @@
#include "nsMsgHeaderParser.h"
#include "nsMimeHeaders.h"
static NS_DEFINE_CID(kCMimeMimeObjectClassAccessCID, NS_MIME_OBJECT_CLASS_ACCESS_CID);
static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID);
static NS_DEFINE_CID(kCStreamConverterCID, NS_MAILNEWS_MIME_STREAM_CONVERTER_CID);
static NS_DEFINE_CID(kCMsgHeaderParserCID, NS_MSGHEADERPARSER_CID);
static NS_DEFINE_CID(kCIMimeHeadersCID, NS_IMIMEHEADERS_CID);
// private factory declarations for each component we know how to produce
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMimeObjectClassAccess)
@@ -47,65 +41,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStreamConverter)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgHeaderParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMimeHeaders)
// Module implementation for the sample library
class nsMimeModule : public nsIModule
{
public:
nsMimeModule();
virtual ~nsMimeModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mObjectClassAccessFactory;
nsCOMPtr<nsIGenericFactory> mMimeConverterFactory;
nsCOMPtr<nsIGenericFactory> mStreamConverterFactory;
nsCOMPtr<nsIGenericFactory> mMsgHeaderParserFactory;
nsCOMPtr<nsIGenericFactory> mMimeHeadersFactory;
};
nsMimeModule::nsMimeModule()
: mInitialized(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
nsMimeModule::~nsMimeModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS1(nsMimeModule, nsIModule)
// Perform our one-time intialization for this module
nsresult nsMimeModule::Initialize()
{
if (mInitialized)
return NS_OK;
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void nsMimeModule::Shutdown()
{
// Release the factory object
mObjectClassAccessFactory = null_nsCOMPtr();
mMimeConverterFactory = null_nsCOMPtr();
mStreamConverterFactory = null_nsCOMPtr();
mMsgHeaderParserFactory = null_nsCOMPtr();
mMimeHeadersFactory = null_nsCOMPtr();
}
// Destructor for stream converter
extern "C" void comi18n_destructor();
static NS_IMETHODIMP streamConverterDestructor()
@@ -114,167 +49,31 @@ static NS_IMETHODIMP streamConverterDestructor()
return NS_OK;
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP nsMimeModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv = NS_OK;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj)
return NS_ERROR_INVALID_POINTER;
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized)
{
rv = Initialize();
if (NS_FAILED(rv)) // Initialization failed! yikes!
return rv;
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kCMimeMimeObjectClassAccessCID))
{
if (!mObjectClassAccessFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mObjectClassAccessFactory), &nsMimeObjectClassAccessConstructor);
fact = mObjectClassAccessFactory;
}
else if (aClass.Equals(kCMimeConverterCID))
{
if (!mMimeConverterFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMimeConverterFactory), &nsMimeConverterConstructor);
fact = mMimeConverterFactory;
}
else if (aClass.Equals(kCStreamConverterCID))
{
if (!mStreamConverterFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mStreamConverterFactory), &nsStreamConverterConstructor);
fact = mStreamConverterFactory;
fact->SetDestructor(streamConverterDestructor);
}
else if (aClass.Equals(kCMsgHeaderParserCID))
{
if (!mMsgHeaderParserFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMsgHeaderParserFactory), &nsMsgHeaderParserConstructor);
fact = mMsgHeaderParserFactory;
}
else if (aClass.Equals(kCIMimeHeadersCID))
{
if (!mMimeHeadersFactory)
rv = NS_NewGenericFactory(getter_AddRefs(mMimeHeadersFactory), &nsMimeHeadersConstructor);
fact = mMimeHeadersFactory;
}
if (fact)
rv = fact->QueryInterface(aIID, r_classObj);
return rv;
}
struct Components {
const char* mDescription;
const nsID* mCID;
const char* mContractID;
};
// The list of components we register
static Components gComponents[] = {
{ "MimeObjectClassAccess", &kCMimeMimeObjectClassAccessCID,
nsnull },
{ "Mime Converter", &kCMimeConverterCID,
nsnull},
{ "Msg Header Parser", &kCMsgHeaderParserCID,
NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID },
{ "Mailnews Mime Stream Converter", &kCStreamConverterCID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID },
{ "Mailnews Mime Stream Converter", &kCStreamConverterCID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID1 },
{ "Mailnews Mime Stream Converter", &kCStreamConverterCID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID2 },
{ "Mime Headers", &kCIMimeHeadersCID,
nsnull }
static nsModuleComponentInfo gComponents[] = {
{ "MimeObjectClassAccess", NS_MIME_OBJECT_CLASS_ACCESS_CID,
nsnull, nsMimeObjectClassAccessConstructor },
{ "Mime Converter", NS_MIME_CONVERTER_CID,
nsnull, nsMimeConverterConstructor },
{ "Msg Header Parser", NS_MSGHEADERPARSER_CID,
NS_MAILNEWS_MIME_HEADER_PARSER_CONTRACTID, nsMsgHeaderParserConstructor },
{ "Mailnews Mime Stream Converter", NS_MAILNEWS_MIME_STREAM_CONVERTER_CID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID,
nsStreamConverterConstructor, 0, 0, streamConverterDestructor },
{ "Mailnews Mime Stream Converter", NS_MAILNEWS_MIME_STREAM_CONVERTER_CID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID1,
nsStreamConverterConstructor, 0, 0, streamConverterDestructor },
{ "Mailnews Mime Stream Converter", NS_MAILNEWS_MIME_STREAM_CONVERTER_CID,
NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID2,
nsStreamConverterConstructor, 0, 0, streamConverterDestructor },
{ "Mime Headers", NS_IMIMEHEADERS_CID,
nsnull, nsMimeHeadersConstructor }
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
NS_IMETHODIMP nsMimeModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
cp->mContractID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv))
break;
cp++;
}
return rv;
}
NS_IMETHODIMP nsMimeModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
while (cp < end)
{
aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
cp++;
}
return NS_OK;
}
NS_IMETHODIMP nsMimeModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
if (!okToUnload)
return NS_ERROR_INVALID_POINTER;
*okToUnload = PR_FALSE;
return NS_ERROR_FAILURE;
}
//----------------------------------------------------------------------
static nsMimeModule *gModule = NULL;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
nsIFile* aPath,
nsIModule** return_cobj)
{
nsresult rv = NS_OK;
NS_ASSERTION(return_cobj, "Null argument");
NS_ASSERTION(gModule == NULL, "nsMimeModule: Module already created.");
// Create an initialize the imap module instance
nsMimeModule *module = new nsMimeModule();
if (!module)
return NS_ERROR_OUT_OF_MEMORY;
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = module->QueryInterface(NS_GET_IID(nsIModule), (void**)return_cobj);
if (NS_FAILED(rv))
{
delete module;
module = nsnull;
}
gModule = module; // WARNING: Weak Reference
return rv;
}
NS_IMPL_NSGETMODULE("mime services", gComponents)

View File

@@ -185,12 +185,14 @@ public:
RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType);
const char* aComponentType,
const nsModuleComponentInfo *info);
static NS_METHOD
UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation);
const char* aRegistryLocation,
const nsModuleComponentInfo *info);
NS_DECL_ISUPPORTS
@@ -432,7 +434,8 @@ NS_METHOD
SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType)
const char* aComponentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -458,7 +461,8 @@ SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
NS_METHOD
SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation)
const char* aRegistryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;

View File

@@ -280,7 +280,8 @@ NS_METHOD
EventsPluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType)
const char* aComponentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -306,7 +307,8 @@ EventsPluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
NS_METHOD
EventsPluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation)
const char* aRegistryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;

View File

@@ -185,12 +185,14 @@ public:
RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType);
const char* aComponentType,
const nsModuleComponentInfo *info);
static NS_METHOD
UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation);
const char* aRegistryLocation,
const nsModuleComponentInfo *info);
NS_DECL_ISUPPORTS
@@ -432,7 +434,8 @@ NS_METHOD
SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType)
const char* aComponentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -458,7 +461,8 @@ SimplePluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
NS_METHOD
SimplePluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation)
const char* aRegistryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;

View File

@@ -280,7 +280,8 @@ NS_METHOD
EventsPluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation,
const char* aComponentType)
const char* aComponentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
@@ -306,7 +307,8 @@ EventsPluginInstance::RegisterSelf(nsIComponentManager* aCompMgr,
NS_METHOD
EventsPluginInstance::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* aRegistryLocation)
const char* aRegistryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;

View File

@@ -122,7 +122,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsBasicAuth);
/* XXX this should all be data-driven, via NS_IMPL_GETMODULE_WITH_CATEGORIES */
static NS_METHOD
RegisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType)
const char *registryLocation, const char *componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
@@ -135,7 +136,8 @@ RegisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
static NS_METHOD
UnregisterBasicAuth(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation)
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
@@ -230,7 +232,9 @@ static char *g_StreamConverterArray[] = {
// a graph of converters for potential chaining.
static NS_METHOD
RegisterStreamConverters(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation, const char *componentType) {
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info) {
nsresult rv;
nsCOMPtr<nsICategoryManager> catmgr =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
@@ -251,7 +255,8 @@ RegisterStreamConverters(nsIComponentManager *aCompMgr, nsIFile *aPath,
// same as RegisterStreamConverters except the reverse.
static NS_METHOD
UnregisterStreamConverters(nsIComponentManager *aCompMgr, nsIFile *aPath,
const char *registryLocation) {
const char *registryLocation,
const nsModuleComponentInfo *info) {
nsresult rv;
nsCOMPtr<nsICategoryManager> catmgr =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);

View File

@@ -159,25 +159,6 @@ static NS_DEFINE_CID(kViewSourceDTDCID, NS_VIEWSOURCE_DTD_CID);
static NS_DEFINE_CID(kHTMLContentSinkStreamCID, NS_HTMLCONTENTSINKSTREAM_CID);
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
struct Components {
const char* mDescription;
const nsID* mCID;
};
static Components gComponents[] = {
{ "Parser", &kParserCID },
{ "Logging sink", &kLoggingSinkCID },
{ "Well formed DTD", &kWellFormedDTDCID },
{ "Navigator HTML DTD", &kNavDTDCID },
{ "OTHER DTD", &kCOtherDTDCID },
{ "Transitional DTD", &kCTransitionalDTDCID },
{ "ViewSource DTD", &kViewSourceDTDCID },
{ "HTML Content Sink Stream", &kHTMLContentSinkStreamCID },
{ "ParserService", &kParserServiceCID },
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]));
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParser)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLoggingSink)
NS_GENERIC_FACTORY_CONSTRUCTOR(CWellFormedDTD)
@@ -188,6 +169,21 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(CViewSourceHTML)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLContentSinkStream)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsParserService)
static nsModuleComponentInfo gComponents[] = {
{ "Parser", NS_PARSER_CID, NULL, nsParserConstructor },
{ "Logging sink", NS_LOGGING_SINK_CID, NULL, nsLoggingSinkConstructor },
{ "Well formed DTD", NS_WELLFORMEDDTD_CID, NULL, CWellFormedDTDConstructor },
{ "Navigator HTML DTD", NS_CNAVDTD_CID, NULL, CNavDTDConstructor },
{ "OTHER DTD", NS_COTHER_DTD_CID, NULL, COtherDTDConstructor },
{ "Transitional DTD", NS_CTRANSITIONAL_DTD_CID, NULL,
CTransitionalDTDConstructor },
{ "ViewSource DTD", NS_VIEWSOURCE_DTD_CID, NULL, CViewSourceHTMLConstructor },
{ "HTML Content Sink Stream", NS_HTMLCONTENTSINKSTREAM_CID, NULL,
nsHTMLContentSinkStreamConstructor },
{ "ParserService", NS_PARSERSERVICE_CID, NULL, nsParserServiceConstructor }
};
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
//----------------------------------------------------------------------
class nsParserModule : public nsIModule {
@@ -205,20 +201,8 @@ protected:
void Shutdown();
PRBool mInitialized;
nsCOMPtr<nsIGenericFactory> mParserFactory;
nsCOMPtr<nsIGenericFactory> mParserNodeFactory;
nsCOMPtr<nsIGenericFactory> mLoggingSinkFactory;
nsCOMPtr<nsIGenericFactory> mWellFormedDTDFactory;
nsCOMPtr<nsIGenericFactory> mNavHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mOtherHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mTransitionalHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mViewSourceHTMLDTDFactory;
nsCOMPtr<nsIGenericFactory> mHTMLContentSinkStreamFactory;
nsCOMPtr<nsIGenericFactory> mParserServiceFactory;
};
static NS_DEFINE_IID(kIModuleIID, NS_IMODULE_IID);
nsParserModule::nsParserModule()
: mInitialized(PR_FALSE)
{
@@ -230,7 +214,7 @@ nsParserModule::~nsParserModule()
Shutdown();
}
NS_IMPL_ISUPPORTS(nsParserModule, kIModuleIID)
NS_IMPL_ISUPPORTS1(nsParserModule, nsIModule)
nsresult
nsParserModule::Initialize()
@@ -277,71 +261,11 @@ nsParserModule::GetClassObject(nsIComponentManager *aCompMgr,
nsCOMPtr<nsIGenericFactory> fact;
if (aClass.Equals(kParserCID)) {
if (!mParserFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mParserFactory),
&nsParserConstructor);
for (unsigned int i = 0; i < NUM_COMPONENTS; i++) {
if (aClass.Equals(gComponents[i].mCID)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), &gComponents[i]);
break;
}
fact = mParserFactory;
}
else if (aClass.Equals(kLoggingSinkCID)) {
if (!mLoggingSinkFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mLoggingSinkFactory),
&nsLoggingSinkConstructor);
}
fact = mLoggingSinkFactory;
}
else if (aClass.Equals(kWellFormedDTDCID)) {
if (!mWellFormedDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mWellFormedDTDFactory),
&CWellFormedDTDConstructor);
}
fact = mWellFormedDTDFactory;
}
else if (aClass.Equals(kNavDTDCID)) {
if (!mNavHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mNavHTMLDTDFactory),
&CNavDTDConstructor);
}
fact = mNavHTMLDTDFactory;
}
else if (aClass.Equals(kCOtherDTDCID)) {
if (!mOtherHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mOtherHTMLDTDFactory),
&COtherDTDConstructor);
}
fact = mOtherHTMLDTDFactory;
}
else if (aClass.Equals(kCTransitionalDTDCID)) {
if (!mTransitionalHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mTransitionalHTMLDTDFactory),
&CTransitionalDTDConstructor);
}
fact = mTransitionalHTMLDTDFactory;
}
else if (aClass.Equals(kViewSourceDTDCID)) {
if (!mViewSourceHTMLDTDFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mViewSourceHTMLDTDFactory),
&CViewSourceHTMLConstructor);
}
fact = mViewSourceHTMLDTDFactory;
}
else if (aClass.Equals(kHTMLContentSinkStreamCID)) {
if (!mHTMLContentSinkStreamFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mHTMLContentSinkStreamFactory),
&nsHTMLContentSinkStreamConstructor);
}
fact = mHTMLContentSinkStreamFactory;
}
else if (aClass.Equals(kParserServiceCID)) {
if (!mParserServiceFactory) {
rv = NS_NewGenericFactory(getter_AddRefs(mParserServiceFactory),
&nsParserServiceConstructor);
}
fact = mParserServiceFactory;
}
else {
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
}
if (fact) {
@@ -358,10 +282,9 @@ nsParserModule::RegisterSelf(nsIComponentManager *aCompMgr,
const char* componentType)
{
nsresult rv = NS_OK;
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
nsModuleComponentInfo* cp = gComponents, *end = cp + NUM_COMPONENTS;
while (cp < end) {
rv = aCompMgr->RegisterComponentSpec(*cp->mCID, cp->mDescription,
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
nsnull, aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
@@ -380,10 +303,9 @@ nsParserModule::UnregisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
Components* cp = gComponents;
Components* end = cp + NUM_COMPONENTS;
nsModuleComponentInfo* cp = gComponents, *end = cp + NUM_COMPONENTS;
while (cp < end) {
nsresult rv = aCompMgr->UnregisterComponentSpec(*cp->mCID, aPath);
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsParserModule: unable to unregister %s component => %x\n",

View File

@@ -226,6 +226,10 @@ nsViewModule::~nsViewModule(void)
NS_ASSERTION(mObjCount <= 0, "Module released while having outstanding objects.");
}
static nsModuleComponentInfo ViewManagerCI = {
NULL, NS_VIEW_MANAGER_CID, NULL, nsViewManagerConstructor
};
//
// The class object for us is just the factory and nothing more.
//
@@ -244,7 +248,7 @@ nsViewModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass
if (aClass.Equals(kCViewManager))
{
nsCOMPtr<nsIGenericFactory> factory;
rv = NS_NewGenericFactory(getter_AddRefs(factory), &nsViewManagerConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(factory), &ViewManagerCI);
if (NS_SUCCEEDED(rv))
{
rv = factory->QueryInterface(aIID, aFactory);

View File

@@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file

View File

@@ -398,10 +398,10 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
NS_INTERFACE_MAP_ENTRY(nsISupports) \
NS_INTERFACE_MAP_END
#define NS_IMPL_QUERY_INTERFACE1(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
#define NS_IMPL_QUERY_INTERFACE1(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_INTERFACE_MAP_END
#define NS_IMPL_QUERY_INTERFACE2(_class, _i1, _i2) \
@@ -1243,6 +1243,101 @@ CallQueryInterface( nsISupports* aSource, DestinationType** aDestination )
} // extern "C++"
///////////////////////////////////////////////////////////////////////////////
// Macros for implementing nsIClassInfo-related stuff.
///////////////////////////////////////////////////////////////////////////////
// include here instead of at the top because it requires the nsISupport decl
#include "nsIClassInfo.h"
#define NS_CLASSINFO_NAME(_class) _class##_classInfoGlobal
#define NS_CI_INTERFACE_GETTER_NAME(_class) _class##_GetInterfacesHelper
#define NS_DECL_CLASSINFO(_class) \
extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *, nsIID ***); \
nsIClassInfo *NS_CLASSINFO_NAME(_class);
#define NS_IMPL_QUERY_CLASSINFO(_class) \
if ( aIID.Equals(NS_GET_IID(nsIClassInfo)) ) { \
extern nsIClassInfo *NS_CLASSINFO_NAME(_class); \
foundInterface = NS_STATIC_CAST(nsIClassInfo*, NS_CLASSINFO_NAME(_class)); \
} else
#define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \
NS_IMETHODIMP \
NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *count, nsIID ***array) \
{ \
*count = _c; \
*array = (nsIID **)nsMemory::Alloc(sizeof (nsIID *) * _c);
#define NS_CLASSINFO_HELPER_ENTRY(_i, _interface) \
(*array)[_i] = (nsIID *)nsMemory::Clone(&NS_GET_IID(_interface), \
sizeof(nsIID));
#define NS_CLASSINFO_HELPER_END \
return NS_OK; \
}
#define NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface) \
NS_CLASSINFO_HELPER_BEGIN(_class, 1) \
NS_CLASSINFO_HELPER_ENTRY(0, _interface) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE1_CI(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS1_CI(_class, _interface) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE1_CI(_class, _interface) \
NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface)
#define NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2) \
NS_CLASSINFO_HELPER_BEGIN(_class, 2) \
NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY(_i2) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS2_CI(_class, _i1, _i2) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2)
#define NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3) \
NS_CLASSINFO_HELPER_BEGIN(_class, 3) \
NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY(_i2) \
NS_INTERFACE_MAP_ENTRY(_i3) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS3_CI(_class, _i1, _i2, _i3) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3)
///////////////////////////////////////////////////////////////////////////////
// Macros for checking the trueness of an expression passed in within an
// interface implementation.

View File

@@ -134,7 +134,7 @@ void XXXNeverCalled()
xptc_dummy();
xptc_dummy2();
XPTI_GetInterfaceInfoManager();
NS_NewGenericFactory(NULL, NULL, NULL);
NS_NewGenericFactory(NULL, NULL);
NS_NewHashtableEnumerator(NULL, NULL, NULL, NULL);
nsCWeakProxy(0, 0);
nsCWeakReferent(0);
@@ -177,4 +177,4 @@ void XXXNeverCalled()
NS_TraceMallocDumpAllocations(NULL);
NS_TraceMallocFlushLogfiles();
#endif
}
}

View File

@@ -82,59 +82,13 @@
#include "nsICaseConversion.h"
#endif /* XPCOM_STANDALONE */
// base
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
static NS_DEFINE_CID(kConsoleServiceCID, NS_CONSOLESERVICE_CID);
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
static NS_DEFINE_CID(kLoggingServiceCID, NS_LOGGINGSERVICE_CID);
// ds
static NS_DEFINE_CID(kArenaCID, NS_ARENA_CID);
static NS_DEFINE_CID(kByteBufferCID, NS_BYTEBUFFER_CID);
#ifdef PAGE_MANAGER
static NS_DEFINE_CID(kPageManagerCID, NS_PAGEMANAGER_CID);
#endif
static NS_DEFINE_CID(kPropertiesCID, NS_PROPERTIES_CID);
static NS_DEFINE_CID(kSupportsArrayCID, NS_SUPPORTSARRAY_CID);
// ds/nsISupportsPrimitives
static NS_DEFINE_CID(kSupportsIDCID, NS_SUPPORTS_ID_CID);
static NS_DEFINE_CID(kSupportsStringCID, NS_SUPPORTS_STRING_CID);
static NS_DEFINE_CID(kSupportsWStringCID, NS_SUPPORTS_WSTRING_CID);
static NS_DEFINE_CID(kSupportsPRBoolCID, NS_SUPPORTS_PRBOOL_CID);
static NS_DEFINE_CID(kSupportsPRUint8CID, NS_SUPPORTS_PRUINT8_CID);
static NS_DEFINE_CID(kSupportsPRUint16CID, NS_SUPPORTS_PRUINT16_CID);
static NS_DEFINE_CID(kSupportsPRUint32CID, NS_SUPPORTS_PRUINT32_CID);
static NS_DEFINE_CID(kSupportsPRUint64CID, NS_SUPPORTS_PRUINT64_CID);
static NS_DEFINE_CID(kSupportsPRTimeCID, NS_SUPPORTS_PRTIME_CID);
static NS_DEFINE_CID(kSupportsCharCID, NS_SUPPORTS_CHAR_CID);
static NS_DEFINE_CID(kSupportsPRInt16CID, NS_SUPPORTS_PRINT16_CID);
static NS_DEFINE_CID(kSupportsPRInt32CID, NS_SUPPORTS_PRINT32_CID);
static NS_DEFINE_CID(kSupportsPRInt64CID, NS_SUPPORTS_PRINT64_CID);
static NS_DEFINE_CID(kSupportsFloatCID, NS_SUPPORTS_FLOAT_CID);
static NS_DEFINE_CID(kSupportsDoubleCID, NS_SUPPORTS_DOUBLE_CID);
static NS_DEFINE_CID(kSupportsVoidCID, NS_SUPPORTS_VOID_CID);
// io
static NS_DEFINE_CID(kFileSpecCID, NS_FILESPEC_CID);
static NS_DEFINE_CID(kDirectoryIteratorCID, NS_DIRECTORYITERATOR_CID);
static NS_DEFINE_CID(kScriptableInputStreamCID, NS_SCRIPTABLEINPUTSTREAM_CID);
// components
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
// threads
static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID);
static NS_DEFINE_CID(kLoggingServiceCID, NS_LOGGINGSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
static NS_DEFINE_CID(kThreadCID, NS_THREAD_CID);
static NS_DEFINE_CID(kThreadPoolCID, NS_THREADPOOL_CID);
static NS_DEFINE_CID(kProcessCID, NS_PROCESS_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess);
// proxy
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
// atoms
static NS_DEFINE_CID(kAtomServiceCID, NS_ATOMSERVICE_CID);
// ds/nsISupportsPrimitives
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
@@ -178,14 +132,15 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService);
//
static nsresult
RegisterGenericFactory(nsIComponentManager* compMgr, const nsCID& cid, const char* className,
const char *contractid, nsIGenericFactory::ConstructorProcPtr constr)
RegisterGenericFactory(nsIComponentManager* compMgr,
nsModuleComponentInfo *info)
{
nsresult rv;
nsIGenericFactory* fact;
rv = NS_NewGenericFactory(&fact, constr);
rv = NS_NewGenericFactory(&fact, info);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterFactory(cid, className, contractid, fact, PR_TRUE);
rv = compMgr->RegisterFactory(info->mCID, info->mDescription,
info->mContractID, fact, PR_TRUE);
NS_RELEASE(fact);
return rv;
}
@@ -200,6 +155,86 @@ nsIProperties *gDirectoryService = NULL;
extern nsIServiceManager* gServiceManager;
extern PRBool gShuttingDown;
// For each class that wishes to support nsIClassInfo, add a line like this
// NS_DECL_CLASSINFO(nsMyClass)
#define COMPONENT(NAME, Ctor) \
{ NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
#define COMPONENT_CI(NAME, Ctor, Class) \
{ NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor, \
NULL, NULL, NULL, NS_CI_INTERFACE_GETTER_NAME(Class), NULL, \
&NS_CLASSINFO_NAME(Class) }
static nsModuleComponentInfo components[] = {
COMPONENT(MEMORY, nsMemoryImpl::Create),
#define NS_ERRORSERVICE_CLASSNAME NS_ERRORSERVICE_NAME
COMPONENT(ERRORSERVICE, nsErrorService::Create),
#ifdef NS_ENABLE_LOGGING
COMPONENT(LOGGINGSERVICE, nsLoggingService::Create),
#endif
COMPONENT(ARENA, ArenaImpl::Create),
COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
#ifdef PAGE_MANAGER
COMPONENT(PAGEMANAGER, nsPageMgr::Create),
#endif
COMPONENT(PROPERTIES, nsProperties::Create),
#define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create),
COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create),
COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor),
COMPONENT(ATOMSERVICE, nsAtomServiceConstructor),
COMPONENT(OBSERVER, nsObserver::Create),
COMPONENT(OBSERVERSERVICE, nsObserverService::Create),
COMPONENT(GENERICFACTORY, nsGenericFactory::Create),
COMPONENT(EVENTQUEUESERVICE, nsEventQueueServiceImpl::Create),
COMPONENT(EVENTQUEUE, nsEventQueueImpl::Create),
COMPONENT(THREAD, nsThread::Create),
COMPONENT(THREADPOOL, nsThreadPool::Create),
#define NS_XPCOMPROXY_CID NS_PROXYEVENT_MANAGER_CID
COMPONENT(XPCOMPROXY, nsProxyObjectManager::Create),
#define COMPONENT_SUPPORTS(TYPE, Type) \
COMPONENT(SUPPORTS_##TYPE, nsSupports##Type##ImplConstructor)
COMPONENT_SUPPORTS(ID, ID),
COMPONENT_SUPPORTS(STRING, String),
COMPONENT_SUPPORTS(WSTRING, WString),
COMPONENT_SUPPORTS(PRBOOL, PRBool),
COMPONENT_SUPPORTS(PRUINT8, PRUint8),
COMPONENT_SUPPORTS(PRUINT16, PRUint16),
COMPONENT_SUPPORTS(PRUINT32, PRUint32),
COMPONENT_SUPPORTS(PRUINT64, PRUint64),
COMPONENT_SUPPORTS(PRTIME, PRTime),
COMPONENT_SUPPORTS(CHAR, Char),
COMPONENT_SUPPORTS(PRINT16, PRInt16),
COMPONENT_SUPPORTS(PRINT32, PRInt32),
COMPONENT_SUPPORTS(PRINT64, PRInt64),
COMPONENT_SUPPORTS(FLOAT, Float),
COMPONENT_SUPPORTS(DOUBLE, Double),
COMPONENT_SUPPORTS(VOID, Void),
#undef COMPONENT_SUPPORTS
COMPONENT(LOCAL_FILE, nsLocalFile::nsLocalFileConstructor),
COMPONENT(DIRECTORY_SERVICE, nsDirectoryService::Create),
COMPONENT(PROCESS, nsProcessConstructor),
COMPONENT(FILESPEC, nsFileSpecImpl::Create),
COMPONENT(DIRECTORYITERATOR, nsDirectoryIteratorImpl::Create)
};
#undef COMPONENT
const int components_length = sizeof(components) / sizeof(components[0]);
nsresult NS_COM NS_InitXPCOM(nsIServiceManager* *result,
nsIFile* binDirectory)
@@ -355,271 +390,8 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result,
return rv;
}
rv = RegisterGenericFactory(compMgr, kMemoryCID,
NS_MEMORY_CLASSNAME,
NS_MEMORY_CONTRACTID,
nsMemoryImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kErrorServiceCID,
NS_ERRORSERVICE_NAME,
NS_ERRORSERVICE_CONTRACTID,
nsErrorService::Create);
if (NS_FAILED(rv)) return rv;
#ifdef NS_ENABLE_LOGGING
rv = RegisterGenericFactory(compMgr, kLoggingServiceCID,
NS_LOGGINGSERVICE_CLASSNAME,
NS_LOGGINGSERVICE_CONTRACTID,
nsLoggingService::Create);
if (NS_FAILED(rv)) return rv;
#endif
rv = RegisterGenericFactory(compMgr, kArenaCID,
NS_ARENA_CLASSNAME,
NS_ARENA_CONTRACTID,
ArenaImpl::Create);
if (NS_FAILED(rv)) return rv;
#if 0
rv = RegisterGenericFactory(compMgr, kBufferCID,
NS_BUFFER_CLASSNAME,
NS_BUFFER_CONTRACTID,
nsBuffer::Create);
if (NS_FAILED(rv)) return rv;
#endif
rv = RegisterGenericFactory(compMgr, kByteBufferCID,
NS_BYTEBUFFER_CLASSNAME,
NS_BYTEBUFFER_CONTRACTID,
ByteBufferImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kScriptableInputStreamCID,
NS_SCRIPTABLEINPUTSTREAM_CLASSNAME,
NS_SCRIPTABLEINPUTSTREAM_CONTRACTID,
nsScriptableInputStream::Create);
if (NS_FAILED(rv)) return rv;
#ifdef PAGE_MANAGER
rv = RegisterGenericFactory(compMgr, kPageManagerCID,
NS_PAGEMANAGER_CLASSNAME,
NS_PAGEMANAGER_CONTRACTID,
nsPageMgr::Create);
if (NS_FAILED(rv)) return rv;
#endif
rv = RegisterGenericFactory(compMgr, kPropertiesCID,
NS_PROPERTIES_CLASSNAME,
NS_PROPERTIES_CONTRACTID,
nsProperties::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kPersistentPropertiesCID,
NS_PERSISTENTPROPERTIES_CLASSNAME,
NS_PERSISTENTPROPERTIES_CONTRACTID,
nsPersistentProperties::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsArrayCID,
NS_SUPPORTSARRAY_CLASSNAME,
NS_SUPPORTSARRAY_CONTRACTID,
nsSupportsArray::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kConsoleServiceCID,
NS_CONSOLESERVICE_CLASSNAME,
NS_CONSOLESERVICE_CONTRACTID,
nsConsoleServiceConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kAtomServiceCID,
NS_ATOMSERVICE_CLASSNAME,
NS_ATOMSERVICE_CONTRACTID,
nsAtomServiceConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, nsObserver::GetCID(),
NS_OBSERVER_CLASSNAME,
NS_OBSERVER_CONTRACTID,
nsObserver::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, nsObserverList::GetCID(),
NS_OBSERVERLIST_CLASSNAME,
NS_OBSERVERLIST_CONTRACTID,
nsObserverList::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, nsObserverService::GetCID(),
NS_OBSERVERSERVICE_CLASSNAME,
NS_OBSERVERSERVICE_CONTRACTID,
nsObserverService::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kGenericFactoryCID,
NS_GENERICFACTORY_CLASSNAME,
NS_GENERICFACTORY_CONTRACTID,
nsGenericFactory::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kEventQueueServiceCID,
NS_EVENTQUEUESERVICE_CLASSNAME,
NS_EVENTQUEUESERVICE_CONTRACTID,
nsEventQueueServiceImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kEventQueueCID,
NS_EVENTQUEUE_CLASSNAME,
NS_EVENTQUEUE_CONTRACTID,
nsEventQueueImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kThreadCID,
NS_THREAD_CLASSNAME,
NS_THREAD_CONTRACTID,
nsThread::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kThreadPoolCID,
NS_THREADPOOL_CLASSNAME,
NS_THREADPOOL_CONTRACTID,
nsThreadPool::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr,
kProxyObjectManagerCID,
NS_XPCOMPROXY_CLASSNAME,
NS_XPCOMPROXY_CONTRACTID,
nsProxyObjectManager::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsIDCID,
NS_SUPPORTS_ID_CLASSNAME,
NS_SUPPORTS_ID_CONTRACTID,
nsSupportsIDImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsStringCID,
NS_SUPPORTS_STRING_CLASSNAME,
NS_SUPPORTS_STRING_CONTRACTID,
nsSupportsStringImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsWStringCID,
NS_SUPPORTS_WSTRING_CLASSNAME,
NS_SUPPORTS_WSTRING_CONTRACTID,
nsSupportsWStringImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRBoolCID,
NS_SUPPORTS_PRBOOL_CLASSNAME,
NS_SUPPORTS_PRBOOL_CONTRACTID,
nsSupportsPRBoolImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRUint8CID,
NS_SUPPORTS_PRUINT8_CLASSNAME,
NS_SUPPORTS_PRUINT8_CONTRACTID,
nsSupportsPRUint8ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRUint16CID,
NS_SUPPORTS_PRUINT16_CLASSNAME,
NS_SUPPORTS_PRUINT16_CONTRACTID,
nsSupportsPRUint16ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRUint32CID,
NS_SUPPORTS_PRUINT32_CLASSNAME,
NS_SUPPORTS_PRUINT32_CONTRACTID,
nsSupportsPRUint32ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRUint64CID,
NS_SUPPORTS_PRUINT64_CLASSNAME,
NS_SUPPORTS_PRUINT64_CONTRACTID,
nsSupportsPRUint64ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRTimeCID,
NS_SUPPORTS_PRTIME_CLASSNAME,
NS_SUPPORTS_PRTIME_CONTRACTID,
nsSupportsPRTimeImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsCharCID,
NS_SUPPORTS_CHAR_CLASSNAME,
NS_SUPPORTS_CHAR_CONTRACTID,
nsSupportsCharImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRInt16CID,
NS_SUPPORTS_PRINT16_CLASSNAME,
NS_SUPPORTS_PRINT16_CONTRACTID,
nsSupportsPRInt16ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRInt32CID,
NS_SUPPORTS_PRINT32_CLASSNAME,
NS_SUPPORTS_PRINT32_CONTRACTID,
nsSupportsPRInt32ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsPRInt64CID,
NS_SUPPORTS_PRINT64_CLASSNAME,
NS_SUPPORTS_PRINT64_CONTRACTID,
nsSupportsPRInt64ImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsFloatCID,
NS_SUPPORTS_FLOAT_CLASSNAME,
NS_SUPPORTS_FLOAT_CONTRACTID,
nsSupportsFloatImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsDoubleCID,
NS_SUPPORTS_DOUBLE_CLASSNAME,
NS_SUPPORTS_DOUBLE_CONTRACTID,
nsSupportsDoubleImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsVoidCID,
NS_SUPPORTS_VOID_CLASSNAME,
NS_SUPPORTS_VOID_CONTRACTID,
nsSupportsVoidImplConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, nsLocalFile::GetCID(),
NS_LOCAL_FILE_CLASSNAME,
NS_LOCAL_FILE_CONTRACTID,
nsLocalFile::nsLocalFileConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, nsDirectoryService::GetCID(),
NS_DIRECTORY_SERVICE_CLASSNAME,
NS_DIRECTORY_SERVICE_CONTRACTID,
nsDirectoryService::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kProcessCID,
NS_PROCESS_CLASSNAME,
NS_PROCESS_CONTRACTID,
nsProcessConstructor);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kFileSpecCID,
NS_FILESPEC_CLASSNAME,
NS_FILESPEC_CONTRACTID,
nsFileSpecImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kDirectoryIteratorCID,
NS_DIRECTORYITERATOR_CLASSNAME,
NS_DIRECTORYITERATOR_CONTRACTID,
nsDirectoryIteratorImpl::Create);
if (NS_FAILED(rv)) return rv;
for (int i = 0; i < components_length; i++)
RegisterGenericFactory(compMgr, &components[i]);
// Prepopulate registry for performance
// Ignore return value. It is ok if this fails.

View File

@@ -1,5 +1,6 @@
nsICategoryHandler.idl
nsICategoryManager.idl
nsIClassInfo.idl
nsIComponentLoader.idl
nsIComponentManager.idl
nsIFactory.idl

View File

@@ -38,7 +38,7 @@ CPPSRCS = \
nsRegistry.cpp \
nsRepository.cpp \
nsServiceManager.cpp \
nsCategoryManager.cpp \
nsCategoryManager.cpp \
xcDll.cpp \
$(NULL)
@@ -54,6 +54,7 @@ EXPORTS = \
XPIDLSRCS = \
nsICategoryHandler.idl \
nsICategoryManager.idl \
nsIClassInfo.idl \
nsIComponentLoader.idl \
nsIComponentManager.idl \
nsIFactory.idl \

View File

@@ -41,6 +41,7 @@ EXPORTS = \
XPIDLSRCS = \
.\nsICategoryHandler.idl \
.\nsICategoryManager.idl \
.\nsIClassInfo.idl \
.\nsIComponentLoader.idl \
.\nsIComponentManager.idl \
.\nsIFactory.idl \

View File

@@ -26,73 +26,137 @@
#include "nsGenericFactory.h"
#include "nsCRT.h"
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
: mConstructor(constructor), mDestructor(NULL)
nsGenericFactory::nsGenericFactory(nsModuleComponentInfo *info)
: mInfo(info)
{
NS_INIT_ISUPPORTS();
NS_INIT_ISUPPORTS();
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
}
nsGenericFactory::~nsGenericFactory()
{
if (mDestructor != NULL)
(*mDestructor) ();
if (mInfo) {
if (mInfo->mFactoryDestructor)
mInfo->mFactoryDestructor();
if (mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = 0;
}
}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsGenericFactory,
NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericFactory,
nsIGenericFactory,
nsIFactory)
nsIFactory,
nsIClassInfo)
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID, void **aResult)
{
return mConstructor(aOuter, aIID, aResult);
return mInfo->mConstructor(aOuter, aIID, aResult);
}
NS_IMETHODIMP nsGenericFactory::LockFactory(PRBool aLock)
{
return NS_OK;
// XXX do we care if (mInfo->mFlags & THREADSAFE)?
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
NS_IMETHODIMP nsGenericFactory::GetInterfaces(PRUint32 *countp,
nsIID* **array)
{
mConstructor = constructor;
return NS_OK;
if (!mInfo->mGetInterfacesProc) {
*countp = 0;
*array = nsnull;
return NS_OK;
}
return mInfo->mGetInterfacesProc(countp, array);
}
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
NS_IMETHODIMP nsGenericFactory::GetHelperForLanguage(PRUint32 language,
nsISupports **helper)
{
mDestructor = destructor;
return NS_OK;
if (mInfo->mGetLanguageHelperProc)
return mInfo->mGetLanguageHelperProc(language, helper);
*helper = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetContractID(char **aContractID)
{
if (mInfo->mContractID) {
*aContractID = (char *)nsMemory::Alloc(strlen(mInfo->mContractID) + 1);
if (!*aContractID)
return NS_ERROR_OUT_OF_MEMORY;
strcpy(*aContractID, mInfo->mContractID);
} else {
*aContractID = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID **aClassID)
{
*aClassID = (nsCID *)nsMemory::Clone(&mInfo->mCID, sizeof(nsCID));
if (!*aClassID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetImplementationLanguage(PRUint32 *langp)
{
*langp = nsIClassInfo::LANGUAGE_CPP;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetFlags(PRUint32 *flagsp)
{
*flagsp = mInfo->mFlags;
return NS_OK;
}
// nsIGenericFactory: component-info accessors
NS_IMETHODIMP nsGenericFactory::SetComponentInfo(nsModuleComponentInfo *info)
{
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = 0;
mInfo = info;
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetComponentInfo(nsModuleComponentInfo **infop)
{
*infop = mInfo;
return NS_OK;
}
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
// sorry, aggregation not spoken here.
nsresult res = NS_ERROR_NO_AGGREGATION;
if (outer == NULL) {
nsGenericFactory* factory = new nsGenericFactory;
if (factory != NULL) {
res = factory->QueryInterface(aIID, aInstancePtr);
if (res != NS_OK)
delete factory;
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
return res;
// sorry, aggregation not spoken here.
nsresult res = NS_ERROR_NO_AGGREGATION;
if (outer == NULL) {
nsGenericFactory* factory = new nsGenericFactory;
if (factory != NULL) {
res = factory->QueryInterface(aIID, aInstancePtr);
if (res != NS_OK)
delete factory;
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
return res;
}
NS_COM nsresult
NS_NewGenericFactory(nsIGenericFactory* *result,
nsIGenericFactory::ConstructorProcPtr constructor,
nsIGenericFactory::DestructorProcPtr destructor)
nsModuleComponentInfo *info)
{
nsresult rv;
nsIGenericFactory* fact;
rv = nsGenericFactory::Create(NULL, NS_GET_IID(nsIGenericFactory), (void**)&fact);
if (NS_FAILED(rv)) return rv;
rv = fact->SetConstructor(constructor);
if (NS_FAILED(rv)) goto error;
rv = fact->SetDestructor(destructor);
rv = fact->SetComponentInfo(info);
if (NS_FAILED(rv)) goto error;
*result = fact;
return rv;
@@ -177,7 +241,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
nsModuleComponentInfo* desc = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
if (desc->mCID.Equals(aClass)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc->mConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
if (NS_FAILED(rv)) return rv;
(void)mFactories.Put(&key, fact);
@@ -192,7 +256,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
nsCRT::free(cs);
#endif
// XXX put in stop-gap so that we don't search for this one again
return NS_ERROR_FACTORY_NOT_REGISTERED;
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
found:
rv = fact->QueryInterface(aIID, r_classObj);
@@ -226,7 +290,8 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr,
// Call the registration hook of the component, if any
if (cp->mRegisterSelfProc)
{
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation, componentType);
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation,
componentType, cp);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsGenericModule %s: Register hook for %s component returned error => %x\n",
@@ -254,7 +319,7 @@ nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
// Call the unregistration hook of the component, if any
if (cp->mUnregisterSelfProc)
{
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation);
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation, cp);
}
// Unregister the component
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);

View File

@@ -24,41 +24,33 @@
#define nsGenericFactory_h___
#include "nsIGenericFactory.h"
#include "nsIClassInfo.h"
/**
* Most factories follow this simple pattern, so why not just use a function pointer
* for most creation operations?
*/
class nsGenericFactory : public nsIGenericFactory {
class nsGenericFactory : public nsIGenericFactory, public nsIClassInfo {
public:
static const nsCID& CID() { static nsCID cid = NS_GENERICFACTORY_CID; return cid; }
nsGenericFactory(ConstructorProcPtr constructor = NULL);
nsGenericFactory(nsModuleComponentInfo *info = NULL);
virtual ~nsGenericFactory();
NS_DECL_ISUPPORTS
NS_DECL_NSICLASSINFO
/* nsIGenericFactory methods */
NS_IMETHOD SetComponentInfo(nsModuleComponentInfo *info);
NS_IMETHOD GetComponentInfo(nsModuleComponentInfo **infop);
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
private:
ConstructorProcPtr mConstructor;
DestructorProcPtr mDestructor;
nsModuleComponentInfo *mInfo;
};
////////////////////////////////////////////////////////////////////////////////

View File

@@ -74,12 +74,14 @@ interface nsIClassInfo : nsISupports
nsISupports getHelperForLanguage(in PRUint32 language);
/**
* null if not supported
* A contract ID through which an instance of this class can be created
* (or accessed as a service, if |flags & SINGLETON|), or null.
*/
readonly attribute string contractID;
/**
* null if not supported
* A class ID through which an instance of this class can be created
* (or accessed as a service, if |flags & SINGLETON|), or null.
*/
readonly attribute nsCIDPtr classID;

View File

@@ -35,6 +35,9 @@
#define NS_GENERICFACTORY_CONTRACTID "@mozilla.org/generic-factory;1"
#define NS_GENERICFACTORY_CLASSNAME "Generic Factory"
struct nsModuleComponentInfo; // forward declaration
/**
* Provides a Generic nsIFactory implementation that can be used by
* DLLs with very simple factory needs.
@@ -43,27 +46,14 @@ class nsIGenericFactory : public nsIFactory {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
typedef NS_CALLBACK(DestructorProcPtr) (void);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
NS_IMETHOD SetComponentInfo(nsModuleComponentInfo *info) = 0;
NS_IMETHOD GetComponentInfo(nsModuleComponentInfo **infop) = 0;
};
extern NS_COM nsresult
NS_NewGenericFactory(nsIGenericFactory* *result,
nsIGenericFactory::ConstructorProcPtr constructor,
nsIGenericFactory::DestructorProcPtr destructor = nsnull);
NS_NewGenericFactory(nsIGenericFactory **result,
nsModuleComponentInfo *info);
////////////////////////////////////////////////////////////////////////////////
// Generic Modules
@@ -72,14 +62,27 @@ NS_NewGenericFactory(nsIGenericFactory* *result,
#include "nsIModule.h"
typedef NS_CALLBACK(NSConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID,
void **aResult);
typedef NS_CALLBACK(NSRegisterSelfProcPtr) (nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType);
const char *componentType,
const nsModuleComponentInfo *info);
typedef NS_CALLBACK(NSUnregisterSelfProcPtr) (nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation);
const char *registryLocation,
const nsModuleComponentInfo *info);
typedef NS_CALLBACK(NSFactoryDestructorProcPtr) (void);
typedef NS_CALLBACK(NSGetInterfacesProcPtr) (PRUint32 *countp,
nsIID* **array);
typedef NS_CALLBACK(NSGetLanguageHelperProcPtr) (PRUint32 language,
nsISupports **helper);
/**
* Use this type to define a list of module component info to pass to
@@ -91,9 +94,14 @@ struct nsModuleComponentInfo {
const char* mDescription;
nsCID mCID;
const char* mContractID;
nsIGenericFactory::ConstructorProcPtr mConstructor;
NSConstructorProcPtr mConstructor;
NSRegisterSelfProcPtr mRegisterSelfProc;
NSUnregisterSelfProcPtr mUnregisterSelfProc;
NSFactoryDestructorProcPtr mFactoryDestructor;
NSGetInterfacesProcPtr mGetInterfacesProc;
NSGetLanguageHelperProcPtr mGetLanguageHelperProc;
nsIClassInfo ** mClassInfoGlobal;
PRUint32 mFlags;
};
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);

View File

@@ -846,9 +846,9 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when,
nsCOMPtr<nsIFile> dllSpec;
if (NS_SUCCEEDED(dll->GetDllSpec(getter_AddRefs(dllSpec))) && dllSpec)
{
nsXPIDLCString leafName;
dllSpec->GetLeafName(getter_Copies(leafName));
fileName.AssignWithConversion(leafName);
nsXPIDLCString dllLeafName;
dllSpec->GetLeafName(getter_Copies(dllLeafName));
fileName.AssignWithConversion(dllLeafName);
}
statusMsg.Append(fileName);

View File

@@ -1,150 +1,262 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>nsIClassInfo Overview</title>
<meta name="author" content="Mike Shaver">
<meta name="description" content="General Overview of nsIClassInfo infrastructure">
<style type="text/css">
a:link, a:visited { text-decoration: none; }
</style>
</head>
<body bgcolor="#ffffff" link="#0000ee" vlink="#551a8b" alink="#0000ee">
<h2><code>nsIClassInfo</code> Overview</h2>
Mike Shaver &lt;<a href="mailto:shaver@mozilla.org">shaver@mozilla.org</a>
&gt;<br>
Last Modified: March 7, 2001<br>
<hr align="Left" width="100%" size="2">
Mike Shaver &lt;<a href="mailto:shaver@mozilla.org">shaver@mozilla.org</a>
&gt;<br>
&nbsp;&nbsp; &nbsp; Last Modified: March 12, 2001<br>
<hr align="Left" width="100%" size="2">
<h3>Table of Contents</h3>
<ul>
<li><a href="#What_is_nsIClassInfo">What is <code>nsIClassInfo</code>?</a></li>
<li><a href="#How_do_I_use_it">How do I use it?</a><a href="#What_is_nsIClassInfo"></a></li>
<li><a href="#Doesnt_that_break_the_COM">Doesn't that break the COM <code>
QueryInterface</code> rules?</a><a href="#Doesnt_that_break_the_COM"></a></li>
<li><a href="#That_sounds_useful_How_do_I_make_it">That sounds useful.
How do I make that work with my code?</a></li>
QueryInterface</code> rules?</a><a href="#Doesnt_that_break_the_COM"></a></li>
<li><a href="#What_are_the_language_helpers_for">What are the "language
helpers" for?</a><br>
</li>
<li><a href="#That_sounds_useful_How_do_I_make_it">That sounds useful.
How do I make that work with my code?</a></li>
<ul>
<li>I'm writing C++ code, and</li>
<ul>
<li><a href="#Im_writing_C_code_and_I_use_the">I use the generic factory
and <code>nsModuleComponentInfo</code></a></li>
<li><a href="#Im_writing_C_code_and_I_use_a_custom">I use a custom
factory or a singleton service object</a><br>
</li>
<li><a href="#Im_writing_C_code_and_I_use_the">I use the generic factory
and <code>nsModuleComponentInfo</code></a></li>
<li><a href="#Im_writing_C_code_and_I_use_a_custom">I use a custom factory
or a singleton service object</a><br>
</li>
</ul>
</ul>
<ul>
<li><a href="#Im_writing_JS_code">I'm writing JS code.</a></li>
</ul>
<li><a href="#Whats_interface_flattening">What's "interface flattening"?</a><br>
</li>
</li>
</ul>
<hr align="Left" width="100%" size="2">
<hr align="Left" width="100%" size="2">
<h4><a name="What_is_nsIClassInfo"></a>What is <code>nsIClassInfo</code>?</h4>
<p><a href="http://lxr.mozilla.org/mozilla/source/xpcom/components/nsIClassInfo.idl#38"><code>
nsIClassInfo</code></a> is an interface that provides information about
a specific implementation class, to wit:</p>
nsIClassInfo</code></a> is an interface that provides information
about a specific implementation class, to wit:</p>
<ul>
<li> a contract ID and class ID through which it may be instantiated;</li>
<li>the language of implementation (C++, JavaScript, etc.);</li>
<li> a list of the interfaces implemented by the class;</li>
<li>flags indicating whether or not the class is threadsafe or a singleton;
and</li>
<li>flags indicating whether or not the class is threadsafe or a singleton;
and</li>
<li>helper objects in support of various language bindings.</li>
</ul>
<h4><a name="How_do_I_use_it"></a>How do I use it?</h4>
<p> To get the <code>nsIClassInfo</code> object for the implementation behind
a given interface, simply <code>QueryInterface</code> for the nsIClassInfo
interface:</p>
<p> To get the <code>nsIClassInfo</code> object for the implementation behind
a given interface, simply <code>QueryInterface</code> for the nsIClassInfo
interface:</p>
<blockquote>C++:<br>
<code>nsCOMPtr&lt;nsIClassInfo&gt; info = do_QueryInterface(ifacePtr);</code><br>
<br>
JavaScript:<br>
<code>var info = ifacePtr.QueryInterface(Components.interfaces.nsIClassInfo);</code></blockquote>
<code>nsCOMPtr&lt;nsIClassInfo&gt; info = do_QueryInterface(ifacePtr);</code><br>
<br>
JavaScript:<br>
<code>var info = ifacePtr.QueryInterface(Components.interfaces.nsIClassInfo);</code></blockquote>
<p>It's important to note that this will usually return a <i>singleton</i>
object: there often exists only one nsIClassInfo implementation for all
implementations of a given class. This is very important, because it means
that you can't <code>QueryInterface</code> back to the original object,
object: there often exists only one nsIClassInfo implementation for
all implementations of a given class. This is very important, because it
means that you can't <code>QueryInterface</code> back to the original object,
no matter how hard you try.</p>
<h4><a name="Doesnt_that_break_the_COM"></a>Doesn't that break the COM
<code>QueryInterface</code> rules?</h4>
<h4><a name="Doesnt_that_break_the_COM"></a>Doesn't that break the COM
<code>QueryInterface</code> rules?</h4>
<p>Quite. As discussed in <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=67699">
bug 67699</a>, though, it's a reasonable concession to make in order to
avoid an additional vtbl entry on every class that wants to export <code>
nsIClassInfo</code> data.<br>
</p>
<h4><a name="That_sounds_useful_How_do_I_make_it"></a>That sounds useful.
How do I make it work with my code?</h4>
<p>Why, yes, it <i>is</i> useful. To provide <code>nsIClassInfo</code>
data for your class, you need to ensure that it returns an <code>nsIClassInfo</code>
-implementing object when it is <code>QueryInterface</code>d for <code>
nsIClassInfo</code> . Simple enough, but it can be even simpler through
the use of a handful of helper macros/functions. Choose your own adventure:</p>
<h4><a name="Im_writing_C_code_and_I_use_the"></a>I'm writing C++ code,
and I use the generic factory and <code>nsModuleComponentInfo</code>.</h4>
<p>First, make sure that your class has the <code>nsIClassInfo</code> helpers,
by changing the <code>NS_IMPL_ISUPPORTS</code> line:</p>
<blockquote><code>NS_IMPL_ISUPPORTS2(nsSampleImpl, nsISample, nsIOther)</code><br>
bug 67699</a>, though, it's a reasonable concession to make in order
to avoid an additional vtbl entry on every class that wants to export <code>
nsIClassInfo</code> data.<br>
</p>
<h4><a name="What_are_the_language_helpers_for"></a>What are the "language
helpers" for?</h4>
<p>The language helpers are basically hooks for alternate language bindings
to use for providing language-specific wrapping and manipulation behaviour,
without adding code to every wrapped object.&nbsp; In <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=67699">
bug 67669</a>, jband tells us what XPConnect does with the language helpers:</p>
<blockquote>
<p>When wrapping an object xpconnect QIs the object for its classinfo
(say 'foo'). If it has seen that foo classinfo pointer before then it knows
that this object is a foo and it can reuse all the info is knows about foo
objects. If it has never seen foo it will gather info (such as the JS helper)
and remember that for future wrappings of foo objects.</p>
<p> Assuming that the foo helper tells xpconnect to not bother QI'ing
each foo instance for a per instance helper (or if the instances don't respond
to QI for the helper) then the same foo helper is used on all calls from
JS relating to the foo instances. </p>
<p>What you may be missing is that methods on the helper (nsIXPCScriptable
in the xpconnect case) *all* receive a pointer to the instance wrapper when
called. I.e. the helper methods have an explicit 'self' param. This allows
the helper to customize its response for each method call without requiring
a helper per instance.</p>
</blockquote>
<p>becomes</p>
<blockquote><code>NS_IMPL_ISUPPORTS2_CI(nsSampleImpl, nsISample, nsIOther)</code><br>
</blockquote>
<p>This will provide an implementation of a helper function, named
<code>nsSampleImpl_GetInterfacesHelper</code>, which handles the processing
of <code>nsIClassInfo::getInterfaces</code>.</p>
<p>Next, in your module code, use <code>NS_DECL_CLASSINFO</code> to
provide the rest of the per-class infrastructure (a global pointer into
which to stash the <code>nsIClassInfo</code> object, and an extern declaration
of the interfaces-helper, in case it's defined in another file):</p>
<blockquote><code>NS_DECL_CLASSINFO(nsSampleImpl)</code><br>
</blockquote>
<p>You'll need one of these lines for each <code>nsIClassInfo</code>
-supporting class represented in your <code>nsModuleComponentInfo</code>
array.</p>
<p>Lastly, fill in the appropriate members of <code>nsModuleComponentInfo</code>
to wire everything up:</p>
<blockquote><code>static nsModuleComponentInfo components[] =</code><br>
<code>{</code><br>
<code> &nbsp; {<br>
&nbsp; &nbsp; "Sample Component", NS_SAMPLE_CID, NS_SAMPLE_CONTRACTID,
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>
&nbsp; &nbsp; nsSampleImplConstructor,</code><br>
<code> &nbsp; &nbsp; nsSampleRegistrationProc,</code><br>
<code> &nbsp; &nbsp; nsSampleUnregistrationProc,</code><br>
<code> &nbsp; &nbsp; nsnull /* no factory destructor */,</code><br>
<code><font color="#ff0000"> &nbsp; &nbsp; NS_CI_INTERFACE_GETTER_NAME(nsSampleImpl),&nbsp;
/* interface getter */</font></code><br>
<code> &nbsp; &nbsp; nsnull /* no language helper */,</code><br>
<code><font color="#ff0000"> &nbsp; &nbsp; &amp;NS_CLASSINFO_NAME(nsSampleImpl),&nbsp;
/* global class-info pointer */</font></code><br>
<code> &nbsp; &nbsp; 0 /* no class flags */<br>
&nbsp; }</code><br>
<code>};</code><br>
</blockquote>
<p>If you want to add a callback which provides language-helper
objects, replace the last <code>nsnull</code> with your callback. See the
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/components/nsIClassInfo.idl"><code>
nsIClassInfo</code> IDL file</a> for details on language helpers and other
esoterica.</p>
<h4><a name="Im_writing_C_code_and_I_use_a_custom"></a>I'm writing
C++ code, and I use a custom factory or a singleton service object.</h4>
<p>You need some utility macros, don't ya? We're working on it.</p>
<h4><a name="Im_writing_JS_code"></a>I'm writing JS code.</h4>
You poor thing. You suffer without even a GenericModule helper. We're
working on that, too.
<h4><a name="Whats_interface_flattening"></a>What's "interface
See <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=67699">bug 67699</a>
for more interesting discussion about pluggable language helpers and decoupling
them from specific wrapped classes.
<p></p>
<h4><a name="That_sounds_useful_How_do_I_make_it"></a>That sounds useful.
How do I make it work with my code?</h4>
<p>Why, yes, it <i>is</i> useful. To provide <code>nsIClassInfo</code>
data for your class, you need to ensure that it returns an <code>nsIClassInfo</code>
-implementing object when it is <code>QueryInterface</code>d for <code>
nsIClassInfo</code> . Simple enough, but it can be even simpler through
the use of a handful of helper macros/functions. Choose your own adventure:</p>
<h4><a name="Im_writing_C_code_and_I_use_the"></a>I'm writing C++ code,
and I use the generic factory and <code>nsModuleComponentInfo</code>.</h4>
<p>First, make sure that your class has the <code>nsIClassInfo</code>
helpers, by changing the <code>NS_IMPL_ISUPPORTS</code> line:</p>
<blockquote><code>NS_IMPL_ISUPPORTS2(nsSampleImpl, nsISample, nsIOther)</code><br>
</blockquote>
<p>becomes</p>
<blockquote><code>NS_IMPL_ISUPPORTS2_CI(nsSampleImpl, nsISample, nsIOther)</code><br>
</blockquote>
<p>This will provide an implementation of a helper function, named
<code>nsSampleImpl_GetInterfacesHelper</code>, which handles the processing
of <code>nsIClassInfo::getInterfaces</code>.</p>
<p>Next, in your module code, use <code>NS_DECL_CLASSINFO</code> to
provide the rest of the per-class infrastructure (a global pointer into
which to stash the <code>nsIClassInfo</code> object, and an extern declaration
of the interfaces-helper, in case it's defined in another file):</p>
<blockquote><code>NS_DECL_CLASSINFO(nsSampleImpl)</code><br>
</blockquote>
<p>You'll need one of these lines for each <code>nsIClassInfo</code>
-supporting class represented in your <code>nsModuleComponentInfo</code>
array.</p>
<p>Lastly, fill in the appropriate members of <code>nsModuleComponentInfo</code>
to wire everything up:</p>
<blockquote><code>static nsModuleComponentInfo components[] =</code><br>
<code>{</code><br>
<code> &nbsp; {<br>
&nbsp; &nbsp; "Sample Component", NS_SAMPLE_CID, NS_SAMPLE_CONTRACTID,
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>
&nbsp; &nbsp; nsSampleImplConstructor,</code><br>
<code> &nbsp; &nbsp; nsSampleRegistrationProc,</code><br>
<code> &nbsp; &nbsp; nsSampleUnregistrationProc,</code><br>
<code> &nbsp; &nbsp; nsnull /* no factory destructor */,</code><br>
<code><font color="#ff0000"> &nbsp; &nbsp; NS_CI_INTERFACE_GETTER_NAME(nsSampleImpl),&nbsp;
/* interface getter */</font></code><br>
<code> &nbsp; &nbsp; nsnull /* no language helper */,</code><br>
<code><font color="#ff0000"> &nbsp; &nbsp; &amp;NS_CLASSINFO_NAME(nsSampleImpl),&nbsp;
/* global class-info pointer */</font></code><br>
<code> &nbsp; &nbsp; 0 /* no class flags */<br>
&nbsp; }</code><br>
<code>};</code><br>
</blockquote>
<p>If you want to add a callback which provides language-helper
objects, replace the last <code>nsnull</code> with your callback. See the
<a href="http://lxr.mozilla.org/mozilla/source/xpcom/components/nsIClassInfo.idl"><code>
nsIClassInfo</code> IDL file</a> for details on language helpers and
other esoterica.</p>
<p><b><i>Note</i></b>: the details of these macros may change
slightly over the next week or so, as we refine a system for using table-driven
QI and sharing data between QI and the class-info calls.<br>
</p>
<h4><a name="Im_writing_C_code_and_I_use_a_custom"></a>I'm writing
C++ code, and I use a custom factory or a singleton service object.</h4>
<p>You need some utility macros, don't ya?&nbsp; We're working
on it.&nbsp; (You should really use the generic factory and module, though.&nbsp;
See <a href="http://lxr.mozilla.org/seamonkey/source/intl/uconv/src/nsUConvModule.cpp">
nsUConvModule.cpp</a> for an example of how to use <code>nsModuleComponentInfo</code>
and the generic modules even when you have highly-custom registration
requirements.)</p>
<h4><a name="Im_writing_JS_code"></a>I'm writing JS code.</h4>
You poor thing. You suffer without even a GenericModule helper. We're
<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=71689">working on
that</a>, too.
<h4><a name="Whats_interface_flattening"></a>What's "interface
flattening"?</h4>
<p>You'd think that you might find an explanation of interface
flattening in <a href="http://bugzilla.mozilla.org/show_bug.cgi?id=13422">
bug 13422</a> , but you'd be wrong. I'll need to write one here.<br>
<br>
</p>
<br>
<br>
<br>
</body>
</html>
<p></p>
<p> Interface flattening is a way to present multiple interfaces
of the same object to a language binding, without requiring explicit <code>
QueryInterface</code> calls.&nbsp; Consider the following interfaces and
an object <code>obj</code> that implements both of them:</p>
<blockquote>
<p><code>interface nsIFoo : nsISupports {<br>
&nbsp; &nbsp; void fooMeth(in string message);<br>
};</code></p>
<p><code>interface nsIBar : nsISupports {<br>
&nbsp; &nbsp; void barMeth(in PRUint32 meaning);<br>
};</code></p>
</blockquote>
<p>You could use the following code to call both fooMeth and
barMeth without any QueryInterface:<br>
</p>
<blockquote><code>obj.fooMeth("welcome to foo");<br>
obj.barMeth(42);</code></blockquote>
<p>Pretty, no?&nbsp; Pretty, yes. </p>
<p>There are also intricacies related to conflicting method
names and the difference between interface sets that are part of a contract's
promise and those which are simply artifacts of the implementation, but they're
beyond the scope of this overview.<br>
<br>
</p>
</body>
</html>

View File

@@ -26,73 +26,137 @@
#include "nsGenericFactory.h"
#include "nsCRT.h"
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
: mConstructor(constructor), mDestructor(NULL)
nsGenericFactory::nsGenericFactory(nsModuleComponentInfo *info)
: mInfo(info)
{
NS_INIT_ISUPPORTS();
NS_INIT_ISUPPORTS();
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
}
nsGenericFactory::~nsGenericFactory()
{
if (mDestructor != NULL)
(*mDestructor) ();
if (mInfo) {
if (mInfo->mFactoryDestructor)
mInfo->mFactoryDestructor();
if (mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = 0;
}
}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsGenericFactory,
NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericFactory,
nsIGenericFactory,
nsIFactory)
nsIFactory,
nsIClassInfo)
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter,
REFNSIID aIID, void **aResult)
{
return mConstructor(aOuter, aIID, aResult);
return mInfo->mConstructor(aOuter, aIID, aResult);
}
NS_IMETHODIMP nsGenericFactory::LockFactory(PRBool aLock)
{
return NS_OK;
// XXX do we care if (mInfo->mFlags & THREADSAFE)?
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
NS_IMETHODIMP nsGenericFactory::GetInterfaces(PRUint32 *countp,
nsIID* **array)
{
mConstructor = constructor;
return NS_OK;
if (!mInfo->mGetInterfacesProc) {
*countp = 0;
*array = nsnull;
return NS_OK;
}
return mInfo->mGetInterfacesProc(countp, array);
}
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
NS_IMETHODIMP nsGenericFactory::GetHelperForLanguage(PRUint32 language,
nsISupports **helper)
{
mDestructor = destructor;
return NS_OK;
if (mInfo->mGetLanguageHelperProc)
return mInfo->mGetLanguageHelperProc(language, helper);
*helper = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetContractID(char **aContractID)
{
if (mInfo->mContractID) {
*aContractID = (char *)nsMemory::Alloc(strlen(mInfo->mContractID) + 1);
if (!*aContractID)
return NS_ERROR_OUT_OF_MEMORY;
strcpy(*aContractID, mInfo->mContractID);
} else {
*aContractID = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID **aClassID)
{
*aClassID = (nsCID *)nsMemory::Clone(&mInfo->mCID, sizeof(nsCID));
if (!*aClassID)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetImplementationLanguage(PRUint32 *langp)
{
*langp = nsIClassInfo::LANGUAGE_CPP;
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetFlags(PRUint32 *flagsp)
{
*flagsp = mInfo->mFlags;
return NS_OK;
}
// nsIGenericFactory: component-info accessors
NS_IMETHODIMP nsGenericFactory::SetComponentInfo(nsModuleComponentInfo *info)
{
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = 0;
mInfo = info;
if (mInfo && mInfo->mClassInfoGlobal)
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::GetComponentInfo(nsModuleComponentInfo **infop)
{
*infop = mInfo;
return NS_OK;
}
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
// sorry, aggregation not spoken here.
nsresult res = NS_ERROR_NO_AGGREGATION;
if (outer == NULL) {
nsGenericFactory* factory = new nsGenericFactory;
if (factory != NULL) {
res = factory->QueryInterface(aIID, aInstancePtr);
if (res != NS_OK)
delete factory;
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
return res;
// sorry, aggregation not spoken here.
nsresult res = NS_ERROR_NO_AGGREGATION;
if (outer == NULL) {
nsGenericFactory* factory = new nsGenericFactory;
if (factory != NULL) {
res = factory->QueryInterface(aIID, aInstancePtr);
if (res != NS_OK)
delete factory;
} else {
res = NS_ERROR_OUT_OF_MEMORY;
}
}
return res;
}
NS_COM nsresult
NS_NewGenericFactory(nsIGenericFactory* *result,
nsIGenericFactory::ConstructorProcPtr constructor,
nsIGenericFactory::DestructorProcPtr destructor)
nsModuleComponentInfo *info)
{
nsresult rv;
nsIGenericFactory* fact;
rv = nsGenericFactory::Create(NULL, NS_GET_IID(nsIGenericFactory), (void**)&fact);
if (NS_FAILED(rv)) return rv;
rv = fact->SetConstructor(constructor);
if (NS_FAILED(rv)) goto error;
rv = fact->SetDestructor(destructor);
rv = fact->SetComponentInfo(info);
if (NS_FAILED(rv)) goto error;
*result = fact;
return rv;
@@ -177,7 +241,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
nsModuleComponentInfo* desc = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
if (desc->mCID.Equals(aClass)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc->mConstructor);
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
if (NS_FAILED(rv)) return rv;
(void)mFactories.Put(&key, fact);
@@ -192,7 +256,7 @@ nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
nsCRT::free(cs);
#endif
// XXX put in stop-gap so that we don't search for this one again
return NS_ERROR_FACTORY_NOT_REGISTERED;
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
found:
rv = fact->QueryInterface(aIID, r_classObj);
@@ -226,7 +290,8 @@ nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr,
// Call the registration hook of the component, if any
if (cp->mRegisterSelfProc)
{
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation, componentType);
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation,
componentType, cp);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsGenericModule %s: Register hook for %s component returned error => %x\n",
@@ -254,7 +319,7 @@ nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
// Call the unregistration hook of the component, if any
if (cp->mUnregisterSelfProc)
{
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation);
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation, cp);
}
// Unregister the component
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);

View File

@@ -24,41 +24,33 @@
#define nsGenericFactory_h___
#include "nsIGenericFactory.h"
#include "nsIClassInfo.h"
/**
* Most factories follow this simple pattern, so why not just use a function pointer
* for most creation operations?
*/
class nsGenericFactory : public nsIGenericFactory {
class nsGenericFactory : public nsIGenericFactory, public nsIClassInfo {
public:
static const nsCID& CID() { static nsCID cid = NS_GENERICFACTORY_CID; return cid; }
nsGenericFactory(ConstructorProcPtr constructor = NULL);
nsGenericFactory(nsModuleComponentInfo *info = NULL);
virtual ~nsGenericFactory();
NS_DECL_ISUPPORTS
NS_DECL_NSICLASSINFO
/* nsIGenericFactory methods */
NS_IMETHOD SetComponentInfo(nsModuleComponentInfo *info);
NS_IMETHOD GetComponentInfo(nsModuleComponentInfo **infop);
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
private:
ConstructorProcPtr mConstructor;
DestructorProcPtr mDestructor;
nsModuleComponentInfo *mInfo;
};
////////////////////////////////////////////////////////////////////////////////

View File

@@ -35,6 +35,9 @@
#define NS_GENERICFACTORY_CONTRACTID "@mozilla.org/generic-factory;1"
#define NS_GENERICFACTORY_CLASSNAME "Generic Factory"
struct nsModuleComponentInfo; // forward declaration
/**
* Provides a Generic nsIFactory implementation that can be used by
* DLLs with very simple factory needs.
@@ -43,27 +46,14 @@ class nsIGenericFactory : public nsIFactory {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
typedef NS_CALLBACK(DestructorProcPtr) (void);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
NS_IMETHOD SetComponentInfo(nsModuleComponentInfo *info) = 0;
NS_IMETHOD GetComponentInfo(nsModuleComponentInfo **infop) = 0;
};
extern NS_COM nsresult
NS_NewGenericFactory(nsIGenericFactory* *result,
nsIGenericFactory::ConstructorProcPtr constructor,
nsIGenericFactory::DestructorProcPtr destructor = nsnull);
NS_NewGenericFactory(nsIGenericFactory **result,
nsModuleComponentInfo *info);
////////////////////////////////////////////////////////////////////////////////
// Generic Modules
@@ -72,14 +62,27 @@ NS_NewGenericFactory(nsIGenericFactory* *result,
#include "nsIModule.h"
typedef NS_CALLBACK(NSConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID,
void **aResult);
typedef NS_CALLBACK(NSRegisterSelfProcPtr) (nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType);
const char *componentType,
const nsModuleComponentInfo *info);
typedef NS_CALLBACK(NSUnregisterSelfProcPtr) (nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation);
const char *registryLocation,
const nsModuleComponentInfo *info);
typedef NS_CALLBACK(NSFactoryDestructorProcPtr) (void);
typedef NS_CALLBACK(NSGetInterfacesProcPtr) (PRUint32 *countp,
nsIID* **array);
typedef NS_CALLBACK(NSGetLanguageHelperProcPtr) (PRUint32 language,
nsISupports **helper);
/**
* Use this type to define a list of module component info to pass to
@@ -91,9 +94,14 @@ struct nsModuleComponentInfo {
const char* mDescription;
nsCID mCID;
const char* mContractID;
nsIGenericFactory::ConstructorProcPtr mConstructor;
NSConstructorProcPtr mConstructor;
NSRegisterSelfProcPtr mRegisterSelfProc;
NSUnregisterSelfProcPtr mUnregisterSelfProc;
NSFactoryDestructorProcPtr mFactoryDestructor;
NSGetInterfacesProcPtr mGetInterfacesProc;
NSGetLanguageHelperProcPtr mGetLanguageHelperProc;
nsIClassInfo ** mClassInfoGlobal;
PRUint32 mFlags;
};
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);

View File

@@ -398,10 +398,10 @@ NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
NS_INTERFACE_MAP_ENTRY(nsISupports) \
NS_INTERFACE_MAP_END
#define NS_IMPL_QUERY_INTERFACE1(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
#define NS_IMPL_QUERY_INTERFACE1(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_INTERFACE_MAP_END
#define NS_IMPL_QUERY_INTERFACE2(_class, _i1, _i2) \
@@ -1243,6 +1243,101 @@ CallQueryInterface( nsISupports* aSource, DestinationType** aDestination )
} // extern "C++"
///////////////////////////////////////////////////////////////////////////////
// Macros for implementing nsIClassInfo-related stuff.
///////////////////////////////////////////////////////////////////////////////
// include here instead of at the top because it requires the nsISupport decl
#include "nsIClassInfo.h"
#define NS_CLASSINFO_NAME(_class) _class##_classInfoGlobal
#define NS_CI_INTERFACE_GETTER_NAME(_class) _class##_GetInterfacesHelper
#define NS_DECL_CLASSINFO(_class) \
extern NS_IMETHODIMP NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *, nsIID ***); \
nsIClassInfo *NS_CLASSINFO_NAME(_class);
#define NS_IMPL_QUERY_CLASSINFO(_class) \
if ( aIID.Equals(NS_GET_IID(nsIClassInfo)) ) { \
extern nsIClassInfo *NS_CLASSINFO_NAME(_class); \
foundInterface = NS_STATIC_CAST(nsIClassInfo*, NS_CLASSINFO_NAME(_class)); \
} else
#define NS_CLASSINFO_HELPER_BEGIN(_class, _c) \
NS_IMETHODIMP \
NS_CI_INTERFACE_GETTER_NAME(_class)(PRUint32 *count, nsIID ***array) \
{ \
*count = _c; \
*array = (nsIID **)nsMemory::Alloc(sizeof (nsIID *) * _c);
#define NS_CLASSINFO_HELPER_ENTRY(_i, _interface) \
(*array)[_i] = (nsIID *)nsMemory::Clone(&NS_GET_IID(_interface), \
sizeof(nsIID));
#define NS_CLASSINFO_HELPER_END \
return NS_OK; \
}
#define NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface) \
NS_CLASSINFO_HELPER_BEGIN(_class, 1) \
NS_CLASSINFO_HELPER_ENTRY(0, _interface) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE1_CI(_class, _i1) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS1_CI(_class, _interface) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE1_CI(_class, _interface) \
NS_IMPL_CI_INTERFACE_GETTER1(_class, _interface)
#define NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2) \
NS_CLASSINFO_HELPER_BEGIN(_class, 2) \
NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY(_i2) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS2_CI(_class, _i1, _i2) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE2_CI(_class, _i1, _i2) \
NS_IMPL_CI_INTERFACE_GETTER2(_class, _i1, _i2)
#define NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3) \
NS_CLASSINFO_HELPER_BEGIN(_class, 3) \
NS_CLASSINFO_HELPER_ENTRY(0, _i1) \
NS_CLASSINFO_HELPER_ENTRY(1, _i2) \
NS_CLASSINFO_HELPER_ENTRY(2, _i3) \
NS_CLASSINFO_HELPER_END
#define NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
NS_INTERFACE_MAP_BEGIN(_class) \
NS_INTERFACE_MAP_ENTRY(_i1) \
NS_INTERFACE_MAP_ENTRY(_i2) \
NS_INTERFACE_MAP_ENTRY(_i3) \
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1) \
NS_IMPL_QUERY_CLASSINFO(_class) \
NS_INTERFACE_MAP_END
#define NS_IMPL_ISUPPORTS3_CI(_class, _i1, _i2, _i3) \
NS_IMPL_ADDREF(_class) \
NS_IMPL_RELEASE(_class) \
NS_IMPL_QUERY_INTERFACE3_CI(_class, _i1, _i2, _i3) \
NS_IMPL_CI_INTERFACE_GETTER3(_class, _i1, _i2, _i3)
///////////////////////////////////////////////////////////////////////////////
// Macros for checking the trueness of an expression passed in within an
// interface implementation.

Binary file not shown.

View File

@@ -56,10 +56,13 @@ nsSampleImpl::~nsSampleImpl()
* you could use NS_IMPL_ADDREF() and NS_IMPL_RELEASE() to take care of the
* simple stuff, but you would have to create QueryInterface on your own.
* nsSampleFactory.cpp is an example of this approach.
* Notice that the second parameter to the macro is the static IID accessor
* method, and NOT the #defined IID.
* Notice that the second parameter to the macro is name of the interface, and
* NOT the #defined IID.
*
* The _CI variant adds support for nsIClassInfo, which permits introspection
* and interface flattening.
*/
NS_IMPL_ISUPPORTS1(nsSampleImpl, nsISample);
NS_IMPL_ISUPPORTS1_CI(nsSampleImpl, nsISample);
/**
* Notice that in the protoype for this function, the NS_IMETHOD macro was

View File

@@ -60,7 +60,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSampleImpl)
static NS_METHOD nsSampleRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
// Do any registration specific activity like adding yourself to a
// category. The Generic Module will take care of registering your
@@ -74,7 +75,8 @@ static NS_METHOD nsSampleRegistrationProc(nsIComponentManager *aCompMgr,
static NS_METHOD nsSampleUnregistrationProc(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation)
const char *registryLocation,
const nsModuleComponentInfo *info)
{
// Undo any component specific registration like adding yourself to a
// category here. The Generic Module will take care of unregistering your
@@ -87,11 +89,18 @@ static NS_METHOD nsSampleUnregistrationProc(nsIComponentManager *aCompMgr,
return NS_OK;
}
// For each class that wishes to support nsIClassInfo, add a line like this
NS_DECL_CLASSINFO(nsSampleImpl)
static nsModuleComponentInfo components[] =
{
{ "Sample Component", NS_SAMPLE_CID, NS_SAMPLE_CONTRACTID, nsSampleImplConstructor,
nsSampleRegistrationProc /* NULL if you dont need one */,
nsSampleUnregistrationProc /* NULL if you dont need one */
nsSampleUnregistrationProc /* NULL if you dont need one */,
NULL /* no factory destructor */,
NS_CI_INTERFACE_GETTER_NAME(nsSampleImpl),
NULL /* no language helper */,
&NS_CLASSINFO_NAME(nsSampleImpl)
}
};

View File

@@ -33,7 +33,8 @@
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
main()
int
main(void)
{
nsresult rv;

View File

@@ -36,9 +36,11 @@
#include "nsXPIDLString.h"
#include "nsIServiceManager.h"
struct nsModuleComponentInfo; // forward declaration
#define CMDLINEHANDLER_REGISTERPROC_DECLS \
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType); \
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation);
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info); \
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info);
#define CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\
NS_IMETHODIMP macro_class::GetDefaultArgs(PRUnichar **aDefaultArgs) \
@@ -87,7 +89,7 @@ NS_IMETHODIMP macro_class::GetOpenWindowWithArgs(PRBool *aOpenWindowWithArgs) \
*aOpenWindowWithArgs = macro_open_window_with_args; \
return NS_OK; \
} \
NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType) \
NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \
@@ -96,7 +98,7 @@ NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPat
rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_pretty_name, macro_contractid, PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); \
return NS_OK; \
} \
NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation) \
NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \

View File

@@ -36,9 +36,11 @@
#include "nsXPIDLString.h"
#include "nsIServiceManager.h"
struct nsModuleComponentInfo; // forward declaration
#define CMDLINEHANDLER_REGISTERPROC_DECLS \
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType); \
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation);
static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info); \
static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info);
#define CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\
NS_IMETHODIMP macro_class::GetDefaultArgs(PRUnichar **aDefaultArgs) \
@@ -87,7 +89,7 @@ NS_IMETHODIMP macro_class::GetOpenWindowWithArgs(PRBool *aOpenWindowWithArgs) \
*aOpenWindowWithArgs = macro_open_window_with_args; \
return NS_OK; \
} \
NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType) \
NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \
@@ -96,7 +98,7 @@ NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPat
rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_pretty_name, macro_contractid, PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); \
return NS_OK; \
} \
NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation) \
NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info) \
{ \
nsresult rv; \
nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \

View File

@@ -650,7 +650,8 @@ static NS_METHOD
RegisterSoftwareUpdate( nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType)
const char *componentType,
const nsModuleComponentInfo *info)
{
// get the registry
nsIRegistry* registry;