qmgr: Implement the IUnknown interface for IEnumBackgroundCopyFiles.
[wine/wine64.git] / dlls / qmgr / enum_files.c
blob8dd479a8088b1220b4f2d42feb04505161bb9e06
1 /*
2 * Queue Manager (BITS) File Enumerator
4 * Copyright 2007 Google (Roy Shea)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "qmgr.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
26 static void EnumBackgroundCopyFilesDestructor(EnumBackgroundCopyFilesImpl *This)
28 ULONG i;
30 for(i = 0; i < This->numFiles; i++)
31 IBackgroundCopyFile_Release(This->files[i]);
33 HeapFree(GetProcessHeap(), 0, This->files);
34 HeapFree(GetProcessHeap(), 0, This);
37 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_AddRef(
38 IEnumBackgroundCopyFiles* iface)
40 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
41 return InterlockedIncrement(&This->ref);
44 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_QueryInterface(
45 IEnumBackgroundCopyFiles* iface,
46 REFIID riid,
47 void **ppvObject)
49 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
50 TRACE("IID: %s\n", debugstr_guid(riid));
52 if (IsEqualGUID(riid, &IID_IUnknown)
53 || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles))
55 *ppvObject = &This->lpVtbl;
56 BITS_IEnumBackgroundCopyFiles_AddRef(iface);
57 return S_OK;
60 *ppvObject = NULL;
61 return E_NOINTERFACE;
64 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release(
65 IEnumBackgroundCopyFiles* iface)
67 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface;
68 ULONG ref = InterlockedDecrement(&This->ref);
70 if (ref == 0)
71 EnumBackgroundCopyFilesDestructor(This);
73 return ref;
76 /*** IEnumBackgroundCopyFiles methods ***/
77 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next(
78 IEnumBackgroundCopyFiles* iface,
79 ULONG celt,
80 IBackgroundCopyFile **rgelt,
81 ULONG *pceltFetched)
83 FIXME("Not implemented\n");
84 return E_NOTIMPL;
87 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip(
88 IEnumBackgroundCopyFiles* iface,
89 ULONG celt)
91 FIXME("Not implemented\n");
92 return E_NOTIMPL;
95 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset(
96 IEnumBackgroundCopyFiles* iface)
98 FIXME("Not implemented\n");
99 return E_NOTIMPL;
102 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone(
103 IEnumBackgroundCopyFiles* iface,
104 IEnumBackgroundCopyFiles **ppenum)
106 FIXME("Not implemented\n");
107 return E_NOTIMPL;
110 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount(
111 IEnumBackgroundCopyFiles* iface,
112 ULONG *puCount)
114 FIXME("Not implemented\n");
115 return E_NOTIMPL;
118 static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl =
120 BITS_IEnumBackgroundCopyFiles_QueryInterface,
121 BITS_IEnumBackgroundCopyFiles_AddRef,
122 BITS_IEnumBackgroundCopyFiles_Release,
123 BITS_IEnumBackgroundCopyFiles_Next,
124 BITS_IEnumBackgroundCopyFiles_Skip,
125 BITS_IEnumBackgroundCopyFiles_Reset,
126 BITS_IEnumBackgroundCopyFiles_Clone,
127 BITS_IEnumBackgroundCopyFiles_GetCount
130 HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob* iCopyJob)
132 EnumBackgroundCopyFilesImpl *This;
133 BackgroundCopyFileImpl *file;
134 BackgroundCopyJobImpl *job = (BackgroundCopyJobImpl *) iCopyJob;
135 ULONG i;
137 TRACE("%p, %p)\n", ppObj, job);
139 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
140 if (!This)
141 return E_OUTOFMEMORY;
143 This->lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl;
144 This->ref = 1;
146 /* Create array of files */
147 This->indexFiles = 0;
148 This->numFiles = list_count(&job->files);
149 This->files = NULL;
150 if (This->numFiles > 0)
152 This->files = HeapAlloc(GetProcessHeap(), 0,
153 This->numFiles * sizeof This->files[0]);
154 if (!This->files)
156 HeapFree(GetProcessHeap(), 0, This);
157 return E_OUTOFMEMORY;
161 i = 0;
162 LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob)
164 file->lpVtbl->AddRef((IBackgroundCopyFile *) file);
165 This->files[i] = (IBackgroundCopyFile *) file;
166 ++i;
169 *ppObj = &This->lpVtbl;
170 return S_OK;