Logo ROOT   6.14/05
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:
36  TSysEvtHandler() : fIsActive(kTRUE) { }
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 
72  TFileHandler(): fFileNum(-1), fMask(0), fReadyMask(0) { }
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 };
124 
125 
127 
128 protected:
129  ESignals fSignal; //Signal to be handled
130  Bool_t fSync; //Synchronous or a-synchronous signal
131  Int_t fDelay; //Delay handling of signal (use fDelay in Notify())
132 
133  TSignalHandler(): fSignal((ESignals)-1), fSync(kTRUE), fDelay(0) { }
134 
135 public:
136  TSignalHandler(ESignals sig, Bool_t sync = kTRUE);
137  virtual ~TSignalHandler() { Remove(); }
138  void Delay() { fDelay = 1; }
139  void HandleDelayedSignal();
140  ESignals GetSignal() const { return fSignal; }
141  void SetSignal(ESignals sig) { fSignal = sig; }
142  Bool_t IsSync() const { return fSync; }
143  Bool_t IsAsync() const { return !fSync; }
144  virtual Bool_t Notify();
145  virtual void Add();
146  virtual void Remove();
147 
148  ClassDef(TSignalHandler,0) //Signal event handler
149 };
150 
152 {
153  if (fDelay > 1) {
154  fDelay = 0;
155  Notify();
156  } else
157  fDelay = 0;
158 }
159 
160 
161 //////////////////////////////////////////////////////////////////////////
162 // //
163 // TStdExceptionHandler //
164 // //
165 // Handles standard C++ exceptions. //
166 // //
167 //////////////////////////////////////////////////////////////////////////
168 
169 namespace std { class exception; }
170 
172 
173 public:
174  enum EStatus { kSEProceed, kSEHandled, kSEAbort };
175 
177  virtual ~TStdExceptionHandler() { }
178 
179  virtual void Add();
180  virtual void Remove();
181  virtual Bool_t Notify();
182 
183  virtual EStatus Handle(std::exception& exc) = 0;
184 
185  ClassDef(TStdExceptionHandler,0) //C++ exception handler
186 };
187 
188 #endif
virtual void SetWriteReady()
virtual ~TSignalHandler()
virtual ~TStdExceptionHandler()
virtual void DeActivated()
virtual void Add()=0
void Activate()
Activate a system event handler.
virtual ~TFileHandler()
This is the ROOT implementation of the Qt object communication mechanism (see also http://www...
Definition: TQObject.h:49
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 IsWriteReady() const
static const double x2[5]
void * GetSender()
virtual Bool_t IsReadReady() const
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void Added()
virtual void Removed()
Bool_t IsSync() const
ESignals
Bool_t IsAsync() const
Bool_t IsActive() const
virtual void SetReadReady()
Abstract base class for handling system events.
virtual void Remove()=0
int GetFd() const
ESignals GetSignal() const
void HandleDelayedSignal()
static const double x1[5]
virtual void Activated()
void SetFd(int fd)
Mother of all ROOT objects.
Definition: TObject.h:37
virtual ~TSysEvtHandler()
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:165
virtual Bool_t Notify()=0
This method must be overridden to handle object notification.
const Bool_t kTRUE
Definition: RtypesCore.h:87