libzypp  17.35.16
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 "providemessage_p.h"
19 #include <zypp-media/ng/Provide>
20 #include <zypp-core/zyppng/io/Process>
21 #include <zypp-core/ByteCount.h>
22 
23 #include <deque>
24 #include <chrono>
25 
26 namespace zyppng {
27 
28  ZYPP_FWD_DECL_TYPE_WITH_REFS (StompFrameStream);
29 
30  class ProvideQueue : public Base
31  {
32  public:
33  friend struct ProvideResourceData;
34 
35  static constexpr uint32_t InvalidId = (uint32_t) -1;
37 
38  using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
39 
40  struct Item {
41 
42  enum State {
48  };
50  bool isAttachRequest () const;
51  bool isFileRequest () const;
52  bool isDetachRequest() const;
53 
54  ProvideRequestRef _request;
55  };
56 
58  ~ProvideQueue();
59  bool startup ( const std::string &workerScheme, const zypp::Pathname &workDir, const std::string &hostname = "" );
60  void enqueue ( ProvideRequestRef request );
61  void cancel ( ProvideRequest *item, std::exception_ptr error );
62  void detach ( const std::string &id );
63  void scheduleNext ();
64  bool canScheduleMore () const;
65  bool empty () const;
66 
70  bool isIdle () const;
71 
75  std::optional<TimePoint> idleSince () const;
76 
80  uint requestCount () const;
81 
85  uint activeRequests () const;
86 
93 
98  const std::string &hostname () const;
99 
100  const Config &workerConfig () const;
101 
103 
104  private:
105  bool doStartup ();
106  void processMessage ( );
107  void readAllStderr ();
108  void forwardToLog ( std::string &&logLine );
109  void processReadyRead( int channel );
110  void procFinished ( int exitCode );
111  uint32_t nextRequestId();
112 
117  std::list< ProvideQueue::Item >::iterator dequeueActive ( std::list<Item>::iterator it );
118  void fatalWorkerError ( const std::exception_ptr &reason = nullptr );
119  void immediateShutdown ( const std::exception_ptr &reason );
120 
124  std::list< ProvideQueue::Item >::iterator cancelActiveItem (std::list<Item>::iterator i, const std::exception_ptr &error );
125 
126  private:
127  bool _queueShuttingDown = false;
128  uint8_t _crashCounter = 0;
131  std::string _myHostname;
133  std::deque< Item > _waitQueue;
134  std::list< Item > _activeItems;
136  StompFrameStreamRef _messageStream;
138  std::optional<TimePoint> _idleSince;
139  };
140 
141 }
142 
143 #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:31
void enqueue(ProvideRequestRef request)
Definition: providequeue.cc:96
std::chrono::time_point< std::chrono::steady_clock > TimePoint
bool canScheduleMore() const
std::optional< TimePoint > idleSince() const
StompFrameStreamRef _messageStream
static constexpr uint32_t InvalidId
ProvideRequestRef _request
Signal< void()> _sigIdle
void cancel(ProvideRequest *item, std::exception_ptr error)
WeakPtr parent() const
Definition: base.cc:26
uint32_t nextRequestId()
ZYPP_FWD_DECL_TYPE_WITH_REFS(Context)
zypp::ByteCount expectedProvideSize() const
void immediateShutdown(const std::exception_ptr &reason)
uint activeRequests() const
zyppng::WorkerCaps WorkerCaps
Definition: provideworker.h:29
const Config & workerConfig() const
void procFinished(int exitCode)
void forwardToLog(std::string &&logLine)
std::optional< TimePoint > _idleSince
ProvideQueue(ProvidePrivate &parent)
Definition: providequeue.cc:48
ProvidePrivate & _parent
ProcessRef Ptr
Definition: process.h:39
Process::Ptr _workerProc
bool startup(const std::string &workerScheme, const zypp::Pathname &workDir, const std::string &hostname="")
Definition: providequeue.cc:61
SignalProxy< void()> sigIdle()
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