libzypp 17.37.10

lazymediahandle.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
10#define ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
11
12#include <zypp-core/MirroredOrigin.h>
13#include <zypp-media/ng/ProvideSpec>
14#include <optional>
15
16
17 namespace zyppng
18{
19 template < class ProvideType >
20 class LazyMediaHandle {
21 public:
22 using MediaHandle = typename ProvideType::MediaHandle;
23 using ParentType = ProvideType;
24
25 friend ProvideType;
26
27 LazyMediaHandle( Ref<ProvideType> provider, zypp::MirroredOrigin origin, ProvideMediaSpec spec )
28 : _sharedData(
29 std::make_shared<Data>(
30 std::move(provider)
31 ,std::move(origin)
32 ,std::move(spec)
33 ))
34 { }
35
36 LazyMediaHandle(const LazyMediaHandle &) = default;
37 LazyMediaHandle(LazyMediaHandle &&) = default;
38 LazyMediaHandle &operator=(const LazyMediaHandle &) = default;
39 LazyMediaHandle &operator=(LazyMediaHandle &&) = default;
40
41 const Ref<ProvideType> &parent () const {
42 return _sharedData->_provider.lock();
43 }
44
49 const zypp::Url &baseUrl() const {
50 if ( !_sharedData->_mediaHandle ) {
51 return _sharedData->_origin.authority().url();
52 } else {
53 return _sharedData->_mediaHandle->baseUrl();
54 }
55 }
56
57 const zypp::MirroredOrigin &origin() const {
58 return _sharedData->_origin;
59 }
60
61 std::optional<MediaHandle> handle () const {
62 return _sharedData->_mediaHandle;
63 }
64
65 const ProvideMediaSpec &spec() const {
66 return _sharedData->_spec;
67 }
68
69 const std::optional<zypp::Pathname> &localPath() const
70 {
71 static std::optional<zypp::Pathname> noHandle;
72 if ( !attached() )
73 return noHandle;
74 return _sharedData->_mediaHandle.localPath();
75 }
76
77 bool attached() const {
78 return _sharedData->_mediaHandle.has_value();
79 }
80
81 private:
82
83 struct Data {
84 Data(Ref<ProvideType> &&provider, zypp::MirroredOrigin &&origin,
85 ProvideMediaSpec &&spec)
86 : _provider(std::move(provider)), _origin(std::move(origin)),
87 _spec(std::move(spec)) {}
88
89 Data(const Data &) = delete;
90 Data(Data &&) = delete;
91 Data &operator=(const Data &) = delete;
92 Data &operator=(Data &&) = delete;
93
94 WeakRef<ProvideType> _provider;
95 zypp::MirroredOrigin _origin;
96 ProvideMediaSpec _spec;
97 std::optional<MediaHandle> _mediaHandle;
98 };
99 Ref<Data> _sharedData;
100 };
101}
102
103#endif // ZYPP_MEDIA_NG_LAZYMEDIAHANDLE_H
MirroredOrigin.h
zypp::MirroredOrigin
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Definition MirroredOrigin.h:170
zypp::Url
Url manipulation class.
Definition Url.h:93
zyppng::LazyMediaHandle< Provide >::origin
const zypp::MirroredOrigin & origin() const
Definition lazymediahandle.h:57
zyppng::LazyMediaHandle< Provide >::ParentType
Provide ParentType
Definition lazymediahandle.h:23
zyppng::LazyMediaHandle::localPath
const std::optional< zypp::Pathname > & localPath() const
Definition lazymediahandle.h:69
zyppng::LazyMediaHandle::operator=
LazyMediaHandle & operator=(LazyMediaHandle &&)=default
zyppng::LazyMediaHandle< Provide >::_sharedData
Ref< Data > _sharedData
Definition lazymediahandle.h:99
zyppng::LazyMediaHandle< Provide >::spec
const ProvideMediaSpec & spec() const
Definition lazymediahandle.h:65
zyppng::LazyMediaHandle< Provide >::MediaHandle
typename Provide::MediaHandle MediaHandle
Definition lazymediahandle.h:22
zyppng::LazyMediaHandle< Provide >::ProvideType
friend ProvideType
Definition lazymediahandle.h:25
zyppng::LazyMediaHandle::operator=
LazyMediaHandle & operator=(const LazyMediaHandle &)=default
zyppng::LazyMediaHandle::baseUrl
const zypp::Url & baseUrl() const
Definition lazymediahandle.h:49
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(const LazyMediaHandle &)=default
zyppng::LazyMediaHandle::parent
const Ref< ProvideType > & parent() const
Definition lazymediahandle.h:41
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(LazyMediaHandle &&)=default
zyppng::LazyMediaHandle::attached
bool attached() const
Definition lazymediahandle.h:77
zyppng::LazyMediaHandle::handle
std::optional< MediaHandle > handle() const
Definition lazymediahandle.h:61
zyppng::LazyMediaHandle::LazyMediaHandle
LazyMediaHandle(Ref< ProvideType > provider, zypp::MirroredOrigin origin, ProvideMediaSpec spec)
Definition lazymediahandle.h:27
zyppng::ProvideMediaSpec
Definition providespec.h:29
std
Definition Arch.h:364
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::Ref
std::shared_ptr< T > Ref
Definition zyppglobal.h:110
zyppng::WeakRef
std::weak_ptr< T > WeakRef
Definition zyppglobal.h:113
zyppng::LazyMediaHandle::Data::Data
Data(Data &&)=delete
zyppng::LazyMediaHandle::Data::_mediaHandle
std::optional< MediaHandle > _mediaHandle
Definition lazymediahandle.h:97
zyppng::LazyMediaHandle::Data::operator=
Data & operator=(Data &&)=delete
zyppng::LazyMediaHandle::Data::_origin
zypp::MirroredOrigin _origin
Definition lazymediahandle.h:95
zyppng::LazyMediaHandle::Data::Data
Data(Ref< ProvideType > &&provider, zypp::MirroredOrigin &&origin, ProvideMediaSpec &&spec)
Definition lazymediahandle.h:84
zyppng::LazyMediaHandle::Data::operator=
Data & operator=(const Data &)=delete
zyppng::LazyMediaHandle::Data::Data
Data(const Data &)=delete
zyppng::LazyMediaHandle::Data::_spec
ProvideMediaSpec _spec
Definition lazymediahandle.h:96
zyppng::LazyMediaHandle::Data::_provider
WeakRef< ProvideType > _provider
Definition lazymediahandle.h:94