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
25 #include "dxdiag_private.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag
);
31 static inline IDxDiagContainerImpl
*impl_from_IDxDiagContainer(IDxDiagContainer
*iface
)
33 return CONTAINING_RECORD(iface
, IDxDiagContainerImpl
, IDxDiagContainer_iface
);
36 /* IDxDiagContainer IUnknown parts follow: */
37 static HRESULT WINAPI
IDxDiagContainerImpl_QueryInterface(IDxDiagContainer
*iface
, REFIID riid
,
40 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
42 if (!ppobj
) return E_INVALIDARG
;
44 if (IsEqualGUID(riid
, &IID_IUnknown
)
45 || IsEqualGUID(riid
, &IID_IDxDiagContainer
)) {
46 IUnknown_AddRef(iface
);
51 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
56 static ULONG WINAPI
IDxDiagContainerImpl_AddRef(IDxDiagContainer
*iface
)
58 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
59 ULONG refCount
= InterlockedIncrement(&This
->ref
);
61 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
68 static ULONG WINAPI
IDxDiagContainerImpl_Release(IDxDiagContainer
*iface
)
70 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
71 ULONG refCount
= InterlockedDecrement(&This
->ref
);
73 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
76 IDxDiagProvider_Release(This
->pProv
);
77 HeapFree(GetProcessHeap(), 0, This
);
80 DXDIAGN_UnlockModule();
85 /* IDxDiagContainer Interface follow: */
86 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer
*iface
,
89 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
91 TRACE("(%p)\n", iface
);
92 if (NULL
== pdwCount
) {
95 *pdwCount
= This
->cont
->nSubContainers
;
99 static HRESULT WINAPI
IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer
*iface
,
100 DWORD dwIndex
, LPWSTR pwszContainer
, DWORD cchContainer
)
102 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
103 IDxDiagContainerImpl_Container
*p
;
106 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszContainer
, cchContainer
);
108 if (NULL
== pwszContainer
|| 0 == cchContainer
) {
112 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
115 TRACE("Found container name %s, copying string\n", debugstr_w(p
->contName
));
116 lstrcpynW(pwszContainer
, p
->contName
, cchContainer
);
117 return (cchContainer
<= strlenW(p
->contName
)) ?
118 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
123 TRACE("Failed to find container name at specified index\n");
124 *pwszContainer
= '\0';
128 static HRESULT
IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container
*cont
, LPCWSTR pwszContainer
, IDxDiagContainerImpl_Container
**subcont
) {
129 IDxDiagContainerImpl_Container
*p
;
131 LIST_FOR_EACH_ENTRY(p
, &cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
133 if (0 == lstrcmpW(p
->contName
, pwszContainer
)) {
142 static HRESULT WINAPI
IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer
*iface
,
143 LPCWSTR pwszContainer
, IDxDiagContainer
**ppInstance
)
145 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
146 IDxDiagContainerImpl_Container
*pContainer
= This
->cont
;
147 LPWSTR tmp
, orig_tmp
;
150 HRESULT hr
= E_INVALIDARG
;
152 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszContainer
), ppInstance
);
154 if (NULL
== ppInstance
|| NULL
== pwszContainer
) {
160 tmp_len
= strlenW(pwszContainer
) + 1;
161 orig_tmp
= tmp
= HeapAlloc(GetProcessHeap(), 0, tmp_len
* sizeof(WCHAR
));
162 if (NULL
== tmp
) return E_FAIL
;
163 lstrcpynW(tmp
, pwszContainer
, tmp_len
);
165 /* special handling for an empty string and leaf container */
166 if (!tmp
[0] && list_empty(&pContainer
->subContainers
)) {
167 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
169 TRACE("Succeeded in getting the container instance\n");
173 cur
= strchrW(tmp
, '.');
174 while (NULL
!= cur
) {
175 *cur
= '\0'; /* cut tmp string to '.' */
176 if (!*(cur
+ 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
177 TRACE("Trying to get parent container %s\n", debugstr_w(tmp
));
178 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
181 cur
++; /* go after '.' (just replaced by \0) */
183 cur
= strchrW(tmp
, '.');
186 TRACE("Trying to get container %s\n", debugstr_w(tmp
));
187 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
189 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
191 TRACE("Succeeded in getting the container instance\n");
195 HeapFree(GetProcessHeap(), 0, orig_tmp
);
199 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer
*iface
,
202 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
204 TRACE("(%p)\n", iface
);
205 if (NULL
== pdwCount
) {
208 *pdwCount
= This
->cont
->nProperties
;
212 static HRESULT WINAPI
IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer
*iface
, DWORD dwIndex
,
213 LPWSTR pwszPropName
, DWORD cchPropName
)
215 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
216 IDxDiagContainerImpl_Property
*p
;
219 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszPropName
, cchPropName
);
221 if (NULL
== pwszPropName
|| 0 == cchPropName
) {
225 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
228 TRACE("Found property name %s, copying string\n", debugstr_w(p
->propName
));
229 lstrcpynW(pwszPropName
, p
->propName
, cchPropName
);
230 return (cchPropName
<= strlenW(p
->propName
)) ?
231 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
236 TRACE("Failed to find property name at specified index\n");
240 static HRESULT WINAPI
IDxDiagContainerImpl_GetProp(IDxDiagContainer
*iface
, LPCWSTR pwszPropName
,
243 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
244 IDxDiagContainerImpl_Property
*p
;
246 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszPropName
), pvarProp
);
248 if (NULL
== pvarProp
|| NULL
== pwszPropName
) {
252 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
254 if (0 == lstrcmpW(p
->propName
, pwszPropName
)) {
255 VariantInit(pvarProp
);
256 return VariantCopy(pvarProp
, &p
->vProp
);
263 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
=
265 IDxDiagContainerImpl_QueryInterface
,
266 IDxDiagContainerImpl_AddRef
,
267 IDxDiagContainerImpl_Release
,
268 IDxDiagContainerImpl_GetNumberOfChildContainers
,
269 IDxDiagContainerImpl_EnumChildContainerNames
,
270 IDxDiagContainerImpl_GetChildContainer
,
271 IDxDiagContainerImpl_GetNumberOfProps
,
272 IDxDiagContainerImpl_EnumPropNames
,
273 IDxDiagContainerImpl_GetProp
277 HRESULT
DXDiag_CreateDXDiagContainer(REFIID riid
, IDxDiagContainerImpl_Container
*cont
, IDxDiagProvider
*pProv
, LPVOID
*ppobj
) {
278 IDxDiagContainerImpl
* container
;
280 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppobj
);
282 container
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDxDiagContainerImpl
));
283 if (NULL
== container
) {
285 return E_OUTOFMEMORY
;
287 container
->IDxDiagContainer_iface
.lpVtbl
= &DxDiagContainer_Vtbl
;
288 container
->ref
= 0; /* will be inited with QueryInterface */
289 container
->cont
= cont
;
290 container
->pProv
= pProv
;
291 IDxDiagProvider_AddRef(pProv
);
292 return IDxDiagContainerImpl_QueryInterface(&container
->IDxDiagContainer_iface
, riid
, ppobj
);