libzypp 17.37.10

zyppng::EventDispatcher Class Reference

`#include <zypp-core/zyppng/base/eventdispatcher.h>`

Inheritance diagram for zyppng::EventDispatcher:

## Public Types
using | Ptr = std::shared_ptr<EventDispatcher>
using | WeakPtr = std::shared_ptr<EventDispatcher>
using | IdleFunction = std::function<bool ()>
using | WaitPidCallback = std::function<void(int, int)>
Public Types inherited from zyppng::Base
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
| ~EventDispatcher () override
virtual bool | run_once ()
void | clearUnrefLaterList ()
ulong | runningTimers () const
void * | nativeDispatcherHandle () const
| Returns the native dispatcher handle if the used implementation supports it.
void | trackChildProcess (int pid, std::function< void(int, int)> callback)
bool | untrackChildProcess (int pid)
UnixSignalSourceRef | unixSignalSource ()
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)

## Static Public Member Functions
template<typename T = IdleFunction>
static void | invokeOnIdle (T &&callback)
| Convenience function to schedule a callback to be called later.
template<typename T>
static void | unrefLater (T &&ptr)
static std::shared_ptr< EventDispatcher > | instance ()
static void | setThreadDispatcher (const std::shared_ptr< EventDispatcher > &disp)
static bool | waitForFdEvent (const int fd, int events, int &revents, int &timeout)
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)

## Protected Member Functions
| EventDispatcher (void *ctx=nullptr)
void | unrefLaterImpl (std::shared_ptr< void > &&ptr)
void | invokeOnIdleImpl (IdleFunction &&callback)
virtual void | updateEventSource (AbstractEventSource &notifier, int fd, int mode)
virtual void | removeEventSource (AbstractEventSource &notifier, int fd=-1)
virtual void | registerTimer (Timer &timer)
virtual void | removeTimer (Timer &timer)
Protected Member Functions inherited from zyppng::Base
| Base (BasePrivate &dd)

## Friends
class | AbstractEventSource
class | Timer

## Additional Inherited Members
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivate > | d_ptr

## Detailed Description

The EventDispatcher class implements the libzypp event loop native backend.

Libzypp is using a thread local dispatcher, which means each thread has its own unique disptacher. The only special case is when we need to work together with an already exisiting event loop, for example in a Qt application. The default implementation however uses the glib eventloop, just like Qt and GTK, so integrating libzypp here is just a matter of passing the default main context to the constructor of EventDispatcher.

Definition at line 41 of file eventdispatcher.h.

## Member Typedef Documentation

## ◆ Ptr

using zyppng::EventDispatcher::Ptr = std::shared_ptr<EventDispatcher>

Definition at line 49 of file eventdispatcher.h.

## ◆ WeakPtr

using zyppng::EventDispatcher::WeakPtr = std::shared_ptr<EventDispatcher>

Definition at line 50 of file eventdispatcher.h.

## ◆ IdleFunction

using zyppng::EventDispatcher::IdleFunction = std::function<bool ()>

Definition at line 51 of file eventdispatcher.h.

## ◆ WaitPidCallback

using zyppng::EventDispatcher::WaitPidCallback = std::function<void(int, int)>

Definition at line 131 of file eventdispatcher.h.

## Constructor & Destructor Documentation

## ◆ ~EventDispatcher()

zyppng::EventDispatcher::~EventDispatcher | ( |  | ) |
| override

Definition at line 373 of file eventdispatcher_glib.cc.

## ◆ EventDispatcher()

zyppng::EventDispatcher::EventDispatcher | ( | void * | ctx = nullptr | ) |
| protected

Create a new instance of the EventDispatcher, if ctx is given it is used as the new context for the eventloop

Definition at line 368 of file eventdispatcher_glib.cc.

## Member Function Documentation

## ◆ run_once()

bool zyppng::EventDispatcher::run_once | ( |  | ) |
| virtual

Enters the eventloop once and dequeues all pending events, once the event queue is empty the function returns

Definition at line 566 of file eventdispatcher_glib.cc.

## ◆ invokeOnIdle()

template<typename T = IdleFunction>

void zyppng::EventDispatcher::invokeOnIdle | ( | T && | callback | ) |
| inline static

Convenience function to schedule a callback to be called later.

Parameters

  callback | a std::function that is called after all other events have been processed

Definition at line 67 of file eventdispatcher.h.

## ◆ unrefLater()

template<typename T>

void zyppng::EventDispatcher::unrefLater | ( | T && | ptr | ) |
| inline static

Schedules a

See also
  std::shared_ptr to be unreferenced in the next idle phase of the event loop.

In some cases it might be required to delay the cleanup of a ressource until the current event loop iteration was finished, in case there are more pending events for the ressource.

Note
  Normally this should be handled by using correct shared_ptr semantics, and always owning a reference to a object were functions are called on. Only if that is not possible unrefLater should be used.

Definition at line 85 of file eventdispatcher.h.

## ◆ clearUnrefLaterList()

void zyppng::EventDispatcher::clearUnrefLaterList | ( |  | ) |

Immediately clears the list of all shared_ptr's that were registered to be unreferenced later. Mainly used to be called when a event loop exits, otherwise we might have weird side effects when the main loop instance preserves pointers that should be cleared at that point already. Like child items still trying to access the parent object that was already cleaned up before the MainLoop instance.

