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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr
);
28 IEnumBackgroundCopyJobs IEnumBackgroundCopyJobs_iface
;
30 IBackgroundCopyJob
**jobs
;
33 } EnumBackgroundCopyJobsImpl
;
35 static inline EnumBackgroundCopyJobsImpl
*impl_from_IEnumBackgroundCopyJobs(IEnumBackgroundCopyJobs
*iface
)
37 return CONTAINING_RECORD(iface
, EnumBackgroundCopyJobsImpl
, IEnumBackgroundCopyJobs_iface
);
40 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_QueryInterface(IEnumBackgroundCopyJobs
*iface
,
41 REFIID riid
, void **ppv
)
43 TRACE("(%p,%s,%p)\n", iface
, debugstr_guid(riid
), ppv
);
45 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IEnumBackgroundCopyJobs
))
48 IEnumBackgroundCopyJobs_AddRef(iface
);
56 static ULONG WINAPI
BITS_IEnumBackgroundCopyJobs_AddRef(IEnumBackgroundCopyJobs
*iface
)
58 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
59 ULONG ref
= InterlockedIncrement(&This
->ref
);
61 TRACE("(%p) ref=%d\n", This
, ref
);
66 static ULONG WINAPI
BITS_IEnumBackgroundCopyJobs_Release(IEnumBackgroundCopyJobs
*iface
)
68 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
69 ULONG ref
= InterlockedDecrement(&This
->ref
);
72 TRACE("(%p) ref=%d\n", This
, ref
);
75 for(i
= 0; i
< This
->numJobs
; i
++)
76 IBackgroundCopyJob_Release(This
->jobs
[i
]);
77 HeapFree(GetProcessHeap(), 0, This
->jobs
);
78 HeapFree(GetProcessHeap(), 0, This
);
84 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_Next(IEnumBackgroundCopyJobs
*iface
, ULONG celt
,
85 IBackgroundCopyJob
**rgelt
, ULONG
*pceltFetched
)
87 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
90 IBackgroundCopyJob
*job
;
92 fetched
= min(celt
, This
->numJobs
- This
->indexJobs
);
94 *pceltFetched
= fetched
;
97 /* We need to initialize this array if the caller doesn't request
98 the length because length_is will default to celt. */
99 for (i
= 0; i
< celt
; ++i
)
102 /* pceltFetched can only be NULL if celt is 1 */
107 /* Fill in the array of objects */
108 for (i
= 0; i
< fetched
; ++i
)
110 job
= This
->jobs
[This
->indexJobs
++];
111 IBackgroundCopyJob_AddRef(job
);
115 return fetched
== celt
? S_OK
: S_FALSE
;
118 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_Skip(IEnumBackgroundCopyJobs
*iface
, ULONG celt
)
120 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
122 if (This
->numJobs
- This
->indexJobs
< celt
)
124 This
->indexJobs
= This
->numJobs
;
128 This
->indexJobs
+= celt
;
132 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_Reset(IEnumBackgroundCopyJobs
*iface
)
134 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
139 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_Clone(IEnumBackgroundCopyJobs
*iface
,
140 IEnumBackgroundCopyJobs
**ppenum
)
142 FIXME("Not implemented\n");
146 static HRESULT WINAPI
BITS_IEnumBackgroundCopyJobs_GetCount(IEnumBackgroundCopyJobs
*iface
,
149 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
150 *puCount
= This
->numJobs
;
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
enum_copy_job_create(BackgroundCopyManagerImpl
*qmgr
, IEnumBackgroundCopyJobs
**enumjob
)
168 EnumBackgroundCopyJobsImpl
*This
;
169 BackgroundCopyJobImpl
*job
;
172 TRACE("%p, %p)\n", qmgr
, enumjob
);
174 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
176 return E_OUTOFMEMORY
;
177 This
->IEnumBackgroundCopyJobs_iface
.lpVtbl
= &BITS_IEnumBackgroundCopyJobs_Vtbl
;
180 /* Create array of jobs */
183 EnterCriticalSection(&qmgr
->cs
);
184 This
->numJobs
= list_count(&qmgr
->jobs
);
186 if (0 < This
->numJobs
)
188 This
->jobs
= HeapAlloc(GetProcessHeap(), 0,
189 This
->numJobs
* sizeof *This
->jobs
);
192 LeaveCriticalSection(&qmgr
->cs
);
193 HeapFree(GetProcessHeap(), 0, This
);
194 return E_OUTOFMEMORY
;
201 LIST_FOR_EACH_ENTRY(job
, &qmgr
->jobs
, BackgroundCopyJobImpl
, entryFromQmgr
)
203 IBackgroundCopyJob
*job_iface
= (IBackgroundCopyJob
*)&job
->IBackgroundCopyJob2_iface
;
204 IBackgroundCopyJob_AddRef(job_iface
);
205 This
->jobs
[i
++] = job_iface
;
207 LeaveCriticalSection(&qmgr
->cs
);
209 *enumjob
= &This
->IEnumBackgroundCopyJobs_iface
;