libzypp: zyppng::SocketNotifier Class Reference

libzypp 17.38.14

zyppng::SocketNotifier Class Reference

`#include <zypp-core/ng/base/socketnotifier.h>`

Inheritance diagram for zyppng::SocketNotifier:

## Public Types
using | Ptr = std::shared_ptr<SocketNotifier>
using | WeakPtr = std::weak_ptr<SocketNotifier>
using | EventTypes = AbstractEventSource::EventTypes
Public Types inherited from zyppng::AbstractEventSource
enum | EventTypes { Read = 0x01 , Write = 0x02 , Exception = 0x04 , Error = 0x08 }
Public Types inherited from zyppng::Base
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
void | setMode (int mode)
int | mode () const
void | setEnabled (bool enabled=true)
int | socket () const
SignalProxy< void(const SocketNotifier &sock, int evTypes)> | sigActivated ()
void | onFdReady (int, int events) override
void | onSignal (int signal) override
Public Member Functions inherited from zyppng::AbstractEventSource
| AbstractEventSource ()
| AbstractEventSource (AbstractEventSourcePrivate &dd)
| ~AbstractEventSource () override
std::weak_ptr< EventDispatcher > | eventDispatcher () const
Public Member Functions inherited from zyppng::Base
| Base ()
virtual | ~Base ()
WeakPtr | parent () const
void | addChild (const Base::Ptr &child)
void | removeChild (const Ptr &child)
const std::unordered_set< Ptr > & | children () const
std::thread::id | threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > | findChildren () const
template<typename T>
std::shared_ptr< T > | shared_this () const
template<typename T>
std::shared_ptr< T > | shared_this ()
template<typename T>
std::weak_ptr< T > | weak_this () const
template<typename T>
std::weak_ptr< T > | weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
void | setData (uint32_t quark, zypp::AutoDispose< void * > data)
void * | data (uint32_t quark)
void | clearData (uint32_t quark)

## Static Public Member Functions
static Ptr | create (int socket, int evTypes, bool enable=true)
Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) | make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Protected Member Functions
| SocketNotifier (int socket, int evTypes)
Protected Member Functions inherited from zyppng::AbstractEventSource
void | updateFdWatch (int fd, int mode)
void | removeFdWatch (int fd)
Protected Member Functions inherited from zyppng::Base
| Base (BasePrivate &dd)

## Additional Inherited Members
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivate > | d_ptr

## Detailed Description

The SocketNotifier class provides a generic way to monitor activity on a file descriptors.

Once a file descriptor was created using either low level OS API or was created by a 3rd party library, the SocketNotifier can be created to integrate the file descriptor into the event loop.

Each file descriptor can be monitored for all types of activiy supported by the base class

See also
  AbstractEventSource.

