2 * Background Copy Job Interface for BITS
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);
26 static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
28 HeapFree(GetProcessHeap(), 0, This->displayName);
29 HeapFree(GetProcessHeap(), 0, This);
32 static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob* iface)
34 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
35 return InterlockedIncrement(&This->ref);
38 static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
39 IBackgroundCopyJob* iface, REFIID riid, LPVOID *ppvObject)
41 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
42 TRACE("IID: %s\n", debugstr_guid(riid));
44 if (IsEqualGUID(riid, &IID_IUnknown)
45 || IsEqualGUID(riid, &IID_IBackgroundCopyJob))
47 *ppvObject = &This->lpVtbl;
48 BITS_IBackgroundCopyJob_AddRef(iface);
56 static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob* iface)
58 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
59 ULONG ref = InterlockedDecrement(&This->ref);
62 BackgroundCopyJobDestructor(This);
67 /*** IBackgroundCopyJob methods ***/
69 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
70 IBackgroundCopyJob* iface,
72 BG_FILE_INFO *pFileSet)
74 FIXME("Not implemented\n");
78 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
79 IBackgroundCopyJob* iface,
83 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
84 IBackgroundCopyFile *pFile;
85 BackgroundCopyFileImpl *file;
88 /* We should return E_INVALIDARG in these cases. */
89 FIXME("Check for valid filenames and supported protocols\n");
91 res = BackgroundCopyFileConstructor(RemoteUrl, LocalName, (LPVOID *) &pFile);
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;
104 static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
105 IBackgroundCopyJob* iface,
106 IEnumBackgroundCopyFiles **ppEnum)
109 return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
112 static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
113 IBackgroundCopyJob* iface)
115 FIXME("Not implemented\n");
119 static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
120 IBackgroundCopyJob* iface)
122 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
124 if (This->state == BG_JOB_STATE_CANCELLED
125 || This->state == BG_JOB_STATE_ACKNOWLEDGED)
127 return BG_E_INVALID_STATE;
130 if (This->jobProgress.FilesTransferred == This->jobProgress.FilesTotal)
133 if (This->state == BG_JOB_STATE_CONNECTING
134 || This->state == BG_JOB_STATE_TRANSFERRING)
139 This->state = BG_JOB_STATE_QUEUED;
143 static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
144 IBackgroundCopyJob* iface)
146 FIXME("Not implemented\n");
150 static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
151 IBackgroundCopyJob* iface)
153 FIXME("Not implemented\n");
157 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
158 IBackgroundCopyJob* iface,
161 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
166 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
167 IBackgroundCopyJob* iface,
170 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
179 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
180 IBackgroundCopyJob* iface,
181 BG_JOB_PROGRESS *pVal)
183 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
188 pVal->BytesTotal = This->jobProgress.BytesTotal;
189 pVal->BytesTransferred = This->jobProgress.BytesTransferred;
190 pVal->FilesTotal = This->jobProgress.FilesTotal;
191 pVal->FilesTransferred = This->jobProgress.FilesTransferred;
196 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
197 IBackgroundCopyJob* iface,
200 FIXME("Not implemented\n");
204 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
205 IBackgroundCopyJob* iface,
208 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
217 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
218 IBackgroundCopyJob* iface,
219 IBackgroundCopyError **ppError)
221 FIXME("Not implemented\n");
225 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
226 IBackgroundCopyJob* iface,
229 FIXME("Not implemented\n");
233 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
234 IBackgroundCopyJob* iface,
237 FIXME("Not implemented\n");
241 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
242 IBackgroundCopyJob* iface,
245 BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
251 n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
252 *pVal = CoTaskMemAlloc(n);
254 return E_OUTOFMEMORY;
255 memcpy(*pVal, This->displayName, n);
259 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
260 IBackgroundCopyJob* iface,
263 FIXME("Not implemented\n");
267 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
268 IBackgroundCopyJob* iface,
271 FIXME("Not implemented\n");
275 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
276 IBackgroundCopyJob* iface,
279 FIXME("Not implemented\n");
283 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
284 IBackgroundCopyJob* iface,
285 BG_JOB_PRIORITY *pVal)
287 FIXME("Not implemented\n");
291 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
292 IBackgroundCopyJob* iface,
295 FIXME("Not implemented\n");
299 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
300 IBackgroundCopyJob* iface,
303 FIXME("Not implemented\n");
307 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
308 IBackgroundCopyJob* iface,
311 FIXME("Not implemented\n");
315 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
316 IBackgroundCopyJob* iface,
319 FIXME("Not implemented\n");
323 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
324 IBackgroundCopyJob* iface,
327 FIXME("Not implemented\n");
331 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
332 IBackgroundCopyJob* iface,
335 FIXME("Not implemented\n");
339 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
340 IBackgroundCopyJob* iface,
343 FIXME("Not implemented\n");
347 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
348 IBackgroundCopyJob* iface,
351 FIXME("Not implemented\n");
355 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
356 IBackgroundCopyJob* iface,
359 FIXME("Not implemented\n");
363 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
364 IBackgroundCopyJob* iface,
365 BG_JOB_PROXY_USAGE ProxyUsage,
366 const WCHAR *ProxyList,
367 const WCHAR *ProxyBypassList)
369 FIXME("Not implemented\n");
373 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
374 IBackgroundCopyJob* iface,
375 BG_JOB_PROXY_USAGE *pProxyUsage,
377 LPWSTR *pProxyBypassList)
379 FIXME("Not implemented\n");
383 static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
384 IBackgroundCopyJob* iface)
386 FIXME("Not implemented\n");
391 static const IBackgroundCopyJobVtbl BITS_IBackgroundCopyJob_Vtbl =
393 BITS_IBackgroundCopyJob_QueryInterface,
394 BITS_IBackgroundCopyJob_AddRef,
395 BITS_IBackgroundCopyJob_Release,
396 BITS_IBackgroundCopyJob_AddFileSet,
397 BITS_IBackgroundCopyJob_AddFile,
398 BITS_IBackgroundCopyJob_EnumFiles,
399 BITS_IBackgroundCopyJob_Suspend,
400 BITS_IBackgroundCopyJob_Resume,
401 BITS_IBackgroundCopyJob_Cancel,
402 BITS_IBackgroundCopyJob_Complete,
403 BITS_IBackgroundCopyJob_GetId,
404 BITS_IBackgroundCopyJob_GetType,
405 BITS_IBackgroundCopyJob_GetProgress,
406 BITS_IBackgroundCopyJob_GetTimes,
407 BITS_IBackgroundCopyJob_GetState,
408 BITS_IBackgroundCopyJob_GetError,
409 BITS_IBackgroundCopyJob_GetOwner,
410 BITS_IBackgroundCopyJob_SetDisplayName,
411 BITS_IBackgroundCopyJob_GetDisplayName,
412 BITS_IBackgroundCopyJob_SetDescription,
413 BITS_IBackgroundCopyJob_GetDescription,
414 BITS_IBackgroundCopyJob_SetPriority,
415 BITS_IBackgroundCopyJob_GetPriority,
416 BITS_IBackgroundCopyJob_SetNotifyFlags,
417 BITS_IBackgroundCopyJob_GetNotifyFlags,
418 BITS_IBackgroundCopyJob_SetNotifyInterface,
419 BITS_IBackgroundCopyJob_GetNotifyInterface,
420 BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
421 BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
422 BITS_IBackgroundCopyJob_SetNoProgressTimeout,
423 BITS_IBackgroundCopyJob_GetNoProgressTimeout,
424 BITS_IBackgroundCopyJob_GetErrorCount,
425 BITS_IBackgroundCopyJob_SetProxySettings,
426 BITS_IBackgroundCopyJob_GetProxySettings,
427 BITS_IBackgroundCopyJob_TakeOwnership,
430 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
431 GUID *pJobId, LPVOID *ppObj)
434 BackgroundCopyJobImpl *This;
437 TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
439 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
441 return E_OUTOFMEMORY;
443 This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
447 n = (lstrlenW(displayName) + 1) * sizeof *displayName;
448 This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
449 if (!This->displayName)
451 HeapFree(GetProcessHeap(), 0, This);
452 return E_OUTOFMEMORY;
454 memcpy(This->displayName, displayName, n);
456 hr = CoCreateGuid(&This->jobId);
459 HeapFree(GetProcessHeap(), 0, This->displayName);
460 HeapFree(GetProcessHeap(), 0, This);
463 *pJobId = This->jobId;
465 list_init(&This->files);
466 This->jobProgress.BytesTotal = 0;
467 This->jobProgress.BytesTransferred = 0;
468 This->jobProgress.FilesTotal = 0;
469 This->jobProgress.FilesTransferred = 0;
471 This->state = BG_JOB_STATE_SUSPENDED;
473 *ppObj = &This->lpVtbl;