ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

enum_jobs.c
Go to the documentation of this file.
00001 /*
00002  * Queue Manager (BITS) Job Enumerator
00003  *
00004  * Copyright 2007 Google (Roy Shea)
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 EnumBackgroundCopyJobsDestructor(EnumBackgroundCopyJobsImpl *This)
00027 {
00028     ULONG i;
00029 
00030     for(i = 0; i < This->numJobs; i++)
00031         IBackgroundCopyJob_Release(This->jobs[i]);
00032 
00033     HeapFree(GetProcessHeap(), 0, This->jobs);
00034     HeapFree(GetProcessHeap(), 0, This);
00035 }
00036 
00037 static ULONG WINAPI BITS_IEnumBackgroundCopyJobs_AddRef(
00038     IEnumBackgroundCopyJobs* iface)
00039 {
00040     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00041     return InterlockedIncrement(&This->ref);
00042 }
00043 
00044 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_QueryInterface(
00045     IEnumBackgroundCopyJobs* iface,
00046     REFIID riid,
00047     void **ppvObject)
00048 {
00049     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00050     TRACE("IID: %s\n", debugstr_guid(riid));
00051 
00052     if (IsEqualGUID(riid, &IID_IUnknown)
00053         || IsEqualGUID(riid, &IID_IEnumBackgroundCopyJobs))
00054     {
00055         *ppvObject = &This->lpVtbl;
00056         BITS_IEnumBackgroundCopyJobs_AddRef(iface);
00057         return S_OK;
00058     }
00059 
00060     *ppvObject = NULL;
00061     return E_NOINTERFACE;
00062 }
00063 
00064 static ULONG WINAPI BITS_IEnumBackgroundCopyJobs_Release(
00065     IEnumBackgroundCopyJobs* iface)
00066 {
00067     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00068     ULONG ref = InterlockedDecrement(&This->ref);
00069 
00070     if (ref == 0)
00071         EnumBackgroundCopyJobsDestructor(This);
00072 
00073     return ref;
00074 }
00075 
00076 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Next(
00077     IEnumBackgroundCopyJobs* iface,
00078     ULONG celt,
00079     IBackgroundCopyJob **rgelt,
00080     ULONG *pceltFetched)
00081 {
00082     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00083     ULONG fetched;
00084     ULONG i;
00085     IBackgroundCopyJob *job;
00086 
00087     fetched = min(celt, This->numJobs - This->indexJobs);
00088     if (pceltFetched)
00089         *pceltFetched = fetched;
00090     else
00091     {
00092         /* We need to initialize this array if the caller doesn't request
00093            the length because length_is will default to celt.  */
00094         for (i = 0; i < celt; ++i)
00095             rgelt[i] = NULL;
00096 
00097         /* pceltFetched can only be NULL if celt is 1 */
00098         if (celt != 1)
00099             return E_INVALIDARG;
00100     }
00101 
00102     /* Fill in the array of objects */
00103     for (i = 0; i < fetched; ++i)
00104     {
00105         job = This->jobs[This->indexJobs++];
00106         IBackgroundCopyJob_AddRef(job);
00107         rgelt[i] = job;
00108     }
00109 
00110     return fetched == celt ? S_OK : S_FALSE;
00111 }
00112 
00113 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Skip(
00114     IEnumBackgroundCopyJobs* iface,
00115     ULONG celt)
00116 {
00117     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00118 
00119     if (This->numJobs - This->indexJobs < celt)
00120     {
00121         This->indexJobs = This->numJobs;
00122         return S_FALSE;
00123     }
00124 
00125     This->indexJobs += celt;
00126     return S_OK;
00127 }
00128 
00129 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Reset(
00130     IEnumBackgroundCopyJobs* iface)
00131 {
00132     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00133     This->indexJobs = 0;
00134     return S_OK;
00135 }
00136 
00137 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_Clone(
00138     IEnumBackgroundCopyJobs* iface,
00139     IEnumBackgroundCopyJobs **ppenum)
00140 {
00141     FIXME("Not implemented\n");
00142     return E_NOTIMPL;
00143 }
00144 
00145 static HRESULT WINAPI BITS_IEnumBackgroundCopyJobs_GetCount(
00146     IEnumBackgroundCopyJobs* iface,
00147     ULONG *puCount)
00148 {
00149     EnumBackgroundCopyJobsImpl *This = (EnumBackgroundCopyJobsImpl *) iface;
00150     *puCount = This->numJobs;
00151     return S_OK;
00152 }
00153 
00154 static const IEnumBackgroundCopyJobsVtbl BITS_IEnumBackgroundCopyJobs_Vtbl =
00155 {
00156     BITS_IEnumBackgroundCopyJobs_QueryInterface,
00157     BITS_IEnumBackgroundCopyJobs_AddRef,
00158     BITS_IEnumBackgroundCopyJobs_Release,
00159     BITS_IEnumBackgroundCopyJobs_Next,
00160     BITS_IEnumBackgroundCopyJobs_Skip,
00161     BITS_IEnumBackgroundCopyJobs_Reset,
00162     BITS_IEnumBackgroundCopyJobs_Clone,
00163     BITS_IEnumBackgroundCopyJobs_GetCount
00164 };
00165 
00166 HRESULT EnumBackgroundCopyJobsConstructor(LPVOID *ppObj,
00167                                           IBackgroundCopyManager* copyManager)
00168 {
00169     BackgroundCopyManagerImpl *qmgr = (BackgroundCopyManagerImpl *) copyManager;
00170     EnumBackgroundCopyJobsImpl *This;
00171     BackgroundCopyJobImpl *job;
00172     ULONG i;
00173 
00174     TRACE("%p, %p)\n", ppObj, copyManager);
00175 
00176     This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
00177     if (!This)
00178         return E_OUTOFMEMORY;
00179     This->lpVtbl = &BITS_IEnumBackgroundCopyJobs_Vtbl;
00180     This->ref = 1;
00181 
00182     /* Create array of jobs */
00183     This->indexJobs = 0;
00184 
00185     EnterCriticalSection(&qmgr->cs);
00186     This->numJobs = list_count(&qmgr->jobs);
00187 
00188     if (0 < This->numJobs)
00189     {
00190         This->jobs = HeapAlloc(GetProcessHeap(), 0,
00191                                This->numJobs * sizeof *This->jobs);
00192         if (!This->jobs)
00193         {
00194             LeaveCriticalSection(&qmgr->cs);
00195             HeapFree(GetProcessHeap(), 0, This);
00196             return E_OUTOFMEMORY;
00197         }
00198     }
00199     else
00200         This->jobs = NULL;
00201 
00202     i = 0;
00203     LIST_FOR_EACH_ENTRY(job, &qmgr->jobs, BackgroundCopyJobImpl, entryFromQmgr)
00204     {
00205         IBackgroundCopyJob *iJob = (IBackgroundCopyJob *) job;
00206         IBackgroundCopyJob_AddRef(iJob);
00207         This->jobs[i++] = iJob;
00208     }
00209     LeaveCriticalSection(&qmgr->cs);
00210 
00211     *ppObj = &This->lpVtbl;
00212     return S_OK;
00213 }

Generated on Sun May 27 2012 04:25:56 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.