Ignition Common

API Reference

4.4.0

Register callbacks that get triggered on SIGINT and SIGTERM. More...

#include <SignalHandler.hh>

Public Member Functions

 SignalHandler ()
 Constructor. More...
 
virtual ~SignalHandler ()
 Destructor. More...
 
bool AddCallback (std::function< void(int)> _cb)
 Add a callback to execute when a signal is received. More...
 
bool Initialized () const
 Get whether the signal handlers were successfully initialized. More...
 

Protected Member Functions

virtual void SetInitialized (const bool _init)
 Set whether the signal handler was successfully initialized. This function is here for testing purposes, and if for some reason a person needs to create a subclass to control the initialization value. More...
 

Detailed Description

Register callbacks that get triggered on SIGINT and SIGTERM.

This class is a thread-safe interface to system signals (SIGINT and SIGTERM). Use the AddCallback(std::function<void(int)>) function to register callbacks that should be called when a SIGINT or SIGTERM is triggered.

Example using a lambda callback:

SignalHandler handler;
handler.AddCallback([] (int _sig)
{
printf("Signal[%d] received\n", _sig);
});

Constructor & Destructor Documentation

◆ SignalHandler()

Constructor.

◆ ~SignalHandler()

virtual ~SignalHandler ( )
virtual

Destructor.

Member Function Documentation

◆ AddCallback()

bool AddCallback ( std::function< void(int)>  _cb)

Add a callback to execute when a signal is received.

Parameters
[in]_cbCallback to execute.
Returns
True if the callback was added. A callback may not be added if the SignalHandler was not successfully initialized.
See also
bool Initialized() const

◆ Initialized()

bool Initialized ( ) const

Get whether the signal handlers were successfully initialized.

Returns
True if the signal handlers were successfully created.

◆ SetInitialized()

virtual void SetInitialized ( const bool  _init)
protectedvirtual

Set whether the signal handler was successfully initialized. This function is here for testing purposes, and if for some reason a person needs to create a subclass to control the initialization value.

Parameters
[in]_initNew value of the initialized member variabl.e

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