libzypp: zypp-core/ng/base/private/eventdispatcher_glib_p.h Source File

libzypp 17.38.14

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"
5#include <zypp-core/ng/base/eventdispatcher.h>
6#include <glib.h>
7#include <thread>
8#include <unordered_map>
9#include <queue>
10
11namespace zyppng {
12
13 ZYPP_FWD_DECL_TYPE_WITH_REFS ( UnixSignalSource );
14
15 struct GUnixPollFD
16{
17 GIOCondition reqEvents;
18 int pollfd = -1;
19 gpointer tag = nullptr;
20};
21
28 struct GAbstractEventSource
29{
30 GSource source;
31 EventDispatcherPrivate *_ev;
32 AbstractEventSource *eventSource;
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
39 static GAbstractEventSource *create (EventDispatcherPrivate *ev);
40 static void destruct ( GAbstractEventSource *src );
41};
42
49 struct GLibTimerSource
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
62 struct GlibWaitPIDData
63{
64 GlibWaitPIDData( GPid pid );
65 GlibWaitPIDData( GlibWaitPIDData &&other ) noexcept;
66 ~GlibWaitPIDData();
67
68 GlibWaitPIDData & operator= ( GlibWaitPIDData &&other ) noexcept;
69
70 guint tag = 0;
71 GSource *source = nullptr;
72 EventDispatcher::WaitPidCallback callback;
73};
74
75 struct GlibTimeoutData {
76 std::function<bool()> _callback;
77};
78
79 class EventDispatcherPrivate : public BasePrivate
80{
81 ZYPP_DECLARE_PUBLIC(EventDispatcher)
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 ( GMainContext *ctx = 0 );
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
base_p.h
bool
zyppng::AbstractEventSource
Definition abstracteventsource.h:38
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::EventDispatcherPrivate
Definition eventdispatcher_glib_p.h:80
zyppng::EventDispatcherPrivate::~EventDispatcherPrivate
~EventDispatcherPrivate() override
Definition eventdispatcher_glib.cc:291
zyppng::EventDispatcherPrivate::_idleFuncs
std::queue< EventDispatcher::IdleFunction > _idleFuncs
Definition eventdispatcher_glib_p.h:103
zyppng::EventDispatcherPrivate::_unrefLater
std::vector< std::shared_ptr< void > > _unrefLater
Definition eventdispatcher_glib_p.h:102
zyppng::EventDispatcherPrivate::timeoutCallback
static bool timeoutCallback(gpointer user_data)
Definition eventdispatcher_glib.cc:366
zyppng::EventDispatcherPrivate::waitPidCallback
static void waitPidCallback(GPid pid, gint status, gpointer user_data)
Definition eventdispatcher_glib.cc:346
zyppng::EventDispatcherPrivate::_myThreadId
std::thread::id _myThreadId
Definition eventdispatcher_glib_p.h:95
zyppng::EventDispatcherPrivate::_ctx
GMainContext * _ctx
Definition eventdispatcher_glib_p.h:96
zyppng::EventDispatcherPrivate::_waitPIDs
std::unordered_map< int, GlibWaitPIDData > _waitPIDs
Definition eventdispatcher_glib_p.h:104
zyppng::EventDispatcherPrivate::runIdleTasks
bool runIdleTasks()
Definition eventdispatcher_glib.cc:311
zyppng::EventDispatcherPrivate::_idleSource
GSource * _idleSource
Definition eventdispatcher_glib_p.h:98
zyppng::EventDispatcherPrivate::_eventSources
std::vector< GAbstractEventSource * > _eventSources
Definition eventdispatcher_glib_p.h:101
zyppng::EventDispatcherPrivate::create
static std::shared_ptr< EventDispatcher > create(GMainContext *ctx=0)
Definition eventdispatcher_glib.cc:341
zyppng::EventDispatcherPrivate::_signalSource
UnixSignalSourceWeakRef _signalSource
Definition eventdispatcher_glib_p.h:105
zyppng::EventDispatcherPrivate::_runningTimers
std::vector< GLibTimerSource * > _runningTimers
Definition eventdispatcher_glib_p.h:100
zyppng::EventDispatcherPrivate::timeoutDestroyCallback
static void timeoutDestroyCallback(gpointer user_data)
Definition eventdispatcher_glib.cc:375
zyppng::EventDispatcherPrivate::EventDispatcherPrivate
EventDispatcherPrivate(GMainContext *ctx, EventDispatcher &p)
Definition eventdispatcher_glib.cc:275
zyppng::EventDispatcherPrivate::enableIdleSource
void enableIdleSource()
Definition eventdispatcher_glib.cc:332
zyppng::EventDispatcher
Definition eventdispatcher.h:43
zyppng::EventDispatcher::WaitPidCallback
std::function< void(int, int)> WaitPidCallback
Definition eventdispatcher.h:148
zyppng::Timer
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
zyppng::UnixSignalSource
Definition unixsignalsource.h:13
eventdispatcher.h
GMainContext
struct _GMainContext GMainContext
Definition eventdispatcher.h:24
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::GAbstractEventSource
Definition eventdispatcher_glib_p.h:29
zyppng::GAbstractEventSource::check
static gboolean check(GSource *source)
Definition eventdispatcher_glib.cc:96
zyppng::GAbstractEventSource::pollfds
std::vector< GUnixPollFD > pollfds
Definition eventdispatcher_glib_p.h:33
zyppng::GAbstractEventSource::source
GSource source
Definition eventdispatcher_glib_p.h:30
zyppng::GAbstractEventSource::eventSource
AbstractEventSource * eventSource
Definition eventdispatcher_glib_p.h:32
zyppng::GAbstractEventSource::dispatch
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
Definition eventdispatcher_glib.cc:126
zyppng::GAbstractEventSource::create
static GAbstractEventSource * create(EventDispatcherPrivate *ev)
Definition eventdispatcher_glib.cc:63
zyppng::GAbstractEventSource::destruct
static void destruct(GAbstractEventSource *src)
Definition eventdispatcher_glib.cc:73
zyppng::GAbstractEventSource::prepare
static gboolean prepare(GSource *, gint *timeout)
Definition eventdispatcher_glib.cc:86
zyppng::GAbstractEventSource::_ev
EventDispatcherPrivate * _ev
Definition eventdispatcher_glib_p.h:31
zyppng::GLibTimerSource
Definition eventdispatcher_glib_p.h:50
zyppng::GLibTimerSource::destruct
static void destruct(GLibTimerSource *src)
Definition eventdispatcher_glib.cc:222
zyppng::GLibTimerSource::source
GSource source
Definition eventdispatcher_glib_p.h:51
zyppng::GLibTimerSource::prepare
static gboolean prepare(GSource *src, gint *timeout)
Definition eventdispatcher_glib.cc:173
zyppng::GLibTimerSource::check
static gboolean check(GSource *source)
Definition eventdispatcher_glib.cc:194
zyppng::GLibTimerSource::create
static GLibTimerSource * create()
Definition eventdispatcher_glib.cc:214
zyppng::GLibTimerSource::dispatch
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
Definition eventdispatcher_glib.cc:200
zyppng::GLibTimerSource::_t
Timer * _t
Definition eventdispatcher_glib_p.h:52
zyppng::GUnixPollFD
Definition eventdispatcher_glib_p.h:16
zyppng::GUnixPollFD::pollfd
int pollfd
Definition eventdispatcher_glib_p.h:18
zyppng::GUnixPollFD::tag
gpointer tag
Definition eventdispatcher_glib_p.h:19
zyppng::GUnixPollFD::reqEvents
GIOCondition reqEvents
Definition eventdispatcher_glib_p.h:17
zyppng::GlibTimeoutData
Definition eventdispatcher_glib_p.h:75
zyppng::GlibTimeoutData::_callback
std::function< bool()> _callback
Definition eventdispatcher_glib_p.h:76
zyppng::GlibWaitPIDData::~GlibWaitPIDData
~GlibWaitPIDData()
Definition eventdispatcher_glib.cc:258
zyppng::GlibWaitPIDData::source
GSource * source
Definition eventdispatcher_glib_p.h:71
zyppng::GlibWaitPIDData::operator=
GlibWaitPIDData & operator=(GlibWaitPIDData &&other) noexcept
Definition eventdispatcher_glib.cc:266
zyppng::GlibWaitPIDData::callback
EventDispatcher::WaitPidCallback callback
Definition eventdispatcher_glib_p.h:72
zyppng::GlibWaitPIDData::GlibWaitPIDData
GlibWaitPIDData(GPid pid)
Definition eventdispatcher_glib.cc:245
zyppng::GlibWaitPIDData::tag
guint tag
Definition eventdispatcher_glib_p.h:70
ZYPP_DECLARE_PUBLIC
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:91
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:119