libzypp 17.37.10

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/zyppng/base/eventdispatcher.h>
6#include <glib.h>
7#include <thread>
8#include <unordered_map>
9#include <queue>
10
11 namespace 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 class EventDispatcherPrivate : public BasePrivate
76{
77 ZYPP_DECLARE_PUBLIC(EventDispatcher)
78 public:
79 EventDispatcherPrivate( GMainContext *ctx, EventDispatcher &p );
80 ~EventDispatcherPrivate() override;
81
82 bool runIdleTasks();
83 void enableIdleSource ();
84
85 static std::shared_ptr<EventDispatcher> create ( );
86 static void waitPidCallback ( GPid pid, gint status, gpointer user_data );
87
88 std::thread::id _myThreadId;
89 GMainContext *_ctx = nullptr;
90
91 GSource *_idleSource = nullptr;
92
93 std::vector<GLibTimerSource *> _runningTimers;
94 std::vector<GAbstractEventSource *> _eventSources;
95 std::vector< std::shared_ptr<void> > _unrefLater;
96 std::queue< EventDispatcher::IdleFunction > _idleFuncs;
97 std::unordered_map<int, GlibWaitPIDData> _waitPIDs;
98 UnixSignalSourceWeakRef _signalSource;
99};
100
101}
102
103
104#endif
base_p.h
zyppng::AbstractEventSource
Definition abstracteventsource.h:38
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::EventDispatcherPrivate
Definition eventdispatcher_glib_p.h:76
zyppng::EventDispatcherPrivate::~EventDispatcherPrivate
~EventDispatcherPrivate() override
Definition eventdispatcher_glib.cc:291
zyppng::EventDispatcherPrivate::_idleFuncs
std::queue< EventDispatcher::IdleFunction > _idleFuncs
Definition eventdispatcher_glib_p.h:96
zyppng::EventDispatcherPrivate::_unrefLater
std::vector< std::shared_ptr< void > > _unrefLater
Definition eventdispatcher_glib_p.h:95
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:88
zyppng::EventDispatcherPrivate::_ctx
GMainContext * _ctx
Definition eventdispatcher_glib_p.h:89
zyppng::EventDispatcherPrivate::_waitPIDs
std::unordered_map< int, GlibWaitPIDData > _waitPIDs
Definition eventdispatcher_glib_p.h:97
zyppng::EventDispatcherPrivate::runIdleTasks
bool runIdleTasks()
Definition eventdispatcher_glib.cc:311
zyppng::EventDispatcherPrivate::_idleSource
GSource * _idleSource
Definition eventdispatcher_glib_p.h:91
zyppng::EventDispatcherPrivate::_eventSources
std::vector< GAbstractEventSource * > _eventSources
Definition eventdispatcher_glib_p.h:94
zyppng::EventDispatcherPrivate::_signalSource
UnixSignalSourceWeakRef _signalSource
Definition eventdispatcher_glib_p.h:98
zyppng::EventDispatcherPrivate::_runningTimers
std::vector< GLibTimerSource * > _runningTimers
Definition eventdispatcher_glib_p.h:93
zyppng::EventDispatcherPrivate::EventDispatcherPrivate
EventDispatcherPrivate(GMainContext *ctx, EventDispatcher &p)
Definition eventdispatcher_glib.cc:275
zyppng::EventDispatcherPrivate::create
static std::shared_ptr< EventDispatcher > create()
Definition eventdispatcher_glib.cc:341
zyppng::EventDispatcherPrivate::enableIdleSource
void enableIdleSource()
Definition eventdispatcher_glib.cc:332
zyppng::EventDispatcher
Definition eventdispatcher.h:42
zyppng::EventDispatcher::WaitPidCallback
std::function< void(int, int)> WaitPidCallback
Definition eventdispatcher.h:131
zyppng::Timer
The Timer class provides repetitive and single-shot timers.
Definition timer.h:45
zyppng::UnixSignalSource
Definition unixsignalsource.h:13
eventdispatcher.h
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::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:98
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126