winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ConfigurationSetApplyProcessor.h (4781B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include "ConfigurationSet.h"
      5 #include "ConfigurationUnit.h"
      6 #include "ApplyGroupSettingsResult.h"
      7 #include "ApplyConfigurationUnitResult.h"
      8 #include "ConfigurationUnitResultInformation.h"
      9 #include "ShutdownSynchronization.h"
     10 
     11 #include <map>
     12 #include <string>
     13 #include <vector>
     14 
     15 namespace winrt::Microsoft::Management::Configuration::implementation
     16 {
     17     // A helper to better organize the configuration set Apply.
     18     struct ConfigurationSetApplyProcessor
     19     {
     20         using ConfigurationSet = Configuration::ConfigurationSet;
     21         using ConfigurationUnit = Configuration::ConfigurationUnit;
     22         using ConfigurationSetChangeData = Configuration::ConfigurationSetChangeData;
     23 
     24         using result_type = decltype(make_self<wil::details::module_count_wrapper<implementation::ApplyGroupSettingsResult>>());
     25         using progress_type = ShutdownAwareAsyncProgress<IApplyGroupSettingsResult, IApplyGroupMemberSettingsResult>;
     26 
     27         ConfigurationSetApplyProcessor(const ConfigurationSet& configurationSet, IConfigurationSetProcessor setProcessor, progress_type&& progress);
     28 
     29         // Processes the apply for the configuration set.
     30         void Process(bool preProcessOnly = false);
     31 
     32         // Gets the result object.
     33         IApplyGroupSettingsResult Result() const;
     34 
     35     private:
     36         // Contains all of the relevant data for a configuration unit.
     37         struct UnitInfo
     38         {
     39             UnitInfo(const ConfigurationUnit& unit);
     40 
     41             ConfigurationUnit Unit;
     42             std::vector<size_t> DependencyIndices;
     43             decltype(make_self<wil::details::module_count_wrapper<implementation::ApplyConfigurationUnitResult>>()) Result;
     44             decltype(make_self<wil::details::module_count_wrapper<implementation::ConfigurationUnitResultInformation>>()) ResultInformation;
     45             bool PreProcessed = false;
     46             bool Processed = false;
     47         };
     48 
     49         // Builds out some data used during processing and validates the set along the way.
     50         bool PreProcess();
     51 
     52         // Adds the given unit to the identifier to unit info index map.
     53         bool AddUnitToMap(UnitInfo& unitInfo, size_t unitInfoIndex);
     54 
     55         // Checks the dependency; returns true to indicate that the dependency is satisfied, false if not.
     56         using CheckDependencyPtr = bool (*)(const UnitInfo&);
     57 
     58         // Processes the unit; returns true if successful, false if not.
     59         using ProcessUnitPtr = bool (ConfigurationSetApplyProcessor::*)(UnitInfo&);
     60 
     61         // Return true to process these intents, false to skip them.
     62         using IntentFilterPtr = bool (*)(ConfigurationUnitIntent);
     63 
     64         // Runs the processing using the given functions.
     65         bool ProcessInternal(CheckDependencyPtr checkDependencyFunction, ProcessUnitPtr processUnitFunction, bool sendProgress = false);
     66 
     67         // Processes one of the non-writing intent types, which are fatal if not all successful
     68         bool ProcessIntentInternal(
     69             std::vector<size_t>& unitsToProcess,
     70             CheckDependencyPtr checkDependencyFunction,
     71             ProcessUnitPtr processUnitFunction,
     72             IntentFilterPtr intentFilter,
     73             hresult errorForOtherIntents,
     74             hresult errorForFailures,
     75             bool sendProgress);
     76 
     77         // Determines if the given unit has the given intent and all of its dependencies are satisfied
     78         bool HasIntentAndSatisfiedDependencies(
     79             const UnitInfo& unitInfo,
     80             IntentFilterPtr intentFilter,
     81             CheckDependencyPtr checkDependencyFunction) const;
     82 
     83         // Checks a dependency for preprocessing.
     84         static bool HasPreprocessed(const UnitInfo& unitInfo);
     85 
     86         // Marks a unit as preprocessed.
     87         bool MarkPreprocessed(UnitInfo& unitInfo);
     88 
     89         // Checks a dependency for having processed successfully.
     90         static bool HasProcessedSuccessfully(const UnitInfo& unitInfo);
     91 
     92         // Processes a configuration unit per its intent.
     93         bool ProcessUnit(UnitInfo& unitInfo);
     94 
     95         // Sends progress
     96         // TODO: Eventually these functions/call sites will be used for history
     97         void SendProgress(ConfigurationUnitState state, const UnitInfo& unitInfo);
     98         void SendProgressIfNotComplete(ConfigurationUnitState state, const UnitInfo& unitInfo);
     99 
    100         ConfigurationSet m_configurationSet;
    101         IConfigurationSetProcessor m_setProcessor;
    102         result_type m_result;
    103         progress_type m_progress;
    104         std::vector<UnitInfo> m_unitInfo;
    105         std::map<std::string, size_t> m_idToUnitInfoIndex;
    106         hresult m_resultCode;
    107     };
    108 }