libzypp 17.37.10

socketnotifier.cc
Go to the documentation of this file.
1#include "socketnotifier.h"
2#include "private/abstracteventsource_p.h"
3
4 namespace zyppng {
5
6 class SocketNotifierPrivate : public AbstractEventSourcePrivate
7{
8 ZYPP_DECLARE_PUBLIC(SocketNotifier)
9 public:
10
11 SocketNotifierPrivate ( SocketNotifier &p ) :
12 AbstractEventSourcePrivate(p){}
13
14 Signal< void (const SocketNotifier &, int)> _activated;
15
16 int _socket = -1;
17 int _mode = SocketNotifier::Read;
18 bool _enabled = false;
19
20};
21
22
23 ZYPP_IMPL_PRIVATE( SocketNotifier )
24
25 SocketNotifier::SocketNotifier (int socket, int evTypes )
26 : AbstractEventSource ( * new SocketNotifierPrivate( *this ) )
27{
28 Z_D();
29 d->_socket = socket;
30 d->_mode = evTypes;
31}
32
33 SocketNotifier::Ptr SocketNotifier::create(int socket, int evTypes, bool enable )
34{
35 auto ptr = std::shared_ptr<SocketNotifier>( new SocketNotifier( socket, evTypes ) );
36 ptr->setEnabled( enable );
37 return ptr;
38}
39
40 void SocketNotifier::setMode(int mode)
41{
42 Z_D();
43 if ( mode == d->_mode )
44 return;
45
46 d->_mode = mode;
47
48 if ( d->_enabled && d->_socket >= 0)
49 updateFdWatch( d->_socket, d->_mode );
50}
51
52 int SocketNotifier::mode() const
53{
54 return d_func()->_mode;
55}
56
57 void SocketNotifier::setEnabled( bool enabled )
58{
59 Z_D();
60 if ( enabled == d->_enabled || d->_socket < 0 )
61 return;
62
63 d->_enabled = enabled;
64
65 if ( enabled )
66 updateFdWatch( d->_socket, d->_mode );
67 else
68 removeFdWatch( -1 );
69}
70
71 int SocketNotifier::socket() const
72{
73 return d_func()->_socket;
74}
75
76 SignalProxy<void (const SocketNotifier &, int)> SocketNotifier::sigActivated()
77{
78 return d_func()->_activated;
79}
80
81 void SocketNotifier::onFdReady( int, int events )
82{
83 d_func()->_activated.emit( *this, events );
84}
85
86 void SocketNotifier::onSignal( int )
87{ }
88
89
90}
91
92
abstracteventsource_p.h
zyppng::AbstractEventSourcePrivate::AbstractEventSourcePrivate
AbstractEventSourcePrivate(AbstractEventSource &p)
Definition abstracteventsource.cc:10
zyppng::AbstractEventSource::AbstractEventSource
AbstractEventSource()
Definition abstracteventsource.cc:20
zyppng::AbstractEventSource::Read
@ Read
Definition abstracteventsource.h:47
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::SignalProxy
Definition signals.h:325
zyppng::Signal
Definition signals.h:151
zyppng::SocketNotifierPrivate
Definition socketnotifier.cc:7
zyppng::SocketNotifierPrivate::SocketNotifierPrivate
SocketNotifierPrivate(SocketNotifier &p)
Definition socketnotifier.cc:11
zyppng::SocketNotifierPrivate::_activated
Signal< void(const SocketNotifier &, int)> _activated
Definition socketnotifier.cc:14
zyppng::SocketNotifierPrivate::_mode
int _mode
Definition socketnotifier.cc:17
zyppng::SocketNotifierPrivate::_socket
int _socket
Definition socketnotifier.cc:16
zyppng::SocketNotifierPrivate::_enabled
bool _enabled
Definition socketnotifier.cc:18
zyppng::SocketNotifier
Definition socketnotifier.h:69
zyppng::SocketNotifier::SocketNotifier
SocketNotifier(int socket, int evTypes)
Definition socketnotifier.cc:25
zyppng::SocketNotifier::Ptr
std::shared_ptr< SocketNotifier > Ptr
Definition socketnotifier.h:73
zyppng::SocketNotifier::onSignal
void onSignal(int signal) override
Definition socketnotifier.cc:86
zyppng::SocketNotifier::create
static Ptr create(int socket, int evTypes, bool enable=true)
Definition socketnotifier.cc:33
zyppng::SocketNotifier::socket
int socket() const
Definition socketnotifier.cc:71
zyppng::SocketNotifier::onFdReady
void onFdReady(int, int events) override
Definition socketnotifier.cc:81
zyppng::SocketNotifier::mode
int mode() const
Definition socketnotifier.cc:52
zyppng::SocketNotifier::sigActivated
SignalProxy< void(const SocketNotifier &sock, int evTypes)> sigActivated()
Definition socketnotifier.cc:76
zyppng::SocketNotifier::setMode
void setMode(int mode)
Definition socketnotifier.cc:40
zyppng::SocketNotifier::setEnabled
void setEnabled(bool enabled=true)
Definition socketnotifier.cc:57
zyppng
Definition MediaNetworkRequestExecutor.h:16
socketnotifier.h
ZYPP_IMPL_PRIVATE
#define ZYPP_IMPL_PRIVATE(Class)
Definition zyppglobal.h:92
Z_D
#define Z_D()
Definition zyppglobal.h:105
ZYPP_DECLARE_PUBLIC
#define ZYPP_DECLARE_PUBLIC(Class)
Definition zyppglobal.h:98