libzypp: zyppng::ProvideItem Class Reference

libzypp 17.36.6

Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
zyppng::ProvideItem Class Referenceabstract

`#include <zypp-media/ng/provideitem.h>`

Inheritance diagram for zyppng::ProvideItem:

## Classes
struct | ItemStats

## Public Types
enum | State { Uninitialized , Pending , Downloading , Processing , Cancelling , Finalizing , Finished }
Public Types inherited from zyppng::Base
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
| ProvideItem (ProvidePrivate &parent)
| ~ProvideItem ()
virtual void | initialize ()=0
virtual void | released ()
State | state () const
SignalProxy< void(ProvideItem &item, State oldState, State newState)> | sigStateChanged ()
ProvidePrivate & | provider ()
virtual bool | canRedirectTo (ProvideRequestRef startedReq, const zypp::Url &url)
const std::optional< ItemStats > & | currentStats () const
const std::optional< ItemStats > & | previousStats () const
virtual std::chrono::steady_clock::time_point | startTime () const
virtual std::chrono::steady_clock::time_point | finishedTime () const
void | pulse ()
virtual zypp::ByteCount | bytesExpected () const
Public Member Functions inherited from zyppng::Base
| Base ()
virtual | ~Base ()
WeakPtr | parent () const
void | addChild (const Base::Ptr &child)
void | removeChild (const Ptr &child)
const std::unordered_set< Ptr > & | children () const
std::thread::id | threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > | findChildren () const
template<typename T>
std::shared_ptr< T > | shared_this () const
template<typename T>
std::shared_ptr< T > | shared_this ()
template<typename T>
std::weak_ptr< T > | weak_this () const
template<typename T>
std::weak_ptr< T > | weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Protected Member Functions
virtual ItemStats | makeStats ()
virtual void | informalMessage (ProvideQueue &, ProvideRequestRef req, const ProvideMessage &msg)
virtual void | cacheMiss (ProvideRequestRef req)
virtual void | finishReq (ProvideQueue &queue, ProvideRequestRef finishedReq, const ProvideMessage &msg)
virtual void | finishReq (ProvideQueue *queue, ProvideRequestRef finishedReq, const std::exception_ptr excpt)
virtual expected< zypp::media::AuthData > | authenticationRequired (ProvideQueue &queue, ProvideRequestRef req, const zypp::Url &effectiveUrl, int64_t lastTimestamp, const std::map< std::string, std::string > &extraFields)
bool | safeRedirectTo (ProvideRequestRef startedReq, const zypp::Url &url)
void | redirectTo (ProvideRequestRef startedReq, const zypp::Url &url)
virtual bool | enqueueRequest (ProvideRequestRef request)
virtual void | cancelWithError (std::exception_ptr error)=0
bool | dequeue ()
void | updateState (const State newState)
void | setFinished ()
Protected Member Functions inherited from zyppng::Base
| Base (BasePrivate &dd)

## Protected Attributes
ProvideRequestRef | _runningReq
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivate > | d_ptr

## Friends
class | Provide
class | ProvidePrivate
class | ProvideQueue

## Additional Inherited Members
Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) | make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Detailed Description

Represents a operation added to the provide queue by the user code. A "user" operation can have multiple steps of downloading and processing one or multiple files. Even though this class is in public API space it's not possible to implement custom Items since more internal API would be required for it. It is only public to support the ProvideStatus class, so it can query details of a Item.

Definition at line 28 of file provideitem.h.

## Member Enumeration Documentation

## ◆ State

enum zyppng::ProvideItem::State

Enumerator
Uninitialized |
Pending |
Downloading |
Processing |
Cancelling |
Finalizing |
Finished |

Definition at line 35 of file provideitem.h.

## Constructor & Destructor Documentation

## ◆ ProvideItem()

zyppng::ProvideItem::ProvideItem | ( | ProvidePrivate & | parent | ) |

Definition at line 83 of file provideitem.cc.

## ◆ ~ProvideItem()

zyppng::ProvideItem::~ProvideItem | ( |  | ) |

Definition at line 87 of file provideitem.cc.

## Member Function Documentation

