job.c 16.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Background Copy Job Interface for BITS
 *
 * Copyright 2007 Google (Roy Shea)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

21 22 23 24 25
#include <stdarg.h>

#include "windef.h"
#include "winbase.h"

26 27 28 29 30 31 32
#include "qmgr.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(qmgr);

static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
{
33
    This->cs.DebugInfo->Spare[0] = 0;
34
    DeleteCriticalSection(&This->cs);
35
    HeapFree(GetProcessHeap(), 0, This->displayName);
36 37 38
    HeapFree(GetProcessHeap(), 0, This);
}

39
static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
40 41 42 43 44 45
{
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    return InterlockedIncrement(&This->ref);
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
46
    IBackgroundCopyJob2 *iface, REFIID riid, LPVOID *ppvObject)
47 48 49 50 51
{
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    TRACE("IID: %s\n", debugstr_guid(riid));

    if (IsEqualGUID(riid, &IID_IUnknown)
52 53
        || IsEqualGUID(riid, &IID_IBackgroundCopyJob)
        || IsEqualGUID(riid, &IID_IBackgroundCopyJob2))
54 55 56 57 58 59 60 61 62 63
    {
        *ppvObject = &This->lpVtbl;
        BITS_IBackgroundCopyJob_AddRef(iface);
        return S_OK;
    }

    *ppvObject = NULL;
    return E_NOINTERFACE;
}

64
static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
65 66 67 68 69 70 71 72 73 74 75 76 77
{
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    ULONG ref = InterlockedDecrement(&This->ref);

    if (ref == 0)
        BackgroundCopyJobDestructor(This);

    return ref;
}

/*** IBackgroundCopyJob methods ***/

static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
78
    IBackgroundCopyJob2 *iface,
79 80 81
    ULONG cFileCount,
    BG_FILE_INFO *pFileSet)
{
82 83 84 85 86
    ULONG i;
    for (i = 0; i < cFileCount; ++i)
    {
        HRESULT hr = IBackgroundCopyJob_AddFile(iface, pFileSet[i].RemoteName,
                                                pFileSet[i].LocalName);
87
        if (FAILED(hr))
88 89 90
            return hr;
    }
    return S_OK;
91 92 93
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
94
    IBackgroundCopyJob2 *iface,
95 96 97
    LPCWSTR RemoteUrl,
    LPCWSTR LocalName)
{
98 99 100 101 102 103 104 105
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    IBackgroundCopyFile *pFile;
    BackgroundCopyFileImpl *file;
    HRESULT res;

    /* We should return E_INVALIDARG in these cases.  */
    FIXME("Check for valid filenames and supported protocols\n");

106
    res = BackgroundCopyFileConstructor(This, RemoteUrl, LocalName, (LPVOID *) &pFile);
107 108 109 110 111 112
    if (res != S_OK)
        return res;

    /* Add a reference to the file to file list */
    IBackgroundCopyFile_AddRef(pFile);
    file = (BackgroundCopyFileImpl *) pFile;
113
    EnterCriticalSection(&This->cs);
114
    list_add_head(&This->files, &file->entryFromJob);
115
    This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
116
    ++This->jobProgress.FilesTotal;
117
    LeaveCriticalSection(&This->cs);
118 119

    return S_OK;
120 121 122
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
123
    IBackgroundCopyJob2 *iface,
124
    IEnumBackgroundCopyFiles **ppEnum)
125
{
126 127
    TRACE("\n");
    return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
128 129 130
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
131
    IBackgroundCopyJob2 *iface)
132 133 134 135 136 137
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
138
    IBackgroundCopyJob2 *iface)
139
{
140
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
141
    HRESULT rv = S_OK;
142

143
    EnterCriticalSection(&globalMgr.cs);
144 145 146
    if (This->state == BG_JOB_STATE_CANCELLED
        || This->state == BG_JOB_STATE_ACKNOWLEDGED)
    {
147
        rv = BG_E_INVALID_STATE;
148
    }
149
    else if (This->jobProgress.FilesTransferred == This->jobProgress.FilesTotal)
150
    {
151
        rv = BG_E_EMPTY;
152
    }
153 154 155 156
    else if (This->state != BG_JOB_STATE_CONNECTING
             && This->state != BG_JOB_STATE_TRANSFERRING)
    {
        This->state = BG_JOB_STATE_QUEUED;
157
        SetEvent(globalMgr.jobEvent);
158 159
    }
    LeaveCriticalSection(&globalMgr.cs);
160

161
    return rv;
162 163 164
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
165
    IBackgroundCopyJob2 *iface)
