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 /* IDxDiagContainer IUnknown parts follow: */
32 static HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(PDXDIAGCONTAINER iface, REFIID riid, LPVOID *ppobj)
34 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
36 if (!ppobj) return E_INVALIDARG;
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
40 IUnknown_AddRef(iface);
45 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
50 static ULONG WINAPI IDxDiagContainerImpl_AddRef(PDXDIAGCONTAINER iface) {
51 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
52 ULONG refCount = InterlockedIncrement(&This->ref);
54 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
61 static ULONG WINAPI IDxDiagContainerImpl_Release(PDXDIAGCONTAINER iface) {
62 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
63 ULONG refCount = InterlockedDecrement(&This->ref);
65 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
68 IDxDiagProvider_Release(This->pProv);
69 HeapFree(GetProcessHeap(), 0, This);
72 DXDIAGN_UnlockModule();
77 /* IDxDiagContainer Interface follow: */
78 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
79 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
80 TRACE("(%p)\n", iface);
81 if (NULL == pdwCount) {
84 *pdwCount = This->cont->nSubContainers;
88 static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer) {
89 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
90 IDxDiagContainerImpl_Container *p;
93 TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
95 if (NULL == pwszContainer || 0 == cchContainer) {
99 LIST_FOR_EACH_ENTRY(p, &This->cont->subContainers, IDxDiagContainerImpl_Container, entry)
102 TRACE("Found container name %s, copying string\n", debugstr_w(p->contName));
103 lstrcpynW(pwszContainer, p->contName, cchContainer);
104 return (cchContainer <= strlenW(p->contName)) ?
105 DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
110 TRACE("Failed to find container name at specified index\n");
111 *pwszContainer = '\0';
115 static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container *cont, LPCWSTR pwszContainer, IDxDiagContainerImpl_Container **subcont) {
116 IDxDiagContainerImpl_Container *p;
118 LIST_FOR_EACH_ENTRY(p, &cont->subContainers, IDxDiagContainerImpl_Container, entry)
120 if (0 == lstrcmpW(p->contName, pwszContainer)) {
129 static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer **ppInstance) {
130 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
131 IDxDiagContainerImpl_Container *pContainer = This->cont;
132 LPWSTR tmp, orig_tmp;
135 HRESULT hr = E_INVALIDARG;
137 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
139 if (NULL == ppInstance || NULL == pwszContainer) {
145 tmp_len = strlenW(pwszContainer) + 1;
146 orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR));
147 if (NULL == tmp) return E_FAIL;
148 lstrcpynW(tmp, pwszContainer, tmp_len);
150 cur = strchrW(tmp, '.');
151 while (NULL != cur) {
152 *cur = '\0'; /* cut tmp string to '.' */
153 if (!*(cur + 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
154 TRACE("Trying to get parent container %s\n", debugstr_w(tmp));
155 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
158 cur++; /* go after '.' (just replaced by \0) */
160 cur = strchrW(tmp, '.');
163 TRACE("Trying to get container %s\n", debugstr_w(tmp));
164 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
166 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
168 TRACE("Succeeded in getting the container instance\n");
172 HeapFree(GetProcessHeap(), 0, orig_tmp);
176 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
177 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
178 TRACE("(%p)\n", iface);
179 if (NULL == pdwCount) {
182 *pdwCount = This->cont->nProperties;
186 static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName) {
187 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
188 IDxDiagContainerImpl_Property *p;
191 TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszPropName, cchPropName);
193 if (NULL == pwszPropName || 0 == cchPropName) {
197 LIST_FOR_EACH_ENTRY(p, &This->cont->properties, IDxDiagContainerImpl_Property, entry)
200 TRACE("Found property name %s, copying string\n", debugstr_w(p->propName));
201 lstrcpynW(pwszPropName, p->propName, cchPropName);
202 return (cchPropName <= strlenW(p->propName)) ?
203 DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
208 TRACE("Failed to find property name at specified index\n");
212 static HRESULT WINAPI IDxDiagContainerImpl_GetProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pvarProp) {
213 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
214 IDxDiagContainerImpl_Property *p;
216 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
218 if (NULL == pvarProp || NULL == pwszPropName) {
222 LIST_FOR_EACH_ENTRY(p, &This->cont->properties, IDxDiagContainerImpl_Property, entry)
224 if (0 == lstrcmpW(p->propName, pwszPropName)) {
225 VariantInit(pvarProp);
226 return VariantCopy(pvarProp, &p->vProp);
233 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
235 IDxDiagContainerImpl_QueryInterface,
236 IDxDiagContainerImpl_AddRef,
237 IDxDiagContainerImpl_Release,
238 IDxDiagContainerImpl_GetNumberOfChildContainers,
239 IDxDiagContainerImpl_EnumChildContainerNames,
240 IDxDiagContainerImpl_GetChildContainer,
241 IDxDiagContainerImpl_GetNumberOfProps,
242 IDxDiagContainerImpl_EnumPropNames,
243 IDxDiagContainerImpl_GetProp
247 HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, IDxDiagContainerImpl_Container *cont, IDxDiagProvider *pProv, LPVOID *ppobj) {
248 IDxDiagContainerImpl* container;
250 TRACE("(%p, %p)\n", debugstr_guid(riid), ppobj);
252 container = HeapAlloc(GetProcessHeap(), 0, sizeof(IDxDiagContainerImpl));
253 if (NULL == container) {
255 return E_OUTOFMEMORY;
257 container->lpVtbl = &DxDiagContainer_Vtbl;
258 container->ref = 0; /* will be inited with QueryInterface */
259 container->cont = cont;
260 container->pProv = pProv;
261 IDxDiagProvider_AddRef(pProv);
262 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)container, riid, ppobj);