ReactOS  0.4.13-dev-79-gcd489d8
container.c
Go to the documentation of this file.
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 
30 
31 static inline IDxDiagContainerImpl *impl_from_IDxDiagContainer(IDxDiagContainer *iface)
32 {
33  return CONTAINING_RECORD(iface, IDxDiagContainerImpl, IDxDiagContainer_iface);
34 }
35 
36 /* IDxDiagContainer IUnknown parts follow: */
38  void **ppobj)
39 {
41 
42  if (!ppobj) return E_INVALIDARG;
43 
45  || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
46  IUnknown_AddRef(iface);
47  *ppobj = This;
48  return S_OK;
49  }
50 
51  WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
52  *ppobj = NULL;
53  return E_NOINTERFACE;
54 }
55 
56 static ULONG WINAPI IDxDiagContainerImpl_AddRef(IDxDiagContainer *iface)
57 {
59  ULONG refCount = InterlockedIncrement(&This->ref);
60 
61  TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
62 
64 
65  return refCount;
66 }
67 
68 static ULONG WINAPI IDxDiagContainerImpl_Release(IDxDiagContainer *iface)
69 {
71  ULONG refCount = InterlockedDecrement(&This->ref);
72 
73  TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
74 
75  if (!refCount) {
78  }
79 
81 
82  return refCount;
83 }
84 
85 /* IDxDiagContainer Interface follow: */
87  DWORD *pdwCount)
88 {
90 
91  TRACE("(%p)\n", iface);
92  if (NULL == pdwCount) {
93  return E_INVALIDARG;
94  }
95  *pdwCount = This->cont->nSubContainers;
96  return S_OK;
97 }
98 
100  DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer)
101 {
104  DWORD i = 0;
105 
106  TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
107 
108  if (NULL == pwszContainer || 0 == cchContainer) {
109  return E_INVALIDARG;
110  }
111 
113  {
114  if (dwIndex == i) {
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)) ?
119  }
120  ++i;
121  }
122 
123  TRACE("Failed to find container name at specified index\n");
124  *pwszContainer = '\0';
125  return E_INVALIDARG;
126 }
127 
130 
132  {
133  if (0 == lstrcmpW(p->contName, pwszContainer)) {
134  *subcont = p;
135  return S_OK;
136  }
137  }
138 
139  return E_INVALIDARG;
140 }
141 
143  LPCWSTR pwszContainer, IDxDiagContainer **ppInstance)
144 {
146  IDxDiagContainerImpl_Container *pContainer = This->cont;
147  LPWSTR tmp, orig_tmp;
148  INT tmp_len;
149  WCHAR* cur;
151 
152  TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
153 
154  if (NULL == ppInstance || NULL == pwszContainer) {
155  return E_INVALIDARG;
156  }
157 
158  *ppInstance = NULL;
159 
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);
164 
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);
168  if (SUCCEEDED(hr))
169  TRACE("Succeeded in getting the container instance\n");
170  goto out;
171  }
172 
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);
179  if (FAILED(hr))
180  goto out;
181  cur++; /* go after '.' (just replaced by \0) */
182  tmp = cur;
183  cur = strchrW(tmp, '.');
184  }
185 
186  TRACE("Trying to get container %s\n", debugstr_w(tmp));
187  hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
188  if (SUCCEEDED(hr)) {
189  hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
190  if (SUCCEEDED(hr))
191  TRACE("Succeeded in getting the container instance\n");
192  }
193 
194 out:
195  HeapFree(GetProcessHeap(), 0, orig_tmp);
196  return hr;
197 }
198 
199 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer *iface,
200  DWORD *pdwCount)
201 {
203 
204  TRACE("(%p)\n", iface);
205  if (NULL == pdwCount) {
206  return E_INVALIDARG;
207  }
208  *pdwCount = This->cont->nProperties;
209  return S_OK;
210 }
211 
212 static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer *iface, DWORD dwIndex,
213  LPWSTR pwszPropName, DWORD cchPropName)
214 {
217  DWORD i = 0;
218 
219  TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszPropName, cchPropName);
220 
221  if (NULL == pwszPropName || 0 == cchPropName) {
222  return E_INVALIDARG;
223  }
224 
226  {
227  if (dwIndex == i) {
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)) ?
232  }
233  ++i;
234  }
235 
236  TRACE("Failed to find property name at specified index\n");
237  return E_INVALIDARG;
238 }
239 
240 static HRESULT WINAPI IDxDiagContainerImpl_GetProp(IDxDiagContainer *iface, LPCWSTR pwszPropName,
241  VARIANT *pvarProp)
242 {
245 
246  TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
247 
248  if (NULL == pvarProp || NULL == pwszPropName) {
249  return E_INVALIDARG;
250  }
251 
253  {
254  if (0 == lstrcmpW(p->propName, pwszPropName)) {
255  VariantInit(pvarProp);
256  return VariantCopy(pvarProp, &p->vProp);
257  }
258  }
259 
260  return E_INVALIDARG;
261 }
262 
263 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
264 {
274 };
275 
276 
279 
280  TRACE("(%s, %p)\n", debugstr_guid(riid), ppobj);
281 
283  if (NULL == container) {
284  *ppobj = NULL;
285  return E_OUTOFMEMORY;
286  }
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);
293 }
#define REFIID
Definition: guiddef.h:113
#define E_NOINTERFACE
Definition: winerror.h:2364
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
REFIID riid
Definition: precomp.h:44
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
#define IDxDiagProvider_Release(p)
Definition: dxdiag.h:61
#define DXDIAG_E_INSUFFICIENT_BUFFER
Definition: dxdiag.h:57
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
uint8_t entry
Definition: isohybrid.c:63
#define WARN(fmt,...)
Definition: debug.h:111
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:571
static ULONG WINAPI IDxDiagContainerImpl_AddRef(IDxDiagContainer *iface)
Definition: container.c:56
#define E_FAIL
Definition: ddrawi.h:102
int32_t INT
Definition: typedefs.h:56
static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer *iface, LPCWSTR pwszContainer, IDxDiagContainer **ppInstance)
Definition: container.c:142
static void DXDIAGN_UnlockModule(void)
#define lstrcpynW
Definition: compat.h:397
static void DXDIAGN_LockModule(void)
static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer *iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer)
Definition: container.c:99
struct container container
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(IDxDiagContainer *iface, REFIID riid, void **ppobj)
Definition: container.c:37
#define IDxDiagProvider_AddRef(p)
Definition: dxdiag.h:60
static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container *cont, LPCWSTR pwszContainer, IDxDiagContainerImpl_Container **subcont)
Definition: container.c:128
#define debugstr_w
Definition: kernel32.h:32
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer *iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName)
Definition: container.c:212
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
const GUID IID_IUnknown
#define WINAPI
Definition: msvc.h:8
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer *iface, DWORD *pdwCount)
Definition: container.c:199
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT WINAPI IDxDiagContainerImpl_GetProp(IDxDiagContainer *iface, LPCWSTR pwszPropName, VARIANT *pvarProp)
Definition: container.c:240
#define InterlockedDecrement
Definition: armddk.h:52
HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, IDxDiagContainerImpl_Container *cont, IDxDiagProvider *pProv, LPVOID *ppobj)
Definition: container.c:277
static ULONG WINAPI IDxDiagContainerImpl_Release(IDxDiagContainer *iface)
Definition: container.c:68
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
#define S_OK
Definition: intsafe.h:59
WINE_DEFAULT_DEBUG_CHANNEL(dxdiag)
#define InterlockedIncrement
Definition: armddk.h:53
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
static IDxDiagContainerImpl * impl_from_IDxDiagContainer(IDxDiagContainer *iface)
Definition: container.c:31
static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
Definition: container.c:263
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:751
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer *iface, DWORD *pdwCount)
Definition: container.c:86
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57