qmgr: COM cleanup of IBackgroundCopyJob2 interface.

This commit is contained in:
Nikolay Sivov 2013-01-17 22:39:26 +04:00 committed by Alexandre Julliard
parent 62b4f31d6d
commit a7449dbf59
6 changed files with 52 additions and 45 deletions

View file

@ -167,14 +167,13 @@ static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl =
BITS_IEnumBackgroundCopyFiles_GetCount
};
HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *iCopyJob)
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl *job, IEnumBackgroundCopyFiles **enum_files)
{
EnumBackgroundCopyFilesImpl *This;
BackgroundCopyFileImpl *file;
BackgroundCopyJobImpl *job = (BackgroundCopyJobImpl *) iCopyJob;
ULONG i;
TRACE("%p, %p)\n", ppObj, job);
TRACE("%p, %p)\n", job, enum_files);
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
if (!This)
@ -209,6 +208,6 @@ HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *i
}
LeaveCriticalSection(&job->cs);
*ppObj = &This->IEnumBackgroundCopyFiles_iface;
*enum_files = &This->IEnumBackgroundCopyFiles_iface;
return S_OK;
}

View file

@ -200,9 +200,9 @@ HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr, IEnumBackgroundCop
i = 0;
LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
{
IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job;
IBackgroundCopyJob_AddRef(iJob);
This->jobs[i++] = iJob;
IBackgroundCopyJob *job_iface = (IBackgroundCopyJob*)&job->IBackgroundCopyJob2_iface;
IBackgroundCopyJob_AddRef(job_iface);
This->jobs[i++] = job_iface;
}
LeaveCriticalSection(&qmgr->cs);

View file

@ -37,7 +37,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
static void BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
{
IBackgroundCopyJob_Release((IBackgroundCopyJob *) This->owner);
IBackgroundCopyJob2_Release(&This->owner->IBackgroundCopyJob2_iface);
HeapFree(GetProcessHeap(), 0, This->info.LocalName);
HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
HeapFree(GetProcessHeap(), 0, This);
@ -177,7 +177,7 @@ HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
This->fileProgress.BytesTransferred = 0;
This->fileProgress.Completed = FALSE;
This->owner = owner;
IBackgroundCopyJob_AddRef((IBackgroundCopyJob *) owner);
IBackgroundCopyJob2_AddRef(&owner->IBackgroundCopyJob2_iface);
*ppObj = &This->lpVtbl;
return S_OK;

View file

@ -36,36 +36,46 @@ static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
HeapFree(GetProcessHeap(), 0, This);
}
static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
static inline BackgroundCopyJobImpl *impl_from_IBackgroundCopyJob2(IBackgroundCopyJob2 *iface)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
return InterlockedIncrement(&This->ref);
return CONTAINING_RECORD(iface, BackgroundCopyJobImpl, IBackgroundCopyJob2_iface);
}
static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
IBackgroundCopyJob2 *iface, REFIID riid, LPVOID *ppvObject)
IBackgroundCopyJob2 *iface, REFIID riid, void **obj)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
TRACE("IID: %s\n", debugstr_guid(riid));
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IBackgroundCopyJob)
|| IsEqualGUID(riid, &IID_IBackgroundCopyJob2))
{
*ppvObject = &This->lpVtbl;
BITS_IBackgroundCopyJob_AddRef(iface);
*obj = iface;
IBackgroundCopyJob2_AddRef(iface);
return S_OK;
}
*ppvObject = NULL;
*obj = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob2 *iface)
{
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p)->(%d)\n", This, ref);
return ref;
}
static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob2 *iface)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p)->(%d)\n", This, ref);
if (ref == 0)
BackgroundCopyJobDestructor(This);
@ -95,7 +105,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
LPCWSTR RemoteUrl,
LPCWSTR LocalName)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
IBackgroundCopyFile *pFile;
BackgroundCopyFileImpl *file;
HRESULT res;
@ -121,10 +131,11 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
IBackgroundCopyJob2 *iface,
IEnumBackgroundCopyFiles **ppEnum)
IEnumBackgroundCopyFiles **enum_files)
{
TRACE("\n");
return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
TRACE("(%p)->(%p)\n", This, enum_files);
return EnumBackgroundCopyFilesConstructor(This, enum_files);
}
static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
@ -137,7 +148,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
IBackgroundCopyJob2 *iface)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
HRESULT rv = S_OK;
EnterCriticalSection(&globalMgr.cs);
@ -171,7 +182,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
IBackgroundCopyJob2 *iface)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
HRESULT rv = S_OK;
EnterCriticalSection(&This->cs);
@ -214,7 +225,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
IBackgroundCopyJob2 *iface,
GUID *pVal)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
*pVal = This->jobId;
return S_OK;
}
@ -223,7 +234,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
IBackgroundCopyJob2 *iface,
BG_JOB_TYPE *pVal)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
if (!pVal)
return E_INVALIDARG;
@ -236,7 +247,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
IBackgroundCopyJob2 *iface,
BG_JOB_PROGRESS *pVal)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
if (!pVal)
return E_INVALIDARG;
@ -263,7 +274,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
IBackgroundCopyJob2 *iface,
BG_JOB_STATE *pVal)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
if (!pVal)
return E_INVALIDARG;
@ -301,7 +312,7 @@ static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
IBackgroundCopyJob2 *iface,
LPWSTR *pVal)
{
BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
BackgroundCopyJobImpl *This = impl_from_IBackgroundCopyJob2(iface);
int n;
if (!pVal)
@ -563,20 +574,19 @@ static const IBackgroundCopyJob2Vtbl BITS_IBackgroundCopyJob_Vtbl =
BITS_IBackgroundCopyJob_RemoveCredentials
};
HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
GUID *pJobId, LPVOID *ppObj)
HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type, GUID *job_id, BackgroundCopyJobImpl **job)
{
HRESULT hr;
BackgroundCopyJobImpl *This;
int n;
TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, job);
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
if (!This)
return E_OUTOFMEMORY;
This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
This->IBackgroundCopyJob2_iface.lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
InitializeCriticalSection(&This->cs);
This->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": BackgroundCopyJobImpl.cs");
@ -603,7 +613,7 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
HeapFree(GetProcessHeap(), 0, This);
return hr;
}
*pJobId = This->jobId;
*job_id = This->jobId;
list_init(&This->files);
This->jobProgress.BytesTotal = 0;
@ -613,7 +623,7 @@ HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
This->state = BG_JOB_STATE_SUSPENDED;
*ppObj = &This->lpVtbl;
*job = This;
return S_OK;
}

