kernel32/tests: Add a test to check some fields in fake dlls.
[wine.git] / dlls / dpnet / threadpool.c
blob7e84a5afbb9ffb7a399fb17b38dbf70620e50c64
1 /*
2 * DirectPlay8 ThreadPool
4 * Copyright 2004 Raphael Junqueira
5 * Copyright 2008 Alexander N. Sørnes <alex@thehandofagony.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
25 #include <stdarg.h>
27 #define COBJMACROS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "objbase.h"
33 #include "wine/debug.h"
35 #include "dpnet_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
39 static PFNDPNMESSAGEHANDLER threadpool_msghandler = NULL;
40 static DWORD threadpool_flags = 0;
41 static void *threadpool_usercontext = NULL;
43 static inline IDirectPlay8ThreadPoolImpl *impl_from_IDirectPlay8ThreadPool(IDirectPlay8ThreadPool *iface)
45 return CONTAINING_RECORD(iface, IDirectPlay8ThreadPoolImpl, IDirectPlay8ThreadPool_iface);
48 /* IUnknown interface follows */
49 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_QueryInterface(IDirectPlay8ThreadPool *iface,
50 REFIID riid, void **ppobj)
52 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
54 if(IsEqualGUID(riid, &IID_IUnknown) ||
55 IsEqualGUID(riid, &IID_IDirectPlay8ThreadPool))
57 IUnknown_AddRef(iface);
58 *ppobj = This;
59 return DPN_OK;
62 WARN("(%p)->(%s,%p): not found\n", This, debugstr_guid(riid), ppobj);
63 return E_NOINTERFACE;
66 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_AddRef(IDirectPlay8ThreadPool *iface)
68 IDirectPlay8ThreadPoolImpl* This = impl_from_IDirectPlay8ThreadPool(iface);
69 ULONG RefCount = InterlockedIncrement(&This->ref);
71 return RefCount;
74 static ULONG WINAPI IDirectPlay8ThreadPoolImpl_Release(IDirectPlay8ThreadPool *iface)
76 IDirectPlay8ThreadPoolImpl* This = impl_from_IDirectPlay8ThreadPool(iface);
77 ULONG RefCount = InterlockedDecrement(&This->ref);
79 if(!RefCount)
80 HeapFree(GetProcessHeap(), 0, This);
82 return RefCount;
85 /* IDirectPlay8ThreadPool interface follows */
86 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Initialize(IDirectPlay8ThreadPool *iface,
87 void * const pvUserContext, const PFNDPNMESSAGEHANDLER pfn, const DWORD dwFlags)
89 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
91 TRACE("(%p)->(%p,%p,%x)\n", This, pvUserContext, pfn, dwFlags);
93 if(!pfn)
94 return DPNERR_INVALIDPARAM;
96 if(threadpool_msghandler)
97 return DPNERR_ALREADYINITIALIZED;
99 threadpool_msghandler = pfn;
100 threadpool_flags = dwFlags;
101 threadpool_usercontext = pvUserContext;
103 return DPN_OK;
106 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_Close(IDirectPlay8ThreadPool *iface,
107 const DWORD dwFlags)
109 IDirectPlay8ThreadPoolImpl *This = impl_from_IDirectPlay8ThreadPool(iface);
111 FIXME("(%p)->(%x)\n", This, dwFlags);
113 if(!threadpool_msghandler)
114 return DPNERR_UNINITIALIZED;
116 threadpool_msghandler = NULL;
118 return DPN_OK;
121 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_GetThreadCount(IDirectPlay8ThreadPool *iface,
122 const DWORD dwProcessorNum, DWORD * const pdwNumThreads, const DWORD dwFlags)
124 FIXME("(%p)->(%x,%p,%x): stub\n", iface, dwProcessorNum, pdwNumThreads, dwFlags);
125 *pdwNumThreads = 0;
126 return DPN_OK;
129 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_SetThreadCount(IDirectPlay8ThreadPool *iface,
130 const DWORD dwProcessorNum, const DWORD dwNumThreads, const DWORD dwFlags)
132 FIXME("(%p)->(%x,%x,%x): stub\n", iface, dwProcessorNum, dwNumThreads, dwFlags);
133 return DPN_OK;
136 static HRESULT WINAPI IDirectPlay8ThreadPoolImpl_DoWork(IDirectPlay8ThreadPool *iface,
137 const DWORD dwAllowedTimeSlice, const DWORD dwFlags)
139 static BOOL Run = FALSE;
141 if(!Run)
142 FIXME("(%p)->(%x,%x): stub\n", iface, dwAllowedTimeSlice, dwFlags);
144 Run = TRUE;
146 return DPN_OK;
149 static const IDirectPlay8ThreadPoolVtbl DirectPlay8ThreadPool_Vtbl =
151 IDirectPlay8ThreadPoolImpl_QueryInterface,
152 IDirectPlay8ThreadPoolImpl_AddRef,
153 IDirectPlay8ThreadPoolImpl_Release,
154 IDirectPlay8ThreadPoolImpl_Initialize,
155 IDirectPlay8ThreadPoolImpl_Close,
156 IDirectPlay8ThreadPoolImpl_GetThreadCount,
157 IDirectPlay8ThreadPoolImpl_SetThreadCount,
158 IDirectPlay8ThreadPoolImpl_DoWork
161 HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj)
163 IDirectPlay8ThreadPoolImpl* Client;
165 Client = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectPlay8ThreadPoolImpl));
167 if(Client == NULL)
169 *ppobj = NULL;
170 WARN("Not enough memory\n");
171 return E_OUTOFMEMORY;
174 Client->IDirectPlay8ThreadPool_iface.lpVtbl = &DirectPlay8ThreadPool_Vtbl;
175 Client->ref = 0;
177 return IDirectPlay8ThreadPoolImpl_QueryInterface(&Client->IDirectPlay8ThreadPool_iface, riid,
178 ppobj);