qmgr: Implement IBackgroundCopyJob_GetType with test.
[wine] / dlls / qmgr / job.c
1 /*
2  * Background Copy Job Interface for BITS
3  *
4  * Copyright 2007 Google (Roy Shea)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "qmgr.h"
22 #include "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
25
26 static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
27 {
28     HeapFree(GetProcessHeap(), 0, This->displayName);
29     HeapFree(GetProcessHeap(), 0, This);
30 }
31
32 static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob* iface)
33 {
34     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
35     return InterlockedIncrement(&This->ref);
36 }
37
38 static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
39     IBackgroundCopyJob* iface, REFIID riid, LPVOID *ppvObject)
40 {
41     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
42     TRACE("IID: %s\n", debugstr_guid(riid));
43
44     if (IsEqualGUID(riid, &IID_IUnknown)
45         || IsEqualGUID(riid, &IID_IBackgroundCopyJob))
46     {
47         *ppvObject = &This->lpVtbl;
48         BITS_IBackgroundCopyJob_AddRef(iface);
49         return S_OK;
50     }
51
52     *ppvObject = NULL;
53     return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob* iface)
57 {
58     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
59     ULONG ref = InterlockedDecrement(&This->ref);
60
61     if (ref == 0)
62         BackgroundCopyJobDestructor(This);
63
64     return ref;
65 }
66
67 /*** IBackgroundCopyJob methods ***/
68
69 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
70     IBackgroundCopyJob* iface,
71     ULONG cFileCount,
72     BG_FILE_INFO *pFileSet)
73 {
74     FIXME("Not implemented\n");
75     return E_NOTIMPL;
76 }
77
78 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
79     IBackgroundCopyJob* iface,
80     LPCWSTR RemoteUrl,
81     LPCWSTR LocalName)
82 {
83     FIXME("Not implemented\n");
84     return E_NOTIMPL;
85 }
86
87 static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
88     IBackgroundCopyJob* iface,
89     IEnumBackgroundCopyFiles **pEnum)
90 {
91     FIXME("Not implemented\n");
92     return E_NOTIMPL;
93 }
94
95 static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
96     IBackgroundCopyJob* iface)
97 {
98     FIXME("Not implemented\n");
99     return E_NOTIMPL;
100 }
101
102 static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
103     IBackgroundCopyJob* iface)
104 {
105     FIXME("Not implemented\n");
106     return E_NOTIMPL;
107 }
108
109 static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
110     IBackgroundCopyJob* iface)
111 {
112     FIXME("Not implemented\n");
113     return E_NOTIMPL;
114 }
115
116 static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
117     IBackgroundCopyJob* iface)
118 {
119     FIXME("Not implemented\n");
120     return E_NOTIMPL;
121 }
122
123 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
124     IBackgroundCopyJob* iface,
125     GUID *pVal)
126 {
127     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
128     memcpy(pVal, &This->jobId, sizeof *pVal);
129     return S_OK;
130 }
131
132 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
133     IBackgroundCopyJob* iface,
134     BG_JOB_TYPE *pVal)
135 {
136     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
137
138     if (!pVal)
139         return E_INVALIDARG;
140
141     *pVal = This->type;
142     return S_OK;
143 }
144
145 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
146     IBackgroundCopyJob* iface,
147     BG_JOB_PROGRESS *pVal)
148 {
149     FIXME("Not implemented\n");
150     return E_NOTIMPL;
151 }
152
153 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
154     IBackgroundCopyJob* iface,
155     BG_JOB_TIMES *pVal)
156 {
157     FIXME("Not implemented\n");
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
162     IBackgroundCopyJob* iface,
163     BG_JOB_STATE *pVal)
164 {
165     FIXME("Not implemented\n");
166     return E_NOTIMPL;
167 }
168
169 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
170     IBackgroundCopyJob* iface,
171     IBackgroundCopyError **ppError)
172 {
173     FIXME("Not implemented\n");
174     return E_NOTIMPL;
175 }
176
177 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
178     IBackgroundCopyJob* iface,
179     LPWSTR *pVal)
180 {
181     FIXME("Not implemented\n");
182     return E_NOTIMPL;
183 }
184
185 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
186     IBackgroundCopyJob* iface,
187     LPCWSTR Val)
188 {
189     FIXME("Not implemented\n");
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
194     IBackgroundCopyJob* iface,
195     LPWSTR *pVal)
196 {
197     FIXME("Not implemented\n");
198     return E_NOTIMPL;
199 }
200
201 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
202     IBackgroundCopyJob* iface,
203     LPCWSTR Val)
204 {
205     FIXME("Not implemented\n");
206     return E_NOTIMPL;
207 }
208
209 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
210     IBackgroundCopyJob* iface,
211     LPWSTR *pVal)
212 {
213     FIXME("Not implemented\n");
214     return E_NOTIMPL;
215 }
216
217 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
218     IBackgroundCopyJob* iface,
219     BG_JOB_PRIORITY Val)
220 {
221     FIXME("Not implemented\n");
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
226     IBackgroundCopyJob* iface,
227     BG_JOB_PRIORITY *pVal)
228 {
229     FIXME("Not implemented\n");
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
234     IBackgroundCopyJob* iface,
235     ULONG Val)
236 {
237     FIXME("Not implemented\n");
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
242     IBackgroundCopyJob* iface,
243     ULONG *pVal)
244 {
245     FIXME("Not implemented\n");
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
250     IBackgroundCopyJob* iface,
251     IUnknown *Val)
252 {
253     FIXME("Not implemented\n");
254     return E_NOTIMPL;
255 }
256
257 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
258     IBackgroundCopyJob* iface,
259     IUnknown **pVal)
260 {
261     FIXME("Not implemented\n");
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
266     IBackgroundCopyJob* iface,
267     ULONG Seconds)
268 {
269     FIXME("Not implemented\n");
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
274     IBackgroundCopyJob* iface,
275     ULONG *Seconds)
276 {
277     FIXME("Not implemented\n");
278     return E_NOTIMPL;
279 }
280
281 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
282     IBackgroundCopyJob* iface,
283     ULONG Seconds)
284 {
285     FIXME("Not implemented\n");
286     return E_NOTIMPL;
287 }
288
289 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
290     IBackgroundCopyJob* iface,
291     ULONG *Seconds)
292 {
293     FIXME("Not implemented\n");
294     return E_NOTIMPL;
295 }
296
297 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
298     IBackgroundCopyJob* iface,
299     ULONG *Errors)
300 {
301     FIXME("Not implemented\n");
302     return E_NOTIMPL;
303 }
304
305 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
306     IBackgroundCopyJob* iface,
307     BG_JOB_PROXY_USAGE ProxyUsage,
308     const WCHAR *ProxyList,
309     const WCHAR *ProxyBypassList)
310 {
311     FIXME("Not implemented\n");
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
316     IBackgroundCopyJob* iface,
317     BG_JOB_PROXY_USAGE *pProxyUsage,
318     LPWSTR *pProxyList,
319     LPWSTR *pProxyBypassList)
320 {
321     FIXME("Not implemented\n");
322     return E_NOTIMPL;
323 }
324
325 static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
326     IBackgroundCopyJob* iface)
327 {
328     FIXME("Not implemented\n");
329     return E_NOTIMPL;
330 }
331
332
333 static const IBackgroundCopyJobVtbl BITS_IBackgroundCopyJob_Vtbl =
334 {
335     BITS_IBackgroundCopyJob_QueryInterface,
336     BITS_IBackgroundCopyJob_AddRef,
337     BITS_IBackgroundCopyJob_Release,
338     BITS_IBackgroundCopyJob_AddFileSet,
339     BITS_IBackgroundCopyJob_AddFile,
340     BITS_IBackgroundCopyJob_EnumFiles,
341     BITS_IBackgroundCopyJob_Suspend,
342     BITS_IBackgroundCopyJob_Resume,
343     BITS_IBackgroundCopyJob_Cancel,
344     BITS_IBackgroundCopyJob_Complete,
345     BITS_IBackgroundCopyJob_GetId,
346     BITS_IBackgroundCopyJob_GetType,
347     BITS_IBackgroundCopyJob_GetProgress,
348     BITS_IBackgroundCopyJob_GetTimes,
349     BITS_IBackgroundCopyJob_GetState,
350     BITS_IBackgroundCopyJob_GetError,
351     BITS_IBackgroundCopyJob_GetOwner,
352     BITS_IBackgroundCopyJob_SetDisplayName,
353     BITS_IBackgroundCopyJob_GetDisplayName,
354     BITS_IBackgroundCopyJob_SetDescription,
355     BITS_IBackgroundCopyJob_GetDescription,
356     BITS_IBackgroundCopyJob_SetPriority,
357     BITS_IBackgroundCopyJob_GetPriority,
358     BITS_IBackgroundCopyJob_SetNotifyFlags,
359     BITS_IBackgroundCopyJob_GetNotifyFlags,
360     BITS_IBackgroundCopyJob_SetNotifyInterface,
361     BITS_IBackgroundCopyJob_GetNotifyInterface,
362     BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
363     BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
364     BITS_IBackgroundCopyJob_SetNoProgressTimeout,
365     BITS_IBackgroundCopyJob_GetNoProgressTimeout,
366     BITS_IBackgroundCopyJob_GetErrorCount,
367     BITS_IBackgroundCopyJob_SetProxySettings,
368     BITS_IBackgroundCopyJob_GetProxySettings,
369     BITS_IBackgroundCopyJob_TakeOwnership,
370 };
371
372 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
373                                      GUID *pJobId, LPVOID *ppObj)
374 {
375     HRESULT hr;
376     BackgroundCopyJobImpl *This;
377     int n;
378
379     TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
380
381     This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
382     if (!This)
383         return E_OUTOFMEMORY;
384
385     This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
386     This->ref = 1;
387     This->type = type;
388
389     n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
390     This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
391     if (!This->displayName)
392     {
393         HeapFree(GetProcessHeap(), 0, This);
394         return E_OUTOFMEMORY;
395     }
396     memcpy(This->displayName, displayName, n);
397
398     hr = CoCreateGuid(&This->jobId);
399     if (FAILED(hr))
400     {
401         HeapFree(GetProcessHeap(), 0, This->displayName);
402         HeapFree(GetProcessHeap(), 0, This);
403         return hr;
404     }
405     memcpy(pJobId, &This->jobId, sizeof(GUID));
406
407     *ppObj = &This->lpVtbl;
408     return S_OK;
409 }