/*
 * Task Scheduler Service definitions
 *
 * Copyright 2014 Dmitry Timoshkov
 *
 * 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
 */

cpp_quote("#define SCHEDSVC_TRANSPORT {'n','c','a','l','r','p','c',0}")
cpp_quote("#define SCH_FLAG_STATE 0x10000000")

import "oaidl.idl";
import "ocidl.idl";

[
    uuid(86d35949-83c9-4044-b424-db363231fd0c),
    implicit_handle(handle_t rpc_handle),
    version(1.0),
    pointer_default(unique)
]
interface ITaskSchedulerService
{
    typedef struct _TASK_USER_CRED
    {
        [string] const WCHAR *user;
        [string] const WCHAR *password;
        DWORD flags;
    } TASK_USER_CRED;

    typedef struct _TASK_XML_ERROR_INFO
    {
        DWORD line, column;
        [string] WCHAR *node;
        [string] WCHAR *value;
    } TASK_XML_ERROR_INFO;

    typedef [string] WCHAR **TASK_NAMES;

    HRESULT SchRpcHighestVersion([out] DWORD *version);
    HRESULT SchRpcRegisterTask([in, string, unique] const WCHAR *path,
                [in, string] const WCHAR *xml, [in] DWORD flags,
                [in, string, unique] const WCHAR *sddl,
                [in] DWORD task_logon_type, [in] DWORD n_creds,
                [in, size_is(n_creds), unique] const TASK_USER_CRED *creds,
                [out, string] WCHAR **actual_path,
                [out] TASK_XML_ERROR_INFO **xml_error_info);
    HRESULT SchRpcRetrieveTask([in, string] const WCHAR *path,
                [in, string] const WCHAR *languages,
                [in] unsigned long *n_languages, [out, string] WCHAR **xml);
    HRESULT SchRpcCreateFolder([in, string] const WCHAR *path,
                [in, string, unique] const WCHAR *sddl, [in] DWORD flags);
    HRESULT SchRpcSetSecurity([in, string] const WCHAR *path,
                [in, string] const WCHAR *sddl, [in] DWORD flags);
    HRESULT SchRpcGetSecurity([in, string] const WCHAR *path,
                [in] DWORD flags, [out, string] WCHAR **sddl);
    HRESULT SchRpcEnumFolders([in, string] const WCHAR *path,
                [in] DWORD flags, [in, out] DWORD *start_index,
                [in] DWORD n_requested, [out] DWORD *n_names,
                [out, string, size_is(,*n_names)] TASK_NAMES *names);
    HRESULT SchRpcEnumTasks([in, string] const WCHAR *path,
                [in] DWORD flags, [in, out] DWORD *start_index,
                [in] DWORD n_requested, [out] DWORD *n_names,
                [out, string, size_is(,*n_names)] TASK_NAMES *names);
    HRESULT SchRpcEnumInstances([in, string, unique] const WCHAR *path,
                [in] DWORD flags, [out] DWORD *n_guids,
                [out, size_is(,*n_guids)] GUID **guids);
    HRESULT SchRpcGetInstanceInfo([in] GUID guid, [out, string] WCHAR **path,
                [out] DWORD *task_state, [out, string] WCHAR **action,
                [out, string] WCHAR **info, [out] DWORD *n_instances,
                [out, size_is(,*n_instances)] GUID **instances, [out] DWORD *pid);
    HRESULT SchRpcStopInstance([in] GUID guid, [in] DWORD flags);
    HRESULT SchRpcStop([in, string, unique] const WCHAR *path, [in] DWORD flags);
    HRESULT SchRpcRun([in, string] const WCHAR *path,
                [in] DWORD n_args, [in, size_is(n_args),unique] const WCHAR **args,
                [in] DWORD flags, [in] DWORD session_id,
                [in, unique, string] const WCHAR *user, [out] GUID *guid);
    HRESULT SchRpcDelete([in, string] const WCHAR *path, [in] DWORD flags);
    HRESULT SchRpcRename([in, string] const WCHAR *path, [in, string] const WCHAR *name, [in] DWORD flags);
    HRESULT SchRpcScheduledRuntimes([in, string] const WCHAR *path,
                [in, unique] SYSTEMTIME *start, [in, unique] SYSTEMTIME *end,
                [in] DWORD flags, [in] DWORD n_requested, [out] DWORD *n_runtimes,
                [out, size_is(,*n_runtimes)] SYSTEMTIME **runtimes);
    HRESULT SchRpcGetLastRunInfo([in, string] const WCHAR *path,
                [out] SYSTEMTIME *last_runtime, [out] DWORD *last_return_code);
    HRESULT SchRpcGetTaskInfo([in, string] const WCHAR *path, [in] DWORD flags,
                [out] DWORD *enabled, [out] DWORD *task_state);
    HRESULT SchRpcGetNumberOfMissedRuns([in, string] const WCHAR *path, [out] DWORD *runs);
    HRESULT SchRpcEnableTask([in, string] const WCHAR *path, [in] DWORD enabled);
}