libzypp  17.36.1
abstracteventsource.cc
Go to the documentation of this file.
1 #include "abstracteventsource.h"
3 #include "eventdispatcher.h"
4 #include "private/base_p.h"
5 
7 
8 namespace zyppng {
9 
11 {
12  auto ev = EventDispatcher::instance();
13  if ( !ev )
14  ZYPP_THROW( zypp::Exception( "Creating event sources without a EventDispatcher instance is not supported" ) );
15  _ev = ev;
16 }
17 
19 
21  : Base ( * new AbstractEventSourcePrivate( *this ) )
22 { }
23 
25  : Base ( dd )
26 { }
27 
29 {
30  Z_D();
31  auto ev = d->_ev.lock();
32  //if ev is null , eventloop is shutting down
33  if ( ev )
34  ev->removeEventSource( *this );
35 }
36 
37 std::weak_ptr<EventDispatcher> AbstractEventSource::eventDispatcher() const
38 {
39  return d_func()->_ev;
40 }
41 
42 void AbstractEventSource::updateFdWatch(int fd, int mode)
43 {
44  auto ev = d_func()->_ev.lock();
45 
46  //if ev is null we are shutting down
47  if ( !ev )
48  return;
49  ev->updateEventSource( *this, fd, mode );
50 }
51 
53 {
54  auto ev = d_func()->_ev.lock();
55 
56  //if ev is null we are shutting down
57  if ( !ev )
58  return;
59  ev->removeEventSource( *this , fd );
60 }
61 
62 }
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
#define Z_D()
Definition: zyppglobal.h:105
AbstractEventSourcePrivate(AbstractEventSource &p)
void updateFdWatch(int fd, int mode)
static std::shared_ptr< EventDispatcher > instance()
Base class for Exception.
Definition: Exception.h:146
ZYPP_IMPL_PRIVATE(UnixSignalSource)
std::weak_ptr< EventDispatcher > _ev
std::weak_ptr< EventDispatcher > eventDispatcher() const