libzypp: zypp-core/zyppng/base/eventdispatcher.h Source File

libzypp 17.36.6

eventdispatcher.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 ZYPP_BASE_EVENTDISPATCHER_DEFINED
15#define ZYPP_BASE_EVENTDISPATCHER_DEFINED
16
17#include <zypp-core/zyppng/base/zyppglobal.h>
18#include <zypp-core/zyppng/base/Signals>
19#include <zypp-core/zyppng/base/Base>
20#include <zypp-core/zyppng/base/AbstractEventSource>
21#include <memory>
22#include <functional>
23
24namespace zyppng {
25
26class SocketNotifier;
27class Timer;
28
29 ZYPP_FWD_DECL_TYPE_WITH_REFS( EventDispatcher );
30 ZYPP_FWD_DECL_TYPE_WITH_REFS( UnixSignalSource );
31class EventDispatcherPrivate;
32
41 class LIBZYPP_NG_EXPORT EventDispatcher : public Base
42{
43 ZYPP_DECLARE_PRIVATE(EventDispatcher)
44 friend class AbstractEventSource;
45 friend class Timer;
46
47public:
48
49 using Ptr = std::shared_ptr<EventDispatcher>;
50 using WeakPtr = std::shared_ptr<EventDispatcher>;
51 using IdleFunction = std::function<bool ()>;
52
53
54 ~EventDispatcher() override;
55
60 virtual bool run_once();
61
66 template< typename T = IdleFunction >
67 static void invokeOnIdle ( T &&callback )
68 {
69 auto ev = instance();
70 if ( ev )
71 ev->invokeOnIdleImpl( std::forward<T>(callback) );
72 }
73
84 template< typename T >
85 static void unrefLater ( T &&ptr ) {
86 auto ev = instance();
87 if ( ev )
88 ev->unrefLaterImpl( std::static_pointer_cast<void>( std::forward<T>(ptr) ) );
89 }
90
98 void clearUnrefLaterList ();
99
103 ulong runningTimers() const;
104
108 static std::shared_ptr<EventDispatcher> instance();
109
115 static void setThreadDispatcher ( const std::shared_ptr<EventDispatcher> &disp );
116
121 void *nativeDispatcherHandle () const;
122
129 static bool waitForFdEvent ( const int fd, int events, int &revents, int &timeout );
130
131 using WaitPidCallback = std::function<void(int, int)>;
132
137 void trackChildProcess ( int pid, std::function<void(int, int)> callback );
138
144 bool untrackChildProcess ( int pid );
145
150 UnixSignalSourceRef unixSignalSource ();
151
152protected:
153
158 EventDispatcher( void *ctx = nullptr );
159
163 void unrefLaterImpl ( std::shared_ptr<void> &&ptr );
164
168 void invokeOnIdleImpl ( IdleFunction &&callback );
169
176 virtual void updateEventSource ( AbstractEventSource &notifier, int fd, int mode );
177
184 virtual void removeEventSource ( AbstractEventSource &notifier, int fd = -1 );
185
189 virtual void registerTimer ( Timer &timer );
190
194 virtual void removeTimer ( Timer &timer );
195
196};
197
198}
199
200#endif
shared_ptr
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::EventDispatcherPrivate
Definition eventdispatcher_glib_p.h:76
zyppng::EventDispatcher
Definition eventdispatcher.h:42
zyppng::EventDispatcher::AbstractEventSource
friend class AbstractEventSource
Definition eventdispatcher.h:44
zyppng::EventDispatcher::unrefLater
static void unrefLater(T &&ptr)
Definition eventdispatcher.h:85
zyppng::EventDispatcher::run_once
virtual bool run_once()
Definition eventdispatcher_glib.cc:566
zyppng::EventDispatcher::unixSignalSource
UnixSignalSourceRef unixSignalSource()
Definition eventdispatcher_glib.cc:553
zyppng::EventDispatcher::registerTimer
virtual void registerTimer(Timer &timer)
Definition eventdispatcher_glib.cc:458
zyppng::EventDispatcher::WaitPidCallback
std::function< void(int, int)> WaitPidCallback
Definition eventdispatcher.h:131
zyppng::EventDispatcher::Timer
friend class Timer
Definition eventdispatcher.h:45
zyppng::EventDispatcher::WeakPtr
std::shared_ptr< EventDispatcher > WeakPtr
Definition eventdispatcher.h:50
zyppng::EventDispatcher::unrefLaterImpl
void unrefLaterImpl(std::shared_ptr< void > &&ptr)
Definition eventdispatcher_glib.cc:578
zyppng::EventDispatcher::IdleFunction
std::function< bool()> IdleFunction
Definition eventdispatcher.h:51
zyppng::EventDispatcher::EventDispatcher
EventDispatcher(void *ctx=nullptr)
Definition eventdispatcher_glib.cc:368
zyppng::EventDispatcher::removeTimer
virtual void removeTimer(Timer &timer)
Definition eventdispatcher_glib.cc:474
zyppng::EventDispatcher::trackChildProcess
void trackChildProcess(int pid, std::function< void(int, int)> callback)
Definition eventdispatcher_glib.cc:531
zyppng::EventDispatcher::untrackChildProcess
bool untrackChildProcess(int pid)
Definition eventdispatcher_glib.cc:542
zyppng::EventDispatcher::updateEventSource
virtual void updateEventSource(AbstractEventSource &notifier, int fd, int mode)
Definition eventdispatcher_glib.cc:377
zyppng::EventDispatcher::removeEventSource
virtual void removeEventSource(AbstractEventSource &notifier, int fd=-1)
Definition eventdispatcher_glib.cc:419
zyppng::EventDispatcher::instance
static std::shared_ptr< EventDispatcher > instance()
Definition eventdispatcher_glib.cc:595
zyppng::EventDispatcher::invokeOnIdleImpl
void invokeOnIdleImpl(IdleFunction &&callback)
Definition eventdispatcher_glib.cc:571
zyppng::EventDispatcher::Ptr
std::shared_ptr< EventDispatcher > Ptr
Definition eventdispatcher.h:49
zyppng::EventDispatcher::invokeOnIdle
static void invokeOnIdle(T &&callback)
Convenience function to schedule a callback to be called later.
Definition eventdispatcher.h:67
zyppng::SocketNotifier
Definition socketnotifier.h:69
zyppng::Timer
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
zyppng::UnixSignalSource
Definition unixsignalsource.h:13
std
Definition Arch.h:364
zypp::callback
Callbacks light.
Definition Callback.h:146
zyppng
Definition MediaCurl2.h:22
zyppglobal.h
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87
LIBZYPP_NG_EXPORT
#define LIBZYPP_NG_EXPORT
Definition zyppglobal.h:8
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126