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