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

libzypp 17.38.14

abstracteventsource.cc
Go to the documentation of this file.
1#include "abstracteventsource.h"
2#include "private/abstracteventsource_p.h"
3#include "eventdispatcher.h"
4#include "private/base_p.h"
5
6#include <zypp-core/base/Exception.h>
7
8namespace zyppng {
9
10AbstractEventSourcePrivate::AbstractEventSourcePrivate( AbstractEventSource &p ) : BasePrivate( p )
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
18 ZYPP_IMPL_PRIVATE(AbstractEventSource)
19
20AbstractEventSource::AbstractEventSource()
21 : Base ( * new AbstractEventSourcePrivate( *this ) )
22{ }
23
24 AbstractEventSource::AbstractEventSource( AbstractEventSourcePrivate &dd )
25 : Base ( dd )
26{ }
27
28AbstractEventSource::~AbstractEventSource()
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
37std::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
52 void AbstractEventSource::removeFdWatch(int fd)
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}
Exception.h
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
abstracteventsource.h
abstracteventsource_p.h
base_p.h
zypp::Exception
Base class for Exception.
Definition Exception.h:153
zyppng::AbstractEventSourcePrivate
Definition abstracteventsource_p.h:23
zyppng::AbstractEventSourcePrivate::_ev
std::weak_ptr< EventDispatcher > _ev
Definition abstracteventsource_p.h:28
zyppng::AbstractEventSourcePrivate::AbstractEventSourcePrivate
AbstractEventSourcePrivate(AbstractEventSource &p)
Definition abstracteventsource.cc:10
zyppng::AbstractEventSource
Definition abstracteventsource.h:38
zyppng::AbstractEventSource::AbstractEventSource
AbstractEventSource()
Definition abstracteventsource.cc:20
zyppng::AbstractEventSource::~AbstractEventSource
~AbstractEventSource() override
Definition abstracteventsource.cc:28
zyppng::AbstractEventSource::eventDispatcher
std::weak_ptr< EventDispatcher > eventDispatcher() const
Definition abstracteventsource.cc:37
zyppng::AbstractEventSource::updateFdWatch
void updateFdWatch(int fd, int mode)
Definition abstracteventsource.cc:42
zyppng::AbstractEventSource::removeFdWatch
void removeFdWatch(int fd)
Definition abstracteventsource.cc:52
zyppng::BasePrivate::BasePrivate
BasePrivate(Base &b)
Definition base_p.h:17
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::EventDispatcher::instance
static std::shared_ptr< EventDispatcher > instance()
Definition eventdispatcher_glib.cc:629
eventdispatcher.h
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::ZYPP_IMPL_PRIVATE
ZYPP_IMPL_PRIVATE(UnixSignalSource)
Z_D
#define Z_D()
Definition zyppglobal.h:98