## ◆ initialize()

virtual void zyppng::ProvideItem::initialize | ( |  | ) |
| pure virtual

Called by the controller when the item is supposed to start fetching / processing

Implemented in zyppng::AttachMediaItem, and zyppng::ProvideFileItem.

## ◆ released()

void zyppng::ProvideItem::released | ( |  | ) |
| virtual

Called when the promise reference is released by the user process, cancel all running requests if there are any and clean up

Definition at line 486 of file provideitem.cc.

## ◆ state()

ProvideItem::State zyppng::ProvideItem::state | ( |  | ) | const

Definition at line 495 of file provideitem.cc.

## ◆ sigStateChanged()

SignalProxy< void(ProvideItem &item, State oldState, State newState)> zyppng::ProvideItem::sigStateChanged | ( |  | ) |

Signal that is emitted when the state of the Item has changed

## ◆ provider()

ProvidePrivate & zyppng::ProvideItem::provider | ( |  | ) |

Definition at line 90 of file provideitem.cc.

## ◆ canRedirectTo()

bool zyppng::ProvideItem::canRedirectTo | ( | ProvideRequestRef | startedReq,
|  | const zypp::Url & | url )
| virtual

Returns true if a redirect is allowed and does not conflict with previous redirects. Otherwise false is returned. This does not remember the passed URL as a redirect

Definition at line 110 of file provideitem.cc.

## ◆ currentStats()

const std::optional< ProvideItem::ItemStats > & zyppng::ProvideItem::currentStats | ( |  | ) | const

Returns the item statistics that were collected the last time pulse() was called on the item. If the item has not been started yet, this returns a empty optional

Definition at line 122 of file provideitem.cc.

## ◆ previousStats()

const std::optional< ProvideItem::ItemStats > & zyppng::ProvideItem::previousStats | ( |  | ) | const

Returns the item statistics that were collected the previous time pulse() was called on the item.

Note
  The item needs to be started and pulse() needs to be called at least once for this func to return something

Definition at line 127 of file provideitem.cc.

## ◆ startTime()

std::chrono::steady_clock::time_point zyppng::ProvideItem::startTime | ( |  | ) | const
| virtual

Returns the time point when the item started to process/download. If the item has not started yet, this returns epoch

Definition at line 132 of file provideitem.cc.

## ◆ finishedTime()

std::chrono::steady_clock::time_point zyppng::ProvideItem::finishedTime | ( |  | ) | const
| virtual

Returns the time point when the item was finished. If the item was not finished yet, this returns epoch

Definition at line 137 of file provideitem.cc.

## ◆ pulse()

void zyppng::ProvideItem::pulse | ( |  | ) |

Updates the item statistics, this is called automatically by the Provide instance and usually does not need to be called explicitely by usercode.

Definition at line 141 of file provideitem.cc.

## ◆ bytesExpected()

zypp::ByteCount zyppng::ProvideItem::bytesExpected | ( |  | ) | const
| virtual

Returns the bytes the item expects to provide, the default impl returns 0

Reimplemented in zyppng::ProvideFileItem.

Definition at line 154 of file provideitem.cc.

## ◆ makeStats()

ProvideItem::ItemStats zyppng::ProvideItem::makeStats | ( |  | ) |
| protectedvirtual

Reimplemented in zyppng::ProvideFileItem.

Definition at line 159 of file provideitem.cc.

## ◆ informalMessage()

void zyppng::ProvideItem::informalMessage | ( | ProvideQueue & | ,
|  | ProvideRequestRef | req,
|  | const ProvideMessage & | msg )
| protectedvirtual

Request received a informal message, e.g. ProvideStarted

Reimplemented in zyppng::ProvideFileItem.

Definition at line 167 of file provideitem.cc.

## ◆ cacheMiss()

void zyppng::ProvideItem::cacheMiss | ( | ProvideRequestRef | req | ) |
| protectedvirtual

Request had a cache miss and will be queued again, forget all about the request

Definition at line 180 of file provideitem.cc.

## ◆ finishReq() [1/2]

