////////////////////////////////////////////////////////////////////////////////////////
// File: AxeRuntime.h
//
// Abstract: This file contains definitions that are consumed by AXE Runtime (assessments).
//
// (c) Microsoft. All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////


#if defined( _MSC_VER )
#pragma once
#endif  // _MSC_VER

#if !defined( AXERUNTIME_H )
#define AXERUNTIME_H

#if NTDDI_VERSION >= NTDDI_WIN7

// This file is only for C++ clients. C is not supported.
//
#if !defined( __cplusplus )
#error C++ compiler required
#endif  // C++


////////////////////////////////////////////////////////////////////////////////////////
// Include files
////////////////////////////////////////////////////////////////////////////////////////

#include "AxeCore.h"


// The AXE Assessment APIs exist in the Microsoft::Assessments::Runtime namespace.
//
namespace Microsoft { namespace Assessments { namespace Runtime
{
    ////////////////////////////////////////////////////////////////////////////////////////
    // Constants
    ////////////////////////////////////////////////////////////////////////////////////////

    namespace EnvironmentVariable
    {
        static LPCWSTR const ResultsPath        = L"AssessmentResultsPath";
        static LPCWSTR const TempPath           = L"AssessmentTempPath";
        static LPCWSTR const JobFile            = L"AssessmentJobFile";
        static LPCWSTR const AxeBinaryPath      = L"AssessmentAxeBinPath";
        static LPCWSTR const UniqueSession      = L"AssessmentUniqueSession";
        static LPCWSTR const RebootIteration    = L"AssessmentRebootIteration";
        static LPCWSTR const RunIndex           = L"AssessmentRunIndex";
    }

    namespace SessionParameter
    {
        static LPCWSTR const ResultsPath        = L"ResultsPath";
        static LPCWSTR const TempPath           = L"TempPath";
        static LPCWSTR const JobFile            = L"JobFile";
        static LPCWSTR const AxeBinaryPath      = L"AxeBinPath";
        static LPCWSTR const UniqueSession      = L"UniqueSession";
        static LPCWSTR const RebootIteration    = L"RebootIteration";
        static LPCWSTR const RunIndex           = L"RunIndex";
    }


    ////////////////////////////////////////////////////////////////////////////////////////
    // Forward declarations
    ////////////////////////////////////////////////////////////////////////////////////////

    __interface Support;
    __interface SystemState;
    __interface ParameterSet;
    __interface Parameter;


    ////////////////////////////////////////////////////////////////////////////////////////
    // Enumerations
    ////////////////////////////////////////////////////////////////////////////////////////

    enum AssessmentError
    {
        AssessmentErrorNone                             = 0,
        AssessmentErrorAlreadyInit                      = AXE_E_ALREADY_INIT,
        AssessmentErrorInternalError                    = AXE_E_INTERNAL_ERROR,
        AssessmentErrorUnknownWin32Error                = AXE_E_UNKNOWN_WIN32_ERROR,
        AssessmentErrorParameterConversionFailed        = AXE_E_PARAM_CONVERSION_FAILED,
        AssessmentErrorEngineNotRunning                 = AXE_E_ENGINE_NOT_RUNNING,
        AssessmentErrorParameterNotFound                = AXE_E_PARAMETER_NOT_FOUND
    };

    enum ParameterNamespace
    {
        ParameterNamespaceNone = 0,  // always first
        ParameterNamespaceAssessment,
        ParameterNamespaceJob,
        ParameterNamespaceSession,
        ParameterNamespaceInvalid  // always last
    };

    enum SystemSetting
    {
        SystemSettingNone                       = 0,
        SystemSettingFlagGetBool                = /*0x00010000*/ 0x1 << 16,
        SystemSettingFlagSetBoolFalse           = /*0x01000000*/ 0x1 << 24,
        SystemSettingFlagSetBoolTrue            = /*0x02000000*/ 0x1 << 25,

