Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsIGenericFactory.h File Reference
#include "nsIFactory.h"
#include "nsIModule.h"
#include "nsIClassInfo.h"

Go to the source code of this file.

Classes

class  nsIGenericFactory
 Provides a Generic nsIFactory implementation that can be used by DLLs with very simple factory needs. More...
struct  nsModuleComponentInfo
 nsModuleComponentInfo More...
struct  nsModuleInfo
 nsModuleInfo More...

Defines

#define NS_GENERICFACTORY_CID
#define NS_IGENERICFACTORY_IID
#define NS_GENERICFACTORY_CONTRACTID   "@mozilla.org/generic-factory;1"
#define NS_GENERICFACTORY_CLASSNAME   "Generic Factory"
#define NS_MODULEINFO_VERSION   0x00015000UL
 Rev this if you change the nsModuleInfo, and are worried about binary compatibility.
#define NSGETMODULE_ENTRY_POINT(_name)   extern "C" NS_EXPORT nsresult NSGetModule
#define NS_IMPL_NSGETMODULE(_name, _components)   NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, nsnull)
 Ease of use Macros which define NSGetModule for your component.
#define NS_IMPL_NSGETMODULE_WITH_CTOR(_name, _components, _ctor)   NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, nsnull)
#define NS_IMPL_NSGETMODULE_WITH_DTOR(_name, _components, _dtor)   NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, _dtor)
#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, _dtor)
#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass)
#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod)
#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc)

Typedefs

typedef NS_CALLBACKNSConstructorProcPtr )(nsISupports *aOuter, REFNSIID aIID, void **aResult)
 Component Callbacks.
typedef NS_CALLBACKNSRegisterSelfProcPtr )(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
 NSRegisterSelfProcPtr.
typedef NS_CALLBACKNSUnregisterSelfProcPtr )(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const nsModuleComponentInfo *aInfo)
 NSUnregisterSelfProcPtr.
typedef NS_CALLBACKNSFactoryDestructorProcPtr )(void)
 NSFactoryDestructorProcPtr.
typedef NS_CALLBACKNSGetInterfacesProcPtr )(PRUint32 *countp, nsIID ***array)
 NSGetInterfacesProcPtr.
typedef NS_CALLBACKNSGetLanguageHelperProcPtr )(PRUint32 language, nsISupports **helper)
 NSGetLanguageHelperProcPtr.

Functions

NS_COM_GLUE nsresult NS_NewGenericFactory (nsIGenericFactory **result, const nsModuleComponentInfo *info)
typedef nsresult (PR_CALLBACK *nsModuleConstructorProc)(nsIModule *self)
 Module Callbacks.
typedef void (PR_CALLBACK *nsModuleDestructorProc)(nsIModule *self)
 nsModuleDestructorProc
NS_COM_GLUE nsresult NS_NewGenericModule2 (nsModuleInfo const *info, nsIModule **result)
 Create a new generic module.
NS_COM_GLUE nsresult NS_NewGenericModule (const char *moduleName, PRUint32 componentCount, nsModuleComponentInfo *components, nsModuleDestructorProc dtor, nsIModule **result)
 Obsolete.

Class Documentation

struct nsModuleComponentInfo

nsModuleComponentInfo

Use this type to define a list of module component info to pass to NS_NewGenericModule.

Parameters:
mDescription: Class Name of given object
mCID: CID of given object
mContractID: Contract ID of given object
mConstructor: Constructor of given object
mRegisterSelfProc: (optional) Registration Callback
mUnregisterSelfProc: (optional) Unregistration Callback
mFactoryDestructor: (optional) Destruction Callback
mGetInterfacesProc: (optional) Interfaces Callback
mGetLanguageHelperProc: (optional) Language Helper Callback
mClassInfoGlobal: (optional) Global Class Info of given object
mFlags: (optional) Class Info Flags
See also:
nsIClassInfo

E.g.: static nsModuleComponentInfo components[] = { ... };

See xpcom/sample/nsSampleModule.cpp for more info.

Definition at line 231 of file nsIGenericFactory.h.