Definition at line 585 of file eventdispatcher_glib.cc.

## ◆ runningTimers()

ulong zyppng::EventDispatcher::runningTimers | ( |  | ) | const

Returns the number of the currently active timers

Definition at line 590 of file eventdispatcher_glib.cc.

## ◆ instance()

std::shared_ptr< EventDispatcher > zyppng::EventDispatcher::instance | ( |  | ) |
| static

Returns the EventDispatcher instance for the current thread.

Definition at line 595 of file eventdispatcher_glib.cc.

## ◆ setThreadDispatcher()

void zyppng::EventDispatcher::setThreadDispatcher | ( | const std::shared_ptr< EventDispatcher > & | disp | ) |
| static

Registers the given event dispatcher as the default for the current thread. The reference count for the shared pointer will not be increased, so the application is responsible to keep it until the application exits.

Note
  This must be called before the default dispatcher is registered, otherwise its ignored.

Definition at line 600 of file eventdispatcher_glib.cc.

## ◆ nativeDispatcherHandle()

void * zyppng::EventDispatcher::nativeDispatcherHandle | ( |  | ) | const

Returns the native dispatcher handle if the used implementation supports it.

Note
  the glib backend will return the used glib GMainContext

Definition at line 488 of file eventdispatcher_glib.cc.

## ◆ waitForFdEvent()

bool zyppng::EventDispatcher::waitForFdEvent | ( | const int | fd,
|  | int | events,
|  | int & | revents,
|  | int & | timeout )
| static

Waits until one of the requested events in events happens on the file descriptor. Use AbstractEventSource::EventTypes to define for which events should be polled. Returns true on success, revents will contain the bitwise combination of AbstractEventSource::EventTypes that triggered the wakeup.

Definition at line 493 of file eventdispatcher_glib.cc.

## ◆ trackChildProcess()

void zyppng::EventDispatcher::trackChildProcess | ( | int | pid,
|  | std::function< void(int, int)> | callback )

Tracks a child process until its execution did end. Callback is called when the child exits, the callback arguments are pid and status

Definition at line 531 of file eventdispatcher_glib.cc.

## ◆ untrackChildProcess()

bool zyppng::EventDispatcher::untrackChildProcess | ( | int | pid | ) |

Removes a child process from the internal sources, the process will not be reaped anymore if it is still running!

Returns
  true if the pid was removed

Definition at line 542 of file eventdispatcher_glib.cc.

## ◆ unixSignalSource()

UnixSignalSourceRef zyppng::EventDispatcher::unixSignalSource | ( |  | ) |

Returns the currently active UnixSignalSource for this EventDispatcher. It is required to keep the reference alive as long as signals need to be catched.

Definition at line 553 of file eventdispatcher_glib.cc.

## ◆ unrefLaterImpl()

void zyppng::EventDispatcher::unrefLaterImpl | ( | std::shared_ptr< void > && | ptr | ) |
| protected

See also
  unrefLater

Definition at line 578 of file eventdispatcher_glib.cc.

## ◆ invokeOnIdleImpl()

void zyppng::EventDispatcher::invokeOnIdleImpl | ( | EventDispatcher::IdleFunction && | callback | ) |
| protected

See also
  invokeOnIdle

Definition at line 571 of file eventdispatcher_glib.cc.

## ◆ updateEventSource()

void zyppng::EventDispatcher::updateEventSource | ( | AbstractEventSource & | notifier,
|  | int | fd,
|  | int | mode )
| protected virtual

Updates or registeres a event source in the event loop

Parameters

  notifier | The event source implementation that should receive the event notification
  fd | The file descriptor that is added to the internal watchlist
  mode | The watch mode for the given file desriptor

See also
  zyppng::AbstractEventSource::EventTypes

Definition at line 377 of file eventdispatcher_glib.cc.

## ◆ removeEventSource()

void zyppng::EventDispatcher::removeEventSource | ( | zyppng::AbstractEventSource & | notifier,
|  | int | fd = -1 )
| protected virtual

Removes a file descriptor from the internal watchlist, if fd is set to -1 all file descriptors associated with the

See also
  AbstractEventSource are removed

Parameters

  notifier | The

See also
  AbstractEventSource parent of the file descriptor

Parameters

  fd | The file descriptor to be removed, set to -1 to remove all descriptors for a

See also
  AbstractEventSource

Definition at line 419 of file eventdispatcher_glib.cc.

## ◆ registerTimer()

void zyppng::EventDispatcher::registerTimer | ( | Timer & | timer | ) |
| protected virtual

Adds a new Timer instance to the internal timer list

Definition at line 458 of file eventdispatcher_glib.cc.

## ◆ removeTimer()

void zyppng::EventDispatcher::removeTimer | ( | Timer & | timer | ) |
| protected virtual

Removes a timer from the internal timer list, once a Timer is removed it does not fire anymore

Definition at line 474 of file eventdispatcher_glib.cc.

## Friends And Related Symbol Documentation

## ◆ AbstractEventSource

friend class AbstractEventSource
| friend

Definition at line 44 of file eventdispatcher.h.

## ◆ Timer

friend class Timer
| friend

Definition at line 45 of file eventdispatcher.h.

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

- zypp-core/zyppng/base/eventdispatcher.h
- zypp-core/zyppng/base/eventdispatcher_glib.cc