libzypp: zypp-core/ng/base/eventloop_glib.cc Source File

libzypp 17.38.14

eventloop_glib.cc
Go to the documentation of this file.
1#include "private/eventloop_glib_p.h"
2#include <zypp-core/ng/base/EventDispatcher>
3
4namespace zyppng {
5
6 EventLoopPrivate::EventLoopPrivate( EventLoop &p ) : BasePrivate( p )
7 { }
8
9 ZYPP_IMPL_PRIVATE(EventLoop)
10
11 EventLoop::EventLoop( EventDispatcherRef disp )
12 : Base ( * new EventLoopPrivate(*this) )
13 {
14 Z_D();
15 d->_dispatcher = std::move(disp);
16 d->_loop = g_main_loop_new( reinterpret_cast<GMainContext*>(d->_dispatcher->nativeDispatcherHandle()), false );
17 }
18
19
20 EventLoop::EventLoop( GMainContext *ctx )
21 : EventLoop( ThreadData::current().ensureDispatcher( ctx ) )
22 {}
23
24 EventLoop::~EventLoop()
25 {
26 g_main_loop_unref( d_func()->_loop );
27 }
28
29 EventLoop::Ptr EventLoop::create( GMainContext *ctx )
30 {
31 return Ptr( new EventLoop( ctx ) );
32 }
33
34 EventLoop::Ptr EventLoop::create( EventDispatcherRef dispatcher )
35 {
36 return Ptr( new EventLoop( std::move(dispatcher) ) );
37 }
38
39
40 void EventLoop::run()
41 {
42 Z_D();
43 g_main_context_push_thread_default( reinterpret_cast<GMainContext*>(d->_dispatcher->nativeDispatcherHandle()) );
44 zypp_defer {
45 d->_dispatcher->clearUnrefLaterList();
46 g_main_context_pop_thread_default( reinterpret_cast<GMainContext*>(d->_dispatcher->nativeDispatcherHandle()) );
47 };
48 g_main_loop_run( d->_loop );
49 }
50
51 void EventLoop::quit()
52 {
53 g_main_loop_quit( d_func()->_loop );
54 }
55
56 std::shared_ptr<EventDispatcher> EventLoop::eventDispatcher() const
57 {
58 return d_func()->_dispatcher;
59 }
60}
zypp_defer
#define zypp_defer
Definition AutoDispose.h:293
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::EventLoopPrivate
Definition eventloop_glib_p.h:12
zyppng::EventLoopPrivate::EventLoopPrivate
EventLoopPrivate(EventLoop &p)
Definition eventloop_glib.cc:6
zyppng::EventLoop
Definition eventloop.h:43
zyppng::EventLoop::run
void run()
Definition eventloop_glib.cc:40
zyppng::EventLoop::Ptr
EventLoopRef Ptr
Definition eventloop.h:47
zyppng::EventLoop::quit
void quit()
Definition eventloop_glib.cc:51
zyppng::EventLoop::EventLoop
EventLoop(GMainContext *ctx=nullptr)
Definition eventloop_glib.cc:20
zyppng::EventLoop::create
static Ptr create(GMainContext *ctx=nullptr)
Definition eventloop_glib.cc:29
zyppng::EventLoop::~EventLoop
~EventLoop() override
Definition eventloop_glib.cc:24
zyppng::EventLoop::eventDispatcher
std::shared_ptr< EventDispatcher > eventDispatcher() const
Definition eventloop_glib.cc:56
GMainContext
struct _GMainContext GMainContext
Definition eventdispatcher.h:24
eventloop_glib_p.h
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::ZYPP_IMPL_PRIVATE
ZYPP_IMPL_PRIVATE(UnixSignalSource)
zyppng::ThreadData
Definition threaddata_p.h:16
Z_D
#define Z_D()
Definition zyppglobal.h:98