SetDestructor

This commit is contained in:
beard%netscape.com 1999-02-28 19:04:47 +00:00
parent 4300354ee1
commit f8887c33ae
9 changed files with 99 additions and 6 deletions

View File

@ -18,12 +18,17 @@
#include "nsGenericFactory.h"
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor) : mConstructor(constructor)
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
: mConstructor(constructor), mDestructor(NULL)
{
NS_INIT_ISUPPORTS();
}
nsGenericFactory::~nsGenericFactory() {}
nsGenericFactory::~nsGenericFactory()
{
if (mDestructor != NULL)
(*mDestructor) ();
}
NS_METHOD nsGenericFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
@ -59,6 +64,12 @@ NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
{
mDestructor = destructor;
return NS_OK;
}
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
// sorry, aggregation not spoken here.

View File

@ -38,11 +38,23 @@ public:
NS_IMETHOD LockFactory(PRBool aLock);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
private:
ConstructorProcPtr mConstructor;
DestructorProcPtr mDestructor;
};
#endif /* nsGenericFactory_h___ */

View File

@ -44,12 +44,20 @@ public:
static const nsIID& IID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
typedef NS_CALLBACK(DestructorProcPtr) (void);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
};
#endif /* nsIGenericFactory_h___ */

View File

@ -18,12 +18,17 @@
#include "nsGenericFactory.h"
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor) : mConstructor(constructor)
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
: mConstructor(constructor), mDestructor(NULL)
{
NS_INIT_ISUPPORTS();
}
nsGenericFactory::~nsGenericFactory() {}
nsGenericFactory::~nsGenericFactory()
{
if (mDestructor != NULL)
(*mDestructor) ();
}
NS_METHOD nsGenericFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
@ -59,6 +64,12 @@ NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
{
mDestructor = destructor;
return NS_OK;
}
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
// sorry, aggregation not spoken here.

View File

@ -38,11 +38,23 @@ public:
NS_IMETHOD LockFactory(PRBool aLock);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
private:
ConstructorProcPtr mConstructor;
DestructorProcPtr mDestructor;
};
#endif /* nsGenericFactory_h___ */

View File

@ -44,12 +44,20 @@ public:
static const nsIID& IID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
typedef NS_CALLBACK(DestructorProcPtr) (void);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
};
#endif /* nsIGenericFactory_h___ */

View File

@ -44,12 +44,20 @@ public:
static const nsIID& IID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
typedef NS_CALLBACK(DestructorProcPtr) (void);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
};
#endif /* nsIGenericFactory_h___ */

View File

@ -18,12 +18,17 @@
#include "nsGenericFactory.h"
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor) : mConstructor(constructor)
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
: mConstructor(constructor), mDestructor(NULL)
{
NS_INIT_ISUPPORTS();
}
nsGenericFactory::~nsGenericFactory() {}
nsGenericFactory::~nsGenericFactory()
{
if (mDestructor != NULL)
(*mDestructor) ();
}
NS_METHOD nsGenericFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
@ -59,6 +64,12 @@ NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
return NS_OK;
}
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
{
mDestructor = destructor;
return NS_OK;
}
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
{
// sorry, aggregation not spoken here.

View File

@ -38,11 +38,23 @@ public:
NS_IMETHOD LockFactory(PRBool aLock);
/**
* Establishes the generic factory's constructor function, which will be called
* by CreateInstance.
*/
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
/**
* Establishes the generic factory's destructor function, which will be called
* whe the generic factory is deleted. This is used to notify the DLL that
* an instance of one of its generic factories is going away.
*/
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
private:
ConstructorProcPtr mConstructor;
DestructorProcPtr mDestructor;
};
#endif /* nsGenericFactory_h___ */