/*
* freescope - Free source browser
* Copyright (C) 2001 Olivier Deme
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* FILE: siglink.h
*
* DESCRIPTION: This file declares the SIGLINK class definition.
* Siglink holds a vector of queues.
* Each vector index correspond to a a Unix signal number, and
* each element of the queue is a structure containing:
* - a pointer to a callback function
* - a pointer to void passed as argument when the callback
* function is called.
*/
#ifndef _SIGLINK_H_
#define _SIGLINK_H_
/************/
/* INCLUDES */
/************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <string>
#include <vector>
#include <map>
#include "defs.h"
/**********/
/* MACROS */
/**********/
#define SIGLINK (SigLink::instance())
/********************/
/* PRE-DECLARATIONS */
/********************/
class SigLink;
class SigLink_Exception;
/********************/
/* TYPE DEFINITIONS */
/********************/
typedef void (*Handler) (int signo, void* arg);
typedef map<Handler, void*, less<Handler> > Handler_map;
typedef map<int, Handler_map*, less<int> > Signal_map;
/*********************/
/* CLASS DEFINITIONS */
/*********************/
class SigLink
{
// CONSTRUCTORS
private:
SigLink() {};
public:
virtual ~SigLink();
// METHODS
public:
void Register (int signo, Handler handler, void* arg = NULL)
throw (bad_alloc, SigLink_Exception);
void Deregister (int signo, Handler handler)
throw (SigLink_Exception);
static void SigHandler (int signo)
throw ();
static SigLink* instance () throw (bad_alloc);
// ATTRIBUTES
protected:
static Signal_map m_signalhdl;
private:
static SigLink* m_instance;
};
class SigLink_Exception
{
// FRIENDS
friend class SigLink;
// TYPE DEFINITIONS
typedef enum
{
SIGLINK_SIGNAL_FAILED,
SIGLINK_NO_SUCH_HANDLER
} Siglink_error;
// CONSTRUCTORS
private:
SigLink_Exception () {};
SigLink_Exception (Siglink_error error) { m_error = error; }
// METHODS
public:
string what () const throw ();
// ATTRIBUTES
private:
Siglink_error m_error;
};
#endif // _SIGLINK_H_
syntax highlighted by Code2HTML, v. 0.9.1