qmgr: Implement IBackgroundCopyFile_GetProgress.
[wine/gsoc_dplay.git] / dlls / qmgr / file.c
blob93ffba4922b870ef61c040540cbd67bc30fc50cf
1 /*
2 * Queue Manager (BITS) File
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 BackgroundCopyFileDestructor(BackgroundCopyFileImpl *This)
28 HeapFree(GetProcessHeap(), 0, This->info.LocalName);
29 HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
30 HeapFree(GetProcessHeap(), 0, This);
33 static ULONG WINAPI BITS_IBackgroundCopyFile_AddRef(IBackgroundCopyFile* iface)
35 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
36 return InterlockedIncrement(&This->ref);
39 static HRESULT WINAPI BITS_IBackgroundCopyFile_QueryInterface(
40 IBackgroundCopyFile* iface,
41 REFIID riid,
42 void **ppvObject)
44 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
46 if (IsEqualGUID(riid, &IID_IUnknown)
47 || IsEqualGUID(riid, &IID_IBackgroundCopyFile))
49 *ppvObject = &This->lpVtbl;
50 BITS_IBackgroundCopyFile_AddRef(iface);
51 return S_OK;
54 *ppvObject = NULL;
55 return E_NOINTERFACE;
59 static ULONG WINAPI BITS_IBackgroundCopyFile_Release(
60 IBackgroundCopyFile* iface)
62 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
63 ULONG ref = InterlockedDecrement(&This->ref);
65 if (ref == 0)
66 BackgroundCopyFileDestructor(This);
68 return ref;
71 /* Get the remote name of a background copy file */
72 static HRESULT WINAPI BITS_IBackgroundCopyFile_GetRemoteName(
73 IBackgroundCopyFile* iface,
74 LPWSTR *pVal)
76 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
77 int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR);
79 *pVal = CoTaskMemAlloc(n);
80 if (!*pVal)
81 return E_OUTOFMEMORY;
83 memcpy(*pVal, This->info.RemoteName, n);
84 return S_OK;
87 static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
88 IBackgroundCopyFile* iface,
89 LPWSTR *pVal)
91 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
92 int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR);
94 *pVal = CoTaskMemAlloc(n);
95 if (!*pVal)
96 return E_OUTOFMEMORY;
98 memcpy(*pVal, This->info.LocalName, n);
99 return S_OK;
102 static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
103 IBackgroundCopyFile* iface,
104 BG_FILE_PROGRESS *pVal)
106 BackgroundCopyFileImpl *This = (BackgroundCopyFileImpl *) iface;
108 pVal->BytesTotal = This->fileProgress.BytesTotal;
109 pVal->BytesTransferred = This->fileProgress.BytesTransferred;
110 pVal->Completed = This->fileProgress.Completed;
112 return S_OK;
115 static const IBackgroundCopyFileVtbl BITS_IBackgroundCopyFile_Vtbl =
117 BITS_IBackgroundCopyFile_QueryInterface,
118 BITS_IBackgroundCopyFile_AddRef,
119 BITS_IBackgroundCopyFile_Release,
120 BITS_IBackgroundCopyFile_GetRemoteName,
121 BITS_IBackgroundCopyFile_GetLocalName,
122 BITS_IBackgroundCopyFile_GetProgress
125 HRESULT BackgroundCopyFileConstructor(LPCWSTR remoteName,
126 LPCWSTR localName, LPVOID *ppObj)
128 BackgroundCopyFileImpl *This;
129 int n;
131 TRACE("(%s,%s,%p)\n", debugstr_w(remoteName),
132 debugstr_w(localName), ppObj);
134 This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
135 if (!This)
136 return E_OUTOFMEMORY;
138 n = (lstrlenW(remoteName) + 1) * sizeof(WCHAR);
139 This->info.RemoteName = HeapAlloc(GetProcessHeap(), 0, n);
140 if (!This->info.RemoteName)
142 HeapFree(GetProcessHeap(), 0, This);
143 return E_OUTOFMEMORY;
145 memcpy(This->info.RemoteName, remoteName, n);
147 n = (lstrlenW(localName) + 1) * sizeof(WCHAR);
148 This->info.LocalName = HeapAlloc(GetProcessHeap(), 0, n);
149 if (!This->info.LocalName)
151 HeapFree(GetProcessHeap(), 0, This->info.RemoteName);
152 HeapFree(GetProcessHeap(), 0, This);
153 return E_OUTOFMEMORY;
155 memcpy(This->info.LocalName, localName, n);
157 This->lpVtbl = &BITS_IBackgroundCopyFile_Vtbl;
158 This->ref = 1;
160 This->fileProgress.BytesTotal = BG_SIZE_UNKNOWN;
161 This->fileProgress.BytesTransferred = 0;
162 This->fileProgress.Completed = FALSE;
164 *ppObj = &This->lpVtbl;
165 return S_OK;