winepulse: Wrap unix call parameters in structs.
[wine.git] / dlls / taskschd / folder_collection.c
blob394210db318e583af9ea0fef73fa4e307e77bf03
1 /*
2 * Copyright 2014 Dmitry Timoshkov
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "taskschd.h"
27 #include "schrpc.h"
28 #include "taskschd_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(taskschd);
34 typedef struct
36 ITaskFolderCollection ITaskFolderCollection_iface;
37 LONG ref;
38 WCHAR *path;
39 TASK_NAMES list;
40 DWORD count;
41 } TaskFolderCollection;
43 static HRESULT NewEnum_create(TaskFolderCollection *folders, IUnknown **obj);
45 static inline TaskFolderCollection *impl_from_ITaskFolderCollection(ITaskFolderCollection *iface)
47 return CONTAINING_RECORD(iface, TaskFolderCollection, ITaskFolderCollection_iface);
50 static ULONG WINAPI folders_AddRef(ITaskFolderCollection *iface)
52 TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
53 return InterlockedIncrement(&folders->ref);
56 static void free_list(LPWSTR *list, DWORD count)
58 LONG i;
60 for (i = 0; i < count; i++)
61 MIDL_user_free(list[i]);
63 MIDL_user_free(list);
66 static ULONG WINAPI folders_Release(ITaskFolderCollection *iface)
68 TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
69 LONG ref = InterlockedDecrement(&folders->ref);
71 if (!ref)
73 TRACE("destroying %p\n", iface);
74 free_list(folders->list, folders->count);
75 heap_free(folders->path);
76 heap_free(folders);
79 return ref;
82 static HRESULT WINAPI folders_QueryInterface(ITaskFolderCollection *iface, REFIID riid, void **obj)
84 if (!riid || !obj) return E_INVALIDARG;
86 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
88 if (IsEqualGUID(riid, &IID_ITaskFolderCollection) ||
89 IsEqualGUID(riid, &IID_IDispatch) ||
90 IsEqualGUID(riid, &IID_IUnknown))
92 ITaskFolderCollection_AddRef(iface);
93 *obj = iface;
94 return S_OK;
97 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
98 *obj = NULL;
99 return E_NOINTERFACE;
102 static HRESULT WINAPI folders_GetTypeInfoCount(ITaskFolderCollection *iface, UINT *count)
104 FIXME("%p,%p: stub\n", iface, count);
105 return E_NOTIMPL;
108 static HRESULT WINAPI folders_GetTypeInfo(ITaskFolderCollection *iface, UINT index, LCID lcid, ITypeInfo **info)
110 FIXME("%p,%u,%u,%p: stub\n", iface, index, lcid, info);
111 return E_NOTIMPL;
114 static HRESULT WINAPI folders_GetIDsOfNames(ITaskFolderCollection *iface, REFIID riid, LPOLESTR *names,
115 UINT count, LCID lcid, DISPID *dispid)
117 FIXME("%p,%s,%p,%u,%u,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
118 return E_NOTIMPL;
121 static HRESULT WINAPI folders_Invoke(ITaskFolderCollection *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
122 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
124 FIXME("%p,%d,%s,%04x,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
125 params, result, excepinfo, argerr);
126 return E_NOTIMPL;
129 static HRESULT WINAPI folders_get_Count(ITaskFolderCollection *iface, LONG *count)
131 TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
133 TRACE("%p,%p\n", iface, count);
135 if (!count) return E_POINTER;
137 *count = folders->count;
139 return S_OK;
142 static LONG get_var_int(const VARIANT *var)
144 switch(V_VT(var))
146 case VT_I1:
147 case VT_UI1:
148 return V_UI1(var);
150 case VT_I2:
151 case VT_UI2:
152 return V_UI2(var);
154 case VT_I4:
155 case VT_UI4:
156 return V_UI4(var);
158 case VT_I8:
159 case VT_UI8:
160 return V_UI8(var);
162 case VT_INT:
163 case VT_UINT:
164 return V_UINT(var);
166 default:
167 FIXME("unsupported variant type %d\n", V_VT(var));
168 return 0;
172 static HRESULT WINAPI folders_get_Item(ITaskFolderCollection *iface, VARIANT index, ITaskFolder **folder)
174 TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
175 LONG idx;
177 TRACE("%p,%s,%p\n", iface, debugstr_variant(&index), folder);
179 if (!folder) return E_POINTER;
181 if (V_VT(&index) == VT_BSTR)
182 return TaskFolder_create(folders->path, V_BSTR(&index), folder, FALSE);
184 idx = get_var_int(&index);
185 /* collections are 1 based */
186 if (idx < 1 || idx > folders->count)
187 return E_INVALIDARG;
189 return TaskFolder_create(folders->path, folders->list[idx - 1], folder, FALSE);
192 static HRESULT WINAPI folders_get__NewEnum(ITaskFolderCollection *iface, IUnknown **penum)
194 TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
196 TRACE("%p,%p\n", iface, penum);
198 if (!penum) return E_POINTER;
200 return NewEnum_create(folders, penum);
203 static const ITaskFolderCollectionVtbl TaskFolderCollection_vtbl =
205 folders_QueryInterface,
206 folders_AddRef,
207 folders_Release,
208 folders_GetTypeInfoCount,
209 folders_GetTypeInfo,
210 folders_GetIDsOfNames,
211 folders_Invoke,
212 folders_get_Count,
213 folders_get_Item,
214 folders_get__NewEnum
217 HRESULT TaskFolderCollection_create(const WCHAR *path, ITaskFolderCollection **obj)
219 TaskFolderCollection *folders;
220 HRESULT hr;
221 TASK_NAMES list;
222 DWORD start_index, count;
224 start_index = 0;
225 list = NULL;
226 hr = SchRpcEnumFolders(path, 0, &start_index, 0, &count, &list);
227 if (hr != S_OK) return hr;
229 folders = heap_alloc(sizeof(*folders));
230 if (!folders)
232 free_list(list, count);
233 return E_OUTOFMEMORY;
236 folders->ITaskFolderCollection_iface.lpVtbl = &TaskFolderCollection_vtbl;
237 folders->ref = 1;
238 if (!(folders->path = heap_strdupW(path)))
240 heap_free(folders);
241 free_list(list, count);
242 return E_OUTOFMEMORY;
244 folders->count = count;
245 folders->list = list;
246 *obj = &folders->ITaskFolderCollection_iface;
248 TRACE("created %p\n", *obj);
250 return S_OK;
253 typedef struct
255 IEnumVARIANT IEnumVARIANT_iface;
256 LONG ref, pos;
257 TaskFolderCollection *folders;
258 } EnumVARIANT;
260 static inline EnumVARIANT *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
262 return CONTAINING_RECORD(iface, EnumVARIANT, IEnumVARIANT_iface);
265 static HRESULT WINAPI enumvar_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **obj)
267 if (!riid || !obj) return E_INVALIDARG;
269 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
271 if (IsEqualGUID(riid, &IID_IEnumVARIANT) ||
272 IsEqualGUID(riid, &IID_IUnknown))
274 IEnumVARIANT_AddRef(iface);
275 *obj = iface;
276 return S_OK;
279 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
280 *obj = NULL;
281 return E_NOINTERFACE;
284 static ULONG WINAPI enumvar_AddRef(IEnumVARIANT *iface)
286 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
287 return InterlockedIncrement(&enumvar->ref);
290 static ULONG WINAPI enumvar_Release(IEnumVARIANT *iface)
292 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
293 LONG ref = InterlockedDecrement(&enumvar->ref);
295 if (!ref)
297 TRACE("destroying %p\n", iface);
298 ITaskFolderCollection_Release(&enumvar->folders->ITaskFolderCollection_iface);
299 heap_free(enumvar);
302 return ref;
305 static HRESULT WINAPI enumvar_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *var, ULONG *fetched)
307 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
308 LONG i;
310 TRACE("%p,%u,%p,%p\n", iface, celt, var, fetched);
312 for (i = 0; i < celt && enumvar->pos < enumvar->folders->count; i++)
314 ITaskFolder *folder;
315 HRESULT hr;
317 hr = TaskFolder_create(enumvar->folders->path, enumvar->folders->list[enumvar->pos++], &folder, FALSE);
318 if (hr) return hr;
320 if (!var)
322 ITaskFolder_Release(folder);
323 return E_POINTER;
326 V_VT(&var[i]) = VT_DISPATCH;
327 V_DISPATCH(&var[i]) = (IDispatch *)folder;
330 if (fetched) *fetched = i;
332 return i == celt ? S_OK : S_FALSE;
335 static HRESULT WINAPI enumvar_Skip(IEnumVARIANT *iface, ULONG celt)
337 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
339 TRACE("%p,%u\n", iface, celt);
341 enumvar->pos += celt;
343 if (enumvar->pos > enumvar->folders->count)
345 enumvar->pos = enumvar->folders->count;
346 return S_FALSE;
349 return S_OK;
352 static HRESULT WINAPI enumvar_Reset(IEnumVARIANT *iface)
354 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
356 TRACE("%p\n", iface);
358 enumvar->pos = 0;
360 return S_OK;
363 static HRESULT WINAPI enumvar_Clone(IEnumVARIANT *iface, IEnumVARIANT **penum)
365 EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
367 TRACE("%p,%p\n", iface, penum);
369 return NewEnum_create(enumvar->folders, (IUnknown **)penum);
372 static const struct IEnumVARIANTVtbl EnumVARIANT_vtbl =
374 enumvar_QueryInterface,
375 enumvar_AddRef,
376 enumvar_Release,
377 enumvar_Next,
378 enumvar_Skip,
379 enumvar_Reset,
380 enumvar_Clone
383 static HRESULT NewEnum_create(TaskFolderCollection *folders, IUnknown **obj)
385 EnumVARIANT *enumvar;
387 enumvar = heap_alloc(sizeof(*enumvar));
388 if (!enumvar) return E_OUTOFMEMORY;
390 enumvar->IEnumVARIANT_iface.lpVtbl = &EnumVARIANT_vtbl;
391 enumvar->ref = 1;
392 enumvar->pos = 0;
393 enumvar->folders = folders;
394 ITaskFolderCollection_AddRef(&folders->ITaskFolderCollection_iface);
396 *obj = (IUnknown *)&enumvar->IEnumVARIANT_iface;
398 TRACE("created %p\n", *obj);
400 return S_OK;