View file

@ -60,14 +60,13 @@ static HRESULT WINAPI BITS_IBackgroundCopyManager_CreateJob(IBackgroundCopyManag
HRESULT hres;
TRACE("\n");
hres = BackgroundCopyJobConstructor(DisplayName, Type, pJobId,
(LPVOID *) ppJob);
hres = BackgroundCopyJobConstructor(DisplayName, Type, pJobId, &job);
if (FAILED(hres))
return hres;
/* Add a reference to the job to job list */
*ppJob = (IBackgroundCopyJob*)&job->IBackgroundCopyJob2_iface;
IBackgroundCopyJob_AddRef(*ppJob);
job = (BackgroundCopyJobImpl *) *ppJob;
EnterCriticalSection(&globalMgr.cs);
list_add_head(&globalMgr.jobs, &job->entryFromQmgr);
LeaveCriticalSection(&globalMgr.cs);
@ -141,7 +140,7 @@ DWORD WINAPI fileTransfer(void *param)
LIST_FOR_EACH_ENTRY_SAFE(job, jobCur, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
{
list_remove(&job->entryFromQmgr);
IBackgroundCopyJob_Release((IBackgroundCopyJob *) job);
IBackgroundCopyJob2_Release(&job->IBackgroundCopyJob2_iface);
}
return 0;
}
@ -156,7 +155,7 @@ DWORD WINAPI fileTransfer(void *param)
if (job->state == BG_JOB_STATE_ACKNOWLEDGED || job->state == BG_JOB_STATE_CANCELLED)
{
list_remove(&job->entryFromQmgr);
IBackgroundCopyJob_Release((IBackgroundCopyJob *) job);
IBackgroundCopyJob2_Release(&job->IBackgroundCopyJob2_iface);
}
else if (job->state == BG_JOB_STATE_QUEUED)
{

View file

@ -33,7 +33,7 @@
/* Background copy job vtbl and related data */
typedef struct
{
const IBackgroundCopyJob2Vtbl *lpVtbl;
IBackgroundCopyJob2 IBackgroundCopyJob2_iface;
LONG ref;
LPWSTR displayName;
BG_JOB_TYPE type;
@ -79,14 +79,13 @@ extern BackgroundCopyManagerImpl globalMgr DECLSPEC_HIDDEN;
HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj) DECLSPEC_HIDDEN;
HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
GUID *pJobId, LPVOID *ppObj) DECLSPEC_HIDDEN;
GUID *pJobId, BackgroundCopyJobImpl **job) DECLSPEC_HIDDEN;
HRESULT enum_copy_job_create(BackgroundCopyManagerImpl *qmgr,
IEnumBackgroundCopyJobs **enumjob) DECLSPEC_HIDDEN;
HRESULT BackgroundCopyFileConstructor(BackgroundCopyJobImpl *owner,
LPCWSTR remoteName, LPCWSTR localName,
LPVOID *ppObj) DECLSPEC_HIDDEN;
HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj,
IBackgroundCopyJob2 *copyJob) DECLSPEC_HIDDEN;
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl*, IEnumBackgroundCopyFiles**) DECLSPEC_HIDDEN;
DWORD WINAPI fileTransfer(void *param) DECLSPEC_HIDDEN;
void processJob(BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;
BOOL processFile(BackgroundCopyFileImpl *file, BackgroundCopyJobImpl *job) DECLSPEC_HIDDEN;