2008-02-27 02:52:04 +01:00
|
|
|
/*
|
|
|
|
* Queue Manager (BITS) File Enumerator
|
|
|
|
*
|
2008-02-29 03:57:52 +01:00
|
|
|
* Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman)
|
2008-02-27 02:52:04 +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-05 23:53:15 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IEnumBackgroundCopyFiles IEnumBackgroundCopyFiles_iface;
|
|
|
|
LONG ref;
|
|
|
|
IBackgroundCopyFile **files;
|
|
|
|
ULONG numFiles;
|
|
|
|
ULONG indexFiles;
|
|
|
|
} EnumBackgroundCopyFilesImpl;
|
|
|
|
|
|
|
|
static inline EnumBackgroundCopyFilesImpl *impl_from_IEnumBackgroundCopyFiles(IEnumBackgroundCopyFiles *iface)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
return CONTAINING_RECORD(iface, EnumBackgroundCopyFilesImpl, IEnumBackgroundCopyFiles_iface);
|
2008-02-27 02:52:04 +01:00
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_QueryInterface(IEnumBackgroundCopyFiles *iface,
|
|
|
|
REFIID riid, void **ppv)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppv);
|
2008-02-27 02:52:04 +01:00
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles))
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
*ppv = iface;
|
|
|
|
IEnumBackgroundCopyFiles_AddRef(iface);
|
2008-02-27 02:52:04 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
*ppv = NULL;
|
2008-02-27 02:52:04 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_AddRef(IEnumBackgroundCopyFiles *iface)
|
|
|
|
{
|
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release(IEnumBackgroundCopyFiles *iface)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
2008-02-27 02:52:04 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2012-12-05 23:57:52 +01:00
|
|
|
ULONG i;
|
2008-02-27 02:52:04 +01:00
|
|
|
|
|
|
|
if (ref == 0)
|
2012-12-05 23:57:52 +01:00
|
|
|
{
|
|
|
|
for(i = 0; i < This->numFiles; i++)
|
|
|
|
IBackgroundCopyFile_Release(This->files[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->files);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2008-02-27 02:52:04 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2008-02-29 03:57:52 +01:00
|
|
|
/* Return reference to one or more files in the file enumerator */
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next(IEnumBackgroundCopyFiles *iface,
|
|
|
|
ULONG celt, IBackgroundCopyFile **rgelt, ULONG *pceltFetched)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
2008-02-29 03:57:52 +01:00
|
|
|
ULONG fetched;
|
|
|
|
ULONG i;
|
|
|
|
IBackgroundCopyFile *file;
|
|
|
|
|
|
|
|
/* Despite documented behavior, Windows (tested on XP) is not verifying
|
|
|
|
that the caller set pceltFetched to zero. No check here. */
|
|
|
|
|
|
|
|
fetched = min(celt, This->numFiles - This->indexFiles);
|
|
|
|
if (pceltFetched)
|
|
|
|
*pceltFetched = fetched;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We need to initialize this array if the caller doesn't request
|
|
|
|
the length because length_is will default to celt. */
|
|
|
|
for (i = 0; i < celt; i++)
|
|
|
|
rgelt[i] = NULL;
|
|
|
|
|
|
|
|
/* pceltFetched can only be NULL if celt is 1 */
|
|
|
|
if (celt != 1)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the array of objects */
|
|
|
|
for (i = 0; i < fetched; i++)
|
|
|
|
{
|
|
|
|
file = This->files[This->indexFiles++];
|
|
|
|
IBackgroundCopyFile_AddRef(file);
|
|
|
|
rgelt[i] = file;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fetched == celt ? S_OK : S_FALSE;
|
2008-02-27 02:52:04 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 03:58:32 +01:00
|
|
|
/* Skip over one or more files in the file enumerator */
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip(IEnumBackgroundCopyFiles *iface,
|
|
|
|
ULONG celt)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
2008-02-29 03:58:32 +01:00
|
|
|
|
|
|
|
if (celt > This->numFiles - This->indexFiles)
|
|
|
|
{
|
|
|
|
This->indexFiles = This->numFiles;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->indexFiles += celt;
|
|
|
|
return S_OK;
|
2008-02-27 02:52:04 +01:00
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset(IEnumBackgroundCopyFiles *iface)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
2008-02-29 03:58:32 +01:00
|
|
|
This->indexFiles = 0;
|
|
|
|
return S_OK;
|
2008-02-27 02:52:04 +01:00
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone(IEnumBackgroundCopyFiles *iface,
|
|
|
|
IEnumBackgroundCopyFiles **ppenum)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
|
|
|
FIXME("Not implemented\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount(IEnumBackgroundCopyFiles *iface,
|
|
|
|
ULONG *puCount)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
2012-12-05 23:53:15 +01:00
|
|
|
EnumBackgroundCopyFilesImpl *This = impl_from_IEnumBackgroundCopyFiles(iface);
|
2008-02-28 06:04:58 +01:00
|
|
|
*puCount = This->numFiles;
|
|
|
|
return S_OK;
|
2008-02-27 02:52:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl =
|
|
|
|
{
|
|
|
|
BITS_IEnumBackgroundCopyFiles_QueryInterface,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_AddRef,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_Release,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_Next,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_Skip,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_Reset,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_Clone,
|
|
|
|
BITS_IEnumBackgroundCopyFiles_GetCount
|
|
|
|
};
|
|
|
|
|
2013-01-17 19:39:26 +01:00
|
|
|
HRESULT EnumBackgroundCopyFilesConstructor(BackgroundCopyJobImpl *job, IEnumBackgroundCopyFiles **enum_files)
|
2008-02-27 02:52:04 +01:00
|
|
|
{
|
|
|
|
EnumBackgroundCopyFilesImpl *This;
|
|
|
|
BackgroundCopyFileImpl *file;
|
|
|
|
ULONG i;
|
|
|
|
|
2013-01-17 19:39:26 +01:00
|
|
|
TRACE("%p, %p)\n", job, enum_files);
|
2008-02-27 02:52:04 +01:00
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-12-05 23:53:15 +01:00
|
|
|
This->IEnumBackgroundCopyFiles_iface.lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl;
|
2008-02-27 02:52:04 +01:00
|
|
|
This->ref = 1;
|
|
|
|
|
|
|
|
/* Create array of files */
|
|
|
|
This->indexFiles = 0;
|
2008-03-12 19:56:13 +01:00
|
|
|
EnterCriticalSection(&job->cs);
|
2008-02-27 02:52:04 +01:00
|
|
|
This->numFiles = list_count(&job->files);
|
|
|
|
This->files = NULL;
|
|
|
|
if (This->numFiles > 0)
|
|
|
|
{
|
|
|
|
This->files = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
This->numFiles * sizeof This->files[0]);
|
|
|
|
if (!This->files)
|
|
|
|
{
|
2008-03-12 19:56:13 +01:00
|
|
|
LeaveCriticalSection(&job->cs);
|
2008-02-27 02:52:04 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
|
|
|
|
{
|
2013-01-18 05:38:49 +01:00
|
|
|
IBackgroundCopyFile_AddRef(&file->IBackgroundCopyFile_iface);
|
|
|
|
This->files[i] = &file->IBackgroundCopyFile_iface;
|
2008-02-27 02:52:04 +01:00
|
|
|
++i;
|
|
|
|
}
|
2008-03-12 19:56:13 +01:00
|
|
|
LeaveCriticalSection(&job->cs);
|
2008-02-27 02:52:04 +01:00
|
|
|
|
2013-01-17 19:39:26 +01:00
|
|
|
*enum_files = &This->IEnumBackgroundCopyFiles_iface;
|
2008-02-27 02:52:04 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|