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