libzypp 17.37.17
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
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
32
42{
44 friend class AbstractEventSource;
45 friend class Timer;
46
47public:
48
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
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
friend class AbstractEventSource
static void unrefLater(T &&ptr)
UnixSignalSourceRef unixSignalSource()
virtual void registerTimer(Timer &timer)
std::function< void(int, int)> WaitPidCallback
std::shared_ptr< EventDispatcher > WeakPtr
void unrefLaterImpl(std::shared_ptr< void > &&ptr)
std::function< bool()> IdleFunction
EventDispatcher(void *ctx=nullptr)
virtual void removeTimer(Timer &timer)
void trackChildProcess(int pid, std::function< void(int, int)> callback)
virtual void updateEventSource(AbstractEventSource &notifier, int fd, int mode)
virtual void removeEventSource(AbstractEventSource &notifier, int fd=-1)
static std::shared_ptr< EventDispatcher > instance()
void invokeOnIdleImpl(IdleFunction &&callback)
std::shared_ptr< EventDispatcher > Ptr
static void invokeOnIdle(T &&callback)
Convenience function to schedule a callback to be called later.
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
Definition Arch.h:364
Callbacks light.
Definition Callback.h:146
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87
#define LIBZYPP_NG_EXPORT
Definition zyppglobal.h:8
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126