166 167 168 169 170 171
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
172
    IBackgroundCopyJob2 *iface)
173
{
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    HRESULT rv = S_OK;

    EnterCriticalSection(&This->cs);

    if (This->state == BG_JOB_STATE_CANCELLED
        || This->state == BG_JOB_STATE_ACKNOWLEDGED)
    {
        rv = BG_E_INVALID_STATE;
    }
    else
    {
        BackgroundCopyFileImpl *file;
        LIST_FOR_EACH_ENTRY(file, &This->files, BackgroundCopyFileImpl, entryFromJob)
        {
            if (file->fileProgress.Completed)
            {
                if (!MoveFileExW(file->tempFileName, file->info.LocalName,
                                 (MOVEFILE_COPY_ALLOWED
                                  | MOVEFILE_REPLACE_EXISTING
                                  | MOVEFILE_WRITE_THROUGH)))
                {
                    ERR("Couldn't rename file %s -> %s\n",
                        debugstr_w(file->tempFileName),
                        debugstr_w(file->info.LocalName));
                    rv = BG_S_PARTIAL_COMPLETE;
                }
            }
            else
                rv = BG_S_PARTIAL_COMPLETE;
        }
    }

    This->state = BG_JOB_STATE_ACKNOWLEDGED;
    LeaveCriticalSection(&This->cs);

    return rv;
211 212 213
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
214
    IBackgroundCopyJob2 *iface,
215 216
    GUID *pVal)
{
217
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
218
    *pVal = This->jobId;
219
    return S_OK;
220 221 222
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
223
    IBackgroundCopyJob2 *iface,
224 225
    BG_JOB_TYPE *pVal)
{
226 227 228 229 230 231 232
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;

    if (!pVal)
        return E_INVALIDARG;

    *pVal = This->type;
    return S_OK;
233 234 235
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
236
    IBackgroundCopyJob2 *iface,
237 238
    BG_JOB_PROGRESS *pVal)
{
239 240 241 242 243
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;

    if (!pVal)
        return E_INVALIDARG;

244
    EnterCriticalSection(&This->cs);
245 246 247 248
    pVal->BytesTotal = This->jobProgress.BytesTotal;
    pVal->BytesTransferred = This->jobProgress.BytesTransferred;
    pVal->FilesTotal = This->jobProgress.FilesTotal;
    pVal->FilesTransferred = This->jobProgress.FilesTransferred;
249
    LeaveCriticalSection(&This->cs);
250 251

    return S_OK;
252 253 254
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
255
    IBackgroundCopyJob2 *iface,
256 257 258 259 260 261 262
    BG_JOB_TIMES *pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
263
    IBackgroundCopyJob2 *iface,
264 265
    BG_JOB_STATE *pVal)
{
266 267 268 269 270
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;

    if (!pVal)
        return E_INVALIDARG;

271
    /* Don't think we need a critical section for this */
272 273
    *pVal = This->state;
    return S_OK;
274 275 276
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
277
    IBackgroundCopyJob2 *iface,
278 279 280 281 282 283 284
    IBackgroundCopyError **ppError)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
285
    IBackgroundCopyJob2 *iface,
286 287 288 289 290 291 292
    LPWSTR *pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
293
    IBackgroundCopyJob2 *iface,
294 295 296 297 298 299 300
    LPCWSTR Val)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
301
    IBackgroundCopyJob2 *iface,
302 303
    LPWSTR *pVal)
{
304 305 306 307 308 309 310 311 312 313 314 315
    BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
    int n;

    if (!pVal)
        return E_INVALIDARG;

    n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
    *pVal = CoTaskMemAlloc(n);
    if (*pVal == NULL)
        return E_OUTOFMEMORY;
    memcpy(*pVal, This->displayName, n);
    return S_OK;
316 317 318
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
319
    IBackgroundCopyJob2 *iface,
320 321 322 323 324 325 326
    LPCWSTR Val)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
327
    IBackgroundCopyJob2 *iface,
328 329 330 331 332 333 334
    LPWSTR *pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
335
    IBackgroundCopyJob2 *iface,
