~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/dxdiagn/container.c

Version: ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /* 
  2  * IDxDiagContainer Implementation
  3  * 
  4  * Copyright 2004 Raphael Junqueira
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  *
 20  */
 21 
 22 #include "config.h"
 23 
 24 #define COBJMACROS
 25 #include "dxdiag_private.h"
 26 #include "wine/debug.h"
 27 #include "wine/unicode.h"
 28 
 29 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
 30 
 31 /* IDxDiagContainer IUnknown parts follow: */
 32 HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(PDXDIAGCONTAINER iface, REFIID riid, LPVOID *ppobj)
 33 {
 34     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
 35 
 36     if (!ppobj) return E_INVALIDARG;
 37 
 38     if (IsEqualGUID(riid, &IID_IUnknown)
 39         || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
 40         IUnknown_AddRef(iface);
 41         *ppobj = This;
 42         return S_OK;
 43     }
 44 
 45     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
 46     *ppobj = NULL;
 47     return E_NOINTERFACE;
 48 }
 49 
 50 static ULONG WINAPI IDxDiagContainerImpl_AddRef(PDXDIAGCONTAINER iface) {
 51     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
 52     ULONG refCount = InterlockedIncrement(&This->ref);
 53 
 54     TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
 55 
 56     DXDIAGN_LockModule();
 57 
 58     return refCount;
 59 }
 60 
 61 static ULONG WINAPI IDxDiagContainerImpl_Release(PDXDIAGCONTAINER iface) {
 62     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
 63     ULONG refCount = InterlockedDecrement(&This->ref);
 64 
 65     TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
 66 
 67     if (!refCount) {
 68         HeapFree(GetProcessHeap(), 0, This);
 69     }
 70 
 71     DXDIAGN_UnlockModule();
 72     
 73     return refCount;
 74 }
 75 
 76 /* IDxDiagContainer Interface follow: */
 77 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
 78   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
 79   TRACE("(%p)\n", iface);
 80   if (NULL == pdwCount) {
 81     return E_INVALIDARG;
 82   }
 83   *pdwCount = This->nSubContainers;
 84   return S_OK;
 85 }
 86 
 87 static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer) {
 88   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
 89   IDxDiagContainerImpl_SubContainer* p = NULL;
 90   DWORD i = 0;
 91 
 92   TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
 93 
 94   if (NULL == pwszContainer || 0 == cchContainer) {
 95     return E_INVALIDARG;
 96   }
 97 
 98   p = This->subContainers;
 99   while (NULL != p) {
100     if (dwIndex == i) {
101       TRACE("Found container name %s, copying string\n", debugstr_w(p->contName));
102       lstrcpynW(pwszContainer, p->contName, cchContainer);
103       return (cchContainer <= strlenW(p->contName)) ?
104               DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
105     }
106     p = p->next;
107     ++i;
108   }
109 
110   TRACE("Failed to find container name at specified index\n");
111   *pwszContainer = '\0';
112   return E_INVALIDARG;
113 }
114 
115 static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) {
116   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
117   IDxDiagContainerImpl_SubContainer* p = NULL;
118 
119   p = This->subContainers;
120   while (NULL != p) {
121     if (0 == lstrcmpW(p->contName, pwszContainer)) {
122       *ppInstance = p->pCont;
123       return S_OK;
124     }
125     p = p->next;
126   }
127   return E_INVALIDARG;
128 }
129 
130 static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) {
131   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
132   IDxDiagContainer* pContainer = (PDXDIAGCONTAINER)This;
133   LPWSTR tmp, orig_tmp;
134   INT tmp_len;
135   WCHAR* cur;
136   HRESULT hr = E_INVALIDARG;
137 
138   TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
139 
140   if (NULL == ppInstance || NULL == pwszContainer) {
141     return E_INVALIDARG;
142   }
143 
144   *ppInstance = NULL;
145 
146   tmp_len = strlenW(pwszContainer) + 1;
147   orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR));
148   if (NULL == tmp) return E_FAIL;
149   lstrcpynW(tmp, pwszContainer, tmp_len);
150 
151   cur = strchrW(tmp, '.');
152   while (NULL != cur) {
153     *cur = '\0'; /* cut tmp string to '.' */
154     if (!*(cur + 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
155     TRACE("Trying to get parent container %s\n", debugstr_w(tmp));
156     hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
157     if (FAILED(hr) || NULL == pContainer)
158       goto on_error;
159     cur++; /* go after '.' (just replaced by \0) */
160     tmp = cur;
161     cur = strchrW(tmp, '.');
162   }
163 
164   TRACE("Trying to get container %s\n", debugstr_w(tmp));
165   hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, ppInstance);
166   if (SUCCEEDED(hr)) {
167     TRACE("Succeeded in getting the container instance\n");
168     IDxDiagContainerImpl_AddRef(*ppInstance);
169   }
170 
171 on_error:
172   HeapFree(GetProcessHeap(), 0, orig_tmp);
173   return hr;
174 }
175 
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;
181   }
182   *pdwCount = This->nProperties;
183   return S_OK;
184 }
185 
186 static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName) {
187   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
188   IDxDiagContainerImpl_Property* p = NULL;
189   DWORD i = 0;
190 
191   TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszPropName, cchPropName);
192 
193   if (NULL == pwszPropName || 0 == cchPropName) {
194     return E_INVALIDARG;
195   }
196 
197   p = This->properties;
198   while (NULL != p) {
199     if (dwIndex == i) {
200       TRACE("Found property name %s, copying string\n", debugstr_w(p->vName));
201       lstrcpynW(pwszPropName, p->vName, cchPropName);
202       return (cchPropName <= strlenW(p->vName)) ?
203               DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
204     }
205     p = p->next;
206     ++i;
207   }
208   TRACE("Failed to find property name at specified index\n");
209   return E_INVALIDARG;
210 }
211 
212 static HRESULT WINAPI IDxDiagContainerImpl_GetProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pvarProp) {
213   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
214   IDxDiagContainerImpl_Property* p = NULL;
215 
216   TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
217 
218   if (NULL == pvarProp || NULL == pwszPropName) {
219     return E_INVALIDARG;
220   }
221 
222   p = This->properties;
223   while (NULL != p) {
224     if (0 == lstrcmpW(p->vName, pwszPropName)) {      
225       VariantCopy(pvarProp, &p->v);
226       return S_OK;
227     }
228     p = p->next;
229   }
230   return S_OK;
231 }
232 
233 HRESULT WINAPI IDxDiagContainerImpl_AddProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pVarProp) {
234   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
235   IDxDiagContainerImpl_Property* p = NULL;
236   IDxDiagContainerImpl_Property* pNew = NULL;
237 
238   TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pVarProp);
239 
240   if (NULL == pVarProp || NULL == pwszPropName) {
241     return E_INVALIDARG;
242   }
243 
244   pNew =  HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_Property));
245   if (NULL == pNew) {
246     return E_OUTOFMEMORY;
247   }
248   VariantInit(&pNew->v);
249   VariantCopy(&pNew->v, pVarProp);
250   pNew->vName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszPropName) + 1) * sizeof(WCHAR));
251   lstrcpyW(pNew->vName, pwszPropName);
252   pNew->next = NULL;
253 
254   p = This->properties;
255   if (NULL == p) {
256     This->properties = pNew;
257   } else {
258     while (NULL != p->next) {
259       p = p->next;
260     }
261     p->next = pNew;
262   }
263   ++This->nProperties;
264   return S_OK;
265 }
266 
267 HRESULT WINAPI IDxDiagContainerImpl_AddChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pszContName, PDXDIAGCONTAINER pSubCont) {
268   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
269   IDxDiagContainerImpl_SubContainer* p = NULL;
270   IDxDiagContainerImpl_SubContainer* pNew = NULL;
271 
272   TRACE("(%p, %s, %p)\n", iface, debugstr_w(pszContName), pSubCont);
273 
274   if (NULL == pSubCont || NULL == pszContName) {
275     return E_INVALIDARG;
276   }
277 
278   pNew =  HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_SubContainer));
279   if (NULL == pNew) {
280     return E_OUTOFMEMORY;
281   }
282   pNew->pCont = pSubCont;
283   pNew->contName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pszContName) + 1) * sizeof(WCHAR));
284   lstrcpyW(pNew->contName, pszContName);
285   pNew->next = NULL;
286 
287   p = This->subContainers;
288   if (NULL == p) {
289     This->subContainers = pNew;
290   } else {
291     while (NULL != p->next) {
292       p = p->next;
293     }
294     p->next = pNew;
295   }
296   ++This->nSubContainers;
297   return S_OK;
298 }
299 
300 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
301 {
302     IDxDiagContainerImpl_QueryInterface,
303     IDxDiagContainerImpl_AddRef,
304     IDxDiagContainerImpl_Release,
305     IDxDiagContainerImpl_GetNumberOfChildContainers,
306     IDxDiagContainerImpl_EnumChildContainerNames,
307     IDxDiagContainerImpl_GetChildContainer,
308     IDxDiagContainerImpl_GetNumberOfProps,
309     IDxDiagContainerImpl_EnumPropNames,
310     IDxDiagContainerImpl_GetProp
311 };
312 
313 
314 HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, LPVOID *ppobj) {
315   IDxDiagContainerImpl* container;
316 
317   TRACE("(%p, %p)\n", debugstr_guid(riid), ppobj);
318   
319   container = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl));
320   if (NULL == container) {
321     *ppobj = NULL;
322     return E_OUTOFMEMORY;
323   }
324   container->lpVtbl = &DxDiagContainer_Vtbl;
325   container->ref = 0; /* will be inited with QueryInterface */
326   return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)container, riid, ppobj);
327 }
328 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.