TSysEvtHandler.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TSysEvtHandler.cxx 21270 2007-12-07 12:15:24Z rdm $
00002 // Author: Fons Rademakers   16/09/95
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TSysEvtHandler                                                       //
00015 //                                                                      //
00016 // Abstract base class for handling system events.                      //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 #include "TSysEvtHandler.h"
00021 #include "TSystem.h"
00022 
00023 
00024 ClassImp(TSysEvtHandler)
00025 ClassImp(TFileHandler)
00026 ClassImp(TSignalHandler)
00027 ClassImp(TStdExceptionHandler)
00028 
00029 
00030 //______________________________________________________________________________
00031 void TSysEvtHandler::Activate()
00032 {
00033    // Activate a system event handler. All handlers are by default
00034    // activated. Use this method to activate a de-activated handler.
00035 
00036    fIsActive = kTRUE;
00037    Activated();      // emit Activated() signal
00038 }
00039 
00040 //______________________________________________________________________________
00041 void TSysEvtHandler::DeActivate()
00042 {
00043    // De-activate a system event handler. Use this method to temporarily
00044    // disable an event handler to avoid it from being recursively called.
00045    // Use DeActivate() / Activate() instead of Remove() / Add() for this
00046    // purpose, since the Add() will add the handler back to the end of
00047    // the list of handlers and cause it to be called again for the same,
00048    // already handled, event.
00049 
00050    fIsActive = kFALSE;
00051    DeActivated();    // emit DeActivated() signal
00052 }
00053 
00054 
00055 //______________________________________________________________________________
00056 TFileHandler::TFileHandler(int fd, int mask)
00057 {
00058    // Create a file descriptor event handler. If mask=kRead then we
00059    // want to monitor the file for read readiness, if mask=kWrite
00060    // then we monitor the file for write readiness, if mask=kRead|kWrite
00061    // then we monitor both read and write readiness.
00062 
00063    fFileNum = fd;
00064    if (!mask)
00065       mask = kRead;
00066    fMask = mask;
00067    fReadyMask = 0;
00068 }
00069 
00070 //______________________________________________________________________________
00071 Bool_t TFileHandler::Notify()
00072 {
00073    // Notify when event occured on descriptor associated with this handler.
00074 
00075    Notified();       // emit Notified() signal
00076    return kFALSE;
00077 }
00078 
00079 //______________________________________________________________________________
00080 Bool_t TFileHandler::ReadNotify()
00081 {
00082    // Notify when something can be read from the descriptor associated with
00083    // this handler.
00084 
00085    Notified();       // emit Notified() signal
00086    return kFALSE;
00087 }
00088 
00089 //______________________________________________________________________________
00090 Bool_t TFileHandler::WriteNotify()
00091 {
00092    // Notify when something can be written to the descriptor associated with
00093    // this handler.
00094 
00095    Notified();       // emit Notified() signal
00096    return kFALSE;
00097 }
00098 
00099 //______________________________________________________________________________
00100 Bool_t TFileHandler::HasReadInterest()
00101 {
00102    // True if handler is interested in read events.
00103 
00104    return (fMask & 1);
00105 }
00106 
00107 //______________________________________________________________________________
00108 Bool_t TFileHandler::HasWriteInterest()
00109 {
00110    // True if handler is interested in write events.
00111 
00112    return (fMask & 2);
00113 }
00114 
00115 //______________________________________________________________________________
00116 void TFileHandler::SetInterest(Int_t mask)
00117 {
00118    // Set interest mask to 'mask'.
00119 
00120    if (!mask)
00121       mask = kRead;
00122    fMask = mask;
00123 }
00124 
00125 //______________________________________________________________________________
00126 void TFileHandler::Add()
00127 {
00128    // Add file event handler to system file handler list.
00129 
00130    if (gSystem && fFileNum != -1) {
00131       gSystem->AddFileHandler(this);
00132       Added();      // emit Added() signal
00133    }
00134 }
00135 
00136 //______________________________________________________________________________
00137 void TFileHandler::Remove()
00138 {
00139    // Remove file event handler from system file handler list.
00140 
00141    if (gSystem && fFileNum != -1) {
00142       gSystem->RemoveFileHandler(this);
00143       Removed();     // emit Removed() signal
00144    }
00145 }
00146 
00147 
00148 //______________________________________________________________________________
00149 TSignalHandler::TSignalHandler(ESignals sig, Bool_t sync)
00150 {
00151    // Create signal event handler.
00152 
00153    fSignal = sig;
00154    fSync   = sync;
00155    fDelay  = 0;
00156 }
00157 
00158 //______________________________________________________________________________
00159 Bool_t TSignalHandler::Notify()
00160 {
00161    // Notify when signal occurs.
00162 
00163    Notified();       // emit Notified() signal
00164    return kFALSE;
00165 }
00166 
00167 //______________________________________________________________________________
00168 void TSignalHandler::Add()
00169 {
00170    // Add signal handler to system signal handler list.
00171 
00172    if (gSystem && fSignal != (ESignals)-1) {
00173       gSystem->AddSignalHandler(this);
00174       Added();      // emit Added() signal
00175    }
00176 }
00177 
00178 //______________________________________________________________________________
00179 void TSignalHandler::Remove()
00180 {
00181    // Remove signal handler from system signal handler list.
00182 
00183    if (gSystem && fSignal != (ESignals)-1) {
00184       gSystem->RemoveSignalHandler(this);
00185       Removed();     // emit Removed() signal
00186    }
00187 }
00188 
00189 
00190 //______________________________________________________________________________
00191 TStdExceptionHandler::TStdExceptionHandler() : TSysEvtHandler()
00192 {
00193    // Handle standard C++ exceptions intercepted by the TSystem::Run().
00194    //
00195    // Virtual method EStatus Handle(std::exception& exc) is called on the
00196    // collection of handlers registered to TSystem. The return value of
00197    // each handler influences the continuation of handling procedure:
00198    //    kSEProceed - Proceed with passing of the exception to other
00199    //                 handlers, the exception has not been handled.
00200    //    kSEHandled - The exception has been handled, do not pass it to
00201    //                 other handlers.
00202    //    kSEAbort   - Abort application.
00203    // If all handlers return kSEProceed TSystem::Run() rethrows the
00204    // exception, possibly resulting in process abortion.
00205 
00206 }
00207 
00208 //______________________________________________________________________________
00209 void TStdExceptionHandler::Add()
00210 {
00211    // Add std::exception handler to system handler list.
00212 
00213    if (gSystem) {
00214       gSystem->AddStdExceptionHandler(this);
00215       Added();      // emit Added() signal
00216    }
00217 }
00218 
00219 //______________________________________________________________________________
00220 void TStdExceptionHandler::Remove()
00221 {
00222    // Remove std::exception handler from system handler list.
00223 
00224    if (gSystem) {
00225       gSystem->RemoveStdExceptionHandler(this);
00226       Removed();     // emit Removed() signal
00227    }
00228 }
00229 
00230 //______________________________________________________________________________
00231 Bool_t TStdExceptionHandler::Notify()
00232 {
00233    // Notify when signal occurs.
00234 
00235    Notified();       // emit Notified() signal
00236    return kFALSE;
00237 }

Generated on Tue Jul 5 14:11:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1