ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

job.c
Go to the documentation of this file.
00001 /*
00002  * Background Copy Job Interface for BITS
00003  *
00004  * Copyright 2007 Google (Roy Shea)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <stdarg.h>
00022 
00023 #include "windef.h"
00024 #include "winbase.h"
00025 
00026 #include "qmgr.h"
00027 #include "wine/debug.h"
00028 
00029 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
00030 
00031 static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
00032 {
00033     DeleteCriticalSection(&This->cs);
00034     HeapFree(GetProcessHeap(), 0, This->displayName);
00035     HeapFree(GetProcessHeap(), 0, This);
00036 }
00037 
00038 static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
00039 {
00040     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00041     return InterlockedIncrement(&This->ref);
00042 }
00043 
00044 static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
00045     IBackgroundCopyJob2 *iface, REFIID riid, LPVOID *ppvObject)
00046 {
00047     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00048     TRACE("IID: %s\n", debugstr_guid(riid));
00049 
00050     if (IsEqualGUID(riid, &IID_IUnknown)
00051         || IsEqualGUID(riid, &IID_IBackgroundCopyJob)
00052         || IsEqualGUID(riid, &IID_IBackgroundCopyJob2))
00053     {
00054         *ppvObject = &This->lpVtbl;
00055         BITS_IBackgroundCopyJob_AddRef(iface);
00056         return S_OK;
00057     }
00058 
00059     *ppvObject = NULL;
00060     return E_NOINTERFACE;
00061 }
00062 
00063 static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
00064 {
00065     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00066     ULONG ref = InterlockedDecrement(&This->ref);
00067 
00068     if (ref == 0)
00069         BackgroundCopyJobDestructor(This);
00070 
00071     return ref;
00072 }
00073 
00074 /*** IBackgroundCopyJob methods ***/
00075 
00076 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
00077     IBackgroundCopyJob2 *iface,
00078     ULONG cFileCount,
00079     BG_FILE_INFO *pFileSet)
00080 {
00081     ULONG i;
00082     for (i = 0; i < cFileCount; ++i)
00083     {
00084         HRESULT hr = IBackgroundCopyJob_AddFile(iface, pFileSet[i].RemoteName,
00085                                                 pFileSet[i].LocalName);
00086         if (FAILED(hr))
00087             return hr;
00088     }
00089     return S_OK;
00090 }
00091 
00092 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
00093     IBackgroundCopyJob2 *iface,
00094     LPCWSTR RemoteUrl,
00095     LPCWSTR LocalName)
00096 {
00097     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00098     IBackgroundCopyFile *pFile;
00099     BackgroundCopyFileImpl *file;
00100     HRESULT res;
00101 
00102     /* We should return E_INVALIDARG in these cases.  */
00103     FIXME("Check for valid filenames and supported protocols\n");
00104 
00105     res = BackgroundCopyFileConstructor(This, RemoteUrl, LocalName, (LPVOID *) &pFile);
00106     if (res != S_OK)
00107         return res;
00108 
00109     /* Add a reference to the file to file list */
00110     IBackgroundCopyFile_AddRef(pFile);
00111     file = (BackgroundCopyFileImpl *) pFile;
00112     EnterCriticalSection(&This->cs);
00113     list_add_head(&This->files, &file->entryFromJob);
00114     This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
00115     ++This->jobProgress.FilesTotal;
00116     LeaveCriticalSection(&This->cs);
00117 
00118     return S_OK;
00119 }
00120 
00121 static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
00122     IBackgroundCopyJob2 *iface,
00123     IEnumBackgroundCopyFiles **ppEnum)
00124 {
00125     TRACE("\n");
00126     return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
00127 }
00128 
00129 static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
00130     IBackgroundCopyJob2 *iface)
00131 {
00132     FIXME("Not implemented\n");
00133     return E_NOTIMPL;
00134 }
00135 
00136 static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
00137     IBackgroundCopyJob2 *iface)
00138 {
00139     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00140     HRESULT rv = S_OK;
00141 
00142     EnterCriticalSection(&globalMgr.cs);
00143     if (This->state == BG_JOB_STATE_CANCELLED
00144         || This->state == BG_JOB_STATE_ACKNOWLEDGED)
00145     {
00146         rv = BG_E_INVALID_STATE;
00147     }
00148     else if (This->jobProgress.FilesTransferred == This->jobProgress.FilesTotal)
00149     {
00150         rv = BG_E_EMPTY;
00151     }
00152     else if (This->state != BG_JOB_STATE_CONNECTING
00153              && This->state != BG_JOB_STATE_TRANSFERRING)
00154     {
00155         This->state = BG_JOB_STATE_QUEUED;
00156         SetEvent(globalMgr.jobEvent);
00157     }
00158     LeaveCriticalSection(&globalMgr.cs);
00159 
00160     return rv;
00161 }
00162 
00163 static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
00164     IBackgroundCopyJob2 *iface)
00165 {
00166     FIXME("Not implemented\n");
00167     return E_NOTIMPL;
00168 }
00169 
00170 static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
00171     IBackgroundCopyJob2 *iface)
00172 {
00173     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00174     HRESULT rv = S_OK;
00175 
00176     EnterCriticalSection(&This->cs);
00177 
00178     if (This->state == BG_JOB_STATE_CANCELLED
00179         || This->state == BG_JOB_STATE_ACKNOWLEDGED)
00180     {
00181         rv = BG_E_INVALID_STATE;
00182     }
00183     else
00184     {
00185         BackgroundCopyFileImpl *file;
00186         LIST_FOR_EACH_ENTRY(file, &This->files, BackgroundCopyFileImpl, entryFromJob)
00187         {
00188             if (file->fileProgress.Completed)
00189             {
00190                 if (!MoveFileExW(file->tempFileName, file->info.LocalName,
00191                                  (MOVEFILE_COPY_ALLOWED
00192                                   | MOVEFILE_REPLACE_EXISTING
00193                                   | MOVEFILE_WRITE_THROUGH)))
00194                 {
00195                     ERR("Couldn't rename file %s -> %s\n",
00196                         debugstr_w(file->tempFileName),
00197                         debugstr_w(file->info.LocalName));
00198                     rv = BG_S_PARTIAL_COMPLETE;
00199                 }
00200             }
00201             else
00202                 rv = BG_S_PARTIAL_COMPLETE;
00203         }
00204     }
00205 
00206     This->state = BG_JOB_STATE_ACKNOWLEDGED;
00207     LeaveCriticalSection(&This->cs);
00208 
00209     return rv;
00210 }
00211 
00212 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
00213     IBackgroundCopyJob2 *iface,
00214     GUID *pVal)
00215 {
00216     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00217     *pVal = This->jobId;
00218     return S_OK;
00219 }
00220 
00221 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
00222     IBackgroundCopyJob2 *iface,
00223     BG_JOB_TYPE *pVal)
00224 {
00225     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00226 
00227     if (!pVal)
00228         return E_INVALIDARG;
00229 
00230     *pVal = This->type;
00231     return S_OK;
00232 }
00233 
00234 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
00235     IBackgroundCopyJob2 *iface,
00236     BG_JOB_PROGRESS *pVal)
00237 {
00238     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00239 
00240     if (!pVal)
00241         return E_INVALIDARG;
00242 
00243     EnterCriticalSection(&This->cs);
00244     pVal->BytesTotal = This->jobProgress.BytesTotal;
00245     pVal->BytesTransferred = This->jobProgress.BytesTransferred;
00246     pVal->FilesTotal = This->jobProgress.FilesTotal;
00247     pVal->FilesTransferred = This->jobProgress.FilesTransferred;
00248     LeaveCriticalSection(&This->cs);
00249 
00250     return S_OK;
00251 }
00252 
00253 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
00254     IBackgroundCopyJob2 *iface,
00255     BG_JOB_TIMES *pVal)
00256 {
00257     FIXME("Not implemented\n");
00258     return E_NOTIMPL;
00259 }
00260 
00261 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
00262     IBackgroundCopyJob2 *iface,
00263     BG_JOB_STATE *pVal)
00264 {
00265     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00266 
00267     if (!pVal)
00268         return E_INVALIDARG;
00269 
00270     /* Don't think we need a critical section for this */
00271     *pVal = This->state;
00272     return S_OK;
00273 }
00274 
00275 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
00276     IBackgroundCopyJob2 *iface,
00277     IBackgroundCopyError **ppError)
00278 {
00279     FIXME("Not implemented\n");
00280     return E_NOTIMPL;
00281 }
00282 
00283 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
00284     IBackgroundCopyJob2 *iface,
00285     LPWSTR *pVal)
00286 {
00287     FIXME("Not implemented\n");
00288     return E_NOTIMPL;
00289 }
00290 
00291 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
00292     IBackgroundCopyJob2 *iface,
00293     LPCWSTR Val)
00294 {
00295     FIXME("Not implemented\n");
00296     return E_NOTIMPL;
00297 }
00298 
00299 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
00300     IBackgroundCopyJob2 *iface,
00301     LPWSTR *pVal)
00302 {
00303     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
00304     int n;
00305 
00306     if (!pVal)
00307         return E_INVALIDARG;
00308 
00309     n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
00310     *pVal = CoTaskMemAlloc(n);
00311     if (*pVal == NULL)
00312         return E_OUTOFMEMORY;
00313     memcpy(*pVal, This->displayName, n);
00314     return S_OK;
00315 }
00316 
00317 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
00318     IBackgroundCopyJob2 *iface,
00319     LPCWSTR Val)
00320 {
00321     FIXME("Not implemented\n");
00322     return E_NOTIMPL;
00323 }
00324 
00325 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
00326     IBackgroundCopyJob2 *iface,
00327     LPWSTR *pVal)
00328 {
00329     FIXME("Not implemented\n");
00330     return E_NOTIMPL;
00331 }
00332 
00333 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
00334     IBackgroundCopyJob2 *iface,
00335     BG_JOB_PRIORITY Val)
00336 {
00337     FIXME("(%p,0x%08x) stub\n", iface, Val);
00338     return S_OK;
00339 }
00340 
00341 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
00342     IBackgroundCopyJob2 *iface,
00343     BG_JOB_PRIORITY *pVal)
00344 {
00345     FIXME("Not implemented\n");
00346     return E_NOTIMPL;
00347 }
00348 
00349 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
00350     IBackgroundCopyJob2 *iface,
00351     ULONG Val)
00352 {
00353     FIXME("Not implemented\n");
00354     return E_NOTIMPL;
00355 }
00356 
00357 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
00358     IBackgroundCopyJob2 *iface,
00359     ULONG *pVal)
00360 {
00361     FIXME("Not implemented\n");
00362     return E_NOTIMPL;
00363 }
00364 
00365 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
00366     IBackgroundCopyJob2 *iface,
00367     IUnknown *Val)
00368 {
00369     FIXME("Not implemented\n");
00370     return E_NOTIMPL;
00371 }
00372 
00373 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
00374     IBackgroundCopyJob2 *iface,
00375     IUnknown **pVal)
00376 {
00377     FIXME("Not implemented\n");
00378     return E_NOTIMPL;
00379 }
00380 
00381 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
00382     IBackgroundCopyJob2 *iface,
00383     ULONG Seconds)
00384 {
00385     FIXME("%u\n", Seconds);
00386     return S_OK;
00387 }
00388 
00389 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
00390     IBackgroundCopyJob2 *iface,
00391     ULONG *Seconds)
00392 {
00393     FIXME("%p\n", Seconds);
00394     *Seconds = 30;
00395     return S_OK;
00396 }
00397 
00398 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
00399     IBackgroundCopyJob2 *iface,
00400     ULONG Seconds)
00401 {
00402     FIXME("%u\n", Seconds);
00403     return S_OK;
00404 }
00405 
00406 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
00407     IBackgroundCopyJob2 *iface,
00408     ULONG *Seconds)
00409 {
00410     FIXME("%p\n", Seconds);
00411     *Seconds = 900;
00412     return S_OK;
00413 }
00414 
00415 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
00416     IBackgroundCopyJob2 *iface,
00417     ULONG *Errors)
00418 {
00419     FIXME("Not implemented\n");
00420     return E_NOTIMPL;
00421 }
00422 
00423 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
00424     IBackgroundCopyJob2 *iface,
00425     BG_JOB_PROXY_USAGE ProxyUsage,
00426     const WCHAR *ProxyList,
00427     const WCHAR *ProxyBypassList)
00428 {
00429     FIXME("Not implemented\n");
00430     return E_NOTIMPL;
00431 }
00432 
00433 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
00434     IBackgroundCopyJob2 *iface,
00435     BG_JOB_PROXY_USAGE *pProxyUsage,
00436     LPWSTR *pProxyList,
00437     LPWSTR *pProxyBypassList)
00438 {
00439     FIXME("Not implemented\n");
00440     return E_NOTIMPL;
00441 }
00442 
00443 static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
00444     IBackgroundCopyJob2 *iface)
00445 {
00446     FIXME("Not implemented\n");
00447     return E_NOTIMPL;
00448 }
00449 
00450 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyCmdLine(
00451     IBackgroundCopyJob2 *iface,
00452     LPCWSTR prog,
00453     LPCWSTR params)
00454 {
00455     FIXME("Not implemented\n");
00456     return E_NOTIMPL;
00457 }
00458 
00459 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyCmdLine(
00460     IBackgroundCopyJob2 *iface,
00461     LPWSTR *prog,
00462     LPWSTR *params)
00463 {
00464     FIXME("Not implemented\n");
00465     return E_NOTIMPL;
00466 }
00467 
00468 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyProgress(
00469     IBackgroundCopyJob2 *iface,
00470     BG_JOB_REPLY_PROGRESS *progress)
00471 {
00472     FIXME("Not implemented\n");
00473     return E_NOTIMPL;
00474 }
00475 
00476 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyData(
00477     IBackgroundCopyJob2 *iface,
00478     byte **pBuffer,
00479     UINT64 *pLength)
00480 {
00481     FIXME("Not implemented\n");
00482     return E_NOTIMPL;
00483 }
00484 
00485 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetReplyFileName(
00486     IBackgroundCopyJob2 *iface,
00487     LPCWSTR filename)
00488 {
00489     FIXME("Not implemented\n");
00490     return E_NOTIMPL;
00491 }
00492 
00493 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetReplyFileName(
00494     IBackgroundCopyJob2 *iface,
00495     LPWSTR *pFilename)
00496 {
00497     FIXME("Not implemented\n");
00498     return E_NOTIMPL;
00499 }
00500 
00501 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetCredentials(
00502     IBackgroundCopyJob2 *iface,
00503     BG_AUTH_CREDENTIALS *cred)
00504 {
00505     FIXME("Not implemented\n");
00506     return S_OK;
00507 }
00508 
00509 static HRESULT WINAPI BITS_IBackgroundCopyJob_RemoveCredentials(
00510     IBackgroundCopyJob2 *iface,
00511     BG_AUTH_TARGET target,
00512     BG_AUTH_SCHEME scheme)
00513 {
00514     FIXME("Not implemented\n");
00515     return S_OK;
00516 }
00517 
00518 static const IBackgroundCopyJob2Vtbl BITS_IBackgroundCopyJob_Vtbl =
00519 {
00520     BITS_IBackgroundCopyJob_QueryInterface,
00521     BITS_IBackgroundCopyJob_AddRef,
00522     BITS_IBackgroundCopyJob_Release,
00523     BITS_IBackgroundCopyJob_AddFileSet,
00524     BITS_IBackgroundCopyJob_AddFile,
00525     BITS_IBackgroundCopyJob_EnumFiles,
00526     BITS_IBackgroundCopyJob_Suspend,
00527     BITS_IBackgroundCopyJob_Resume,
00528     BITS_IBackgroundCopyJob_Cancel,
00529     BITS_IBackgroundCopyJob_Complete,
00530     BITS_IBackgroundCopyJob_GetId,
00531     BITS_IBackgroundCopyJob_GetType,
00532     BITS_IBackgroundCopyJob_GetProgress,
00533     BITS_IBackgroundCopyJob_GetTimes,
00534     BITS_IBackgroundCopyJob_GetState,
00535     BITS_IBackgroundCopyJob_GetError,
00536     BITS_IBackgroundCopyJob_GetOwner,
00537     BITS_IBackgroundCopyJob_SetDisplayName,
00538     BITS_IBackgroundCopyJob_GetDisplayName,
00539     BITS_IBackgroundCopyJob_SetDescription,
00540     BITS_IBackgroundCopyJob_GetDescription,
00541     BITS_IBackgroundCopyJob_SetPriority,
00542     BITS_IBackgroundCopyJob_GetPriority,
00543     BITS_IBackgroundCopyJob_SetNotifyFlags,
00544     BITS_IBackgroundCopyJob_GetNotifyFlags,
00545     BITS_IBackgroundCopyJob_SetNotifyInterface,
00546     BITS_IBackgroundCopyJob_GetNotifyInterface,
00547     BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
00548     BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
00549     BITS_IBackgroundCopyJob_SetNoProgressTimeout,
00550     BITS_IBackgroundCopyJob_GetNoProgressTimeout,
00551     BITS_IBackgroundCopyJob_GetErrorCount,
00552     BITS_IBackgroundCopyJob_SetProxySettings,
00553     BITS_IBackgroundCopyJob_GetProxySettings,
00554     BITS_IBackgroundCopyJob_TakeOwnership,
00555     BITS_IBackgroundCopyJob_SetNotifyCmdLine,
00556     BITS_IBackgroundCopyJob_GetNotifyCmdLine,
00557     BITS_IBackgroundCopyJob_GetReplyProgress,
00558     BITS_IBackgroundCopyJob_GetReplyData,
00559     BITS_IBackgroundCopyJob_SetReplyFileName,
00560     BITS_IBackgroundCopyJob_GetReplyFileName,
00561     BITS_IBackgroundCopyJob_SetCredentials,
00562     BITS_IBackgroundCopyJob_RemoveCredentials
00563 };
00564 
00565 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
00566                                      GUID *pJobId, LPVOID *ppObj)
00567 {
00568     HRESULT hr;
00569     BackgroundCopyJobImpl *This;
00570     int n;
00571 
00572     TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
00573 
00574     This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
00575     if (!This)
00576         return E_OUTOFMEMORY;
00577 
00578     This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
00579     InitializeCriticalSection(&This->cs);
00580     This->ref = 1;
00581     This->type = type;
00582 
00583     n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
00584     This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
00585     if (!This->displayName)
00586     {
00587         DeleteCriticalSection(&This->cs);
00588         HeapFree(GetProcessHeap(), 0, This);
00589         return E_OUTOFMEMORY;
00590     }
00591     memcpy(This->displayName, displayName, n);
00592 
00593     hr = CoCreateGuid(&This->jobId);
00594     if (FAILED(hr))
00595     {
00596         DeleteCriticalSection(&This->cs);
00597         HeapFree(GetProcessHeap(), 0, This->displayName);
00598         HeapFree(GetProcessHeap(), 0, This);
00599         return hr;
00600     }
00601     *pJobId = This->jobId;
00602 
00603     list_init(&This->files);
00604     This->jobProgress.BytesTotal = 0;
00605     This->jobProgress.BytesTransferred = 0;
00606     This->jobProgress.FilesTotal = 0;
00607     This->jobProgress.FilesTransferred = 0;
00608 
00609     This->state = BG_JOB_STATE_SUSPENDED;
00610 
00611     *ppObj = &This->lpVtbl;
00612     return S_OK;
00613 }
00614 
00615 void processJob(BackgroundCopyJobImpl *job)
00616 {
00617     for (;;)
00618     {
00619         BackgroundCopyFileImpl *file;
00620         BOOL done = TRUE;
00621 
00622         EnterCriticalSection(&job->cs);
00623         LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
00624             if (!file->fileProgress.Completed)
00625             {
00626                 done = FALSE;
00627                 break;
00628             }
00629         LeaveCriticalSection(&job->cs);
00630         if (done)
00631         {
00632             transitionJobState(job, BG_JOB_STATE_QUEUED, BG_JOB_STATE_TRANSFERRED);
00633             return;
00634         }
00635 
00636         if (!processFile(file, job))
00637           return;
00638     }
00639 }

Generated on Sun May 27 2012 04:24:28 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.