itss: Simplify the class factory.

This commit is contained in:
Mike McCormack 2006-08-22 17:17:23 +09:00 committed by Alexandre Julliard
parent 86de27bad6
commit 73137390b0
1 changed files with 20 additions and 63 deletions

View File

@ -67,32 +67,17 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
* ITSS ClassFactory * ITSS ClassFactory
*/ */
typedef struct { typedef struct {
IClassFactory ITF_IClassFactory; const IClassFactoryVtbl *lpVtbl;
LONG ref;
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj); HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
} IClassFactoryImpl; } IClassFactoryImpl;
struct object_creation_info
{
const CLSID *clsid;
LPCSTR szClassName;
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
};
static const struct object_creation_info object_creation[] =
{
{ &CLSID_ITStorage, "ITStorage", ITSS_create },
{ &CLSID_ITSProtocol, "ITSProtocol", ITS_IParseDisplayName_create },
};
static HRESULT WINAPI static HRESULT WINAPI
ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
{ {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface; IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
if (IsEqualGUID(riid, &IID_IUnknown) if (IsEqualGUID(riid, &IID_IUnknown) ||
|| IsEqualGUID(riid, &IID_IClassFactory)) IsEqualGUID(riid, &IID_IClassFactory))
{ {
IClassFactory_AddRef(iface); IClassFactory_AddRef(iface);
*ppobj = This; *ppobj = This;
@ -105,22 +90,14 @@ ITSSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface) static ULONG WINAPI ITSSCF_AddRef(LPCLASSFACTORY iface)
{ {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface; InterlockedIncrement(&dll_count);
return InterlockedIncrement(&This->ref); return 2;
} }
static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface) static ULONG WINAPI ITSSCF_Release(LPCLASSFACTORY iface)
{ {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
InterlockedDecrement(&dll_count); InterlockedDecrement(&dll_count);
} return 1;
return ref;
} }
@ -163,49 +140,29 @@ static const IClassFactoryVtbl ITSSCF_Vtbl =
ITSSCF_LockServer ITSSCF_LockServer
}; };
static const IClassFactoryImpl ITStorage_factory = { &ITSSCF_Vtbl, ITSS_create };
static const IClassFactoryImpl ITSProtocol_factory = { &ITSSCF_Vtbl, ITS_IParseDisplayName_create };
/*********************************************************************** /***********************************************************************
* DllGetClassObject (ITSS.@) * DllGetClassObject (ITSS.@)
*/ */
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv) HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
{ {
DWORD i; const IClassFactoryImpl *factory;
IClassFactoryImpl *factory;
TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv); TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
if ( !IsEqualGUID( &IID_IClassFactory, iid ) if (IsEqualGUID(&CLSID_ITStorage, rclsid))
&& ! IsEqualGUID( &IID_IUnknown, iid) ) factory = &ITStorage_factory;
return E_NOINTERFACE; else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
factory = &ITSProtocol_factory;
for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++) else
{
if (IsEqualGUID(object_creation[i].clsid, rclsid))
break;
}
if (i == sizeof(object_creation)/sizeof(object_creation[0]))
{ {
FIXME("%s: no class found.\n", debugstr_guid(rclsid)); FIXME("%s: no class found.\n", debugstr_guid(rclsid));
return CLASS_E_CLASSNOTAVAILABLE; return CLASS_E_CLASSNOTAVAILABLE;
} }
TRACE("Creating a class factory for %s\n",object_creation[i].szClassName); return IUnknown_QueryInterface( (IUnknown*) factory, iid, ppv );
factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
if (factory == NULL) return E_OUTOFMEMORY;
factory->ITF_IClassFactory.lpVtbl = &ITSSCF_Vtbl;
factory->ref = 1;
factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
*ppv = &(factory->ITF_IClassFactory);
InterlockedIncrement(&dll_count);
TRACE("(%p) <- %p\n", ppv, &(factory->ITF_IClassFactory) );
return S_OK;
} }
/*****************************************************************************/ /*****************************************************************************/