|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef mozilla_Module_h |
|
7 #define mozilla_Module_h |
|
8 |
|
9 #include "nscore.h" |
|
10 #include "nsID.h" |
|
11 #include "nsIFactory.h" |
|
12 #include "nsCOMPtr.h" // for already_AddRefed |
|
13 |
|
14 namespace mozilla { |
|
15 |
|
16 /** |
|
17 * A module implements one or more XPCOM components. This structure is used |
|
18 * for both binary and script modules, but the registration members |
|
19 * (cids/contractids/categoryentries) are unused for modules which are loaded |
|
20 * via a module loader. |
|
21 */ |
|
22 struct Module |
|
23 { |
|
24 static const unsigned int kVersion = 31; |
|
25 |
|
26 struct CIDEntry; |
|
27 |
|
28 typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr) |
|
29 (const Module& module, const CIDEntry& entry); |
|
30 |
|
31 typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter, |
|
32 const nsIID& aIID, |
|
33 void** aResult); |
|
34 |
|
35 typedef nsresult (*LoadFuncPtr)(); |
|
36 typedef void (*UnloadFuncPtr)(); |
|
37 |
|
38 /** |
|
39 * This selector allows CIDEntrys to be marked so that they're only loaded |
|
40 * into certain kinds of processes. |
|
41 */ |
|
42 enum ProcessSelector |
|
43 { |
|
44 ANY_PROCESS = 0, |
|
45 MAIN_PROCESS_ONLY, |
|
46 CONTENT_PROCESS_ONLY |
|
47 }; |
|
48 |
|
49 /** |
|
50 * The constructor callback is an implementation detail of the default binary |
|
51 * loader and may be null. |
|
52 */ |
|
53 struct CIDEntry |
|
54 { |
|
55 const nsCID* cid; |
|
56 bool service; |
|
57 GetFactoryProcPtr getFactoryProc; |
|
58 ConstructorProcPtr constructorProc; |
|
59 ProcessSelector processSelector; |
|
60 }; |
|
61 |
|
62 struct ContractIDEntry |
|
63 { |
|
64 const char* contractid; |
|
65 nsID const * cid; |
|
66 ProcessSelector processSelector; |
|
67 }; |
|
68 |
|
69 struct CategoryEntry |
|
70 { |
|
71 const char* category; |
|
72 const char* entry; |
|
73 const char* value; |
|
74 }; |
|
75 |
|
76 /** |
|
77 * Binary compatibility check, should be kModuleVersion. |
|
78 */ |
|
79 unsigned int mVersion; |
|
80 |
|
81 /** |
|
82 * An array of CIDs (class IDs) implemented by this module. The final entry |
|
83 * should be { nullptr }. |
|
84 */ |
|
85 const CIDEntry* mCIDs; |
|
86 |
|
87 /** |
|
88 * An array of mappings from contractid to CID. The final entry should |
|
89 * be { nullptr }. |
|
90 */ |
|
91 const ContractIDEntry* mContractIDs; |
|
92 |
|
93 /** |
|
94 * An array of category manager entries. The final entry should be |
|
95 * { nullptr }. |
|
96 */ |
|
97 const CategoryEntry* mCategoryEntries; |
|
98 |
|
99 /** |
|
100 * When the component manager tries to get the factory for a CID, it first |
|
101 * checks for this module-level getfactory callback. If this function is |
|
102 * not implemented, it checks the CIDEntry getfactory callback. If that is |
|
103 * also nullptr, a generic factory is generated using the CIDEntry |
|
104 * constructor callback which must be non-nullptr. |
|
105 */ |
|
106 GetFactoryProcPtr getFactoryProc; |
|
107 |
|
108 /** |
|
109 * Optional Function which are called when this module is loaded and |
|
110 * at shutdown. These are not C++ constructor/destructors to avoid |
|
111 * calling them too early in startup or too late in shutdown. |
|
112 */ |
|
113 LoadFuncPtr loadProc; |
|
114 UnloadFuncPtr unloadProc; |
|
115 }; |
|
116 |
|
117 } // namespace |
|
118 |
|
119 #if defined(MOZILLA_INTERNAL_API) |
|
120 # define NSMODULE_NAME(_name) _name##_NSModule |
|
121 # define NSMODULE_DECL(_name) extern mozilla::Module const *const NSMODULE_NAME(_name) |
|
122 # define NSMODULE_DEFN(_name) NSMODULE_DECL(_name) |
|
123 #else |
|
124 # define NSMODULE_NAME(_name) NSModule |
|
125 # define NSMODULE_DEFN(_name) extern "C" NS_EXPORT mozilla::Module const *const NSModule |
|
126 #endif |
|
127 |
|
128 #endif // mozilla_Module_h |