00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4DataRunnable.h"
00015
00016 #include "Riostream.h"
00017 #include <signal.h>
00018
00019 #include "TGo4Log.h"
00020 #include "TGo4Thread.h"
00021 #include "TGo4BufferQueue.h"
00022 #include "TGo4SocketSignalHandler.h"
00023 #include "TGo4Socket.h"
00024 #include "TGo4TaskHandler.h"
00025 #include "TGo4TaskHandlerAbortException.h"
00026 #include "TGo4Task.h"
00027 #include "TGo4ComDisconnectSlave.h"
00028
00029 TGo4DataRunnable::TGo4DataRunnable(const char* name,
00030 TGo4ThreadManager* man,
00031 TGo4TaskHandler* hand,
00032 Bool_t receivermode)
00033 :TGo4TaskHandlerRunnable(name,man,hand,receivermode)
00034 {
00035 fxBufferQueue=dynamic_cast<TGo4BufferQueue*> (fxTaskHandler->GetDataQueue() );
00036 fxTransport=fxTaskHandler->GetDataTransport();
00037 }
00038
00039 TGo4DataRunnable::~TGo4DataRunnable()
00040 {
00041 }
00042
00043 Int_t TGo4DataRunnable::Run(void* ptr)
00044 {
00045 if(!CheckTransportOpen()) return 0;
00046 if(fbReceiverMode)
00047 {
00048 Int_t rev=fxTransport->ReceiveBuffer();
00049 if(rev>=0)
00050 {
00051 TBuffer* buf=const_cast<TBuffer*> (fxTransport->GetBuffer());
00052 Int_t val=0;
00053 if(CheckStopBuffer(buf,&val)) return 0;
00054 Go4EmergencyCommand_t comvalue= (Go4EmergencyCommand_t) (val);
00055 if(val>=0 && comvalue==kComQuit)
00056 {
00057
00058 GetThread()->Stop();
00059 TGo4Command* qcommand = new TGo4ComDisconnectSlave;
00060 TGo4Task* cli = dynamic_cast<TGo4Task*>(fxManager);
00061 if(cli) cli->SubmitLocalCommand(qcommand);
00062 return 0;
00063 }
00064 else
00065 {
00066 fxBufferQueue->AddBuffer(buf, kTRUE);
00067 }
00068 }
00069 else
00070 {
00071
00072 if (TGo4SocketSignalHandler::GetLastSignal() == SIGWINCH)
00073
00074 {
00075
00076 TGo4Log::Debug(" %s: caught SIGWINCH ",GetName());
00077 TGo4SocketSignalHandler::SetLastSignal(0);
00078
00079 }
00080 else if(fxManager->IsTerminating())
00081 {
00082
00083 TGo4Log::Debug("Receive Error in %s during threadmanager termination. Ignored.",GetName());
00084 GetThread()->Stop();
00085
00086 }
00087 else
00088 {
00089 TGo4Log::Debug(" !!!Receive Error in %s!!!",
00090 GetName());
00091
00092 throw TGo4TaskHandlerAbortException(this);
00093 }
00094
00095 }
00096
00097 }
00098 else
00099 {
00100
00101 TBuffer* buf= fxBufferQueue->WaitBuffer();
00102 if (buf)
00103
00104 {
00105 CheckStopBuffer(buf);
00106 fxTransport->SendBuffer(buf);
00107 fxBufferQueue->FreeBuffer(buf);
00108 }
00109 }
00110 return 0;
00111 }