GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4DataRunnable.cxx
Go to the documentation of this file.
1// $Id$
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"
25
28 TGo4TaskHandler *hand,
29 Bool_t receivermode)
30 :TGo4TaskHandlerRunnable(name,man,hand,receivermode)
31{
32 fxBufferQueue=dynamic_cast<TGo4BufferQueue*> (fxTaskHandler->GetDataQueue() );
33 fxTransport=fxTaskHandler->GetDataTransport();
34}
35
39
40Int_t TGo4DataRunnable::Run(void *ptr)
41{
42 if(!CheckTransportOpen()) return 0;
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 GetThread()->Stop();
55 TGo4Command *qcommand = new TGo4ComDisconnectSlave;
56 TGo4Task* cli = dynamic_cast<TGo4Task*>(fxManager);
57 if(cli) cli->SubmitLocalCommand(qcommand);
58 return 0;
59 }
60 else
61 {
62 fxBufferQueue->AddBuffer(buf, kTRUE);
63 }
64 }
65 else
66 {
67 // error
69 //if (TGo4SocketSignalHandler::fgxLastSignal == kSigWindowChanged)
70 {
71 // TSocket error because of window resize, do not abort!
72 TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
74 //TGo4SocketSignalHandler::fgxLastSignal = (ESignals) 0;
75 }
76 else if(fxManager->IsTerminating())
77 {
78 TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
79 GetThread()->Stop();
80 }
81 else
82 {
83 TGo4Log::Debug(" !!!Receive Error in %s!!!", GetName());
84 //GetThread()->Stop(); std::cout <<"Stopped data runnable. no termination" << std::endl;
86 }
87
88 } // end if(rev >= 0)
89
90 }
91 else
92 {
93 // get next command from queue or wait for it
94 TBuffer *buf= fxBufferQueue->WaitBuffer();
95 if (buf)
96 // check if there is really an object from queue
97 {
98 CheckStopBuffer(buf);
99 fxTransport->SendBuffer(buf);
100 fxBufferQueue->FreeBuffer(buf); // will delete it or put it back into own free buffer list
101 }
102 }
103 return 0;
104}
Go4EmergencyCommand_t
Class containing a pointer queue for TBuffers.
master command: current slave is removed (disconnected) from server
This is the Go4 Abstract Command Class; part of the Base command pattern.
Definition TGo4Command.h:35
Int_t Run(void *) override
The working function which runs in the thread.
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
TGo4Thread * GetThread() const
TGo4ThreadManager * fxManager
The threadmanager which is responsible for our thread.
static void SetLastSignal(Int_t v=0)
Bool_t fbReceiverMode
flag indicating operation mode of runnable, depending on client or server mode of task handler
Bool_t CheckTransportOpen()
Test if socket transport exists and is open.
Bool_t CheckStopBuffer(TBuffer *buf, Int_t *result=nullptr)
Test if buffer contains a message to stop this runnable.
TGo4TaskHandler * fxTaskHandler
link to external task handler (for server mode) 1 1
TGo4Socket * fxTransport
link to external inter-tasl transport channel
TGo4TaskHandlerRunnable(const char *name, TGo4ThreadManager *man, TGo4TaskHandler *hand, Bool_t receivermode=kTRUE)
TGo4BufferQueue * fxBufferQueue
Link to external buffer queue.
This class is responsible for the interconnection of two tasks: provided are three communication chan...
Go4 Task.
Definition TGo4Task.h:39
Bool_t SubmitLocalCommand(TGo4Command *com)
Send given command to the current client task.
Definition TGo4Task.cxx:508
Go4 thread manager.
Bool_t Stop()
resets running flag for runnable