2 * Copyright (C) 2008 Google (Roy Shea)
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
20 #include "mstask_private.h"
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(mstask);
27 ITaskScheduler ITaskScheduler_iface;
31 static inline TaskSchedulerImpl *impl_from_ITaskScheduler(ITaskScheduler *iface)
33 return CONTAINING_RECORD(iface, TaskSchedulerImpl, ITaskScheduler_iface);
36 static void TaskSchedulerDestructor(TaskSchedulerImpl *This)
39 HeapFree(GetProcessHeap(), 0, This);
40 InterlockedDecrement(&dll_ref);
43 static HRESULT WINAPI MSTASK_ITaskScheduler_QueryInterface(
44 ITaskScheduler* iface,
48 TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
50 TRACE("IID: %s\n", debugstr_guid(riid));
52 if (IsEqualGUID(riid, &IID_IUnknown) ||
53 IsEqualGUID(riid, &IID_ITaskScheduler))
55 *ppvObject = &This->ITaskScheduler_iface;
56 ITaskScheduler_AddRef(iface);
64 static ULONG WINAPI MSTASK_ITaskScheduler_AddRef(
65 ITaskScheduler* iface)
67 TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
69 return InterlockedIncrement(&This->ref);
72 static ULONG WINAPI MSTASK_ITaskScheduler_Release(
73 ITaskScheduler* iface)
75 TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
78 ref = InterlockedDecrement(&This->ref);
80 TaskSchedulerDestructor(This);
84 static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer(
85 ITaskScheduler* iface,
88 TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
89 WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 3]; /* extra space for two '\' and a zero */
90 DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for a zero */
92 TRACE("(%p)->(%s)\n", This, debugstr_w(pwszComputer));
94 /* NULL is an alias for the local computer */
100 if (GetComputerNameW(buffer + 2, &len))
102 if (!lstrcmpiW(buffer, pwszComputer) || /* full unc name */
103 !lstrcmpiW(buffer + 2, pwszComputer)) /* name without backslash */
107 FIXME("remote computer %s not supported\n", debugstr_w(pwszComputer));
108 return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH);
111 static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer(
112 ITaskScheduler* iface,
113 LPWSTR *ppwszComputer)
115 TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
117 DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for the zero */
119 TRACE("(%p)->(%p)\n", This, ppwszComputer);
124 /* extra space for two '\' and a zero */
125 buffer = CoTaskMemAlloc((MAX_COMPUTERNAME_LENGTH + 3) * sizeof(WCHAR));
130 if (GetComputerNameW(buffer + 2, &len))
132 *ppwszComputer = buffer;
135 CoTaskMemFree(buffer);
137 *ppwszComputer = NULL;
138 return HRESULT_FROM_WIN32(GetLastError());
141 static HRESULT WINAPI MSTASK_ITaskScheduler_Enum(
142 ITaskScheduler* iface,
143 IEnumWorkItems **ppEnumTasks)
145 FIXME("%p, %p: stub\n", iface, ppEnumTasks);
149 static HRESULT WINAPI MSTASK_ITaskScheduler_Activate(
150 ITaskScheduler* iface,
155 TRACE("%p, %s, %s, %p: stub\n", iface, debugstr_w(pwszName),
156 debugstr_guid(riid), ppunk);
157 FIXME("Partial stub always returning COR_E_FILENOTFOUND\n");
158 return COR_E_FILENOTFOUND;
161 static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(
162 ITaskScheduler* iface,
165 FIXME("%p, %s: stub\n", iface, debugstr_w(pwszName));
169 static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
170 ITaskScheduler* iface,
171 LPCWSTR pwszTaskName,
177 TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(pwszTaskName),
178 debugstr_guid(rclsid) ,debugstr_guid(riid), ppunk);
180 if (!IsEqualGUID(rclsid, &CLSID_CTask))
181 return CLASS_E_CLASSNOTAVAILABLE;
183 if (!IsEqualGUID(riid, &IID_ITask))
184 return E_NOINTERFACE;
186 hr = TaskConstructor(pwszTaskName, (LPVOID *)ppunk);
190 static HRESULT WINAPI MSTASK_ITaskScheduler_AddWorkItem(
191 ITaskScheduler* iface,
192 LPCWSTR pwszTaskName,
193 IScheduledWorkItem *pWorkItem)
195 FIXME("%p, %s, %p: stub\n", iface, debugstr_w(pwszTaskName), pWorkItem);
199 static HRESULT WINAPI MSTASK_ITaskScheduler_IsOfType(
200 ITaskScheduler* iface,
204 FIXME("%p, %s, %s: stub\n", iface, debugstr_w(pwszName),
205 debugstr_guid(riid));
209 static const ITaskSchedulerVtbl MSTASK_ITaskSchedulerVtbl =
211 MSTASK_ITaskScheduler_QueryInterface,
212 MSTASK_ITaskScheduler_AddRef,
213 MSTASK_ITaskScheduler_Release,
214 MSTASK_ITaskScheduler_SetTargetComputer,
215 MSTASK_ITaskScheduler_GetTargetComputer,
216 MSTASK_ITaskScheduler_Enum,
217 MSTASK_ITaskScheduler_Activate,
218 MSTASK_ITaskScheduler_Delete,
219 MSTASK_ITaskScheduler_NewWorkItem,
220 MSTASK_ITaskScheduler_AddWorkItem,
221 MSTASK_ITaskScheduler_IsOfType
224 HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
226 TaskSchedulerImpl *This;
227 TRACE("(%p)\n", ppObj);
229 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
231 return E_OUTOFMEMORY;
233 This->ITaskScheduler_iface.lpVtbl = &MSTASK_ITaskSchedulerVtbl;
236 *ppObj = &This->ITaskScheduler_iface;
237 InterlockedIncrement(&dll_ref);