libzypp 17.37.10

attachedmediainfo.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*/
10#include "private/attachedmediainfo_p.h"
11
12 namespace zyppng {
13
14 IMPL_PTR_TYPE( AttachedMediaInfo )
15
16
17 AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, ProvideMediaSpec &spec )
18 : AttachedMediaInfo( id, {}, workerType, originConfig, spec )
19 { }
20
21 AttachedMediaInfo::AttachedMediaInfo(const std::string &id, ProvideQueueWeakRef backingQueue, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, const ProvideMediaSpec &mediaSpec , const std::optional<zypp::Pathname> &mnt )
22 : _name(id)
23 , _backingQueue( std::move(backingQueue) )
24 , _workerType( workerType )
25 , _originConfig( originConfig )
26 , _spec( mediaSpec )
27 , _localMountPoint( mnt )
28 {
29 // idle on construction, since only the Provide has a reference atm
30 _idleSince = std::chrono::steady_clock::now();
31 }
32
33 void AttachedMediaInfo::setName(std::string &&name)
34 {
35 _name = std::move(name);
36 }
37
38 const std::string &AttachedMediaInfo::name() const
39 {
40 return _name;
41 }
42
43 zypp::Url AttachedMediaInfo::attachedUrl() const
44 {
45 if ( !_originConfig.isValid() )
46 return {};
47
48 return _originConfig.authority().url();
49 }
50
51 void AttachedMediaInfo::unref_to(unsigned int refCnt) const {
52 // last reference is always owned by the Provide instance
53 if ( refCnt == 1 )
54 _idleSince = std::chrono::steady_clock::now();
55 }
56
57 void AttachedMediaInfo::ref_to(unsigned int refCnt) const {
58 if ( _idleSince && refCnt > 1 ) _idleSince.reset();
59 }
60
61 bool AttachedMediaInfo::isSameMedium(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec) {
62 return isSameMedium( _originConfig, _spec, origin, spec );
63 }
64
65 bool AttachedMediaInfo::isSameMedium( const zypp::MirroredOrigin &originA, const ProvideMediaSpec &specA, const zypp::MirroredOrigin &originB, const ProvideMediaSpec &specB )
66 {
67 const auto check = specA.isSameMedium(specB);
68 if ( !zypp::indeterminate (check) )
69 return (bool)check;
70
71 // if the endpoints intersect we assume same medium
72 const auto &intersects = []( const zypp::MirroredOrigin &l1, const zypp::MirroredOrigin &l2 ){
73 bool intersect = false;
74 for ( const auto &u: l1 ) {
75 intersect = ( std::find( l2.begin (), l2.end(), u ) != l2.end() );
76 if ( intersect )
77 break;
78 }
79 return intersect;
80 };
81
82 return intersects( originA, originB );
83 }
84
85}
attachedmediainfo_p.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::AttachedMediaInfo
Definition attachedmediainfo_p.h:31
zyppng::AttachedMediaInfo::unref_to
void unref_to(unsigned int refCnt) const override
Definition attachedmediainfo.cc:51
zyppng::AttachedMediaInfo::attachedUrl
zypp::Url attachedUrl() const
Definition attachedmediainfo.cc:43
zyppng::AttachedMediaInfo::_spec
ProvideMediaSpec _spec
Definition attachedmediainfo_p.h:57
zyppng::AttachedMediaInfo::_originConfig
zypp::MirroredOrigin _originConfig
Definition attachedmediainfo_p.h:56
zyppng::AttachedMediaInfo::isSameMedium
bool isSameMedium(const zypp::MirroredOrigin &origin, const ProvideMediaSpec &spec)
Definition attachedmediainfo.cc:61
zyppng::AttachedMediaInfo::name
const std::string & name() const
Definition attachedmediainfo.cc:38
zyppng::AttachedMediaInfo::_localMountPoint
std::optional< zypp::Pathname > _localMountPoint
Definition attachedmediainfo_p.h:58
zyppng::AttachedMediaInfo::_idleSince
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
Definition attachedmediainfo_p.h:59
zyppng::AttachedMediaInfo::_name
std::string _name
Definition attachedmediainfo_p.h:53
zyppng::AttachedMediaInfo::ref_to
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
Definition attachedmediainfo.cc:57
zyppng::AttachedMediaInfo::_backingQueue
ProvideQueueWeakRef _backingQueue
Definition attachedmediainfo_p.h:54
zyppng::AttachedMediaInfo::setName
void setName(std::string &&name)
Definition attachedmediainfo.cc:33
zyppng::AttachedMediaInfo::AttachedMediaInfo
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::MirroredOrigin &originConfig, ProvideMediaSpec &spec)
Definition attachedmediainfo.cc:17
zyppng::AttachedMediaInfo::_workerType
ProvideQueue::Config::WorkerType _workerType
Definition attachedmediainfo_p.h:55
zyppng::ProvideMediaSpec
Definition providespec.h:29
zyppng::ProvideMediaSpec::isSameMedium
zypp::TriBool isSameMedium(const ProvideMediaSpec &other) const
Definition providespec.cc:146
zyppng::ProvideQueue
Definition providequeue_p.h:31
zyppng::WorkerCaps::WorkerType
WorkerType
Definition providemessage_p.h:379
std
Definition Arch.h:364
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
zyppng
Definition MediaNetworkRequestExecutor.h:16
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137