#ifndef INCLUDED_BOBCAT_SIGNAL_
#define INCLUDED_BOBCAT_SIGNAL_

#include <vector>
#include <csignal>

namespace FBB
{

class SignalHandler
{
    friend class Signal;

    public:
        virtual ~SignalHandler();
    private:
        virtual void signalHandler(size_t signum) = 0;
};

class Signal
{
    typedef std::vector<SignalHandler *> SignalHandlerVector;
    std::vector<SignalHandlerVector> d_signals;

    // d_signals is a vector of vectors of pointers to SignalHandlers
    // the row dimension refers to the signal number
    // each row holds a SignalHandler object handling that kind of signal


    static Signal *s_signal;

    public:
        static Signal &instance();
        
        Signal(Signal const &) = delete;
        Signal &operator=(Signal const &) = delete;

        void add(size_t signum, SignalHandler &object);
        void remove(size_t signum, SignalHandler &object);

        void ignore(size_t signum);
        void reset(size_t signum);

    private:
        Signal();

        static void verify(size_t signum, char const *member);
        static void handler(int signum);                // called by remove
        void signal(int signum, sighandler_t handler);  // calls sigaction
};

}
        
#endif



