libzypp  17.31.31
providequeue_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_QUEUE_P_H_INCLUDED
15 #define ZYPP_MEDIA_PRIVATE_PROVIDE_QUEUE_P_H_INCLUDED
16 
17 #include "providefwd_p.h"
18 #include <zypp-media/ng/Provide>
19 #include <zypp-proto/media/provider.pb.h>
20 #include <zypp-core/zyppng/io/Process>
21 #include <zypp-core/ByteCount.h>
22 
23 #include <deque>
24 #include <chrono>
25 #include <variant>
26 
27 namespace zyppng {
28 
29  class RpcMessageStream;
30  using RpcMessageStreamPtr = std::shared_ptr<RpcMessageStream>;
31 
32  class ProvideQueue : public Base
33  {
34  public:
35  friend struct ProvideResourceData;
36 
37  static constexpr uint32_t InvalidId = (uint32_t) -1;
38  using Config = zypp::proto::Capabilities;
39 
40  using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
41 
42  struct Item {
43 
44  enum State {
50  };
52  bool isAttachRequest () const;
53  bool isFileRequest () const;
54  bool isDetachRequest() const;
55 
56  ProvideRequestRef _request;
57  };
58 
59  ProvideQueue( ProvidePrivate &parent );
60  ~ProvideQueue();
61  bool startup ( const std::string &workerScheme, const zypp::Pathname &workDir, const std::string &hostname = "" );
62  void enqueue ( ProvideRequestRef request );
63  void cancel ( ProvideRequest *item, std::exception_ptr error );
64  void detach ( const std::string &id );
65  void scheduleNext ();
66  bool canScheduleMore () const;;
67  bool empty () const;
68 
72  bool isIdle () const;
73 
77  std::optional<TimePoint> idleSince () const;
78 
82  uint requestCount () const;
83 
87  uint activeRequests () const;
88 
95 
100  const std::string &hostname () const;
101 
102  const Config &workerConfig () const;
103 
104  SignalProxy<void()> sigIdle();
105 
106  private:
107  bool doStartup ();
108  void processMessage ( );
109  void readAllStderr ();
110  void forwardToLog ( std::string &&logLine );
111  void processReadyRead( int channel );
112  void procFinished ( int exitCode );
113  uint32_t nextRequestId();
114 
119  std::list< ProvideQueue::Item >::iterator dequeueActive ( std::list<Item>::iterator it );
120  void fatalWorkerError ( const std::exception_ptr &reason = nullptr );
121  void immediateShutdown ( const std::exception_ptr &reason );
122 
126  std::list< ProvideQueue::Item >::iterator cancelActiveItem (std::list<Item>::iterator i, const std::exception_ptr &error );
127 
128  private:
129  bool _queueShuttingDown = false;
130  uint8_t _crashCounter = 0;
133  std::string _myHostname;
135  std::deque< Item > _waitQueue;
136  std::list< Item > _activeItems;
137  Process::Ptr _workerProc;
139  Signal<void()> _sigIdle;
140  std::optional<TimePoint> _idleSince;
141  };
142 
143 }
144 
145 #endif
std::list< Item > _activeItems
std::list< ProvideQueue::Item >::iterator dequeueActive(std::list< Item >::iterator it)
Store and operate with byte count.
Definition: ByteCount.h:30
RpcMessageStreamPtr _messageStream
void enqueue(ProvideRequestRef request)
Definition: providequeue.cc:92
std::chrono::time_point< std::chrono::steady_clock > TimePoint
bool canScheduleMore() const
std::optional< TimePoint > idleSince() const
static constexpr uint32_t InvalidId
ProvideRequestRef _request
Signal< void()> _sigIdle
void cancel(ProvideRequest *item, std::exception_ptr error)
uint32_t nextRequestId()
zypp::ByteCount expectedProvideSize() const
void immediateShutdown(const std::exception_ptr &reason)
uint activeRequests() const
const Config & workerConfig() const
void procFinished(int exitCode)
void forwardToLog(std::string &&logLine)
std::optional< TimePoint > _idleSince
ProvideQueue(ProvidePrivate &parent)
Definition: providequeue.cc:44
ProvidePrivate & _parent
Process::Ptr _workerProc
bool startup(const std::string &workerScheme, const zypp::Pathname &workDir, const std::string &hostname="")
Definition: providequeue.cc:57
zypp::proto::Capabilities Config
SignalProxy< void()> sigIdle()
std::shared_ptr< RpcMessageStream > RpcMessageStreamPtr
Definition: provide_p.h:47
zypp::Pathname _currentExe
void fatalWorkerError(const std::exception_ptr &reason=nullptr)
std::list< ProvideQueue::Item >::iterator cancelActiveItem(std::list< Item >::iterator i, const std::exception_ptr &error)
void detach(const std::string &id)
uint requestCount() const
std::deque< Item > _waitQueue
void processReadyRead(int channel)
const std::string & hostname() const