Logo ROOT  
Reference Guide
TSysEvtHandler.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 16/09/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TSysEvtHandler
13 #define ROOT_TSysEvtHandler
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TSysEvtHandler //
19 // //
20 // Abstract base class for handling system events. //
21 // //
22 //////////////////////////////////////////////////////////////////////////
23 
24 #include "TObject.h"
25 #include "TQObject.h"
26 
27 
28 class TSysEvtHandler : public TObject, public TQObject {
29 
30 private:
31  Bool_t fIsActive; // kTRUE if handler is active, kFALSE if not active
32 
33  void *GetSender() { return this; } //used to set gTQSender
34 
35 public:
37  virtual ~TSysEvtHandler() { }
38 
39  void Activate();
40  void DeActivate();
41  Bool_t IsActive() const { return fIsActive; }
42 
43  virtual void Add() = 0;
44  virtual void Remove() = 0;
45  virtual Bool_t Notify() = 0;
46 
47  virtual void Activated() { Emit("Activated()"); } //*SIGNAL*
48  virtual void DeActivated() { Emit("DeActivated()"); } //*SIGNAL*
49  virtual void Notified() { Emit("Notified()"); } //*SIGNAL*
50  virtual void Added() { Emit("Added()"); } //*SIGNAL*
51  virtual void Removed() { Emit("Removed()"); } //*SIGNAL*
52 
53  ClassDef(TSysEvtHandler,0) //ABC for handling system events
54 };
55 
56 
57 //////////////////////////////////////////////////////////////////////////
58 // //
59 // TFileHandler //
60 // //
61 // Handles events on file descriptors. //
62 // //
63 //////////////////////////////////////////////////////////////////////////
64 
65 class TFileHandler : public TSysEvtHandler {
66 
67 protected:
68  int fFileNum; //File descriptor
69  int fMask; //Event interest mask, either bit 1 (read), 2 (write) or both can be set
70  int fReadyMask; //Readiness mask, either bit 1 (read), 2 (write) or both can be set
71 
73 
74 public:
75  enum { kRead = 1, kWrite = 2 };
76 
77  TFileHandler(int fd, int mask);
78  virtual ~TFileHandler() { Remove(); }
79  int GetFd() const { return fFileNum; }
80  void SetFd(int fd) { fFileNum = fd; }
81  virtual Bool_t Notify();
82  virtual Bool_t ReadNotify();
83  virtual Bool_t WriteNotify();
84  virtual Bool_t HasReadInterest();
85  virtual Bool_t HasWriteInterest();
86  virtual void SetInterest(Int_t mask);
87  virtual void ResetReadyMask() { fReadyMask = 0; }
88  virtual void SetReadReady() { fReadyMask |= 0x1; }
89  virtual void SetWriteReady() { fReadyMask |= 0x2; }
90  virtual Bool_t IsReadReady() const { return (fReadyMask & 0x1) == 0x1; }
91  virtual Bool_t IsWriteReady() const { return (fReadyMask & 0x2) == 0x2; }
92  virtual void Add();
93  virtual void Remove();
94 
95  ClassDef(TFileHandler,0) //Handles events on file descriptors
96 };
97 
98 
99 //////////////////////////////////////////////////////////////////////////
100 // //
101 // TSignalHandler //
102 // //
103 // Handles signals. //
104 // //
105 //////////////////////////////////////////////////////////////////////////
106 
107 enum ESignals {
123  kSigUser2
124 };
125 
126 
128 
129 protected:
130  ESignals fSignal; //Signal to be handled
131  Bool_t fSync; //Synchronous or a-synchronous signal
132  Int_t fDelay; //Delay handling of signal (use fDelay in Notify())
133 
135 
136 public:
137  TSignalHandler(ESignals sig, Bool_t sync = kTRUE);
138  virtual ~TSignalHandler() { Remove(); }
139  void Delay() { fDelay = 1; }
140  void HandleDelayedSignal();
141  ESignals GetSignal() const { return fSignal; }
142  void SetSignal(ESignals sig) { fSignal = sig; }
143  Bool_t IsSync() const { return fSync; }
144  Bool_t IsAsync() const { return !fSync; }
145  virtual Bool_t Notify();
146  virtual void Add();
147  virtual void Remove();
148 
149  ClassDef(TSignalHandler,0) //Signal event handler
150 };
151 
153 {
154  if (fDelay > 1) {
155  fDelay = 0;
156  Notify();
157  } else
158  fDelay = 0;
159 }
160 
161 
162 //////////////////////////////////////////////////////////////////////////
163 // //
164 // TStdExceptionHandler //
165 // //
166 // Handles standard C++ exceptions. //
167 // //
168 //////////////////////////////////////////////////////////////////////////
169 
170 namespace std { class exception; }
171 
173 
174 public:
176 
178  virtual ~TStdExceptionHandler() { }
179 
180  virtual void Add();
181  virtual void Remove();
182  virtual Bool_t Notify();
183 
184  virtual EStatus Handle(std::exception& exc) = 0;
185 
186  ClassDef(TStdExceptionHandler,0) //C++ exception handler
187 };
188 
189 #endif
TStdExceptionHandler::kSEAbort
@ kSEAbort
Definition: TSysEvtHandler.h:175
TSysEvtHandler
Abstract base class for handling system events.
Definition: TSysEvtHandler.h:28
TFileHandler::HasWriteInterest
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
Definition: TSysEvtHandler.cxx:108
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TSignalHandler::~TSignalHandler
virtual ~TSignalHandler()
Definition: TSysEvtHandler.h:138
kSigPipe
@ kSigPipe
Definition: TSysEvtHandler.h:111
TFileHandler::WriteNotify
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
Definition: TSysEvtHandler.cxx:91
TFileHandler::TFileHandler
TFileHandler()
Definition: TSysEvtHandler.h:72
TSysEvtHandler::DeActivated
virtual void DeActivated()
Definition: TSysEvtHandler.h:48
TFileHandler::SetFd
void SetFd(int fd)
Definition: TSysEvtHandler.h:80
TSysEvtHandler::IsActive
Bool_t IsActive() const
Definition: TSysEvtHandler.h:41
kSigBus
@ kSigBus
Definition: TSysEvtHandler.h:108
kSigInterrupt
@ kSigInterrupt
Definition: TSysEvtHandler.h:115
TSysEvtHandler::Add
virtual void Add()=0
TSignalHandler::fSignal
ESignals fSignal
Definition: TSysEvtHandler.h:130
TFileHandler::Remove
virtual void Remove()
Remove file event handler from system file handler list.
Definition: TSysEvtHandler.cxx:137
TSignalHandler
Definition: TSysEvtHandler.h:127
TFileHandler::Add
virtual void Add()
Add file event handler to system file handler list.
Definition: TSysEvtHandler.cxx:126
TSignalHandler::Delay
void Delay()
Definition: TSysEvtHandler.h:139
TStdExceptionHandler::Handle
virtual EStatus Handle(std::exception &exc)=0
TFileHandler::ResetReadyMask
virtual void ResetReadyMask()
Definition: TSysEvtHandler.h:87
Int_t
int Int_t
Definition: RtypesCore.h:45
TSignalHandler::IsSync
Bool_t IsSync() const
Definition: TSysEvtHandler.h:143
TStdExceptionHandler::TStdExceptionHandler
TStdExceptionHandler()
Handle standard C++ exceptions intercepted by the TSystem::Run().
Definition: TSysEvtHandler.cxx:202
TStdExceptionHandler::kSEHandled
@ kSEHandled
Definition: TSysEvtHandler.h:175
TSignalHandler::fSync
Bool_t fSync
Definition: TSysEvtHandler.h:131
TStdExceptionHandler::Remove
virtual void Remove()
Remove std::exception handler from system handler list.
Definition: TSysEvtHandler.cxx:220
TFileHandler::SetInterest
virtual void SetInterest(Int_t mask)
Set interest mask to 'mask'.
Definition: TSysEvtHandler.cxx:116
ESignals
ESignals
Definition: TSysEvtHandler.h:107
TStdExceptionHandler::Add
virtual void Add()
Add std::exception handler to system handler list.
Definition: TSysEvtHandler.cxx:209
TSignalHandler::fDelay
Int_t fDelay
Definition: TSysEvtHandler.h:132
kSigUser2
@ kSigUser2
Definition: TSysEvtHandler.h:123
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFileHandler::IsWriteReady
virtual Bool_t IsWriteReady() const
Definition: TSysEvtHandler.h:91
TSysEvtHandler::Removed
virtual void Removed()
Definition: TSysEvtHandler.h:51
TFileHandler::fReadyMask
int fReadyMask
Definition: TSysEvtHandler.h:70
bool
TSysEvtHandler::fIsActive
Bool_t fIsActive
Definition: TSysEvtHandler.h:31
TSignalHandler::GetSignal
ESignals GetSignal() const
Definition: TSysEvtHandler.h:141
kSigIllegalInstruction
@ kSigIllegalInstruction
Definition: TSysEvtHandler.h:112
TFileHandler::ReadNotify
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
Definition: TSysEvtHandler.cxx:81
TSignalHandler::HandleDelayedSignal
void HandleDelayedSignal()
Definition: TSysEvtHandler.h:152
TFileHandler::kRead
@ kRead
Definition: TSysEvtHandler.h:75
TQObject.h
TStdExceptionHandler::kSEProceed
@ kSEProceed
Definition: TSysEvtHandler.h:175
TSignalHandler::IsAsync
Bool_t IsAsync() const
Definition: TSysEvtHandler.h:144
TQObject
This is the ROOT implementation of the Qt object communication mechanism (see also http://www....
Definition: TQObject.h:48
kSigWindowChanged
@ kSigWindowChanged
Definition: TSysEvtHandler.h:116
kSigChild
@ kSigChild
Definition: TSysEvtHandler.h:118
TStdExceptionHandler::Notify
virtual Bool_t Notify()
Notify when signal occurs.
Definition: TSysEvtHandler.cxx:231
TSysEvtHandler::Notify
virtual Bool_t Notify()=0
This method must be overridden to handle object notification.
TFileHandler::kWrite
@ kWrite
Definition: TSysEvtHandler.h:75
kSigAbort
@ kSigAbort
Definition: TSysEvtHandler.h:113
TFileHandler::~TFileHandler
virtual ~TFileHandler()
Definition: TSysEvtHandler.h:78
TSignalHandler::Notify
virtual Bool_t Notify()
Notify when signal occurs.
Definition: TSysEvtHandler.cxx:159
TFileHandler::GetFd
int GetFd() const
Definition: TSysEvtHandler.h:79
TSysEvtHandler::DeActivate
void DeActivate()
De-activate a system event handler.
Definition: TSysEvtHandler.cxx:46
kSigTermination
@ kSigTermination
Definition: TSysEvtHandler.h:121
TSysEvtHandler::Added
virtual void Added()
Definition: TSysEvtHandler.h:50
TSysEvtHandler::Remove
virtual void Remove()=0
TStdExceptionHandler::EStatus
EStatus
Definition: TSysEvtHandler.h:175
kSigSystem
@ kSigSystem
Definition: TSysEvtHandler.h:110
TSysEvtHandler::TSysEvtHandler
TSysEvtHandler()
Definition: TSysEvtHandler.h:36
TFileHandler::SetWriteReady
virtual void SetWriteReady()
Definition: TSysEvtHandler.h:89
TStdExceptionHandler::~TStdExceptionHandler
virtual ~TStdExceptionHandler()
Definition: TSysEvtHandler.h:178
TSysEvtHandler::~TSysEvtHandler
virtual ~TSysEvtHandler()
Definition: TSysEvtHandler.h:37
TFileHandler::fFileNum
int fFileNum
Definition: TSysEvtHandler.h:68
TSysEvtHandler::Notified
virtual void Notified()
Definition: TSysEvtHandler.h:49
TFileHandler::SetReadReady
virtual void SetReadReady()
Definition: TSysEvtHandler.h:88
kSigUrgent
@ kSigUrgent
Definition: TSysEvtHandler.h:119
TSignalHandler::Add
virtual void Add()
Add signal handler to system signal handler list.
Definition: TSysEvtHandler.cxx:168
TObject.h
TSignalHandler::SetSignal
void SetSignal(ESignals sig)
Definition: TSysEvtHandler.h:142
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TFileHandler::fMask
int fMask
Definition: TSysEvtHandler.h:69
kSigFloatingException
@ kSigFloatingException
Definition: TSysEvtHandler.h:120
kSigAlarm
@ kSigAlarm
Definition: TSysEvtHandler.h:117
TFileHandler::IsReadReady
virtual Bool_t IsReadReady() const
Definition: TSysEvtHandler.h:90
TFileHandler
Definition: TSysEvtHandler.h:65
TSignalHandler::Remove
virtual void Remove()
Remove signal handler from system signal handler list.
Definition: TSysEvtHandler.cxx:179
TSysEvtHandler::GetSender
void * GetSender()
Definition: TSysEvtHandler.h:33
TSignalHandler::TSignalHandler
TSignalHandler()
Definition: TSysEvtHandler.h:134
kSigUser1
@ kSigUser1
Definition: TSysEvtHandler.h:122
kSigSegmentationViolation
@ kSigSegmentationViolation
Definition: TSysEvtHandler.h:109
kSigQuit
@ kSigQuit
Definition: TSysEvtHandler.h:114
TStdExceptionHandler
Definition: TSysEvtHandler.h:172
TSysEvtHandler::Activate
void Activate()
Activate a system event handler.
Definition: TSysEvtHandler.cxx:32
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TFileHandler::HasReadInterest
virtual Bool_t HasReadInterest()
True if handler is interested in read events.
Definition: TSysEvtHandler.cxx:100
TSysEvtHandler::Activated
virtual void Activated()
Definition: TSysEvtHandler.h:47
int
TFileHandler::Notify
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
Definition: TSysEvtHandler.cxx:71