msxml3: Support setting unlimited nesting depth for a reader.
[wine/multimedia.git] / dlls / qmgr / enum_jobs.c
blob85aca47c496b077113becbe9a4e24a7cf38afd7c
1 /*
2 * Queue Manager (BITS) Job Enumerator
4 * Copyright 2007 Google (Roy Shea)
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
21 #include "qmgr.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
26 static void EnumBackgroundCopyJobsDestructor(EnumBackgroundCopyJobsImpl *This)
28 ULONG i;
30 for(i = 0; i < This->numJobs; i++)
31 IBackgroundCopyJob_Release(This->jobs[i]);
33 HeapFree(GetProcessHeap(), 0, This->jobs);
34 HeapFree(GetProcessHeap(), 0, This);
37 static ULONG WINAPI BITS_IEnumBackgroundCopyJobs_AddRef(
38 IEnumBackgroundCopyJobs* iface)
40 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
41 return InterlockedIncrement(&This->ref);
44 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_QueryInterface(
45 IEnumBackgroundCopyJobs* iface,
46 REFIID riid,
47 void **ppvObject)
49 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
50 TRACE("IID: %s\n", debugstr_guid(riid));
52 if (IsEqualGUID(riid, &IID_IUnknown)
53 || IsEqualGUID(riid, &IID_IEnumBackgroundCopyJobs))
55 *ppvObject = &This->lpVtbl;
56 BITS_IEnumBackgroundCopyJobs_AddRef(iface);
57 return S_OK;
60 *ppvObject = NULL;
61 return E_NOINTERFACE;
64 static ULONG WINAPI BITS_IEnumBackgroundCopyJobs_Release(
65 IEnumBackgroundCopyJobs* iface)
67 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
68 ULONG ref = InterlockedDecrement(&This->ref);
70 if (ref == 0)
71 EnumBackgroundCopyJobsDestructor(This);
73 return ref;
76 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Next(
77 IEnumBackgroundCopyJobs* iface,
78 ULONG celt,
79 IBackgroundCopyJob **rgelt,
80 ULONG *pceltFetched)
82 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
83 ULONG fetched;
84 ULONG i;
85 IBackgroundCopyJob *job;
87 fetched = min(celt, This->numJobs - This->indexJobs);
88 if (pceltFetched)
89 *pceltFetched = fetched;
90 else
92 /* We need to initialize this array if the caller doesn't request
93 the length because length_is will default to celt. */
94 for (i = 0; i < celt; ++i)
95 rgelt[i] = NULL;
97 /* pceltFetched can only be NULL if celt is 1 */
98 if (celt != 1)
99 return E_INVALIDARG;
102 /* Fill in the array of objects */
103 for (i = 0; i < fetched; ++i)
105 job = This->jobs[This->indexJobs++];
106 IBackgroundCopyJob_AddRef(job);
107 rgelt[i] = job;
110 return fetched == celt ? S_OK : S_FALSE;
113 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Skip(
114 IEnumBackgroundCopyJobs* iface,
115 ULONG celt)
117 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
119 if (This->numJobs - This->indexJobs < celt)
121 This->indexJobs = This->numJobs;
122 return S_FALSE;
125 This->indexJobs += celt;
126 return S_OK;
129 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Reset(
130 IEnumBackgroundCopyJobs* iface)
132 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
133 This->indexJobs = 0;
134 return S_OK;
137 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Clone(
138 IEnumBackgroundCopyJobs* iface,
139 IEnumBackgroundCopyJobs **ppenum)
141 FIXME("Not implemented\n");
142 return E_NOTIMPL;
145 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_GetCount(
146 IEnumBackgroundCopyJobs* iface,
147 ULONG *puCount)
149 EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
150 *puCount = This->numJobs;
151 return S_OK;
154 static const IEnumBackgroundCopyJobsVtbl BITS_IEnumBackgroundCopyJobs_Vtbl =
156 BITS_IEnumBackgroundCopyJobs_QueryInterface,
157 BITS_IEnumBackgroundCopyJobs_AddRef,
158 BITS_IEnumBackgroundCopyJobs_Release,
159 BITS_IEnumBackgroundCopyJobs_Next,
160 BITS_IEnumBackgroundCopyJobs_Skip,
161 BITS_IEnumBackgroundCopyJobs_Reset,
162 BITS_IEnumBackgroundCopyJobs_Clone,
163 BITS_IEnumBackgroundCopyJobs_GetCount
166 HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj,
167 IBackgroundCopyManager* copyManager)
169 BackgroundCopyManagerImpl *qmgr = (BackgroundCopyManagerImpl *) copyManager;
170 EnumBackgroundCopyJobsImpl *This;
171 BackgroundCopyJobImpl *job;
172 ULONG i;
174 TRACE("%p, %p)\n", ppObj, copyManager);
176 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
177 if (!This)
178 return E_OUTOFMEMORY;
179 This->lpVtbl = &BITS_IEnumBackgroundCopyJobs_Vtbl;
180 This->ref = 1;
182 /* Create array of jobs */
183 This->indexJobs = 0;
185 EnterCriticalSection(&qmgr->cs);
186 This->numJobs = list_count(&qmgr->jobs);
188 if (0 < This->numJobs)
190 This->jobs = HeapAlloc(GetProcessHeap(), 0,
191 This->numJobs * sizeof *This->jobs);
192 if (!This->jobs)
194 LeaveCriticalSection(&qmgr->cs);
195 HeapFree(GetProcessHeap(), 0, This);
196 return E_OUTOFMEMORY;
199 else
200 This->jobs = NULL;
202 i = 0;
203 LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
205 IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job;
206 IBackgroundCopyJob_AddRef(iJob);
207 This->jobs[i++] = iJob;
209 LeaveCriticalSection(&qmgr->cs);
211 *ppObj = &This->lpVtbl;
212 return S_OK;