2010-06-10 22:11:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-10 22:11:11 +04:00
|
|
|
|
|
|
|
#ifndef mozilla_GenericModule_h
|
|
|
|
#define mozilla_GenericModule_h
|
|
|
|
|
2011-12-18 07:47:45 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-06-10 22:11:11 +04:00
|
|
|
#include "mozilla/Module.h"
|
|
|
|
|
|
|
|
#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
|
|
|
|
static nsresult \
|
|
|
|
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
|
|
|
|
void **aResult) \
|
|
|
|
{ \
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<_InstanceClass> inst; \
|
2010-06-10 22:11:11 +04:00
|
|
|
\
|
2013-10-11 00:41:00 +04:00
|
|
|
*aResult = nullptr; \
|
|
|
|
if (nullptr != aOuter) { \
|
2015-10-02 01:53:38 +03:00
|
|
|
return NS_ERROR_NO_AGGREGATION; \
|
2010-06-10 22:11:11 +04:00
|
|
|
} \
|
|
|
|
\
|
2010-07-05 13:42:18 +04:00
|
|
|
inst = new _InstanceClass(); \
|
2015-10-02 01:53:38 +03:00
|
|
|
return inst->QueryInterface(aIID, aResult); \
|
2010-06-10 22:11:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
|
|
|
|
static nsresult \
|
|
|
|
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
|
|
|
|
void **aResult) \
|
|
|
|
{ \
|
|
|
|
nsresult rv; \
|
|
|
|
\
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<_InstanceClass> inst; \
|
2010-06-10 22:11:11 +04:00
|
|
|
\
|
2013-10-11 00:41:00 +04:00
|
|
|
*aResult = nullptr; \
|
|
|
|
if (nullptr != aOuter) { \
|
2015-10-02 01:53:38 +03:00
|
|
|
return NS_ERROR_NO_AGGREGATION; \
|
2010-06-10 22:11:11 +04:00
|
|
|
} \
|
|
|
|
\
|
2010-07-05 13:42:18 +04:00
|
|
|
inst = new _InstanceClass(); \
|
2010-06-10 22:11:11 +04:00
|
|
|
rv = inst->_InitMethod(); \
|
|
|
|
if(NS_SUCCEEDED(rv)) { \
|
|
|
|
rv = inst->QueryInterface(aIID, aResult); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
return rv; \
|
|
|
|
}
|
|
|
|
|
|
|
|
// 'Constructor' that uses an existing getter function that gets a singleton.
|
|
|
|
// NOTE: assumes that getter does an AddRef - so additional AddRef is not done.
|
|
|
|
#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
|
|
|
|
static nsresult \
|
|
|
|
_InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \
|
|
|
|
void **aResult) \
|
|
|
|
{ \
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<_InstanceClass> inst; \
|
2010-06-10 22:11:11 +04:00
|
|
|
\
|
2013-10-11 00:41:00 +04:00
|
|
|
*aResult = nullptr; \
|
|
|
|
if (nullptr != aOuter) { \
|
2015-10-02 01:53:38 +03:00
|
|
|
return NS_ERROR_NO_AGGREGATION; \
|
2010-06-10 22:11:11 +04:00
|
|
|
} \
|
|
|
|
\
|
2015-10-02 01:53:38 +03:00
|
|
|
inst = already_AddRefed<_InstanceClass>(_GetterProc()); \
|
2013-10-11 00:41:00 +04:00
|
|
|
if (nullptr == inst) { \
|
2015-10-02 01:53:38 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY; \
|
2010-06-10 22:11:11 +04:00
|
|
|
} \
|
2015-10-02 01:53:38 +03:00
|
|
|
return inst->QueryInterface(aIID, aResult); \
|
2010-06-10 22:11:11 +04:00
|
|
|
}
|
|
|
|
|
2010-06-25 00:36:27 +04:00
|
|
|
#ifndef MOZILLA_INTERNAL_API
|
|
|
|
|
|
|
|
#include "nsIModule.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class GenericModule final : public nsIModule
|
2010-06-25 00:36:27 +04:00
|
|
|
{
|
2014-08-03 00:44:06 +04:00
|
|
|
~GenericModule() {}
|
2014-07-01 02:11:53 +04:00
|
|
|
|
2010-06-25 00:36:27 +04:00
|
|
|
public:
|
2014-08-03 00:44:06 +04:00
|
|
|
explicit GenericModule(const mozilla::Module* aData) : mData(aData) {}
|
2010-06-25 00:36:27 +04:00
|
|
|
|
2014-08-03 00:44:06 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIMODULE
|
2010-06-25 00:36:27 +04:00
|
|
|
|
|
|
|
private:
|
2014-08-03 00:44:06 +04:00
|
|
|
const mozilla::Module* mData;
|
2010-06-25 00:36:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-06-10 22:11:11 +04:00
|
|
|
#endif // mozilla_GenericModule_h
|