ROOT  6.06/09
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 #ifndef ROOT_TObject
25 #include "TObject.h"
26 #endif
27 #ifndef ROOT_TQObject
28 #include "TQObject.h"
29 #endif
30 
31 
32 class TSysEvtHandler : public TObject, public TQObject {
33 
34 private:
35  Bool_t fIsActive; // kTRUE if handler is active, kFALSE if not active
36 
37  void *GetSender() { return this; } //used to set gTQSender
38 
39 public:
40  TSysEvtHandler() : fIsActive(kTRUE) { }
41  virtual ~TSysEvtHandler() { }
42 
43  void Activate();
44  void DeActivate();
45  Bool_t IsActive() const { return fIsActive; }
46 
47  virtual void Add() = 0;
48  virtual void Remove() = 0;
49  virtual Bool_t Notify() = 0;
50 
51  virtual void Activated() { Emit("Activated()"); } //*SIGNAL*
52  virtual void DeActivated() { Emit("DeActivated()"); } //*SIGNAL*
53  virtual void Notified() { Emit("Notified()"); } //*SIGNAL*
54  virtual void Added() { Emit("Added()"); } //*SIGNAL*
55  virtual void Removed() { Emit("Removed()"); } //*SIGNAL*
56 
57  ClassDef(TSysEvtHandler,0) //ABC for handling system events
58 };
59 
60 
61 //////////////////////////////////////////////////////////////////////////
62 // //
63 // TFileHandler //
64 // //
65 // Handles events on file descriptors. //
66 // //
67 //////////////////////////////////////////////////////////////////////////
68 
69 class TFileHandler : public TSysEvtHandler {
70 
71 protected:
72  int fFileNum; //File descriptor
73  int fMask; //Event interest mask, either bit 1 (read), 2 (write) or both can be set
74  int fReadyMask; //Readiness mask, either bit 1 (read), 2 (write) or both can be set
75 
76  TFileHandler(): fFileNum(-1), fMask(0), fReadyMask(0) { }
77 
78 public:
79  enum { kRead = 1, kWrite = 2 };
80 
81  TFileHandler(int fd, int mask);
82  virtual ~TFileHandler() { Remove(); }
83  int GetFd() const { return fFileNum; }
84  void SetFd(int fd) { fFileNum = fd; }
85  virtual Bool_t Notify();
86  virtual Bool_t ReadNotify();
87  virtual Bool_t WriteNotify();
88  virtual Bool_t HasReadInterest();
89  virtual Bool_t HasWriteInterest();
90  virtual void SetInterest(Int_t mask);
91  virtual void ResetReadyMask() { fReadyMask = 0; }
92  virtual void SetReadReady() { fReadyMask |= 0x1; }
93  virtual void SetWriteReady() { fReadyMask |= 0x2; }
94  virtual Bool_t IsReadReady() const { return (fReadyMask & 0x1) == 0x1; }
95  virtual Bool_t IsWriteReady() const { return (fReadyMask & 0x2) == 0x2; }
96  virtual void Add();
97  virtual void Remove();
98 
99  ClassDef(TFileHandler,0) //Handles events on file descriptors
100 };
101 
102 
103 //////////////////////////////////////////////////////////////////////////
104 // //
105 // TSignalHandler //
106 // //
107 // Handles signals. //
108 // //
109 //////////////////////////////////////////////////////////////////////////
110 
111 enum ESignals {
127 };
128 
129 
131 
132 protected:
133  ESignals fSignal; //Signal to be handled
134  Bool_t fSync; //Synchronous or a-synchronous signal
135  Int_t fDelay; //Delay handling of signal (use fDelay in Notify())
136 
137  TSignalHandler(): fSignal((ESignals)-1), fSync(kTRUE), fDelay(0) { }
138 
139 public:
140  TSignalHandler(ESignals sig, Bool_t sync = kTRUE);
141  virtual ~TSignalHandler() { Remove(); }
142  void Delay() { fDelay = 1; }
143  void HandleDelayedSignal();
144  ESignals GetSignal() const { return fSignal; }
145  void SetSignal(ESignals sig) { fSignal = sig; }
146  Bool_t IsSync() const { return fSync; }
147  Bool_t IsAsync() const { return !fSync; }
148  virtual Bool_t Notify();
149  virtual void Add();
150  virtual void Remove();
151 
152  ClassDef(TSignalHandler,0) //Signal event handler
153 };
154 
156 {
157  if (fDelay > 1) {
158  fDelay = 0;
159  Notify();
160  } else
161  fDelay = 0;
162 }
163 
164 
165 //////////////////////////////////////////////////////////////////////////
166 // //
167 // TStdExceptionHandler //
168 // //
169 // Handles standard C++ exceptions. //
170 // //
171 //////////////////////////////////////////////////////////////////////////
172 
173 namespace std { class exception; }
174 
176 
177 public:
179 
181  virtual ~TStdExceptionHandler() { }
182 
183  virtual void Add();
184  virtual void Remove();
185  virtual Bool_t Notify();
186 
187  virtual EStatus Handle(std::exception& exc) = 0;
188 
189  ClassDef(TStdExceptionHandler,0) //C++ exception handler
190 };
191 
192 #endif
virtual void SetWriteReady()
virtual ~TSignalHandler()
virtual ~TStdExceptionHandler()
virtual void DeActivated()
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
Bool_t IsSync() const
virtual Bool_t IsReadReady() const
virtual void Add()=0
virtual ~TFileHandler()
virtual void Add()
Add signal handler to system signal handler list.
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:53
virtual void Remove()
Remove std::exception handler from system handler list.
virtual void Add()
Add file event handler to system file handler list.
int Int_t
Definition: RtypesCore.h:41
virtual void Notified()
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
virtual void ResetReadyMask()
void SetSignal(ESignals sig)
void DeActivate()
De-activate a system event handler.
virtual Bool_t Notify()
Notify when signal occurs.
static const double x2[5]
void * GetSender()
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void Added()
virtual void Removed()
void Emit(const char *signal)
Acitvate signal without args.
Definition: TQObject.cxx:559
int GetFd() const
virtual EStatus Handle(std::exception &exc)=0
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
ESignals
Bool_t IsActive() const
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
virtual void SetReadReady()
Abstract base class for handling system events.
virtual void Remove()=0
Bool_t IsAsync() const
void HandleDelayedSignal()
static const double x1[5]
virtual void Activated()
void SetFd(int fd)
virtual void Remove()
Remove signal handler from system signal handler list.
virtual Bool_t IsWriteReady() const
virtual void Remove()
Remove file event handler from system file handler list.
Mother of all ROOT objects.
Definition: TObject.h:58
ESignals GetSignal() const
virtual void SetInterest(Int_t mask)
Set interest mask to 'mask'.
virtual ~TSysEvtHandler()
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
virtual Bool_t Notify()=0
This method must be overridden to handle object notification.
const Bool_t kTRUE
Definition: Rtypes.h:91
TStdExceptionHandler()
Handle standard C++ exceptions intercepted by the TSystem::Run().
virtual void Add()
Add std::exception handler to system handler list.
virtual Bool_t Notify()
Notify when signal occurs.
virtual Bool_t HasReadInterest()
True if handler is interested in read events.