libzypp 17.36.5
attachedmediainfo.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*/
11
12namespace zyppng {
13
15
16
17 AttachedMediaInfo::AttachedMediaInfo( const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, ProvideMediaSpec &spec )
18 : AttachedMediaInfo( id, {}, workerType, baseUrl, spec )
19 { }
20
21 AttachedMediaInfo::AttachedMediaInfo( const std::string &id, ProvideQueueWeakRef backingQueue, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, const ProvideMediaSpec &mediaSpec , const std::optional<zypp::Pathname> &mnt )
22 : _name(id)
23 , _backingQueue( std::move(backingQueue) )
24 , _workerType( workerType )
25 , _attachedUrl( baseUrl )
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 void AttachedMediaInfo::unref_to(unsigned int refCnt) const {
44 // last reference is always owned by the Provide instance
45 if ( refCnt == 1 )
46 _idleSince = std::chrono::steady_clock::now();
47 }
48
49 void AttachedMediaInfo::ref_to(unsigned int refCnt) const {
50 if ( _idleSince && refCnt > 1 ) _idleSince.reset();
51 }
52 bool AttachedMediaInfo::isSameMedium(const std::vector<zypp::Url> &urls, const ProvideMediaSpec &spec) {
53
54 const auto check = _spec.isSameMedium(spec);
55 if ( !zypp::indeterminate (check) )
56 return (bool)check;
57
58 // let the URL rule
59 return ( std::find( urls.begin(), urls.end(), _attachedUrl ) != urls.end() );
60 }
61
62}
Url manipulation class.
Definition Url.h:93
void unref_to(unsigned int refCnt) const override
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
const std::string & name() const
std::optional< zypp::Pathname > _localMountPoint
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, ProvideMediaSpec &spec)
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
ProvideQueueWeakRef _backingQueue
void setName(std::string &&name)
ProvideQueue::Config::WorkerType _workerType
Definition Arch.h:364
Easy-to use interface to the ZYPP dependency resolver.
#define IMPL_PTR_TYPE(NAME)