        SystemSettingBatteryPresent             = /*0x00010001*/ 0x1 | SystemSettingFlagGetBool,
        SystemSettingOnACPower                  = /*0x00010002*/ 0x2 | SystemSettingFlagGetBool,
        SystemSettingElevated                   = /*0x00010003*/ 0x3 | SystemSettingFlagGetBool,
        SystemSettingPioModeOnSystemDrive       = /*0x00010004*/ 0x4 | SystemSettingFlagGetBool,
        SystemSettingUsingBasicDisplay          = /*0x00010005*/ 0x5 | SystemSettingFlagGetBool,
        SystemSettingIEPresent                  = /*0x00010006*/ 0x6 | SystemSettingFlagGetBool,
        SystemSettingAutoLogOnEnabled           = /*0x00010007*/ 0x7 | SystemSettingFlagGetBool,
        SystemSettingAntivirusActive            = /*0x00010008*/ 0x8 | SystemSettingFlagGetBool,
        SystemSettingKernelDebuggerEnabled      = /*0x00010009*/ 0x9 | SystemSettingFlagGetBool,
        SystemSettingDriverVerifierEnabled      = /*0x0001000A*/ 0xA | SystemSettingFlagGetBool,
        SystemSettingProblemDevicesExist        = /*0x0001000B*/ 0xB | SystemSettingFlagGetBool,
        SystemSettingPowerProfileMinSavings     = /*0x0201000C*/ 0xC | SystemSettingFlagGetBool | SystemSettingFlagSetBoolTrue,
        SystemSettingPowerProfileBalanced       = /*0x0201000D*/ 0xD | SystemSettingFlagGetBool | SystemSettingFlagSetBoolTrue,
        SystemSettingPowerProfileMaxSavings     = /*0x0201000E*/ 0xE | SystemSettingFlagGetBool | SystemSettingFlagSetBoolTrue,
        SystemSettingLowBatteryAction           = /*0x0301000F*/ 0xF | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingScreensaver                = /*0x01010010*/ 0x10 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse,
        SystemSettingCriticalBatteryAction      = /*0x03010011*/ 0x11 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAutoSleepAC                = /*0x03010012*/ 0x12 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAutoSleepDC                = /*0x03010013*/ 0x13 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAutoHibernateAC            = /*0x03010014*/ 0x14 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAutoHibernateDC            = /*0x03010015*/ 0x15 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingDisplayTimeoutAC           = /*0x03010016*/ 0x16 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingDisplayTimeoutDC           = /*0x03010017*/ 0x17 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingDisplayDimAC               = /*0x03010018*/ 0x18 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingDisplayDimDC               = /*0x03010019*/ 0x19 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingVolumeShadowCopy           = /*0x0301001A*/ 0x1A | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingWindowsAutoUpdate          = /*0x0101001B*/ 0x1B | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse,
        SystemSettingWirelessAdaptersConnected  = /*0x0101001C*/ 0x1C | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse,
        SystemSettingLockOnWakeAC               = /*0x0301001D*/ 0x1D | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingLockOnWakeDC               = /*0x0301001E*/ 0x1E | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingWakeOnTimerAC              = /*0x0301001F*/ 0x1F | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingWakeOnTimerDC              = /*0x03010020*/ 0x20 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingHibernateOn                = /*0x00010021*/ 0x21 | SystemSettingFlagGetBool,
        SystemSettingSuspendOn                  = /*0x00010022*/ 0x22 | SystemSettingFlagGetBool,
        SystemSettingFastStartupOn              = /*0x00010023*/ 0x23 | SystemSettingFlagGetBool,
        SystemSettingShowExtensions             = /*0x03010024*/ 0x24 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingShowAllObjects             = /*0x03010025*/ 0x25 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingScreenBackground           = /*0x01010026*/ 0x26 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse,
        SystemSettingIEFirstRun                 = /*0x01000027*/ 0x27 | SystemSettingFlagSetBoolFalse,
        SystemSettingScreensaverSecure          = /*0x03010028*/ 0x28 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingTracingRunning             = /*0x00010029*/ 0x29 | SystemSettingFlagGetBool,
        SystemSettingAudioRenderDevicePresent   = /*0x0001002A*/ 0x2A | SystemSettingFlagGetBool,
        SystemSettingDisplayBootMenu            = /*0x0001002B*/ 0x2B | SystemSettingFlagGetBool,
        SystemSettingConnectedStandbyOn         = /*0x0001002C*/ 0x2C | SystemSettingFlagGetBool,
        SystemSettingAllowDisplayRequiredAC     = /*0x0301002D*/ 0x2D | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAllowDisplayRequiredDC     = /*0x0301002E*/ 0x2E | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAllowExecutionRequiredAC   = /*0x0301002F*/ 0x2F | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingAllowExecutionRequiredDC   = /*0x03010030*/ 0x30 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
        SystemSettingLockScreen                 = /*0x03010032*/ 0x32 | SystemSettingFlagGetBool | SystemSettingFlagSetBoolFalse | SystemSettingFlagSetBoolTrue,
    };



    ////////////////////////////////////////////////////////////////////////////////////////
    // Interfaces
    ////////////////////////////////////////////////////////////////////////////////////////

