qmgr: Implement IBackgroundCopyManager_EnumJobs with test.
[wine] / dlls / qmgr / qmgr.c
1 /*
2  * Queue Manager (BITS) core functions
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 /* Destructor for instances of background copy manager */
27 static void BackgroundCopyManagerDestructor(BackgroundCopyManagerImpl *This)
28 {
29     TRACE("%p\n", This);
30     HeapFree(GetProcessHeap(), 0, This);
31 }
32
33 /* Add a reference to the iface pointer */
34 static ULONG WINAPI BITS_IBackgroundCopyManager_AddRef(
35         IBackgroundCopyManager* iface)
36 {
37     BackgroundCopyManagerImpl * This = (BackgroundCopyManagerImpl *)iface;
38     ULONG ref;
39
40     TRACE("\n");
41
42     ref = InterlockedIncrement(&This->ref);
43     return ref;
44 }
45
46 /* Attempt to provide a new interface to interact with iface */
47 static HRESULT WINAPI BITS_IBackgroundCopyManager_QueryInterface(
48         IBackgroundCopyManager* iface,
49         REFIID riid,
50         LPVOID *ppvObject)
51 {
52     BackgroundCopyManagerImpl * This = (BackgroundCopyManagerImpl *)iface;
53
54     TRACE("IID: %s\n", debugstr_guid(riid));
55
56     if (IsEqualGUID(riid, &IID_IUnknown) ||
57             IsEqualGUID(riid, &IID_IBackgroundCopyManager))
58     {
59         *ppvObject = &This->lpVtbl;
60         BITS_IBackgroundCopyManager_AddRef(iface);
61         return S_OK;
62     }
63
64     *ppvObject = NULL;
65     return E_NOINTERFACE;
66 }
67
68 /* Release an interface to iface */
69 static ULONG WINAPI BITS_IBackgroundCopyManager_Release(
70         IBackgroundCopyManager* iface)
71 {
72     BackgroundCopyManagerImpl * This = (BackgroundCopyManagerImpl *)iface;
73     ULONG ref;
74
75     TRACE("\n");
76
77     ref = InterlockedDecrement(&This->ref);
78     if (ref == 0)
79     {
80         BackgroundCopyManagerDestructor(This);
81     }
82     return ref;
83 }
84
85 /*** IBackgroundCopyManager interface methods ***/
86
87 static HRESULT WINAPI BITS_IBackgroundCopyManager_CreateJob(
88         IBackgroundCopyManager* iface,
89         LPCWSTR DisplayName,
90         BG_JOB_TYPE Type,
91         GUID *pJobId,
92         IBackgroundCopyJob **ppJob)
93 {
94     TRACE("\n");
95     return BackgroundCopyJobConstructor(DisplayName, Type, pJobId,
96                                         (LPVOID *) ppJob);
97 }
98
99 static HRESULT WINAPI BITS_IBackgroundCopyManager_GetJob(
100         IBackgroundCopyManager* iface,
101         REFGUID jobID,
102         IBackgroundCopyJob **ppJob)
103 {
104     FIXME("Not implemented\n");
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI BITS_IBackgroundCopyManager_EnumJobs(
109         IBackgroundCopyManager* iface,
110         DWORD dwFlags,
111         IEnumBackgroundCopyJobs **ppEnum)
112 {
113     TRACE("\n");
114     return EnumBackgroundCopyJobsConstructor((LPVOID *) ppEnum, iface);
115 }
116
117 static HRESULT WINAPI BITS_IBackgroundCopyManager_GetErrorDescription(
118         IBackgroundCopyManager* iface,
119         HRESULT hResult,
120         DWORD LanguageId,
121         LPWSTR *pErrorDescription)
122 {
123     FIXME("Not implemented\n");
124     return E_NOTIMPL;
125 }
126
127
128 static const IBackgroundCopyManagerVtbl BITS_IBackgroundCopyManager_Vtbl =
129 {
130     BITS_IBackgroundCopyManager_QueryInterface,
131     BITS_IBackgroundCopyManager_AddRef,
132     BITS_IBackgroundCopyManager_Release,
133     BITS_IBackgroundCopyManager_CreateJob,
134     BITS_IBackgroundCopyManager_GetJob,
135     BITS_IBackgroundCopyManager_EnumJobs,
136     BITS_IBackgroundCopyManager_GetErrorDescription
137 };
138
139 /* Constructor for instances of background copy manager */
140 HRESULT BackgroundCopyManagerConstructor(IUnknown *pUnkOuter, LPVOID *ppObj)
141 {
142     BackgroundCopyManagerImpl *This;
143
144     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
145
146     This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
147     if (!This)
148     {
149         return E_OUTOFMEMORY;
150     }
151
152     This->lpVtbl = &BITS_IBackgroundCopyManager_Vtbl;
153     This->ref = 1;
154
155     *ppObj = &This->lpVtbl;
156     return S_OK;
157 }