Hans Leidekker : qmgr: Implement IBackgroundCopyJob::Cancel.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Jun 15 08:49:07 CDT 2015
Module: wine
Branch: master
Commit: 13c3f7ac2b563596a74811590239ebee535a0889
URL: http://source.winehq.org/git/wine.git/?a=commit;h=13c3f7ac2b563596a74811590239ebee535a0889
Author: Hans Leidekker <hans at codeweavers.com>
Date: Fri Jun 12 15:06:59 2015 +0200
qmgr: Implement IBackgroundCopyJob::Cancel.
---
dlls/qmgr/file.c | 1 +
dlls/qmgr/job.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c
index a5a41d1..0321ab6 100644
--- a/dlls/qmgr/file.c
+++ b/dlls/qmgr/file.c
@@ -201,6 +201,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
This->fileProgress.Completed = FALSE;
This->owner = owner;
This->read_size = 0;
+ This->tempFileName[0] = 0;
IBackgroundCopyJob3_AddRef(&owner->IBackgroundCopyJob3_iface);
*file = This;
diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c
index bf48480..37ef5f9 100644
--- a/dlls/qmgr/job.c
+++ b/dlls/qmgr/job.c
@@ -259,6 +259,9 @@ static ULONG WINAPI BackgroundCopyJob_Release(IBackgroundCopyJob3 *iface)
HeapFree(GetProcessHeap(), 0, cred->Credentials.Basic.Password);
}
}
+ CloseHandle(This->wait);
+ CloseHandle(This->cancel);
+ CloseHandle(This->done);
HeapFree(GetProcessHeap(), 0, This);
}
@@ -365,8 +368,48 @@ static HRESULT WINAPI BackgroundCopyJob_Cancel(
IBackgroundCopyJob3 *iface)
{
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob3(iface);
- FIXME("(%p): stub\n", This);
- return E_NOTIMPL;
+ HRESULT rv = S_OK;
+
+ TRACE("(%p)\n", This);
+
+ EnterCriticalSection(&This->cs);
+
+ if (is_job_done(This))
+ {
+ rv = BG_E_INVALID_STATE;
+ }
+ else
+ {
+ BackgroundCopyFileImpl *file;
+
+ if (This->state == BG_JOB_STATE_CONNECTING || This->state == BG_JOB_STATE_TRANSFERRING)
+ {
+ This->state = BG_JOB_STATE_CANCELLED;
+ SetEvent(This->cancel);
+
+ LeaveCriticalSection(&This->cs);
+ WaitForSingleObject(This->done, INFINITE);
+ EnterCriticalSection(&This->cs);
+ }
+
+ LIST_FOR_EACH_ENTRY(file, &This->files, BackgroundCopyFileImpl, entryFromJob)
+ {
+ if (file->tempFileName[0] && !DeleteFileW(file->tempFileName))
+ {
+ WARN("Couldn't delete %s (%u)\n", debugstr_w(file->tempFileName), GetLastError());
+ rv = BG_S_UNABLE_TO_DELETE_FILES;
+ }
+ if (file->info.LocalName && !DeleteFileW(file->info.LocalName))
+ {
+ WARN("Couldn't delete %s (%u)\n", debugstr_w(file->info.LocalName), GetLastError());
+ rv = BG_S_UNABLE_TO_DELETE_FILES;
+ }
+ }
+ This->state = BG_JOB_STATE_CANCELLED;
+ }
+
+ LeaveCriticalSection(&This->cs);
+ return rv;
}
static HRESULT WINAPI BackgroundCopyJob_Complete(
@@ -1193,6 +1236,10 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID
memset(&This->http_options, 0, sizeof(This->http_options));
+ This->wait = CreateEventW(NULL, FALSE, FALSE, NULL);
+ This->cancel = CreateEventW(NULL, FALSE, FALSE, NULL);
+ This->done = CreateEventW(NULL, FALSE, FALSE, NULL);
+
*job = This;
TRACE("created job %s:%p\n", debugstr_guid(&This->jobId), This);
More information about the wine-cvs
mailing list