libzypp 17.37.17
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>
26#include <zypp-core/zyppng/base/Timer>
28
29namespace 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;
42 {
44 public:
45 ProvidePrivate( zypp::Pathname &&workDir, Provide &pub );
46
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
87
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;
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
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
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
144
145 ProvideStatusRef _log;
147 };
148}
149
150#endif
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
Url manipulation class.
Definition Url.h:93
BasePrivate(Base &b)
Definition base_p.h:17
std::unordered_map< std::string, ProvideQueue::Config > _schemeConfigs
Definition provide_p.h:134
const std::string queueName(ProvideQueue &q) const
Definition provide.cc:859
void doSchedule(Timer &)
Definition provide.cc:70
void onItemStateChanged(ProvideItem &item)
Definition provide.cc:923
std::string effectiveScheme(const std::string &scheme) const
Definition provide.cc:873
std::list< ProvideItemRef > _items
Definition provide_p.h:121
std::optional< zypp::ManagedFile > addToFileCache(const zypp::Pathname &downloadedFile)
Definition provide.cc:754
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Definition provide.cc:832
ProvideStatusRef _log
Definition provide_p.h:145
zypp::media::CredManagerOptions _credManagerOptions
Definition provide_p.h:143
ProvidePrivate(zypp::Pathname &&workDir, Provide &pub)
Definition provide.cc:21
std::string nextMediaId() const
Definition provide.cc:798
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
void queueItem(ProvideItemRef item)
Definition provide.cc:780
zypp::media::CredManagerOptions & credManagerOptions()
Definition provide.cc:704
Timer::Ptr _scheduleTrigger
Definition provide_p.h:118
zypp::Pathname _workerPath
Definition provide_p.h:142
bool isRunning() const
Definition provide.cc:868
bool queueRequest(ProvideRequestRef req)
Definition provide.cc:816
std::unordered_map< std::string, ProvideQueueRef > _workerQueues
Definition provide_p.h:133
std::vector< AttachedMediaInfo_Ptr > _attachedMediaInfos
Definition provide_p.h:131
std::unordered_map< std::string, FileCacheItem > _fileCache
Definition provide_p.h:140
zypp::MirroredOrigin sanitizeUrls(const zypp::MirroredOrigin &origin)
Definition provide.cc:709
void onPulseTimeout(Timer &)
Definition provide.cc:882
bool isInCache(const zypp::Pathname &downloadedFile) const
Definition provide.cc:774
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition provide.cc:734
std::deque< QueueItem > _queues
Definition provide_p.h:128
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
zypp::Pathname _workDir
Definition provide_p.h:119
void schedule(ScheduleReason reason)
Definition provide.cc:38
AttachedMediaInfo_Ptr addMedium(AttachedMediaInfo_Ptr &&medium)
Definition provide.cc:804
std::unordered_map< std::string, std::string > _workerAlias
Definition provide_p.h:103
void dequeueItem(ProvideItem *item)
Definition provide.cc:786
expected< ProvideQueue::Config > schemeConfig(const std::string &scheme)
Definition provide.cc:739
uint32_t nextRequestId()
Definition provide.cc:941
ProvideStatusRef log()
Definition provide_p.h:90
const zypp::Pathname & workerPath() const
Definition provide.cc:854
std::list< ProvideItemRef > & items()
Definition provide.cc:699
Signal< void()> _sigIdle
Definition provide_p.h:146
std::optional< Action > MediaChangeAction
Definition provide.h:177
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
static std::shared_ptr< Timer > create()
Creates a new Timer object, the timer is not started at this point.
Definition timer.cc:52
std::shared_ptr< Timer > Ptr
Definition timer.h:51
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
Definition ManagedFile.h:27
constexpr auto DEFAULT_CPU_WORKERS
Definition provide_p.h:37
constexpr auto DEFAULT_ACTIVE_CONN_PER_HOST
Definition provide_p.h:34
constexpr std::string_view DEFAULT_PROVIDE_WORKER_PATH
Definition provide_p.h:32
constexpr auto DEFAULT_ACTIVE_CONN
Definition provide_p.h:35
constexpr auto DEFAULT_MAX_DYNAMIC_WORKERS
Definition provide_p.h:36
constexpr std::string_view ATTACHED_MEDIA_SUFFIX
Definition provide_p.h:33
std::optional< std::chrono::steady_clock::time_point > _deathTimer
Definition provide_p.h:138
std::deque< ProvideRequestRef > _requests
Definition provide_p.h:126
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98