TRemoteObject.cxx

Go to the documentation of this file.
00001 // @(#)root/base:$Id: TRemoteObject.cxx 35590 2010-09-22 14:15:45Z rdm $
00002 // Author: Bertrand Bellenot   19/06/2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TRemoteObject                                                        //
00015 //                                                                      //
00016 // The TRemoteObject class provides protocol for browsing ROOT objects  //
00017 // from a remote ROOT session.                                          //
00018 // It contains informations on the real remote object as:               //
00019 //  - Object Properties (i.e. file stat if the object is a TSystemFile) //
00020 //  - Object Name                                                       //
00021 //  - Class Name                                                        //
00022 //  - TKey Object Name (if the remote object is a TKey)                 //
00023 //  - TKey Class Name (if the remote object is a TKey)                  //
00024 //  - Remote object address                                             //
00025 //                                                                      //
00026 //////////////////////////////////////////////////////////////////////////
00027 
00028 #include "TApplication.h"
00029 #include "TROOT.h"
00030 #include "TRemoteObject.h"
00031 #include "TSystem.h"
00032 #include "TBrowser.h"
00033 #include "TOrdCollection.h"
00034 #include "TList.h"
00035 #include "TClass.h"
00036 
00037 ClassImp(TRemoteObject);
00038 
00039 //______________________________________________________________________________
00040 TRemoteObject::TRemoteObject()
00041 {
00042    // Create a remote object.
00043 
00044    fIsFolder = kFALSE;
00045    fRemoteAddress = 0;
00046 }
00047 
00048 //______________________________________________________________________________
00049 TRemoteObject::TRemoteObject(const char *name, const char *title,
00050                              const char *classname) : TNamed(name, title)
00051 {
00052    // Create a remote object.
00053 
00054    fIsFolder = kFALSE;
00055    fClassName = classname;
00056    if ((fClassName == "TSystemDirectory") ||
00057        (fClassName == "TFile"))
00058       fIsFolder = kTRUE;
00059    if (!strcmp(classname, "TSystemDirectory") ||
00060        !strcmp(classname, "TSystemFile")) {
00061       gSystem->GetPathInfo(name, fFileStat);
00062    }
00063    Long_t raddr = (Long_t) this;
00064    fRemoteAddress = raddr;
00065 }
00066 
00067 //______________________________________________________________________________
00068 TRemoteObject::~TRemoteObject()
00069 {
00070    // Delete remote object.
00071 
00072 }
00073 
00074 //______________________________________________________________________________
00075 void TRemoteObject::Browse(TBrowser *b)
00076 {
00077    // Browse remote object.
00078 
00079    TList *ret;
00080    TRemoteObject *robj;
00081    const char *file;
00082 
00083    if (fClassName == "TSystemFile") {
00084       if (b)
00085          b->ExecuteDefaultAction(this);
00086       return;
00087    }
00088    if (fClassName == "TKey") {
00089       if (b->GetRefreshFlag())
00090          b->SetRefreshFlag(kFALSE);
00091       gApplication->SetBit(TApplication::kProcessRemotely);
00092       TObject *obj = (TObject *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
00093       if (obj) {
00094          if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
00095             gROOT->ProcessLine(Form("((%s *)0x%lx)->SetDirectory(0);", obj->ClassName(), (ULong_t)obj));
00096          obj->Browse(b);
00097          b->SetRefreshFlag(kTRUE);
00098       }
00099    }
00100    if (fClassName == "TSystemDirectory") {
00101       if (b->GetRefreshFlag())
00102          b->SetRefreshFlag(kFALSE);
00103       gApplication->SetBit(TApplication::kProcessRemotely);
00104       ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseDirectory(\"%s\");", GetTitle()));
00105       if (ret) {
00106          TIter next(ret);
00107          while ((robj = (TRemoteObject *)next())) {
00108             file = robj->GetName();
00109             if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
00110                continue;
00111             b->Add(robj, robj->GetName());
00112          }
00113       }
00114       return;
00115    }
00116    if (fClassName == "TFile") {
00117       if (b->GetRefreshFlag())
00118          b->SetRefreshFlag(kFALSE);
00119       gApplication->SetBit(TApplication::kProcessRemotely);
00120       ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseFile(\"%s\");", GetName()));
00121       if (ret) {
00122          TIter next(ret);
00123          while ((robj = (TRemoteObject *)next())) {
00124             //file = robj->GetName();
00125             b->Add(robj, robj->GetName());
00126          }
00127       }
00128       return;
00129    }
00130 }
00131 
00132 //______________________________________________________________________________
00133 TList *TRemoteObject::Browse()
00134 {
00135    // Browse OS system directories.
00136 
00137    // Collections to keep track of all browser objects that have been
00138    // generated. It's main goal is to prevent the contineous
00139    // allocations of new objects with the same names during browsing.
00140    TList *objects  = new TList;
00141 
00142    static Int_t level = 0;
00143    const char *name = GetTitle();
00144    TRemoteObject *sdir;
00145 
00146    if (GetName()[0] == '.' && GetName()[1] == '.')
00147       SetName(gSystem->BaseName(name));
00148 
00149    TSystemDirectory dir(name, name);
00150    TList *files = dir.GetListOfFiles();
00151    if (files) {
00152       files->Sort();
00153       TIter next(files);
00154       TSystemFile *file;
00155       TString fname;
00156       // directories first
00157       while ((file=(TSystemFile*)next())) {
00158          fname = file->GetName();
00159          if (file->IsDirectory()) {
00160             level++;
00161             TString sdirpath;
00162             if (!strcmp(fname.Data(), "."))
00163                sdirpath = name;
00164             else if (!strcmp(fname.Data(), ".."))
00165                sdirpath = gSystem->DirName(name);
00166             else {
00167                sdirpath =  name;
00168                if (!sdirpath.EndsWith("/"))
00169                   sdirpath += "/";
00170                sdirpath += fname.Data();
00171             }
00172             sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
00173             objects->Add(sdir);
00174             level--;
00175          }
00176       }
00177       // then files...
00178       TIter nextf(files);
00179       while ((file=(TSystemFile*)nextf())) {
00180          fname = file->GetName();
00181          if (!file->IsDirectory()) {
00182             sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
00183             objects->Add(sdir);
00184          }
00185       }
00186       delete files;
00187    }
00188    return objects;
00189 }
00190 
00191 //______________________________________________________________________________
00192 Bool_t TRemoteObject::GetFileStat(FileStat_t *buf)
00193 {
00194    // Get remote file status.
00195 
00196    buf->fDev    = fFileStat.fDev;
00197    buf->fIno    = fFileStat.fIno;
00198    buf->fMode   = fFileStat.fMode;
00199    buf->fUid    = fFileStat.fUid;
00200    buf->fGid    = fFileStat.fGid;
00201    buf->fSize   = fFileStat.fSize;
00202    buf->fMtime  = fFileStat.fMtime;
00203    buf->fIsLink = fFileStat.fIsLink;
00204    return kTRUE;
00205 }
00206 
00207 //______________________________________________________________________________
00208 void TRemoteObject::Streamer(TBuffer &b)
00209 {
00210    // Remote object streamer.
00211 
00212    if (b.IsReading()) {
00213       b >> fFileStat.fDev;
00214       b >> fFileStat.fIno;
00215       b >> fFileStat.fMode;
00216       b >> fFileStat.fUid;
00217       b >> fFileStat.fGid;
00218       b >> fFileStat.fSize;
00219       b >> fFileStat.fMtime;
00220       b >> fFileStat.fIsLink;
00221       b >> fIsFolder;
00222       b >> fRemoteAddress;
00223       b >> fClassName;
00224       b >> fKeyObjectName;
00225       b >> fKeyClassName;
00226    }
00227    else {
00228       b << fFileStat.fDev;
00229       b << fFileStat.fIno;
00230       b << fFileStat.fMode;
00231       b << fFileStat.fUid;
00232       b << fFileStat.fGid;
00233       b << fFileStat.fSize;
00234       b << fFileStat.fMtime;
00235       b << fFileStat.fIsLink;
00236       b << fIsFolder;
00237       b << fRemoteAddress;
00238       b << fClassName;
00239       b << fKeyObjectName;
00240       b << fKeyClassName;
00241    }
00242    TNamed::Streamer(b);
00243 }

Generated on Tue Jul 5 14:11:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1