Logo ROOT   6.12/07
Reference Guide
TRemoteObject.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Bertrand Bellenot 19/06/2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TRemoteObject
13 \ingroup Base
14 
15 The TRemoteObject class provides protocol for browsing ROOT objects
16 from a remote ROOT session.
17 
18 It contains information on the real remote object as:
19 
20  - Object Properties (i.e. file stat if the object is a TSystemFile)
21  - Object Name
22  - Class Name
23  - TKey Object Name (if the remote object is a TKey)
24  - TKey Class Name (if the remote object is a TKey)
25  - Remote object address
26 */
27 
28 #include "TApplication.h"
29 #include "TROOT.h"
30 #include "TRemoteObject.h"
31 #include "TSystem.h"
32 #include "TBrowser.h"
33 #include "TOrdCollection.h"
34 #include "TList.h"
35 #include "TClass.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Create a remote object.
41 
43 {
44  fIsFolder = kFALSE;
45  fRemoteAddress = 0;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Create a remote object.
50 
51 TRemoteObject::TRemoteObject(const char *name, const char *title,
52  const char *classname) : TNamed(name, title)
53 {
54  fIsFolder = kFALSE;
55  fClassName = classname;
56  if ((fClassName == "TSystemDirectory") ||
57  (fClassName == "TFile"))
58  fIsFolder = kTRUE;
59  if (!strcmp(classname, "TSystemDirectory") ||
60  !strcmp(classname, "TSystemFile")) {
62  }
63  Long_t raddr = (Long_t) this;
64  fRemoteAddress = raddr;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Delete remote object.
69 
71 {
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Browse remote object.
76 
78 {
79  TList *ret;
80  TRemoteObject *robj;
81  const char *file;
82 
83  if (fClassName == "TSystemFile") {
84  if (b)
85  b->ExecuteDefaultAction(this);
86  return;
87  }
88  if (fClassName == "TKey") {
89  if (b->GetRefreshFlag())
92  TObject *obj = (TObject *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
93  if (obj) {
94  if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
95  gROOT->ProcessLine(Form("((%s *)0x%lx)->SetDirectory(0);", obj->ClassName(), (ULong_t)obj));
96  obj->Browse(b);
98  }
99  }
100  if (fClassName == "TSystemDirectory") {
101  if (b->GetRefreshFlag())
104  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseDirectory(\"%s\");", GetTitle()));
105  if (ret) {
106  TIter next(ret);
107  while ((robj = (TRemoteObject *)next())) {
108  file = robj->GetName();
109  if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
110  continue;
111  b->Add(robj, robj->GetName());
112  }
113  }
114  return;
115  }
116  if (fClassName == "TFile") {
117  if (b->GetRefreshFlag())
120  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseFile(\"%s\");", GetName()));
121  if (ret) {
122  TIter next(ret);
123  while ((robj = (TRemoteObject *)next())) {
124  //file = robj->GetName();
125  b->Add(robj, robj->GetName());
126  }
127  }
128  return;
129  }
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Browse OS system directories.
134 
136 {
137  // Collections to keep track of all browser objects that have been
138  // generated. It's main goal is to prevent the continuous
139  // allocations of new objects with the same names during browsing.
140  TList *objects = new TList;
141 
142  static Int_t level = 0;
143  const char *name = GetTitle();
144  TRemoteObject *sdir;
145 
146  if (GetName()[0] == '.' && GetName()[1] == '.')
147  SetName(gSystem->BaseName(name));
148 
149  TSystemDirectory dir(name, name);
150  TList *files = dir.GetListOfFiles();
151  if (files) {
152  files->Sort();
153  TIter next(files);
154  TSystemFile *file;
155  TString fname;
156  // directories first
157  while ((file=(TSystemFile*)next())) {
158  fname = file->GetName();
159  if (file->IsDirectory()) {
160  level++;
161  TString sdirpath;
162  if (!strcmp(fname.Data(), "."))
163  sdirpath = name;
164  else if (!strcmp(fname.Data(), ".."))
165  sdirpath = gSystem->DirName(name);
166  else {
167  sdirpath = name;
168  if (!sdirpath.EndsWith("/"))
169  sdirpath += "/";
170  sdirpath += fname.Data();
171  }
172  sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
173  objects->Add(sdir);
174  level--;
175  }
176  }
177  // then files...
178  TIter nextf(files);
179  while ((file=(TSystemFile*)nextf())) {
180  fname = file->GetName();
181  if (!file->IsDirectory()) {
182  sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
183  objects->Add(sdir);
184  }
185  }
186  delete files;
187  }
188  return objects;
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Get remote file status.
193 
195 {
196  buf->fDev = fFileStat.fDev;
197  buf->fIno = fFileStat.fIno;
198  buf->fMode = fFileStat.fMode;
199  buf->fUid = fFileStat.fUid;
200  buf->fGid = fFileStat.fGid;
201  buf->fSize = fFileStat.fSize;
202  buf->fMtime = fFileStat.fMtime;
203  buf->fIsLink = fFileStat.fIsLink;
204  return kTRUE;
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Remote object streamer.
209 
210 void TRemoteObject::Streamer(TBuffer &b)
211 {
212  if (b.IsReading()) {
213  b >> fFileStat.fDev;
214  b >> fFileStat.fIno;
215  b >> fFileStat.fMode;
216  b >> fFileStat.fUid;
217  b >> fFileStat.fGid;
218  b >> fFileStat.fSize;
219  b >> fFileStat.fMtime;
220  b >> fFileStat.fIsLink;
221  b >> fIsFolder;
222  b >> fRemoteAddress;
223  b >> fClassName;
224  b >> fKeyObjectName;
225  b >> fKeyClassName;
226  }
227  else {
228  b << fFileStat.fDev;
229  b << fFileStat.fIno;
230  b << fFileStat.fMode;
231  b << fFileStat.fUid;
232  b << fFileStat.fGid;
233  b << fFileStat.fSize;
234  b << fFileStat.fMtime;
235  b << fFileStat.fIsLink;
236  b << fIsFolder;
237  b << fRemoteAddress;
238  b << fClassName;
239  b << fKeyObjectName;
240  b << fKeyClassName;
241  }
242  TNamed::Streamer(b);
243 }
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:261
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:932
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Bool_t IsReading() const
Definition: TBuffer.h:83
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:869
Int_t fUid
Definition: TSystem.h:129
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Definition: TSystem.cxx:1374
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
#define gROOT
Definition: TROOT.h:402
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
Basic string class.
Definition: TString.h:125
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:119
void ExecuteDefaultAction(TObject *obj)
Execute default action for selected object (action is specified in the $HOME/.root.mimes or $ROOTSYS/etc/root.mimes file).
Definition: TBrowser.cxx:357
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1004
bool Bool_t
Definition: RtypesCore.h:59
Long_t fMtime
Definition: TSystem.h:132
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:53
Long64_t fSize
Definition: TSystem.h:131
TString fKeyObjectName
Definition: TRemoteObject.h:43
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
Int_t fMode
Definition: TSystem.h:128
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:933
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:36
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2231
Int_t fGid
Definition: TSystem.h:130
Describes an Operating System directory for the browser.
A doubly linked list.
Definition: TList.h:44
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Bool_t fIsLink
Definition: TSystem.h:133
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
void SetRefreshFlag(Bool_t flag)
Definition: TBrowser.h:97
char * Form(const char *fmt,...)
FileStat_t fFileStat
Definition: TRemoteObject.h:39
Bool_t GetRefreshFlag() const
Definition: TBrowser.h:95
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t fIsFolder
Definition: TRemoteObject.h:40
virtual ~TRemoteObject()
Delete remote object.
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:359
unsigned long ULong_t
Definition: RtypesCore.h:51
TString fKeyClassName
Definition: TRemoteObject.h:44
Long64_t fRemoteAddress
Definition: TRemoteObject.h:41
Mother of all ROOT objects.
Definition: TObject.h:37
TString fClassName
Definition: TRemoteObject.h:42
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
virtual void Add(TObject *obj)
Definition: TList.h:87
Definition: file.py:1
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
Long_t fIno
Definition: TSystem.h:127
TList * Browse()
Browse OS system directories.
Long_t fDev
Definition: TSystem.h:126
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
const Bool_t kTRUE
Definition: RtypesCore.h:87
char name[80]
Definition: TGX11.cxx:109
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
TRemoteObject()
Create a remote object.
const char * Data() const
Definition: TString.h:345