Branching for 0.3.15 release after two days of no response from a certain sphere...
[reactos.git] / dll / win32 / mstask / task_scheduler.c
1 /*
2 * Copyright (C) 2008 Google (Roy Shea)
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #include <corerror.h>
24 #include "mstask_private.h"
25 #include <wine/debug.h>
26
27 WINE_DEFAULT_DEBUG_CHANNEL(mstask);
28
29 typedef struct
30 {
31 ITaskScheduler ITaskScheduler_iface;
32 LONG ref;
33 } TaskSchedulerImpl;
34
35 static inline TaskSchedulerImpl *impl_from_ITaskScheduler(ITaskScheduler *iface)
36 {
37 return CONTAINING_RECORD(iface, TaskSchedulerImpl, ITaskScheduler_iface);
38 }
39
40 static void TaskSchedulerDestructor(TaskSchedulerImpl *This)
41 {
42 TRACE("%p\n", This);
43 HeapFree(GetProcessHeap(), 0, This);
44 InterlockedDecrement(&dll_ref);
45 }
46
47 static HRESULT WINAPI MSTASK_ITaskScheduler_QueryInterface(
48 ITaskScheduler* iface,
49 REFIID riid,
50 void **ppvObject)
51 {
52 TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
53
54 TRACE("IID: %s\n", debugstr_guid(riid));
55
56 if (IsEqualGUID(riid, &IID_IUnknown) ||
57 IsEqualGUID(riid, &IID_ITaskScheduler))
58 {
59 *ppvObject = &This->ITaskScheduler_iface;
60 ITaskScheduler_AddRef(iface);
61 return S_OK;
62 }
63
64 *ppvObject = NULL;
65 return E_NOINTERFACE;
66 }
67
68 static ULONG WINAPI MSTASK_ITaskScheduler_AddRef(
69 ITaskScheduler* iface)
70 {
71 TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
72 TRACE("\n");
73 return InterlockedIncrement(&This->ref);
74 }
75
76 static ULONG WINAPI MSTASK_ITaskScheduler_Release(
77 ITaskScheduler* iface)
78 {
79 TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
80 ULONG ref;
81 TRACE("\n");
82 ref = InterlockedDecrement(&This->ref);
83 if (ref == 0)
84 TaskSchedulerDestructor(This);
85 return ref;
86 }
87
88 static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer(
89 ITaskScheduler* iface,
90 LPCWSTR pwszComputer)
91 {
92 FIXME("%p, %s: stub\n", iface, debugstr_w(pwszComputer));
93 return E_NOTIMPL;
94 }
95
96 static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer(
97 ITaskScheduler* iface,
98 LPWSTR *ppwszComputer)
99 {
100 FIXME("%p, %p: stub\n", iface, ppwszComputer);
101 return E_NOTIMPL;
102 }
103
104 static HRESULT WINAPI MSTASK_ITaskScheduler_Enum(
105 ITaskScheduler* iface,
106 IEnumWorkItems **ppEnumTasks)
107 {
108 FIXME("%p, %p: stub\n", iface, ppEnumTasks);
109 return E_NOTIMPL;
110 }
111
112 static HRESULT WINAPI MSTASK_ITaskScheduler_Activate(
113 ITaskScheduler* iface,
114 LPCWSTR pwszName,
115 REFIID riid,
116 IUnknown **ppunk)
117 {
118 TRACE("%p, %s, %s, %p: stub\n", iface, debugstr_w(pwszName),
119 debugstr_guid(riid), ppunk);
120 FIXME("Partial stub always returning COR_E_FILENOTFOUND\n");
121 return COR_E_FILENOTFOUND;
122 }
123
124 static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(
125 ITaskScheduler* iface,
126 LPCWSTR pwszName)
127 {
128 FIXME("%p, %s: stub\n", iface, debugstr_w(pwszName));
129 return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
133 ITaskScheduler* iface,
134 LPCWSTR pwszTaskName,
135 REFCLSID rclsid,
136 REFIID riid,
137 IUnknown **ppunk)
138 {
139 HRESULT hr;
140 TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(pwszTaskName),
141 debugstr_guid(rclsid) ,debugstr_guid(riid), ppunk);
142
143 if (!IsEqualGUID(rclsid, &CLSID_CTask))
144 return CLASS_E_CLASSNOTAVAILABLE;
145
146 if (!IsEqualGUID(riid, &IID_ITask))
147 return E_NOINTERFACE;
148
149 hr = TaskConstructor(pwszTaskName, (LPVOID *)ppunk);
150 return hr;
151 }
152
153 static HRESULT WINAPI MSTASK_ITaskScheduler_AddWorkItem(
154 ITaskScheduler* iface,
155 LPCWSTR pwszTaskName,
156 IScheduledWorkItem *pWorkItem)
157 {
158 FIXME("%p, %s, %p: stub\n", iface, debugstr_w(pwszTaskName), pWorkItem);
159 return E_NOTIMPL;
160 }
161
162 static HRESULT WINAPI MSTASK_ITaskScheduler_IsOfType(
163 ITaskScheduler* iface,
164 LPCWSTR pwszName,
165 REFIID riid)
166 {
167 FIXME("%p, %s, %s: stub\n", iface, debugstr_w(pwszName),
168 debugstr_guid(riid));
169 return E_NOTIMPL;
170 }
171
172 static const ITaskSchedulerVtbl MSTASK_ITaskSchedulerVtbl =
173 {
174 MSTASK_ITaskScheduler_QueryInterface,
175 MSTASK_ITaskScheduler_AddRef,
176 MSTASK_ITaskScheduler_Release,
177 MSTASK_ITaskScheduler_SetTargetComputer,
178 MSTASK_ITaskScheduler_GetTargetComputer,
179 MSTASK_ITaskScheduler_Enum,
180 MSTASK_ITaskScheduler_Activate,
181 MSTASK_ITaskScheduler_Delete,
182 MSTASK_ITaskScheduler_NewWorkItem,
183 MSTASK_ITaskScheduler_AddWorkItem,
184 MSTASK_ITaskScheduler_IsOfType
185 };
186
187 HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
188 {
189 TaskSchedulerImpl *This;
190 TRACE("(%p)\n", ppObj);
191
192 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
193 if (!This)
194 return E_OUTOFMEMORY;
195
196 This->ITaskScheduler_iface.lpVtbl = &MSTASK_ITaskSchedulerVtbl;
197 This->ref = 1;
198
199 *ppObj = &This->ITaskScheduler_iface;
200 InterlockedIncrement(&dll_ref);
201 return S_OK;
202 }