// Example code that uses a pipe() to communicate between a thread and the main loop
zyppng::EventLoop::Ptr loop = zyppng::EventLoop::create();
int wakeupPipe[2] = { -1, -1 };
pipe2 ( wakeupPipe, O_NONBLOCK );
//listen for activity on the event source
zyppng::SocketNotifier::Ptr notifier = zyppng::SocketNotifier::create( wakeupPipe[0], zyppng::SocketNotifier::Read, false );
notifier->sigActivated().connect([ &loop ]( const zyppng::SocketNotifier &notifier, int ) {
char dummy;
//read all available data
while ( read( notifier.socket(), &dummy, 1 ) > 0 ) {
std::cout<<dummy;
}
std::cout << std::endl;
loop->quit();
});
notifier->setEnabled( true );
std::thread t( [ &wakeupPipe ](){
const char * test = "Some text";
std::chrono::milliseconds dura( 1000 );
std::this_thread::sleep_for( dura );
write( wakeupPipe[1], test, 9 );
std::this_thread::sleep_for( dura );
return;
});
loop->run();
std::cout << "Bye Bye" << std::endl;
t.join();
zyppng::AbstractEventSource::Read
@ Read
Definition abstracteventsource.h:47
zyppng::EventLoop::Ptr
EventLoopRef Ptr
Definition eventloop.h:47
zyppng::EventLoop::create
static Ptr create(GMainContext *ctx=nullptr)
Definition eventloop_glib.cc:29
zyppng::SocketNotifier
Definition socketnotifier.h:69
zyppng::SocketNotifier::Ptr
std::shared_ptr< SocketNotifier > Ptr
Definition socketnotifier.h:73
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::setEnabled
void setEnabled(bool enabled=true)
Definition socketnotifier.cc:57
zypp::base::sysconfig::write
bool write(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Add or change a value in sysconfig file path_r.
Definition sysconfig.cc:80

Definition at line 68 of file socketnotifier.h.

## Member Typedef Documentation

## ◆ Ptr

using zyppng::SocketNotifier::Ptr = std::shared_ptr<SocketNotifier>

Definition at line 73 of file socketnotifier.h.

## ◆ WeakPtr

using zyppng::SocketNotifier::WeakPtr = std::weak_ptr<SocketNotifier>

Definition at line 74 of file socketnotifier.h.

## ◆ EventTypes

using zyppng::SocketNotifier::EventTypes = AbstractEventSource::EventTypes

Definition at line 76 of file socketnotifier.h.

## Constructor & Destructor Documentation

## ◆ SocketNotifier()

zyppng::SocketNotifier::SocketNotifier | ( | int | socket,
|  | int | evTypes )
| protected

Definition at line 25 of file socketnotifier.cc.

## Member Function Documentation

## ◆ create()

SocketNotifier::Ptr zyppng::SocketNotifier::create | ( | int | socket,
|  | int | evTypes,
|  | bool | enable = true )
| static

Returns a new SocketNotifier

Parameters

  socket | this is the filedescriptor to be modified
  evTypes | the event types that should be monitored

See also
  AbstractEventSource::EventTypes

Parameters

  enable | If set to true the notifier is enabled right away, otherwise

See also
  setEnabled needs to be called explicitely

Definition at line 33 of file socketnotifier.cc.

## ◆ setMode()

void zyppng::SocketNotifier::setMode | ( | int | mode | ) |

Update the fd watch to the mode specified.

See also
  AbstractEventSource::EventTypes

Definition at line 40 of file socketnotifier.cc.

## ◆ mode()

int zyppng::SocketNotifier::mode | ( |  | ) | const

Returns the current mode used to monitor the file descriptor

See also
  AbstractEventSource::EventTypes

Definition at line 52 of file socketnotifier.cc.

## ◆ setEnabled()

void zyppng::SocketNotifier::setEnabled | ( | bool | enabled = true | ) |

Enables or disables the SocketNotifier

Definition at line 57 of file socketnotifier.cc.

## ◆ socket()

int zyppng::SocketNotifier::socket | ( |  | ) | const

Returns the monitored file descriptor

Definition at line 71 of file socketnotifier.cc.

## ◆ sigActivated()

SignalProxy< void(const SocketNotifier &, int)> zyppng::SocketNotifier::sigActivated | ( |  | ) |

Emitted when there is activity on the socket according to the requested mode

Definition at line 76 of file socketnotifier.cc.

## ◆ onFdReady()

void zyppng::SocketNotifier::onFdReady | ( | int | fd,
|  | int | events )
| overridevirtual

Called by the

See also
  EventDispatcher when activity was detected on a registered fd. The events are set according to the activity on the file descriptor.

Implements zyppng::AbstractEventSource.

Definition at line 81 of file socketnotifier.cc.

## ◆ onSignal()

void zyppng::SocketNotifier::onSignal | ( | int | signal | ) |
| overridevirtual

Called when a event source has registered to receive unix signals

Note
  this is not supported yet

Implements zyppng::AbstractEventSource.

Definition at line 86 of file socketnotifier.cc.

The documentation for this class was generated from the following files:

- zypp-core/ng/base/socketnotifier.h
- zypp-core/ng/base/socketnotifier.cc