dxdiagn vendor import
[reactos.git] / reactos / lib / dxdiagn / provider.c
1 /*
2 * IDxDiagProvider Implementation
3 *
4 * Copyright 2004 Raphael Junqueira
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22 #include "config.h"
23 #include "dxdiag_private.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
27
28 /* IDxDiagProvider IUnknown parts follow: */
29 HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
30 {
31 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
32
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
35 IDxDiagProviderImpl_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
38 }
39
40 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
41 return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
45 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
46 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
47 return ++(This->ref);
48 }
49
50 ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
51 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
52 ULONG ref = --This->ref;
53 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
54 if (ref == 0) {
55 HeapFree(GetProcessHeap(), 0, This);
56 }
57 return ref;
58 }
59
60 /* IDxDiagProvider Interface follow: */
61 HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
62 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
63 TRACE("(%p,%p)\n", iface, pParams);
64
65 if (NULL == pParams) {
66 return E_POINTER;
67 }
68 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
69 return E_INVALIDARG;
70 }
71
72 This->init = TRUE;
73 memcpy(&This->params, pParams, pParams->dwSize);
74 return S_OK;
75 }
76
77 HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
78 HRESULT hr = S_OK;
79 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
80 TRACE("(%p,%p)\n", iface, ppInstance);
81
82 if (NULL == ppInstance) {
83 return E_INVALIDARG;
84 }
85 if (FALSE == This->init) {
86 return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
87 }
88 if (NULL == This->pRootContainer) {
89 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
90 if (FAILED(hr)) {
91 return hr;
92 }
93 }
94 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
95 }
96
97 IDxDiagProviderVtbl DxDiagProvider_Vtbl =
98 {
99 IDxDiagProviderImpl_QueryInterface,
100 IDxDiagProviderImpl_AddRef,
101 IDxDiagProviderImpl_Release,
102 IDxDiagProviderImpl_Initialize,
103 IDxDiagProviderImpl_GetRootContainer
104 };
105
106 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
107 IDxDiagProviderImpl* provider;
108
109 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
110
111 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
112 if (NULL == provider) {
113 *ppobj = NULL;
114 return E_OUTOFMEMORY;
115 }
116 provider->lpVtbl = &DxDiagProvider_Vtbl;
117 provider->ref = 0; /* will be inited with QueryInterface */
118 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
119 }