Loading...
Searching...
No Matches
Handlers.h
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// Handlers.h
//------------------------------------------------------------------------------
// Copyright (c) 2000,2005 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//------------------------------------------------------------------------
#ifndef _Handlers_h
#define _Handlers_h
#include <sys/types.h>
#if !defined(WIN32)
# include <sys/wait.h>
#endif
#include "assa/EventHandler.h"
#include "assa/Assure.h"
namespace ASSA {
#if !defined(WIN32)
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__NetBSD__)
# define ASSAIOSIG SIGIO
#else
# define ASSAIOSIG SIGPOLL
#endif
class SIGINTHandler : public EventHandler
{
public:
SIGINTHandler();
int handle_signal (int signum_);
sig_atomic_t graceful_quit();
void resetState();
private:
sig_atomic_t m_graceful_quit;
};
inline
SIGINTHandler::
SIGINTHandler ()
: m_graceful_quit (0)
{
trace_with_mask("SIGINTHandler::SIGINTHandler", SIGHAND);
}
inline int
SIGINTHandler::
handle_signal (int signum_)
{
trace_with_mask("SIGINTHandler::handle_signal", SIGHAND);
if (signum_ == SIGINT) {
m_graceful_quit = 1;
return 0;
}
return -1;
}
inline sig_atomic_t
SIGINTHandler::
graceful_quit ()
{
return m_graceful_quit;
}
inline void
SIGINTHandler::
resetState()
{
trace_with_mask("SIGINTHandler::resetState", SIGHAND);
m_graceful_quit = 0;
}
class SIGUSR1Handler : public EventHandler
{
public:
SIGUSR1Handler() : m_count(0) {
trace_with_mask("SIGUSR1Handler::SIGUSR1Handler", SIGHAND);
}
int handle_signal(int signum_) {
trace_with_mask("SIGUSR1Handler::handle_signal()", SIGHAND);
if (signum_ == SIGUSR1) {
m_count++;
DL((TRACE, "signal count = %d\n", m_count));
return 0;
}
return -1;
}
sig_atomic_t received_count() const { return m_count; }
void resetState() { m_count = 0; }
private:
sig_atomic_t m_count;
};
class SIGUSR2Handler : public EventHandler
{
public:
SIGUSR2Handler() : m_count(0) {
trace_with_mask("SIGUSR2Handler::SIGUSR2Handler", SIGHAND);
}
int handle_signal(int signum_) {
trace_with_mask("SIGUSR2Handler::handle_signal()", SIGHAND);
if (signum_ == SIGUSR2) {
m_count++;
DL((TRACE, "signal count = %d\n", m_count));
return 0;
}
return -1;
}
sig_atomic_t received_count() const { return m_count; }
void resetState() { m_count = 0; }
private:
sig_atomic_t m_count;
};
class SIGCHLDHandler : public EventHandler
{
public:
SIGCHLDHandler() : m_child_exit_flag(0) {
trace_with_mask("SIGCHLDHandler::SIGCHLDHandler", SIGHAND);
}
int handle_signal(int signum_) {
trace_with_mask("SIGCHLDHandler::handle_signal", SIGHAND);
if (signum_ == SIGCHLD && wait(NULL) != -1) {
m_child_exit_flag = 1;
return 0;
}
return -1;
}
sig_atomic_t child_exited() { return m_child_exit_flag; }
void resetState() { m_child_exit_flag = 0; }
private:
sig_atomic_t m_child_exit_flag;
};
class SIGALRMHandler : public EventHandler
{
public:
SIGALRMHandler() : m_alarm_flag(0) {
trace_with_mask("SIGALRMHandler::SIGALRMHandler", SIGHAND);
}
int handle_signal(int signum_) {
trace_with_mask("SIGALRMHandler::handle_signal", SIGHAND);
if (signum_ == SIGALRM) {
m_alarm_flag = 1; // notice that we have seen alarm
return 0;
}
return -1;
}
sig_atomic_t alarmed () { return m_alarm_flag; }
void resetState () { m_alarm_flag = 0; }
private:
sig_atomic_t m_alarm_flag;
};
class SIGPOLLHandler : public EventHandler
{
public:
SIGPOLLHandler () {
trace_with_mask("SIGPOLLHandler", SIGHAND);
}
int handle_signal ( int signum_ ) {
trace_with_mask("SIGPOLLHandler::handle_signal", SIGHAND);
return (signum_ == ASSAIOSIG) ? 0 : -1;
}
};
#endif // !defined(WIN32)
} // end namespace ASSA
#endif
Assure.h
A collection of assert function wrappers.
EventHandler.h
An abstract interface for handling I/O events, timers, and such.
ASSAIOSIG
#define ASSAIOSIG
Definition Handlers.h:38
DL
#define DL(X)
A macro for writing debug message to the Logger.
Definition Logger.h:273
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
ASSA::EventHandler::EventHandler
EventHandler()
Constructor.
Definition EventHandler.h:165
ASSA::SIGALRMHandler::SIGALRMHandler
SIGALRMHandler()
Constructor.
Definition Handlers.h:225
ASSA::SIGALRMHandler::alarmed
sig_atomic_t alarmed()
Has alarm gone off?
Definition Handlers.h:242
ASSA::SIGALRMHandler::m_alarm_flag
sig_atomic_t m_alarm_flag
Indicator whether alarm gone off yet.
Definition Handlers.h:249
ASSA::SIGALRMHandler::resetState
void resetState()
Reset internal state.
Definition Handlers.h:245
ASSA::SIGALRMHandler::handle_signal
int handle_signal(int signum_)
Receive ALRM signal.
Definition Handlers.h:231
ASSA::SIGCHLDHandler::resetState
void resetState()
Reset child's exit state.
Definition Handlers.h:212
ASSA::SIGCHLDHandler::handle_signal
int handle_signal(int signum_)
Receive CHLD signal.
Definition Handlers.h:197
ASSA::SIGCHLDHandler::m_child_exit_flag
sig_atomic_t m_child_exit_flag
Child exit's state.
Definition Handlers.h:216
ASSA::SIGCHLDHandler::child_exited
sig_atomic_t child_exited()
Did child exit?
Definition Handlers.h:208
ASSA::SIGCHLDHandler::SIGCHLDHandler
SIGCHLDHandler()
Constructor.
Definition Handlers.h:191
ASSA::SIGINTHandler::handle_signal
int handle_signal(int signum_)
Receive SIGINT signal.
Definition Handlers.h:80
ASSA::SIGINTHandler::m_graceful_quit
sig_atomic_t m_graceful_quit
flag that indicates whether signal was caught.
Definition Handlers.h:67
ASSA::SIGINTHandler::SIGINTHandler
SIGINTHandler()
constructor
Definition Handlers.h:72
ASSA::SIGINTHandler::graceful_quit
sig_atomic_t graceful_quit()
Indicates whether graceful quit signal has been raised by the signal handler.
Definition Handlers.h:93
ASSA::SIGINTHandler::resetState
void resetState()
Reset state of the object to initial.
Definition Handlers.h:100
ASSA::SIGPOLLHandler::SIGPOLLHandler
SIGPOLLHandler()
Constructor.
Definition Handlers.h:266
ASSA::SIGPOLLHandler::handle_signal
int handle_signal(int signum_)
Catch and absorb SIGPOLL signal.
Definition Handlers.h:271
ASSA::SIGUSR1Handler::resetState
void resetState()
Set received signals count back to 0.
Definition Handlers.h:140
ASSA::SIGUSR1Handler::m_count
sig_atomic_t m_count
Received signals count.
Definition Handlers.h:144
ASSA::SIGUSR1Handler::handle_signal
int handle_signal(int signum_)
Catch USR1 signal and increment count.
Definition Handlers.h:123
ASSA::SIGUSR1Handler::received_count
sig_atomic_t received_count() const
Report count of received signals.
Definition Handlers.h:136
ASSA::SIGUSR1Handler::SIGUSR1Handler
SIGUSR1Handler()
Constructor.
Definition Handlers.h:117
ASSA::SIGUSR2Handler::received_count
sig_atomic_t received_count() const
Report count of received signals.
Definition Handlers.h:174
ASSA::SIGUSR2Handler::handle_signal
int handle_signal(int signum_)
Catch USR2 signal and increment count.
Definition Handlers.h:161
ASSA::SIGUSR2Handler::SIGUSR2Handler
SIGUSR2Handler()
Constructor.
Definition Handlers.h:155
ASSA::SIGUSR2Handler::m_count
sig_atomic_t m_count
Received signals count.
Definition Handlers.h:182
ASSA::SIGUSR2Handler::resetState
void resetState()
Set received signals count back to 0.
Definition Handlers.h:178
ASSA
Definition Acceptor.h:40
ASSA::SIGHAND
@ SIGHAND
Class SigHandler(s) messages.
Definition LogMask.h:38
ASSA::TRACE
@ TRACE
Function call trace.
Definition LogMask.h:26