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