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
22 #include "dxdiag_private.h"
24 static inline IDxDiagContainerImpl
*impl_from_IDxDiagContainer(IDxDiagContainer
*iface
)
26 return CONTAINING_RECORD(iface
, IDxDiagContainerImpl
, IDxDiagContainer_iface
);
29 /* IDxDiagContainer IUnknown parts follow: */
30 static HRESULT WINAPI
IDxDiagContainerImpl_QueryInterface(IDxDiagContainer
*iface
, REFIID riid
,
33 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
35 if (!ppobj
) return E_INVALIDARG
;
37 if (IsEqualGUID(riid
, &IID_IUnknown
)
38 || IsEqualGUID(riid
, &IID_IDxDiagContainer
)) {
39 IUnknown_AddRef(iface
);
44 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
49 static ULONG WINAPI
IDxDiagContainerImpl_AddRef(IDxDiagContainer
*iface
)
51 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
52 ULONG refCount
= InterlockedIncrement(&This
->ref
);
54 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
61 static ULONG WINAPI
IDxDiagContainerImpl_Release(IDxDiagContainer
*iface
)
63 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
64 ULONG refCount
= InterlockedDecrement(&This
->ref
);
66 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
69 IDxDiagProvider_Release(This
->pProv
);
70 HeapFree(GetProcessHeap(), 0, This
);
73 DXDIAGN_UnlockModule();
78 /* IDxDiagContainer Interface follow: */
79 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer
*iface
,
82 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
84 TRACE("(%p)\n", iface
);
85 if (NULL
== pdwCount
) {
88 *pdwCount
= This
->cont
->nSubContainers
;
92 static HRESULT WINAPI
IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer
*iface
,
93 DWORD dwIndex
, LPWSTR pwszContainer
, DWORD cchContainer
)
95 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
96 IDxDiagContainerImpl_Container
*p
;
99 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszContainer
, cchContainer
);
101 if (NULL
== pwszContainer
|| 0 == cchContainer
) {
105 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
108 TRACE("Found container name %s, copying string\n", debugstr_w(p
->contName
));
109 lstrcpynW(pwszContainer
, p
->contName
, cchContainer
);
110 return (cchContainer
<= strlenW(p
->contName
)) ?
111 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
116 TRACE("Failed to find container name at specified index\n");
117 *pwszContainer
= '\0';
121 static HRESULT
IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container
*cont
, LPCWSTR pwszContainer
, IDxDiagContainerImpl_Container
**subcont
) {
122 IDxDiagContainerImpl_Container
*p
;
124 LIST_FOR_EACH_ENTRY(p
, &cont
->subContainers
, IDxDiagContainerImpl_Container
, entry
)
126 if (0 == lstrcmpW(p
->contName
, pwszContainer
)) {
135 static HRESULT WINAPI
IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer
*iface
,
136 LPCWSTR pwszContainer
, IDxDiagContainer
**ppInstance
)
138 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
139 IDxDiagContainerImpl_Container
*pContainer
= This
->cont
;
140 LPWSTR tmp
, orig_tmp
;
143 HRESULT hr
= E_INVALIDARG
;
145 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszContainer
), ppInstance
);
147 if (NULL
== ppInstance
|| NULL
== pwszContainer
) {
153 tmp_len
= strlenW(pwszContainer
) + 1;
154 orig_tmp
= tmp
= HeapAlloc(GetProcessHeap(), 0, tmp_len
* sizeof(WCHAR
));
155 if (NULL
== tmp
) return E_FAIL
;
156 lstrcpynW(tmp
, pwszContainer
, tmp_len
);
158 /* special handling for an empty string and leaf container */
159 if (!tmp
[0] && list_empty(&pContainer
->subContainers
)) {
160 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
162 TRACE("Succeeded in getting the container instance\n");
166 cur
= strchrW(tmp
, '.');
167 while (NULL
!= cur
) {
168 *cur
= '\0'; /* cut tmp string to '.' */
169 if (!*(cur
+ 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
170 TRACE("Trying to get parent container %s\n", debugstr_w(tmp
));
171 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
174 cur
++; /* go after '.' (just replaced by \0) */
176 cur
= strchrW(tmp
, '.');
179 TRACE("Trying to get container %s\n", debugstr_w(tmp
));
180 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
182 hr
= DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer
, pContainer
, This
->pProv
, (void **)ppInstance
);
184 TRACE("Succeeded in getting the container instance\n");
188 HeapFree(GetProcessHeap(), 0, orig_tmp
);
192 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer
*iface
,
195 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
197 TRACE("(%p)\n", iface
);
198 if (NULL
== pdwCount
) {
201 *pdwCount
= This
->cont
->nProperties
;
205 static HRESULT WINAPI
IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer
*iface
, DWORD dwIndex
,
206 LPWSTR pwszPropName
, DWORD cchPropName
)
208 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
209 IDxDiagContainerImpl_Property
*p
;
212 TRACE("(%p, %u, %p, %u)\n", iface
, dwIndex
, pwszPropName
, cchPropName
);
214 if (NULL
== pwszPropName
|| 0 == cchPropName
) {
218 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
221 TRACE("Found property name %s, copying string\n", debugstr_w(p
->propName
));
222 lstrcpynW(pwszPropName
, p
->propName
, cchPropName
);
223 return (cchPropName
<= strlenW(p
->propName
)) ?
224 DXDIAG_E_INSUFFICIENT_BUFFER
: S_OK
;
229 TRACE("Failed to find property name at specified index\n");
233 static HRESULT WINAPI
IDxDiagContainerImpl_GetProp(IDxDiagContainer
*iface
, LPCWSTR pwszPropName
,
236 IDxDiagContainerImpl
*This
= impl_from_IDxDiagContainer(iface
);
237 IDxDiagContainerImpl_Property
*p
;
239 TRACE("(%p, %s, %p)\n", iface
, debugstr_w(pwszPropName
), pvarProp
);
241 if (NULL
== pvarProp
|| NULL
== pwszPropName
) {
245 LIST_FOR_EACH_ENTRY(p
, &This
->cont
->properties
, IDxDiagContainerImpl_Property
, entry
)
247 if (0 == lstrcmpW(p
->propName
, pwszPropName
)) {
248 VariantInit(pvarProp
);
249 return VariantCopy(pvarProp
, &p
->vProp
);
256 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
=
258 IDxDiagContainerImpl_QueryInterface
,
259 IDxDiagContainerImpl_AddRef
,
260 IDxDiagContainerImpl_Release
,
261 IDxDiagContainerImpl_GetNumberOfChildContainers
,
262 IDxDiagContainerImpl_EnumChildContainerNames
,
263 IDxDiagContainerImpl_GetChildContainer
,
264 IDxDiagContainerImpl_GetNumberOfProps
,
265 IDxDiagContainerImpl_EnumPropNames
,
266 IDxDiagContainerImpl_GetProp
270 HRESULT
DXDiag_CreateDXDiagContainer(REFIID riid
, IDxDiagContainerImpl_Container
*cont
, IDxDiagProvider
*pProv
, LPVOID
*ppobj
) {
271 IDxDiagContainerImpl
* container
;
273 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppobj
);
275 container
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDxDiagContainerImpl
));
276 if (NULL
== container
) {
278 return E_OUTOFMEMORY
;
280 container
->IDxDiagContainer_iface
.lpVtbl
= &DxDiagContainer_Vtbl
;
281 container
->ref
= 0; /* will be inited with QueryInterface */
282 container
->cont
= cont
;
283 container
->pProv
= pProv
;
284 IDxDiagProvider_AddRef(pProv
);
285 return IDxDiagContainerImpl_QueryInterface(&container
->IDxDiagContainer_iface
, riid
, ppobj
);