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