libzypp 17.34.0
|
#include <zypp-core/zyppng/base/eventdispatcher.h>
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)> |
![]() | |
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 () |
![]() | |
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 | |
EventDispatcher (void *ctx=nullptr) | |
void | unrefLaterImpl (std::shared_ptr< void > &&ptr) |
void | invokeOnIdleImpl (IdleFunction &&callback) |
virtual void | updateEventSource (AbstractEventSource ¬ifier, int fd, int mode) |
virtual void | removeEventSource (AbstractEventSource ¬ifier, int fd=-1) |
virtual void | registerTimer (Timer &timer) |
virtual void | removeTimer (Timer &timer) |
![]() | |
Base (BasePrivate &dd) | |
Friends | |
class | AbstractEventSource |
class | Timer |
Additional Inherited Members | |
![]() | |
std::unique_ptr< BasePrivate > | d_ptr |
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.
using zyppng::EventDispatcher::Ptr = std::shared_ptr<EventDispatcher> |
Definition at line 49 of file eventdispatcher.h.
using zyppng::EventDispatcher::WeakPtr = std::shared_ptr<EventDispatcher> |
Definition at line 50 of file eventdispatcher.h.
using zyppng::EventDispatcher::IdleFunction = std::function<bool ()> |
Definition at line 51 of file eventdispatcher.h.
using zyppng::EventDispatcher::WaitPidCallback = std::function<void(int, int)> |
Definition at line 131 of file eventdispatcher.h.
|
override |
Definition at line 372 of file eventdispatcher_glib.cc.
Create a new instance of the EventDispatcher, if ctx is given it is used as the new context for the eventloop
Definition at line 367 of file eventdispatcher_glib.cc.
|
virtual |
Enters the eventloop once and dequeues all pending events, once the event queue is empty the function returns
Definition at line 568 of file eventdispatcher_glib.cc.
|
inlinestatic |
Convenience function to schedule a callback to be called later.
callback | a std::function that is called after all other events have been processed |
Definition at line 67 of file eventdispatcher.h.
Schedules a
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.
Definition at line 85 of file eventdispatcher.h.
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 587 of file eventdispatcher_glib.cc.
ulong zyppng::EventDispatcher::runningTimers | ( | ) | const |
Returns the number of the currently active timers
Definition at line 592 of file eventdispatcher_glib.cc.
|
static |
Returns the EventDispatcher instance for the current thread.
Definition at line 597 of file eventdispatcher_glib.cc.
|
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.
Definition at line 602 of file eventdispatcher_glib.cc.
void * zyppng::EventDispatcher::nativeDispatcherHandle | ( | ) | const |
Returns the native dispatcher handle if the used implementation supports it.
Definition at line 487 of file eventdispatcher_glib.cc.
|
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 492 of file eventdispatcher_glib.cc.
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 533 of file eventdispatcher_glib.cc.
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!
Definition at line 544 of file eventdispatcher_glib.cc.
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 555 of file eventdispatcher_glib.cc.
Definition at line 580 of file eventdispatcher_glib.cc.
|
protected |
Definition at line 573 of file eventdispatcher_glib.cc.
|
protectedvirtual |
Updates or registeres a event source in the event loop
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 |
Definition at line 376 of file eventdispatcher_glib.cc.
|
protectedvirtual |
Removes a file descriptor from the internal watchlist, if fd is set to -1 all file descriptors associated with the
notifier | The |
fd | The file descriptor to be removed, set to -1 to remove all descriptors for a |
Definition at line 418 of file eventdispatcher_glib.cc.
Adds a new Timer instance to the internal timer list
Definition at line 457 of file eventdispatcher_glib.cc.
Removes a timer from the internal timer list, once a Timer is removed it does not fire anymore
Definition at line 473 of file eventdispatcher_glib.cc.
|
friend |
Definition at line 44 of file eventdispatcher.h.
Definition at line 45 of file eventdispatcher.h.