Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenenum_files.c
Go to the documentation of this file.
00001 /* 00002 * Queue Manager (BITS) File Enumerator 00003 * 00004 * Copyright 2007, 2008 Google (Roy Shea, Dan Hipschman) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00019 */ 00020 00021 #include "qmgr.h" 00022 #include "wine/debug.h" 00023 00024 WINE_DEFAULT_DEBUG_CHANNEL(qmgr); 00025 00026 static void EnumBackgroundCopyFilesDestructor(EnumBackgroundCopyFilesImpl *This) 00027 { 00028 ULONG i; 00029 00030 for(i = 0; i < This->numFiles; i++) 00031 IBackgroundCopyFile_Release(This->files[i]); 00032 00033 HeapFree(GetProcessHeap(), 0, This->files); 00034 HeapFree(GetProcessHeap(), 0, This); 00035 } 00036 00037 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_AddRef( 00038 IEnumBackgroundCopyFiles* iface) 00039 { 00040 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00041 return InterlockedIncrement(&This->ref); 00042 } 00043 00044 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_QueryInterface( 00045 IEnumBackgroundCopyFiles* iface, 00046 REFIID riid, 00047 void **ppvObject) 00048 { 00049 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00050 TRACE("IID: %s\n", debugstr_guid(riid)); 00051 00052 if (IsEqualGUID(riid, &IID_IUnknown) 00053 || IsEqualGUID(riid, &IID_IEnumBackgroundCopyFiles)) 00054 { 00055 *ppvObject = &This->lpVtbl; 00056 BITS_IEnumBackgroundCopyFiles_AddRef(iface); 00057 return S_OK; 00058 } 00059 00060 *ppvObject = NULL; 00061 return E_NOINTERFACE; 00062 } 00063 00064 static ULONG WINAPI BITS_IEnumBackgroundCopyFiles_Release( 00065 IEnumBackgroundCopyFiles* iface) 00066 { 00067 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00068 ULONG ref = InterlockedDecrement(&This->ref); 00069 00070 if (ref == 0) 00071 EnumBackgroundCopyFilesDestructor(This); 00072 00073 return ref; 00074 } 00075 00076 /* Return reference to one or more files in the file enumerator */ 00077 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Next( 00078 IEnumBackgroundCopyFiles* iface, 00079 ULONG celt, 00080 IBackgroundCopyFile **rgelt, 00081 ULONG *pceltFetched) 00082 { 00083 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00084 ULONG fetched; 00085 ULONG i; 00086 IBackgroundCopyFile *file; 00087 00088 /* Despite documented behavior, Windows (tested on XP) is not verifying 00089 that the caller set pceltFetched to zero. No check here. */ 00090 00091 fetched = min(celt, This->numFiles - This->indexFiles); 00092 if (pceltFetched) 00093 *pceltFetched = fetched; 00094 else 00095 { 00096 /* We need to initialize this array if the caller doesn't request 00097 the length because length_is will default to celt. */ 00098 for (i = 0; i < celt; i++) 00099 rgelt[i] = NULL; 00100 00101 /* pceltFetched can only be NULL if celt is 1 */ 00102 if (celt != 1) 00103 return E_INVALIDARG; 00104 } 00105 00106 /* Fill in the array of objects */ 00107 for (i = 0; i < fetched; i++) 00108 { 00109 file = This->files[This->indexFiles++]; 00110 IBackgroundCopyFile_AddRef(file); 00111 rgelt[i] = file; 00112 } 00113 00114 return fetched == celt ? S_OK : S_FALSE; 00115 } 00116 00117 /* Skip over one or more files in the file enumerator */ 00118 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Skip( 00119 IEnumBackgroundCopyFiles* iface, 00120 ULONG celt) 00121 { 00122 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00123 00124 if (celt > This->numFiles - This->indexFiles) 00125 { 00126 This->indexFiles = This->numFiles; 00127 return S_FALSE; 00128 } 00129 00130 This->indexFiles += celt; 00131 return S_OK; 00132 } 00133 00134 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Reset( 00135 IEnumBackgroundCopyFiles* iface) 00136 { 00137 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00138 This->indexFiles = 0; 00139 return S_OK; 00140 } 00141 00142 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_Clone( 00143 IEnumBackgroundCopyFiles* iface, 00144 IEnumBackgroundCopyFiles **ppenum) 00145 { 00146 FIXME("Not implemented\n"); 00147 return E_NOTIMPL; 00148 } 00149 00150 static HRESULT WINAPI BITS_IEnumBackgroundCopyFiles_GetCount( 00151 IEnumBackgroundCopyFiles* iface, 00152 ULONG *puCount) 00153 { 00154 EnumBackgroundCopyFilesImpl *This = (EnumBackgroundCopyFilesImpl *) iface; 00155 *puCount = This->numFiles; 00156 return S_OK; 00157 } 00158 00159 static const IEnumBackgroundCopyFilesVtbl BITS_IEnumBackgroundCopyFiles_Vtbl = 00160 { 00161 BITS_IEnumBackgroundCopyFiles_QueryInterface, 00162 BITS_IEnumBackgroundCopyFiles_AddRef, 00163 BITS_IEnumBackgroundCopyFiles_Release, 00164 BITS_IEnumBackgroundCopyFiles_Next, 00165 BITS_IEnumBackgroundCopyFiles_Skip, 00166 BITS_IEnumBackgroundCopyFiles_Reset, 00167 BITS_IEnumBackgroundCopyFiles_Clone, 00168 BITS_IEnumBackgroundCopyFiles_GetCount 00169 }; 00170 00171 HRESULT EnumBackgroundCopyFilesConstructor(LPVOID *ppObj, IBackgroundCopyJob2 *iCopyJob) 00172 { 00173 EnumBackgroundCopyFilesImpl *This; 00174 BackgroundCopyFileImpl *file; 00175 BackgroundCopyJobImpl *job = (BackgroundCopyJobImpl *) iCopyJob; 00176 ULONG i; 00177 00178 TRACE("%p, %p)\n", ppObj, job); 00179 00180 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This); 00181 if (!This) 00182 return E_OUTOFMEMORY; 00183 00184 This->lpVtbl = &BITS_IEnumBackgroundCopyFiles_Vtbl; 00185 This->ref = 1; 00186 00187 /* Create array of files */ 00188 This->indexFiles = 0; 00189 EnterCriticalSection(&job->cs); 00190 This->numFiles = list_count(&job->files); 00191 This->files = NULL; 00192 if (This->numFiles > 0) 00193 { 00194 This->files = HeapAlloc(GetProcessHeap(), 0, 00195 This->numFiles * sizeof This->files[0]); 00196 if (!This->files) 00197 { 00198 LeaveCriticalSection(&job->cs); 00199 HeapFree(GetProcessHeap(), 0, This); 00200 return E_OUTOFMEMORY; 00201 } 00202 } 00203 00204 i = 0; 00205 LIST_FOR_EACH_ENTRY(file, &job->files, BackgroundCopyFileImpl, entryFromJob) 00206 { 00207 file->lpVtbl->AddRef((IBackgroundCopyFile *) file); 00208 This->files[i] = (IBackgroundCopyFile *) file; 00209 ++i; 00210 } 00211 LeaveCriticalSection(&job->cs); 00212 00213 *ppObj = &This->lpVtbl; 00214 return S_OK; 00215 } Generated on Sat May 26 2012 04:24:29 for ReactOS by
1.7.6.1
|