2008-07-18 01:56:14 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Google (Roy Shea)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2008-08-19 02:23:42 +02:00
|
|
|
#include "corerror.h"
|
2008-07-18 01:56:14 +02:00
|
|
|
#include "mstask_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mstask);
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ITaskScheduler ITaskScheduler_iface;
|
|
|
|
LONG ref;
|
|
|
|
} TaskSchedulerImpl;
|
|
|
|
|
|
|
|
static inline TaskSchedulerImpl *impl_from_ITaskScheduler(ITaskScheduler *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TaskSchedulerImpl, ITaskScheduler_iface);
|
|
|
|
}
|
|
|
|
|
2008-07-18 01:56:14 +02:00
|
|
|
static void TaskSchedulerDestructor(TaskSchedulerImpl *This)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2008-07-23 01:54:07 +02:00
|
|
|
InterlockedDecrement(&dll_ref);
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_QueryInterface(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
REFIID riid,
|
|
|
|
void **ppvObject)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
|
|
|
|
TRACE("IID: %s\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ITaskScheduler))
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
*ppvObject = &This->ITaskScheduler_iface;
|
2008-07-18 01:56:14 +02:00
|
|
|
ITaskScheduler_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITaskScheduler_AddRef(
|
|
|
|
ITaskScheduler* iface)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
TRACE("\n");
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MSTASK_ITaskScheduler_Release(
|
|
|
|
ITaskScheduler* iface)
|
|
|
|
{
|
2011-01-24 00:14:53 +01:00
|
|
|
TaskSchedulerImpl * This = impl_from_ITaskScheduler(iface);
|
2008-07-18 01:56:14 +02:00
|
|
|
ULONG ref;
|
|
|
|
TRACE("\n");
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
TaskSchedulerDestructor(This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_SetTargetComputer(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszComputer)
|
|
|
|
{
|
2012-11-08 00:12:47 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
|
|
|
WCHAR buffer[MAX_COMPUTERNAME_LENGTH + 3]; /* extra space for two '\' and a zero */
|
|
|
|
DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for a zero */
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(pwszComputer));
|
|
|
|
|
|
|
|
/* NULL is an alias for the local computer */
|
|
|
|
if (!pwszComputer)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
buffer[0] = '\\';
|
|
|
|
buffer[1] = '\\';
|
|
|
|
if (GetComputerNameW(buffer + 2, &len))
|
|
|
|
{
|
|
|
|
if (!lstrcmpiW(buffer, pwszComputer) || /* full unc name */
|
|
|
|
!lstrcmpiW(buffer + 2, pwszComputer)) /* name without backslash */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("remote computer %s not supported\n", debugstr_w(pwszComputer));
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_BAD_NETPATH);
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_GetTargetComputer(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPWSTR *ppwszComputer)
|
|
|
|
{
|
2012-11-06 00:20:12 +01:00
|
|
|
TaskSchedulerImpl *This = impl_from_ITaskScheduler(iface);
|
|
|
|
LPWSTR buffer;
|
|
|
|
DWORD len = MAX_COMPUTERNAME_LENGTH + 1; /* extra space for the zero */
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, ppwszComputer);
|
|
|
|
|
|
|
|
if (!ppwszComputer)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* extra space for two '\' and a zero */
|
|
|
|
buffer = CoTaskMemAlloc((MAX_COMPUTERNAME_LENGTH + 3) * sizeof(WCHAR));
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
buffer[0] = '\\';
|
|
|
|
buffer[1] = '\\';
|
|
|
|
if (GetComputerNameW(buffer + 2, &len))
|
|
|
|
{
|
|
|
|
*ppwszComputer = buffer;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
CoTaskMemFree(buffer);
|
|
|
|
}
|
|
|
|
*ppwszComputer = NULL;
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Enum(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
IEnumWorkItems **ppEnumTasks)
|
|
|
|
{
|
|
|
|
FIXME("%p, %p: stub\n", iface, ppEnumTasks);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Activate(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszName,
|
|
|
|
REFIID riid,
|
|
|
|
IUnknown **ppunk)
|
|
|
|
{
|
2008-08-19 02:23:42 +02:00
|
|
|
TRACE("%p, %s, %s, %p: stub\n", iface, debugstr_w(pwszName),
|
2008-07-18 01:56:14 +02:00
|
|
|
debugstr_guid(riid), ppunk);
|
2008-08-19 02:23:42 +02:00
|
|
|
FIXME("Partial stub always returning COR_E_FILENOTFOUND\n");
|
|
|
|
return COR_E_FILENOTFOUND;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_Delete(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszName)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s: stub\n", iface, debugstr_w(pwszName));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_NewWorkItem(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszTaskName,
|
|
|
|
REFCLSID rclsid,
|
|
|
|
REFIID riid,
|
|
|
|
IUnknown **ppunk)
|
|
|
|
{
|
2008-08-04 20:46:14 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p, %s, %s, %s, %p)\n", iface, debugstr_w(pwszTaskName),
|
2008-07-18 01:56:14 +02:00
|
|
|
debugstr_guid(rclsid) ,debugstr_guid(riid), ppunk);
|
2008-08-04 20:46:14 +02:00
|
|
|
|
|
|
|
if (!IsEqualGUID(rclsid, &CLSID_CTask))
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
|
|
|
if (!IsEqualGUID(riid, &IID_ITask))
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
hr = TaskConstructor(pwszTaskName, (LPVOID *)ppunk);
|
|
|
|
return hr;
|
2008-07-18 01:56:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_AddWorkItem(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszTaskName,
|
|
|
|
IScheduledWorkItem *pWorkItem)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %p: stub\n", iface, debugstr_w(pwszTaskName), pWorkItem);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MSTASK_ITaskScheduler_IsOfType(
|
|
|
|
ITaskScheduler* iface,
|
|
|
|
LPCWSTR pwszName,
|
|
|
|
REFIID riid)
|
|
|
|
{
|
|
|
|
FIXME("%p, %s, %s: stub\n", iface, debugstr_w(pwszName),
|
|
|
|
debugstr_guid(riid));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ITaskSchedulerVtbl MSTASK_ITaskSchedulerVtbl =
|
|
|
|
{
|
|
|
|
MSTASK_ITaskScheduler_QueryInterface,
|
|
|
|
MSTASK_ITaskScheduler_AddRef,
|
|
|
|
MSTASK_ITaskScheduler_Release,
|
|
|
|
MSTASK_ITaskScheduler_SetTargetComputer,
|
|
|
|
MSTASK_ITaskScheduler_GetTargetComputer,
|
|
|
|
MSTASK_ITaskScheduler_Enum,
|
|
|
|
MSTASK_ITaskScheduler_Activate,
|
|
|
|
MSTASK_ITaskScheduler_Delete,
|
|
|
|
MSTASK_ITaskScheduler_NewWorkItem,
|
|
|
|
MSTASK_ITaskScheduler_AddWorkItem,
|
|
|
|
MSTASK_ITaskScheduler_IsOfType
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT TaskSchedulerConstructor(LPVOID *ppObj)
|
|
|
|
{
|
|
|
|
TaskSchedulerImpl *This;
|
|
|
|
TRACE("(%p)\n", ppObj);
|
|
|
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
This->ITaskScheduler_iface.lpVtbl = &MSTASK_ITaskSchedulerVtbl;
|
2008-07-18 01:56:14 +02:00
|
|
|
This->ref = 1;
|
|
|
|
|
2011-01-24 00:14:53 +01:00
|
|
|
*ppObj = &This->ITaskScheduler_iface;
|
2008-07-23 01:54:07 +02:00
|
|
|
InterlockedIncrement(&dll_ref);
|
2008-07-18 01:56:14 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|