Fixposition SDK 0.0.0-heads/main-0-g4e80ed3
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
fpsdk::common::app::SigIntHelper Class Reference

Helper to catch SIGINT (CTRL-c) More...

#include <app.hpp>

Public Member Functions

 SigIntHelper (const bool warn=true)
 Constructor.
 
 ~SigIntHelper ()
 Destructor.
 
bool ShouldAbort ()
 Check if signal was raised and we should abort.
 
bool WaitAbort (const uint32_t millis=0)
 Wait (block) until signal is raised and we should abort.
 

Detailed Description

Helper to catch SIGINT (CTRL-c)

On construction this installs a handler for SIGINT. On destruction it sets the handler back to its previous state. Note that signal handlers are global and therefore you can only use one SigIntHelper in a app.

When the signal is received it (optionally) prints a message and ShouldAbort() and WaitAbort() react accordingly. Also, the signal handler is reset to the previous state (typically, but not necessarily, the default handler) and any further SIGINT triggers the previously set handler. This allows for apps to handle the the first SIGINT nicely and allows the user to "SIGINT again" and trigger the previous handler (typically the default one, i.e. "hard abort").

Example:

SigIntHelper sigint;
while (!sigint.ShouldAbort()) {
// do stuff..
}
if (sigint.ShouldAbort()) {
INFO("We've been asked to stop");
}
Helper to catch SIGINT (CTRL-c)
Definition app.hpp:64
bool ShouldAbort()
Check if signal was raised and we should abort.
#define INFO(...)
Print a info message.
Definition logging.hpp:89

Definition at line 63 of file app.hpp.

Constructor & Destructor Documentation

◆ SigIntHelper()

fpsdk::common::app::SigIntHelper::SigIntHelper ( const bool warn = true)

Constructor.

Parameters
[in]warnPrint a WARNING() (true, default) or a DEBUG() (false) on signal

Member Function Documentation

◆ ShouldAbort()

bool fpsdk::common::app::SigIntHelper::ShouldAbort ( )

Check if signal was raised and we should abort.

Returns
true if signal was raised and we should abort, false otherwise

◆ WaitAbort()

bool fpsdk::common::app::SigIntHelper::WaitAbort ( const uint32_t millis = 0)

Wait (block) until signal is raised and we should abort.

Parameters
[in]millisWait at most this long [ms], 0 = forever
Returns
true if the signal was raised, false if timeout expired

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