Commit 73137390 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

itss: Simplify the class factory.

parent 86de27ba
...@@ -67,32 +67,17 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv) ...@@ -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) ...@@ -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; InterlockedDecrement(&dll_count);
return 1;
ULONG ref = InterlockedDecrement(&This->ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
InterlockedDecrement(&dll_count);
}
return ref;
} }
...@@ -130,8 +107,8 @@ static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOut ...@@ -130,8 +107,8 @@ static HRESULT WINAPI ITSSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOut
IClassFactoryImpl *This = (IClassFactoryImpl *)iface; IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
HRESULT hres; HRESULT hres;
LPUNKNOWN punk; LPUNKNOWN punk;
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj); TRACE("(%p)->(%p,%s,%p)\n", This, pOuter, debugstr_guid(riid), ppobj);
*ppobj = NULL; *ppobj = NULL;
hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk); hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
...@@ -146,7 +123,7 @@ static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock) ...@@ -146,7 +123,7 @@ static HRESULT WINAPI ITSSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
{ {
TRACE("(%p)->(%d)\n", iface, dolock); TRACE("(%p)->(%d)\n", iface, dolock);
if(dolock) if (dolock)
InterlockedIncrement(&dll_count); InterlockedIncrement(&dll_count);
else else
InterlockedDecrement(&dll_count); InterlockedDecrement(&dll_count);
...@@ -163,49 +140,29 @@ static const IClassFactoryVtbl ITSSCF_Vtbl = ...@@ -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);
if ( !IsEqualGUID( &IID_IClassFactory, iid )
&& ! IsEqualGUID( &IID_IUnknown, iid) )
return E_NOINTERFACE;
for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++) TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
{
if (IsEqualGUID(object_creation[i].clsid, rclsid))
break;
}
if (i == sizeof(object_creation)/sizeof(object_creation[0])) if (IsEqualGUID(&CLSID_ITStorage, rclsid))
factory = &ITStorage_factory;
else if (IsEqualGUID(&CLSID_ITSProtocol, rclsid))
factory = &ITSProtocol_factory;
else
{ {
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;
} }
/*****************************************************************************/ /*****************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment