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

TGo4DataRunnable.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 "TGo4DataRunnable.h"
00017 
00018 #include "Riostream.h"
00019 #include <signal.h>
00020 
00021 #include "TGo4Log.h"
00022 #include "TGo4Thread.h"
00023 #include "TGo4BufferQueue.h"
00024 #include "TGo4SocketSignalHandler.h"
00025 #include "TGo4Socket.h"
00026 #include "TGo4TaskHandler.h"
00027 #include "TGo4TaskHandlerAbortException.h"
00028 #include "TGo4Task.h"
00029 #include "TGo4ComDisconnectSlave.h"
00030 
00031 TGo4DataRunnable::TGo4DataRunnable(const char* name,
00032                                    TGo4ThreadManager* man,
00033                                    TGo4TaskHandler* hand,
00034                                    Bool_t receivermode)
00035    :TGo4TaskHandlerRunnable(name,man,hand,receivermode)
00036 {
00037    fxBufferQueue=dynamic_cast<TGo4BufferQueue*> (fxTaskHandler->GetDataQueue() );
00038    fxTransport=fxTaskHandler->GetDataTransport();
00039 }
00040 
00041 TGo4DataRunnable::~TGo4DataRunnable()
00042 {
00043 }
00044 
00045 Int_t TGo4DataRunnable::Run(void* ptr)
00046 {
00047    if(!CheckTransportOpen()) return 0;
00048    if(fbReceiverMode)
00049       {
00050       Int_t rev=fxTransport->ReceiveBuffer();
00051       if(rev>=0)
00052          {
00053             TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
00054             Int_t val=0;
00055             if(CheckStopBuffer(buf,&val)) return 0; // stop for disconnect mode
00056             Go4EmergencyCommand_t comvalue= (Go4EmergencyCommand_t) (val);
00057             if(val>=0 && comvalue==kComQuit)
00058                {
00059                   //cout <<"QQQQQQQQQ Data Runnable has QUIT "<<endl;
00060                   GetThread()->Stop();
00061                   TGo4Command* qcommand = new TGo4ComDisconnectSlave;
00062                   TGo4Task* cli = dynamic_cast<TGo4Task*>(fxManager);
00063                   if(cli) cli->SubmitLocalCommand(qcommand);
00064                   return 0;
00065                 }
00066             else
00067                {
00068                   fxBufferQueue->AddBuffer(buf, kTRUE);
00069                }
00070           } 
00071       else
00072          {
00073             // error
00074              if (TGo4SocketSignalHandler::GetLastSignal() == SIGWINCH)
00075              //if (TGo4SocketSignalHandler::fgxLastSignal == kSigWindowChanged)
00076                {
00077                   // TSocket error because of window resize, do not abort!
00078                   TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
00079                   TGo4SocketSignalHandler::SetLastSignal(0); // reset
00080                   //TGo4SocketSignalHandler::fgxLastSignal = (ESignals) 0;
00081                }
00082             else if(fxManager->IsTerminating())
00083                {
00084                   //cout <<"Receive error in "<<GetName()<< " while threadmanager is terminating. Ignored!" << endl;
00085                   TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
00086                   GetThread()->Stop();
00087 
00088                }
00089             else
00090                {
00091                   TGo4Log::Debug(" !!!Receive Error in %s!!!",
00092                      GetName());
00093                   //GetThread()->Stop(); cout <<"Stopped data runnable. no termination" << endl;
00094                   throw TGo4TaskHandlerAbortException(this);
00095                }
00096 
00097          } // end if(rev>=0)
00098 
00099       } 
00100    else
00101       {
00102          // get next command from queue or wait for it
00103          TBuffer* buf= fxBufferQueue->WaitBuffer();
00104          if (buf)
00105             // check if there is really an object from queue
00106             {
00107                CheckStopBuffer(buf);
00108                fxTransport->SendBuffer(buf);
00109                fxBufferQueue->FreeBuffer(buf); // will delete it or put it back into own free buffer list
00110             }
00111       } 
00112    return 0;
00113 }
00114 
00115 //----------------------------END OF GO4 SOURCE FILE ---------------------

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