Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4CommandProtoList.cxx

Go to the documentation of this file.
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 "TGo4CommandProtoList.h"
00017 
00018 #include "Riostream.h"
00019 
00020 #include "TMutex.h"
00021 #include "TObjArray.h"
00022 
00023 #include "TGo4LockGuard.h"
00024 #include "TGo4Log.h"
00025 #include "TGo4RemoteCommand.h"
00026 
00027 TGo4CommandProtoList::TGo4CommandProtoList(const char* name) :
00028    TNamed(name,"This is a TGo4CommandProtoList")
00029 {
00030    TRACE((14,"TGo4CommandProtoList::TGo4CommandProtoList(Text_t*) ctor",__LINE__, __FILE__));
00031 
00032    fxListMutex = new TMutex;
00033    fxCommandList = new TObjArray;
00034    AddCommand (new TGo4RemoteCommand);
00035 }
00036 
00037 TGo4CommandProtoList::~TGo4CommandProtoList()
00038 {
00039    TRACE((14,"TGo4CommandProtoList::~TGo4CommandProtoList() dtor",__LINE__, __FILE__));
00040    {
00041       TGo4LockGuard listguard(fxListMutex);
00042       fxCommandList->Delete();
00043       delete fxCommandList;
00044    }
00045    delete fxListMutex;
00046 }
00047 
00048 void TGo4CommandProtoList::ShowCommands()
00049 {
00050 TRACE((12,"TGo4CommandProtoList::ShowCommands()",__LINE__, __FILE__));
00051 
00052    {
00053    TGo4LockGuard listguard(fxListMutex);
00054    TGo4Command* com;
00055    TIter iter(fxCommandList);
00056    TGo4Log::Debug(" CommandProtoList Showing the known commands:");
00057    cout << " Name: \t| Description:"<<endl;
00058    while((com= (TGo4Command*) iter())!=0)
00059       {
00060          cout << " "<< com->GetName()<<"\t| "<<com->What()<<endl;
00061       }
00062    }
00063 }
00064 
00065 TGo4Command* TGo4CommandProtoList::MakeCommand(const char* name)
00066 {
00067 TRACE((12,"TGo4CommandProtoList::MakeCommand(Text_t*)",__LINE__, __FILE__));
00068 TGo4Command* rev=0;
00069    {
00070    TGo4LockGuard listguard(fxListMutex);
00071    TObject* obj=fxCommandList->FindObject(name);
00072       if(obj==0)
00073       // is command in list?
00074          {
00075             //no, do nothing
00076             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00077          }
00078       else
00079          {
00080             // yes, create it it
00081             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) cloning command",__LINE__, __FILE__));
00082             rev= (TGo4Command*) obj->Clone();
00083 
00084          }
00085    }
00086 
00087 return rev;
00088 
00089 }
00090 
00091 TGo4Command* TGo4CommandProtoList::MakeCommand(TGo4RemoteCommand* remcon)
00092 {
00093 if(remcon==0) return 0;
00094 TGo4Command* com=MakeCommand(remcon->GetCommandName());
00095 if(com==0) return 0;
00096 com->Set(remcon); // copy optional parameters from remote command
00097 return com;
00098 }
00099 
00100 
00101 void TGo4CommandProtoList::RemoveCommand(const char* name)
00102 {
00103 TRACE((12,"TGo4CommandProtoList::RemoveCommand(Text_t*)",__LINE__, __FILE__));
00104    {
00105    TGo4LockGuard listguard(fxListMutex);
00106    TObject* obj=fxCommandList->FindObject(name);
00107       if(obj==0)
00108       // is command in list?
00109          {
00110             //no, do nothing
00111             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00112          }
00113       else
00114          {
00115             // yes, remove it
00116             TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) removing command from array",__LINE__, __FILE__));
00117             fxCommandList->Remove(obj);
00118             fxCommandList->Compress();
00119             fxCommandList->Expand(fxCommandList->GetLast()+1);
00120             delete obj;
00121          }
00122    }
00123 }
00124 
00125 
00126 void TGo4CommandProtoList::AddCommand(TGo4Command* com)
00127 {
00128 TRACE((12,"TGo4CommandProtoList::AddCommand(TGo4Command*)",__LINE__, __FILE__));
00129    {
00130    TGo4LockGuard listguard(fxListMutex);
00131       if(fxCommandList->FindObject(com)==0)
00132       // is command already in list?
00133          {
00134             //no, add new command
00135             TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) Adding new go4 commandto array",__LINE__, __FILE__));
00136             fxCommandList->AddLast(com);
00137          }
00138       else
00139          {
00140             // yes, do nothing
00141             TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) command was already in array",__LINE__, __FILE__));
00142          }
00143    }
00144 }
00145 
00146 TGo4CommandProtoList& TGo4CommandProtoList::operator+=(const TGo4CommandProtoList& two)
00147 {
00148    if(this!=&two) {
00149        TGo4LockGuard outerguard(two.fxListMutex);
00150        TIter iter(two.fxCommandList);
00151        TGo4Command* com;
00152        while ( (com=dynamic_cast<TGo4Command*>(iter())) !=0)
00153               AddCommand(com);
00154        cout <<"CommandProtoList "<< GetName() <<"used operator += for adding list " << two.GetName() << endl;
00155    }
00156    return *this;
00157 }
00158 
00159 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:05 2008 for Go4-v3.04-1 by  doxygen 1.4.2