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