ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TSysEvtHandler.cxx
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 /** \class TSysEvtHandler
13 Abstract base class for handling system events.
14 */
15 
16 #include "TSysEvtHandler.h"
17 #include "TSystem.h"
18 
19 
24 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Activate a system event handler. All handlers are by default
28 /// activated. Use this method to activate a de-activated handler.
29 
30 void TSysEvtHandler::Activate()
31 {
32  fIsActive = kTRUE;
33  Activated(); // emit Activated() signal
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// De-activate a system event handler. Use this method to temporarily
38 /// disable an event handler to avoid it from being recursively called.
39 /// Use DeActivate() / Activate() instead of Remove() / Add() for this
40 /// purpose, since the Add() will add the handler back to the end of
41 /// the list of handlers and cause it to be called again for the same,
42 /// already handled, event.
43 
45 {
46  fIsActive = kFALSE;
47  DeActivated(); // emit DeActivated() signal
48 }
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Create a file descriptor event handler. If mask=kRead then we
53 /// want to monitor the file for read readiness, if mask=kWrite
54 /// then we monitor the file for write readiness, if mask=kRead|kWrite
55 /// then we monitor both read and write readiness.
56 
57 TFileHandler::TFileHandler(int fd, int mask)
58 {
59  fFileNum = fd;
60  if (!mask)
61  mask = kRead;
62  fMask = mask;
63  fReadyMask = 0;
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Notify when event occurred on descriptor associated with this handler.
68 
70 {
71  Notified(); // emit Notified() signal
72  return kFALSE;
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Notify when something can be read from the descriptor associated with
77 /// this handler.
78 
80 {
81  Notified(); // emit Notified() signal
82  return kFALSE;
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Notify when something can be written to the descriptor associated with
87 /// this handler.
88 
90 {
91  Notified(); // emit Notified() signal
92  return kFALSE;
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// True if handler is interested in read events.
97 
99 {
100  return (fMask & 1);
101 }
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// True if handler is interested in write events.
105 
107 {
108  return (fMask & 2);
109 }
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Set interest mask to 'mask'.
113 
115 {
116  if (!mask)
117  mask = kRead;
118  fMask = mask;
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Add file event handler to system file handler list.
123 
125 {
126  if (gSystem && fFileNum != -1) {
127  gSystem->AddFileHandler(this);
128  Added(); // emit Added() signal
129  }
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Remove file event handler from system file handler list.
134 
136 {
137  if (gSystem && fFileNum != -1) {
138  gSystem->RemoveFileHandler(this);
139  Removed(); // emit Removed() signal
140  }
141 }
142 
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Create signal event handler.
146 
148 {
149  fSignal = sig;
150  fSync = sync;
151  fDelay = 0;
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Notify when signal occurs.
156 
158 {
159  Notified(); // emit Notified() signal
160  return kFALSE;
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Add signal handler to system signal handler list.
165 
167 {
168  if (gSystem && fSignal != (ESignals)-1) {
169  gSystem->AddSignalHandler(this);
170  Added(); // emit Added() signal
171  }
172 }
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Remove signal handler from system signal handler list.
176 
178 {
179  if (gSystem && fSignal != (ESignals)-1) {
181  Removed(); // emit Removed() signal
182  }
183 }
184 
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Handle standard C++ exceptions intercepted by the TSystem::Run().
188 ///
189 /// Virtual method EStatus Handle(std::exception& exc) is called on the
190 /// collection of handlers registered to TSystem. The return value of
191 /// each handler influences the continuation of handling procedure:
192 /// - kSEProceed - Proceed with passing of the exception to other
193 /// handlers, the exception has not been handled.
194 /// - kSEHandled - The exception has been handled, do not pass it to
195 /// other handlers.
196 /// - kSEAbort - Abort application.
197 /// If all handlers return kSEProceed TSystem::Run() rethrows the
198 /// exception, possibly resulting in process abortion.
199 
201 {
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Add std::exception handler to system handler list.
206 
208 {
209  if (gSystem) {
211  Added(); // emit Added() signal
212  }
213 }
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 /// Remove std::exception handler from system handler list.
217 
219 {
220  if (gSystem) {
222  Removed(); // emit Removed() signal
223  }
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Notify when signal occurs.
228 
230 {
231  Notified(); // emit Notified() signal
232  return kFALSE;
233 }
virtual void DeActivated()
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this handler.
ClassImp(TSysEvtHandler) ClassImp(TFileHandler) ClassImp(TSignalHandler) ClassImp(TStdExceptionHandler) void TSysEvtHandler
Activate a system event handler.
virtual void Add()
Add signal handler to system signal handler list.
virtual void AddSignalHandler(TSignalHandler *sh)
Add a signal handler to list of system signal handlers.
Definition: TSystem.cxx:536
virtual void Remove()
Remove std::exception handler from system handler list.
virtual void AddStdExceptionHandler(TStdExceptionHandler *eh)
Add an exception handler to list of system exception handlers.
Definition: TSystem.cxx:615
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
const Bool_t kFALSE
Definition: Rtypes.h:92
void DeActivate()
De-activate a system event handler.
virtual TFileHandler * RemoveFileHandler(TFileHandler *fh)
Remove a file handler from the list of file handlers.
Definition: TSystem.cxx:568
virtual Bool_t Notify()
Notify when signal occurs.
virtual void Added()
virtual void Removed()
virtual Bool_t WriteNotify()
Notify when something can be written to the descriptor associated with this handler.
ESignals
virtual TStdExceptionHandler * RemoveStdExceptionHandler(TStdExceptionHandler *eh)
Remove an exception handler from list of exception handlers.
Definition: TSystem.cxx:625
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
Abstract base class for handling system events.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
Definition: TSystem.cxx:546
virtual void Remove()
Remove signal handler from system signal handler list.
virtual void Remove()
Remove file event handler from system file handler list.
virtual void SetInterest(Int_t mask)
Set interest mask to 'mask'.
virtual Bool_t ReadNotify()
Notify when something can be read from the descriptor associated with this handler.
virtual void AddFileHandler(TFileHandler *fh)
Add a file handler to the list of system file handlers.
Definition: TSystem.cxx:558
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.