libzypp 17.37.10

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;
36 using Config = zyppng::WorkerCaps;
37
38 using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
39
40 struct Item {
41
42 enum State {
43 Pending,
44 Queued,
45 Running,
46 Cancelling,
47 Finished
48 };
49 State _state = Pending;
50 bool isAttachRequest () const;
51 bool isFileRequest () const;
52 bool isDetachRequest() const;
53
54 ProvideRequestRef _request;
55 };
56
57 ProvideQueue( ProvidePrivate &parent );
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
92 zypp::ByteCount expectedProvideSize() const;
93
98 const std::string &hostname () const;
99
100 const Config &workerConfig () const;
101
102 SignalProxy<void()> sigIdle();
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;
129 Config _capabilities;
130 zypp::Pathname _currentExe;
131 std::string _myHostname;
132 ProvidePrivate &_parent;
133 std::deque< Item > _waitQueue;
134 std::list< Item > _activeItems;
135 Process::Ptr _workerProc;
136 StompFrameStreamRef _messageStream;
137 Signal<void()> _sigIdle;
138 std::optional<TimePoint> _idleSince;
139 };
140
141}
142
143#endif
zypp::ByteCount
Store and operate with byte count.
Definition ByteCount.h:32
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zyppng::Base::parent
WeakPtr parent() const
Definition base.cc:26
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::Process::Ptr
ProcessRef Ptr
Definition process.h:39
zyppng::ProvidePrivate
Definition provide_p.h:42
zyppng::ProvideQueue::empty
bool empty() const
Definition providequeue.cc:264
zyppng::ProvideQueue::TimePoint
std::chrono::time_point< std::chrono::steady_clock > TimePoint
Definition providequeue_p.h:38
zyppng::ProvideQueue::cancelActiveItem
std::list< ProvideQueue::Item >::iterator cancelActiveItem(std::list< Item >::iterator i, const std::exception_ptr &error)
Definition providequeue.cc:184
zyppng::ProvideQueue::expectedProvideSize
zypp::ByteCount expectedProvideSize() const
Definition providequeue.cc:279
zyppng::ProvideQueue::_workerProc
Process::Ptr _workerProc
Definition providequeue_p.h:135
zyppng::ProvideQueue::ProvideQueue
ProvideQueue(ProvidePrivate &parent)
Definition providequeue.cc:48
zyppng::ProvideQueue::_myHostname
std::string _myHostname
Definition providequeue_p.h:131
zyppng::ProvideQueue::_messageStream
StompFrameStreamRef _messageStream
Definition providequeue_p.h:136
zyppng::ProvideQueue::immediateShutdown
void immediateShutdown(const std::exception_ptr &reason)
Definition providequeue.cc:155
zyppng::ProvideQueue::_waitQueue
std::deque< Item > _waitQueue
Definition providequeue_p.h:133
zyppng::ProvideQueue::cancel
void cancel(ProvideRequest *item, std::exception_ptr error)
Definition providequeue.cc:107
zyppng::ProvideQueue::requestCount
uint requestCount() const
Definition providequeue.cc:269
zyppng::ProvideQueue::_currentExe
zypp::Pathname _currentExe
Definition providequeue_p.h:130
zyppng::ProvideQueue::_sigIdle
Signal< void()> _sigIdle
Definition providequeue_p.h:137
zyppng::ProvideQueue::canScheduleMore
bool canScheduleMore() const
Definition providequeue.cc:249
zyppng::ProvideQueue::_queueShuttingDown
bool _queueShuttingDown
Definition providequeue_p.h:127
zyppng::ProvideQueue::doStartup
bool doStartup()
Definition providequeue.cc:317
zyppng::ProvideQueue::processReadyRead
void processReadyRead(int channel)
Definition providequeue.cc:733
zyppng::ProvideQueue::hostname
const std::string & hostname() const
Definition providequeue.cc:302
zyppng::ProvideQueue::readAllStderr
void readAllStderr()
Definition providequeue.cc:715
zyppng::ProvideQueue::_idleSince
std::optional< TimePoint > _idleSince
Definition providequeue_p.h:138
zyppng::ProvideQueue::scheduleNext
void scheduleNext()
Definition providequeue.cc:213
zyppng::ProvideQueue::_parent
ProvidePrivate & _parent
Definition providequeue_p.h:132
zyppng::ProvideQueue::startup
bool startup(const std::string &workerScheme, const zypp::Pathname &workDir, const std::string &hostname="")
Definition providequeue.cc:61
zyppng::ProvideQueue::workerConfig
const Config & workerConfig() const
Definition providequeue.cc:307
zyppng::ProvideQueue::idleSince
std::optional< TimePoint > idleSince() const
Definition providequeue.cc:259
zyppng::ProvideQueue::ProvideResourceData
friend struct ProvideResourceData
Definition providequeue_p.h:33
zyppng::ProvideQueue::nextRequestId
uint32_t nextRequestId()
Definition providequeue.cc:781
zyppng::ProvideQueue::~ProvideQueue
~ProvideQueue()
Definition providequeue.cc:51
zyppng::ProvideQueue::Config
zyppng::WorkerCaps Config
Definition providequeue_p.h:36
zyppng::ProvideQueue::procFinished
void procFinished(int exitCode)
Definition providequeue.cc:749
zyppng::ProvideQueue::activeRequests
uint activeRequests() const
Definition providequeue.cc:274
zyppng::ProvideQueue::_activeItems
std::list< Item > _activeItems
Definition providequeue_p.h:134
zyppng::ProvideQueue::forwardToLog
void forwardToLog(std::string &&logLine)
Definition providequeue.cc:725
zyppng::ProvideQueue::enqueue
void enqueue(ProvideRequestRef request)
Definition providequeue.cc:96
zyppng::ProvideQueue::sigIdle
SignalProxy< void()> sigIdle()
Definition providequeue.cc:312
zyppng::ProvideQueue::isIdle
bool isIdle() const
Definition providequeue.cc:254
zyppng::ProvideQueue::detach
void detach(const std::string &id)
zyppng::ProvideQueue::dequeueActive
std::list< ProvideQueue::Item >::iterator dequeueActive(std::list< Item >::iterator it)
Definition providequeue.cc:136
zyppng::ProvideQueue::_crashCounter
uint8_t _crashCounter
Definition providequeue_p.h:128
zyppng::ProvideQueue::_capabilities
Config _capabilities
Definition providequeue_p.h:129
zyppng::ProvideQueue::fatalWorkerError
void fatalWorkerError(const std::exception_ptr &reason=nullptr)
Definition providequeue.cc:150
zyppng::ProvideQueue::processMessage
void processMessage()
Definition providequeue.cc:387
zyppng::ProvideQueue::InvalidId
static constexpr uint32_t InvalidId
Definition providequeue_p.h:35
zyppng::ProvideRequest
Definition provideitem_p.h:36
zyppng::SignalProxy
Definition signals.h:325
zyppng::Signal
Definition signals.h:151
zyppng::StompFrameStream
Definition stompframestream.h:95
zyppng::WorkerCaps
Definition providemessage_p.h:376
zyppng
Definition MediaNetworkRequestExecutor.h:16
providefwd_p.h
providemessage_p.h
zyppng::ProvideQueue::Item
Definition providequeue_p.h:40
zyppng::ProvideQueue::Item::isDetachRequest
bool isDetachRequest() const
Definition providequeue.cc:41
zyppng::ProvideQueue::Item::State
State
Definition providequeue_p.h:42
zyppng::ProvideQueue::Item::Cancelling
@ Cancelling
Definition providequeue_p.h:46
zyppng::ProvideQueue::Item::Running
@ Running
Definition providequeue_p.h:45
zyppng::ProvideQueue::Item::Pending
@ Pending
Definition providequeue_p.h:43
zyppng::ProvideQueue::Item::Finished
@ Finished
Definition providequeue_p.h:47
zyppng::ProvideQueue::Item::Queued
@ Queued
Definition providequeue_p.h:44
zyppng::ProvideQueue::Item::_request
ProvideRequestRef _request
Definition providequeue_p.h:54
zyppng::ProvideQueue::Item::_state
State _state
Definition providequeue_p.h:49
zyppng::ProvideQueue::Item::isAttachRequest
bool isAttachRequest() const
Definition providequeue.cc:27
zyppng::ProvideQueue::Item::isFileRequest
bool isFileRequest() const
Definition providequeue.cc:34
ByteCount.h
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126