libzypp 17.38.5
eventdispatcher_glib_p.h
Go to the documentation of this file.
1#ifndef ZYPP_BASE_EVENTDISPATCHER_GLIB_P_DEFINED
2#define ZYPP_BASE_EVENTDISPATCHER_GLIB_P_DEFINED
3
4#include "base_p.h"
6#include <glib.h>
7#include <thread>
8#include <unordered_map>
9#include <queue>
10
11namespace zyppng {
12
14
16{
17 GIOCondition reqEvents;
18 int pollfd = -1;
19 gpointer tag = nullptr;
20};
21
29{
30 GSource source;
33 std::vector<GUnixPollFD> pollfds;
34
35 static gboolean prepare(GSource *, gint *timeout);
36 static gboolean check(GSource *source);
37 static gboolean dispatch(GSource *source, GSourceFunc, gpointer);
38
40 static void destruct ( GAbstractEventSource *src );
41};
42
50{
51 GSource source;
52 Timer *_t = nullptr;
53
54 static gboolean prepare(GSource *src, gint *timeout);
55 static gboolean check(GSource *source);
56 static gboolean dispatch(GSource *source, GSourceFunc, gpointer);
57
58 static GLibTimerSource *create ();
59 static void destruct ( GLibTimerSource *src );
60};
61
63{
64 GlibWaitPIDData( GPid pid );
65 GlibWaitPIDData( GlibWaitPIDData &&other ) noexcept;
67
68 GlibWaitPIDData & operator= ( GlibWaitPIDData &&other ) noexcept;
69
70 guint tag = 0;
71 GSource *source = nullptr;
73};
74
76 std::function<bool()> _callback;
77};
78
80{
82public:
83 EventDispatcherPrivate( GMainContext *ctx, EventDispatcher &p );
84 ~EventDispatcherPrivate() override;
85
86 bool runIdleTasks();
87 void enableIdleSource ();
88
89 static std::shared_ptr<EventDispatcher> create ( );
90 static void waitPidCallback ( GPid pid, gint status, gpointer user_data );
91
92 static bool timeoutCallback ( gpointer user_data );
93 static void timeoutDestroyCallback( gpointer user_data );
94
95 std::thread::id _myThreadId;
96 GMainContext *_ctx = nullptr;
97
98 GSource *_idleSource = nullptr;
99
100 std::vector<GLibTimerSource *> _runningTimers;
101 std::vector<GAbstractEventSource *> _eventSources;
102 std::vector< std::shared_ptr<void> > _unrefLater;
103 std::queue< EventDispatcher::IdleFunction > _idleFuncs;
104 std::unordered_map<int, GlibWaitPIDData> _waitPIDs;
105 UnixSignalSourceWeakRef _signalSource;
106};
107
108}
109
110
111#endif
BasePrivate(Base &b)
Definition base_p.h:17
std::queue< EventDispatcher::IdleFunction > _idleFuncs
std::vector< std::shared_ptr< void > > _unrefLater
static bool timeoutCallback(gpointer user_data)
static void waitPidCallback(GPid pid, gint status, gpointer user_data)
std::unordered_map< int, GlibWaitPIDData > _waitPIDs
std::vector< GAbstractEventSource * > _eventSources
std::vector< GLibTimerSource * > _runningTimers
static void timeoutDestroyCallback(gpointer user_data)
EventDispatcherPrivate(GMainContext *ctx, EventDispatcher &p)
static std::shared_ptr< EventDispatcher > create()
std::function< void(int, int)> WaitPidCallback
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
static gboolean check(GSource *source)
std::vector< GUnixPollFD > pollfds
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
static GAbstractEventSource * create(EventDispatcherPrivate *ev)
static void destruct(GAbstractEventSource *src)
static gboolean prepare(GSource *, gint *timeout)
static void destruct(GLibTimerSource *src)
static gboolean prepare(GSource *src, gint *timeout)
static gboolean check(GSource *source)
static GLibTimerSource * create()
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
std::function< bool()> _callback
GlibWaitPIDData & operator=(GlibWaitPIDData &&other) noexcept
EventDispatcher::WaitPidCallback callback
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126