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