libzypp  17.35.11
socketnotifier.cc
Go to the documentation of this file.
1 #include "socketnotifier.h"
3 
4 namespace zyppng {
5 
7 {
9 public:
10 
13 
15 
16  int _socket = -1;
18  bool _enabled = false;
19 
20 };
21 
22 
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 
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 
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 
72 {
73  return d_func()->_socket;
74 }
75 
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 
87 { }
88 
89 
90 }
91 
92 
Signal< void(const SocketNotifier &, int)> _activated
void onSignal(int signal) override
void onFdReady(int, int events) override
SocketNotifier(int socket, int evTypes)
void setMode(int mode)
std::shared_ptr< SocketNotifier > Ptr
SocketNotifierPrivate(SocketNotifier &p)
static Ptr create(int socket, int evTypes, bool enable=true)
#define Z_D()
Definition: zyppglobal.h:105
void updateFdWatch(int fd, int mode)
void setEnabled(bool enabled=true)
ZYPP_IMPL_PRIVATE(UnixSignalSource)
SignalProxy< void(const SocketNotifier &sock, int evTypes)> sigActivated()
#define ZYPP_DECLARE_PUBLIC(Class)
Definition: zyppglobal.h:98