d3d9: Reorder the spec file.
[wine] / dlls / qmgr / job.c
1 /*
2  * Background Copy Job Interface for BITS
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
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
25
26 static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
27 {
28     HeapFree(GetProcessHeap(), 0, This->displayName);
29     HeapFree(GetProcessHeap(), 0, This);
30 }
31
32 static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob* iface)
33 {
34     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
35     return InterlockedIncrement(&This->ref);
36 }
37
38 static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
39     IBackgroundCopyJob* iface, REFIID riid, LPVOID *ppvObject)
40 {
41     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
42     TRACE("IID: %s\n", debugstr_guid(riid));
43
44     if (IsEqualGUID(riid, &IID_IUnknown)
45         || IsEqualGUID(riid, &IID_IBackgroundCopyJob))
46     {
47         *ppvObject = &This->lpVtbl;
48         BITS_IBackgroundCopyJob_AddRef(iface);
49         return S_OK;
50     }
51
52     *ppvObject = NULL;
53     return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob* iface)
57 {
58     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
59     ULONG ref = InterlockedDecrement(&This->ref);
60
61     if (ref == 0)
62         BackgroundCopyJobDestructor(This);
63
64     return ref;
65 }
66
67 /*** IBackgroundCopyJob methods ***/
68
69 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
70     IBackgroundCopyJob* iface,
71     ULONG cFileCount,
72     BG_FILE_INFO *pFileSet)
73 {
74     FIXME("Not implemented\n");
75     return E_NOTIMPL;
76 }
77
78 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
79     IBackgroundCopyJob* iface,
80     LPCWSTR RemoteUrl,
81     LPCWSTR LocalName)
82 {
83     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
84     IBackgroundCopyFile *pFile;
85     BackgroundCopyFileImpl *file;
86     HRESULT res;
87
88     /* We should return E_INVALIDARG in these cases.  */
89     FIXME("Check for valid filenames and supported protocols\n");
90
91     res = BackgroundCopyFileConstructor(RemoteUrl, LocalName, (LPVOID *) &pFile);
92     if (res != S_OK)
93         return res;
94
95     /* Add a reference to the file to file list */
96     IBackgroundCopyFile_AddRef(pFile);
97     file = (BackgroundCopyFileImpl *) pFile;
98     list_add_head(&This->files, &file->entryFromJob);
99     ++This->jobProgress.FilesTotal;
100
101     return S_OK;
102 }
103
104 static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
105     IBackgroundCopyJob* iface,
106     IEnumBackgroundCopyFiles **ppEnum)
107 {
108     TRACE("\n");
109     return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
110 }
111
112 static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
113     IBackgroundCopyJob* iface)
114 {
115     FIXME("Not implemented\n");
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
120     IBackgroundCopyJob* iface)
121 {
122     FIXME("Not implemented\n");
123     return E_NOTIMPL;
124 }
125
126 static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
127     IBackgroundCopyJob* iface)
128 {
129     FIXME("Not implemented\n");
130     return E_NOTIMPL;
131 }
132
133 static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
134     IBackgroundCopyJob* iface)
135 {
136     FIXME("Not implemented\n");
137     return E_NOTIMPL;
138 }
139
140 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
141     IBackgroundCopyJob* iface,
142     GUID *pVal)
143 {
144     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
145     memcpy(pVal, &This->jobId, sizeof *pVal);
146     return S_OK;
147 }
148
149 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
150     IBackgroundCopyJob* iface,
151     BG_JOB_TYPE *pVal)
152 {
153     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
154
155     if (!pVal)
156         return E_INVALIDARG;
157
158     *pVal = This->type;
159     return S_OK;
160 }
161
162 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
163     IBackgroundCopyJob* iface,
164     BG_JOB_PROGRESS *pVal)
165 {
166     FIXME("Not implemented\n");
167     return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
171     IBackgroundCopyJob* iface,
172     BG_JOB_TIMES *pVal)
173 {
174     FIXME("Not implemented\n");
175     return E_NOTIMPL;
176 }
177
178 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
179     IBackgroundCopyJob* iface,
180     BG_JOB_STATE *pVal)
181 {
182     FIXME("Not implemented\n");
183     return E_NOTIMPL;
184 }
185
186 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
187     IBackgroundCopyJob* iface,
188     IBackgroundCopyError **ppError)
189 {
190     FIXME("Not implemented\n");
191     return E_NOTIMPL;
192 }
193
194 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
195     IBackgroundCopyJob* iface,
196     LPWSTR *pVal)
197 {
198     FIXME("Not implemented\n");
199     return E_NOTIMPL;
200 }
201
202 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
203     IBackgroundCopyJob* iface,
204     LPCWSTR Val)
205 {
206     FIXME("Not implemented\n");
207     return E_NOTIMPL;
208 }
209
210 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
211     IBackgroundCopyJob* iface,
212     LPWSTR *pVal)
213 {
214     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
215     int n;
216
217     if (!pVal)
218         return E_INVALIDARG;
219
220     n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
221     *pVal = CoTaskMemAlloc(n);
222     if (*pVal == NULL)
223         return E_OUTOFMEMORY;
224     memcpy(*pVal, This->displayName, n);
225     return S_OK;
226 }
227
228 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
229     IBackgroundCopyJob* iface,
230     LPCWSTR Val)
231 {
232     FIXME("Not implemented\n");
233     return E_NOTIMPL;
234 }
235
236 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
237     IBackgroundCopyJob* iface,
238     LPWSTR *pVal)
239 {
240     FIXME("Not implemented\n");
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
245     IBackgroundCopyJob* iface,
246     BG_JOB_PRIORITY Val)
247 {
248     FIXME("Not implemented\n");
249     return E_NOTIMPL;
250 }
251
252 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
253     IBackgroundCopyJob* iface,
254     BG_JOB_PRIORITY *pVal)
255 {
256     FIXME("Not implemented\n");
257     return E_NOTIMPL;
258 }
259
260 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
261     IBackgroundCopyJob* iface,
262     ULONG Val)
263 {
264     FIXME("Not implemented\n");
265     return E_NOTIMPL;
266 }
267
268 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
269     IBackgroundCopyJob* iface,
270     ULONG *pVal)
271 {
272     FIXME("Not implemented\n");
273     return E_NOTIMPL;
274 }
275
276 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
277     IBackgroundCopyJob* iface,
278     IUnknown *Val)
279 {
280     FIXME("Not implemented\n");
281     return E_NOTIMPL;
282 }
283
284 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
285     IBackgroundCopyJob* iface,
286     IUnknown **pVal)
287 {
288     FIXME("Not implemented\n");
289     return E_NOTIMPL;
290 }
291
292 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
293     IBackgroundCopyJob* iface,
294     ULONG Seconds)
295 {
296     FIXME("Not implemented\n");
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
301     IBackgroundCopyJob* iface,
302     ULONG *Seconds)
303 {
304     FIXME("Not implemented\n");
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
309     IBackgroundCopyJob* iface,
310     ULONG Seconds)
311 {
312     FIXME("Not implemented\n");
313     return E_NOTIMPL;
314 }
315
316 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
317     IBackgroundCopyJob* iface,
318     ULONG *Seconds)
319 {
320     FIXME("Not implemented\n");
321     return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
325     IBackgroundCopyJob* iface,
326     ULONG *Errors)
327 {
328     FIXME("Not implemented\n");
329     return E_NOTIMPL;
330 }
331
332 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
333     IBackgroundCopyJob* iface,
334     BG_JOB_PROXY_USAGE ProxyUsage,
335     const WCHAR *ProxyList,
336     const WCHAR *ProxyBypassList)
337 {
338     FIXME("Not implemented\n");
339     return E_NOTIMPL;
340 }
341
342 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
343     IBackgroundCopyJob* iface,
344     BG_JOB_PROXY_USAGE *pProxyUsage,
345     LPWSTR *pProxyList,
346     LPWSTR *pProxyBypassList)
347 {
348     FIXME("Not implemented\n");
349     return E_NOTIMPL;
350 }
351
352 static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
353     IBackgroundCopyJob* iface)
354 {
355     FIXME("Not implemented\n");
356     return E_NOTIMPL;
357 }
358
359
360 static const IBackgroundCopyJobVtbl BITS_IBackgroundCopyJob_Vtbl =
361 {
362     BITS_IBackgroundCopyJob_QueryInterface,
363     BITS_IBackgroundCopyJob_AddRef,
364     BITS_IBackgroundCopyJob_Release,
365     BITS_IBackgroundCopyJob_AddFileSet,
366     BITS_IBackgroundCopyJob_AddFile,
367     BITS_IBackgroundCopyJob_EnumFiles,
368     BITS_IBackgroundCopyJob_Suspend,
369     BITS_IBackgroundCopyJob_Resume,
370     BITS_IBackgroundCopyJob_Cancel,
371     BITS_IBackgroundCopyJob_Complete,
372     BITS_IBackgroundCopyJob_GetId,
373     BITS_IBackgroundCopyJob_GetType,
374     BITS_IBackgroundCopyJob_GetProgress,
375     BITS_IBackgroundCopyJob_GetTimes,
376     BITS_IBackgroundCopyJob_GetState,
377     BITS_IBackgroundCopyJob_GetError,
378     BITS_IBackgroundCopyJob_GetOwner,
379     BITS_IBackgroundCopyJob_SetDisplayName,
380     BITS_IBackgroundCopyJob_GetDisplayName,
381     BITS_IBackgroundCopyJob_SetDescription,
382     BITS_IBackgroundCopyJob_GetDescription,
383     BITS_IBackgroundCopyJob_SetPriority,
384     BITS_IBackgroundCopyJob_GetPriority,
385     BITS_IBackgroundCopyJob_SetNotifyFlags,
386     BITS_IBackgroundCopyJob_GetNotifyFlags,
387     BITS_IBackgroundCopyJob_SetNotifyInterface,
388     BITS_IBackgroundCopyJob_GetNotifyInterface,
389     BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
390     BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
391     BITS_IBackgroundCopyJob_SetNoProgressTimeout,
392     BITS_IBackgroundCopyJob_GetNoProgressTimeout,
393     BITS_IBackgroundCopyJob_GetErrorCount,
394     BITS_IBackgroundCopyJob_SetProxySettings,
395     BITS_IBackgroundCopyJob_GetProxySettings,
396     BITS_IBackgroundCopyJob_TakeOwnership,
397 };
398
399 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
400                                      GUID *pJobId, LPVOID *ppObj)
401 {
402     HRESULT hr;
403     BackgroundCopyJobImpl *This;
404     int n;
405
406     TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
407
408     This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
409     if (!This)
410         return E_OUTOFMEMORY;
411
412     This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
413     This->ref = 1;
414     This->type = type;
415
416     n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
417     This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
418     if (!This->displayName)
419     {
420         HeapFree(GetProcessHeap(), 0, This);
421         return E_OUTOFMEMORY;
422     }
423     memcpy(This->displayName, displayName, n);
424
425     hr = CoCreateGuid(&This->jobId);
426     if (FAILED(hr))
427     {
428         HeapFree(GetProcessHeap(), 0, This->displayName);
429         HeapFree(GetProcessHeap(), 0, This);
430         return hr;
431     }
432     memcpy(pJobId, &This->jobId, sizeof(GUID));
433
434     list_init(&This->files);
435     This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
436     This->jobProgress.BytesTransferred = 0;
437     This->jobProgress.FilesTotal = 0;
438     This->jobProgress.FilesTransferred = 0;
439
440     *ppObj = &This->lpVtbl;
441     return S_OK;
442 }