[2/3] qmgr: Add infrastructure for background file transferring.

Dan Hipschman dsh at linux.ucla.edu
Wed Mar 5 20:01:32 CST 2008


This adds the infrastructure for background downloading.

---
 dlls/qmgr/qmgr.c    |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 dlls/qmgr/qmgr.h    |    1 +
 dlls/qmgr/service.c |   10 +++++++
 3 files changed, 79 insertions(+), 1 deletions(-)

diff --git a/dlls/qmgr/qmgr.c b/dlls/qmgr/qmgr.c
index dbcbab4..10f767f 100644
--- a/dlls/qmgr/qmgr.c
+++ b/dlls/qmgr/qmgr.c
@@ -1,7 +1,7 @@
 /*
  * Queue Manager (BITS) core functions
  *
- * Copyright 2007 Google (Roy Shea)
+ * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -181,3 +181,70 @@ HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj)
     *ppObj = &This->lpVtbl;
     return S_OK;
 }
+
+DWORD WINAPI fileTransfer(void *param)
+{
+    IBackgroundCopyManager *qmgr = (IBackgroundCopyManager *) &globalMgr;
+    for (;;)
+    {
+        IEnumBackgroundCopyJobs *jobs;
+        HRESULT hr;
+        ULONG i, n;
+
+        Sleep(1000);
+
+        hr = IBackgroundCopyManager_EnumJobs(qmgr, 0, &jobs);
+        if (hr != S_OK)
+        {
+            ERR("Couldn't enumerate jobs: 0x%08x\n", hr);
+            continue;
+        }
+
+        hr = IEnumBackgroundCopyJobs_GetCount(jobs, &n);
+        if (hr != S_OK)
+        {
+            ERR("Couldn't get job count: 0x%08x\n", hr);
+            n = 0;
+        }
+
+        for (i = 0; i < n; ++i)
+        {
+            BG_JOB_STATE state;
+            IBackgroundCopyJob *job;
+            hr = IEnumBackgroundCopyJobs_Next(jobs, 1, &job, NULL);
+            if (hr != S_OK)
+            {
+                ERR("IEnumBackgroundCopyJobs_Next failed: 0x%08x\n", hr);
+                break;
+            }
+
+            hr = IBackgroundCopyJob_GetState(job, &state);
+            if (hr == S_OK)
+            {
+                switch (state)
+                {
+                case BG_JOB_STATE_QUEUED:
+                    /* Connect and start downloading */
+                    break;
+                case BG_JOB_STATE_CONNECTING:
+                case BG_JOB_STATE_TRANSFERRING:
+                case BG_JOB_STATE_TRANSIENT_ERROR:
+                    /* We shouldn't see these */
+                    ERR("In an inconsistent state: %d\n", state);
+                    break;
+                case BG_JOB_STATE_ACKNOWLEDGED:
+                case BG_JOB_STATE_CANCELLED:
+                    /* Remove from queue */
+                    break;
+                default:
+                    /* Do nothing */
+                    break;
+                }
+            }
+
+            IBackgroundCopyJob_Release(job);
+        }
+
+        IEnumBackgroundCopyJobs_Release(jobs);
+    }
+}
diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h
index 5227120..d03724a 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -99,6 +99,7 @@ HRESULT BackgroundCopyFileConstructor(LPCWSTR remoteName,
                                       LPCWSTR localName, LPVOID *ppObj);
 HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj,
                                            IBackgroundCopyJob* copyJob);
+DWORD WINAPI fileTransfer(void *param);
 
 /* Little helper functions */
 static inline char *
diff --git a/dlls/qmgr/service.c b/dlls/qmgr/service.c
index 5e31b8f..ac41988 100644
--- a/dlls/qmgr/service.c
+++ b/dlls/qmgr/service.c
@@ -108,6 +108,8 @@ StartCount(void)
 VOID WINAPI
 ServiceMain(DWORD dwArgc, LPWSTR *lpszArgv)
 {
+    HANDLE fileTxThread;
+    DWORD threadId;
     TRACE("\n");
 
     stop_event = CreateEventW(NULL, TRUE, FALSE, NULL);
@@ -129,6 +131,14 @@ ServiceMain(DWORD dwArgc, LPWSTR *lpszArgv)
         return;
     }
 
+    fileTxThread = CreateThread(NULL, 0, fileTransfer, NULL, 0, &threadId);
+    if (!fileTxThread)
+    {
+        ERR("Failed starting file transfer thread\n");
+        UpdateStatus(SERVICE_STOPPED, NO_ERROR, 0);
+        return;
+    }
+
     UpdateStatus(SERVICE_RUNNING, NO_ERROR, 0);
 
     WaitForSingleObject(stop_event, INFINITE);



More information about the wine-patches mailing list