Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4SocketSignalHandler.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4SocketSignalHandler.h"
00017 
00018 #include "Riostream.h"
00019 
00020 
00021 Int_t TGo4SocketSignalHandler::fgiLastSignal = 0; // unix signal id
00022 
00023 TGo4SocketSignalHandler::TGo4SocketSignalHandler(Int_t signum, Bool_t enabled)
00024 {
00025    SetSignalAction(signum,enabled);
00026    //cout << "set member function as signal handler"<< endl;
00027 }
00028 
00029 TGo4SocketSignalHandler::~TGo4SocketSignalHandler()
00030 {
00031 }
00032 
00033 void TGo4SocketSignalHandler::Handle(int signum)
00034 {
00035    SetSignalAction(signum,0);
00036    //cout << "got a signal " << signum << " ("<< getpid() << ") Id: ";
00037 // optional part:
00038 //   if(signum == SIGWINCH)
00039 //      {
00040 //         //cout << "got a SIGWINCH\n";
00041 //         //TGo4SocketSignalHandler::fgiLastSignal = SIGWINCH;
00042 //
00043 //       }
00044 // end optional part
00045    TGo4SocketSignalHandler::fgiLastSignal = signum;
00046    SetSignalAction(signum,1);
00047 }
00048 
00049 #ifndef WIN32
00050 
00051 void TGo4SocketSignalHandler::SetSignalAction(Int_t signum, Bool_t enabled)
00052 {
00053   struct sigaction new_action, old_action;
00054 
00055   /* Set up the structure to specify the new action. */
00056   if(enabled)
00057     new_action.sa_handler = TGo4SocketSignalHandler::Handle;
00058   else
00059     new_action.sa_handler = SIG_IGN;
00060 
00061   sigemptyset (&new_action.sa_mask);
00062   new_action.sa_flags = 0;
00063   sigaction (signum, NULL, &old_action);
00064   if(enabled)
00065     sigaction (signum, &new_action, NULL);
00066 }
00067 
00068 #else
00069 
00070 // do nothing in windows
00071 
00072 void TGo4SocketSignalHandler::SetSignalAction(Int_t signum, Bool_t enabled)
00073 {
00074 }
00075 
00076 #endif
00077 
00078 Int_t TGo4SocketSignalHandler::GetLastSignal()
00079 {
00080    return fgiLastSignal;
00081 }
00082 
00083 void TGo4SocketSignalHandler::SetLastSignal(Int_t v)
00084 {
00085    fgiLastSignal = v;
00086 }
00087 
00088 
00089 
00090 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:28 2008 for Go4-v3.04-1 by  doxygen 1.4.2