Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TSysEvtHandler.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/base:$Id$
0002 // Author: Fons Rademakers   16/09/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TSysEvtHandler
0013 #define ROOT_TSysEvtHandler
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TSysEvtHandler                                                       //
0019 //                                                                      //
0020 // Abstract base class for handling system events.                      //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TObject.h"
0025 #include "TQObject.h"
0026 
0027 
0028 class TSysEvtHandler : public TObject, public TQObject {
0029 
0030 private:
0031    Bool_t   fIsActive;    // kTRUE if handler is active, kFALSE if not active
0032 
0033    void  *GetSender() override { return this; }  //used to set gTQSender
0034 
0035 public:
0036    TSysEvtHandler() : fIsActive(kTRUE) { }
0037    virtual ~TSysEvtHandler() { }
0038 
0039    void             Activate();
0040    void             DeActivate();
0041    Bool_t           IsActive() const { return fIsActive; }
0042 
0043    virtual void     Add()    = 0;
0044    virtual void     Remove() = 0;
0045    virtual Bool_t   Notify() override = 0;
0046 
0047    virtual void     Activated()   { Emit("Activated()"); }   //*SIGNAL*
0048    virtual void     DeActivated() { Emit("DeActivated()"); } //*SIGNAL*
0049    virtual void     Notified()    { Emit("Notified()"); }    //*SIGNAL*
0050    virtual void     Added()       { Emit("Added()"); }       //*SIGNAL*
0051    virtual void     Removed()     { Emit("Removed()"); }     //*SIGNAL*
0052 
0053    ClassDefOverride(TSysEvtHandler,0)  //ABC for handling system events
0054 };
0055 
0056 
0057 //////////////////////////////////////////////////////////////////////////
0058 //                                                                      //
0059 // TFileHandler                                                         //
0060 //                                                                      //
0061 // Handles events on file descriptors.                                  //
0062 //                                                                      //
0063 //////////////////////////////////////////////////////////////////////////
0064 
0065 class TFileHandler : public TSysEvtHandler {
0066 
0067 protected:
0068    int  fFileNum;     //File descriptor
0069    int  fMask;        //Event interest mask, either bit 1 (read), 2 (write) or both can be set
0070    int  fReadyMask;   //Readiness mask, either bit 1 (read), 2 (write) or both can be set
0071 
0072    TFileHandler(): fFileNum(-1), fMask(0), fReadyMask(0) { }
0073 
0074 public:
0075    enum { kRead = 1, kWrite = 2 };
0076 
0077    TFileHandler(int fd, int mask);
0078    virtual ~TFileHandler() { Remove(); }
0079    int             GetFd() const { return fFileNum; }
0080    void            SetFd(int fd) { fFileNum = fd; }
0081    Bool_t          Notify() override;
0082    virtual Bool_t  ReadNotify();
0083    virtual Bool_t  WriteNotify();
0084    virtual Bool_t  HasReadInterest();
0085    virtual Bool_t  HasWriteInterest();
0086    virtual void    SetInterest(Int_t mask);
0087    virtual void    ResetReadyMask() { fReadyMask = 0; }
0088    virtual void    SetReadReady() { fReadyMask |= 0x1; }
0089    virtual void    SetWriteReady() { fReadyMask |= 0x2; }
0090    virtual Bool_t  IsReadReady() const { return (fReadyMask & 0x1) == 0x1; }
0091    virtual Bool_t  IsWriteReady() const { return (fReadyMask & 0x2) == 0x2; }
0092    void            Add() override;
0093    void            Remove() override;
0094 
0095    ClassDefOverride(TFileHandler,0)  //Handles events on file descriptors
0096 };
0097 
0098 
0099 //////////////////////////////////////////////////////////////////////////
0100 //                                                                      //
0101 // TSignalHandler                                                       //
0102 //                                                                      //
0103 // Handles signals.                                                     //
0104 //                                                                      //
0105 //////////////////////////////////////////////////////////////////////////
0106 
0107 enum ESignals {
0108    kSigBus,
0109    kSigSegmentationViolation,
0110    kSigSystem,
0111    kSigPipe,
0112    kSigIllegalInstruction,
0113    kSigAbort,
0114    kSigQuit,
0115    kSigInterrupt,
0116    kSigWindowChanged,
0117    kSigAlarm,
0118    kSigChild,
0119    kSigUrgent,
0120    kSigFloatingException,
0121    kSigTermination,
0122    kSigUser1,
0123    kSigUser2
0124 };
0125 
0126 
0127 class TSignalHandler : public TSysEvtHandler {
0128 
0129 protected:
0130    ESignals    fSignal;   //Signal to be handled
0131    Bool_t      fSync;     //Synchronous or a-synchronous signal
0132    Int_t       fDelay;    //Delay handling of signal (use fDelay in Notify())
0133 
0134    TSignalHandler(): fSignal((ESignals)-1), fSync(kTRUE), fDelay(0) { }
0135 
0136 public:
0137    TSignalHandler(ESignals sig, Bool_t sync = kTRUE);
0138    virtual ~TSignalHandler() { Remove(); }
0139    void           Delay() { fDelay = 1; }
0140    void           HandleDelayedSignal();
0141    ESignals       GetSignal() const { return fSignal; }
0142    void           SetSignal(ESignals sig) { fSignal = sig; }
0143    Bool_t         IsSync() const { return fSync; }
0144    Bool_t         IsAsync() const { return !fSync; }
0145    Bool_t         Notify() override;
0146    void           Add() override;
0147    void           Remove() override;
0148 
0149    ClassDefOverride(TSignalHandler,0)  //Signal event handler
0150 };
0151 
0152 inline void TSignalHandler::HandleDelayedSignal()
0153 {
0154    if (fDelay > 1) {
0155       fDelay = 0;
0156       Notify();
0157    } else
0158       fDelay = 0;
0159 }
0160 
0161 
0162 //////////////////////////////////////////////////////////////////////////
0163 //                                                                      //
0164 // TStdExceptionHandler                                                 //
0165 //                                                                      //
0166 // Handles standard C++ exceptions.                                     //
0167 //                                                                      //
0168 //////////////////////////////////////////////////////////////////////////
0169 
0170 namespace std { class exception; }
0171 
0172 class TStdExceptionHandler : public TSysEvtHandler {
0173 
0174 public:
0175    enum EStatus { kSEProceed, kSEHandled, kSEAbort };
0176 
0177    TStdExceptionHandler();
0178    virtual ~TStdExceptionHandler() { }
0179 
0180    void     Add() override;
0181    void     Remove() override;
0182    Bool_t   Notify() override;
0183 
0184    virtual EStatus  Handle(std::exception& exc) = 0;
0185 
0186    ClassDefOverride(TStdExceptionHandler,0)  //C++ exception handler
0187 };
0188 
0189 #endif