libzypp  17.35.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"
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 
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 {
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
std::vector< std::shared_ptr< void > > _unrefLater
std::vector< GAbstractEventSource * > _eventSources
GlibWaitPIDData & operator=(GlibWaitPIDData &&other) noexcept
static void destruct(GAbstractEventSource *src)
static std::shared_ptr< EventDispatcher > create()
static gboolean check(GSource *source)
std::function< void(int, int)> WaitPidCallback
static GLibTimerSource * create()
EventDispatcher::WaitPidCallback callback
static void destruct(GLibTimerSource *src)
EventDispatcherPrivate(GMainContext *ctx, EventDispatcher &p)
ZYPP_FWD_DECL_TYPE_WITH_REFS(Context)
The Timer class provides repetitive and single-shot timers.
Definition: timer.h:44
std::vector< GLibTimerSource * > _runningTimers
EventDispatcherPrivate * _ev
static void waitPidCallback(GPid pid, gint status, gpointer user_data)
UnixSignalSourceWeakRef _signalSource
static gboolean prepare(GSource *, gint *timeout)
std::vector< GUnixPollFD > pollfds
std::queue< EventDispatcher::IdleFunction > _idleFuncs
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
static gboolean prepare(GSource *src, gint *timeout)
static GAbstractEventSource * create(EventDispatcherPrivate *ev)
#define ZYPP_DECLARE_PUBLIC(Class)
Definition: zyppglobal.h:98
static gboolean dispatch(GSource *source, GSourceFunc, gpointer)
static gboolean check(GSource *source)
std::unordered_map< int, GlibWaitPIDData > _waitPIDs