libzypp 17.34.0
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;
41 class RpcMessageStream;
42 using RpcMessageStreamPtr = std::shared_ptr<RpcMessageStream>;
43
44
46 {
48 public:
50
60
62
63 bool queueRequest ( ProvideRequestRef req );
64 bool dequeueRequest( ProvideRequestRef req, std::exception_ptr error );
67
68 std::string nextMediaId () const;
69 AttachedMediaInfo_Ptr addMedium ( AttachedMediaInfo_Ptr &&medium );
70
71 std::string effectiveScheme ( const std::string &scheme ) const;
72
73 void onPulseTimeout ( Timer & );
74 void onQueueIdle ();
76 expected<ProvideQueue::Config> schemeConfig(const std::string &scheme);
77
78 std::optional<zypp::ManagedFile> addToFileCache ( const zypp::Pathname &downloadedFile );
79 bool isInCache ( const zypp::Pathname &downloadedFile ) const;
80
81 bool isRunning() const;
82
83 const zypp::Pathname &workerPath() const;
84 const std::string queueName( ProvideQueue &q ) const;
85
86 std::vector<AttachedMediaInfo_Ptr> &attachedMediaInfos();
87
88 std::list<ProvideItemRef> &items();
89
91
92 ProvideStatusRef log () {
93 return _log;
94 }
95
96 uint32_t nextRequestId();
97
98 Signal< Provide::MediaChangeAction ( const std::string &, const std::string &, const int32_t, const std::vector<std::string> &, const std::optional<std::string> &) > _sigMediaChange;
99 Signal< std::optional<zypp::media::AuthData> ( const zypp::Url &reqUrl, const std::string &triedUsername, const std::map<std::string, std::string> &extraValues ) > _sigAuthRequired;
100
101 protected:
102 void doSchedule (Timer &);
103
104 //@TODO should we make those configurable?
105 std::unordered_map< std::string, std::string > _workerAlias {
106 {"ftp" ,"http"},
107 {"tftp" ,"http"},
108 {"https","http"},
109 {"cifs" ,"smb" },
110 {"nfs4" ,"nfs" },
111 {"cd" ,"disc"},
112 {"dvd" ,"disc"},
113 {"file" ,"dir" },
114 {"hd" ,"disk"}
115 };
116
117 bool _isRunning = false;
118 bool _isScheduling = false;
120 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
122
123 std::list< ProvideItemRef > _items; //< The list of running provide Items, each of them can spawn multiple requests
124 uint32_t _nextRequestId = 0; //< The next request ID , we use controller wide unique IDs instead of worker locals IDs , its easier to track
125
126 struct QueueItem {
127 std::string _schemeName;
128 std::deque<ProvideRequestRef> _requests;
129 };
130 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
131
132
133 std::vector< AttachedMediaInfo_Ptr > _attachedMediaInfos; //< List of currently attached medias
134
135 std::unordered_map< std::string, ProvideQueueRef > _workerQueues;
136 std::unordered_map< std::string, ProvideQueue::Config > _schemeConfigs;
137
140 std::optional<std::chrono::steady_clock::time_point> _deathTimer; // timepoint where this item was seen first without a refcount
141 };
142 std::unordered_map< std::string, FileCacheItem > _fileCache;
143
146
147 ProvideStatusRef _log;
149 };
150}
151
152#endif
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Url manipulation class.
Definition Url.h:92
std::unordered_map< std::string, ProvideQueue::Config > _schemeConfigs
Definition provide_p.h:136
const std::string queueName(ProvideQueue &q) const
Definition provide.cc:834
void doSchedule(Timer &)
Definition provide.cc:70
void onItemStateChanged(ProvideItem &item)
Definition provide.cc:898
std::string effectiveScheme(const std::string &scheme) const
Definition provide.cc:848
std::list< ProvideItemRef > _items
Definition provide_p.h:123
std::optional< zypp::ManagedFile > addToFileCache(const zypp::Pathname &downloadedFile)
Definition provide.cc:729
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:98
bool dequeueRequest(ProvideRequestRef req, std::exception_ptr error)
Definition provide.cc:807
ProvideStatusRef _log
Definition provide_p.h:147
zypp::media::CredManagerOptions _credManagerOptions
Definition provide_p.h:145
ProvidePrivate(zypp::Pathname &&workDir, Provide &pub)
Definition provide.cc:21
std::string nextMediaId() const
Definition provide.cc:773
void queueItem(ProvideItemRef item)
Definition provide.cc:755
zypp::media::CredManagerOptions & credManagerOptions()
Definition provide.cc:704
Timer::Ptr _scheduleTrigger
Definition provide_p.h:120
zypp::Pathname _workerPath
Definition provide_p.h:144
bool isRunning() const
Definition provide.cc:843
bool queueRequest(ProvideRequestRef req)
Definition provide.cc:791
std::unordered_map< std::string, ProvideQueueRef > _workerQueues
Definition provide_p.h:135
std::vector< AttachedMediaInfo_Ptr > _attachedMediaInfos
Definition provide_p.h:133
std::unordered_map< std::string, FileCacheItem > _fileCache
Definition provide_p.h:142
void onPulseTimeout(Timer &)
Definition provide.cc:857
bool isInCache(const zypp::Pathname &downloadedFile) const
Definition provide.cc:749
std::vector< AttachedMediaInfo_Ptr > & attachedMediaInfos()
Definition provide.cc:709
std::deque< QueueItem > _queues
Definition provide_p.h:130
zypp::Pathname _workDir
Definition provide_p.h:121
void schedule(ScheduleReason reason)
Definition provide.cc:38
AttachedMediaInfo_Ptr addMedium(AttachedMediaInfo_Ptr &&medium)
Definition provide.cc:779
std::unordered_map< std::string, std::string > _workerAlias
Definition provide_p.h:105
void dequeueItem(ProvideItem *item)
Definition provide.cc:761
expected< ProvideQueue::Config > schemeConfig(const std::string &scheme)
Definition provide.cc:714
uint32_t nextRequestId()
Definition provide.cc:916
ProvideStatusRef log()
Definition provide_p.h:92
const zypp::Pathname & workerPath() const
Definition provide.cc:829
std::list< ProvideItemRef > & items()
Definition provide.cc:699
Signal< void()> _sigIdle
Definition provide_p.h:148
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:99
std::optional< Action > MediaChangeAction
Definition provide.h:162
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
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::shared_ptr< RpcMessageStream > RpcMessageStreamPtr
Definition provide_p.h:42
std::optional< std::chrono::steady_clock::time_point > _deathTimer
Definition provide_p.h:140
std::deque< ProvideRequestRef > _requests
Definition provide_p.h:128