Loading...
Searching...
No Matches
ASSA::SigHandler Class Reference

`#include <SigHandler.h>`

Inheritance diagram for ASSA::SigHandler:

## Public Member Functions

virtual | ~SigHandler ()
| No-op virtual destructor.
virtual int | install (int signum_, EventHandler *new_hand_, SigAction *new_disp_=0, EventHandler **old_hand_=0, SigAction *old_disp_=0)
| Add new signal handler and new disposition for the signal.
virtual int | remove (int signum_, EventHandler *eh_=0, SigAction *new_disp_=0, SigAction *old_disp_=0)
| Remove EventHandler associated with signum_.
EventHandler * | handler (int signum_, EventHandler *new_)
| Set new event handler for signal signum_ and return an existing one.
EventHandler * | handler (int signum_)
| Retrieve current event handler for signum_.

## Static Public Member Functions

static void | dispatch (int signum_)
| Here is the heart of SigHandler class.

## Protected Member Functions

int | in_range (int signum_)
| Check that signum_ is in valid range.

## Static Private Attributes

static EventHandler * | m_signal_handlers [NSIG]
| Static array that stores one user-defined event handler pointer for every signal.

## Detailed Description

Definition at line 49 of file SigHandler.h.

## Constructor & Destructor Documentation

## ~SigHandler()

virtual ASSA::SigHandler::~SigHandler | ( |  | ) |

inline virtual

No-op virtual destructor.

Definition at line 54 of file SigHandler.h.

{ /* no-op */ }

## Member Function Documentation

## dispatch()

void SigHandler::dispatch | ( | int | signum_ | ) |

static

Here is the heart of SigHandler class.

This callback function is really registered with OS to catch all of the signals EventHandlers have been installed for. dispatch () catches the signal and then calls sends the signal to the appropriate EventHandler object.

Parameters

  signum_ | signal delivered by OS.

Returns
  0 on success, -1 on error

Definition at line 129 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::dispatch", SIGHAND);
/*--- save errno ---*/
int my_errno = errno;
EventHandler *eh = m_signal_handlers[signum_];
if (eh != 0 && eh->handle_signal(signum_) == -1) {
/*---
we are in trouble, fall back to defaults
---*/
SigAction defact((C_SIG_HANDLER) SIG_DFL);
m_signal_handlers[signum_] = 0;
defact.register_action(signum_);
}
/*--- restore errno ---*/
errno = my_errno;
}
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
C_SIG_HANDLER
void(* C_SIG_HANDLER)(int)
Definition SigAction.h:28
ASSA::AutoPtrRef
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
ASSA::EventHandler
EventHandler class.
Definition EventHandler.h:103
ASSA::SigAction
Definition SigAction.h:95
ASSA::SigHandler::m_signal_handlers
static EventHandler * m_signal_handlers[NSIG]
Static array that stores one user-defined event handler pointer for every signal.
Definition SigHandler.h:127
ASSA::SIGHAND
@ SIGHAND
Class SigHandler(s) messages
Definition LogMask.h:38

References m_signal_handlers, ASSA::SIGHAND, and trace_with_mask.

Referenced by install().

## handler() [1/2]

EventHandler * SigHandler::handler | ( | int | signum_ | ) |

Retrieve current event handler for signum_.

Definition at line 57 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::handler", SIGHAND);
if ( in_range (signum_) == -1 )
return 0;
return m_signal_handlers[signum_];
}
ASSA::SigHandler::in_range
int in_range(int signum_)
Check that signum_ is in valid range.
Definition SigHandler.cpp:27

References in_range(), m_signal_handlers, ASSA::SIGHAND, and trace_with_mask.

## handler() [2/2]

EventHandler * SigHandler::handler | ( | int | signum_,
|  | EventHandler * | new_
| ) |  |

Set new event handler for signal signum_ and return an existing one.

Returns
  Pointer to the old event handler, or 0 if signum_ is out of range.

Definition at line 41 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::handler(int, EH*)", SIGHAND);
if (in_range(signum_) == -1)
return 0;
EventHandler* oh = m_signal_handlers[signum_];
m_signal_handlers[signum_] = newh_;
return oh;
}

References in_range(), m_signal_handlers, ASSA::SIGHAND, and trace_with_mask.

Referenced by install().

## in_range()

int SigHandler::in_range | ( | int | signum_ | ) |

protected

Check that signum_ is in valid range.

