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 IBackgroundCopyJob4
**jobs
;
33 } EnumBackgroundCopyJobsImpl
;
35 static inline EnumBackgroundCopyJobsImpl
*impl_from_IEnumBackgroundCopyJobs(IEnumBackgroundCopyJobs
*iface
)
37 return CONTAINING_RECORD(iface
, EnumBackgroundCopyJobsImpl
, IEnumBackgroundCopyJobs_iface
);
40 static HRESULT WINAPI
EnumBackgroundCopyJobs_QueryInterface(IEnumBackgroundCopyJobs
*iface
,
41 REFIID riid
, void **ppv
)
43 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
45 TRACE("(%p)->(%s, %p)\n", This
, debugstr_guid(riid
), ppv
);
47 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IEnumBackgroundCopyJobs
))
50 IEnumBackgroundCopyJobs_AddRef(iface
);
58 static ULONG WINAPI
EnumBackgroundCopyJobs_AddRef(IEnumBackgroundCopyJobs
*iface
)
60 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
61 ULONG ref
= InterlockedIncrement(&This
->ref
);
63 TRACE("(%p)->(%ld)\n", This
, ref
);
68 static ULONG WINAPI
EnumBackgroundCopyJobs_Release(IEnumBackgroundCopyJobs
*iface
)
70 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
71 ULONG ref
= InterlockedDecrement(&This
->ref
);
74 TRACE("(%p)->(%ld)\n", This
, ref
);
77 for(i
= 0; i
< This
->numJobs
; i
++)
78 IBackgroundCopyJob4_Release(This
->jobs
[i
]);
86 static HRESULT WINAPI
EnumBackgroundCopyJobs_Next(IEnumBackgroundCopyJobs
*iface
, ULONG celt
,
87 IBackgroundCopyJob
**rgelt
, ULONG
*pceltFetched
)
89 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
93 TRACE("(%p)->(%ld %p %p)\n", This
, celt
, rgelt
, pceltFetched
);
95 fetched
= min(celt
, This
->numJobs
- This
->indexJobs
);
97 *pceltFetched
= fetched
;
100 /* We need to initialize this array if the caller doesn't request
101 the length because length_is will default to celt. */
102 for (i
= 0; i
< celt
; ++i
)
105 /* pceltFetched can only be NULL if celt is 1 */
110 /* Fill in the array of objects */
111 for (i
= 0; i
< fetched
; ++i
)
113 rgelt
[i
] = (IBackgroundCopyJob
*)This
->jobs
[This
->indexJobs
++];
114 IBackgroundCopyJob_AddRef(rgelt
[i
]);
117 return fetched
== celt
? S_OK
: S_FALSE
;
120 static HRESULT WINAPI
EnumBackgroundCopyJobs_Skip(IEnumBackgroundCopyJobs
*iface
, ULONG celt
)
122 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
124 TRACE("(%p)->(%ld)\n", This
, celt
);
126 if (This
->numJobs
- This
->indexJobs
< celt
)
128 This
->indexJobs
= This
->numJobs
;
132 This
->indexJobs
+= celt
;
136 static HRESULT WINAPI
EnumBackgroundCopyJobs_Reset(IEnumBackgroundCopyJobs
*iface
)
138 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
140 TRACE("(%p)\n", This
);
146 static HRESULT WINAPI
EnumBackgroundCopyJobs_Clone(IEnumBackgroundCopyJobs
*iface
,
147 IEnumBackgroundCopyJobs
**ppenum
)
149 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
150 FIXME("(%p)->(%p): stub\n", This
, ppenum
);
154 static HRESULT WINAPI
EnumBackgroundCopyJobs_GetCount(IEnumBackgroundCopyJobs
*iface
,
157 EnumBackgroundCopyJobsImpl
*This
= impl_from_IEnumBackgroundCopyJobs(iface
);
159 TRACE("(%p)->(%p)\n", This
, puCount
);
161 *puCount
= This
->numJobs
;
165 static const IEnumBackgroundCopyJobsVtbl EnumBackgroundCopyJobsVtbl
=
167 EnumBackgroundCopyJobs_QueryInterface
,
168 EnumBackgroundCopyJobs_AddRef
,
169 EnumBackgroundCopyJobs_Release
,
170 EnumBackgroundCopyJobs_Next
,
171 EnumBackgroundCopyJobs_Skip
,
172 EnumBackgroundCopyJobs_Reset
,
173 EnumBackgroundCopyJobs_Clone
,
174 EnumBackgroundCopyJobs_GetCount
177 HRESULT
enum_copy_job_create(BackgroundCopyManagerImpl
*qmgr
, IEnumBackgroundCopyJobs
**enumjob
)
179 EnumBackgroundCopyJobsImpl
*This
;
180 BackgroundCopyJobImpl
*job
;
183 TRACE("%p, %p)\n", qmgr
, enumjob
);
185 This
= malloc(sizeof(*This
));
187 return E_OUTOFMEMORY
;
188 This
->IEnumBackgroundCopyJobs_iface
.lpVtbl
= &EnumBackgroundCopyJobsVtbl
;
191 /* Create array of jobs */
194 EnterCriticalSection(&qmgr
->cs
);
195 This
->numJobs
= list_count(&qmgr
->jobs
);
197 if (0 < This
->numJobs
)
199 This
->jobs
= malloc(This
->numJobs
* sizeof *This
->jobs
);
202 LeaveCriticalSection(&qmgr
->cs
);
204 return E_OUTOFMEMORY
;
211 LIST_FOR_EACH_ENTRY(job
, &qmgr
->jobs
, BackgroundCopyJobImpl
, entryFromQmgr
)
213 IBackgroundCopyJob4_AddRef(&job
->IBackgroundCopyJob4_iface
);
214 This
->jobs
[i
++] = &job
->IBackgroundCopyJob4_iface
;
216 LeaveCriticalSection(&qmgr
->cs
);
218 *enumjob
= &This
->IEnumBackgroundCopyJobs_iface
;