d3dx9: Implement UpdateSemantics mesh method.
[wine/multimedia.git] / dlls / dxdiagn / container.c
blob6de641f6f93fb138bada62384b0ad10b7b8ccd17
1 /*
2 * IDxDiagContainer Implementation
3 *
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 "config.h"
24 #define COBJMACROS
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);
41 *ppobj = This;
42 return S_OK;
45 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46 *ppobj = NULL;
47 return E_NOINTERFACE;
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);
56 DXDIAGN_LockModule();
58 return refCount;
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);
67 if (!refCount) {
68 IDxDiagProvider_Release(This->pProv);
69 HeapFree(GetProcessHeap(), 0, This);
72 DXDIAGN_UnlockModule();
74 return refCount;
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) {
82 return E_INVALIDARG;
84 *pdwCount = This->cont->nSubContainers;
85 return S_OK;
88 static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer) {
89 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
90 IDxDiagContainerImpl_Container *p;
91 DWORD i = 0;
93 TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
95 if (NULL == pwszContainer || 0 == cchContainer) {
96 return E_INVALIDARG;
99 LIST_FOR_EACH_ENTRY(p, &This->cont->subContainers, IDxDiagContainerImpl_Container, entry)
101 if (dwIndex == i) {
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;
107 ++i;
110 TRACE("Failed to find container name at specified index\n");
111 *pwszContainer = '\0';
112 return E_INVALIDARG;
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)) {
121 *subcont = p;
122 return S_OK;
126 return E_INVALIDARG;
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;
133 INT tmp_len;
134 WCHAR* cur;
135 HRESULT hr = E_INVALIDARG;
137 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
139 if (NULL == ppInstance || NULL == pwszContainer) {
140 return E_INVALIDARG;
143 *ppInstance = NULL;
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);
156 if (FAILED(hr))
157 goto on_error;
158 cur++; /* go after '.' (just replaced by \0) */
159 tmp = cur;
160 cur = strchrW(tmp, '.');
163 TRACE("Trying to get container %s\n", debugstr_w(tmp));
164 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
165 if (SUCCEEDED(hr)) {
166 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
167 if (SUCCEEDED(hr))
168 TRACE("Succeeded in getting the container instance\n");
171 on_error:
172 HeapFree(GetProcessHeap(), 0, orig_tmp);
173 return hr;
176 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
177 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
178 TRACE("(%p)\n", iface);
179 if (NULL == pdwCount) {
180 return E_INVALIDARG;
182 *pdwCount = This->cont->nProperties;
183 return S_OK;
186 static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName) {
187 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
188 IDxDiagContainerImpl_Property *p;
189 DWORD i = 0;
191 TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszPropName, cchPropName);
193 if (NULL == pwszPropName || 0 == cchPropName) {
194 return E_INVALIDARG;
197 LIST_FOR_EACH_ENTRY(p, &This->cont->properties, IDxDiagContainerImpl_Property, entry)
199 if (dwIndex == i) {
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;
205 ++i;
208 TRACE("Failed to find property name at specified index\n");
209 return E_INVALIDARG;
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) {
219 return E_INVALIDARG;
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);
230 return E_INVALIDARG;
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) {
254 *ppobj = NULL;
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);