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