SourceFactory.h (1964B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "ISource.h" 5 #include <AppInstallerProgress.h> 6 7 #include <memory> 8 9 10 namespace AppInstaller::Repository 11 { 12 // Interface for manipulating a source based on its details. 13 struct ISourceFactory 14 { 15 virtual ~ISourceFactory() = default; 16 17 // Gets the name of the source type. 18 virtual std::string_view TypeName() const = 0; 19 20 // Creates a source object from the given details. 21 virtual std::shared_ptr<ISourceReference> Create(const SourceDetails& details) = 0; 22 23 // Adds the source from the given details, writing back to the details any changes. 24 // Return value indicates whether the action completed. 25 virtual bool Add(SourceDetails& details, IProgressCallback& progress) = 0; 26 27 // Updates the source from the given details (may not change the details). 28 // Return value indicates whether the action completed. 29 virtual bool Update(const SourceDetails& details, IProgressCallback& progress) = 0; 30 31 // Updates the source from the given details (may not change the details). 32 // This version is for use in automatic, background updates to the source. 33 // It is done this way to preserve the signature for use with member function pointers. 34 // Return value indicates whether the action completed. 35 virtual bool BackgroundUpdate(const SourceDetails& details, IProgressCallback& progress) 36 { 37 return Update(details, progress); 38 } 39 40 // Removes the source from the given details. 41 // Return value indicates whether the action completed. 42 virtual bool Remove(const SourceDetails& details, IProgressCallback& progress) = 0; 43 44 // Gets the factory for the given type. 45 static std::unique_ptr<ISourceFactory> GetForType(std::string_view type); 46 }; 47 }