336 337
    BG_JOB_PRIORITY Val)
{
338 339
    FIXME("(%p,0x%08x) stub\n", iface, Val);
    return S_OK;
340 341 342
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
343
    IBackgroundCopyJob2 *iface,
344 345 346 347 348 349 350
    BG_JOB_PRIORITY *pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
351
    IBackgroundCopyJob2 *iface,
352 353 354 355 356 357 358
    ULONG Val)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
359
    IBackgroundCopyJob2 *iface,
360 361 362 363 364 365 366
    ULONG *pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
367
    IBackgroundCopyJob2 *iface,
368 369 370 371 372 373 374
    IUnknown *Val)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
375
    IBackgroundCopyJob2 *iface,
376 377 378 379 380 381 382
    IUnknown **pVal)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
383
    IBackgroundCopyJob2 *iface,
384 385
    ULONG Seconds)
{
386 387
    FIXME("%u\n", Seconds);
    return S_OK;
388 389 390
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
391
    IBackgroundCopyJob2 *iface,
392 393
    ULONG *Seconds)
{
394 395 396
    FIXME("%p\n", Seconds);
    *Seconds = 30;
    return S_OK;
397 398 399
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
400
    IBackgroundCopyJob2 *iface,
401 402
    ULONG Seconds)
{
403 404
    FIXME("%u\n", Seconds);
    return S_OK;
405 406 407
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
408
    IBackgroundCopyJob2 *iface,
409 410
    ULONG *Seconds)
{
411 412 413
    FIXME("%p\n", Seconds);
    *Seconds = 900;
    return S_OK;
414 415 416
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
417
    IBackgroundCopyJob2 *iface,
418 419 420 421 422 423 424
    ULONG *Errors)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
425
    IBackgroundCopyJob2 *iface,
426 427 428 429 430 431 432 433 434
    BG_JOB_PROXY_USAGE ProxyUsage,
    const WCHAR *ProxyList,
    const WCHAR *ProxyBypassList)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
435
    IBackgroundCopyJob2 *iface,
436 437 438 439 440 441 442 443 444
    BG_JOB_PROXY_USAGE *pProxyUsage,
    LPWSTR *pProxyList,
    LPWSTR *pProxyBypassList)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
445
    IBackgroundCopyJob2 *iface)
446 447 448 449 450
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

