00001 // $Id: TGo4TaskHandlerRunnable.cxx 478 2009-10-29 12:26:09Z linev $ 00002 //----------------------------------------------------------------------- 00003 // The GSI Online Offline Object Oriented (Go4) Project 00004 // Experiment Data Processing at EE department, GSI 00005 //----------------------------------------------------------------------- 00006 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH 00007 // Planckstr. 1, 64291 Darmstadt, Germany 00008 // Contact: http://go4.gsi.de 00009 //----------------------------------------------------------------------- 00010 // This software can be used under the license agreements as stated 00011 // in Go4License.txt file which is part of the distribution. 00012 //----------------------------------------------------------------------- 00013 00014 #include "TGo4TaskHandlerRunnable.h" 00015 00016 #include "TGo4Log.h" 00017 #include "TGo4Socket.h" 00018 #include "TGo4BufferQueue.h" 00019 #include "TGo4TaskHandler.h" 00020 #include "TGo4TaskHandlerAbortException.h" 00021 00022 #include "TGo4Thread.h" 00023 #include "Go4EmergencyCommands.h" 00024 00025 TGo4TaskHandlerRunnable::TGo4TaskHandlerRunnable(const char* name, TGo4ThreadManager* man, TGo4TaskHandler* hand, Bool_t receivermode) 00026 :TGo4Runnable(name,man), fxTransport(0), fbReceiverMode(0) 00027 { 00028 fxTaskHandler=hand; 00029 fbReceiverMode=receivermode; 00030 } 00031 00032 TGo4TaskHandlerRunnable::~TGo4TaskHandlerRunnable() 00033 { 00034 } 00035 00036 TGo4TaskHandler* TGo4TaskHandlerRunnable::GetTaskHandler() 00037 { 00038 return fxTaskHandler; 00039 } 00040 00041 Bool_t TGo4TaskHandlerRunnable::CheckStopBuffer(TBuffer* buf, Int_t* result) 00042 { 00043 if(buf==0) return kFALSE; 00044 //cout <<"CCCCCCCCCC CheckStopBuffer in "<< GetName() << endl; 00045 Int_t val=TGo4BufferQueue::DecodeValueBuffer(buf); 00046 if(result) *result=val; 00047 if(val<0) return kFALSE; // no valid message in buffer 00048 Go4EmergencyCommand_t comvalue= (Go4EmergencyCommand_t) (val); 00049 if(comvalue==kComCloseInput) 00050 { 00051 //cout <<"CCCCCCCCCC CheckStopBuffer has close input in "<< GetName() <<endl; 00052 GetThread()->Stop(); 00053 return kTRUE; 00054 } 00055 else if (comvalue==kComAbortTask) 00056 { 00057 //cout <<"CCCCCCCCCC CheckStopBuffer has task abort command in "<< GetName() <<endl; 00058 TGo4Log::Debug(" !!!Receiving taskhandler abort buffer in %s !!!", GetName()); 00059 throw TGo4TaskHandlerAbortException(this); 00060 00061 } 00062 else 00063 { 00064 return kFALSE; 00065 } 00066 } 00067 00068 Bool_t TGo4TaskHandlerRunnable::CheckTransportOpen() 00069 { 00070 Bool_t open=kTRUE; 00071 if(fxTransport==0) 00072 open=kFALSE; 00073 else if(!fxTransport->IsOpen()) 00074 open=kFALSE; 00075 else 00076 open=kTRUE; 00077 if(!open) TGo4Thread::Sleep(TGo4TaskHandler::Get_fguPORTWAITTIME()); 00078 // avoid wild looping in Run() when socket is not open 00079 return open; 00080 }