// @(#)root/base:$Id$
// Author: Fons Rademakers   16/09/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSysEvtHandler                                                       //
//                                                                      //
// Abstract base class for handling system events.                      //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TSysEvtHandler.h"
#include "TSystem.h"


ClassImp(TSysEvtHandler)
ClassImp(TFileHandler)
ClassImp(TSignalHandler)
ClassImp(TStdExceptionHandler)


//______________________________________________________________________________
void TSysEvtHandler::Activate()
{
   // Activate a system event handler. All handlers are by default
   // activated. Use this method to activate a de-activated handler.

   fIsActive = kTRUE;
   Activated();      // emit Activated() signal
}

//______________________________________________________________________________
void TSysEvtHandler::DeActivate()
{
   // De-activate a system event handler. Use this method to temporarily
   // disable an event handler to avoid it from being recursively called.
   // Use DeActivate() / Activate() instead of Remove() / Add() for this
   // purpose, since the Add() will add the handler back to the end of
   // the list of handlers and cause it to be called again for the same,
   // already handled, event.

   fIsActive = kFALSE;
   DeActivated();    // emit DeActivated() signal
}


//______________________________________________________________________________
TFileHandler::TFileHandler(int fd, int mask)
{
   // Create a file descriptor event handler. If mask=kRead then we
   // want to monitor the file for read readiness, if mask=kWrite
   // then we monitor the file for write readiness, if mask=kRead|kWrite
   // then we monitor both read and write readiness.

   fFileNum = fd;
   if (!mask)
      mask = kRead;
   fMask = mask;
   fReadyMask = 0;
}

//______________________________________________________________________________
Bool_t TFileHandler::Notify()
{
   // Notify when event occured on descriptor associated with this handler.

   Notified();       // emit Notified() signal
   return kFALSE;
}

//______________________________________________________________________________
Bool_t TFileHandler::ReadNotify()
{
   // Notify when something can be read from the descriptor associated with
   // this handler.

   Notified();       // emit Notified() signal
   return kFALSE;
}

//______________________________________________________________________________
Bool_t TFileHandler::WriteNotify()
{
   // Notify when something can be written to the descriptor associated with
   // this handler.

   Notified();       // emit Notified() signal
   return kFALSE;
}

//______________________________________________________________________________
Bool_t TFileHandler::HasReadInterest()
{
   // True if handler is interested in read events.

   return (fMask & 1);
}

//______________________________________________________________________________
Bool_t TFileHandler::HasWriteInterest()
{
   // True if handler is interested in write events.

   return (fMask & 2);
}

//______________________________________________________________________________
void TFileHandler::SetInterest(Int_t mask)
{
   // Set interest mask to 'mask'.

   if (!mask)
      mask = kRead;
   fMask = mask;
}

//______________________________________________________________________________
void TFileHandler::Add()
{
   // Add file event handler to system file handler list.

   if (gSystem && fFileNum != -1) {
      gSystem->AddFileHandler(this);
      Added();      // emit Added() signal
   }
}

//______________________________________________________________________________
void TFileHandler::Remove()
{
   // Remove file event handler from system file handler list.

   if (gSystem && fFileNum != -1) {
      gSystem->RemoveFileHandler(this);
      Removed();     // emit Removed() signal
   }
}


//______________________________________________________________________________
TSignalHandler::TSignalHandler(ESignals sig, Bool_t sync)
{
   // Create signal event handler.

   fSignal = sig;
   fSync   = sync;
   fDelay  = 0;
}

//______________________________________________________________________________
Bool_t TSignalHandler::Notify()
{
   // Notify when signal occurs.

   Notified();       // emit Notified() signal
   return kFALSE;
}

//______________________________________________________________________________
void TSignalHandler::Add()
{
   // Add signal handler to system signal handler list.

   if (gSystem && fSignal != (ESignals)-1) {
      gSystem->AddSignalHandler(this);
      Added();      // emit Added() signal
   }
}

