d3dx9_30: Add stub for D3DXCpuOptimizations.
[wine.git] / dlls / dpnet / address.c
blob7df7ad6f4b1334fb72fd22f2203ec60a47de1080
1 /*
2 * DirectPlay8 Address
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 #include <stdarg.h>
26 #define COBJMACROS
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "objbase.h"
33 #include "wine/unicode.h"
34 #include "wine/debug.h"
36 #include "dplay8.h"
37 #include "dpnet_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
42 static inline void *heap_alloc(size_t len)
44 return HeapAlloc(GetProcessHeap(), 0, len);
47 static inline BOOL heap_free(void *mem)
49 return HeapFree(GetProcessHeap(), 0, mem);
52 static inline LPWSTR heap_strdupW(LPCWSTR str)
54 LPWSTR ret = NULL;
56 if(str) {
57 DWORD size;
59 size = (strlenW(str)+1)*sizeof(WCHAR);
60 ret = heap_alloc(size);
61 if(ret)
62 memcpy(ret, str, size);
65 return ret;
68 static char *heap_strdupA( const char *str )
70 char *ret;
72 if (!str) return NULL;
73 if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
74 return ret;
77 static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface)
79 return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface);
82 /* IDirectPlay8Address IUnknown parts follow: */
83 static HRESULT WINAPI IDirectPlay8AddressImpl_QueryInterface(IDirectPlay8Address *iface,
84 REFIID riid, void **ppv)
86 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDirectPlay8Address)) {
87 IUnknown_AddRef(iface);
88 *ppv = iface;
89 return DPN_OK;
92 WARN("(%p)->(%s,%p),not found\n", iface, debugstr_guid(riid), ppv);
93 return E_NOINTERFACE;
96 static ULONG WINAPI IDirectPlay8AddressImpl_AddRef(IDirectPlay8Address *iface)
98 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
99 ULONG ref = InterlockedIncrement(&This->ref);
101 TRACE("(%p) ref=%u\n", This, ref);
103 return ref;
106 static ULONG WINAPI IDirectPlay8AddressImpl_Release(IDirectPlay8Address *iface)
108 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
109 ULONG ref = InterlockedDecrement(&This->ref);
111 TRACE("(%p) ref=%u\n", This, ref);
113 if (!ref)
115 struct component *entry, *entry2;
117 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->components, struct component, entry)
119 switch(entry->type)
121 case DPNA_DATATYPE_STRING:
122 heap_free(entry->data.string);
123 break;
124 case DPNA_DATATYPE_STRING_ANSI:
125 heap_free(entry->data.ansi);
126 break;
127 case DPNA_DATATYPE_BINARY:
128 heap_free(entry->data.binary);
129 break;
132 HeapFree(GetProcessHeap(), 0, entry);
135 HeapFree(GetProcessHeap(), 0, This);
137 return ref;
140 /* returns name of given GUID */
141 static const char *debugstr_SP(const GUID *id) {
142 static const guid_info guids[] = {
143 /* CLSIDs */
144 GE(CLSID_DP8SP_IPX),
145 GE(CLSID_DP8SP_TCPIP),
146 GE(CLSID_DP8SP_SERIAL),
147 GE(CLSID_DP8SP_MODEM)
149 unsigned int i;
151 if (!id) return "(null)";
153 for (i = 0; i < sizeof(guids)/sizeof(guids[0]); i++) {
154 if (IsEqualGUID(id, guids[i].guid))
155 return guids[i].name;
157 /* if we didn't find it, act like standard debugstr_guid */
158 return debugstr_guid(id);
161 /* IDirectPlay8Address Interface follow: */
163 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLW(IDirectPlay8Address *iface,
164 WCHAR *pwszSourceURL)
166 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
167 TRACE("(%p, %s): stub\n", This, debugstr_w(pwszSourceURL));
168 return DPN_OK;
171 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromURLA(IDirectPlay8Address *iface,
172 CHAR *pszSourceURL)
174 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
175 TRACE("(%p, %s): stub\n", This, pszSourceURL);
176 return DPN_OK;
179 static HRESULT WINAPI IDirectPlay8AddressImpl_Duplicate(IDirectPlay8Address *iface,
180 IDirectPlay8Address **ppdpaNewAddress)
182 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
183 IDirectPlay8Address *dup;
184 HRESULT hr;
186 TRACE("(%p, %p)\n", This, ppdpaNewAddress);
188 if(!ppdpaNewAddress)
189 return E_POINTER;
191 hr = DPNET_CreateDirectPlay8Address(NULL, NULL, &IID_IDirectPlay8Address, (LPVOID*)&dup);
192 if(hr == S_OK)
194 IDirectPlay8AddressImpl *DupThis = impl_from_IDirectPlay8Address(dup);
195 struct component *entry;
197 DupThis->SP_guid = This->SP_guid;
198 DupThis->init = This->init;
200 LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
202 hr = IDirectPlay8Address_AddComponent(dup, entry->name, &entry->data, entry->size, entry->type);
203 if(hr != S_OK)
204 ERR("Failed to copy component: %s - 0x%08x\n", debugstr_w(entry->name), hr);
207 *ppdpaNewAddress = dup;
210 return hr;
213 static HRESULT WINAPI IDirectPlay8AddressImpl_SetEqual(IDirectPlay8Address *iface,
214 IDirectPlay8Address *pdpaAddress)
216 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
217 TRACE("(%p, %p): stub\n", This, pdpaAddress);
218 return DPN_OK;
221 static HRESULT WINAPI IDirectPlay8AddressImpl_IsEqual(IDirectPlay8Address *iface,
222 IDirectPlay8Address *pdpaAddress)
224 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
225 TRACE("(%p, %p): stub\n", This, pdpaAddress);
226 return DPN_OK;
229 static HRESULT WINAPI IDirectPlay8AddressImpl_Clear(IDirectPlay8Address *iface)
231 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
232 TRACE("(%p): stub\n", This);
233 return DPN_OK;
236 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLW(IDirectPlay8Address *iface, WCHAR *pwszURL,
237 DWORD *pdwNumChars)
239 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
240 TRACE("(%p): stub\n", This);
241 return DPN_OK;
244 static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface, CHAR *pszURL,
245 DWORD *pdwNumChars)
247 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
248 TRACE("(%p): stub\n", This);
249 return DPN_OK;
252 static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP)
254 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
256 TRACE("(%p, %p)\n", iface, pguidSP);
258 if(!pguidSP)
259 return DPNERR_INVALIDPOINTER;
261 if(!This->init)
262 return DPNERR_DOESNOTEXIST;
264 *pguidSP = This->SP_guid;
265 return DPN_OK;
268 static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *iface,
269 void *pvUserData, DWORD *pdwBufferSize)
271 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
272 TRACE("(%p): stub\n", This);
273 return DPN_OK;
276 static HRESULT WINAPI IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address *iface,
277 const GUID *const pguidSP)
279 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
281 TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP));
283 if(!pguidSP)
284 return DPNERR_INVALIDPOINTER;
286 This->init = TRUE;
287 This->SP_guid = *pguidSP;
289 IDirectPlay8Address_AddComponent(iface, DPNA_KEY_PROVIDER, &This->SP_guid, sizeof(GUID), DPNA_DATATYPE_GUID);
291 return DPN_OK;
294 static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *iface,
295 const void *const pvUserData, const DWORD dwDataSize)
297 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
298 TRACE("(%p): stub\n", This);
299 return DPN_OK;
302 static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address *iface,
303 DWORD *pdwNumComponents)
305 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
306 TRACE("(%p): stub\n", This);
308 if(!pdwNumComponents)
309 return DPNERR_INVALIDPOINTER;
311 *pdwNumComponents = list_count(&This->components);
313 return DPN_OK;
316 static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address *iface,
317 const WCHAR *const pwszName, void *pvBuffer, DWORD *pdwBufferSize, DWORD *pdwDataType)
319 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
320 TRACE("(%p): stub\n", This);
321 return DPN_OK;
324 static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByIndex(IDirectPlay8Address *iface,
325 const DWORD dwComponentID, WCHAR *pwszName, DWORD *pdwNameLen, void *pvBuffer,
326 DWORD *pdwBufferSize, DWORD *pdwDataType)
328 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
329 TRACE("(%p): stub\n", This);
330 return DPN_OK;
333 static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address *iface,
334 const WCHAR *const pwszName, const void* const lpvData, const DWORD dwDataSize,
335 const DWORD dwDataType)
337 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
338 struct component *entry;
339 BOOL found = FALSE;
341 TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
343 if (NULL == lpvData)
344 return DPNERR_INVALIDPOINTER;
346 LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
348 if (lstrcmpW(pwszName, entry->name) == 0)
350 TRACE("Found %s\n", debugstr_w(pwszName));
351 found = TRUE;
353 break;
357 if(!found)
359 /* Create a new one */
360 entry = heap_alloc(sizeof(struct component));
361 entry->name = heap_strdupW(pwszName);
362 entry->type = dwDataType;
364 list_add_tail(&This->components, &entry->entry);
367 entry->size = dwDataSize;
368 switch (dwDataType)
370 case DPNA_DATATYPE_DWORD:
371 if (sizeof(DWORD) != dwDataSize)
372 return DPNERR_INVALIDPARAM;
374 entry->data.value = *(DWORD*)lpvData;
375 TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
376 break;
377 case DPNA_DATATYPE_GUID:
378 if (sizeof(GUID) != dwDataSize)
379 return DPNERR_INVALIDPARAM;
381 entry->data.guid = *(GUID*)lpvData;
382 TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
383 break;
384 case DPNA_DATATYPE_STRING:
385 heap_free(entry->data.string);
387 entry->data.string = heap_strdupW((WCHAR*)lpvData);
388 TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, debugstr_w((WCHAR*)lpvData));
389 break;
390 case DPNA_DATATYPE_STRING_ANSI:
391 heap_free(entry->data.ansi);
393 entry->data.ansi = heap_strdupA((CHAR*)lpvData);
394 TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
395 break;
396 case DPNA_DATATYPE_BINARY:
397 heap_free(entry->data.binary);
399 entry->data.binary = heap_alloc(dwDataSize);
400 memcpy(entry->data.binary, lpvData, dwDataSize);
401 TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
402 break;
405 return DPN_OK;
408 static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
409 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
410 TRACE("(%p): stub\n", This);
411 return DPN_OK;
414 static HRESULT WINAPI IDirectPlay8AddressImpl_SetDevice(IDirectPlay8Address *iface,
415 const GUID *const devGuid)
417 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
418 TRACE("(%p, %s): stub\n", This, debugstr_guid(devGuid));
419 return DPN_OK;
422 static HRESULT WINAPI IDirectPlay8AddressImpl_BuildFromDirectPlay4Address(IDirectPlay8Address *iface,
423 void *pvAddress, DWORD dwDataSize)
425 IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
426 TRACE("(%p): stub\n", This);
427 return DPN_OK;
430 static const IDirectPlay8AddressVtbl DirectPlay8Address_Vtbl =
432 IDirectPlay8AddressImpl_QueryInterface,
433 IDirectPlay8AddressImpl_AddRef,
434 IDirectPlay8AddressImpl_Release,
435 IDirectPlay8AddressImpl_BuildFromURLW,
436 IDirectPlay8AddressImpl_BuildFromURLA,
437 IDirectPlay8AddressImpl_Duplicate,
438 IDirectPlay8AddressImpl_SetEqual,
439 IDirectPlay8AddressImpl_IsEqual,
440 IDirectPlay8AddressImpl_Clear,
441 IDirectPlay8AddressImpl_GetURLW,
442 IDirectPlay8AddressImpl_GetURLA,
443 IDirectPlay8AddressImpl_GetSP,
444 IDirectPlay8AddressImpl_GetUserData,
445 IDirectPlay8AddressImpl_SetSP,
446 IDirectPlay8AddressImpl_SetUserData,
447 IDirectPlay8AddressImpl_GetNumComponents,
448 IDirectPlay8AddressImpl_GetComponentByName,
449 IDirectPlay8AddressImpl_GetComponentByIndex,
450 IDirectPlay8AddressImpl_AddComponent,
451 IDirectPlay8AddressImpl_GetDevice,
452 IDirectPlay8AddressImpl_SetDevice,
453 IDirectPlay8AddressImpl_BuildFromDirectPlay4Address
456 HRESULT DPNET_CreateDirectPlay8Address(IClassFactory *iface, IUnknown *pUnkOuter, REFIID riid, LPVOID *ppobj)
458 IDirectPlay8AddressImpl* client;
459 HRESULT ret;
461 TRACE("(%p, %s, %p)\n", pUnkOuter, debugstr_guid(riid), ppobj);
463 *ppobj = NULL;
465 client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8AddressImpl));
466 if (!client)
467 return E_OUTOFMEMORY;
469 client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
470 client->ref = 1;
472 list_init(&client->components);
474 ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
475 IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);
477 return ret;