1 #include "socketnotifier.h"
2 #include "private/abstracteventsource_p.h"
6 class SocketNotifierPrivate : public AbstractEventSourcePrivate
8 ZYPP_DECLARE_PUBLIC(SocketNotifier)
11 signal<void (const SocketNotifier &, int)> _activated;
14 int _mode = SocketNotifier::Read;
15 bool _enabled = false;
19 SocketNotifier::SocketNotifier (int socket, int evTypes , bool enable)
20 : AbstractEventSource ( * new SocketNotifierPrivate )
29 SocketNotifier::Ptr SocketNotifier::create(int socket, int evTypes, bool enable )
31 return std::shared_ptr<SocketNotifier>( new SocketNotifier( socket, evTypes, enable ) );
34 void SocketNotifier::setMode(int mode)
37 if ( mode == d->_mode )
42 if ( d->_enabled && d->_socket >= 0)
43 updateFdWatch( d->_socket, d->_mode );
46 int SocketNotifier::mode() const
48 return d_func()->_mode;
51 void SocketNotifier::setEnabled( bool enabled )
54 if ( enabled == d->_enabled || d->_socket < 0 )
57 d->_enabled = enabled;
60 updateFdWatch( d->_socket, d->_mode );
65 int SocketNotifier::socket() const
67 return d_func()->_socket;
70 SignalProxy<void (const SocketNotifier &, int)> SocketNotifier::sigActivated()
72 return d_func()->_activated;
75 void SocketNotifier::onFdReady( int, int events )
77 d_func()->_activated( *this, events );
80 void SocketNotifier::onSignal( int )