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

/Go4GUIRegistry/TGo4GUIRegistry.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 "TGo4GUIRegistry.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TApplication.h"
00021 
00022 #include "TGo4SubmittedCommandsEntry.h"
00023 #include "TGo4RecieverInfo.h"
00024 #include "TGo4RegisteredSlotsList.h"
00025 #include "TGo4DependentStatusList.h"
00026 #include "Go4StatusBase/TGo4Status.h"
00027 #include "Go4LockGuard/TGo4LockGuard.h"
00028 #include "Go4AnalysisClient/TGo4AnalysisClientStatus.h"
00029 #include "Go4CommandsTaskHandler/Go4CommandsTaskHandler.h"
00030 #include "Go4GUIBase/TGo4SlotsBaseClass.h"
00031 #include "Go4GUI/TGo4MainWindow.h"
00032 #include "Go4Display/TGo4Display.h"
00033 #include "Go4Queue/TGo4BufferQueue.h"
00034 #include "Go4TaskHandler/TGo4TaskHandler.h"
00035 
00036 TGo4GUIRegistry * TGo4GUIRegistry::fxInstance= 0;
00037 
00038 TGo4GUIRegistry *TGo4GUIRegistry::Instance()
00039 {
00040    if (fxInstance == 0)
00041       fxInstance = new TGo4GUIRegistry();
00042    return fxInstance;
00043 }
00044 
00045 TGo4GUIRegistry::TGo4GUIRegistry()
00046 {
00047    SlotClassList.SetOwner(kTRUE);
00048 
00049    // TGo4LockGuard globalguard;
00050    DependenceList.SetOwner(kTRUE);
00051    
00052    SubmittedCommandsList.SetOwner(kTRUE);
00053 
00054    fxDisplayStatusMonitor = 0;
00055    fxTGo4Display = 0;
00056    fxDisplayAnalysisConfig = 0;
00057    fxMainWindow = 0;
00058    fxCentralWindow = 0;
00059    fxLogInfo = 0;
00060    fxMemBrowser = 0;
00061    fbAnalysisReady = kFALSE;
00062    fbAnaSettingsReady = kFALSE;
00063    fiClientRole=-1;
00064 }
00065 
00066 TGo4GUIRegistry::~TGo4GUIRegistry()
00067 {
00068     // TGo4LockGuard globalguard;
00069 }
00070 
00071 void TGo4GUIRegistry::UnRegisterClass(TGo4SlotsBaseClass * p, TGo4Status* s)
00072 {
00073       //cout << "TGo4GUIRegistry::UnRegisterClass " << p->GetName() << endl;
00074    // TGo4LockGuard globalguard;
00075    
00076    TObject* item = SlotClassList.FindObject(p->GetName());
00077    if(item!=0) {
00078       SlotClassList.Remove(item);
00079       SlotClassList.Compress();
00080       delete item;
00081    }
00082    
00083    for(int n=0;n<=DependenceList.GetLast();n++) {
00084       TGo4DependentStatusList* entry = (TGo4DependentStatusList*) DependenceList.At(n);
00085       if (entry->SlotClass()==p) {
00086          DependenceList.Remove(entry);
00087          delete entry;
00088       }
00089    }
00090    DependenceList.Compress();
00091 
00092    for(int n=0;n<=SubmittedCommandsList.GetLast();n++) {
00093        TGo4SubmittedCommandsEntry* RObject = 
00094           (TGo4SubmittedCommandsEntry*) SubmittedCommandsList.At(n);
00095        RObject->RemoveSlotEntries(p); 
00096        if (RObject->NoOfRecv()==0) {
00097           SubmittedCommandsList.Remove(RObject);
00098           delete RObject;
00099        }
00100    } 
00101    SubmittedCommandsList.Compress();
00102 }
00103 
00104 void TGo4GUIRegistry::UpdateDependents(TGo4Status* s)
00105 {
00106    // TGo4LockGuard globalguard;
00107    
00108    for(int n=0;n<=DependenceList.GetLast();n++) {
00109       TGo4DependentStatusList* entry = (TGo4DependentStatusList*) DependenceList.At(n);
00110       if (entry->StatusClass() == s) 
00111         entry->SlotClass()->StatusChanged(s);
00112    }
00113 }
00114 
00115 void TGo4GUIRegistry::UnRegisterDependentClass(TGo4SlotsBaseClass *p, const char* name)
00116 {
00117    for(int n=0;n<=DependenceList.GetLast();n++) {
00118       TGo4DependentStatusList* entry = (TGo4DependentStatusList*) DependenceList.At(n);
00119       if((entry->SlotClass() == p) && (strcmp(entry->GetName(),name)==0)) {
00120           DependenceList.Remove(entry);
00121           delete entry;
00122       }
00123    }
00124    DependenceList.Compress();
00125 }
00126 
00127 TGo4Status* TGo4GUIRegistry::GetStatus(const char * name)
00128 {
00129    // TGo4LockGuard globalguard;
00130    
00131    if (name==0) return 0;
00132    
00133    for(int n=0;n<=SlotClassList.GetLast();n++) {
00134       TGo4RegisteredSlotsList* entry = 
00135         (TGo4RegisteredSlotsList*) SlotClassList.At(n);
00136       if (strcmp(name , entry->GetStatusClass()->GetName())==0) 
00137         return entry->GetStatusClass();
00138    }
00139    
00140    return 0;
00141 }
00142 
00143 TGo4SlotsBaseClass* TGo4GUIRegistry::GetSlotClass(const char * name)
00144 {
00145    // TGo4LockGuard globalguard;
00146 
00147    if (name==0) return 0;
00148    
00149    TGo4RegisteredSlotsList* entry = (TGo4RegisteredSlotsList*) SlotClassList.FindObject(name);
00150    
00151    return entry==0 ? 0 : entry->GetSlotClass();
00152 }
00153 
00154 TGo4SlotsBaseClass* TGo4GUIRegistry::GetSlotClass(TGo4SlotsBaseClass *SlotClass)
00155 {
00156     // TGo4LockGuard globalguard;
00157    return  GetSlotClass(SlotClass->GetName());
00158 }
00159 
00160 QWidget *TGo4GUIRegistry::GetGUIClass(TGo4SlotsBaseClass *SlotClass)
00161 {
00162    // TGo4LockGuard globalguard;
00163    TGo4RegisteredSlotsList* entry = 
00164      dynamic_cast <TGo4RegisteredSlotsList *> 
00165        (SlotClassList.FindObject(SlotClass->GetName()));
00166    return entry==0 ? 0 : entry->GetGUI();
00167 }
00168 
00169 QWidget *TGo4GUIRegistry::GetMainWindow()
00170 {
00171     // TGo4LockGuard globalguard;
00172    return fxMainWindow;
00173 }
00174 
00175 void TGo4GUIRegistry::SetMainWindow(QWidget * widget)
00176 {
00177     // TGo4LockGuard globalguard;
00178    fxMainWindow = widget;
00179 }
00180 
00181 QWidget *TGo4GUIRegistry::GetCentralWindow()
00182 {
00183     // TGo4LockGuard globalguard;
00184    return fxCentralWindow;
00185 }
00186 
00187 void TGo4GUIRegistry::SetCentralWindow(QWidget * widget)
00188 {
00189     // TGo4LockGuard globalguard;
00190    fxCentralWindow = widget;
00191 }
00192 
00193 void  TGo4GUIRegistry::GuiIsChanged(TGo4SlotsBaseClass * SlotClass, QWidget * GUI)
00194 {
00195    // TGo4LockGuard globalguard;
00196    TGo4RegisteredSlotsList* entry = 
00197       dynamic_cast <TGo4RegisteredSlotsList*> 
00198         (SlotClassList.FindObject(SlotClass->GetName()));
00199    if (entry!=0)
00200      entry->SetGUI(GUI);
00201 }
00202 
00203 void TGo4GUIRegistry::RegisterSlotClass(TGo4SlotsBaseClass * p, TGo4Status* s, QWidget *GUI)
00204 {
00205     // TGo4LockGuard globalguard;
00206 
00207     SlotClassList.Add(new TGo4RegisteredSlotsList(p->GetName(),p, s, GUI));
00208     
00209     if (s!=0)
00210        for(int n=0;n<=DependenceList.GetLast();n++) {
00211           TGo4DependentStatusList* entry = (TGo4DependentStatusList*) DependenceList.At(n);
00212           if (strcmp(s->GetName(), entry->GetName())==0) 
00213             entry->SetStatusClass(s);
00214        }
00215 }
00216 
00217 void TGo4GUIRegistry::RegisterDependentClass(TGo4SlotsBaseClass *p, const Char_t* name)
00218 {
00219    if (name==0) return; 
00220     
00221 // TGo4LockGuard globalguard;
00222    DependenceList.Add(new TGo4DependentStatusList(name, p, GetStatus(name)));
00223 }
00224 
00225 TGo4SubmittedCommandsEntry* TGo4GUIRegistry::FindCmdEntry(const char* name, Bool_t force)
00226 {
00227     if (name==0) return 0;
00228     
00229     TGo4SubmittedCommandsEntry *entry = 
00230       (TGo4SubmittedCommandsEntry*) SubmittedCommandsList.FindObject(name);
00231     if ((entry==0) && force) {
00232       entry = new TGo4SubmittedCommandsEntry(name);
00233       SubmittedCommandsList.Add(entry);
00234     } 
00235     return entry;
00236 }
00237 
00238 void TGo4GUIRegistry::DisplayData(TNamed * data)
00239 {
00240    if (data==0) return; 
00241     
00242    // TGo4LockGuard globalguard;
00243    TGo4SubmittedCommandsEntry *RObject = FindCmdEntry(data->GetName());
00244    
00245    if (RObject!=0) {
00246      
00247      TObjArray cleanup;
00248      
00249      Bool_t issubmited = kFALSE;
00250      
00251      // first process all entries
00252      for (int n=0;n<RObject->NoOfRecv();n++) {
00253          TGo4RecieverInfo* entry = RObject->GetRecv(n);
00254          
00255          if (issubmited && entry->IsSubmited()) continue;
00256          if (entry->IsSubmited()) issubmited = kTRUE;
00257          
00258          TGo4SlotsBaseClass* sl = entry->GetRecvSlot();
00259          if (sl==0) sl = fxMemBrowser;
00260          
00261          if(entry->GetCanvas()!=0)
00262             sl->AddObject(data, entry->GetCanvas(), entry->GetPad());
00263          else
00264             sl->AddObject(data);
00265             
00266          cleanup.Add(entry);   
00267      }
00268      
00269      // now remove all correspondent entries
00270      for (int n=0;n<=cleanup.GetLast();n++) {
00271         TGo4RecieverInfo* entry = (TGo4RecieverInfo*) cleanup.At(n); 
00272          if (!entry->IsMonitored()) 
00273            RObject->RemoveRecvEntry(entry);
00274      }
00275      
00276      if(RObject->NoOfRecv()==0) RemoveFromSubmittedList(RObject);
00277      
00278    } else
00279      fxMemBrowser->AddObject(data);
00280   
00281    delete data;
00282 }
00283 
00284 void TGo4GUIRegistry::SubmitEmergencyCommand(Int_t val)
00285 {
00286     // TGo4LockGuard globalguard;
00287     if(fxTGo4Display!=0) fxTGo4Display->SubmitEmergencyCommand((Go4EmergencyCommand_t)val);
00288 }
00289 
00290 void TGo4GUIRegistry::SubmitCommand(const char* name)
00291 {
00292    // TGo4LockGuard globalguard;
00293    if(fxTGo4Display!=0) fxTGo4Display->SubmitCommand(name);
00294 }
00295 
00296 void TGo4GUIRegistry::SubmitCommand(const char* name, TGo4SlotsBaseClass *p)
00297 {
00298    // TGo4LockGuard globalguard;
00299    if(fxTGo4Display==0) return;
00300    TGo4SubmittedCommandsEntry* entry = FindCmdEntry(name, kTRUE);
00301    entry->SetNewReciever(p, kFALSE, 0, 0, kTRUE);
00302    fxTGo4Display->SubmitCommand(name);
00303 }
00304 
00305 void TGo4GUIRegistry::SubmitCommand(TGo4Command* com, 
00306                                     const char* ObjectName,
00307                                     TGo4SlotsBaseClass *p, 
00308                                     Bool_t Monitor, 
00309                                     TQRootCanvas *c, 
00310                                     TPad *pad)
00311 {
00312   // TGo4LockGuard globalguard;
00313    if(fxTGo4Display==0) return;
00314    if ((ObjectName==0) || (p==0 && c==0)) {
00315       fxTGo4Display->SubmitCommand(com);
00316    } else {
00317       TGo4SubmittedCommandsEntry* entry = FindCmdEntry(ObjectName, kTRUE);
00318       entry->SetNewReciever(p, Monitor, c, pad, kTRUE);
00319       fxTGo4Display->SubmitCommand(com);
00320    }
00321 }
00322 
00323 void TGo4GUIRegistry::ReDirectObject(const char* ObjectName, TGo4SlotsBaseClass *p, bool Monitor, TQRootCanvas *c, TPad *pad)
00324 {
00325    // TGo4LockGuard globalguard;
00326    if(fxTGo4Display==0) return;
00327 
00328    if ((ObjectName==0) || ((p==0) && (c==0))) return;
00329 
00330    TGo4SubmittedCommandsEntry* entry = FindCmdEntry(ObjectName, kTRUE);
00331    entry->SetNewReciever(p, Monitor, c, pad, kFALSE);
00332 }
00333 
00334 TGo4Command* TGo4GUIRegistry::MakeCommand(const char* name)
00335 {
00336    TGo4Command* com = 0;
00337    if(fxTGo4Display!=0)    
00338       {
00339          com = fxTGo4Display->GetTask()->MakeCommand(name);
00340       }
00341    return com;
00342 }
00343 
00344 void TGo4GUIRegistry::SetDisplay(TGo4Display *DisplayClass)
00345 {
00346      // TGo4LockGuard globalguard;
00347     fxTGo4Display=DisplayClass;
00348 }
00349 
00350 void TGo4GUIRegistry::SetDisplayAnalysisConfig(TGo4SlotsBaseClass * p)
00351 {
00352    // TGo4LockGuard globalguard;
00353    if(p!=0) 
00354       fxDisplayAnalysisConfig=p;
00355 }
00356 
00357 void TGo4GUIRegistry::DisplayLog(TGo4Status * status)
00358 {
00359    if(status==0) return;
00360 
00361    if (status->InheritsFrom("TGo4AnalysisClientStatus")) {
00363       if(fxDisplayStatusMonitor!=0)
00364          fxDisplayStatusMonitor->StatusChanged(status);
00365       else
00366          delete status;
00367    } else 
00368    if(status->InheritsFrom("TGo4AnalysisStatus")) {
00369       SetAnalysisReady(kTRUE); // incoming status object indicates analysis is up
00370       if(fxDisplayAnalysisConfig!=0)
00371          fxDisplayAnalysisConfig->StatusChanged(status);
00372       delete status;
00373    } else {
00374       // check for initialization ready, or kind of connection:
00375       TString message=status->GetName();
00376       if(message.Contains("event classes were initialized"))
00377          {
00378             SetAnaSettingsReady(kTRUE);
00379          }
00380       
00381       else if (message.Contains("is logged in at")) 
00382          {
00383             // for gui as client at analysis server
00384             for(int j=0; j<4;++j)
00385                {
00386                   if(message.Contains(TGo4Command::GetModeDescription((Go4CommandMode_t) j )))
00387                      {
00388                         SetMasterMode(j);   
00389                         break;
00390                      }
00391                }
00392          } 
00393       else if (message.Contains("is shutting down now!")) 
00394          {
00395             StopMonitoring();
00396          }     
00397       else if (message.Contains("connected successfully")) 
00398          {
00399             // gui is server with one analysis client:
00400             SetMasterMode(2); // always controller mode
00401          }      
00402       else {}
00404          
00405       if (fxLogInfo!=0) 
00406         fxLogInfo->StatusChanged(status);
00407       else
00408         // if we do not have an active monitor just delete the log data
00409         // (we are responsible for status object, avoid memory leak!)
00410         delete status; 
00411    }
00412 }
00413 
00414 void TGo4GUIRegistry::RemoveFromSubmittedList(const char *Name)
00415 {
00416    RemoveFromSubmittedList(FindCmdEntry(Name));
00417 }
00418 
00419 void TGo4GUIRegistry::RemoveFromSubmittedList(TGo4SubmittedCommandsEntry *Entry)
00420 {
00421     // TGo4LockGuard globalguard;
00422    if(Entry==0) return;
00423    
00424    SubmittedCommandsList.Remove(Entry);
00425    SubmittedCommandsList.Compress();
00426    delete Entry;
00427 }
00428 
00429 void TGo4GUIRegistry::RemoveFromSubmittedList(const char *Name, TGo4SlotsBaseClass *p)
00430 {
00431    // TGo4LockGuard globalguard;
00432    TGo4SubmittedCommandsEntry* Entry = FindCmdEntry(Name);
00433    if (Entry==0) return;
00434 
00435    Entry->RemoveSlotEntries(p);
00436    
00437    if(Entry->NoOfRecv()==0) 
00438      RemoveFromSubmittedList(Entry);
00439 }
00440 
00441 void TGo4GUIRegistry::RemoveFromSubmittedList(const char *Name, TQRootCanvas *c)
00442 {
00443    // TGo4LockGuard globalguard;
00444    TGo4SubmittedCommandsEntry* Entry = FindCmdEntry(Name);
00445    if (Entry==0) return;
00446 
00447    Entry->RemoveCanvasEntries(c);
00448    
00449    RemoveFromSubmittedList(Entry);
00450 }
00451 
00452 void TGo4GUIRegistry::RemoveRedirectEntry(const char *Name)
00453 {
00454    RemoveFromSubmittedList(Name);
00455 }
00456 
00457 void TGo4GUIRegistry::RemoveRedirectEntry(const char *Name, TGo4SlotsBaseClass *p)
00458 {
00459    RemoveFromSubmittedList(Name,p);
00460 }
00461 
00462 void TGo4GUIRegistry::RemoveRedirectEntry(const char *Name, TQRootCanvas *c)
00463 {
00464    RemoveFromSubmittedList(Name,c);
00465 }
00466 
00467 void TGo4GUIRegistry::SetLogInfo(TGo4SlotsBaseClass * p)
00468 {
00469     // TGo4LockGuard globalguard;
00471    if(p==0) delete fxLogInfo; 
00472    
00474    fxLogInfo = p;
00475 }
00476 
00477 void TGo4GUIRegistry::SetDisplayStatusMonitor(TGo4SlotsBaseClass * p)
00478 {
00479     // TGo4LockGuard globalguard;
00481    if(p==0) delete fxDisplayStatusMonitor;
00482 
00484    fxDisplayStatusMonitor=p;
00485 }
00486 
00487 void TGo4GUIRegistry::StartAnalysisWindow(const char* text)
00488 {
00489    TGo4MainWindow* mw = dynamic_cast<TGo4MainWindow*> (fxMainWindow);
00490    if(mw!=0) {
00491        mw->ShowAnylsisOutput(text);
00492    } else {
00493        cerr <<"GUIRegistry without mainwindow! NEVER COME HERE!!" << endl;
00494        gApplication->Terminate();
00495    }
00496 }
00497 
00498 void TGo4GUIRegistry::SetMasterMode(Int_t role)
00499 {
00500 TGo4MainWindow* mw = dynamic_cast<TGo4MainWindow*> (fxMainWindow);
00501 if(mw) mw->SetMasterMode(role);      
00502 }
00503 
00504 void TGo4GUIRegistry::StopMonitoring()
00505 {
00506 TGo4MainWindow* mw = dynamic_cast<TGo4MainWindow*> (fxMainWindow);
00507 if(mw) mw->StopMonitoring();
00508 TGo4Task* task=fxTGo4Display->GetTask();
00509 TGo4BufferQueue* qu=task->GetCommandQueue();
00510 if(qu) qu->Clear();    
00511 
00512    
00513 }
00514 
00515 
00516 void TGo4GUIRegistry::SetMemoryBrowser(TGo4SlotsBaseClass * browser)
00517 {
00518    // TGo4LockGuard globalguard;
00519    fxMemBrowser = browser;
00520 }
00521 
00522 //----------------------------END OF GO4 SOURCE FILE ---------------------

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