class::sys::SignalHandler

class sys::SignalHandler
  : public api::InfoObject

This class is used for handling signal events.

This class is a wrapper for the underlying POSIX signals API.

Here is an example of setting up a signal handler.

#include <sapi/sys.hpp>

volatile bool wait_for_signal;
void my_handler(int a){
   //do something
   wait_for_signal = false;
}

int main(int argc, char * argv[]){
   SignalHandler handler(my_handler);
   Signal event(SIGINT);

   wait_for_signal = true;

   //this will cause my_handler() to be executed when SIGINT is received
   event.set_handler(handler);

   //the program will stay in this loop until SIGINT is received
   while( wait_for_signal == true ){
      Timer::wait_milliseconds(1);
   }

   return 0;

}

Summary

[SignalHandler](#classsys_1_1_signal_handler_1a816856a85fe8eb3b5ace5783fd496050)(  

arg::SignalFunction signal_function
)

[SignalHandler](#classsys_1_1_signal_handler_1a63ee3b3492e19d645cb0d75737ff5f89)(  

arg::SignalActionFunction signal_action_function,
const arg::SignalFlags flags,
const arg::SignalMask mask
)

const struct sigaction * sigaction() const

Members

SignalHandler(

arg::SignalFunction signal_function
)

Constructs a signal handler.

Parameters

  • handler The function to execute with an associated signal

SignalHandler(

arg::SignalActionFunction signal_action_function,
const arg::SignalFlags flags,
const arg::SignalMask mask
)

Constructs a sigaction handler.

Parameters

  • sigaction The action to execute with an associated signal

  • flags Not used

  • mask Not used

void action_callback(int signo, siginfo_t * info, void * context);

SignalHandler handler(action_callback);

Signal alarm(Signal::INT, 10);
alarm.set_handler(handler);

const struct sigaction * sigaction() const

Accesses the sigaction member.


X

Thanks for Coming!

Subscribe to news and updates