14#ifndef ZYPP_NG_BASE_SIGNALS_H_INCLUDED
15#define ZYPP_NG_BASE_SIGNALS_H_INCLUDED
18#include <sywu/signal.hpp>
20#include <sigc++/trackable.h>
21#include <sigc++/signal.h>
22#include <sigc++/connection.h>
23#include <sigc++/visit_each.h>
24#include <sigc++/adaptors/adaptors.h>
150 template <
class R,
class... T>
159 template <
class SignalHost,
typename ReturnType,
typename... Arguments>
168 template <
class R,
class... T>
171 template <
class R,
class... T>
172 class Signal<R(T...)> :
public sywu::Signal<R(T...)>
175 template <
class SignalHost,
typename ReturnType,
typename... Arguments>
176 class MemSignal<SignalHost, ReturnType(Arguments...)> :
public sywu::MemberSignal<SignalHost, ReturnType(Arguments...)>
182 using sigc::track_obj;
184 template <
class R,
class... T>
188 template <
class R,
class... T>
189 class Signal<R(T...)> :
public sigc::signal<R(T...)>
193 assert(this->impl()->exec_count_ == 0);
194 if ( this->impl()->exec_count_ > 0 ) {
195 WAR <<
"Deleting Signal during emission, this is usually a BUG, Slots will be blocked to prevent SIGSEGV." << std::endl;
196#ifdef LIBZYPP_USE_SIGC_BLOCK_WORKAROUND
210 template <
class SignalHost,
typename ReturnType,
typename... Arguments>
211 class MemSignal<SignalHost, ReturnType(Arguments...)> :
public sigc::signal<ReturnType(Arguments...)>
218 assert(this->impl()->exec_count_ == 0);
219 if ( this->impl()->exec_count_ > 0 ) {
220 WAR <<
"Deleting MemSignal during emission, this is definitely a BUG, Slots will be blocked to prevent SIGSEGV." << std::endl;
221#ifdef LIBZYPP_USE_SIGC_BLOCK_WORKAROUND
233 template<
typename... Args>
234 auto emit( Args&& ...arg )
const {
235 auto ref =
_host.shared_from_this();
236 return sigc::signal<ReturnType(Arguments...)>
::emit( std::forward<Args>(arg)...);
239 template<
typename... Args>
242 return sigc::signal<ReturnType(Arguments...)>::operator()( std::forward<Args>(arg)...);
255 template <
typename T>
259 return locker.z_func()->shared_from_this();
261 return locker.shared_from_this();
263 }
catch (
const std::bad_weak_ptr &e ) {
273 template <
typename T_functor,
typename ...Lockers>
276 template <
typename... Args>
277 decltype(
auto)
operator()( Args&&... args )
const {
280 auto __attribute__ ((__unused__)) lck = std::apply( [](
auto&... lockers ) {
287 if constexpr (
sizeof... (Args) == 0 ) {
288 return this->functor_();
290 return this->functor_.template operator()<
decltype ( std::forward<Args>(args) )...> ( std::forward<Args>(args)... );
292 }
catch (
const std::bad_weak_ptr &e ) {
294 ERR <<
"Ignoring signal emit due to a bad_weak_ptr exception during object locking. Maybe the signal was sent to a object that is currently destructing?" << std::endl;
298 if constexpr ( !std::is_same_v<void, typename sigc::adapts<T_functor>::result_type> )
299 return typename sigc::adapts<T_functor>::result_type{};
312 std::tuple<sigc::const_limit_reference<Lockers>...>
_lcks;
315 template<
typename Functor,
typename ...Obj >
316 inline decltype(
auto)
locking_fun(
const Functor &f,
const Obj&... o )
324 template <
class R,
class... T>
332 template <
class R,
class... T>
343 template <
typename... Args>
346 return _sig.connect( std::forward<Args>(slot)... );
360 template <
typename T_functor,
typename ...Lockers>
361 struct visitor<
zyppng::internal::lock_shared<T_functor, Lockers...> >
363 template <
typename T_action>
367 sigc::visit_each(action, target.functor_);
368 std::apply( [&](
auto&...
a) {
369 ((void)sigc::visit_each(action,
a),...);
auto emit(Args &&...arg) const
MemSignal(SignalHost &host)
auto operator()(Args &&...arg) const
SignalProxy(SignalType &sig)
connection connect(Args &&... slot)
Forwards the arguments to the internal connect function of the signal type.
SignalProxyBase< R, T... > SignalType
constexpr bool is_base_of_v
decltype(auto) locking_fun(const Functor &f, const Obj &... o)
auto lock_shared_makeLock(const T &locker)
sigc::trackable trackable
sigc::connection connection
sigc::signal< R(T...)> SignalProxyBase
static void do_visit_each(const T_action &action, const zyppng::internal::lock_shared< T_functor, Lockers... > &target)
std::tuple< sigc::const_limit_reference< Lockers >... > _lcks
lock_shared(const T_functor &functor, const Lockers &... lcks)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.