GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4DataRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4DataRunnable.cxx 2757 2020-04-16 11:45:21Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4DataRunnable.h"
15 
16 #include "TGo4Log.h"
17 #include "TGo4Thread.h"
18 #include "TGo4BufferQueue.h"
20 #include "TGo4Socket.h"
21 #include "TGo4TaskHandler.h"
23 #include "TGo4Task.h"
24 #include "TGo4ComDisconnectSlave.h"
25 
27  TGo4ThreadManager* man,
28  TGo4TaskHandler* hand,
29  Bool_t receivermode)
30  :TGo4TaskHandlerRunnable(name,man,hand,receivermode)
31 {
34 }
35 
37 {
38 }
39 
40 Int_t TGo4DataRunnable::Run(void* ptr)
41 {
42  if(!CheckTransportOpen()) return 0;
43  if(fbReceiverMode)
44  {
45  Int_t rev=fxTransport->ReceiveBuffer();
46  if(rev>=0)
47  {
48  TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
49  Int_t val=0;
50  if(CheckStopBuffer(buf,&val)) return 0; // stop for disconnect mode
52  if(val>=0 && comvalue==kComQuit)
53  {
54  //std::cout <<"QQQQQQQQQ Data Runnable has QUIT "<< std::endl;
55  GetThread()->Stop();
56  TGo4Command* qcommand = new TGo4ComDisconnectSlave;
57  TGo4Task* cli = dynamic_cast<TGo4Task*>(fxManager);
58  if(cli) cli->SubmitLocalCommand(qcommand);
59  return 0;
60  }
61  else
62  {
63  fxBufferQueue->AddBuffer(buf, kTRUE);
64  }
65  }
66  else
67  {
68  // error
70  //if (TGo4SocketSignalHandler::fgxLastSignal == kSigWindowChanged)
71  {
72  // TSocket error because of window resize, do not abort!
73  TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
75  //TGo4SocketSignalHandler::fgxLastSignal = (ESignals) 0;
76  }
77  else if(fxManager->IsTerminating())
78  {
79  //std::cout <<"Receive error in "<<GetName()<< " while threadmanager is terminating. Ignored!" << std::endl;
80  TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
81  GetThread()->Stop();
82 
83  }
84  else
85  {
86  TGo4Log::Debug(" !!!Receive Error in %s!!!",
87  GetName());
88  //GetThread()->Stop(); std::cout <<"Stopped data runnable. no termination" << std::endl;
90  }
91 
92  } // end if(rev>=0)
93 
94  }
95  else
96  {
97  // get next command from queue or wait for it
98  TBuffer* buf= fxBufferQueue->WaitBuffer();
99  if (buf)
100  // check if there is really an object from queue
101  {
102  CheckStopBuffer(buf);
103  fxTransport->SendBuffer(buf);
104  fxBufferQueue->FreeBuffer(buf); // will delete it or put it back into own free buffer list
105  }
106  }
107  return 0;
108 }
Go4EmergencyCommand_t
Bool_t SubmitLocalCommand(TGo4Command *com)
Definition: TGo4Task.cxx:529
TGo4ThreadManager * fxManager
Definition: TGo4Runnable.h:71
const TBuffer * GetBuffer() const
Definition: TGo4Socket.h:58
Int_t SendBuffer(TBuffer *buf)
Definition: TGo4Socket.cxx:222
Bool_t Stop()
Definition: TGo4Thread.cxx:327
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:45
TGo4Socket * GetDataTransport() const
static void SetLastSignal(Int_t v=0)
TBuffer * WaitBuffer()
virtual ~TGo4DataRunnable()
TGo4Queue * GetDataQueue() const
Int_t ReceiveBuffer()
Definition: TGo4Socket.cxx:275
void AddBuffer(TBuffer *buffer, Bool_t clone=kFALSE)
Bool_t CheckStopBuffer(TBuffer *buf, Int_t *result=0)
virtual Int_t Run(void *ptr)
Bool_t IsTerminating() const
void FreeBuffer(TBuffer *buffer)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:274