Collaboration diagram for nsModuleComponentInfo:
Class Members
nsCID mCID
nsIClassInfo ** mClassInfoGlobal
NSConstructorProcPtr mConstructor
const char * mContractID
const char * mDescription
NSFactoryDestructorProcPtr mFactoryDestructor
PRUint32 mFlags
NSGetInterfacesProcPtr mGetInterfacesProc
NSGetLanguageHelperProcPtr mGetLanguageHelperProc
NSRegisterSelfProcPtr mRegisterSelfProc
NSUnregisterSelfProcPtr mUnregisterSelfProc
struct nsModuleInfo

nsModuleInfo

Use this structure to define meta-information about the module itself, including the name, its components, and an optional module-level initialization or shutdown routine.

Parameters:
mVersion: Module Info Version
mModuleName: Module Name
mComponents: Array of Components
mCount: Count of mComponents
mCtor: Module user defined constructor
mDtor: Module user defined destructor

Definition at line 287 of file nsIGenericFactory.h.

Collaboration diagram for nsModuleInfo:
Class Members
const nsModuleComponentInfo * mComponents
PRUint32 mCount
nsModuleConstructorProc mCtor
nsModuleDestructorProc mDtor
const char * mModuleName
PRUint32 mVersion

Define Documentation

#define NS_GENERIC_FACTORY_CONSTRUCTOR (   _InstanceClass)
Value:
static NS_IMETHODIMP                                                          \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                            void **aResult)                                   \
{                                                                             \
    nsresult rv;                                                              \
                                                                              \
    _InstanceClass * inst;                                                    \
                                                                              \
    *aResult = NULL;                                                          \
    if (NULL != aOuter) {                                                     \
        rv = NS_ERROR_NO_AGGREGATION;                                         \
        return rv;                                                            \
    }                                                                         \
                                                                              \
    NS_NEWXPCOM(inst, _InstanceClass);                                        \
    if (NULL == inst) {                                                       \
        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
        return rv;                                                            \
    }                                                                         \
    NS_ADDREF(inst);                                                          \
    rv = inst->QueryInterface(aIID, aResult);                                 \
    NS_RELEASE(inst);                                                         \
                                                                              \
    return rv;                                                                \
}                                                                             \

Definition at line 360 of file nsIGenericFactory.h.

#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT (   _InstanceClass,
  _InitMethod 
)
Value:
static NS_IMETHODIMP                                                          \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                            void **aResult)                                   \
{                                                                             \
    nsresult rv;                                                              \
                                                                              \
    _InstanceClass * inst;                                                    \
                                                                              \
    *aResult = NULL;                                                          \
    if (NULL != aOuter) {                                                     \
        rv = NS_ERROR_NO_AGGREGATION;                                         \
        return rv;                                                            \
    }                                                                         \
                                                                              \
    NS_NEWXPCOM(inst, _InstanceClass);                                        \
    if (NULL == inst) {                                                       \
        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
        return rv;                                                            \
    }                                                                         \
    NS_ADDREF(inst);                                                          \
    rv = inst->_InitMethod();                                                 \
    if(NS_SUCCEEDED(rv)) {                                                    \
        rv = inst->QueryInterface(aIID, aResult);                             \
    }                                                                         \
    NS_RELEASE(inst);                                                         \
                                                                              \
    return rv;                                                                \
}                                                                             \

Definition at line 388 of file nsIGenericFactory.h.

#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR (   _InstanceClass,
  _GetterProc 
)
Value:
static NS_IMETHODIMP                                                          \
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID,               \
                            void **aResult)                                   \
{                                                                             \
    nsresult rv;                                                              \
                                                                              \
    _InstanceClass * inst;                                                    \
                                                                              \
    *aResult = NULL;                                                          \
    if (NULL != aOuter) {                                                     \
        rv = NS_ERROR_NO_AGGREGATION;                                         \
        return rv;                                                            \
    }                                                                         \
                                                                              \
    inst = _GetterProc();                                                     \
    if (NULL == inst) {                                                       \
        rv = NS_ERROR_OUT_OF_MEMORY;                                          \
        return rv;                                                            \
    }                                                                         \
    /* NS_ADDREF(inst); */                                                    \
    rv = inst->QueryInterface(aIID, aResult);                                 \
    NS_RELEASE(inst);                                                         \
                                                                              \
    return rv;                                                                \
}                                                                             \

