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
25 IEnumBackgroundCopyJobs IEnumBackgroundCopyJobs_iface
;
27 IBackgroundCopyJob3
**jobs
;
30 } EnumBackgroundCopyJobsImpl
;
32 static inline EnumBackgroundCopyJobsImpl
*impl_from_IEnumBackgroundCopyJobs(IEnumBackgroundCopyJobs
*iface
)
34 return CONTAINING_RECORD(iface
, EnumBackgroundCopyJobsImpl
, IEnumBackgroundCopyJobs_iface
);
37 static HRESULT WINAPI
EnumBackgroundCopyJobs_QueryInterface(IEnumBackgroundCopyJobs
*iface
,
38 REFIID riid
, void **ppv
)
40 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
42 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
44 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IEnumBackgroundCopyJobs
))
47 IEnumBackgroundCopyJobs_AddRef(iface
);
55 static ULONG WINAPI
EnumBackgroundCopyJobs_AddRef(IEnumBackgroundCopyJobs
*iface
)
57 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
58 ULONG ref
= InterlockedIncrement(&This
->ref
);
60 TRACE("(%p)->(%d)\n", This
, ref
);
65 static ULONG WINAPI
EnumBackgroundCopyJobs_Release(IEnumBackgroundCopyJobs
*iface
)
67 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
68 ULONG ref
= InterlockedDecrement(&This
->ref
);
71 TRACE("(%p)->(%d)\n", This
, ref
);
74 for(i
= 0; i
< This
->numJobs
; i
++)
75 IBackgroundCopyJob3_Release(This
->jobs
[i
]);
76 HeapFree(GetProcessHeap(), 0, This
->jobs
);
77 HeapFree(GetProcessHeap(), 0, This
);
83 static HRESULT WINAPI
EnumBackgroundCopyJobs_Next(IEnumBackgroundCopyJobs
*iface
, ULONG celt
,
84 IBackgroundCopyJob
**rgelt
, ULONG
*pceltFetched
)
86 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
89 IBackgroundCopyJob3
*job
;
91 TRACE("(%p)->(%d %p %p)\n", This
, celt
, rgelt
, pceltFetched
);
93 fetched
= min(celt
, This
->numJobs
- This
->indexJobs
);
95 *pceltFetched
= fetched
;
98 /* We need to initialize this array if the caller doesn't request
99 the length because length_is will default to celt. */
100 for (i
= 0; i
< celt
; ++i
)
103 /* pceltFetched can only be NULL if celt is 1 */
108 /* Fill in the array of objects */
109 for (i
= 0; i
< fetched
; ++i
)
111 job
= This
->jobs
[This
->indexJobs
++];
112 IBackgroundCopyJob3_AddRef(job
);
113 rgelt
[i
] = (IBackgroundCopyJob
*)job
;
116 return fetched
== celt
? S_OK
: S_FALSE
;
119 static HRESULT WINAPI
EnumBackgroundCopyJobs_Skip(IEnumBackgroundCopyJobs
*iface
, ULONG celt
)
121 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
123 TRACE("(%p)->(%d)\n", This
, celt
);
125 if (This
->numJobs
- This
->indexJobs
< celt
)
127 This
->indexJobs
= This
->numJobs
;
131 This
->indexJobs
+= celt
;
135 static HRESULT WINAPI
EnumBackgroundCopyJobs_Reset(IEnumBackgroundCopyJobs
*iface
)
137 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
139 TRACE("(%p)\n", This
);
145 static HRESULT WINAPI
EnumBackgroundCopyJobs_Clone(IEnumBackgroundCopyJobs
*iface
,
146 IEnumBackgroundCopyJobs
**ppenum
)
148 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
149 FIXME("(%p)->(%p): stub\n", This
, ppenum
);
153 static HRESULT WINAPI
EnumBackgroundCopyJobs_GetCount(IEnumBackgroundCopyJobs
*iface
,
156 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
158 TRACE("(%p)->(%p)\n", This
, puCount
);
160 *puCount
= This
->numJobs
;
164 static const IEnumBackgroundCopyJobsVtbl EnumBackgroundCopyJobsVtbl
=
166 EnumBackgroundCopyJobs_QueryInterface
,
167 EnumBackgroundCopyJobs_AddRef
,
168 EnumBackgroundCopyJobs_Release
,
169 EnumBackgroundCopyJobs_Next
,
170 EnumBackgroundCopyJobs_Skip
,
171 EnumBackgroundCopyJobs_Reset
,
172 EnumBackgroundCopyJobs_Clone
,
173 EnumBackgroundCopyJobs_GetCount
176 HRESULT
enum_copy_job_create(BackgroundCopyManagerImpl
*qmgr
, IEnumBackgroundCopyJobs
**enumjob
)
178 EnumBackgroundCopyJobsImpl
*This
;
179 BackgroundCopyJobImpl
*job
;
182 TRACE("%p, %p)\n", qmgr
, enumjob
);
184 This
= HeapAlloc(GetProcessHeap(), 0, sizeof *This
);
186 return E_OUTOFMEMORY
;
187 This
->IEnumBackgroundCopyJobs_iface
.lpVtbl
= &EnumBackgroundCopyJobsVtbl
;
190 /* Create array of jobs */
193 EnterCriticalSection(&qmgr
->cs
);
194 This
->numJobs
= list_count(&qmgr
->jobs
);
196 if (0 < This
->numJobs
)
198 This
->jobs
= HeapAlloc(GetProcessHeap(), 0,
199 This
->numJobs
* sizeof *This
->jobs
);
202 LeaveCriticalSection(&qmgr
->cs
);
203 HeapFree(GetProcessHeap(), 0, This
);
204 return E_OUTOFMEMORY
;
211 LIST_FOR_EACH_ENTRY(job
, &qmgr
->jobs
, BackgroundCopyJobImpl
, entryFromQmgr
)
213 IBackgroundCopyJob3_AddRef(&job
->IBackgroundCopyJob3_iface
);
214 This
->jobs
[i
++] = &job
->IBackgroundCopyJob3_iface
;
216 LeaveCriticalSection(&qmgr
->cs
);
218 *enumjob
= &This
->IEnumBackgroundCopyJobs_iface
;