libzypp 17.37.10

provide_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPP_MEDIA_PRIVATE_PROVIDE_P_H_INCLUDED
15#define ZYPP_MEDIA_PRIVATE_PROVIDE_P_H_INCLUDED
16
17#include "providefwd_p.h"
18#include "providequeue_p.h"
19#include "attachedmediainfo_p.h"
20
21#include <zypp-media/auth/CredentialManager>
22#include <zypp-media/ng/Provide>
23#include <zypp-media/ng/ProvideItem>
24#include <zypp-media/ng/ProvideSpec>
25#include <zypp-core/zyppng/base/private/base_p.h>
26#include <zypp-core/zyppng/base/Timer>
27#include <zypp-core/ManagedFile.h>
28
29 namespace zyppng {
30
31 namespace constants {
32 constexpr std::string_view DEFAULT_PROVIDE_WORKER_PATH = ZYPP_WORKER_PATH;
33 constexpr std::string_view ATTACHED_MEDIA_SUFFIX = "-media";
34 constexpr auto DEFAULT_ACTIVE_CONN_PER_HOST = 5; //< how many simultanious connections to the same host are allowed
35 constexpr auto DEFAULT_ACTIVE_CONN = 10; //< how many simultanious connections are allowed
36 constexpr auto DEFAULT_MAX_DYNAMIC_WORKERS = 20;
37 constexpr auto DEFAULT_CPU_WORKERS = 4;
38 }
39
40 class ProvideQueue;
41 class ProvidePrivate : public BasePrivate
42 {
43 ZYPP_DECLARE_PUBLIC(Provide)
44 public:
45 ProvidePrivate( zypp::Pathname &&workDir, Provide &pub );
46
47 enum ScheduleReason
48 {
49 ProvideStart,
50 QueueIdle,
51 EnqueueItem,
52 EnqueueReq,
53 RestartAttach,
54 FinishReq
55 };
56
57 void schedule( ScheduleReason reason );
58
59 bool queueRequest ( ProvideRequestRef req );
60 bool dequeueRequest( ProvideRequestRef req, std::exception_ptr error );
61 void queueItem ( ProvideItemRef item );
62 void dequeueItem ( ProvideItem *item );
63
64 std::string nextMediaId () const;
65 AttachedMediaInfo_Ptr addMedium ( AttachedMediaInfo_Ptr &&medium );
66
67 std::string effectiveScheme ( const std::string &scheme ) const;
68
69 void onPulseTimeout ( Timer & );
70 void onQueueIdle ();
71 void onItemStateChanged ( ProvideItem &item );
72 expected<ProvideQueue::Config> schemeConfig(const std::string &scheme);
73
74 std::optional<zypp::ManagedFile> addToFileCache ( const zypp::Pathname &downloadedFile );
75 bool isInCache ( const zypp::Pathname &downloadedFile ) const;
76
77 bool isRunning() const;
78
79 const zypp::Pathname &workerPath() const;
80 const std::string queueName( ProvideQueue &q ) const;
81
82 std::vector<AttachedMediaInfo_Ptr> &attachedMediaInfos();
83
84 std::list<ProvideItemRef> &items();
85
86 zypp::media::CredManagerOptions &credManagerOptions ();
87
88 zypp::MirroredOrigin sanitizeUrls (const zypp::MirroredOrigin &origin );
89
90 ProvideStatusRef log () {
91 return _log;
92 }
93
94 uint32_t nextRequestId();
95
96 Signal< Provide::MediaChangeAction ( const std::string &, const std::string &, const int32_t, const std::vector<std::string> &, const std::optional<std::string> &) > _sigMediaChange;
97 Signal< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > _sigAuthRequired;
98
99 protected:
100 void doSchedule (Timer &);
101
102 //@TODO should we make those configurable?
103 std::unordered_map< std::string, std::string > _workerAlias {
104 {"ftp" ,"http"},
105 {"tftp" ,"http"},
106 {"https","http"},
107 {"cifs" ,"smb" },
108 {"nfs4" ,"nfs" },
109 {"cd" ,"disc"},
110 {"dvd" ,"disc"},
111 {"file" ,"dir" },
112 {"hd" ,"disk"}
113 };
114
115 bool _isRunning = false;
116 bool _isScheduling = false;
117 Timer::Ptr _pulseTimer = Timer::create();
118 Timer::Ptr _scheduleTrigger = Timer::create(); //< instead of constantly calling schedule we set a trigger event so it runs as soon as event loop is on again
119 zypp::Pathname _workDir;
120
121 std::list< ProvideItemRef > _items; //< The list of running provide Items, each of them can spawn multiple requests
122 uint32_t _nextRequestId = 0; //< The next request ID , we use controller wide unique IDs instead of worker locals IDs , its easier to track
123
124 struct QueueItem {
125 std::string _schemeName;
126 std::deque<ProvideRequestRef> _requests;
127 };
128 std::deque<QueueItem> _queues; //< List of request queues for the workers, grouped by scheme. We use a deque and not a map because of possible changes to the list of queues during scheduling
129
130
131 std::vector< AttachedMediaInfo_Ptr > _attachedMediaInfos; //< List of currently attached medias
132
133 std::unordered_map< std::string, ProvideQueueRef > _workerQueues;
134 std::unordered_map< std::string, ProvideQueue::Config > _schemeConfigs;
135
136 struct FileCacheItem {
137 zypp::ManagedFile _file;
138 std::optional<std::chrono::steady_clock::time_point> _deathTimer; // timepoint where this item was seen first without a refcount
139 };
140 std::unordered_map< std::string, FileCacheItem > _fileCache;
141
142 zypp::Pathname _workerPath;
143 zypp::media::CredManagerOptions _credManagerOptions;
144
145 ProvideStatusRef _log;
146 Signal<void()> _sigIdle;
147 };
148}
149
150#endif
attachedmediainfo_p.h
base_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
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::ProvideItem
Definition provideitem.h:29
zyppng::ProvidePrivate::_pulseTimer
Timer::Ptr _pulseTimer
Definition provide_p.h:117
zyppng::ProvidePrivate::_schemeConfigs
std::unordered_map< std::string, ProvideQueue::Config > _schemeConfigs
Definition provide_p.h:134
zyppng::ProvidePrivate::_isScheduling
bool _isScheduling
Definition provide_p.h:116
zyppng::ProvidePrivate::queueName
const std::string queueName(ProvideQueue &q) const
Definition provide.cc:859
zyppng::ProvidePrivate::doSchedule
void doSchedule(Timer &)
Definition provide.cc:70
zyppng::ProvidePrivate::onItemStateChanged
void onItemStateChanged(ProvideItem &item)
Definition provide.cc:923
zyppng::ProvidePrivate::effectiveScheme
std::string effectiveScheme(const std::string &scheme) const
Definition provide.cc:873
zyppng::ProvidePrivate::_items
std::list< ProvideItemRef > _items
Definition provide_p.h:121
zyppng::ProvidePrivate::addToFileCache
std::optional< zypp::ManagedFile > addToFileCache(const zypp::Pathname &downloadedFile)
Definition provide.cc:754
zyppng::ProvidePrivate::_nextRequestId
uint32_t _nextRequestId
Definition provide_p.h:122
zyppng::ProvidePrivate::dequeueRequest
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Definition provide.cc:832
zyppng::ProvidePrivate::_log
ProvideStatusRef _log
Definition provide_p.h:145
zyppng::ProvidePrivate::_credManagerOptions
zypp::media::CredManagerOptions _credManagerOptions
Definition provide_p.h:143
zyppng::ProvidePrivate::onQueueIdle
void onQueueIdle()
Definition provide.cc:910
zyppng::ProvidePrivate::ProvidePrivate
ProvidePrivate(zypp::Pathname &&workDir, Provide &pub)
Definition provide.cc:21
zyppng::ProvidePrivate::_isRunning
bool _isRunning
Definition provide_p.h:115
zyppng::ProvidePrivate::nextMediaId
std::string nextMediaId() const
Definition provide.cc:798
zyppng::ProvidePrivate::_sigAuthRequired
Signal< std::optional< zypp::media::AuthData >(const zypp::Url &reqUrl, const std::string &triedUsername, const std::map< std::string, std::string > &extraValues) > _sigAuthRequired
Definition provide_p.h:97
zyppng::ProvidePrivate::queueItem
void queueItem(ProvideItemRef item)
Definition provide.cc:780
zyppng::ProvidePrivate::credManagerOptions
zypp::media::CredManagerOptions & credManagerOptions()
Definition provide.cc:704
zyppng::ProvidePrivate::_scheduleTrigger
Timer::Ptr _scheduleTrigger
Definition provide_p.h:118
zyppng::ProvidePrivate::_workerPath
zypp::Pathname _workerPath
Definition provide_p.h:142
zyppng::ProvidePrivate::isRunning
bool isRunning() const
Definition provide.cc:868
zyppng::ProvidePrivate::queueRequest
bool queueRequest(ProvideRequestRef req)
Definition provide.cc:816
zyppng::ProvidePrivate::_workerQueues
std::unordered_map< std::string, ProvideQueueRef > _workerQueues
Definition provide_p.h:133
zyppng::ProvidePrivate::_attachedMediaInfos
std::vector< AttachedMediaInfo_Ptr > _attachedMediaInfos
Definition provide_p.h:131
zyppng::ProvidePrivate::_fileCache
std::unordered_map< std::string, FileCacheItem > _fileCache
Definition provide_p.h:140
zyppng::ProvidePrivate::sanitizeUrls
zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin)
Definition provide.cc:709
zyppng::ProvidePrivate::onPulseTimeout
void onPulseTimeout(Timer &)
Definition provide.cc:882
zyppng::ProvidePrivate::isInCache
bool isInCache(const zypp::Pathname &downloadedFile) const
Definition provide.cc:774
zyppng::ProvidePrivate::attachedMediaInfos
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition provide.cc:734
zyppng::ProvidePrivate::_queues
std::deque< QueueItem > _queues
Definition provide_p.h:128
zyppng::ProvidePrivate::_sigMediaChange
Signal< Provide::MediaChangeAction(const std::string &, const std::string &, const int32_t, const std::vector< std::string > &, const std::optional< std::string > &) > _sigMediaChange
Definition provide_p.h:96
zyppng::ProvidePrivate::_workDir
zypp::Pathname _workDir
Definition provide_p.h:119
zyppng::ProvidePrivate::schedule
void schedule(ScheduleReason reason)
Definition provide.cc:38
zyppng::ProvidePrivate::addMedium
AttachedMediaInfo_Ptr addMedium(AttachedMediaInfo_Ptr &&medium)
Definition provide.cc:804
zyppng::ProvidePrivate::_workerAlias
std::unordered_map< std::string, std::string > _workerAlias
Definition provide_p.h:103
zyppng::ProvidePrivate::dequeueItem
void dequeueItem(ProvideItem *item)
Definition provide.cc:786
zyppng::ProvidePrivate::schemeConfig
expected< ProvideQueue::Config > schemeConfig(const std::string &scheme)
Definition provide.cc:739
zyppng::ProvidePrivate::nextRequestId
uint32_t nextRequestId()
Definition provide.cc:941
zyppng::ProvidePrivate::log
ProvideStatusRef log()
Definition provide_p.h:90
zyppng::ProvidePrivate::workerPath
const zypp::Pathname & workerPath() const
Definition provide.cc:854
zyppng::ProvidePrivate::items
std::list< ProvideItemRef > & items()
Definition provide.cc:699
zyppng::ProvidePrivate::_sigIdle
Signal< void()> _sigIdle
Definition provide_p.h:146
zyppng::ProvidePrivate::ScheduleReason
ScheduleReason
Definition provide_p.h:48
zyppng::ProvidePrivate::EnqueueItem
@ EnqueueItem
Definition provide_p.h:51
zyppng::ProvidePrivate::RestartAttach
@ RestartAttach
Definition provide_p.h:53
zyppng::ProvidePrivate::FinishReq
@ FinishReq
Definition provide_p.h:54
zyppng::ProvidePrivate::QueueIdle
@ QueueIdle
Definition provide_p.h:50
zyppng::ProvidePrivate::ProvideStart
@ ProvideStart
Definition provide_p.h:49
zyppng::ProvidePrivate::EnqueueReq
@ EnqueueReq
Definition provide_p.h:52
zyppng::ProvideQueue
Definition providequeue_p.h:31
zyppng::Provide
Definition provide.h:116
zyppng::Provide::MediaChangeAction
std::optional< Action > MediaChangeAction
Definition provide.h:177
zyppng::Signal
Definition signals.h:151
zyppng::Timer
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
zyppng::Timer::create
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Definition timer.cc:52
zyppng::Timer::Ptr
std::shared_ptr< Timer > Ptr
Definition timer.h:51
zyppng::expected
Definition expected.h:27
zypp::ManagedFile
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
zyppng::constants
Definition iodevice_p.h:27
zyppng::constants::DEFAULT_CPU_WORKERS
constexpr auto DEFAULT_CPU_WORKERS
Definition provide_p.h:37
zyppng::constants::DEFAULT_ACTIVE_CONN_PER_HOST
constexpr auto DEFAULT_ACTIVE_CONN_PER_HOST
Definition provide_p.h:34
zyppng::constants::DEFAULT_PROVIDE_WORKER_PATH
constexpr std::string_view DEFAULT_PROVIDE_WORKER_PATH
Definition provide_p.h:32
zyppng::constants::DEFAULT_ACTIVE_CONN
constexpr auto DEFAULT_ACTIVE_CONN
Definition provide_p.h:35
zyppng::constants::DEFAULT_MAX_DYNAMIC_WORKERS
constexpr auto DEFAULT_MAX_DYNAMIC_WORKERS
Definition provide_p.h:36
zyppng::constants::ATTACHED_MEDIA_SUFFIX
constexpr std::string_view ATTACHED_MEDIA_SUFFIX
Definition provide_p.h:33
zyppng
Definition MediaNetworkRequestExecutor.h:16
providefwd_p.h
providequeue_p.h
zypp::media::CredManagerOptions
Definition credentialmanager.h:40
zyppng::ProvidePrivate::FileCacheItem
Definition provide_p.h:136
zyppng::ProvidePrivate::FileCacheItem::_deathTimer
std::optional< std::chrono::steady_clock::time_point > _deathTimer
Definition provide_p.h:138
zyppng::ProvidePrivate::FileCacheItem::_file
zypp::ManagedFile _file
Definition provide_p.h:137
zyppng::ProvidePrivate::QueueItem
Definition provide_p.h:124
zyppng::ProvidePrivate::QueueItem::_requests
std::deque< ProvideRequestRef > _requests
Definition provide_p.h:126
zyppng::ProvidePrivate::QueueItem::_schemeName
std::string _schemeName
Definition provide_p.h:125
ManagedFile.h
ZYPP_DECLARE_PUBLIC
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98