libzypp  17.22.0
abstracteventsource.cc
Go to the documentation of this file.
1 #include "abstracteventsource.h"
3 #include "eventdispatcher.h"
4 #include "private/base_p.h"
5 
6 #include <zypp/base/Exception.h>
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 
20 { }
21 
23  : Base ( dd )
24 { }
25 
27 {
28  Z_D();
29  auto ev = d->_ev.lock();
30  //if ev is null , eventloop is shutting down
31  if ( ev )
32  ev->removeEventSource( this );
33 }
34 
35 std::weak_ptr<EventDispatcher> AbstractEventSource::eventDispatcher() const
36 {
37  return d_func()->_ev;
38 }
39 
40 void AbstractEventSource::updateFdWatch(int fd, int mode)
41 {
42  auto ev = d_func()->_ev.lock();
43 
44  //if ev is null we are shutting down
45  if ( !ev )
46  return;
47  ev->updateEventSource( this, fd, mode );
48 }
49 
51 {
52  auto ev = d_func()->_ev.lock();
53 
54  //if ev is null we are shutting down
55  if ( !ev )
56  return;
57  ev->removeEventSource( this, fd );
58 }
59 
60 }
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
#define Z_D()
Definition: zyppglobal.h:44
void updateFdWatch(int fd, int mode)
static std::shared_ptr< EventDispatcher > instance()
Base class for Exception.
Definition: Exception.h:145
std::weak_ptr< EventDispatcher > _ev
std::weak_ptr< EventDispatcher > eventDispatcher() const