|
libzypp
17.22.0
|
#include <eventdispatcher.h>

Public Types | |
| using | Ptr = std::shared_ptr< EventDispatcher > |
| using | WeakPtr = std::shared_ptr< EventDispatcher > |
| using | IdleFunction = std::function< bool()> |
Public Types inherited from zyppng::Base | |
| using | Ptr = std::shared_ptr< Base > |
| using | WeakPtr = std::weak_ptr< Base > |
Public Member Functions | |
| virtual | ~EventDispatcher () |
| virtual bool | run_once () |
| virtual void | run () |
| virtual void | quit () |
| ulong | runningTimers () const |
Public Member Functions inherited from zyppng::Base | |
| Base () | |
| virtual | ~Base () |
| WeakPtr | parent () const |
| void | addChild (Base::Ptr child) |
| void | removeChild (Ptr child) |
| const std::unordered_set< Ptr > & | children () 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 () |
Static Public Member Functions | |
| static std::shared_ptr< EventDispatcher > | createMain () |
| static std::shared_ptr< EventDispatcher > | createForThread () |
| template<typename T = IdleFunction> | |
| static void | invokeOnIdle (T &&callback) |
| Convenience function to schedule a callback to be called later. More... | |
| template<typename T > | |
| static void | unrefLater (T &&ptr) |
| static std::shared_ptr< EventDispatcher > | instance () |
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 |
The EventDispatcher class implements the libzypp event loop.
A event loop is used to execute multiple tasks concurrently. This is not implemented using threads but usually by either using Timers to poll a ressource or by reacting on events from a file descriptor or socket. In a application like zypper where we heavily make use of I/O heavy tasks like downloading packages, rebuilding the repo metadata or generating a checksum over a file the application needs to wait more for those tasks to finish than actually doing anything. By using a event loop we can start one of those tasks and let the OS handle the execution and subscribe to certain events that can happen, utilizing more of the CPU compared to starting all the tasks serially.
Libzypp is using a thread local eventloop, means each thread needs to start its own loop. Only special case is when we need to work together with a 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 49 of file eventdispatcher.h.
| using zyppng::EventDispatcher::Ptr = std::shared_ptr<EventDispatcher> |
Definition at line 57 of file eventdispatcher.h.
| using zyppng::EventDispatcher::WeakPtr = std::shared_ptr<EventDispatcher> |
Definition at line 58 of file eventdispatcher.h.
| using zyppng::EventDispatcher::IdleFunction = std::function<bool ()> |
Definition at line 59 of file eventdispatcher.h.
|
virtual |
Definition at line 316 of file eventdispatcher_glib.cc.
|
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 300 of file eventdispatcher_glib.cc.
|
static |
Creates a new EventDispatcher, use this function to create a Dispatcher running on the default thread
Definition at line 306 of file eventdispatcher_glib.cc.
|
static |
Creates a new EventDispatcher, use this function to create a Dispatcher running on a threads aside the main thread
Definition at line 311 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 438 of file eventdispatcher_glib.cc.
|
virtual |
Start dispatching events, this function will block until
Definition at line 443 of file eventdispatcher_glib.cc.
|
virtual |
Stop dispatching events and return from the main loop.
Definition at line 448 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 103 of file eventdispatcher.h.
|
inlinestatic |
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 118 of file eventdispatcher.h.
| ulong zyppng::EventDispatcher::runningTimers | ( | ) | const |
Returns the number of the currently active timers
Definition at line 467 of file eventdispatcher_glib.cc.
|
static |
Returns the EventDispatcher instance for the current thread.
Definition at line 472 of file eventdispatcher_glib.cc.
|
protected |
Definition at line 460 of file eventdispatcher_glib.cc.
|
protected |
Definition at line 453 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 321 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 371 of file eventdispatcher_glib.cc.
|
protectedvirtual |
Adds a new Timer instance to the internal timer list
Definition at line 408 of file eventdispatcher_glib.cc.
|
protectedvirtual |
Removes a timer from the internal timer list, once a Timer is removed it does not fire anymore
Definition at line 424 of file eventdispatcher_glib.cc.
|
friend |
Definition at line 52 of file eventdispatcher.h.
|
friend |
Definition at line 53 of file eventdispatcher.h.