winget-cli

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

IConfigurationDatabase.h (6199B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include "winrt/Microsoft.Management.Configuration.h"
      5 #include "ConfigurationSet.h"
      6 #include "ConfigurationUnit.h"
      7 #include "ConfigurationSetChangeData.h"
      8 #include <winget/SQLiteVersion.h>
      9 #include <winget/SQLiteDynamicStorage.h>
     10 #include <wil/cppwinrt_wrl.h>
     11 #include <memory>
     12 #include <tuple>
     13 
     14 namespace winrt::Microsoft::Management::Configuration::implementation
     15 {
     16     // Interface for interacting with the configuration database.
     17     struct IConfigurationDatabase
     18     {
     19         using ConfigurationSetPtr = winrt::com_ptr<implementation::ConfigurationSet>;
     20         using ConfigurationUnitPtr = winrt::com_ptr<implementation::ConfigurationUnit>;
     21         using ConfigurationSetChangeDataPtr = winrt::com_ptr<implementation::ConfigurationSetChangeData>;
     22 
     23         virtual ~IConfigurationDatabase() = default;
     24 
     25         // Gets the latest schema version for the configuration database.
     26         static AppInstaller::SQLite::Version GetLatestVersion();
     27 
     28         // Creates the version appropriate database object for the given storage.
     29         static std::unique_ptr<IConfigurationDatabase> CreateFor(const std::shared_ptr<AppInstaller::SQLite::SQLiteDynamicStorage>& storage, bool allowMigration = false);
     30 
     31         // Gets the schema version from the current interface.
     32         virtual const AppInstaller::SQLite::Version& GetSchemaVersion() = 0;
     33 
     34         // Version 0.1
     35 
     36         // Acts on a database that has been created but contains no tables beyond metadata.
     37         virtual void InitializeDatabase() = 0;
     38 
     39         // Adds the given set to the database.
     40         virtual void AddSet(const Configuration::ConfigurationSet& configurationSet) = 0;
     41 
     42         // Updates the set with the given row id using the given set.
     43         virtual void UpdateSet(AppInstaller::SQLite::rowid_t target, const Configuration::ConfigurationSet& configurationSet) = 0;
     44 
     45         // Removes the set with the given row id from the database.
     46         virtual void RemoveSet(AppInstaller::SQLite::rowid_t target) = 0;
     47 
     48         // Gets all of the sets in the database.
     49         virtual std::vector<ConfigurationSetPtr> GetSets() = 0;
     50 
     51         // Gets the row id of the set with the given instance identifier, if present.
     52         virtual std::optional<AppInstaller::SQLite::rowid_t> GetSetRowId(const GUID& instanceIdentifier) = 0;
     53 
     54         // Version 0.2
     55 
     56         // Migrates from the current interface given.
     57         // Returns true if supported (or is already same schema version); false if not.
     58         // Throws on errors that occur during an attempted migration.
     59         virtual bool MigrateFrom(IConfigurationDatabase* current) = 0;
     60 
     61         // Adds a new queue item for the given configuration set and object name.
     62         virtual void AddQueueItem(const GUID& instanceIdentifier, const std::string& objectName);
     63 
     64         // Sets the queue item with the given object name as active.
     65         virtual void SetActiveQueueItem(const std::string& objectName);
     66 
     67         // Gets all queue items in queue order (item at index 0 is active/next).
     68         virtual std::vector<std::tuple<GUID, std::string, std::chrono::system_clock::time_point, DWORD, bool>> GetQueueItems();
     69 
     70         // Removes the queue item with the given object name.
     71         virtual void RemoveQueueItem(const std::string& objectName);
     72 
     73         // Version 0.3
     74 
     75         // Gets a set from the database.
     76         virtual ConfigurationSetPtr GetSet(const GUID& instanceIdentifier) = 0;
     77 
     78         // The tuple returned for status items.
     79         using StatusItemTuple = std::tuple<
     80             int64_t,
     81             std::chrono::system_clock::time_point,
     82             GUID,
     83             bool,
     84             std::optional<GUID>,
     85             int32_t,
     86             std::optional<HRESULT>,
     87             std::string,
     88             std::string,
     89             ConfigurationUnitResultSource>;
     90 
     91         // Gets all status items that have changed since the given change identifier, in order of changes (last item is the new latest change to pass next).
     92         virtual std::vector<StatusItemTuple> GetStatusSince(int64_t changeIdentifier);
     93 
     94         // Gets the latest change identifier and the set status items.
     95         virtual std::tuple<int64_t, std::vector<StatusItemTuple>> GetStatusBaseline();
     96 
     97         // Adds a new listener to the database.
     98         virtual void AddListener(const std::string& objectName);
     99 
    100         // Removes a listener from the database.
    101         virtual void RemoveListener(const std::string& objectName);
    102 
    103         // Gets all of the change listeners in the database.
    104         virtual std::vector<std::tuple<std::string, std::chrono::system_clock::time_point, DWORD>> GetChangeListeners();
    105 
    106         // Updates a set's state.
    107         virtual void UpdateSetState(const guid& setInstanceIdentifier, ConfigurationSetState state);
    108 
    109         // Updates whether a set is in the queue or not.
    110         virtual void UpdateSetInQueue(const guid& setInstanceIdentifier, bool inQueue);
    111 
    112         // Updates a unit's state.
    113         virtual void UpdateUnitState(const guid& setInstanceIdentifier, const ConfigurationSetChangeDataPtr& changeData);
    114 
    115         // Gets a set's state.
    116         virtual ConfigurationSetState GetSetState(const guid& instanceIdentifier);
    117 
    118         // Gets a set's first apply time.
    119         virtual std::chrono::system_clock::time_point GetSetFirstApply(const guid& instanceIdentifier);
    120 
    121         // Gets a set's latest apply begin time.
    122         virtual std::chrono::system_clock::time_point GetSetApplyBegun(const guid& instanceIdentifier);
    123 
    124         // Gets a set's latest apply end time.
    125         virtual std::chrono::system_clock::time_point GetSetApplyEnded(const guid& instanceIdentifier);
    126 
    127         // Gets a unit's state.
    128         virtual ConfigurationUnitState GetUnitState(const guid& instanceIdentifier);
    129 
    130         // Gets a unit's latest result information.
    131         virtual std::optional<std::tuple<HRESULT, std::string, std::string, ConfigurationUnitResultSource>> GetUnitResultInformation(const guid& instanceIdentifier);
    132     };
    133 }