Returns
  0 if in range; -1 otherwise.

Definition at line 26 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::in_range", SIGHAND);
if ( signum_ >= 1 && signum_ < NSIG) {
return 0;
}
else {
DL((SIGHAND,"signum_ %d is out of range [1;%d]\n", NSIG));
return -1;
}
}
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273

References DL, ASSA::SIGHAND, and trace_with_mask.

Referenced by handler(), handler(), install(), ASSA::SigHandlers::install(), ASSA::SigHandlers::remove(), and remove().

## install()

int SigHandler::install | ( | int | signum_,
|  | EventHandler * | new_hand_,
|  | SigAction * | new_disp_ = `0`,
|  | EventHandler ** | old_hand_ = `0`,
|  | SigAction * | old_disp_ = `0`
| ) |  |

virtual

Add new signal handler and new disposition for the signal.

Note that although new_disp_ might keep C-like handler for the action, new_hand_ will really be handling delivered signal. In other words, new_disp_.sa_handler is ignored.

Parameters

  signum_ | signal number new disposition is installed for.
  new_hand_ | pointer to new EventHandler that will be handling the signal
  new_disp_ | new disposition to use in handling the signal
  old_hand_ | return old handler for the signal
  old_disp_ | return old disposition for the signal

Returns
  0 on success, -1 on error

Reimplemented in ASSA::SigHandlers.

Definition at line 69 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::install", SIGHAND);
if (in_range (signum_) == -1)
return -1;
/*--- replace old Event Handler ptr with new one in my internal
dispatch table, returning the old one.
---*/
EventHandler* eh = handler(signum_, new_hand_);
/*--- if I am given place to store, save old handler ---*/
if (old_hand_ != 0)
*old_hand_ = eh;
/*--- retrieve old disposition ---*/
if (old_disp_ != 0) {
old_disp_->retrieve_action (signum_);
old_disp_->handler ((C_SIG_HANDLER) SIG_DFL);
}
/*--- if new disposition is NULL, use null action instead ---*/
SigAction null_sa;
if (new_disp_ == 0)
new_disp_ = &null_sa;
/*--- install my dispatcher ---*/
new_disp_->handler((C_SIG_HANDLER) SigHandler::dispatch);
return new_disp_->register_action(signum_, old_disp_);
}
ASSA::SigHandler::dispatch
static void dispatch(int signum_)
Here is the heart of SigHandler class.
Definition SigHandler.cpp:130
ASSA::SigHandler::handler
EventHandler * handler(int signum_, EventHandler *new_)
Set new event handler for signal signum_ and return an existing one.
Definition SigHandler.cpp:42

References dispatch(), handler(), in_range(), ASSA::SIGHAND, and trace_with_mask.

Referenced by ASSA::Fork::Fork().

## remove()

int SigHandler::remove | ( | int | signum_,
|  | EventHandler * | eh_ = `0`,
|  | SigAction * | new_disp_ = `0`,
|  | SigAction * | old_disp_ = `0`
| ) |  |

virtual

Remove EventHandler associated with signum_.

Also, install new disposition and return an old one (if given).

Parameters

  signum_ | signal number new disposition is installed for.
  eh_ | pointer to EventHandler that is uninstalled. If eh_ is 0 (by default), all event handlers associated with signum_ will be removed.
  new_disp_ | new disposition to use in handling the signal
  old_disp_ | return old disposition for the signal

Returns
  0 on success, -1 on error

Reimplemented in ASSA::SigHandlers.

Definition at line 106 of file SigHandler.cpp.

{
trace_with_mask("SigHandler::remove", SIGHAND);
if (in_range(signum_) == -1)
return -1;
/*---
We need default disposition here if user forgot to give us one.
---*/
SigAction sa ((C_SIG_HANDLER) SIG_DFL);
if (new_disp_ == 0) {
new_disp_ = &sa;
}
m_signal_handlers[signum_] = 0;
return new_disp_->register_action (signum_, old_disp_);
}

References in_range(), m_signal_handlers, ASSA::SIGHAND, and trace_with_mask.

Referenced by ASSA::Fork::Fork().

## Member Data Documentation

## m_signal_handlers

EventHandler * SigHandler::m_signal_handlers

static private

Static array that stores one user-defined event handler pointer for every signal.

Definition at line 127 of file SigHandler.h.

Referenced by dispatch(), handler(), handler(), and remove().

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

- SigHandler.h
- SigHandler.cpp