qmgr: COM cleanup for IBackgroundCopyFile interface.

This commit is contained in:
Nikolay Sivov 2013-01-18 08:38:49 +04:00 committed by Alexandre Julliard
parent 175039e736
commit d4edda8c46
4 changed files with 37 additions and 30 deletions

View File

@ -202,8 +202,8 @@ HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl *job, IEnumBack
i = 0; i = 0;
LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob) LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
{ {
file->lpVtbl->AddRef((IBackgroundCopyFile *) file); IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
This->files[i] = (IBackgroundCopyFile *) file; This->files[i] = &file->IBackgroundCopyFile_iface;
++i; ++i;
} }
LeaveCriticalSection(&job->cs); LeaveCriticalSection(&job->cs);

View File

@ -35,6 +35,11 @@
WINE_DEFAULT_DEBUG_CHANNEL(qmgr); 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) static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
{ {
IBackgroundCopyJob2_Release(&This->owner->IBackgroundCopyJob2_iface); IBackgroundCopyJob2_Release(&This->owner->IBackgroundCopyJob2_iface);
@ -43,38 +48,43 @@ static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
HeapFree(GetProcessHeap(), 0, 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( static HRESULT WINAPI BITS_IBackgroundCopyFile_QueryInterface(
IBackgroundCopyFile* iface, IBackgroundCopyFile* iface,
REFIID riid, 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) if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IBackgroundCopyFile)) || IsEqualGUID(riid, &IID_IBackgroundCopyFile))
{ {
*ppvObject = &This->lpVtbl; *obj = iface;
BITS_IBackgroundCopyFile_AddRef(iface); IBackgroundCopyFile_AddRef(iface);
return S_OK; return S_OK;
} }
*ppvObject = NULL; *obj = NULL;
return E_NOINTERFACE; 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( static ULONG WINAPI BITS_IBackgroundCopyFile_Release(
IBackgroundCopyFile* iface) IBackgroundCopyFile* iface)
{ {
BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface; BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
ULONG ref = InterlockedDecrement(&This->ref); ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)->(%d)\n", This, ref);
if (ref == 0) if (ref == 0)
BackgroundCopyFileDestructor(This); BackgroundCopyFileDestructor(This);
@ -86,7 +96,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetRemoteName(
IBackgroundCopyFile* iface, IBackgroundCopyFile* iface,
LPWSTR *pVal) LPWSTR *pVal)
{ {
BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface; BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR); int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR);
*pVal = CoTaskMemAlloc(n); *pVal = CoTaskMemAlloc(n);
@ -101,7 +111,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
IBackgroundCopyFile* iface, IBackgroundCopyFile* iface,
LPWSTR *pVal) LPWSTR *pVal)
{ {
BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface; BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR); int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR);
*pVal = CoTaskMemAlloc(n); *pVal = CoTaskMemAlloc(n);
@ -116,7 +126,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
IBackgroundCopyFile* iface, IBackgroundCopyFile* iface,
BG_FILE_PROGRESS *pVal) BG_FILE_PROGRESS *pVal)
{ {
BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface; BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
EnterCriticalSection(&This->owner->cs); EnterCriticalSection(&This->owner->cs);
pVal->BytesTotal = This->fileProgress.BytesTotal; pVal->BytesTotal = This->fileProgress.BytesTotal;
@ -139,13 +149,12 @@ static const IBackgroundCopyFileVtbl BITS_IBackgroundCopyFile_Vtbl =
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner, HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
LPCWSTR remoteName, LPCWSTR localName, LPCWSTR remoteName, LPCWSTR localName,
LPVOID *ppObj) BackgroundCopyFileImpl **file)
{ {
BackgroundCopyFileImpl *This; BackgroundCopyFileImpl *This;
int n; int n;
TRACE("(%s,%s,%p)\n", debugstr_w(remoteName), TRACE("(%s, %s, %p)\n", debugstr_w(remoteName), debugstr_w(localName), file);
debugstr_w(localName), ppObj);
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This); This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
if (!This) if (!This)
@ -170,7 +179,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
} }
memcpy(This->info.LocalName, localName, n); memcpy(This->info.LocalName, localName, n);
This->lpVtbl = &BITS_IBackgroundCopyFile_Vtbl; This->IBackgroundCopyFile_iface.lpVtbl = &BITS_IBackgroundCopyFile_Vtbl;
This->ref = 1; This->ref = 1;
This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN; This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
@ -179,7 +188,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
This->owner = owner; This->owner = owner;
IBackgroundCopyJob2_AddRef(&owner->IBackgroundCopyJob2_iface); IBackgroundCopyJob2_AddRef(&owner->IBackgroundCopyJob2_iface);
*ppObj = &This->lpVtbl; *file = This;
return S_OK; return S_OK;
} }
@ -236,7 +245,7 @@ static ULONG WINAPI DLBindStatusCallback_Release(IBindStatusCallback *iface)
if (ref == 0) if (ref == 0)
{ {
IBackgroundCopyFile_Release((IBackgroundCopyFile *) This->file); IBackgroundCopyFile_Release(&This->file->IBackgroundCopyFile_iface);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
@ -365,7 +374,7 @@ static DLBindStatusCallback *DLBindStatusCallbackConstructor(
return NULL; return NULL;
This->IBindStatusCallback_iface.lpVtbl = &DLBindStatusCallback_Vtbl; This->IBindStatusCallback_iface.lpVtbl = &DLBindStatusCallback_Vtbl;
IBackgroundCopyFile_AddRef((IBackgroundCopyFile *) file); IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
This->file = file; This->file = file;
This->ref = 1; This->ref = 1;
return This; return This;

View File

@ -106,20 +106,18 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
LPCWSTR LocalName) LPCWSTR LocalName)
{ {
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface); BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
IBackgroundCopyFile *pFile;
BackgroundCopyFileImpl *file; BackgroundCopyFileImpl *file;
HRESULT res; HRESULT res;
/* We should return E_INVALIDARG in these cases. */ /* We should return E_INVALIDARG in these cases. */
FIXME("Check for valid filenames and supported protocols\n"); 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) if (res != S_OK)
return res; return res;
/* Add a reference to the file to file list */ /* Add a reference to the file to file list */
IBackgroundCopyFile_AddRef(pFile); IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
file = (BackgroundCopyFileImpl *) pFile;
EnterCriticalSection(&This->cs); EnterCriticalSection(&This->cs);
list_add_head(&This->files, &file->entryFromJob); list_add_head(&This->files, &file->entryFromJob);
This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN; This->jobProgress.BytesTotal = BG_SIZE_UNKNOWN;

View File

@ -49,7 +49,7 @@ typedef struct
/* Background copy file vtbl and related data */ /* Background copy file vtbl and related data */
typedef struct typedef struct
{ {
const IBackgroundCopyFileVtbl *lpVtbl; IBackgroundCopyFile IBackgroundCopyFile_iface;
LONG ref; LONG ref;
BG_FILE_INFO info; BG_FILE_INFO info;
BG_FILE_PROGRESS fileProgress; BG_FILE_PROGRESS fileProgress;
@ -84,7 +84,7 @@ HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr,
IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN; IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN;
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner, HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
LPCWSTR remoteName, LPCWSTR localName, LPCWSTR remoteName, LPCWSTR localName,
LPVOID *ppObj) DECLSPEC_HIDDEN; BackgroundCopyFileImpl **file) DECLSPEC_HIDDEN;
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN; HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN;
DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN; DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN;
void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN; void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;