Definition at line 420 of file nsIGenericFactory.h.

Value:
{ 0x3bc97f01, 0xccdf, 0x11d2,                                               \
    { 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }

Definition at line 50 of file nsIGenericFactory.h.

#define NS_GENERICFACTORY_CLASSNAME   "Generic Factory"

Definition at line 60 of file nsIGenericFactory.h.

#define NS_GENERICFACTORY_CONTRACTID   "@mozilla.org/generic-factory;1"

Definition at line 59 of file nsIGenericFactory.h.

Value:
{ 0x3bc97f00, 0xccdf, 0x11d2,                                               \
    { 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }

Definition at line 55 of file nsIGenericFactory.h.

#define NS_IMPL_NSGETMODULE (   _name,
  _components 
)    NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, nsnull)

Ease of use Macros which define NSGetModule for your component.

See xpcom/sample/nsSampleModule.cpp for more info.

Definition at line 332 of file nsIGenericFactory.h.

#define NS_IMPL_NSGETMODULE_WITH_CTOR (   _name,
  _components,
  _ctor 
)    NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, _ctor, nsnull)

Definition at line 335 of file nsIGenericFactory.h.

#define NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR (   _name,
  _components,
  _ctor,
  _dtor 
)
Value:
static nsModuleInfo const kModuleInfo = {                                     \
    NS_MODULEINFO_VERSION,                                                    \
    (#_name),                                                                 \
    (_components),                                                            \
    (sizeof(_components) / sizeof(_components[0])),                           \
    (_ctor),                                                                  \
    (_dtor)                                                                   \
};                                                                            \
NSGETMODULE_ENTRY_POINT(_name)                                                \
(nsIComponentManager *servMgr,                                                \
            nsIFile* location,                                                \
            nsIModule** result)                                               \
{                                                                             \
    return NS_NewGenericModule2(&kModuleInfo, result);                        \
}

Definition at line 341 of file nsIGenericFactory.h.

#define NS_IMPL_NSGETMODULE_WITH_DTOR (   _name,
  _components,
  _dtor 
)    NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, _dtor)

Definition at line 338 of file nsIGenericFactory.h.

#define NS_MODULEINFO_VERSION   0x00015000UL

Rev this if you change the nsModuleInfo, and are worried about binary compatibility.