//______________________________________________________________________________
void TSignalHandler::Remove()
{
   // Remove signal handler from system signal handler list.

   if (gSystem && fSignal != (ESignals)-1) {
      gSystem->RemoveSignalHandler(this);
      Removed();     // emit Removed() signal
   }
}


//______________________________________________________________________________
TStdExceptionHandler::TStdExceptionHandler() : TSysEvtHandler()
{
   // Handle standard C++ exceptions intercepted by the TSystem::Run().
   //
   // Virtual method EStatus Handle(std::exception& exc) is called on the
   // collection of handlers registered to TSystem. The return value of
   // each handler influences the continuation of handling procedure:
   //    kSEProceed - Proceed with passing of the exception to other
   //                 handlers, the exception has not been handled.
   //    kSEHandled - The exception has been handled, do not pass it to
   //                 other handlers.
   //    kSEAbort   - Abort application.
   // If all handlers return kSEProceed TSystem::Run() rethrows the
   // exception, possibly resulting in process abortion.

}

//______________________________________________________________________________
void TStdExceptionHandler::Add()
{
   // Add std::exception handler to system handler list.

   if (gSystem) {
      gSystem->AddStdExceptionHandler(this);
      Added();      // emit Added() signal
   }
}

//______________________________________________________________________________
void TStdExceptionHandler::Remove()
{
   // Remove std::exception handler from system handler list.

   if (gSystem) {
      gSystem->RemoveStdExceptionHandler(this);
      Removed();     // emit Removed() signal
   }
}

