2 * IDxDiagContainer Implementation
4 * Copyright 2004 Raphael Junqueira
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "dxdiag_private.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag
);
29 static inline IDxDiagContainerImpl
*impl_from_IDxDiagContainer(IDxDiagContainer
*iface
)
31 return CONTAINING_RECORD(iface
, IDxDiagContainerImpl
, IDxDiagContainer_iface
);
34 /* IDxDiagContainer IUnknown parts follow: */
35 static HRESULT WINAPI
IDxDiagContainerImpl_QueryInterface(IDxDiagContainer
*iface
, REFIID riid
,
38 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
40 if (!ppobj
) return E_INVALIDARG
;
42 if (IsEqualGUID(riid
, &IID_IUnknown
)
43 || IsEqualGUID(riid
, &IID_IDxDiagContainer
)) {
44 IUnknown_AddRef(iface
);
49 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
54 static ULONG WINAPI
IDxDiagContainerImpl_AddRef(IDxDiagContainer
*iface
)
56 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
57 ULONG refCount
= InterlockedIncrement(&This
->ref
);
59 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
66 static ULONG WINAPI
IDxDiagContainerImpl_Release(IDxDiagContainer
*iface
)
68 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
69 ULONG refCount
= InterlockedDecrement(&This
->ref
);
71 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
74 IDxDiagProvider_Release(This
->pProv
);
75 HeapFree(GetProcessHeap(), 0, This
);
78 DXDIAGN_UnlockModule();
83 /* IDxDiagContainer Interface follow: */
84 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer
*iface
,
87 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
89 TRACE("(%p)\n", iface
);
90 if (NULL
== pdwCount
) {
93 *pdwCount
= This
->cont
->nSubContainers
;
97 static HRESULT WINAPI
IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer
*iface
,
98 DWORD dwIndex
, LPWSTR pwszContainer
, DWORD cchContainer
)
100 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
101 IDxDiagContainerImpl_Container
*p
;
104 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszContainer
, cchContainer
);
106 if (NULL
== pwszContainer
|| 0 == cchContainer
) {
110 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
113 TRACE("Found container name %s, copying string\n", debugstr_w(p
->contName
));
114 lstrcpynW(pwszContainer
, p
->contName
, cchContainer
);
115 return (cchContainer
<= lstrlenW(p
->contName
)) ?
116 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
121 TRACE("Failed to find container name at specified index\n");
122 *pwszContainer
= '\0';
126 static HRESULT
IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container
*cont
, LPCWSTR pwszContainer
, IDxDiagContainerImpl_Container
**subcont
) {
127 IDxDiagContainerImpl_Container
*p
;
129 LIST_FOR_EACH_ENTRY(p
, &cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
131 if (0 == lstrcmpW(p
->contName
, pwszContainer
)) {
140 static HRESULT WINAPI
IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer
*iface
,
141 LPCWSTR pwszContainer
, IDxDiagContainer
**ppInstance
)
143 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
144 IDxDiagContainerImpl_Container
*pContainer
= This
->cont
;
145 LPWSTR tmp
, orig_tmp
;
148 HRESULT hr
= E_INVALIDARG
;
150 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszContainer
), ppInstance
);
152 if (NULL
== ppInstance
|| NULL
== pwszContainer
) {
158 tmp_len
= lstrlenW(pwszContainer
) + 1;
159 orig_tmp
= tmp
= HeapAlloc(GetProcessHeap(), 0, tmp_len
* sizeof(WCHAR
));
160 if (NULL
== tmp
) return E_FAIL
;
161 lstrcpynW(tmp
, pwszContainer
, tmp_len
);
163 /* special handling for an empty string and leaf container */
164 if (!tmp
[0] && list_empty(&pContainer
->subContainers
)) {
165 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
167 TRACE("Succeeded in getting the container instance\n");
171 cur
= wcschr(tmp
, '.');
172 while (NULL
!= cur
) {
173 *cur
= '\0'; /* cut tmp string to '.' */
174 if (!*(cur
+ 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
175 TRACE("Trying to get parent container %s\n", debugstr_w(tmp
));
176 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
179 cur
++; /* go after '.' (just replaced by \0) */
181 cur
= wcschr(tmp
, '.');
184 TRACE("Trying to get container %s\n", debugstr_w(tmp
));
185 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
187 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
189 TRACE("Succeeded in getting the container instance\n");
193 HeapFree(GetProcessHeap(), 0, orig_tmp
);
197 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer
*iface
,
200 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
202 TRACE("(%p)\n", iface
);
203 if (NULL
== pdwCount
) {
206 *pdwCount
= This
->cont
->nProperties
;
210 static HRESULT WINAPI
IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer
*iface
, DWORD dwIndex
,
211 LPWSTR pwszPropName
, DWORD cchPropName
)
213 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
214 IDxDiagContainerImpl_Property
*p
;
217 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszPropName
, cchPropName
);
219 if (NULL
== pwszPropName
|| 0 == cchPropName
) {
223 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
226 TRACE("Found property name %s, copying string\n", debugstr_w(p
->propName
));
227 lstrcpynW(pwszPropName
, p
->propName
, cchPropName
);
228 return (cchPropName
<= lstrlenW(p
->propName
)) ?
229 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
234 TRACE("Failed to find property name at specified index\n");
238 static HRESULT WINAPI
IDxDiagContainerImpl_GetProp(IDxDiagContainer
*iface
, LPCWSTR pwszPropName
,
241 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
242 IDxDiagContainerImpl_Property
*p
;
244 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszPropName
), pvarProp
);
246 if (NULL
== pvarProp
|| NULL
== pwszPropName
) {
250 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
252 if (0 == lstrcmpW(p
->propName
, pwszPropName
)) {
253 VariantInit(pvarProp
);
254 return VariantCopy(pvarProp
, &p
->vProp
);
261 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
=
263 IDxDiagContainerImpl_QueryInterface
,
264 IDxDiagContainerImpl_AddRef
,
265 IDxDiagContainerImpl_Release
,
266 IDxDiagContainerImpl_GetNumberOfChildContainers
,
267 IDxDiagContainerImpl_EnumChildContainerNames
,
268 IDxDiagContainerImpl_GetChildContainer
,
269 IDxDiagContainerImpl_GetNumberOfProps
,
270 IDxDiagContainerImpl_EnumPropNames
,
271 IDxDiagContainerImpl_GetProp
275 HRESULT
DXDiag_CreateDXDiagContainer(REFIID riid
, IDxDiagContainerImpl_Container
*cont
, IDxDiagProvider
*pProv
, LPVOID
*ppobj
) {
276 IDxDiagContainerImpl
* container
;
278 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppobj
);
280 container
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDxDiagContainerImpl
));
281 if (NULL
== container
) {
283 return E_OUTOFMEMORY
;
285 container
->IDxDiagContainer_iface
.lpVtbl
= &DxDiagContainer_Vtbl
;
286 container
->ref
= 0; /* will be inited with QueryInterface */
287 container
->cont
= cont
;
288 container
->pProv
= pProv
;
289 IDxDiagProvider_AddRef(pProv
);
290 return IDxDiagContainerImpl_QueryInterface(&container
->IDxDiagContainer_iface
, riid
, ppobj
);