Added |do_CreateInstance()|, |do_GetService()| both by CID and ProgID. See bugs #17364, #17448. r={travis, dp}

This commit is contained in:
scc%netscape.com 1999-11-10 00:14:54 +00:00
Родитель fbad7d4b14
Коммит 49bd71ade0
5 изменённых файлов: 231 добавлений и 4 удалений

Просмотреть файл

@ -96,13 +96,23 @@ static NS_DEFINE_CID(kNoCID, NS_NO_CID);
nsresult
nsCreateInstance::operator()( const nsIID& aIID, void** answer ) const
nsCreateInstanceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status = nsComponentManager::CreateInstance(mCID, mOuter, aIID, aInstancePtr);
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
nsresult
nsCreateInstanceByProgID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status;
if ( mFactory )
status = mFactory->CreateInstance(mOuter, aIID, answer);
if ( mProgID )
status = nsComponentManager::CreateInstance(mProgID, mOuter, aIID, aInstancePtr);
else
status = NS_ERROR_NULL_POINTER;
status = NS_ERROR_NULL_POINTER;
if ( mErrorPtr )
*mErrorPtr = status;

Просмотреть файл

@ -19,6 +19,10 @@
#ifndef nsComponentManagerUtils_h__
#define nsComponentManagerUtils_h__
#ifndef nsCOMPtr_h__
#include "nsCOMPtr.h"
#endif
#ifndef OBSOLETE_MODULE_LOADING
/*
* Prototypes for dynamic library export functions. Your DLL/DSO needs to export
@ -171,6 +175,73 @@ public:
};
class NS_EXPORT nsCreateInstanceByCID : public nsCOMPtr_helper
{
public:
nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
: mCID(aCID),
mOuter(aOuter),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const nsCID& mCID;
nsISupports* mOuter;
nsresult* mErrorPtr;
};
class NS_EXPORT nsCreateInstanceByProgID : public nsCOMPtr_helper
{
public:
nsCreateInstanceByProgID( const char* aProgID, nsISupports* aOuter, nsresult* aErrorPtr )
: mProgID(aProgID),
mOuter(aOuter),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const char* mProgID;
nsISupports* mOuter;
nsresult* mErrorPtr;
};
inline
const nsCreateInstanceByCID
do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
{
return nsCreateInstanceByCID(aCID, 0, error);
}
inline
const nsCreateInstanceByCID
do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
{
return nsCreateInstanceByCID(aCID, aOuter, error);
}
inline
const nsCreateInstanceByProgID
do_CreateInstance( const char* aProgID, nsresult* error = 0 )
{
return nsCreateInstanceByProgID(aProgID, 0, error);
}
inline
const nsCreateInstanceByProgID
do_CreateInstance( const char* aProgID, nsISupports* aOuter, nsresult* error = 0 )
{
return nsCreateInstanceByProgID(aProgID, aOuter, error);
}
/* keys for registry use */
extern const char xpcomBaseName[];
extern const char xpcomKeyName[];

Просмотреть файл

@ -26,6 +26,10 @@
#include "nsIComponentManager.h"
#include "nsID.h"
#ifndef nsCOMPtr_h___
#include "nsCOMPtr.h"
#endif
class nsIShutdownListener;
class nsFileSpec;
@ -208,6 +212,54 @@ public:
};
class NS_EXPORT nsGetServiceByCID : public nsCOMPtr_helper
{
public:
nsGetServiceByCID( const nsCID& aCID, nsresult* aErrorPtr )
: mCID(aCID),
mErrorPtr(aErrorPtr)
{
// nothing else to do
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const nsCID& mCID;
nsresult* mErrorPtr;
};
inline
const nsGetServiceByCID
do_GetService( const nsCID& aCID, nsresult* error = 0 )
{
return nsGetServiceByCID(aCID, error);
}
class NS_EXPORT nsGetServiceByProgID : public nsCOMPtr_helper
{
public:
nsGetServiceByProgID( const char* aProgID, nsresult* aErrorPtr )
: mProgID(aProgID),
mErrorPtr(aErrorPtr)
{
// nothing else to do
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const char* mProgID;
nsresult* mErrorPtr;
};
inline
const nsGetServiceByProgID
do_GetService( const char* aProgID, nsresult* error = 0 )
{
return nsGetServiceByProgID(aProgID, error);
}
////////////////////////////////////////////////////////////////////////////////
// NS_WITH_SERVICE: macro to make using services easier.
// Now you can replace this:

Просмотреть файл

@ -28,6 +28,29 @@
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
nsresult
nsGetServiceByCID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status = nsServiceManager::GetService(mCID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0);
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
nsresult
nsGetServiceByProgID::operator()( const nsIID& aIID, void** aInstancePtr ) const
{
nsresult status;
if ( mProgID )
status = nsServiceManager::GetService(mProgID, aIID, NS_REINTERPRET_CAST(nsISupports**, aInstancePtr), 0);
else
status = NS_ERROR_NULL_POINTER;
if ( mErrorPtr )
*mErrorPtr = status;
return status;
}
class nsServiceEntry {
public:

Просмотреть файл

@ -19,6 +19,10 @@
#ifndef nsComponentManagerUtils_h__
#define nsComponentManagerUtils_h__
#ifndef nsCOMPtr_h__
#include "nsCOMPtr.h"
#endif
#ifndef OBSOLETE_MODULE_LOADING
/*
* Prototypes for dynamic library export functions. Your DLL/DSO needs to export
@ -171,6 +175,73 @@ public:
};
class NS_EXPORT nsCreateInstanceByCID : public nsCOMPtr_helper
{
public:
nsCreateInstanceByCID( const nsCID& aCID, nsISupports* aOuter, nsresult* aErrorPtr )
: mCID(aCID),
mOuter(aOuter),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const nsCID& mCID;
nsISupports* mOuter;
nsresult* mErrorPtr;
};
class NS_EXPORT nsCreateInstanceByProgID : public nsCOMPtr_helper
{
public:
nsCreateInstanceByProgID( const char* aProgID, nsISupports* aOuter, nsresult* aErrorPtr )
: mProgID(aProgID),
mOuter(aOuter),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult operator()( const nsIID&, void** ) const;
private:
const char* mProgID;
nsISupports* mOuter;
nsresult* mErrorPtr;
};
inline
const nsCreateInstanceByCID
do_CreateInstance( const nsCID& aCID, nsresult* error = 0 )
{
return nsCreateInstanceByCID(aCID, 0, error);
}
inline
const nsCreateInstanceByCID
do_CreateInstance( const nsCID& aCID, nsISupports* aOuter, nsresult* error = 0 )
{
return nsCreateInstanceByCID(aCID, aOuter, error);
}
inline
const nsCreateInstanceByProgID
do_CreateInstance( const char* aProgID, nsresult* error = 0 )
{
return nsCreateInstanceByProgID(aProgID, 0, error);
}
inline
const nsCreateInstanceByProgID
do_CreateInstance( const char* aProgID, nsISupports* aOuter, nsresult* error = 0 )
{
return nsCreateInstanceByProgID(aProgID, aOuter, error);
}
/* keys for registry use */
extern const char xpcomBaseName[];
extern const char xpcomKeyName[];