зеркало из https://github.com/mozilla/gecko-dev.git
Remove files that have been repo-copied to xpcom/glue.
Bug #120474 r=dougt a=asa
This commit is contained in:
Родитель
4d465d4679
Коммит
c7bcd39c35
|
@ -1,67 +0,0 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __nsInterfaceRequestorUtils_h
|
||||
#define __nsInterfaceRequestorUtils_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// a type-safe shortcut for calling the |GetInterface()| member function
|
||||
// T must inherit from nsIInterfaceRequestor, but the cast may be ambiguous.
|
||||
template <class T, class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallGetInterface( T* aSource, DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->GetInterface(NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
class NS_EXPORT nsGetInterface : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsGetInterface( nsISupports* aSource, nsresult* error )
|
||||
: mSource(aSource),
|
||||
mErrorPtr(error)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult operator()( const nsIID&, void** ) const;
|
||||
virtual ~nsGetInterface() {};
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mSource;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
inline
|
||||
const nsGetInterface
|
||||
do_GetInterface( nsISupports* aSource, nsresult* error = 0 )
|
||||
{
|
||||
return nsGetInterface(aSource, error);
|
||||
}
|
||||
|
||||
#endif // __nsInterfaceRequestorUtils_h
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,275 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Scott Collins <scc@ScottCollins.net>
|
||||
* Dan Mosedale <dmose@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsISupportsUtils_h__
|
||||
#define nsISupportsUtils_h__
|
||||
|
||||
#ifndef nscore_h___
|
||||
#include "nscore.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsISupportsBase_h__
|
||||
#include "nsISupportsBase.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsError_h__
|
||||
#include "nsError.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsDebug_h___
|
||||
#include "nsDebug.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsISupportsImpl_h__
|
||||
#include "nsISupportsImpl.h"
|
||||
#endif
|
||||
|
||||
#ifndef nsISupportsObsolete_h__
|
||||
#include "nsISupportsObsolete.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for instantiating a new object that implements nsISupports.
|
||||
* Use this in your factory methods to allow for refcnt tracing.
|
||||
* Note that you can only use this if you adhere to the no arguments
|
||||
* constructor com policy (which you really should!).
|
||||
* @param _result Where the new instance pointer is stored
|
||||
* @param _type The type of object to call "new" with.
|
||||
*/
|
||||
#define NS_NEWXPCOM(_result,_type) \
|
||||
PR_BEGIN_MACRO \
|
||||
_result = new _type(); \
|
||||
NS_LOG_NEW_XPCOM(_result, #_type, sizeof(_type), __FILE__, __LINE__); \
|
||||
PR_END_MACRO
|
||||
|
||||
/**
|
||||
* Macro for deleting an object that implements nsISupports.
|
||||
* Use this in your Release methods to allow for refcnt tracing.
|
||||
* @param _ptr The object to delete.
|
||||
*/
|
||||
#define NS_DELETEXPCOM(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_LOG_DELETE_XPCOM((_ptr), __FILE__, __LINE__); \
|
||||
delete (_ptr); \
|
||||
PR_END_MACRO
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to an interface.
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#define NS_ADDREF(_ptr) \
|
||||
NS_LOG_ADDREF_CALL((_ptr), (_ptr)->AddRef(), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to this. This macro should be used
|
||||
* because NS_ADDREF (when tracing) may require an ambiguous cast
|
||||
* from the pointers primary type to nsISupports. This macro sidesteps
|
||||
* that entire problem.
|
||||
*/
|
||||
#define NS_ADDREF_THIS() \
|
||||
NS_LOG_ADDREF_CALL(this, AddRef(), __FILE__, __LINE__)
|
||||
|
||||
|
||||
extern "C++" {
|
||||
// ...because some one is accidentally including this file inside
|
||||
// an |extern "C"|
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
nsrefcnt
|
||||
ns_if_addref( T expr )
|
||||
// Making this a |inline| |template| allows |expr| to be evaluated only once,
|
||||
// yet still denies you the ability to |AddRef()| an |nsCOMPtr|.
|
||||
// Note that |NS_ADDREF()| already has this property in the non-logging case.
|
||||
{
|
||||
return expr ? expr->AddRef() : 0;
|
||||
}
|
||||
|
||||
} /* extern "C++" */
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to an interface that checks for NULL.
|
||||
* @param _expr The interface pointer.
|
||||
*/
|
||||
#ifdef NS_BUILD_REFCNT_LOGGING
|
||||
#define NS_IF_ADDREF(_expr) \
|
||||
((0 != (_expr)) \
|
||||
? NS_LOG_ADDREF_CALL((_expr), ns_if_addref(_expr), __FILE__, __LINE__) \
|
||||
: 0)
|
||||
#else
|
||||
#define NS_IF_ADDREF(_expr) ns_if_addref(_expr)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Given these declarations, it explicitly OK and (in the non-logging build) efficient
|
||||
* to end a `getter' with:
|
||||
*
|
||||
* NS_IF_ADDREF(*result = mThing);
|
||||
*
|
||||
* even if |mThing| is an |nsCOMPtr|. If |mThing| is an |nsCOMPtr|, however, it is still
|
||||
* _illegal_ to say |NS_IF_ADDREF(mThing)|.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface.
|
||||
*
|
||||
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#define NS_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(), __FILE__, __LINE__); \
|
||||
(_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface.
|
||||
*
|
||||
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#define NS_RELEASE_THIS() \
|
||||
NS_LOG_RELEASE_CALL(this, Release(), __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface, except that this
|
||||
* macro preserves the return value from the underlying Release call.
|
||||
* The interface pointer argument will only be NULLed if the reference count
|
||||
* goes to zero.
|
||||
*
|
||||
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#define NS_RELEASE2(_ptr,_rv) \
|
||||
PR_BEGIN_MACRO \
|
||||
_rv = NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(),__FILE__,__LINE__); \
|
||||
if (0 == (_rv)) (_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface that checks for NULL;
|
||||
*
|
||||
* Note that when NS_LOSING_ARCHITECTURE is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#define NS_IF_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
if (_ptr) { \
|
||||
NS_LOG_RELEASE_CALL((_ptr), (_ptr)->Release(), __FILE__, __LINE__); \
|
||||
(_ptr) = 0; \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
/*
|
||||
* Often you have to cast an implementation pointer, e.g., |this|, to an
|
||||
* |nsISupports*|, but because you have multiple inheritance, a simple cast
|
||||
* is ambiguous. One could simply say, e.g., (given a base |nsIBase|),
|
||||
* |NS_STATIC_CAST(nsIBase*, this)|; but that disguises the fact that what
|
||||
* you are really doing is disambiguating the |nsISupports|. You could make
|
||||
* that more obvious with a double cast, e.g., |NS_STATIC_CAST(nsISupports*,
|
||||
* NS_STATIC_CAST(nsIBase*, this))|, but that is bulky and harder to read...
|
||||
*
|
||||
* The following macro is clean, short, and obvious. In the example above,
|
||||
* you would use it like this: |NS_ISUPPORTS_CAST(nsIBase*, this)|.
|
||||
*/
|
||||
|
||||
#define NS_ISUPPORTS_CAST(__unambiguousBase, __expr) \
|
||||
NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(__unambiguousBase, __expr))
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C++" {
|
||||
// ...because some one is accidentally including this file inside
|
||||
// an |extern "C"|
|
||||
|
||||
class nsISupports;
|
||||
|
||||
template <class T>
|
||||
struct nsCOMTypeInfo
|
||||
{
|
||||
static const nsIID& GetIID() { return T::GetIID(); }
|
||||
};
|
||||
|
||||
NS_SPECIALIZE_TEMPLATE
|
||||
struct nsCOMTypeInfo<nsISupports>
|
||||
{
|
||||
static const nsIID& GetIID() {
|
||||
static const nsIID iid_NS_ISUPPORTS_IID = NS_ISUPPORTS_IID; return iid_NS_ISUPPORTS_IID;
|
||||
}
|
||||
};
|
||||
|
||||
#define NS_GET_IID(T) nsCOMTypeInfo<T>::GetIID()
|
||||
|
||||
// a type-safe shortcut for calling the |QueryInterface()| member function
|
||||
template <class T, class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallQueryInterface( T* aSource, DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->QueryInterface(NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
} // extern "C++"
|
||||
|
||||
#endif /* __nsISupportsUtils_h */
|
|
@ -1,162 +0,0 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott Collins <scc@mozilla.org> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIWeakReferenceUtils_h__
|
||||
#define nsIWeakReferenceUtils_h__
|
||||
|
||||
#ifndef nsCOMPtr_h__
|
||||
#include "nsCOMPtr.h"
|
||||
#endif
|
||||
|
||||
typedef nsCOMPtr<nsIWeakReference> nsWeakPtr;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
// a type-safe shortcut for calling the |QueryReferent()| member function
|
||||
// T must inherit from nsIWeakReference, but the cast may be ambiguous.
|
||||
template <class T, class DestinationType>
|
||||
inline
|
||||
nsresult
|
||||
CallQueryReferent( T* aSource, DestinationType** aDestination )
|
||||
{
|
||||
NS_PRECONDITION(aSource, "null parameter");
|
||||
NS_PRECONDITION(aDestination, "null parameter");
|
||||
|
||||
return aSource->QueryReferent(NS_GET_IID(DestinationType),
|
||||
NS_REINTERPRET_CAST(void**, aDestination));
|
||||
}
|
||||
|
||||
|
||||
class NS_EXPORT nsQueryReferent : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsQueryReferent( nsIWeakReference* aWeakPtr, nsresult* error )
|
||||
: mWeakPtr(aWeakPtr),
|
||||
mErrorPtr(error)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult operator()( const nsIID& aIID, void** ) const;
|
||||
|
||||
private:
|
||||
nsIWeakReference* mWeakPtr;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
inline
|
||||
const nsQueryReferent
|
||||
do_QueryReferent( nsIWeakReference* aRawPtr, nsresult* error = 0 )
|
||||
{
|
||||
return nsQueryReferent(aRawPtr, error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class NS_COM nsGetWeakReference : public nsCOMPtr_helper
|
||||
{
|
||||
public:
|
||||
nsGetWeakReference( nsISupports* aRawPtr, nsresult* error )
|
||||
: mRawPtr(aRawPtr),
|
||||
mErrorPtr(error)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
virtual nsresult operator()( const nsIID&, void** ) const;
|
||||
|
||||
private:
|
||||
nsISupports* mRawPtr;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
/**
|
||||
* |do_GetWeakReference| is a convenience function that bundles up all the work needed
|
||||
* to get a weak reference to an arbitrary object, i.e., the |QueryInterface|, test, and
|
||||
* call through to |GetWeakReference|, and put it into your |nsCOMPtr|.
|
||||
* It is specifically designed to cooperate with |nsCOMPtr| (or |nsWeakPtr|) like so:
|
||||
* |nsWeakPtr myWeakPtr = do_GetWeakReference(aPtr);|.
|
||||
*/
|
||||
inline
|
||||
const nsGetWeakReference
|
||||
do_GetWeakReference( nsISupports* aRawPtr, nsresult* error = 0 )
|
||||
{
|
||||
return nsGetWeakReference(aRawPtr, error);
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
do_GetWeakReference( nsIWeakReference* aRawPtr, nsresult* error = 0 )
|
||||
{
|
||||
// This signature exists soley to _stop_ you from doing a bad thing.
|
||||
// Saying |do_GetWeakReference()| on a weak reference itself,
|
||||
// is very likely to be a programmer error.
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
void
|
||||
do_GetWeakReference( already_AddRefed<T>& )
|
||||
{
|
||||
// This signature exists soley to _stop_ you from doing the bad thing.
|
||||
// Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by
|
||||
// someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>.
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
void
|
||||
do_GetWeakReference( already_AddRefed<T>&, nsresult* )
|
||||
{
|
||||
// This signature exists soley to _stop_ you from doing the bad thing.
|
||||
// Saying |do_GetWeakReference()| on a pointer that is not otherwise owned by
|
||||
// someone else is an automatic leak. See <http://bugzilla.mozilla.org/show_bug.cgi?id=8221>.
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Deprecated, use |do_GetWeakReference| instead.
|
||||
*/
|
||||
extern NS_COM
|
||||
nsIWeakReference*
|
||||
NS_GetWeakReference( nsISupports* , nsresult* aResult=0 );
|
||||
|
||||
#endif
|
|
@ -1,508 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
// DO NOT COPY THIS CODE INTO YOUR SOURCE! USE NS_IMPL_NSGETMODULE()
|
||||
|
||||
#include "nsGenericFactory.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
|
||||
nsGenericFactory::nsGenericFactory(const nsModuleComponentInfo *info)
|
||||
: mInfo(info)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
if (mInfo && mInfo->mClassInfoGlobal)
|
||||
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
|
||||
}
|
||||
|
||||
nsGenericFactory::~nsGenericFactory()
|
||||
{
|
||||
if (mInfo) {
|
||||
if (mInfo->mFactoryDestructor)
|
||||
mInfo->mFactoryDestructor();
|
||||
if (mInfo->mClassInfoGlobal)
|
||||
*mInfo->mClassInfoGlobal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsGenericFactory,
|
||||
nsIGenericFactory,
|
||||
nsIFactory,
|
||||
nsIClassInfo)
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (mInfo->mConstructor) {
|
||||
return mInfo->mConstructor(aOuter, aIID, aResult);
|
||||
}
|
||||
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// XXX do we care if (mInfo->mFlags & THREADSAFE)?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetInterfaces(PRUint32 *countp,
|
||||
nsIID* **array)
|
||||
{
|
||||
if (!mInfo->mGetInterfacesProc) {
|
||||
*countp = 0;
|
||||
*array = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return mInfo->mGetInterfacesProc(countp, array);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetHelperForLanguage(PRUint32 language,
|
||||
nsISupports **helper)
|
||||
{
|
||||
if (mInfo->mGetLanguageHelperProc)
|
||||
return mInfo->mGetLanguageHelperProc(language, helper);
|
||||
*helper = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetContractID(char **aContractID)
|
||||
{
|
||||
if (mInfo->mContractID) {
|
||||
*aContractID = (char *)nsMemory::Alloc(strlen(mInfo->mContractID) + 1);
|
||||
if (!*aContractID)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
strcpy(*aContractID, mInfo->mContractID);
|
||||
} else {
|
||||
*aContractID = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetClassDescription(char * *aClassDescription)
|
||||
{
|
||||
if (mInfo->mDescription) {
|
||||
*aClassDescription = (char *)
|
||||
nsMemory::Alloc(strlen(mInfo->mDescription) + 1);
|
||||
if (!*aClassDescription)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
strcpy(*aClassDescription, mInfo->mDescription);
|
||||
} else {
|
||||
*aClassDescription = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetClassID(nsCID * *aClassID)
|
||||
{
|
||||
*aClassID =
|
||||
NS_REINTERPRET_CAST(nsCID*,
|
||||
nsMemory::Clone(&mInfo->mCID, sizeof mInfo->mCID));
|
||||
if (! *aClassID)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetClassIDNoAlloc(nsCID *aClassID)
|
||||
{
|
||||
*aClassID = mInfo->mCID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetImplementationLanguage(PRUint32 *langp)
|
||||
{
|
||||
*langp = nsIProgrammingLanguage::CPLUSPLUS;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetFlags(PRUint32 *flagsp)
|
||||
{
|
||||
*flagsp = mInfo->mFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIGenericFactory: component-info accessors
|
||||
NS_IMETHODIMP nsGenericFactory::SetComponentInfo(const nsModuleComponentInfo *info)
|
||||
{
|
||||
if (mInfo && mInfo->mClassInfoGlobal)
|
||||
*mInfo->mClassInfoGlobal = 0;
|
||||
mInfo = info;
|
||||
if (mInfo && mInfo->mClassInfoGlobal)
|
||||
*mInfo->mClassInfoGlobal = NS_STATIC_CAST(nsIClassInfo *, this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::GetComponentInfo(const nsModuleComponentInfo **infop)
|
||||
{
|
||||
*infop = mInfo;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
// sorry, aggregation not spoken here.
|
||||
nsresult res = NS_ERROR_NO_AGGREGATION;
|
||||
if (outer == NULL) {
|
||||
nsGenericFactory* factory = new nsGenericFactory;
|
||||
if (factory != NULL) {
|
||||
res = factory->QueryInterface(aIID, aInstancePtr);
|
||||
if (res != NS_OK)
|
||||
delete factory;
|
||||
} else {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewGenericFactory(nsIGenericFactory* *result,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsGenericModule::nsGenericModule(const char* moduleName, PRUint32 componentCount,
|
||||
const nsModuleComponentInfo* components,
|
||||
nsModuleConstructorProc ctor,
|
||||
nsModuleDestructorProc dtor)
|
||||
: mInitialized(PR_FALSE),
|
||||
mModuleName(moduleName),
|
||||
mComponentCount(componentCount),
|
||||
mComponents(components),
|
||||
mFactoriesNotToBeRegistered(nsnull),
|
||||
mCtor(ctor),
|
||||
mDtor(dtor)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsGenericModule::~nsGenericModule()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsGenericModule, nsIModule)
|
||||
|
||||
nsresult
|
||||
nsGenericModule::AddFactoryNode(nsIGenericFactory* fact)
|
||||
{
|
||||
if (!fact)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
FactoryNode *node = new FactoryNode(fact, mFactoriesNotToBeRegistered);
|
||||
if (!node)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mFactoriesNotToBeRegistered = node;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Perform our one-time intialization for this module
|
||||
nsresult
|
||||
nsGenericModule::Initialize(nsIComponentManager *compMgr)
|
||||
{
|
||||
if (mInitialized) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mCtor) {
|
||||
nsresult rv = mCtor(this);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(compMgr, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// Eagerly populate factory/class object hash for entries
|
||||
// without constructors. If we didn't, the class object would
|
||||
// never get created. Also create the factory, which doubles
|
||||
// as the class object, if the EAGER_CLASSINFO flag was given.
|
||||
// This allows objects to be created (within their modules)
|
||||
// via operator new rather than CreateInstance, yet still be
|
||||
// QI'able to nsIClassInfo.
|
||||
const nsModuleComponentInfo* desc = mComponents;
|
||||
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
||||
if (!desc->mConstructor ||
|
||||
(desc->mFlags & nsIClassInfo::EAGER_CLASSINFO)) {
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
nsresult rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// if we don't have a mConstructor, then we should not populate
|
||||
// the component manager.
|
||||
if (!desc->mConstructor) {
|
||||
rv = AddFactoryNode(fact);
|
||||
} else {
|
||||
rv = registrar->RegisterFactory(desc->mCID,
|
||||
desc->mDescription,
|
||||
desc->mContractID,
|
||||
fact);
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
desc++;
|
||||
}
|
||||
|
||||
mInitialized = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Shutdown this module, releasing all of the module resources
|
||||
void
|
||||
nsGenericModule::Shutdown()
|
||||
{
|
||||
// Free cached factories that were not registered.
|
||||
FactoryNode* node;
|
||||
while (mFactoriesNotToBeRegistered)
|
||||
{
|
||||
node = mFactoriesNotToBeRegistered->mNext;
|
||||
delete mFactoriesNotToBeRegistered;
|
||||
mFactoriesNotToBeRegistered = node;
|
||||
}
|
||||
|
||||
if (mInitialized) {
|
||||
mInitialized = PR_FALSE;
|
||||
|
||||
if (mDtor)
|
||||
mDtor(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a factory object for creating instances of aClass.
|
||||
NS_IMETHODIMP
|
||||
nsGenericModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||
const nsCID& aClass,
|
||||
const nsIID& aIID,
|
||||
void** r_classObj)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Defensive programming: Initialize *r_classObj in case of error below
|
||||
if (!r_classObj) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*r_classObj = NULL;
|
||||
|
||||
// Do one-time-only initialization if necessary
|
||||
if (!mInitialized) {
|
||||
rv = Initialize(aCompMgr);
|
||||
if (NS_FAILED(rv)) {
|
||||
// Initialization failed! yikes!
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Choose the appropriate factory, based on the desired instance
|
||||
// class type (aClass).
|
||||
const nsModuleComponentInfo* desc = mComponents;
|
||||
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
||||
if (desc->mCID.Equals(aClass)) {
|
||||
nsCOMPtr<nsIGenericFactory> fact;
|
||||
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return fact->QueryInterface(aIID, r_classObj);
|
||||
}
|
||||
desc++;
|
||||
}
|
||||
// not found in descriptions
|
||||
#ifdef DEBUG
|
||||
char* cs = aClass.ToString();
|
||||
printf("+++ nsGenericModule %s: unable to create factory for %s\n", mModuleName, cs);
|
||||
// leak until we resolve the nsID Allocator.
|
||||
// nsCRT::free(cs);
|
||||
#endif // XXX put in stop-gap so that we don't search for this one again
|
||||
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericModule::RegisterSelf(nsIComponentManager *aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* registryLocation,
|
||||
const char* componentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("*** Registering %s components (all right -- a generic module!)\n", mModuleName);
|
||||
#endif
|
||||
|
||||
const nsModuleComponentInfo* cp = mComponents;
|
||||
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
||||
// Register the component only if it has a constructor
|
||||
if (cp->mConstructor) {
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
||||
if (registrar)
|
||||
rv = registrar->RegisterFactoryLocation(cp->mCID,
|
||||
cp->mDescription,
|
||||
cp->mContractID,
|
||||
aPath,
|
||||
registryLocation,
|
||||
componentType);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsGenericModule %s: unable to register %s component => %x\n",
|
||||
mModuleName?mModuleName:"(null)", cp->mDescription?cp->mDescription:"(null)", rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Call the registration hook of the component, if any
|
||||
if (cp->mRegisterSelfProc)
|
||||
{
|
||||
rv = cp->mRegisterSelfProc(aCompMgr, aPath, registryLocation,
|
||||
componentType, cp);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsGenericModule %s: Register hook for %s component returned error => %x\n",
|
||||
mModuleName?mModuleName:"(null)", cp->mDescription?cp->mDescription:"(null)", rv);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericModule::UnregisterSelf(nsIComponentManager* aCompMgr,
|
||||
nsIFile* aPath,
|
||||
const char* registryLocation)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("*** Unregistering %s components (all right -- a generic module!)\n", mModuleName);
|
||||
#endif
|
||||
const nsModuleComponentInfo* cp = mComponents;
|
||||
for (PRUint32 i = 0; i < mComponentCount; i++) {
|
||||
// Call the unregistration hook of the component, if any
|
||||
if (cp->mUnregisterSelfProc)
|
||||
{
|
||||
cp->mUnregisterSelfProc(aCompMgr, aPath, registryLocation, cp);
|
||||
}
|
||||
|
||||
// Unregister the component
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(aCompMgr, &rv);
|
||||
if (registrar)
|
||||
rv = registrar->UnregisterFactoryLocation(cp->mCID, aPath);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG
|
||||
printf("nsGenericModule %s: unable to unregister %s component => %x\n",
|
||||
mModuleName, cp->mDescription, rv);
|
||||
#endif
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
|
||||
{
|
||||
if (!okToUnload) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
*okToUnload = PR_FALSE;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewGenericModule2(nsModuleInfo* info, nsIModule* *result)
|
||||
{
|
||||
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 return_cobj
|
||||
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)result);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete m;
|
||||
m = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewGenericModule(const char* moduleName,
|
||||
PRUint32 componentCount,
|
||||
nsModuleComponentInfo* components,
|
||||
nsModuleDestructorProc dtor,
|
||||
nsIModule* *result)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,124 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsGenericFactory_h___
|
||||
#define nsGenericFactory_h___
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIClassInfo.h"
|
||||
|
||||
/**
|
||||
* Most factories follow this simple pattern, so why not just use a function
|
||||
* pointer for most creation operations?
|
||||
*/
|
||||
class nsGenericFactory : public nsIGenericFactory, public nsIClassInfo {
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR(NS_GENERICFACTORY_CID);
|
||||
|
||||
nsGenericFactory(const nsModuleComponentInfo *info = NULL);
|
||||
virtual ~nsGenericFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICLASSINFO
|
||||
|
||||
/* nsIGenericFactory methods */
|
||||
NS_IMETHOD SetComponentInfo(const nsModuleComponentInfo *info);
|
||||
NS_IMETHOD GetComponentInfo(const nsModuleComponentInfo **infop);
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
private:
|
||||
const nsModuleComponentInfo *mInfo;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "plhash.h"
|
||||
|
||||
class nsGenericModule : public nsIModule
|
||||
{
|
||||
public:
|
||||
nsGenericModule(const char* moduleName,
|
||||
PRUint32 componentCount,
|
||||
const nsModuleComponentInfo* components,
|
||||
nsModuleConstructorProc ctor,
|
||||
nsModuleDestructorProc dtor);
|
||||
|
||||
virtual ~nsGenericModule();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMODULE
|
||||
|
||||
struct FactoryNode
|
||||
{
|
||||
FactoryNode(nsIGenericFactory* fact, FactoryNode* next)
|
||||
{
|
||||
mFactory = fact;
|
||||
mNext = next;
|
||||
}
|
||||
~FactoryNode(){}
|
||||
|
||||
nsCOMPtr<nsIGenericFactory> mFactory;
|
||||
FactoryNode* mNext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
nsresult Initialize(nsIComponentManager* compMgr);
|
||||
|
||||
void Shutdown();
|
||||
nsresult AddFactoryNode(nsIGenericFactory* fact);
|
||||
|
||||
PRBool mInitialized;
|
||||
const char* mModuleName;
|
||||
PRUint32 mComponentCount;
|
||||
const nsModuleComponentInfo* mComponents;
|
||||
FactoryNode* mFactoriesNotToBeRegistered;
|
||||
nsModuleConstructorProc mCtor;
|
||||
nsModuleDestructorProc mDtor;
|
||||
};
|
||||
|
||||
#endif /* nsGenericFactory_h___ */
|
||||
|
|
@ -1,445 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIGenericFactory_h___
|
||||
#define nsIGenericFactory_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIModule.h"
|
||||
|
||||
// {3bc97f01-ccdf-11d2-bab8-b548654461fc}
|
||||
#define NS_GENERICFACTORY_CID \
|
||||
{ 0x3bc97f01, 0xccdf, 0x11d2, \
|
||||
{ 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }
|
||||
|
||||
// {3bc97f00-ccdf-11d2-bab8-b548654461fc}
|
||||
#define NS_IGENERICFACTORY_IID \
|
||||
{ 0x3bc97f00, 0xccdf, 0x11d2, \
|
||||
{ 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }
|
||||
|
||||
#define NS_GENERICFACTORY_CONTRACTID "@mozilla.org/generic-factory;1"
|
||||
#define NS_GENERICFACTORY_CLASSNAME "Generic Factory"
|
||||
|
||||
struct nsModuleComponentInfo; // forward declaration
|
||||
|
||||
/**
|
||||
* Provides a Generic nsIFactory implementation that can be used by
|
||||
* DLLs with very simple factory needs.
|
||||
*/
|
||||
class nsIGenericFactory : public nsIFactory {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IGENERICFACTORY_IID)
|
||||
|
||||
NS_IMETHOD SetComponentInfo(const nsModuleComponentInfo *info) = 0;
|
||||
NS_IMETHOD GetComponentInfo(const nsModuleComponentInfo **infop) = 0;
|
||||
};
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_NewGenericFactory(nsIGenericFactory **result,
|
||||
const nsModuleComponentInfo *info);
|
||||
|
||||
|
||||
/** Component Callbacks **/
|
||||
|
||||
/**
|
||||
* NSConstructorProcPtr
|
||||
*
|
||||
* This function will be used by the generic factory to create an
|
||||
* instance of the given CID.
|
||||
*
|
||||
* @param aOuter : Pointer to a component that wishes to be aggregated
|
||||
* in the resulting instance. This will be nsnull if no
|
||||
* aggregation is requested.
|
||||
* @param iid : The IID of the interface being requested in
|
||||
* the component which is being currently created.
|
||||
* @param result : [out] Pointer to the newly created instance, if successful.
|
||||
*
|
||||
* @return 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.
|
||||
**/
|
||||
typedef NS_CALLBACK(NSConstructorProcPtr)(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
/**
|
||||
* NSRegisterSelfProcPtr
|
||||
*
|
||||
* One time registration call back. Allows you to perform registration
|
||||
* specific activity like adding yourself to a category.
|
||||
*
|
||||
* @param aCompMgr : The global component manager
|
||||
* @param aFile : Component File. This file must have an associated
|
||||
* loader and export the required symbols which this
|
||||
* loader defines.
|
||||
* @param 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.
|
||||
* @param 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.
|
||||
* @param aInfo : Pointer to array of nsModuleComponentInfo
|
||||
*
|
||||
* @param aInfo
|
||||
* @return NS_OK Registration was successful.
|
||||
* NS_ERROR* Method failure.
|
||||
**/
|
||||
typedef NS_CALLBACK(NSRegisterSelfProcPtr)(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *aLoaderStr,
|
||||
const char *aType,
|
||||
const nsModuleComponentInfo *aInfo);
|
||||
|
||||
/**
|
||||
* NSUnregisterSelfProcPtr
|
||||
*
|
||||
* One time unregistration call back. Allows you to perform unregistration
|
||||
* specific activity like removing yourself from a category.
|
||||
*
|
||||
* @param aCompMgr : The global component manager
|
||||
* @param aFile : Component File. This file must have an associated
|
||||
* loader and export the required symbols which this
|
||||
* loader defines.
|
||||
* @param 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
|
||||
* @param aInfo : Pointer to array of nsModuleComponentInfo
|
||||
*
|
||||
* @param aInfo
|
||||
* @return NS_OK Registration was successful.
|
||||
* NS_ERROR* Method failure.
|
||||
|
||||
**/
|
||||
typedef NS_CALLBACK(NSUnregisterSelfProcPtr)(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath,
|
||||
const char *aLoaderStr,
|
||||
const nsModuleComponentInfo *aInfo);
|
||||
|
||||
/**
|
||||
* NSFactoryDestructorProcPtr
|
||||
*
|
||||
* This function will be called when the factory is being destroyed.
|
||||
*
|
||||
**/
|
||||
typedef NS_CALLBACK(NSFactoryDestructorProcPtr)(void);
|
||||
|
||||
|
||||
/**
|
||||
* 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 nsIClassInfo.idl
|
||||
**/
|
||||
typedef NS_CALLBACK(NSGetInterfacesProcPtr)(PRUint32 *countp,
|
||||
nsIID* **array);
|
||||
|
||||
/**
|
||||
* 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: nsIClassInfo.idl, nsIProgrammingLanguage.idl
|
||||
*
|
||||
* Should return null if no helper available for given language.
|
||||
**/
|
||||
typedef NS_CALLBACK(NSGetLanguageHelperProcPtr)(PRUint32 language,
|
||||
nsISupports **helper);
|
||||
|
||||
/**
|
||||
* nsModuleComponentInfo
|
||||
*
|
||||
* Use this type to define a list of module component info to pass to
|
||||
* NS_NewGenericModule.
|
||||
*
|
||||
* @param mDescription : Class Name of given object
|
||||
* @param mCID : CID of given object
|
||||
* @param mContractID : Contract ID of given object
|
||||
* @param mConstructor : Constructor of given object
|
||||
* @param mRegisterSelfProc : (optional) Registration Callback
|
||||
* @param mUnregisterSelfProc : (optional) Unregistration Callback
|
||||
* @param mFactoryDestructor : (optional) Destruction Callback
|
||||
* @param mGetInterfacesProc : (optional) Interfaces Callback
|
||||
* @param mGetLanguageHelperProc : (optional) Language Helper Callback
|
||||
* @param mClassInfoGlobal : (optional) Global Class Info of given object
|
||||
* @param mFlags : (optional) Class Info Flags @see nsIClassInfo
|
||||
*
|
||||
* E.g.:
|
||||
* static nsModuleComponentInfo components[] = { ... };
|
||||
*
|
||||
* See xpcom/sample/nsSampleModule.cpp for more info.
|
||||
*/
|
||||
struct nsModuleComponentInfo {
|
||||
const char* mDescription;
|
||||
nsCID mCID;
|
||||
const char* mContractID;
|
||||
NSConstructorProcPtr mConstructor;
|
||||
NSRegisterSelfProcPtr mRegisterSelfProc;
|
||||
NSUnregisterSelfProcPtr mUnregisterSelfProc;
|
||||
NSFactoryDestructorProcPtr mFactoryDestructor;
|
||||
NSGetInterfacesProcPtr mGetInterfacesProc;
|
||||
NSGetLanguageHelperProcPtr mGetLanguageHelperProc;
|
||||
nsIClassInfo ** mClassInfoGlobal;
|
||||
PRUint32 mFlags;
|
||||
};
|
||||
|
||||
|
||||
/** Module Callbacks **/
|
||||
|
||||
|
||||
/**
|
||||
* nsModuleConstructorProc
|
||||
*
|
||||
* This function is called when the module is first being constructed.
|
||||
* @param self module which is being constructed.
|
||||
*
|
||||
* @return NS_OK Construction successful.
|
||||
* NS_ERROR* Method failure which will result in module not being
|
||||
* loaded.
|
||||
**/
|
||||
typedef nsresult (PR_CALLBACK *nsModuleConstructorProc) (nsIModule *self);
|
||||
|
||||
|
||||
/**
|
||||
* nsModuleDestructorProc
|
||||
*
|
||||
* This function is called when the module is being destroyed.
|
||||
* @param self module which is being destroyed.
|
||||
*
|
||||
**/
|
||||
typedef void (PR_CALLBACK *nsModuleDestructorProc) (nsIModule *self);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param mVersion : Module Info Version
|
||||
* @param mModuleName : Module Name
|
||||
* @param mComponents : Array of Components
|
||||
* @param mCount : Count of mComponents
|
||||
* @param mCtor : Module user defined constructor
|
||||
* @param mDtor : Module user defined destructor
|
||||
*
|
||||
**/
|
||||
|
||||
struct nsModuleInfo {
|
||||
PRUint32 mVersion;
|
||||
const char* mModuleName;
|
||||
const nsModuleComponentInfo* mComponents;
|
||||
PRUint32 mCount;
|
||||
nsModuleConstructorProc mCtor;
|
||||
nsModuleDestructorProc mDtor;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.)
|
||||
*/
|
||||
#define NS_MODULEINFO_VERSION 0x00010000UL // 1.0
|
||||
|
||||
/**
|
||||
* Create a new generic module. Use the NS_IMPL_NSGETMODULE macro, or
|
||||
* one of its relatives, rather than using this directly.
|
||||
*/
|
||||
extern NS_COM nsresult
|
||||
NS_NewGenericModule2(nsModuleInfo *info, nsIModule* *result);
|
||||
|
||||
/**
|
||||
* Obsolete. Use NS_NewGenericModule2() instead.
|
||||
*/
|
||||
extern NS_COM nsresult
|
||||
NS_NewGenericModule(const char* moduleName,
|
||||
PRUint32 componentCount,
|
||||
nsModuleComponentInfo* components,
|
||||
nsModuleDestructorProc dtor,
|
||||
nsIModule* *result);
|
||||
|
||||
#if defined(XPCOM_TRANSLATE_NSGM_ENTRY_POINT)
|
||||
# define NSMODULEINFO(_name) _name##_gModuleInfo
|
||||
# define NSGETMODULE_ENTRY_POINT(_info)
|
||||
#else
|
||||
# define NSMODULEINFO(_name) gModuleInfo
|
||||
# define NSGETMODULE_ENTRY_POINT(_info) \
|
||||
extern "C" NS_EXPORT nsresult \
|
||||
NSGetModule(nsIComponentManager *servMgr, \
|
||||
nsIFile* location, \
|
||||
nsIModule** result) \
|
||||
{ \
|
||||
return NS_NewGenericModule2(&(_info), result); \
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Ease of use Macros which define NSGetModule for your component.
|
||||
* See xpcom/sample/nsSampleModule.cpp for more info.
|
||||
*
|
||||
**/
|
||||
|
||||
#define NS_IMPL_NSGETMODULE(_name, _components) \
|
||||
NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(_name, _components, nsnull, nsnull)
|
||||
|
||||
#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) \
|
||||
nsModuleInfo NSMODULEINFO(_name) = { \
|
||||
NS_MODULEINFO_VERSION, \
|
||||
(#_name), \
|
||||
(_components), \
|
||||
(sizeof(_components) / sizeof(_components[0])), \
|
||||
(_ctor), \
|
||||
(_dtor) \
|
||||
}; \
|
||||
NSGETMODULE_ENTRY_POINT(NSMODULEINFO(_name))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
|
||||
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; \
|
||||
} \
|
||||
|
||||
|
||||
#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
|
||||
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; \
|
||||
} \
|
||||
|
||||
// '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 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; \
|
||||
} \
|
||||
|
||||
#endif /* nsIGenericFactory_h___ */
|
Загрузка…
Ссылка в новой задаче