libzypp 17.36.7

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::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}
attachedmediainfo_p.h
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:43
zyppng::AttachedMediaInfo::_attachedUrl
zypp::Url _attachedUrl
Definition attachedmediainfo_p.h:52
zyppng::AttachedMediaInfo::_spec
ProvideMediaSpec _spec
Definition attachedmediainfo_p.h:53
zyppng::AttachedMediaInfo::isSameMedium
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
Definition attachedmediainfo.cc:52
zyppng::AttachedMediaInfo::name
const std::string & name() const
Definition attachedmediainfo.cc:38
zyppng::AttachedMediaInfo::_localMountPoint
std::optional< zypp::Pathname > _localMountPoint
Definition attachedmediainfo_p.h:54
zyppng::AttachedMediaInfo::AttachedMediaInfo
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, ProvideMediaSpec &spec)
Definition attachedmediainfo.cc:17
zyppng::AttachedMediaInfo::_idleSince
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
Definition attachedmediainfo_p.h:55
zyppng::AttachedMediaInfo::_name
std::string _name
Definition attachedmediainfo_p.h:49
zyppng::AttachedMediaInfo::ref_to
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
Definition attachedmediainfo.cc:49
zyppng::AttachedMediaInfo::_backingQueue
ProvideQueueWeakRef _backingQueue
Definition attachedmediainfo_p.h:50
zyppng::AttachedMediaInfo::setName
void setName(std::string &&name)
Definition attachedmediainfo.cc:33
zyppng::AttachedMediaInfo::_workerType
ProvideQueue::Config::WorkerType _workerType
Definition attachedmediainfo_p.h:51
zyppng::ProvideMediaSpec
Definition providespec.h:29
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 MediaCurl2.h:22
IMPL_PTR_TYPE
#define IMPL_PTR_TYPE(NAME)
Definition ReferenceCounted.h:137