libzypp: zypp/ng/workflows/mediafacade.h Source File

libzypp 17.36.6

mediafacade.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_NG_MEDIASETFACADE_INCLUDED
10#define ZYPP_NG_MEDIASETFACADE_INCLUDED
11
12#include <zypp-core/base/PtrTypes.h>
13#include <zypp-media/ng/Provide>
14#include <zypp-media/ng/LazyMediaHandle>
15#include <zypp/MediaSetAccess.h>
16#include <zypp/media/MediaManager.h>
17
18
19#include <vector>
20
21namespace zyppng {
22 ZYPP_FWD_DECL_TYPE_WITH_REFS ( MediaSyncFacade );
23 DEFINE_PTR_TYPE(AttachedSyncMediaInfo);
24
25
26 class SyncMediaHandle {
27 public:
28
29 using ParentType = MediaSyncFacade;
30
31 SyncMediaHandle();
32 SyncMediaHandle( AttachedSyncMediaInfo_Ptr dataPtr );
33 MediaSyncFacadeRef parent() const;
34 bool isValid () const;
35 const zypp::Url &baseUrl() const;
36 const std::optional<zypp::Pathname> &localPath() const;
37 const AttachedSyncMediaInfo &info ()const;
38
39 private:
40 AttachedSyncMediaInfo_Ptr _data;
41 };
42
48 class ZYPP_API MediaSyncFacade : public Base
49 {
50 ZYPP_ADD_CREATE_FUNC(MediaSyncFacade)
51 public:
52
53 friend class AttachedSyncMediaInfo;
54
55 using MediaHandle = SyncMediaHandle;
56 using LazyMediaHandle = ::zyppng::LazyMediaHandle<MediaSyncFacade>;
57
58 class Res {
59 public:
60
61 Res( MediaHandle hdl, zypp::ManagedFile file );
62
66 const zypp::Pathname file () const;
67
73 const zypp::ManagedFile & asManagedFile () const {
74 return _res;
75 }
76
77 private:
78 zypp::ManagedFile _res;
79 MediaHandle _provideHandle;
80 };
81
82 ZYPP_DECL_PRIVATE_CONSTR ( MediaSyncFacade );
83 ~MediaSyncFacade() override;
84
85 expected<LazyMediaHandle> prepareMedia ( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
86 expected<LazyMediaHandle> prepareMedia ( const zypp::Url &url, const ProvideMediaSpec &request );
87
88 expected<MediaHandle> attachMediaIfNeeded( LazyMediaHandle lazyHandle );
89 expected<MediaHandle> attachMedia( const std::vector<zypp::Url> &urls, const ProvideMediaSpec &request );
90 expected<MediaHandle> attachMedia( const zypp::Url &url, const ProvideMediaSpec &request );
91
92 expected<Res> provide( const std::vector<zypp::Url> &urls, const ProvideFileSpec &request );
93 expected<Res> provide( const zypp::Url &url, const ProvideFileSpec &request );
94 expected<Res> provide( const MediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
95 expected<Res> provide( const LazyMediaHandle &attachHandle, const zypp::Pathname &fileName, const ProvideFileSpec &request );
96
97
101 expected<zypp::CheckSum> checksumForFile ( const zypp::Pathname &p, const std::string &algorithm );
102
106 expected<zypp::ManagedFile> copyFile ( const zypp::Pathname &source, const zypp::Pathname &target );
107 expected<zypp::ManagedFile> copyFile ( Res source, const zypp::Pathname &target );
108
109 static auto copyResultToDest ( MediaSyncFacadeRef provider, const zypp::Pathname &targetPath ) {
110 return [ providerRef=std::move(provider), targetPath = targetPath ]( Res &&file ){
111 zypp::filesystem::assert_dir( targetPath.dirname () );
112 return providerRef->copyFile( std::move(file), targetPath );
113 };
114 }
115
116 protected:
117 void releaseMedium ( const AttachedSyncMediaInfo *ptr );
118
119 private:
120 std::vector<zypp::Url> sanitizeUrls(const std::vector<zypp::Url> &urls) const;
121 std::vector<AttachedSyncMediaInfo_Ptr> _attachedMedia;
122 };
123
124 using SyncProvideRes = MediaSyncFacade::Res;
125
126 //template <bool async>
127 //using MediaFacade = std::conditional_t<async, MediaAsyncFacade, MediaSyncFacade>;
128}
129
130
131
132#endif
MediaManager.h
MediaSetAccess.h
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::filesystem::Pathname::dirname
Pathname dirname() const
Return all but the last component od this path.
Definition Pathname.h:126
zyppng::AttachedSyncMediaInfo
Definition mediafacade.cc:22
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::LazyMediaHandle
Definition lazymediahandle.h:19
zyppng::MediaSyncFacade::Res
Definition mediafacade.h:58
zyppng::MediaSyncFacade::Res::_provideHandle
MediaHandle _provideHandle
Definition mediafacade.h:79
zyppng::MediaSyncFacade::Res::asManagedFile
const zypp::ManagedFile & asManagedFile() const
Definition mediafacade.h:73
zyppng::MediaSyncFacade::Res::Res
Res(MediaHandle hdl, zypp::ManagedFile file)
Definition mediafacade.cc:144
zyppng::MediaSyncFacade::Res::_res
zypp::ManagedFile _res
Definition mediafacade.h:78
zyppng::MediaSyncFacade::Res::file
const zypp::Pathname file() const
Definition mediafacade.cc:149
zyppng::MediaSyncFacade
Definition mediafacade.h:49
zyppng::MediaSyncFacade::provide
expected< Res > provide(const std::vector< zypp::Url > &urls, const ProvideFileSpec &request)
Definition mediafacade.cc:449
zyppng::MediaSyncFacade::attachMedia
expected< MediaHandle > attachMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition mediafacade.cc:358
zyppng::MediaSyncFacade::AttachedSyncMediaInfo
friend class AttachedSyncMediaInfo
Definition mediafacade.h:53
zyppng::MediaSyncFacade::checksumForFile
expected< zypp::CheckSum > checksumForFile(const zypp::Pathname &p, const std::string &algorithm)
Definition mediafacade.cc:539
zyppng::MediaSyncFacade::LazyMediaHandle
::zyppng::LazyMediaHandle< MediaSyncFacade > LazyMediaHandle
Definition mediafacade.h:56
zyppng::MediaSyncFacade::copyFile
expected< zypp::ManagedFile > copyFile(const zypp::Pathname &source, const zypp::Pathname &target)
Definition mediafacade.cc:548
zyppng::MediaSyncFacade::MediaHandle
SyncMediaHandle MediaHandle
Definition mediafacade.h:55
zyppng::MediaSyncFacade::_attachedMedia
std::vector< AttachedSyncMediaInfo_Ptr > _attachedMedia
Definition mediafacade.h:121
zyppng::MediaSyncFacade::copyResultToDest
static auto copyResultToDest(MediaSyncFacadeRef provider, const zypp::Pathname &targetPath)
Definition mediafacade.h:109
zyppng::MediaSyncFacade::attachMediaIfNeeded
expected< MediaHandle > attachMediaIfNeeded(LazyMediaHandle lazyHandle)
Definition mediafacade.cc:434
zyppng::MediaSyncFacade::ZYPP_DECL_PRIVATE_CONSTR
ZYPP_DECL_PRIVATE_CONSTR(MediaSyncFacade)
zyppng::MediaSyncFacade::prepareMedia
expected< LazyMediaHandle > prepareMedia(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &request)
Definition mediafacade.cc:421
zyppng::ProvideFileSpec
Definition providespec.h:92
zyppng::ProvideMediaSpec
Definition providespec.h:29
zyppng::SyncMediaHandle
Definition mediafacade.h:26
zyppng::SyncMediaHandle::isValid
bool isValid() const
Definition mediafacade.cc:118
zyppng::SyncMediaHandle::SyncMediaHandle
SyncMediaHandle()
Definition mediafacade.cc:108
zyppng::SyncMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition mediafacade.cc:131
zyppng::SyncMediaHandle::ParentType
MediaSyncFacade ParentType
Definition mediafacade.h:29
zyppng::SyncMediaHandle::info
const AttachedSyncMediaInfo & info() const
Definition mediafacade.cc:139
zyppng::SyncMediaHandle::parent
MediaSyncFacadeRef parent() const
Definition mediafacade.cc:113
zyppng::SyncMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition mediafacade.cc:123
zyppng::SyncMediaHandle::_data
AttachedSyncMediaInfo_Ptr _data
Definition mediafacade.h:40
zyppng::expected
Definition expected.h:27
zypp::filesystem::assert_dir
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition PathInfo.cc:324
zypp::target
Definition KeyRing.h:325
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp::ManagedFile
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
zypp::ZYPP_API
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zyppng
Definition MediaCurl2.h:22
zyppng::SyncProvideRes
MediaSyncFacade::Res SyncProvideRes
Definition mediafacade.h:124
PtrTypes.h
DEFINE_PTR_TYPE
#define DEFINE_PTR_TYPE(NAME)
Forward declaration of Ptr types.
Definition PtrTypes.h:639
ZYPP_ADD_CREATE_FUNC
#define ZYPP_ADD_CREATE_FUNC(Class)
Definition zyppglobal.h:205
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126