(Ostensibly fix NS_NewGenericModule2() to deal with older rev's at the same time.)

Definition at line 301 of file nsIGenericFactory.h.

#define NSGETMODULE_ENTRY_POINT (   _name)    extern "C" NS_EXPORT nsresult NSGetModule

Definition at line 323 of file nsIGenericFactory.h.


Typedef Documentation

typedef NS_CALLBACK( NSConstructorProcPtr)(nsISupports *aOuter, REFNSIID aIID, void **aResult)

Component Callbacks.

NSConstructorProcPtr

This function will be used by the generic factory to create an instance of the given CID.

Parameters:
aOuter: Pointer to a component that wishes to be aggregated in the resulting instance. This will be nsnull if no aggregation is requested.
iid: The IID of the interface being requested in the component which is being currently created.
result: [out] Pointer to the newly created instance, if successful.
Returns:
NS_OK Component successfully created and the interface being requested was successfully returned in result. NS_NOINTERFACE Interface not accessible. NS_ERROR_NO_AGGREGATION if an 'outer' object is supplied, but the component is not aggregatable. NS_ERROR* Method failure.

Definition at line 103 of file nsIGenericFactory.h.

NSFactoryDestructorProcPtr.

This function will be called when the factory is being destroyed.

Definition at line 169 of file nsIGenericFactory.h.

NSGetInterfacesProcPtr.

This function is used to implement class info.

Get an ordered list of the interface ids that instances of the class promise to implement. Note that nsISupports is an implicit member of any such list and need not be included.

Should set *count = 0 and *array = null and return NS_OK if getting the list is not supported.

See also:
nsIClassInfo.idl

Definition at line 186 of file nsIGenericFactory.h.

typedef NS_CALLBACK( NSGetLanguageHelperProcPtr)(PRUint32 language, nsISupports **helper)

NSGetLanguageHelperProcPtr.

This function is used to implement class info.

Get a language mapping specific helper object that may assist in using objects of this class in a specific lanaguage. For instance, if asked for the helper for nsIProgrammingLanguage::JAVASCRIPT this might return an object that can be QI'd into the nsIXPCScriptable interface to assist XPConnect in supplying JavaScript specific behavior to callers of the instance object.

See also:
: nsIClassInfo.idl, nsIProgrammingLanguage.idl

Should return null if no helper available for given language.

Definition at line 205 of file nsIGenericFactory.h.

NSRegisterSelfProcPtr.

One time registration call back. Allows you to perform registration specific activity like adding yourself to a category.

Parameters:
aCompMgr: The global component manager
aFile: Component File. This file must have an associated loader and export the required symbols which this loader defines.
aLoaderStr: Opaque loader specific string. This value is passed into the nsIModule's registerSelf callback and must be fowarded unmodified when registering factories via their location.
aType: Component Type of CID aClass. This value is passed into the nsIModule's registerSelf callback and must be fowarded unmodified when registering factories via their location.
aInfo: Pointer to array of nsModuleComponentInfo
aInfo
Returns:
NS_OK Registration was successful. NS_ERROR* Method failure.

Definition at line 131 of file nsIGenericFactory.h.

NSUnregisterSelfProcPtr.

One time unregistration call back. Allows you to perform unregistration specific activity like removing yourself from a category.

Parameters:
aCompMgr: The global component manager
aFile: Component File. This file must have an associated loader and export the required symbols which this loader defines.
aLoaderStr: Opaque loader specific string. This value is passed into the nsIModule's registerSelf callback and must be fowarded unmodified when registering factories via their location
aInfo: Pointer to array of nsModuleComponentInfo
aInfo
Returns:
NS_OK Registration was successful. NS_ERROR* Method failure.

Definition at line 158 of file nsIGenericFactory.h.


Function Documentation

Definition at line 201 of file nsGenericFactory.cpp.

{
    nsresult rv;
    nsIGenericFactory* fact;
    rv = nsGenericFactory::Create(NULL, NS_GET_IID(nsIGenericFactory), (void**)&fact);
    if (NS_FAILED(rv)) return rv;
    rv = fact->SetComponentInfo(info);
    if (NS_FAILED(rv)) goto error;
    *result = fact;
    return rv;

  error:
    NS_RELEASE(fact);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_COM_GLUE nsresult NS_NewGenericModule ( const char *  moduleName,
PRUint32  componentCount,
nsModuleComponentInfo components,
nsModuleDestructorProc  dtor,
nsIModule **  result 
)

Obsolete.

Use NS_NewGenericModule2() instead.

Definition at line 496 of file nsGenericFactory.cpp.

{
    nsModuleInfo info;
    memset(&info, 0, sizeof(info));

    info.mVersion    = NS_MODULEINFO_VERSION;
    info.mModuleName = moduleName;
    info.mComponents = components;
    info.mCount      = componentCount;
    info.mDtor       = dtor;

    return NS_NewGenericModule2(&info, result);
}

Here is the call graph for this function:

Create a new generic module.

Use the NS_IMPL_NSGETMODULE macro, or one of its relatives, rather than using this directly.

Definition at line 478 of file nsGenericFactory.cpp.

{
    nsresult rv = NS_OK;

    // Create and initialize the module instance
    nsGenericModule *m = 
        new nsGenericModule(info->mModuleName, info->mCount, info->mComponents,
                            info->mCtor, info->mDtor);

    if (!m)
        return NS_ERROR_OUT_OF_MEMORY;

    // Increase refcnt and store away nsIModule interface to m in result
    NS_ADDREF(*result = m);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

typedef nsresult ( PR_CALLBACK nsGetModuleProc)

Module Callbacks.

nsModuleConstructorProc

This function is called when the module is first being constructed.

Parameters:
selfmodule which is being constructed.
Returns:
NS_OK Construction successful. NS_ERROR* Method failure which will result in module not being loaded.

Module Callbacks.

FROZEN

typedef void ( PR_CALLBACK nsModuleDestructorProc)

nsModuleDestructorProc

This function is called when the module is being destroyed.

Parameters:
selfmodule which is being destroyed.