libzypp  17.35.15
attachedmediainfo.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \----------------------------------------------------------------------/
9 */
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 }
IMPL_PTR_TYPE(AttachedSyncMediaInfo)
const std::string & name() const
void unref_to(unsigned int refCnt) const override
Definition: Arch.h:363
bool isSameMedium(const std::vector< zypp::Url > &urls, const ProvideMediaSpec &spec)
void setName(std::string &&name)
zypp::TriBool isSameMedium(const ProvideMediaSpec &other)
Definition: providespec.cc:145
std::optional< std::chrono::steady_clock::time_point > _idleSince
Set if the medium is idle.
bool check(const std::string &sequenceinfo_r, bool quick_r)
Check via sequence info.
void ref_to(unsigned refCnt) const override
Trigger derived classes after refCount was increased.
AttachedMediaInfo(const std::string &id, ProvideQueue::Config::WorkerType workerType, const zypp::Url &baseUrl, ProvideMediaSpec &spec)
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
Url manipulation class.
Definition: Url.h:91