Nikolay Sivov : qmgr: COM cleanup for IBackgroundCopyFile interface.
Alexandre Julliard
julliard at winehq.org
Fri Jan 18 12:07:35 CST 2013
Module: wine
Branch: master
Commit: d4edda8c4627c76dfa2ef769b864faaec6959caa
URL: http://source.winehq.org/git/wine.git/?a=commit;h=d4edda8c4627c76dfa2ef769b864faaec6959caa
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Fri Jan 18 08:38:49 2013 +0400
qmgr: COM cleanup for IBackgroundCopyFile interface.
---
dlls/qmgr/enum_files.c | 4 +-
dlls/qmgr/file.c | 53 ++++++++++++++++++++++++++++-------------------
dlls/qmgr/job.c | 6 +---
dlls/qmgr/qmgr.h | 4 +-
4 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/dlls/qmgr/enum_files.c b/dlls/qmgr/enum_files.c
index 9f1b505..7b0e505 100644
--- a/dlls/qmgr/enum_files.c
+++ b/dlls/qmgr/enum_files.c
@@ -202,8 +202,8 @@ HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl *job, IEnumBack
i = 0;
LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
{
- file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
- This->files[i] = (IBackgroundCopyFile *) file;
+ IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
+ This->files[i] = &file->IBackgroundCopyFile_iface;
++i;
}
LeaveCriticalSection(&job->cs);
diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c
index 9d9d9c1..5fa5d09 100644
--- a/dlls/qmgr/file.c
+++ b/dlls/qmgr/file.c
@@ -35,6 +35,11 @@
WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
+static inline BackgroundCopyFileImpl *impl_from_IBackgroundCopyFile(IBackgroundCopyFile *iface)
+{
+ return CONTAINING_RECORD(iface, BackgroundCopyFileImpl, IBackgroundCopyFile_iface);
+}
+
static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
{
IBackgroundCopyJob2_Release(&This->owner->IBackgroundCopyJob2_iface);
@@ -43,38 +48,43 @@ static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
HeapFree(GetProcessHeap(), 0, This);
}
-static ULONG WINAPI BITS_IBackgroundCopyFile_AddRef(IBackgroundCopyFile* iface)
-{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
- return InterlockedIncrement(&This->ref);
-}
-
static HRESULT WINAPI BITS_IBackgroundCopyFile_QueryInterface(
IBackgroundCopyFile* iface,
REFIID riid,
- void **ppvObject)
+ void **obj)
{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
+
+ TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IBackgroundCopyFile))
{
- *ppvObject = &This->lpVtbl;
- BITS_IBackgroundCopyFile_AddRef(iface);
+ *obj = iface;
+ IBackgroundCopyFile_AddRef(iface);
return S_OK;
}
- *ppvObject = NULL;
+ *obj = NULL;
return E_NOINTERFACE;
}
+static ULONG WINAPI BITS_IBackgroundCopyFile_AddRef(IBackgroundCopyFile* iface)
+{
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
+ ULONG ref = InterlockedIncrement(&This->ref);
+ TRACE("(%p)->(%d)\n", This, ref);
+ return ref;
+}
static ULONG WINAPI BITS_IBackgroundCopyFile_Release(
IBackgroundCopyFile* iface)
{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
ULONG ref = InterlockedDecrement(&This->ref);
+ TRACE("(%p)->(%d)\n", This, ref);
+
if (ref == 0)
BackgroundCopyFileDestructor(This);
@@ -86,7 +96,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetRemoteName(
IBackgroundCopyFile* iface,
LPWSTR *pVal)
{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR);
*pVal = CoTaskMemAlloc(n);
@@ -101,7 +111,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
IBackgroundCopyFile* iface,
LPWSTR *pVal)
{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR);
*pVal = CoTaskMemAlloc(n);
@@ -116,7 +126,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
IBackgroundCopyFile* iface,
BG_FILE_PROGRESS *pVal)
{
- BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
+ BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
EnterCriticalSection(&This->owner->cs);
pVal->BytesTotal = This->fileProgress.BytesTotal;
@@ -139,13 +149,12 @@ static const IBackgroundCopyFileVtbl BITS_IBackgroundCopyFile_Vtbl =
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
LPCWSTR remoteName, LPCWSTR localName,
- LPVOID *ppObj)
+ BackgroundCopyFileImpl **file)
{
BackgroundCopyFileImpl *This;
int n;
- TRACE("(%s,%s,%p)\n", debugstr_w(remoteName),
- debugstr_w(localName), ppObj);
+ TRACE("(%s, %s, %p)\n", debugstr_w(remoteName), debugstr_w(localName), file);
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
if (!This)
@@ -170,7 +179,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
}
memcpy(This->info.LocalName, localName, n);
- This->lpVtbl = &BITS_IBackgroundCopyFile_Vtbl;
+ This->IBackgroundCopyFile_iface.lpVtbl = &BITS_IBackgroundCopyFile_Vtbl;
This->ref = 1;
This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
@@ -179,7 +188,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
This->owner = owner;
IBackgroundCopyJob2_AddRef(&owner->IBackgroundCopyJob2_iface);
- *ppObj = &This->lpVtbl;
+ *file = This;
return S_OK;
}
@@ -236,7 +245,7 @@ static ULONG WINAPI DLBindStatusCallback_Release(IBindStatusCallback *iface)
if (ref == 0)
{
- IBackgroundCopyFile_Release((IBackgroundCopyFile *) This->file);
+ IBackgroundCopyFile_Release(&This->file->IBackgroundCopyFile_iface);
HeapFree(GetProcessHeap(), 0, This);
}
@@ -365,7 +374,7 @@ static DLBindStatusCallback *DLBindStatusCallbackConstructor(
return NULL;
This->IBindStatusCallback_iface.lpVtbl = &DLBindStatusCallback_Vtbl;
- IBackgroundCopyFile_AddRef((IBackgroundCopyFile *) file);
+ IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
This->file = file;
This->ref = 1;
return This;
diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c
index 4d9bf18..26fc43e 100644
--- a/dlls/qmgr/job.c
+++ b/dlls/qmgr/job.c
@@ -106,20 +106,18 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
LPCWSTR LocalName)
{
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
- IBackgroundCopyFile *pFile;
BackgroundCopyFileImpl *file;
HRESULT res;
/* We should return E_INVALIDARG in these cases. */
FIXME("Check for valid filenames and supported protocols\n");
- res = BackgroundCopyFileConstructor(This, RemoteUrl, LocalName, (LPVOID *) &pFile);
+ res = BackgroundCopyFileConstructor(This, RemoteUrl, LocalName, &file);
if (res != S_OK)
return res;
/* Add a reference to the file to file list */
- IBackgroundCopyFile_AddRef(pFile);
- file = (BackgroundCopyFileImpl *) pFile;
+ IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
EnterCriticalSection(&This->cs);
list_add_head(&This->files, &file->entryFromJob);
This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;
diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h
index 0039db7..215c200 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -49,7 +49,7 @@ typedef struct
/* Background copy file vtbl and related data */
typedef struct
{
- const IBackgroundCopyFileVtbl *lpVtbl;
+ IBackgroundCopyFile IBackgroundCopyFile_iface;
LONG ref;
BG_FILE_INFO info;
BG_FILE_PROGRESS fileProgress;
@@ -84,7 +84,7 @@ HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr,
IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN;
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
LPCWSTR remoteName, LPCWSTR localName,
- LPVOID *ppObj) DECLSPEC_HIDDEN;
+ BackgroundCopyFileImpl **file) DECLSPEC_HIDDEN;
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN;
DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN;
void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
More information about the wine-cvs
mailing list