void zyppng::ProvideItem::finishReq | ( | ProvideQueue & | queue,
|  | ProvideRequestRef | finishedReq,
|  | const ProvideMessage & | msg )
| protectedvirtual

Request was finished by the queue Base implementation handles redirect, metalink and error messages. If a different message is received, cancelWithError is called.

A subclass has to overload this function to handle success messages

Reimplemented in zyppng::AttachMediaItem, and zyppng::ProvideFileItem.

Definition at line 190 of file provideitem.cc.

## ◆ finishReq() [2/2]

void zyppng::ProvideItem::finishReq | ( | ProvideQueue * | queue,
|  | ProvideRequestRef | finishedReq,
|  | const std::exception_ptr | excpt )
| protectedvirtual

Request was finished with a error The base implementation simply calls cancelWithError

Note
  queue is allowed to be a nullptr here

Reimplemented in zyppng::AttachMediaItem, and zyppng::ProvideFileItem.

Definition at line 383 of file provideitem.cc.

## ◆ authenticationRequired()

expected< zypp::media::AuthData > zyppng::ProvideItem::authenticationRequired | ( | ProvideQueue & | queue,
|  | ProvideRequestRef | req,
|  | const zypp::Url & | effectiveUrl,
|  | int64_t | lastTimestamp,
|  | const std::map< std::string, std::string > & | extraFields )
| protectedvirtual

Request needs authentication data, the function is supposed to return the AuthData to use for the response, or an error The default implementation simply uses the given URL to look for a Auth match in the zypp::media::CredentialManager.

Reimplemented in zyppng::AttachMediaItem, and zyppng::ProvideFileItem.

Definition at line 399 of file provideitem.cc.

## ◆ safeRedirectTo()

bool zyppng::ProvideItem::safeRedirectTo | ( | ProvideRequestRef | startedReq,
|  | const zypp::Url & | url )
| protected

Remembers previous redirects and returns false if the URL was encountered before, use this to prevent the item getting caught in a redirect loop

Definition at line 95 of file provideitem.cc.

## ◆ redirectTo()

void zyppng::ProvideItem::redirectTo | ( | ProvideRequestRef | startedReq,
|  | const zypp::Url & | url )
| protected

Similar to safeRedirectTo, but does not check if a URL was already used by this Request before.

Definition at line 104 of file provideitem.cc.

## ◆ enqueueRequest()

bool zyppng::ProvideItem::enqueueRequest | ( | ProvideRequestRef | request | ) |
| protectedvirtual

Enqueue the request in the correct queue, the item implementation is supposed to hold its own reference to all started requests, the base implementation just keeps track of 1 request at a time.

Definition at line 448 of file provideitem.cc.

## ◆ cancelWithError()

virtual void zyppng::ProvideItem::cancelWithError | ( | std::exception_ptr | error | ) |
| protectedpure virtual

Cancels all running requests and immediately moves to error state

Implemented in zyppng::AttachMediaItem, and zyppng::ProvideFileItem.

## ◆ dequeue()

bool zyppng::ProvideItem::dequeue | ( |  | ) |
| protected

Dequeue this item and stop all requests in queues running Call this when the item is cancelled or finished.

## ◆ updateState()

void zyppng::ProvideItem::updateState | ( | const State | newState | ) |
| protected

Call this when the state of the item changes.

Note
  calling updateState with state Finished will potentially delete the Item instance

Definition at line 458 of file provideitem.cc.

## ◆ setFinished()

void zyppng::ProvideItem::setFinished | ( |  | ) |
| protected

## Friends And Related Symbol Documentation

## ◆ Provide

friend class Provide
| friend

Definition at line 31 of file provideitem.h.

## ◆ ProvidePrivate

friend class ProvidePrivate
| friend

Definition at line 32 of file provideitem.h.

## ◆ ProvideQueue

friend class ProvideQueue
| friend

Definition at line 33 of file provideitem.h.

## Member Data Documentation

## ◆ _runningReq

ProvideRequestRef zyppng::ProvideItem::_runningReq
| protected

Definition at line 189 of file provideitem.h.

The documentation for this class was generated from the following files:

- zypp-media/ng/provideitem.h
- zypp-media/ng/provideitem.cc