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

TGo4StatusRunnable.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 "TGo4StatusRunnable.h"
00017 
00018 #include "Riostream.h"
00019 #include <signal.h>
00020 
00021 #include "TGo4Log.h"
00022 #include "TGo4ThreadManager.h"
00023 #include "TGo4Thread.h"
00024 #include "TGo4BufferQueue.h"
00025 #include "TGo4Socket.h"
00026 #include "TGo4SocketSignalHandler.h"
00027 #include "TGo4TaskHandler.h"
00028 #include "TGo4TaskHandlerAbortException.h"
00029 
00030 TGo4StatusRunnable::TGo4StatusRunnable(const char* name, TGo4ThreadManager* man, TGo4TaskHandler* hand, Bool_t receivermode) :
00031    TGo4TaskHandlerRunnable(name,man,hand,receivermode)
00032 {
00033    fxBufferQueue = dynamic_cast<TGo4BufferQueue*> (fxTaskHandler->GetStatusQueue() );
00034    fxTransport = fxTaskHandler->GetStatusTransport();
00035 }
00036 
00037 
00038 TGo4StatusRunnable::~TGo4StatusRunnable()
00039 {
00040 }
00041 
00042 Int_t TGo4StatusRunnable::Run(void* ptr)
00043 {
00044    if(!CheckTransportOpen()) return 0;
00045    if(fbReceiverMode)
00046       {
00047       // server side: receive status objects from client
00048       Int_t  rev = fxTransport->ReceiveBuffer();
00049       if(rev>=0)
00050          {
00051             TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
00052             if(CheckStopBuffer(buf)) return 0; // stop for disconnect mode
00053             fxBufferQueue->AddBuffer(buf, kTRUE);
00054          } 
00055       else
00056          {
00057             if (TGo4SocketSignalHandler::GetLastSignal() == SIGWINCH)
00058                {
00059                   // TSocket error because of window resize, do not abort!
00060                   TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
00061                   TGo4SocketSignalHandler::SetLastSignal(0); // reset
00062                }
00063             else if(fxManager->IsTerminating())
00064                {
00065                   //cout <<"Receive error in "<<GetName()<< " while threadmanager is terminating. Ignored!" << endl;
00066                   TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
00067                   GetThread()->Stop();
00068                }
00069             else
00070                {
00071                   TGo4Log::Debug(" !!!Receive Error in %s!!!",
00072                         GetName());
00073                    //GetThread()->Stop(); cout <<"Stopped status runnable. no termination" << endl;
00074                   throw TGo4TaskHandlerAbortException(this);
00075                }
00076          }
00077 
00078    } 
00079    else
00080       {
00081       // client side: send status buffer to server
00082          // get next status buffer from queue or wait for it
00083          TBuffer* buf= fxBufferQueue->WaitBuffer();
00084          if (buf)
00085             // check if there is really an object from queue
00086             {
00087                CheckStopBuffer(buf);
00088                fxTransport->SendBuffer(buf);
00089                fxBufferQueue->FreeBuffer(buf);
00090             }
00091       } // else if(fbReceiverMode)
00092 
00093 
00094 return 0;
00095 }
00096 
00097 
00098 //----------------------------END OF GO4 SOURCE FILE ---------------------

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