libzypp 17.32.5
provideworker.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#ifndef ZYPP_MEDIA_PROVIDE_WORKER_H_INCLUDED
11#define ZYPP_MEDIA_PROVIDE_WORKER_H_INCLUDED
12
13#include <zypp-core/zyppng/base/Base>
14#include <zypp-core/zyppng/base/EventLoop>
15#include <zypp-core/zyppng/base/Timer>
16#include <zypp-core/zyppng/io/AsyncDataSource>
17#include <zypp-core/zyppng/rpc/MessageStream>
18#include <zypp-core/zyppng/pipelines/Expected>
21#include <zypp-media/ng/HeaderValueMap>
22#include <zypp-media/MediaException>
23#include <zypp-media/Mount>
24
25#include <string_view>
26#include <deque>
27
28namespace zyppng::worker {
29
33
34 struct AuthInfo
35 {
36 std::string username;
37 std::string password;
39 std::map<std::string, std::string> extraKeys = {};
40 };
41
47
50
52 {
53 public:
59
60 ProvideWorkerItem( ProvideMessage &&spec ) : _spec( std::move(spec) ) { }
61
64 };
65
66 class ProvideWorker : public Base
67 {
68 public:
69
71 ONLY_NEW_PROVIDES, // provide is called only when new provide requests are added to the queue
72 QUEUE_NOT_EMTPY // provide is called continiously until the queue is empty
73 };
74
75 ProvideWorker( std::string_view workerName );
76 virtual ~ProvideWorker();
77
79
80 expected<void> run ( int recv = STDIN_FILENO, int send = STDOUT_FILENO );
81
82 std::deque<ProvideWorkerItemRef> &requestQueue();
86 virtual void immediateShutdown (){};
87
97 MediaChangeRes requestMediaChange ( const uint32_t id, const std::string &label, const int32_t mediaNr, const std::vector<std::string> &devices, const std::optional<std::string> &desc = {} );
98
106 expected<AuthInfo> requireAuthorization ( const uint32_t id, const zypp::Url &url, const std::string &lastTriedUsername = "", const int64_t lastTimestamp = -1, const std::map<std::string, std::string> &extraFields = {} );
107
108 ProvideNotificatioMode provNotificationMode() const;
109 void setProvNotificationMode(const ProvideNotificatioMode &provNotificationMode);
110
111 protected:
112 virtual void initLog();
114
118 virtual void provide ( ) = 0;
119 virtual void cancel ( const std::deque<ProvideWorkerItemRef>::iterator &request ) = 0;
120
128
138 void provideStart ( const uint32_t id, const zypp::Url &url, const zypp::Pathname &localFile, const zypp::Pathname &stagingFile = {} );
139
144 void provideSuccess (const uint32_t id, bool cacheHit, const zypp::Pathname &localFile, const HeaderValueMap extra = {} );
145
151 void provideFailed ( const uint32_t id, const uint code, const std::string &reason, const bool transient, const HeaderValueMap extra = {} );
152
158 void provideFailed ( const uint32_t id, const uint code, const bool transient, const zypp::Exception &e );
159
163 void attachSuccess ( const uint32_t id, const std::optional<std::string> &localMountPoint = {} );
164
168 void detachSuccess ( const uint32_t id );
169
174 void redirect ( const uint32_t id, const zypp::Url &url, const zypp::Pathname &newPath );
175
180
181
182 private:
184 void maybeDelayedShutdown ();
185 void messageLoop ( Timer & );
188 void messageReceived ();
190 void invalidMessageReceived ( std::exception_ptr p );
192 void pushSingleMessage ( const RpcMessage &msg );
195
196 private:
198 bool _inControllerRequest = false; //< Used to signalize that we are currently in a blocking controller callback
199 bool _isRunning = false;
200 std::string_view _workerName;
207
208 std::exception_ptr _fatalError; //< Error that caused the eventloop to stop
209
210 std::deque<ProvideMessage> _pendingMessages;
211 std::deque<ProvideWorkerItemRef> _pendingProvides;
212 };
213}
214
215
216#endif
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
Base class for Exception.
Definition Exception.h:147
Url manipulation class.
Definition Url.h:92
Just inherits Exception to separate media exceptions.
std::shared_ptr< AsyncDataSource > Ptr
EventLoopRef Ptr
Definition eventloop.h:47
static Ptr create()
std::shared_ptr< RpcMessageStream > Ptr
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
ProvideWorkerItem(ProvideMessage &&spec)
void detachSuccess(const uint32_t id)
std::deque< ProvideWorkerItemRef > _pendingProvides
void handleSingleMessage(const ProvideMessage &provide)
MediaChangeRes requestMediaChange(const uint32_t id, const std::string &label, const int32_t mediaNr, const std::vector< std::string > &devices, const std::optional< std::string > &desc={})
AsyncDataSource & controlIO()
void attachSuccess(const uint32_t id, const std::optional< std::string > &localMountPoint={})
ProvideWorker(std::string_view workerName)
expected< void > executeHandshake()
AsyncDataSource::Ptr _controlIO
void provideStart(const uint32_t id, const zypp::Url &url, const zypp::Pathname &localFile, const zypp::Pathname &stagingFile={})
virtual void cancel(const std::deque< ProvideWorkerItemRef >::iterator &request)=0
std::deque< ProvideMessage > _pendingMessages
void writeFdClosed(AsyncDataSource::ChannelCloseReason)
void provideSuccess(const uint32_t id, bool cacheHit, const zypp::Pathname &localFile, const HeaderValueMap extra={})
RpcMessageStream::Ptr messageStream() const
RpcMessageStream::Ptr _stream
ProvideNotificatioMode provNotificationMode() const
expected< void > run(int recv=STDIN_FILENO, int send=STDOUT_FILENO)
virtual ProvideWorkerItemRef makeItem(ProvideMessage &&spec)
void setProvNotificationMode(const ProvideNotificatioMode &provNotificationMode)
ProviderConfiguration _workerConf
virtual expected< WorkerCaps > initialize(const Configuration &conf)=0
void readFdClosed(uint, AsyncDataSource::ChannelCloseReason)
void pushSingleMessage(const RpcMessage &msg)
void provideFailed(const uint32_t id, const uint code, const std::string &reason, const bool transient, const HeaderValueMap extra={})
std::deque< ProvideWorkerItemRef > & requestQueue()
ProvideNotificatioMode _provNotificationMode
expected< ProvideMessage > parseReceivedMessage(const RpcMessage &m)
expected< AuthInfo > requireAuthorization(const uint32_t id, const zypp::Url &url, const std::string &lastTriedUsername="", const int64_t lastTimestamp=-1, const std::map< std::string, std::string > &extraFields={})
void invalidMessageReceived(std::exception_ptr p)
void redirect(const uint32_t id, const zypp::Url &url, const zypp::Pathname &newPath)
expected< ProvideMessage > sendAndWaitForResponse(const ProvideMessage &request, const std::vector< uint > &responseCodes)
std::exception_ptr _fatalError
Definition Arch.h:364
std::map< std::string, std::string > extraKeys
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:117