Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4CommandsBase/TGo4CommandInvoker.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE 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 "TGo4CommandInvoker.h"
00017 
00018 #include "Go4Log/TGo4Log.h"
00019 #include "Go4LockGuard/TGo4LockGuard.h"
00020 
00021 class TGo4Pair : public TObject {
00022   public:
00023      TGo4Pair(const char* name, TGo4CommandReceiver* p) : 
00024         TObject(),
00025         fxName(name), 
00026         fxReceiver(p) 
00027      {
00028      }
00029      
00030      virtual ~TGo4Pair() {}
00031      
00032      virtual const char* GetName() const { return fxName.Data(); }
00033      
00034      TGo4CommandReceiver* GetReceiver() const { return fxReceiver; }
00035 
00036   private:
00037      TString fxName;         
00038      TGo4CommandReceiver* fxReceiver; 
00039 };
00040 
00041 // ***************************************************************
00042 
00043 ClassImp(TGo4CommandInvoker)
00044 
00045 TMutex * TGo4CommandInvoker::fxMutex = 0;
00046 TGo4CommandInvoker * TGo4CommandInvoker::fxInstance = 0;
00047 TObjArray * TGo4CommandInvoker::fxArray = 0;
00048 
00049 TGo4CommandInvoker * TGo4CommandInvoker::Instance()
00050 {
00051     TRACE((10,"TGo4CommandInvoker * TGo4CommandInvoker::Instance()", __LINE__, __FILE__));
00052     if (fxInstance == 0)
00053       fxInstance = new TGo4CommandInvoker();
00054     return fxInstance;
00055 }
00056 
00057 void TGo4CommandInvoker::Register(const char* name, TGo4CommandReceiver *p)
00058 {
00059     TRACE((12,"static void TGo4CommandInvoker::Register(Text_t * name, TGo4CommandReceiver *p)", __LINE__, __FILE__));
00060     TGo4LockGuard lockguard(fxMutex);
00061     fxArray->Add(new TGo4Pair(name, p));
00062 }
00063 
00064 TGo4CommandReceiver* TGo4CommandInvoker::Lookup(const char* name)
00065 {
00066   TRACE((10,"static TGo4CommandReceiver * TGo4CommandInvoker::Lookup(Text_t * name)", __LINE__, __FILE__));
00067   TGo4Pair* pair = (TGo4Pair*) fxArray->FindObject(name);
00068   
00069   return pair!=0 ? pair->GetReceiver() : 0;
00070 }
00071 
00072 TGo4CommandInvoker::~TGo4CommandInvoker()
00073    {
00074      TRACE((12,"TGo4CommandInvoker::~TGo4CommandInvoker()", __LINE__, __FILE__));
00075      if(fxCommand)
00076        delete fxCommand;
00077      fxCommand = 0;
00078      fxArray->Delete();
00079      delete fxArray;
00080    }
00081 
00082 TGo4CommandInvoker::TGo4CommandInvoker()
00083    {
00084      TRACE((12,"TGo4CommandInvoker::TGo4CommandInvoker()", __LINE__, __FILE__));
00085      fxCommand = 0;
00086      fxArray = new TObjArray(10);
00087      fxMutex = new TMutex(kTRUE);
00088    }
00089 
00090 void TGo4CommandInvoker::Invoke(TGo4Command * com)
00091 {
00092    if(com==0) return;
00093    TGo4LockGuard lockguard(fxMutex);
00094    TGo4CommandReceiver *rec = Lookup(com->GetReceiverName());
00095    if(rec!=0) {
00096        com->SetReceiver(rec);  
00097        if(com->GetMode()>=com->GetProtection())
00098            com->ExeCom();
00099        else
00100            com->RefuseCom();
00101     } else
00102       TGo4Log::Debug(" CommandInvoker: UNKNOWN receiver");
00103 }
00104 
00105 void TGo4CommandInvoker::Invoke()
00106 {
00107      TRACE((12,"void TGo4CommandInvoker::Invoke()", __LINE__, __FILE__));
00108      TGo4LockGuard lockguard(fxMutex);
00109      if(fxCommand==0) return;
00110      
00111      TGo4CommandReceiver* rcv = Lookup(fxCommand->GetReceiverName());
00112      
00113      if(rcv!=0) {
00114           fxCommand->SetReceiver(rcv);
00115           fxCommand->ExeCom();
00116      }
00117      delete fxCommand;
00118      fxCommand = 0;
00119 }
00120 
00121 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:51 2005 for Go4-v2.10-5 by doxygen1.2.15