libzypp: zypp-core/zyppng/pipelines/await.h Source File

libzypp 17.36.6

await.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 ZYPPNG_MONADIC_AWAIT_H_INCLUDED
15#define ZYPPNG_MONADIC_AWAIT_H_INCLUDED
16
17
18#include <zypp-core/zyppng/pipelines/AsyncResult>
19#include <zypp-core/zyppng/base/Signals>
20
21namespace zyppng {
22
23 namespace detail
24 {
25 template <typename T, typename SigGetter> struct AwaitImpl;
26
27 template <typename ArgType, typename SigR, typename ...SigT >
28 struct AwaitImpl<ArgType, SignalProxy<SigR(SigT...)> (ArgType::*)()> : public zyppng::AsyncOp< std::shared_ptr<ArgType> > {
29
30 using SigGetter = SignalProxy<SigR(SigT...)> (ArgType::*)();
31
32 template<typename S>
33 AwaitImpl ( S&& sigGet ) : _sigGet( std::forward<S>(sigGet ) ) {}
34
35 virtual ~AwaitImpl(){ }
36
37 void operator() ( std::shared_ptr<ArgType> &&req ) {
38 _req = std::move(req);
39 std::invoke( _sigGet, _req ).connect( sigc::mem_fun(this, &AwaitImpl::sigHandler<SigR>) );
40 }
41
42 private:
43 template < typename RetType = SigR >
44 std::enable_if_t< std::is_same_v<void,RetType>, RetType >
45 sigHandler ( SigT... ) {
46 this->setReady( std::move(_req) );
47 }
48
49 template < typename RetType = SigR >
50 std::enable_if_t< !std::is_same_v<void,RetType>, RetType >
51 sigHandler ( SigT... ) {
52 this->setReady( std::move(_req) );
53 return {};
54 }
55
56 std::shared_ptr<ArgType> _req;
57 SigGetter _sigGet;
58 };
59 }
60
61 //return a async op that waits for a signal to emitted by a object
62 template <typename T,
63 typename SignalGetter >
64 auto await ( SignalGetter &&sigGet )
65 {
66 return std::make_shared<detail::AwaitImpl<T, SignalGetter>>( std::forward<SignalGetter>(sigGet) );
67 }
68
69}
70
71#endif
zypp::Arch::operator()
bool operator()(const zypp::Arch &lhs, const zypp::Arch &rhs) const
Default order for std::container based Arch::compare.
Definition Arch.h:370
zyppng::SignalProxy
Definition signals.h:325
std
Definition Arch.h:364
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
std::invoke
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition functional.h:32
zyppng::detail
Definition reporthelper.h:31
zyppng
Definition MediaCurl2.h:22
zyppng::await
auto await(SignalGetter &&sigGet)
Definition await.h:64
zyppng::AsyncOp
Definition asyncop.h:161
zyppng::AsyncOp< std::shared_ptr< ArgType > >::setReady
void setReady(value_type &&val)
Definition asyncop.h:183
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::_req
std::shared_ptr< ArgType > _req
Definition await.h:56
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::_sigGet
SigGetter _sigGet
Definition await.h:57
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::SigGetter
SignalProxy< SigR(SigT...)>(ArgType::*)() SigGetter
Definition await.h:30
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::sigHandler
std::enable_if_t< std::is_same_v< void, RetType >, RetType > sigHandler(SigT...)
Definition await.h:45
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::~AwaitImpl
virtual ~AwaitImpl()
Definition await.h:35
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::sigHandler
std::enable_if_t< !std::is_same_v< void, RetType >, RetType > sigHandler(SigT...)
Definition await.h:51
zyppng::detail::AwaitImpl< ArgType, SignalProxy< SigR(SigT...)>(ArgType::*)()>::AwaitImpl
AwaitImpl(S &&sigGet)
Definition await.h:33
zyppng::detail::AwaitImpl
Definition await.h:25