451 452 453 454 455 456 457 458 459 460 461
static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyCmdLine(
    IBackgroundCopyJob2 *iface,
    LPCWSTR prog,
    LPCWSTR params)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyCmdLine(
    IBackgroundCopyJob2 *iface,
462 463
    LPWSTR *prog,
    LPWSTR *params)
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyProgress(
    IBackgroundCopyJob2 *iface,
    BG_JOB_REPLY_PROGRESS *progress)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyData(
    IBackgroundCopyJob2 *iface,
    byte **pBuffer,
    UINT64 *pLength)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetReplyFileName(
    IBackgroundCopyJob2 *iface,
    LPCWSTR filename)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyFileName(
    IBackgroundCopyJob2 *iface,
    LPWSTR *pFilename)
{
    FIXME("Not implemented\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_SetCredentials(
    IBackgroundCopyJob2 *iface,
    BG_AUTH_CREDENTIALS *cred)
{
    FIXME("Not implemented\n");
507
    return S_OK;
508 509 510 511 512 513 514 515
}

static HRESULT WINAPI BITS_IBackgroundCopyJob_RemoveCredentials(
    IBackgroundCopyJob2 *iface,
    BG_AUTH_TARGET target,
    BG_AUTH_SCHEME scheme)
{
    FIXME("Not implemented\n");
516
    return S_OK;
517
}
518

519
static const IBackgroundCopyJob2Vtbl BITS_IBackgroundCopyJob_Vtbl =
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
{
    BITS_IBackgroundCopyJob_QueryInterface,
    BITS_IBackgroundCopyJob_AddRef,
    BITS_IBackgroundCopyJob_Release,
    BITS_IBackgroundCopyJob_AddFileSet,
    BITS_IBackgroundCopyJob_AddFile,
    BITS_IBackgroundCopyJob_EnumFiles,
    BITS_IBackgroundCopyJob_Suspend,
    BITS_IBackgroundCopyJob_Resume,
    BITS_IBackgroundCopyJob_Cancel,
    BITS_IBackgroundCopyJob_Complete,
    BITS_IBackgroundCopyJob_GetId,
    BITS_IBackgroundCopyJob_GetType,
    BITS_IBackgroundCopyJob_GetProgress,
    BITS_IBackgroundCopyJob_GetTimes,
    BITS_IBackgroundCopyJob_GetState,
    BITS_IBackgroundCopyJob_GetError,
    BITS_IBackgroundCopyJob_GetOwner,
    BITS_IBackgroundCopyJob_SetDisplayName,
    BITS_IBackgroundCopyJob_GetDisplayName,
    BITS_IBackgroundCopyJob_SetDescription,
    BITS_IBackgroundCopyJob_GetDescription,
    BITS_IBackgroundCopyJob_SetPriority,
    BITS_IBackgroundCopyJob_GetPriority,
    BITS_IBackgroundCopyJob_SetNotifyFlags,
    BITS_IBackgroundCopyJob_GetNotifyFlags,
    BITS_IBackgroundCopyJob_SetNotifyInterface,
    BITS_IBackgroundCopyJob_GetNotifyInterface,
    BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
    BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
    BITS_IBackgroundCopyJob_SetNoProgressTimeout,
    BITS_IBackgroundCopyJob_GetNoProgressTimeout,
    BITS_IBackgroundCopyJob_GetErrorCount,
    BITS_IBackgroundCopyJob_SetProxySettings,
    BITS_IBackgroundCopyJob_GetProxySettings,
    BITS_IBackgroundCopyJob_TakeOwnership,
556 557 558 559 560 561 562 563
    BITS_IBackgroundCopyJob_SetNotifyCmdLine,
    BITS_IBackgroundCopyJob_GetNotifyCmdLine,
    BITS_IBackgroundCopyJob_GetReplyProgress,
    BITS_IBackgroundCopyJob_GetReplyData,
    BITS_IBackgroundCopyJob_SetReplyFileName,
    BITS_IBackgroundCopyJob_GetReplyFileName,
    BITS_IBackgroundCopyJob_SetCredentials,
    BITS_IBackgroundCopyJob_RemoveCredentials
564
};
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579

HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
                                     GUID *pJobId, LPVOID *ppObj)
{
    HRESULT hr;
    BackgroundCopyJobImpl *This;
    int n;

    TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);

    This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
    if (!This)
        return E_OUTOFMEMORY;

    This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
580
    InitializeCriticalSection(&This->cs);
581 582
    This->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BackgroundCopyJobImpl.cs");

583 584 585 586 587 588 589
    This->ref = 1;
    This->type = type;

    n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
    This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
    if (!This->displayName)
    {
590
        This->cs.DebugInfo->Spare[0] = 0;
591
        DeleteCriticalSection(&This->cs);
592 593 594 595 596 597 598 599
        HeapFree(GetProcessHeap(), 0, This);
        return E_OUTOFMEMORY;
    }
    memcpy(This->displayName, displayName, n);

    hr = CoCreateGuid(&This->jobId);
    if (FAILED(hr))
    {
600
        This->cs.DebugInfo->Spare[0] = 0;
601
        DeleteCriticalSection(&This->cs);
602 603 604 605
        HeapFree(GetProcessHeap(), 0, This->displayName);
        HeapFree(GetProcessHeap(), 0, This);
        return hr;
    }
606
    *pJobId = This->jobId;
607

608
    list_init(&This->files);
609
    This->jobProgress.BytesTotal = 0;
610 611 612 613
    This->jobProgress.BytesTransferred = 0;
    This->jobProgress.FilesTotal = 0;
    This->jobProgress.FilesTransferred = 0;

614 615
    This->state = BG_JOB_STATE_SUSPENDED;

616 617 618
    *ppObj = &This->lpVtbl;
    return S_OK;
}
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644

void processJob(BackgroundCopyJobImpl *job)
{
    for (;;)
    {
        BackgroundCopyFileImpl *file;
        BOOL done = TRUE;

        EnterCriticalSection(&job->cs);
        LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
            if (!file->fileProgress.Completed)
            {
                done = FALSE;
                break;
            }
        LeaveCriticalSection(&job->cs);
        if (done)
        {
            transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSFERRED);
            return;
        }

        if (!processFile(file, job))
          return;
    }
}