2007-12-20 05:02:23 +01:00
|
|
|
/*
|
|
|
|
* Queue Manager (BITS) core functions
|
|
|
|
*
|
2008-03-07 04:04:35 +01:00
|
|
|
* Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
|
2007-12-20 05:02:23 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qmgr.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
|
|
|
|
|
2012-12-04 00:57:09 +01:00
|
|
|
BackgroundCopyManagerImpl globalMgr;
|
2007-12-20 05:02:23 +01:00
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static HRESULT WINAPI BackgroundCopyManager_QueryInterface(IBackgroundCopyManager *iface,
|
2012-12-04 00:57:09 +01:00
|
|
|
REFIID riid, void **ppv)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2013-11-25 07:43:50 +01:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
2007-12-20 05:02:23 +01:00
|
|
|
|
2012-12-04 00:57:09 +01:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IBackgroundCopyManager))
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2012-12-04 00:57:09 +01:00
|
|
|
*ppv = iface;
|
|
|
|
IBackgroundCopyManager_AddRef(iface);
|
2007-12-20 05:02:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-04 00:57:09 +01:00
|
|
|
*ppv = NULL;
|
2007-12-20 05:02:23 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static ULONG WINAPI BackgroundCopyManager_AddRef(IBackgroundCopyManager *iface)
|
2012-12-04 00:57:09 +01:00
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static ULONG WINAPI BackgroundCopyManager_Release(IBackgroundCopyManager *iface)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2008-03-07 04:04:35 +01:00
|
|
|
return 1;
|
2007-12-20 05:02:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IBackgroundCopyManager interface methods ***/
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static HRESULT WINAPI BackgroundCopyManager_CreateJob(IBackgroundCopyManager *iface,
|
2012-12-04 00:57:09 +01:00
|
|
|
LPCWSTR DisplayName, BG_JOB_TYPE Type, GUID *pJobId, IBackgroundCopyJob **ppJob)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2008-02-29 04:01:29 +01:00
|
|
|
BackgroundCopyJobImpl *job;
|
|
|
|
HRESULT hres;
|
2013-11-25 07:43:50 +01:00
|
|
|
|
|
|
|
TRACE("(%s %d %p %p)\n", debugstr_w(DisplayName), Type, pJobId, ppJob);
|
2008-02-29 04:01:29 +01:00
|
|
|
|
2013-01-17 19:39:26 +01:00
|
|
|
hres = BackgroundCopyJobConstructor(DisplayName, Type, pJobId, &job);
|
2008-02-29 04:01:29 +01:00
|
|
|
if (FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
/* Add a reference to the job to job list */
|
2020-05-08 14:40:21 +02:00
|
|
|
*ppJob = (IBackgroundCopyJob *)&job->IBackgroundCopyJob4_iface;
|
2008-02-29 04:01:29 +01:00
|
|
|
IBackgroundCopyJob_AddRef(*ppJob);
|
2012-12-04 00:57:09 +01:00
|
|
|
EnterCriticalSection(&globalMgr.cs);
|
|
|
|
list_add_head(&globalMgr.jobs, &job->entryFromQmgr);
|
|
|
|
LeaveCriticalSection(&globalMgr.cs);
|
2008-02-29 04:01:29 +01:00
|
|
|
return S_OK;
|
2007-12-20 05:02:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static HRESULT WINAPI BackgroundCopyManager_GetJob(IBackgroundCopyManager *iface,
|
2013-11-25 07:43:29 +01:00
|
|
|
REFGUID jobID, IBackgroundCopyJob **job)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2013-11-25 07:43:29 +01:00
|
|
|
BackgroundCopyManagerImpl *qmgr = &globalMgr;
|
|
|
|
HRESULT hr = BG_E_NOT_FOUND;
|
|
|
|
BackgroundCopyJobImpl *cur;
|
|
|
|
|
|
|
|
TRACE("(%s %p)\n", debugstr_guid(jobID), job);
|
|
|
|
|
|
|
|
if (!job || !jobID) return E_INVALIDARG;
|
|
|
|
|
|
|
|
*job = NULL;
|
|
|
|
|
|
|
|
EnterCriticalSection(&qmgr->cs);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(cur, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&cur->jobId, jobID))
|
|
|
|
{
|
2020-05-08 14:40:21 +02:00
|
|
|
*job = (IBackgroundCopyJob *)&cur->IBackgroundCopyJob4_iface;
|
|
|
|
IBackgroundCopyJob_AddRef(*job);
|
2013-11-25 07:43:29 +01:00
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&qmgr->cs);
|
|
|
|
|
|
|
|
return hr;
|
2007-12-20 05:02:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static HRESULT WINAPI BackgroundCopyManager_EnumJobs(IBackgroundCopyManager *iface,
|
|
|
|
DWORD flags, IEnumBackgroundCopyJobs **ppEnum)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2022-02-17 07:11:19 +01:00
|
|
|
TRACE("(0x%lx %p)\n", flags, ppEnum);
|
2012-12-04 00:59:02 +01:00
|
|
|
return enum_copy_job_create(&globalMgr, ppEnum);
|
2007-12-20 05:02:23 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static HRESULT WINAPI BackgroundCopyManager_GetErrorDescription(IBackgroundCopyManager *iface,
|
|
|
|
HRESULT hr, DWORD langid, LPWSTR *error_description)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2022-02-17 07:11:19 +01:00
|
|
|
FIXME("(0x%08lx 0x%lx %p): stub\n", hr, langid, error_description);
|
2007-12-20 05:02:23 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-11-25 07:43:50 +01:00
|
|
|
static const IBackgroundCopyManagerVtbl BackgroundCopyManagerVtbl =
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2013-11-25 07:43:50 +01:00
|
|
|
BackgroundCopyManager_QueryInterface,
|
|
|
|
BackgroundCopyManager_AddRef,
|
|
|
|
BackgroundCopyManager_Release,
|
|
|
|
BackgroundCopyManager_CreateJob,
|
|
|
|
BackgroundCopyManager_GetJob,
|
|
|
|
BackgroundCopyManager_EnumJobs,
|
|
|
|
BackgroundCopyManager_GetErrorDescription
|
2007-12-20 05:02:23 +01:00
|
|
|
};
|
|
|
|
|
2008-03-12 19:56:13 +01:00
|
|
|
BackgroundCopyManagerImpl globalMgr = {
|
2013-11-25 07:43:50 +01:00
|
|
|
{ &BackgroundCopyManagerVtbl },
|
2008-03-07 04:04:35 +01:00
|
|
|
{ NULL, -1, 0, 0, 0, 0 },
|
2008-03-13 23:54:01 +01:00
|
|
|
NULL,
|
2008-03-07 04:04:35 +01:00
|
|
|
LIST_INIT(globalMgr.jobs)
|
|
|
|
};
|
|
|
|
|
2007-12-20 05:02:23 +01:00
|
|
|
/* Constructor for instances of background copy manager */
|
2013-12-30 10:20:33 +01:00
|
|
|
HRESULT BackgroundCopyManagerConstructor(LPVOID *ppObj)
|
2007-12-20 05:02:23 +01:00
|
|
|
{
|
2013-12-30 10:20:33 +01:00
|
|
|
TRACE("(%p)\n", ppObj);
|
2009-01-22 09:51:39 +01:00
|
|
|
*ppObj = &globalMgr;
|
2007-12-20 05:02:23 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2008-03-13 23:54:01 +01:00
|
|
|
|
|
|
|
DWORD WINAPI fileTransfer(void *param)
|
|
|
|
{
|
|
|
|
BackgroundCopyManagerImpl *qmgr = &globalMgr;
|
|
|
|
HANDLE events[2];
|
|
|
|
|
|
|
|
events[0] = stop_event;
|
|
|
|
events[1] = qmgr->jobEvent;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
BackgroundCopyJobImpl *job, *jobCur;
|
|
|
|
BOOL haveJob = FALSE;
|
|
|
|
|
|
|
|
/* Check if it's the stop_event */
|
|
|
|
if (WaitForMultipleObjects(2, events, FALSE, INFINITE) == WAIT_OBJECT_0)
|
2009-03-07 22:56:00 +01:00
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(job, jobCur, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
|
|
|
|
{
|
|
|
|
list_remove(&job->entryFromQmgr);
|
2020-05-08 14:40:21 +02:00
|
|
|
IBackgroundCopyJob4_Release(&job->IBackgroundCopyJob4_iface);
|
2009-03-07 22:56:00 +01:00
|
|
|
}
|
2008-03-13 23:54:01 +01:00
|
|
|
return 0;
|
2009-03-07 22:56:00 +01:00
|
|
|
}
|
2008-03-13 23:54:01 +01:00
|
|
|
|
|
|
|
/* Note that other threads may add files to the job list, but only
|
|
|
|
this thread ever deletes them so we don't need to worry about jobs
|
|
|
|
magically disappearing from the list. */
|
|
|
|
EnterCriticalSection(&qmgr->cs);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(job, jobCur, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
|
|
|
|
{
|
|
|
|
if (job->state == BG_JOB_STATE_ACKNOWLEDGED || job->state == BG_JOB_STATE_CANCELLED)
|
|
|
|
{
|
|
|
|
list_remove(&job->entryFromQmgr);
|
2020-05-08 14:40:21 +02:00
|
|
|
IBackgroundCopyJob4_Release(&job->IBackgroundCopyJob4_iface);
|
2008-03-13 23:54:01 +01:00
|
|
|
}
|
|
|
|
else if (job->state == BG_JOB_STATE_QUEUED)
|
|
|
|
{
|
|
|
|
haveJob = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (job->state == BG_JOB_STATE_CONNECTING
|
|
|
|
|| job->state == BG_JOB_STATE_TRANSFERRING)
|
|
|
|
{
|
|
|
|
ERR("Invalid state for job %p: %d\n", job, job->state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!haveJob)
|
|
|
|
ResetEvent(qmgr->jobEvent);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&qmgr->cs);
|
|
|
|
|
|
|
|
if (haveJob)
|
2008-03-13 23:54:35 +01:00
|
|
|
processJob(job);
|
2008-03-13 23:54:01 +01:00
|
|
|
}
|
|
|
|
}
|