GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4StatusRunnable.cxx
Go to the documentation of this file.
1 // $Id: TGo4StatusRunnable.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 "TGo4StatusRunnable.h"
15 
16 #include "TGo4Log.h"
17 #include "TGo4ThreadManager.h"
18 #include "TGo4Thread.h"
19 #include "TGo4BufferQueue.h"
20 #include "TGo4Socket.h"
22 #include "TGo4TaskHandler.h"
24 
25 TGo4StatusRunnable::TGo4StatusRunnable(const char* name, TGo4ThreadManager* man, TGo4TaskHandler* hand, Bool_t receivermode) :
26  TGo4TaskHandlerRunnable(name,man,hand,receivermode)
27 {
30 }
31 
32 
34 {
35 }
36 
37 Int_t TGo4StatusRunnable::Run(void* ptr)
38 {
39  if(!CheckTransportOpen()) return 0;
40  if(fbReceiverMode)
41  {
42  // server side: receive status objects from client
43  Int_t rev = fxTransport->ReceiveBuffer();
44  if(rev>=0)
45  {
46  TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
47  if(CheckStopBuffer(buf)) return 0; // stop for disconnect mode
48  fxBufferQueue->AddBuffer(buf, kTRUE);
49  }
50  else
51  {
53  {
54  // TSocket error because of window resize, do not abort!
55  TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
57  }
58  else if(fxManager->IsTerminating())
59  {
60  //std::cout <<"Receive error in "<<GetName()<< " while threadmanager is terminating. Ignored!" << std::endl;
61  TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
62  GetThread()->Stop();
63  }
64  else
65  {
66  TGo4Log::Debug(" !!!Receive Error in %s!!!",
67  GetName());
68  //GetThread()->Stop(); std::cout <<"Stopped status runnable. no termination" << std::endl;
70  }
71  }
72 
73  }
74  else
75  {
76  // client side: send status buffer to server
77  // get next status buffer from queue or wait for it
78  TBuffer* buf= fxBufferQueue->WaitBuffer();
79  if (buf)
80  // check if there is really an object from queue
81  {
82  CheckStopBuffer(buf);
83  fxTransport->SendBuffer(buf);
85  }
86  } // else if(fbReceiverMode)
87 
88 
89 return 0;
90 }
91 
TGo4ThreadManager * fxManager
Definition: TGo4Runnable.h:71
const TBuffer * GetBuffer() const
Definition: TGo4Socket.h:58
Int_t SendBuffer(TBuffer *buf)
Definition: TGo4Socket.cxx:222
TGo4Queue * GetStatusQueue() const
Bool_t Stop()
Definition: TGo4Thread.cxx:327
TGo4Thread * GetThread() const
Definition: TGo4Runnable.h:45
static void SetLastSignal(Int_t v=0)
TGo4Socket * GetStatusTransport() const
TBuffer * WaitBuffer()
virtual Int_t Run(void *ptr)
Int_t ReceiveBuffer()
Definition: TGo4Socket.cxx:275
void AddBuffer(TBuffer *buffer, Bool_t clone=kFALSE)
Bool_t CheckStopBuffer(TBuffer *buf, Int_t *result=0)
Bool_t IsTerminating() const
void FreeBuffer(TBuffer *buffer)
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:274