libzypp  17.38.7
eventloop_glib.cc
Go to the documentation of this file.
2 #include <zypp-core/ng/base/EventDispatcher>
3 
4 namespace zyppng {
5 
7  { }
8 
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 
21  : EventLoop( ThreadData::current().ensureDispatcher( ctx ) )
22  {}
23 
25  {
26  g_main_loop_unref( d_func()->_loop );
27  }
28 
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 
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 
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 }
#define zypp_defer
Definition: AutoDispose.h:293
std::shared_ptr< EventDispatcher > eventDispatcher() const
~EventLoop() override
EventLoopRef Ptr
Definition: eventloop.h:47
#define Z_D()
Definition: zyppglobal.h:98
EventLoop(GMainContext *ctx=nullptr)
ZYPP_IMPL_PRIVATE(UnixSignalSource)
EventLoopPrivate(EventLoop &p)
struct _GMainContext GMainContext
static Ptr create(GMainContext *ctx=nullptr)