michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_Module_h michael@0: #define mozilla_Module_h michael@0: michael@0: #include "nscore.h" michael@0: #include "nsID.h" michael@0: #include "nsIFactory.h" michael@0: #include "nsCOMPtr.h" // for already_AddRefed michael@0: michael@0: namespace mozilla { michael@0: michael@0: /** michael@0: * A module implements one or more XPCOM components. This structure is used michael@0: * for both binary and script modules, but the registration members michael@0: * (cids/contractids/categoryentries) are unused for modules which are loaded michael@0: * via a module loader. michael@0: */ michael@0: struct Module michael@0: { michael@0: static const unsigned int kVersion = 31; michael@0: michael@0: struct CIDEntry; michael@0: michael@0: typedef already_AddRefed (*GetFactoryProcPtr) michael@0: (const Module& module, const CIDEntry& entry); michael@0: michael@0: typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter, michael@0: const nsIID& aIID, michael@0: void** aResult); michael@0: michael@0: typedef nsresult (*LoadFuncPtr)(); michael@0: typedef void (*UnloadFuncPtr)(); michael@0: michael@0: /** michael@0: * This selector allows CIDEntrys to be marked so that they're only loaded michael@0: * into certain kinds of processes. michael@0: */ michael@0: enum ProcessSelector michael@0: { michael@0: ANY_PROCESS = 0, michael@0: MAIN_PROCESS_ONLY, michael@0: CONTENT_PROCESS_ONLY michael@0: }; michael@0: michael@0: /** michael@0: * The constructor callback is an implementation detail of the default binary michael@0: * loader and may be null. michael@0: */ michael@0: struct CIDEntry michael@0: { michael@0: const nsCID* cid; michael@0: bool service; michael@0: GetFactoryProcPtr getFactoryProc; michael@0: ConstructorProcPtr constructorProc; michael@0: ProcessSelector processSelector; michael@0: }; michael@0: michael@0: struct ContractIDEntry michael@0: { michael@0: const char* contractid; michael@0: nsID const * cid; michael@0: ProcessSelector processSelector; michael@0: }; michael@0: michael@0: struct CategoryEntry michael@0: { michael@0: const char* category; michael@0: const char* entry; michael@0: const char* value; michael@0: }; michael@0: michael@0: /** michael@0: * Binary compatibility check, should be kModuleVersion. michael@0: */ michael@0: unsigned int mVersion; michael@0: michael@0: /** michael@0: * An array of CIDs (class IDs) implemented by this module. The final entry michael@0: * should be { nullptr }. michael@0: */ michael@0: const CIDEntry* mCIDs; michael@0: michael@0: /** michael@0: * An array of mappings from contractid to CID. The final entry should michael@0: * be { nullptr }. michael@0: */ michael@0: const ContractIDEntry* mContractIDs; michael@0: michael@0: /** michael@0: * An array of category manager entries. The final entry should be michael@0: * { nullptr }. michael@0: */ michael@0: const CategoryEntry* mCategoryEntries; michael@0: michael@0: /** michael@0: * When the component manager tries to get the factory for a CID, it first michael@0: * checks for this module-level getfactory callback. If this function is michael@0: * not implemented, it checks the CIDEntry getfactory callback. If that is michael@0: * also nullptr, a generic factory is generated using the CIDEntry michael@0: * constructor callback which must be non-nullptr. michael@0: */ michael@0: GetFactoryProcPtr getFactoryProc; michael@0: michael@0: /** michael@0: * Optional Function which are called when this module is loaded and michael@0: * at shutdown. These are not C++ constructor/destructors to avoid michael@0: * calling them too early in startup or too late in shutdown. michael@0: */ michael@0: LoadFuncPtr loadProc; michael@0: UnloadFuncPtr unloadProc; michael@0: }; michael@0: michael@0: } // namespace michael@0: michael@0: #if defined(MOZILLA_INTERNAL_API) michael@0: # define NSMODULE_NAME(_name) _name##_NSModule michael@0: # define NSMODULE_DECL(_name) extern mozilla::Module const *const NSMODULE_NAME(_name) michael@0: # define NSMODULE_DEFN(_name) NSMODULE_DECL(_name) michael@0: #else michael@0: # define NSMODULE_NAME(_name) NSModule michael@0: # define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule michael@0: #endif michael@0: michael@0: #endif // mozilla_Module_h