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
19 #include "mstask_private.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(mstask
);
24 static inline TaskImpl
*impl_from_IPersistFile( IPersistFile
*iface
)
26 return (TaskImpl
*) ((char*)(iface
) - FIELD_OFFSET(TaskImpl
, persistVtbl
));
29 static void TaskDestructor(TaskImpl
*This
)
32 HeapFree(GetProcessHeap(), 0, This
->comment
);
33 HeapFree(GetProcessHeap(), 0, This
->parameters
);
34 HeapFree(GetProcessHeap(), 0, This
->taskName
);
35 HeapFree(GetProcessHeap(), 0, This
);
36 InterlockedDecrement(&dll_ref
);
39 static HRESULT WINAPI
MSTASK_ITask_QueryInterface(
44 TaskImpl
* This
= (TaskImpl
*)iface
;
46 TRACE("IID: %s\n", debugstr_guid(riid
));
47 if (ppvObject
== NULL
)
50 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
51 IsEqualGUID(riid
, &IID_ITask
))
53 *ppvObject
= &This
->lpVtbl
;
57 else if (IsEqualGUID(riid
, &IID_IPersistFile
))
59 *ppvObject
= &This
->persistVtbl
;
64 WARN("Unknown interface: %s\n", debugstr_guid(riid
));
69 static ULONG WINAPI
MSTASK_ITask_AddRef(
72 TaskImpl
*This
= (TaskImpl
*)iface
;
75 ref
= InterlockedIncrement(&This
->ref
);
79 static ULONG WINAPI
MSTASK_ITask_Release(
82 TaskImpl
* This
= (TaskImpl
*)iface
;
85 ref
= InterlockedDecrement(&This
->ref
);
91 static HRESULT WINAPI
MSTASK_ITask_CreateTrigger(
94 ITaskTrigger
**ppTrigger
)
96 FIXME("(%p, %p, %p): stub\n", iface
, piNewTrigger
, ppTrigger
);
100 static HRESULT WINAPI
MSTASK_ITask_DeleteTrigger(
104 FIXME("(%p, %d): stub\n", iface
, iTrigger
);
108 static HRESULT WINAPI
MSTASK_ITask_GetTriggerCount(
112 FIXME("(%p, %p): stub\n", iface
, plCount
);
116 static HRESULT WINAPI
MSTASK_ITask_GetTrigger(
119 ITaskTrigger
**ppTrigger
)
121 FIXME("(%p, %d, %p): stub\n", iface
, iTrigger
, ppTrigger
);
125 static HRESULT WINAPI
MSTASK_ITask_GetTriggerString(
128 LPWSTR
*ppwszTrigger
)
130 FIXME("(%p, %d, %p): stub\n", iface
, iTrigger
, ppwszTrigger
);
134 static HRESULT WINAPI
MSTASK_ITask_GetRunTimes(
136 const LPSYSTEMTIME pstBegin
,
137 const LPSYSTEMTIME pstEnd
,
139 LPSYSTEMTIME
*rgstTaskTimes
)
141 FIXME("(%p, %p, %p, %p, %p): stub\n", iface
, pstBegin
, pstEnd
, pCount
,
146 static HRESULT WINAPI
MSTASK_ITask_GetNextRunTime(
148 SYSTEMTIME
*pstNextRun
)
150 FIXME("(%p, %p): stub\n", iface
, pstNextRun
);
154 static HRESULT WINAPI
MSTASK_ITask_SetIdleWait(
157 WORD wDeadlineMinutes
)
159 FIXME("(%p, %d, %d): stub\n", iface
, wIdleMinutes
, wDeadlineMinutes
);
163 static HRESULT WINAPI
MSTASK_ITask_GetIdleWait(
166 WORD
*pwDeadlineMinutes
)
168 FIXME("(%p, %p, %p): stub\n", iface
, pwIdleMinutes
, pwDeadlineMinutes
);
172 static HRESULT WINAPI
MSTASK_ITask_Run(
175 FIXME("(%p): stub\n", iface
);
179 static HRESULT WINAPI
MSTASK_ITask_Terminate(
182 FIXME("(%p): stub\n", iface
);
186 static HRESULT WINAPI
MSTASK_ITask_EditWorkItem(
191 FIXME("(%p, %p, %d): stub\n", iface
, hParent
, dwReserved
);
195 static HRESULT WINAPI
MSTASK_ITask_GetMostRecentRunTime(
197 SYSTEMTIME
*pstLastRun
)
199 FIXME("(%p, %p): stub\n", iface
, pstLastRun
);
203 static HRESULT WINAPI
MSTASK_ITask_GetStatus(
207 FIXME("(%p, %p): stub\n", iface
, phrStatus
);
211 static HRESULT WINAPI
MSTASK_ITask_GetExitCode(
215 FIXME("(%p, %p): stub\n", iface
, pdwExitCode
);
219 static HRESULT WINAPI
MSTASK_ITask_SetComment(
224 TaskImpl
*This
= (TaskImpl
*)iface
;
227 TRACE("(%p, %s)\n", iface
, debugstr_w(pwszComment
));
230 if (pwszComment
[0] == 0)
232 HeapFree(GetProcessHeap(), 0, This
->comment
);
233 This
->comment
= NULL
;
237 /* Set to pwszComment */
238 n
= (lstrlenW(pwszComment
) + 1);
239 tmp_comment
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
241 return E_OUTOFMEMORY
;
242 lstrcpyW(tmp_comment
, pwszComment
);
243 HeapFree(GetProcessHeap(), 0, This
->comment
);
244 This
->comment
= tmp_comment
;
249 static HRESULT WINAPI
MSTASK_ITask_GetComment(
251 LPWSTR
*ppwszComment
)
254 TaskImpl
*This
= (TaskImpl
*)iface
;
256 TRACE("(%p, %p)\n", iface
, ppwszComment
);
258 n
= This
->comment
? lstrlenW(This
->comment
) + 1 : 1;
259 *ppwszComment
= CoTaskMemAlloc(n
* sizeof(WCHAR
));
261 return E_OUTOFMEMORY
;
264 *ppwszComment
[0] = 0;
266 lstrcpyW(*ppwszComment
, This
->comment
);
271 static HRESULT WINAPI
MSTASK_ITask_SetCreator(
275 FIXME("(%p, %p): stub\n", iface
, pwszCreator
);
279 static HRESULT WINAPI
MSTASK_ITask_GetCreator(
281 LPWSTR
*ppwszCreator
)
283 FIXME("(%p, %p): stub\n", iface
, ppwszCreator
);
287 static HRESULT WINAPI
MSTASK_ITask_SetWorkItemData(
292 FIXME("(%p, %d, %p): stub\n", iface
, cBytes
, rgbData
);
296 static HRESULT WINAPI
MSTASK_ITask_GetWorkItemData(
301 FIXME("(%p, %p, %p): stub\n", iface
, pcBytes
, ppBytes
);
305 static HRESULT WINAPI
MSTASK_ITask_SetErrorRetryCount(
309 FIXME("(%p, %d): stub\n", iface
, wRetryCount
);
313 static HRESULT WINAPI
MSTASK_ITask_GetErrorRetryCount(
317 FIXME("(%p, %p): stub\n", iface
, pwRetryCount
);
321 static HRESULT WINAPI
MSTASK_ITask_SetErrorRetryInterval(
325 FIXME("(%p, %d): stub\n", iface
, wRetryInterval
);
329 static HRESULT WINAPI
MSTASK_ITask_GetErrorRetryInterval(
331 WORD
*pwRetryInterval
)
333 FIXME("(%p, %p): stub\n", iface
, pwRetryInterval
);
337 static HRESULT WINAPI
MSTASK_ITask_SetFlags(
341 FIXME("(%p, 0x%08x): stub\n", iface
, dwFlags
);
345 static HRESULT WINAPI
MSTASK_ITask_GetFlags(
349 FIXME("(%p, %p): stub\n", iface
, pdwFlags
);
353 static HRESULT WINAPI
MSTASK_ITask_SetAccountInformation(
355 LPCWSTR pwszAccountName
,
356 LPCWSTR pwszPassword
)
358 FIXME("(%p, %s, %s): stub\n", iface
, debugstr_w(pwszAccountName
),
359 debugstr_w(pwszPassword
));
363 static HRESULT WINAPI
MSTASK_ITask_GetAccountInformation(
365 LPWSTR
*ppwszAccountName
)
367 FIXME("(%p, %p): stub\n", iface
, ppwszAccountName
);
371 static HRESULT WINAPI
MSTASK_ITask_SetApplicationName(
373 LPCWSTR pwszApplicationName
)
376 TaskImpl
*This
= (TaskImpl
*)iface
;
379 TRACE("(%p, %s)\n", iface
, debugstr_w(pwszApplicationName
));
381 /* Empty application name */
382 if (pwszApplicationName
[0] == 0)
384 HeapFree(GetProcessHeap(), 0, This
->applicationName
);
385 This
->applicationName
= NULL
;
389 /* Attempt to set pwszApplicationName to a path resolved application name */
390 n
= SearchPathW(NULL
, pwszApplicationName
, NULL
, 0, NULL
, NULL
);
393 tmp_name
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
395 return E_OUTOFMEMORY
;
396 n
= SearchPathW(NULL
, pwszApplicationName
, NULL
, n
, tmp_name
, NULL
);
399 HeapFree(GetProcessHeap(), 0, This
->applicationName
);
400 This
->applicationName
= tmp_name
;
404 HeapFree(GetProcessHeap(), 0, tmp_name
);
407 /* If unable to path resolve name, simply set to pwszApplicationName */
408 n
= (lstrlenW(pwszApplicationName
) + 1);
409 tmp_name
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
411 return E_OUTOFMEMORY
;
412 lstrcpyW(tmp_name
, pwszApplicationName
);
413 HeapFree(GetProcessHeap(), 0, This
->applicationName
);
414 This
->applicationName
= tmp_name
;
418 static HRESULT WINAPI
MSTASK_ITask_GetApplicationName(
420 LPWSTR
*ppwszApplicationName
)
423 TaskImpl
*This
= (TaskImpl
*)iface
;
425 TRACE("(%p, %p)\n", iface
, ppwszApplicationName
);
427 n
= This
->applicationName
? lstrlenW(This
->applicationName
) + 1 : 1;
428 *ppwszApplicationName
= CoTaskMemAlloc(n
* sizeof(WCHAR
));
429 if (!*ppwszApplicationName
)
430 return E_OUTOFMEMORY
;
432 if (!This
->applicationName
)
433 *ppwszApplicationName
[0] = 0;
435 lstrcpyW(*ppwszApplicationName
, This
->applicationName
);
440 static HRESULT WINAPI
MSTASK_ITask_SetParameters(
442 LPCWSTR pwszParameters
)
445 TaskImpl
*This
= (TaskImpl
*)iface
;
446 LPWSTR tmp_parameters
;
448 TRACE("(%p, %s)\n", iface
, debugstr_w(pwszParameters
));
450 /* Empty parameter list */
451 if (pwszParameters
[0] == 0)
453 HeapFree(GetProcessHeap(), 0, This
->parameters
);
454 This
->parameters
= NULL
;
458 /* Set to pwszParameters */
459 n
= (lstrlenW(pwszParameters
) + 1);
460 tmp_parameters
= HeapAlloc(GetProcessHeap(), 0, n
* sizeof(WCHAR
));
462 return E_OUTOFMEMORY
;
463 lstrcpyW(tmp_parameters
, pwszParameters
);
464 HeapFree(GetProcessHeap(), 0, This
->parameters
);
465 This
->parameters
= tmp_parameters
;
469 static HRESULT WINAPI
MSTASK_ITask_GetParameters(
471 LPWSTR
*ppwszParameters
)
474 TaskImpl
*This
= (TaskImpl
*)iface
;
476 TRACE("(%p, %p)\n", iface
, ppwszParameters
);
478 n
= This
->parameters
? lstrlenW(This
->parameters
) + 1 : 1;
479 *ppwszParameters
= CoTaskMemAlloc(n
* sizeof(WCHAR
));
480 if (!*ppwszParameters
)
481 return E_OUTOFMEMORY
;
483 if (!This
->parameters
)
484 *ppwszParameters
[0] = 0;
486 lstrcpyW(*ppwszParameters
, This
->parameters
);
491 static HRESULT WINAPI
MSTASK_ITask_SetWorkingDirectory(
493 LPCWSTR pwszWorkingDirectory
)
495 FIXME("(%p, %s): stub\n", iface
, debugstr_w(pwszWorkingDirectory
));
499 static HRESULT WINAPI
MSTASK_ITask_GetWorkingDirectory(
501 LPWSTR
*ppwszWorkingDirectory
)
503 FIXME("(%p, %p): stub\n", iface
, ppwszWorkingDirectory
);
507 static HRESULT WINAPI
MSTASK_ITask_SetPriority(
511 FIXME("(%p, 0x%08x): stub\n", iface
, dwPriority
);
515 static HRESULT WINAPI
MSTASK_ITask_GetPriority(
519 FIXME("(%p, %p): stub\n", iface
, pdwPriority
);
523 static HRESULT WINAPI
MSTASK_ITask_SetTaskFlags(
527 FIXME("(%p, 0x%08x): stub\n", iface
, dwFlags
);
531 static HRESULT WINAPI
MSTASK_ITask_GetTaskFlags(
535 FIXME("(%p, %p): stub\n", iface
, pdwFlags
);
539 static HRESULT WINAPI
MSTASK_ITask_SetMaxRunTime(
543 TaskImpl
*This
= (TaskImpl
*)iface
;
545 TRACE("(%p, %d)\n", iface
, dwMaxRunTime
);
547 This
->maxRunTime
= dwMaxRunTime
;
551 static HRESULT WINAPI
MSTASK_ITask_GetMaxRunTime(
553 DWORD
*pdwMaxRunTime
)
555 TaskImpl
*This
= (TaskImpl
*)iface
;
557 TRACE("(%p, %p)\n", iface
, pdwMaxRunTime
);
559 *pdwMaxRunTime
= This
->maxRunTime
;
563 static HRESULT WINAPI
MSTASK_IPersistFile_QueryInterface(
568 TaskImpl
*This
= impl_from_IPersistFile(iface
);
569 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(riid
), ppvObject
);
570 return ITask_QueryInterface((ITask
*) This
, riid
, ppvObject
);
573 static ULONG WINAPI
MSTASK_IPersistFile_AddRef(
576 TaskImpl
*This
= impl_from_IPersistFile(iface
);
579 ref
= InterlockedIncrement(&This
->ref
);
583 static ULONG WINAPI
MSTASK_IPersistFile_Release(
586 TaskImpl
*This
= impl_from_IPersistFile(iface
);
589 ref
= InterlockedDecrement(&This
->ref
);
591 TaskDestructor(This
);
595 static HRESULT WINAPI
MSTASK_IPersistFile_GetClassID(
599 FIXME("(%p, %p): stub\n", iface
, pClassID
);
603 static HRESULT WINAPI
MSTASK_IPersistFile_IsDirty(
606 FIXME("(%p): stub\n", iface
);
610 static HRESULT WINAPI
MSTASK_IPersistFile_Load(
612 LPCOLESTR pszFileName
,
615 FIXME("(%p, %p, 0x%08x): stub\n", iface
, pszFileName
, dwMode
);
619 static HRESULT WINAPI
MSTASK_IPersistFile_Save(
621 LPCOLESTR pszFileName
,
624 FIXME("(%p, %p, %d): stub\n", iface
, pszFileName
, fRemember
);
628 static HRESULT WINAPI
MSTASK_IPersistFile_SaveCompleted(
630 LPCOLESTR pszFileName
)
632 FIXME("(%p, %p): stub\n", iface
, pszFileName
);
636 static HRESULT WINAPI
MSTASK_IPersistFile_GetCurFile(
638 LPOLESTR
*ppszFileName
)
640 FIXME("(%p, %p): stub\n", iface
, ppszFileName
);
645 static const ITaskVtbl MSTASK_ITaskVtbl
=
647 MSTASK_ITask_QueryInterface
,
649 MSTASK_ITask_Release
,
650 MSTASK_ITask_CreateTrigger
,
651 MSTASK_ITask_DeleteTrigger
,
652 MSTASK_ITask_GetTriggerCount
,
653 MSTASK_ITask_GetTrigger
,
654 MSTASK_ITask_GetTriggerString
,
655 MSTASK_ITask_GetRunTimes
,
656 MSTASK_ITask_GetNextRunTime
,
657 MSTASK_ITask_SetIdleWait
,
658 MSTASK_ITask_GetIdleWait
,
660 MSTASK_ITask_Terminate
,
661 MSTASK_ITask_EditWorkItem
,
662 MSTASK_ITask_GetMostRecentRunTime
,
663 MSTASK_ITask_GetStatus
,
664 MSTASK_ITask_GetExitCode
,
665 MSTASK_ITask_SetComment
,
666 MSTASK_ITask_GetComment
,
667 MSTASK_ITask_SetCreator
,
668 MSTASK_ITask_GetCreator
,
669 MSTASK_ITask_SetWorkItemData
,
670 MSTASK_ITask_GetWorkItemData
,
671 MSTASK_ITask_SetErrorRetryCount
,
672 MSTASK_ITask_GetErrorRetryCount
,
673 MSTASK_ITask_SetErrorRetryInterval
,
674 MSTASK_ITask_GetErrorRetryInterval
,
675 MSTASK_ITask_SetFlags
,
676 MSTASK_ITask_GetFlags
,
677 MSTASK_ITask_SetAccountInformation
,
678 MSTASK_ITask_GetAccountInformation
,
679 MSTASK_ITask_SetApplicationName
,
680 MSTASK_ITask_GetApplicationName
,
681 MSTASK_ITask_SetParameters
,
682 MSTASK_ITask_GetParameters
,
683 MSTASK_ITask_SetWorkingDirectory
,
684 MSTASK_ITask_GetWorkingDirectory
,
685 MSTASK_ITask_SetPriority
,
686 MSTASK_ITask_GetPriority
,
687 MSTASK_ITask_SetTaskFlags
,
688 MSTASK_ITask_GetTaskFlags
,
689 MSTASK_ITask_SetMaxRunTime
,
690 MSTASK_ITask_GetMaxRunTime
693 static const IPersistFileVtbl MSTASK_IPersistFileVtbl
=
695 MSTASK_IPersistFile_QueryInterface
,
696 MSTASK_IPersistFile_AddRef
,
697 MSTASK_IPersistFile_Release
,
698 MSTASK_IPersistFile_GetClassID
,
699 MSTASK_IPersistFile_IsDirty
,
700 MSTASK_IPersistFile_Load
,
701 MSTASK_IPersistFile_Save
,
702 MSTASK_IPersistFile_SaveCompleted
,
703 MSTASK_IPersistFile_GetCurFile
706 HRESULT
TaskConstructor(LPCWSTR pwszTaskName
, LPVOID
*ppObj
)
711 TRACE("(%s, %p)\n", debugstr_w(pwszTaskName
), ppObj
);
713 This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
715 return E_OUTOFMEMORY
;
717 This
->lpVtbl
= &MSTASK_ITaskVtbl
;
718 This
->persistVtbl
= &MSTASK_IPersistFileVtbl
;
720 n
= (lstrlenW(pwszTaskName
) + 1) * sizeof(WCHAR
);
721 This
->taskName
= HeapAlloc(GetProcessHeap(), 0, n
);
724 HeapFree(GetProcessHeap(), 0, This
);
725 return E_OUTOFMEMORY
;
727 lstrcpyW(This
->taskName
, pwszTaskName
);
728 This
->applicationName
= NULL
;
729 This
->parameters
= NULL
;
730 This
->comment
= NULL
;
732 /* Default time is 3 days = 259200000 ms */
733 This
->maxRunTime
= 259200000;
735 *ppObj
= &This
->lpVtbl
;
736 InterlockedIncrement(&dll_ref
);