Bug 846687 - Set the transport as non-seekable if the server sends Accept-Ranges...
[gecko.git] / xpcom / components / ModuleUtils.h
blob5cb99e66a07f7163f6e1ad9aba5cdfbe2b9a6df7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/. */
6 #ifndef mozilla_GenericModule_h
7 #define mozilla_GenericModule_h
9 #include "mozilla/Attributes.h"
10 #include "mozilla/Module.h"
12 #define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
13 static nsresult \
14 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
15 void **aResult) \
16 { \
17 nsresult rv; \
19 _InstanceClass * inst; \
21 *aResult = NULL; \
22 if (NULL != aOuter) { \
23 rv = NS_ERROR_NO_AGGREGATION; \
24 return rv; \
25 } \
27 inst = new _InstanceClass(); \
28 if (NULL == inst) { \
29 rv = NS_ERROR_OUT_OF_MEMORY; \
30 return rv; \
31 } \
32 NS_ADDREF(inst); \
33 rv = inst->QueryInterface(aIID, aResult); \
34 NS_RELEASE(inst); \
36 return rv; \
39 #define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
40 static nsresult \
41 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
42 void **aResult) \
43 { \
44 nsresult rv; \
46 _InstanceClass * inst; \
48 *aResult = NULL; \
49 if (NULL != aOuter) { \
50 rv = NS_ERROR_NO_AGGREGATION; \
51 return rv; \
52 } \
54 inst = new _InstanceClass(); \
55 if (NULL == inst) { \
56 rv = NS_ERROR_OUT_OF_MEMORY; \
57 return rv; \
58 } \
59 NS_ADDREF(inst); \
60 rv = inst->_InitMethod(); \
61 if(NS_SUCCEEDED(rv)) { \
62 rv = inst->QueryInterface(aIID, aResult); \
63 } \
64 NS_RELEASE(inst); \
66 return rv; \
69 // 'Constructor' that uses an existing getter function that gets a singleton.
70 // NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
71 #define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
72 static nsresult \
73 _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
74 void **aResult) \
75 { \
76 nsresult rv; \
78 _InstanceClass * inst; \
80 *aResult = NULL; \
81 if (NULL != aOuter) { \
82 rv = NS_ERROR_NO_AGGREGATION; \
83 return rv; \
84 } \
86 inst = already_AddRefed<_InstanceClass>(_GetterProc()).get(); \
87 if (NULL == inst) { \
88 rv = NS_ERROR_OUT_OF_MEMORY; \
89 return rv; \
90 } \
91 /* NS_ADDREF(inst); */ \
92 rv = inst->QueryInterface(aIID, aResult); \
93 NS_RELEASE(inst); \
95 return rv; \
98 #ifndef MOZILLA_INTERNAL_API
100 #include "nsIModule.h"
101 #include "nsISupportsUtils.h"
103 namespace mozilla {
105 class GenericModule MOZ_FINAL : public nsIModule
107 public:
108 GenericModule(const mozilla::Module* aData)
109 : mData(aData)
113 NS_DECL_ISUPPORTS
114 NS_DECL_NSIMODULE
116 private:
117 const mozilla::Module* mData;
120 } // namespace mozilla
122 #define NS_IMPL_MOZILLA192_NSGETMODULE(module) \
123 extern "C" NS_EXPORT nsresult \
124 NSGetModule(nsIComponentManager* aCompMgr, \
125 nsIFile* aLocation, \
126 nsIModule** aResult) \
128 *aResult = new mozilla::GenericModule(module); \
129 NS_ADDREF(*aResult); \
130 return NS_OK; \
133 #endif
135 #endif // mozilla_GenericModule_h