libzypp 17.37.17
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/pipelines/Expected>
20#include <zypp-media/ng/HeaderValueMap>
21#include <zypp-media/MediaException>
22#include <zypp-media/Mount>
23
24#include <string_view>
25#include <deque>
26
27namespace zyppng::worker {
28
32
33 struct AuthInfo
34 {
35 std::string username;
36 std::string password;
38 std::map<std::string, std::string> extraKeys = {};
39 };
40
46
49
51 {
52 public:
58
59 ProvideWorkerItem( ProvideMessage &&spec ) : _spec( std::move(spec) ) { }
60
63 };
64
65 class ProvideWorker : public Base
66 {
67 public:
68
70 ONLY_NEW_PROVIDES, // provide is called only when new provide requests are added to the queue
71 QUEUE_NOT_EMTPY // provide is called continiously until the queue is empty
72 };
73
74 ProvideWorker( std::string_view workerName );
75 virtual ~ProvideWorker();
76
77 StompFrameStreamRef messageStream() const;
78
79 expected<void> run ( int recv = STDIN_FILENO, int send = STDOUT_FILENO );
80
81 std::deque<ProvideWorkerItemRef> &requestQueue();
85 virtual void immediateShutdown (){};
86
96 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 = {} );
97
105 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 = {} );
106
107 ProvideNotificatioMode provNotificationMode() const;
108 void setProvNotificationMode(const ProvideNotificatioMode &provNotificationMode);
109
110 protected:
111 virtual void initLog();
112 virtual expected<WorkerCaps> initialize ( const Configuration &conf ) = 0;
113
117 virtual void provide ( ) = 0;
118 virtual void cancel ( const std::deque<ProvideWorkerItemRef>::iterator &request ) = 0;
119
126 virtual ProvideWorkerItemRef makeItem (ProvideMessage &&spec );
127
137 void provideStart ( const uint32_t id, const zypp::Url &url, const zypp::Pathname &localFile, const zypp::Pathname &stagingFile = {} );
138
143 void provideSuccess (const uint32_t id, bool cacheHit, const zypp::Pathname &localFile, const HeaderValueMap extra = {} );
144
150 void provideFailed (const uint32_t id, const ProvideMessage::Code code, const std::string &reason, const bool transient, const HeaderValueMap extra = {} );
151
157 void provideFailed (const uint32_t id, const ProvideMessage::Code code, const bool transient, const zypp::Exception &e );
158
162 void attachSuccess ( const uint32_t id, const std::optional<std::string> &localMountPoint = {} );
163
167 void detachSuccess ( const uint32_t id );
168
173 void redirect ( const uint32_t id, const zypp::Url &url, const zypp::Pathname &newPath );
174
179
180
181 private:
183 void maybeDelayedShutdown ();
184 void messageLoop ( Timer & );
187 void messageReceived ();
189 void invalidMessageReceived ( std::exception_ptr p );
191 void pushSingleMessage (const zypp::PluginFrame &msg );
192 expected<ProvideMessage> sendAndWaitForResponse ( const ProvideMessage &request, const std::vector<uint> &responseCodes );
194
195 private:
197 bool _inControllerRequest = false; //< Used to signalize that we are currently in a blocking controller callback
198 bool _isRunning = false;
199 std::string_view _workerName;
204 StompFrameStreamRef _stream;
206
207 std::exception_ptr _fatalError; //< Error that caused the eventloop to stop
208
209 std::deque<ProvideMessage> _pendingMessages;
210 std::deque<ProvideWorkerItemRef> _pendingProvides;
211 };
212}
213
214
215#endif
Base class for Exception.
Definition Exception.h:153
Command frame for communication with PluginScript.
Definition PluginFrame.h:42
Url manipulation class.
Definition Url.h:93
Just inherits Exception to separate media exceptions.
std::shared_ptr< AsyncDataSource > Ptr
EventLoopRef Ptr
Definition eventloop.h:47
static Ptr create()
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={})
StompFrameStreamRef messageStream() const
virtual void cancel(const std::deque< ProvideWorkerItemRef >::iterator &request)=0
std::deque< ProvideMessage > _pendingMessages
void writeFdClosed(AsyncDataSource::ChannelCloseReason)
void pushSingleMessage(const zypp::PluginFrame &msg)
expected< ProvideMessage > parseReceivedMessage(const zypp::PluginFrame &m)
void provideSuccess(const uint32_t id, bool cacheHit, const zypp::Pathname &localFile, const HeaderValueMap extra={})
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
void provideFailed(const uint32_t id, const ProvideMessage::Code code, const std::string &reason, const bool transient, const HeaderValueMap extra={})
virtual expected< WorkerCaps > initialize(const Configuration &conf)=0
void readFdClosed(uint, AsyncDataSource::ChannelCloseReason)
StompFrameStreamRef _stream
std::deque< ProvideWorkerItemRef > & requestQueue()
ProvideNotificatioMode _provNotificationMode
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
Url details namespace.
Definition UrlBase.cc:58
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
zyppng::ProviderConfiguration Configuration
zyppng::ProvideMessage Message
zyppng::WorkerCaps WorkerCaps
std::map< std::string, std::string > extraKeys
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126