ReactOS 0.4.17-dev-966-gf06eace
enum_jobs.c
Go to the documentation of this file.
1/*
2 * Queue Manager (BITS) Job Enumerator
3 *
4 * Copyright 2007 Google (Roy Shea)
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "qmgr.h"
22#include "wine/debug.h"
23
25
26typedef struct
27{
34
36{
37 return CONTAINING_RECORD(iface, EnumBackgroundCopyJobsImpl, IEnumBackgroundCopyJobs_iface);
38}
39
41 REFIID riid, void **ppv)
42{
44
45 TRACE("(%p)->(%s, %p)\n", This, debugstr_guid(riid), ppv);
46
47 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumBackgroundCopyJobs))
48 {
49 *ppv = iface;
50 IEnumBackgroundCopyJobs_AddRef(iface);
51 return S_OK;
52 }
53
54 *ppv = NULL;
55 return E_NOINTERFACE;
56}
57
59{
62
63 TRACE("(%p)->(%ld)\n", This, ref);
64
65 return ref;
66}
67
69{
72 ULONG i;
73
74 TRACE("(%p)->(%ld)\n", This, ref);
75
76 if (ref == 0) {
77 for(i = 0; i < This->numJobs; i++)
78 IBackgroundCopyJob4_Release(This->jobs[i]);
79 free(This->jobs);
80 free(This);
81 }
82
83 return ref;
84}
85
87 IBackgroundCopyJob **rgelt, ULONG *pceltFetched)
88{
90 ULONG fetched;
91 ULONG i;
92
93 TRACE("(%p)->(%ld %p %p)\n", This, celt, rgelt, pceltFetched);
94
95 fetched = min(celt, This->numJobs - This->indexJobs);
96 if (pceltFetched)
97 *pceltFetched = fetched;
98 else
99 {
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)
103 rgelt[i] = NULL;
104
105 /* pceltFetched can only be NULL if celt is 1 */
106 if (celt != 1)
107 return E_INVALIDARG;
108 }
109
110 /* Fill in the array of objects */
111 for (i = 0; i < fetched; ++i)
112 {
113 rgelt[i] = (IBackgroundCopyJob *)This->jobs[This->indexJobs++];
114 IBackgroundCopyJob_AddRef(rgelt[i]);
115 }
116
117 return fetched == celt ? S_OK : S_FALSE;
118}
119
121{
123
124 TRACE("(%p)->(%ld)\n", This, celt);
125
126 if (This->numJobs - This->indexJobs < celt)
127 {
128 This->indexJobs = This->numJobs;
129 return S_FALSE;
130 }
131
132 This->indexJobs += celt;
133 return S_OK;
134}
135
137{
139
140 TRACE("(%p)\n", This);
141
142 This->indexJobs = 0;
143 return S_OK;
144}
145
148{
150 FIXME("(%p)->(%p): stub\n", This, ppenum);
151 return E_NOTIMPL;
152}
153
155 ULONG *puCount)
156{
158
159 TRACE("(%p)->(%p)\n", This, puCount);
160
161 *puCount = This->numJobs;
162 return S_OK;
163}
164
165static const IEnumBackgroundCopyJobsVtbl EnumBackgroundCopyJobsVtbl =
166{
175};
176
178{
181 ULONG i;
182
183 TRACE("%p, %p)\n", qmgr, enumjob);
184
185 This = malloc(sizeof(*This));
186 if (!This)
187 return E_OUTOFMEMORY;
188 This->IEnumBackgroundCopyJobs_iface.lpVtbl = &EnumBackgroundCopyJobsVtbl;
189 This->ref = 1;
190
191 /* Create array of jobs */
192 This->indexJobs = 0;
193
194 EnterCriticalSection(&qmgr->cs);
195 This->numJobs = list_count(&qmgr->jobs);
196
197 if (0 < This->numJobs)
198 {
199 This->jobs = malloc(This->numJobs * sizeof *This->jobs);
200 if (!This->jobs)
201 {
202 LeaveCriticalSection(&qmgr->cs);
203 free(This);
204 return E_OUTOFMEMORY;
205 }
206 }
207 else
208 This->jobs = NULL;
209
210 i = 0;
211 LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
212 {
213 IBackgroundCopyJob4_AddRef(&job->IBackgroundCopyJob4_iface);
214 This->jobs[i++] = &job->IBackgroundCopyJob4_iface;
215 }
216 LeaveCriticalSection(&qmgr->cs);
217
218 *enumjob = &This->IEnumBackgroundCopyJobs_iface;
219 return S_OK;
220}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
const GUID IID_IUnknown
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
static HRESULT WINAPI EnumBackgroundCopyJobs_Clone(IEnumBackgroundCopyJobs *iface, IEnumBackgroundCopyJobs **ppenum)
Definition: enum_jobs.c:146
static HRESULT WINAPI EnumBackgroundCopyJobs_GetCount(IEnumBackgroundCopyJobs *iface, ULONG *puCount)
Definition: enum_jobs.c:154
HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr, IEnumBackgroundCopyJobs **enumjob)
Definition: enum_jobs.c:177
static HRESULT WINAPI EnumBackgroundCopyJobs_Skip(IEnumBackgroundCopyJobs *iface, ULONG celt)
Definition: enum_jobs.c:120
static ULONG WINAPI EnumBackgroundCopyJobs_Release(IEnumBackgroundCopyJobs *iface)
Definition: enum_jobs.c:68
static HRESULT WINAPI EnumBackgroundCopyJobs_Next(IEnumBackgroundCopyJobs *iface, ULONG celt, IBackgroundCopyJob **rgelt, ULONG *pceltFetched)
Definition: enum_jobs.c:86
static EnumBackgroundCopyJobsImpl * impl_from_IEnumBackgroundCopyJobs(IEnumBackgroundCopyJobs *iface)
Definition: enum_jobs.c:35
static HRESULT WINAPI EnumBackgroundCopyJobs_QueryInterface(IEnumBackgroundCopyJobs *iface, REFIID riid, void **ppv)
Definition: enum_jobs.c:40
static ULONG WINAPI EnumBackgroundCopyJobs_AddRef(IEnumBackgroundCopyJobs *iface)
Definition: enum_jobs.c:58
static const IEnumBackgroundCopyJobsVtbl EnumBackgroundCopyJobsVtbl
Definition: enum_jobs.c:165
static HRESULT WINAPI EnumBackgroundCopyJobs_Reset(IEnumBackgroundCopyJobs *iface)
Definition: enum_jobs.c:136
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define debugstr_guid
Definition: kernel32.h:35
static HANDLE job
Definition: process.c:79
#define min(a, b)
Definition: monoChain.cc:55
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
__WINE_SERVER_LIST_INLINE unsigned int list_count(const struct list *list)
Definition: list.h:157
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
#define TRACE(s)
Definition: solgame.cpp:4
struct list jobs
Definition: qmgr.h:91
CRITICAL_SECTION cs
Definition: qmgr.h:89
IBackgroundCopyJob4 ** jobs
Definition: enum_jobs.c:30
IEnumBackgroundCopyJobs IEnumBackgroundCopyJobs_iface
Definition: enum_jobs.c:28
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
#define E_NOINTERFACE
Definition: winerror.h:3479