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

Dan Hipschman dsh at linux.ucla.edu
Thu Mar 6 21:05:00 CST 2008


Same as yesterday.

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

diff --git a/dlls/qmgr/qmgr.c b/dlls/qmgr/qmgr.c
index c6fbc42..3d47c68 100644
--- a/dlls/qmgr/qmgr.c
+++ b/dlls/qmgr/qmgr.c
@@ -140,3 +140,70 @@ HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj)
     *ppObj = (IBackgroundCopyManager *) &globalMgr;
     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 166ee40..8931101 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -98,6 +98,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