00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4CommandProtoList.h"
00015
00016 #include "Riostream.h"
00017
00018 #include "TMutex.h"
00019 #include "TObjArray.h"
00020
00021 #include "TGo4LockGuard.h"
00022 #include "TGo4Log.h"
00023 #include "TGo4RemoteCommand.h"
00024
00025 TGo4CommandProtoList::TGo4CommandProtoList(const char* name) :
00026 TNamed(name,"This is a TGo4CommandProtoList")
00027 {
00028 TRACE((14,"TGo4CommandProtoList::TGo4CommandProtoList(const char*) ctor",__LINE__, __FILE__));
00029
00030 fxListMutex = new TMutex;
00031 fxCommandList = new TObjArray;
00032 AddCommand (new TGo4RemoteCommand);
00033 }
00034
00035 TGo4CommandProtoList::~TGo4CommandProtoList()
00036 {
00037 TRACE((14,"TGo4CommandProtoList::~TGo4CommandProtoList() dtor",__LINE__, __FILE__));
00038 {
00039 TGo4LockGuard listguard(fxListMutex);
00040 fxCommandList->Delete();
00041 delete fxCommandList;
00042 }
00043 delete fxListMutex;
00044 }
00045
00046 void TGo4CommandProtoList::ShowCommands()
00047 {
00048 TRACE((12,"TGo4CommandProtoList::ShowCommands()",__LINE__, __FILE__));
00049
00050 TGo4LockGuard listguard(fxListMutex);
00051 TGo4Command* com;
00052 TIter iter(fxCommandList);
00053 TGo4Log::Debug(" CommandProtoList Showing the known commands:");
00054 cout << " Name: \t| Description:"<<endl;
00055 while((com= (TGo4Command*) iter())!=0)
00056 cout << " "<< com->GetName()<<"\t| "<<com->What()<<endl;
00057 }
00058
00059 TGo4Command* TGo4CommandProtoList::MakeCommand(const char* name)
00060 {
00061 TRACE((12,"TGo4CommandProtoList::MakeCommand(const char*)",__LINE__, __FILE__));
00062 TGo4Command* rev=0;
00063 TGo4LockGuard listguard(fxListMutex);
00064 TObject* obj=fxCommandList->FindObject(name);
00065 if(obj==0) {
00066
00067 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00068 } else {
00069
00070 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) cloning command",__LINE__, __FILE__));
00071 rev= (TGo4Command*) obj->Clone();
00072 }
00073
00074 return rev;
00075
00076 }
00077
00078 TGo4Command* TGo4CommandProtoList::MakeCommand(TGo4RemoteCommand* remcon)
00079 {
00080 if(remcon==0) return 0;
00081 TGo4Command* com=MakeCommand(remcon->GetCommandName());
00082 if(com==0) return 0;
00083 com->Set(remcon);
00084 return com;
00085 }
00086
00087
00088 void TGo4CommandProtoList::RemoveCommand(const char* name)
00089 {
00090 TRACE((12,"TGo4CommandProtoList::RemoveCommand(const char*)",__LINE__, __FILE__));
00091
00092 TGo4LockGuard listguard(fxListMutex);
00093 TObject* obj=fxCommandList->FindObject(name);
00094 if(obj==0) {
00095
00096 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
00097 } else {
00098
00099 TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) removing command from array",__LINE__, __FILE__));
00100 fxCommandList->Remove(obj);
00101 fxCommandList->Compress();
00102 fxCommandList->Expand(fxCommandList->GetLast()+1);
00103 delete obj;
00104 }
00105 }
00106
00107
00108 void TGo4CommandProtoList::AddCommand(TGo4Command* com)
00109 {
00110 TRACE((12,"TGo4CommandProtoList::AddCommand(TGo4Command*)",__LINE__, __FILE__));
00111 TGo4LockGuard listguard(fxListMutex);
00112 if(fxCommandList->FindObject(com)==0) {
00113
00114 TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) Adding new go4 commandto array",__LINE__, __FILE__));
00115 fxCommandList->AddLast(com);
00116 } else {
00117
00118 TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) command was already in array",__LINE__, __FILE__));
00119 }
00120 }
00121
00122 TGo4CommandProtoList& TGo4CommandProtoList::operator+=(const TGo4CommandProtoList& two)
00123 {
00124 if(this!=&two) {
00125 TGo4LockGuard outerguard(two.fxListMutex);
00126 TIter iter(two.fxCommandList);
00127 TGo4Command* com;
00128 while ( (com=dynamic_cast<TGo4Command*>(iter())) !=0)
00129 AddCommand(com);
00130 cout <<"CommandProtoList "<< GetName() <<"used operator += for adding list " << two.GetName() << endl;
00131 }
00132 return *this;
00133 }