    // Support interface
    //
    __interface Support : public IUnknown
    {
        HRESULT GetErrorText(
            _In_ HRESULT axeError,
            _Deref_out_ ErrorList** errorList);
        HRESULT GetParameterSet(
            _In_ ParameterNamespace space,
            _Deref_out_ ParameterSet** params);
        HRESULT ReportProgress(
            _In_ AxeProgressType progressType,
            _In_ UINT progressValue,
            _In_opt_z_ LPCWSTR progressMessage) const;
        HRESULT ReportProgress(
            _In_ AxeProgressType progressType,
            _In_ UINT progressValue,
            _In_opt_z_ LPCWSTR progressMessage,
            _Out_opt_ BOOL* cancelAssessment) const;
        HRESULT GetCancelEvent(
            _Out_ HANDLE* cancelEventHandle) const;
        HRESULT IsCanceled(
            _Out_ BOOL* cancelAssessment) const;
        HRESULT IsEngineRunning(
            _Out_ BOOL* engineRunning) const;
        HRESULT CreateLogger(
            _Deref_out_ Logging** log);
        HRESULT ProcessIdleTasks(
            _Out_ HANDLE* idleTasksHandle) const;
        HRESULT SystemSettingCheckBoolean(
            _In_ SystemSetting setting,
            _Out_ BOOL* enabled);
        HRESULT ManageSystemState(
            _In_z_ LPCWSTR fileName,
            _Deref_out_ SystemState** state);
        HRESULT StartTracing(
            _In_z_ LPCWSTR profileFileName,
            _In_z_ LPCWSTR profileName);
        HRESULT StopTracing(
            _In_z_ LPCWSTR profileFileName,
            _In_z_ LPCWSTR propertyName,
            _In_z_ LPCWSTR outputFileName);
        HRESULT RegisterEventManifest();
        HRESULT RegisterEventManifest(
            _In_z_ LPCWSTR manifestFileName,
            _In_z_ LPCWSTR moduleFileName);
        HRESULT UnregisterEventManifest();
        HRESULT UnregisterEventManifest(
            _In_z_ LPCWSTR manifestFileName);
    };

    __interface SystemState : public IUnknown
    {
        HRESULT RestoreAll();
        HRESULT CheckBoolean(
            _In_ SystemSetting setting,
            _Out_ BOOL* enabled);
        HRESULT SetBoolean(
            _In_ SystemSetting setting,
            _In_ BOOL enable);
    };

    // ParameterSet interface
    //
    __interface ParameterSet
    {
        HRESULT GetParameter(
            _In_z_ LPCWSTR parameterName,
            _Outptr_result_maybenull_ Parameter** parameter) const;
    };

    // Parameter interface
    //
    __interface Parameter
    {
        HRESULT ToString(
            _Deref_out_z_ LPCWSTR* paramValue) const;
        HRESULT ToInt16(
            _Out_ SHORT* paramValue) const;
        HRESULT ToInt32(
            _Out_ LONG* paramValue) const;
        HRESULT ToInt64(
            _Out_ LONGLONG* paramValue) const;
        HRESULT ToUInt16(
            _Out_ USHORT* paramValue) const;
        HRESULT ToUInt32(
            _Out_ ULONG* paramValue) const;
        HRESULT ToUInt64(
            _Out_ ULONGLONG* paramValue) const;
        HRESULT ToBoolean(
            _Out_ BOOL* paramValue) const;
        HRESULT ToByte(
            _Out_ BYTE* paramValue) const;
        HRESULT ToSByte(
            _Out_ CHAR* paramValue) const;
        HRESULT ToChar(
            _Out_ WCHAR* paramValue) const;
        HRESULT ToDouble(
            _Out_ DOUBLE* paramValue) const;
        HRESULT ToDateTime(
            _Out_ SYSTEMTIME* paramValue) const;
        HRESULT ToDuration(
            _Out_ LONGLONG* paramValue) const;
    };

} } }  // end namespace Microsoft::Assessments::Runtime


////////////////////////////////////////////////////////////////////////////////////////
// Factory function
////////////////////////////////////////////////////////////////////////////////////////

extern "C" 
{
    HRESULT WINAPI AxeInitAssessment(
        _Inout_opt_ LPVOID pReserved,
        _Deref_out_ Microsoft::Assessments::Runtime::Support** ppSupport);
    typedef HRESULT ( WINAPI * PFNAXE_INITASSESSMENT)(
        _Inout_opt_ LPVOID pReserved,
        _Deref_out_ Microsoft::Assessments::Runtime::Support** ppSupport);
    #define AXE_INITASSESSMENT "AxeInitAssessment"
}

#endif  // NTDDI_VERSION >= NTDDI_WIN7

#endif  // AXERUNTIME_H
