Logo ROOT   6.08/07
Reference Guide
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 \ingroup Base
14 
15 Abstract base class for handling system events.
16 */
17 
18 #include "TSysEvtHandler.h"
19 #include "TSystem.h"
20 
21 
26 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Activate a system event handler. All handlers are by default
30 /// activated. Use this method to activate a de-activated handler.
31 
32 void TSysEvtHandler::Activate()
33 {
34  fIsActive = kTRUE;
35  Activated(); // emit Activated() signal
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// De-activate a system event handler. Use this method to temporarily
40 /// disable an event handler to avoid it from being recursively called.
41 /// Use DeActivate() / Activate() instead of Remove() / Add() for this
42 /// purpose, since the Add() will add the handler back to the end of
43 /// the list of handlers and cause it to be called again for the same,
44 /// already handled, event.
45 
47 {
48  fIsActive = kFALSE;
49  DeActivated(); // emit DeActivated() signal
50 }
51 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Create a file descriptor event handler. If mask=kRead then we
55 /// want to monitor the file for read readiness, if mask=kWrite
56 /// then we monitor the file for write readiness, if mask=kRead|kWrite
57 /// then we monitor both read and write readiness.
58 
59 TFileHandler::TFileHandler(int fd, int mask)
60 {
61  fFileNum = fd;
62  if (!mask)
63  mask = kRead;
64  fMask = mask;
65  fReadyMask = 0;
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Notify when event occurred on descriptor associated with this handler.
70 
72 {
73  Notified(); // emit Notified() signal
74  return kFALSE;
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Notify when something can be read from the descriptor associated with
79 /// this handler.
80 
82 {
83  Notified(); // emit Notified() signal
84  return kFALSE;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Notify when something can be written to the descriptor associated with
89 /// this handler.
90 
92 {
93  Notified(); // emit Notified() signal
94  return kFALSE;
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// True if handler is interested in read events.
99 
101 {
102  return (fMask & 1);
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// True if handler is interested in write events.
107 
109 {
110  return (fMask & 2);
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Set interest mask to 'mask'.
115 
117 {
118  if (!mask)
119  mask = kRead;
120  fMask = mask;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// Add file event handler to system file handler list.
125 
127 {
128  if (gSystem && fFileNum != -1) {
129  gSystem->AddFileHandler(this);
130  Added(); // emit Added() signal
131  }
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Remove file event handler from system file handler list.
136 
138 {
139  if (gSystem && fFileNum != -1) {
140  gSystem->RemoveFileHandler(this);
141  Removed(); // emit Removed() signal
142  }
143 }
144 
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Create signal event handler.
148 
150 {
151  fSignal = sig;
152  fSync = sync;
153  fDelay = 0;
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Notify when signal occurs.
158 
160 {
161  Notified(); // emit Notified() signal
162  return kFALSE;
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Add signal handler to system signal handler list.
167 
169 {
170  if (gSystem && fSignal != (ESignals)-1) {
171  gSystem->AddSignalHandler(this);
172  Added(); // emit Added() signal
173  }
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Remove signal handler from system signal handler list.
178 
180 {
181  if (gSystem && fSignal != (ESignals)-1) {
183  Removed(); // emit Removed() signal
184  }
185 }
186 
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Handle standard C++ exceptions intercepted by the TSystem::Run().
190 ///
191 /// Virtual method EStatus Handle(std::exception& exc) is called on the
192 /// collection of handlers registered to TSystem. The return value of
193 /// each handler influences the continuation of handling procedure:
194 /// - kSEProceed - Proceed with passing of the exception to other
195 /// handlers, the exception has not been handled.
196 /// - kSEHandled - The exception has been handled, do not pass it to
197 /// other handlers.
198 /// - kSEAbort - Abort application.
199 /// If all handlers return kSEProceed TSystem::Run() rethrows the
200 /// exception, possibly resulting in process abortion.
201 
203 {
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Add std::exception handler to system handler list.
208 
210 {
211  if (gSystem) {
213  Added(); // emit Added() signal
214  }
215 }
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Remove std::exception handler from system handler list.
219 
221 {
222  if (gSystem) {
224  Removed(); // emit Removed() signal
225  }
226 }
227 
228 ////////////////////////////////////////////////////////////////////////////////
229 /// Notify when signal occurs.
230 
232 {
233  Notified(); // emit Notified() signal
234  return kFALSE;
235 }
virtual void DeActivated()
virtual Bool_t Notify()
Notify when event occurred on descriptor associated with this 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:537
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:616
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:569
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:626
virtual Bool_t HasWriteInterest()
True if handler is interested in write events.
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
Abstract base class for handling system events.
virtual TSignalHandler * RemoveSignalHandler(TSignalHandler *sh)
Remove a signal handler from list of signal handlers.
Definition: TSystem.cxx:547
#define ClassImp(name)
Definition: Rtypes.h:279
virtual void Remove()
Remove signal handler from system signal handler list.
virtual void Remove()
Remove file event handler from system file handler list.
typedef void((*Func_t)())
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:559
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.