GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4CommandProtoList.cxx
Go to the documentation of this file.
1 // $Id: TGo4CommandProtoList.cxx 2769 2020-04-16 14:54:23Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4CommandProtoList.h"
15 
16 #include <iostream>
17 
18 #include "TMutex.h"
19 #include "TObjArray.h"
20 
21 #include "TGo4LockGuard.h"
22 #include "TGo4Log.h"
23 #include "TGo4RemoteCommand.h"
24 
26  TNamed(name,"This is a TGo4CommandProtoList")
27 {
28  GO4TRACE((14,"TGo4CommandProtoList::TGo4CommandProtoList(const char*) ctor",__LINE__, __FILE__));
29 
30  fxListMutex = new TMutex;
31  fxCommandList = new TObjArray;
33 }
34 
36 {
37  GO4TRACE((14,"TGo4CommandProtoList::~TGo4CommandProtoList() dtor",__LINE__, __FILE__));
38  {
39  TGo4LockGuard listguard(fxListMutex);
40  fxCommandList->Delete();
41  delete fxCommandList;
42  }
43  delete fxListMutex;
44 }
45 
47 {
48  GO4TRACE((12,"TGo4CommandProtoList::ShowCommands()",__LINE__, __FILE__));
49 
50  TGo4LockGuard listguard(fxListMutex);
51  TGo4Command* com;
52  TIter iter(fxCommandList);
53  TGo4Log::Debug(" CommandProtoList Showing the known commands:");
54  std::cout << " Name: \t| Description:"<<std::endl;
55  while((com= (TGo4Command*) iter())!=0)
56  std::cout << " "<< com->GetName()<<"\t| "<<com->What()<<std::endl;
57 }
58 
60 {
61  GO4TRACE((12,"TGo4CommandProtoList::MakeCommand(const char*)",__LINE__, __FILE__));
62  TGo4Command* rev=0;
63  TGo4LockGuard listguard(fxListMutex);
64  TObject* obj=fxCommandList->FindObject(name);
65  if(obj==0) {
66  //no, do nothing
67  GO4TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
68  } else {
69  // yes, create it it
70  GO4TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) cloning command",__LINE__, __FILE__));
71  rev= (TGo4Command*) obj->Clone();
72  }
73 
74  return rev;
75 
76 }
77 
79 {
80  if(remcon==0) return 0;
81  TGo4Command* com=MakeCommand(remcon->GetCommandName());
82  if(com==0) return 0;
83  com->Set(remcon); // copy optional parameters from remote command
84  return com;
85 }
86 
87 
89 {
90  GO4TRACE((12,"TGo4CommandProtoList::RemoveCommand(const char*)",__LINE__, __FILE__));
91 
92  TGo4LockGuard listguard(fxListMutex);
93  TObject* obj=fxCommandList->FindObject(name);
94  if(obj==0) {
95  //no, do nothing
96  GO4TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) command not found in array",__LINE__, __FILE__));
97  } else {
98  // yes, remove it
99  GO4TRACE((10,"TGo4CommandProtoList::RemoveCommand(TGo4Command*) removing command from array",__LINE__, __FILE__));
100  fxCommandList->Remove(obj);
101  fxCommandList->Compress();
102  fxCommandList->Expand(fxCommandList->GetLast()+1);
103  delete obj;
104  }
105 }
106 
107 
109 {
110  GO4TRACE((12,"TGo4CommandProtoList::AddCommand(TGo4Command*)",__LINE__, __FILE__));
111  TGo4LockGuard listguard(fxListMutex);
112  if(fxCommandList->FindObject(com)==0) {
113  //no, add new command
114  GO4TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) Adding new go4 commandto array",__LINE__, __FILE__));
115  fxCommandList->AddLast(com);
116  } else {
117  // yes, do nothing
118  GO4TRACE((10,"TGo4CommandProtoList::AddCommand(TGo4Command*) command was already in array",__LINE__, __FILE__));
119  }
120 }
121 
123 {
124  if(this!=&two) {
125  TGo4LockGuard outerguard(two.fxListMutex);
126  TIter iter(two.fxCommandList);
127  TGo4Command* com;
128  while ( (com=dynamic_cast<TGo4Command*>(iter())) !=0)
129  AddCommand(com);
130  std::cout <<"CommandProtoList "<< GetName() <<"used operator += for adding list " << two.GetName() << std::endl;
131  }
132  return *this;
133 }
virtual void Set(TGo4RemoteCommand *remcon)
const char * GetCommandName() const
void RemoveCommand(const char *name)
TGo4CommandProtoList & operator+=(const TGo4CommandProtoList &two)
void AddCommand(TGo4Command *com)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TGo4Command * MakeCommand(const char *name)
const char * What() const
static void Debug(const char *text,...)
Definition: TGo4Log.cxx:284