//______________________________________________________________________________
Bool_t TStdExceptionHandler::Notify()
{
   // Notify when signal occurs.

   Notified();       // emit Notified() signal
   return kFALSE;
}
 TSysEvtHandler.cxx:1
 TSysEvtHandler.cxx:2
 TSysEvtHandler.cxx:3
 TSysEvtHandler.cxx:4
 TSysEvtHandler.cxx:5
 TSysEvtHandler.cxx:6
 TSysEvtHandler.cxx:7
 TSysEvtHandler.cxx:8
 TSysEvtHandler.cxx:9
 TSysEvtHandler.cxx:10
 TSysEvtHandler.cxx:11
 TSysEvtHandler.cxx:12
 TSysEvtHandler.cxx:13
 TSysEvtHandler.cxx:14
 TSysEvtHandler.cxx:15
 TSysEvtHandler.cxx:16
 TSysEvtHandler.cxx:17
 TSysEvtHandler.cxx:18
 TSysEvtHandler.cxx:19
 TSysEvtHandler.cxx:20
 TSysEvtHandler.cxx:21
 TSysEvtHandler.cxx:22
 TSysEvtHandler.cxx:23
 TSysEvtHandler.cxx:24
 TSysEvtHandler.cxx:25
 TSysEvtHandler.cxx:26
 TSysEvtHandler.cxx:27
 TSysEvtHandler.cxx:28
 TSysEvtHandler.cxx:29
 TSysEvtHandler.cxx:30
 TSysEvtHandler.cxx:31
 TSysEvtHandler.cxx:32
 TSysEvtHandler.cxx:33
 TSysEvtHandler.cxx:34
 TSysEvtHandler.cxx:35
 TSysEvtHandler.cxx:36
 TSysEvtHandler.cxx:37
 TSysEvtHandler.cxx:38
 TSysEvtHandler.cxx:39
 TSysEvtHandler.cxx:40
 TSysEvtHandler.cxx:41
 TSysEvtHandler.cxx:42
 TSysEvtHandler.cxx:43
 TSysEvtHandler.cxx:44
 TSysEvtHandler.cxx:45
 TSysEvtHandler.cxx:46
 TSysEvtHandler.cxx:47
 TSysEvtHandler.cxx:48
 TSysEvtHandler.cxx:49
 TSysEvtHandler.cxx:50
 TSysEvtHandler.cxx:51
 TSysEvtHandler.cxx:52
 TSysEvtHandler.cxx:53
 TSysEvtHandler.cxx:54
 TSysEvtHandler.cxx:55
 TSysEvtHandler.cxx:56
 TSysEvtHandler.cxx:57
 TSysEvtHandler.cxx:58
 TSysEvtHandler.cxx:59
 TSysEvtHandler.cxx:60
 TSysEvtHandler.cxx:61
 TSysEvtHandler.cxx:62
 TSysEvtHandler.cxx:63
 TSysEvtHandler.cxx:64
 TSysEvtHandler.cxx:65
 TSysEvtHandler.cxx:66
 TSysEvtHandler.cxx:67
 TSysEvtHandler.cxx:68
 TSysEvtHandler.cxx:69
 TSysEvtHandler.cxx:70
 TSysEvtHandler.cxx:71
 TSysEvtHandler.cxx:72
 TSysEvtHandler.cxx:73
 TSysEvtHandler.cxx:74
 TSysEvtHandler.cxx:75
 TSysEvtHandler.cxx:76
 TSysEvtHandler.cxx:77
 TSysEvtHandler.cxx:78
 TSysEvtHandler.cxx:79
 TSysEvtHandler.cxx:80
 TSysEvtHandler.cxx:81
 TSysEvtHandler.cxx:82
 TSysEvtHandler.cxx:83
 TSysEvtHandler.cxx:84
 TSysEvtHandler.cxx:85
 TSysEvtHandler.cxx:86
 TSysEvtHandler.cxx:87
 TSysEvtHandler.cxx:88
 TSysEvtHandler.cxx:89
 TSysEvtHandler.cxx:90
 TSysEvtHandler.cxx:91
 TSysEvtHandler.cxx:92
 TSysEvtHandler.cxx:93
 TSysEvtHandler.cxx:94
 TSysEvtHandler.cxx:95
 TSysEvtHandler.cxx:96
 TSysEvtHandler.cxx:97
 TSysEvtHandler.cxx:98
 TSysEvtHandler.cxx:99
 TSysEvtHandler.cxx:100
 TSysEvtHandler.cxx:101
 TSysEvtHandler.cxx:102
 TSysEvtHandler.cxx:103
 TSysEvtHandler.cxx:104
 TSysEvtHandler.cxx:105
 TSysEvtHandler.cxx:106
 TSysEvtHandler.cxx:107
 TSysEvtHandler.cxx:108
 TSysEvtHandler.cxx:109
 TSysEvtHandler.cxx:110
 TSysEvtHandler.cxx:111
 TSysEvtHandler.cxx:112
 TSysEvtHandler.cxx:113
 TSysEvtHandler.cxx:114
 TSysEvtHandler.cxx:115
 TSysEvtHandler.cxx:116
 TSysEvtHandler.cxx:117
 TSysEvtHandler.cxx:118
 TSysEvtHandler.cxx:119
 TSysEvtHandler.cxx:120
 TSysEvtHandler.cxx:121
 TSysEvtHandler.cxx:122
 TSysEvtHandler.cxx:123
 TSysEvtHandler.cxx:124
 TSysEvtHandler.cxx:125
 TSysEvtHandler.cxx:126
 TSysEvtHandler.cxx:127
 TSysEvtHandler.cxx:128
 TSysEvtHandler.cxx:129
 TSysEvtHandler.cxx:130
 TSysEvtHandler.cxx:131
 TSysEvtHandler.cxx:132
 TSysEvtHandler.cxx:133
 TSysEvtHandler.cxx:134
 TSysEvtHandler.cxx:135
 TSysEvtHandler.cxx:136
 TSysEvtHandler.cxx:137
 TSysEvtHandler.cxx:138
 TSysEvtHandler.cxx:139
 TSysEvtHandler.cxx:140
 TSysEvtHandler.cxx:141
 TSysEvtHandler.cxx:142
 TSysEvtHandler.cxx:143
 TSysEvtHandler.cxx:144
 TSysEvtHandler.cxx:145
 TSysEvtHandler.cxx:146
 TSysEvtHandler.cxx:147
 TSysEvtHandler.cxx:148
 TSysEvtHandler.cxx:149
 TSysEvtHandler.cxx:150
 TSysEvtHandler.cxx:151
 TSysEvtHandler.cxx:152
 TSysEvtHandler.cxx:153
 TSysEvtHandler.cxx:154
 TSysEvtHandler.cxx:155
 TSysEvtHandler.cxx:156
 TSysEvtHandler.cxx:157
 TSysEvtHandler.cxx:158
 TSysEvtHandler.cxx:159
 TSysEvtHandler.cxx:160
 TSysEvtHandler.cxx:161
 TSysEvtHandler.cxx:162
 TSysEvtHandler.cxx:163
 TSysEvtHandler.cxx:164
 TSysEvtHandler.cxx:165
 TSysEvtHandler.cxx:166
 TSysEvtHandler.cxx:167
 TSysEvtHandler.cxx:168
 TSysEvtHandler.cxx:169
 TSysEvtHandler.cxx:170
 TSysEvtHandler.cxx:171
 TSysEvtHandler.cxx:172
 TSysEvtHandler.cxx:173
 TSysEvtHandler.cxx:174
 TSysEvtHandler.cxx:175
 TSysEvtHandler.cxx:176
 TSysEvtHandler.cxx:177
 TSysEvtHandler.cxx:178
 TSysEvtHandler.cxx:179
 TSysEvtHandler.cxx:180
 TSysEvtHandler.cxx:181
 TSysEvtHandler.cxx:182
 TSysEvtHandler.cxx:183
 TSysEvtHandler.cxx:184
 TSysEvtHandler.cxx:185
 TSysEvtHandler.cxx:186
 TSysEvtHandler.cxx:187
 TSysEvtHandler.cxx:188
 TSysEvtHandler.cxx:189
 TSysEvtHandler.cxx:190
 TSysEvtHandler.cxx:191
 TSysEvtHandler.cxx:192
 TSysEvtHandler.cxx:193
 TSysEvtHandler.cxx:194
 TSysEvtHandler.cxx:195
 TSysEvtHandler.cxx:196
 TSysEvtHandler.cxx:197
 TSysEvtHandler.cxx:198
 TSysEvtHandler.cxx:199
 TSysEvtHandler.cxx:200
 TSysEvtHandler.cxx:201
 TSysEvtHandler.cxx:202
 TSysEvtHandler.cxx:203
 TSysEvtHandler.cxx:204
 TSysEvtHandler.cxx:205
 TSysEvtHandler.cxx:206
 TSysEvtHandler.cxx:207
 TSysEvtHandler.cxx:208
 TSysEvtHandler.cxx:209
 TSysEvtHandler.cxx:210
 TSysEvtHandler.cxx:211
 TSysEvtHandler.cxx:212
 TSysEvtHandler.cxx:213
 TSysEvtHandler.cxx:214
 TSysEvtHandler.cxx:215
 TSysEvtHandler.cxx:216
 TSysEvtHandler.cxx:217
 TSysEvtHandler.cxx:218
 TSysEvtHandler.cxx:219
 TSysEvtHandler.cxx:220
 TSysEvtHandler.cxx:221
 TSysEvtHandler.cxx:222
 TSysEvtHandler.cxx:223
 TSysEvtHandler.cxx:224
 TSysEvtHandler.cxx:225
 TSysEvtHandler.cxx:226
 TSysEvtHandler.cxx:227
 TSysEvtHandler.cxx:228
 TSysEvtHandler.cxx:229
 TSysEvtHandler.cxx:230
 TSysEvtHandler.cxx:231
 TSysEvtHandler.cxx:232
 TSysEvtHandler.cxx:233
 TSysEvtHandler.cxx:234
 TSysEvtHandler.cxx:235
 TSysEvtHandler.cxx:236
 TSysEvtHandler.cxx:237