ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
14 The TRemoteObject class provides protocol for browsing ROOT objects
15 from a remote ROOT session.
16 
17 It contains information on the real remote object as:
18 
19  - Object Properties (i.e. file stat if the object is a TSystemFile)
20  - Object Name
21  - Class Name
22  - TKey Object Name (if the remote object is a TKey)
23  - TKey Class Name (if the remote object is a TKey)
24  - Remote object address
25 */
26 
27 #include "TApplication.h"
28 #include "TROOT.h"
29 #include "TRemoteObject.h"
30 #include "TSystem.h"
31 #include "TBrowser.h"
32 #include "TOrdCollection.h"
33 #include "TList.h"
34 #include "TClass.h"
35 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a remote object.
40 
42 {
43  fIsFolder = kFALSE;
44  fRemoteAddress = 0;
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Create a remote object.
49 
50 TRemoteObject::TRemoteObject(const char *name, const char *title,
51  const char *classname) : TNamed(name, title)
52 {
53  fIsFolder = kFALSE;
54  fClassName = classname;
55  if ((fClassName == "TSystemDirectory") ||
56  (fClassName == "TFile"))
57  fIsFolder = kTRUE;
58  if (!strcmp(classname, "TSystemDirectory") ||
59  !strcmp(classname, "TSystemFile")) {
61  }
62  Long_t raddr = (Long_t) this;
63  fRemoteAddress = raddr;
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Delete remote object.
68 
70 {
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Browse remote object.
75 
77 {
78  TList *ret;
79  TRemoteObject *robj;
80  const char *file;
81 
82  if (fClassName == "TSystemFile") {
83  if (b)
84  b->ExecuteDefaultAction(this);
85  return;
86  }
87  if (fClassName == "TKey") {
88  if (b->GetRefreshFlag())
91  TObject *obj = (TObject *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
92  if (obj) {
93  if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
94  gROOT->ProcessLine(Form("((%s *)0x%lx)->SetDirectory(0);", obj->ClassName(), (ULong_t)obj));
95  obj->Browse(b);
97  }
98  }
99  if (fClassName == "TSystemDirectory") {
100  if (b->GetRefreshFlag())
103  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseDirectory(\"%s\");", GetTitle()));
104  if (ret) {
105  TIter next(ret);
106  while ((robj = (TRemoteObject *)next())) {
107  file = robj->GetName();
108  if (b->TestBit(TBrowser::kNoHidden) && file[0] == '.' && file[1] != '.' )
109  continue;
110  b->Add(robj, robj->GetName());
111  }
112  }
113  return;
114  }
115  if (fClassName == "TFile") {
116  if (b->GetRefreshFlag())
119  ret = (TList *)gROOT->ProcessLine(Form("((TApplicationServer *)gApplication)->BrowseFile(\"%s\");", GetName()));
120  if (ret) {
121  TIter next(ret);
122  while ((robj = (TRemoteObject *)next())) {
123  //file = robj->GetName();
124  b->Add(robj, robj->GetName());
125  }
126  }
127  return;
128  }
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Browse OS system directories.
133 
135 {
136  // Collections to keep track of all browser objects that have been
137  // generated. It's main goal is to prevent the continuous
138  // allocations of new objects with the same names during browsing.
139  TList *objects = new TList;
140 
141  static Int_t level = 0;
142  const char *name = GetTitle();
143  TRemoteObject *sdir;
144 
145  if (GetName()[0] == '.' && GetName()[1] == '.')
146  SetName(gSystem->BaseName(name));
147 
148  TSystemDirectory dir(name, name);
149  TList *files = dir.GetListOfFiles();
150  if (files) {
151  files->Sort();
152  TIter next(files);
153  TSystemFile *file;
154  TString fname;
155  // directories first
156  while ((file=(TSystemFile*)next())) {
157  fname = file->GetName();
158  if (file->IsDirectory()) {
159  level++;
160  TString sdirpath;
161  if (!strcmp(fname.Data(), "."))
162  sdirpath = name;
163  else if (!strcmp(fname.Data(), ".."))
164  sdirpath = gSystem->DirName(name);
165  else {
166  sdirpath = name;
167  if (!sdirpath.EndsWith("/"))
168  sdirpath += "/";
169  sdirpath += fname.Data();
170  }
171  sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
172  objects->Add(sdir);
173  level--;
174  }
175  }
176  // then files...
177  TIter nextf(files);
178  while ((file=(TSystemFile*)nextf())) {
179  fname = file->GetName();
180  if (!file->IsDirectory()) {
181  sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
182  objects->Add(sdir);
183  }
184  }
185  delete files;
186  }
187  return objects;
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Get remote file status.
192 
194 {
195  buf->fDev = fFileStat.fDev;
196  buf->fIno = fFileStat.fIno;
197  buf->fMode = fFileStat.fMode;
198  buf->fUid = fFileStat.fUid;
199  buf->fGid = fFileStat.fGid;
200  buf->fSize = fFileStat.fSize;
201  buf->fMtime = fFileStat.fMtime;
202  buf->fIsLink = fFileStat.fIsLink;
203  return kTRUE;
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Remote object streamer.
208 
209 void TRemoteObject::Streamer(TBuffer &b)
210 {
211  if (b.IsReading()) {
212  b >> fFileStat.fDev;
213  b >> fFileStat.fIno;
214  b >> fFileStat.fMode;
215  b >> fFileStat.fUid;
216  b >> fFileStat.fGid;
217  b >> fFileStat.fSize;
218  b >> fFileStat.fMtime;
219  b >> fFileStat.fIsLink;
220  b >> fIsFolder;
221  b >> fRemoteAddress;
222  b >> fClassName;
223  b >> fKeyObjectName;
224  b >> fKeyClassName;
225  }
226  else {
227  b << fFileStat.fDev;
228  b << fFileStat.fIno;
229  b << fFileStat.fMode;
230  b << fFileStat.fUid;
231  b << fFileStat.fGid;
232  b << fFileStat.fSize;
233  b << fFileStat.fMtime;
234  b << fFileStat.fIsLink;
235  b << fIsFolder;
236  b << fRemoteAddress;
237  b << fClassName;
238  b << fKeyObjectName;
239  b << fKeyClassName;
240  }
241  TNamed::Streamer(b);
242 }
void Add(TObject *obj, const char *name=0, Int_t check=-1)
Add object with name to browser.
Definition: TBrowser.cxx:259
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:912
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
Bool_t IsReading() const
Definition: TBuffer.h:83
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Int_t fUid
Definition: TSystem.h:139
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:1311
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
Bool_t GetRefreshFlag() const
Definition: TBrowser.h:99
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:178
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:355
int Int_t
Definition: RtypesCore.h:41
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:980
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Long_t fMtime
Definition: TSystem.h:142
R__EXTERN TApplication * gApplication
Definition: TApplication.h:171
Long64_t fSize
Definition: TSystem.h:141
TString fKeyObjectName
Definition: TRemoteObject.h:49
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
Int_t fMode
Definition: TSystem.h:138
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:771
const char * Data() const
Definition: TString.h:349
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session...
Definition: TRemoteObject.h:42
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Int_t fGid
Definition: TSystem.h:140
Describes an Operating System directory for the browser.
A doubly linked list.
Definition: TList.h:47
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2207
Bool_t fIsLink
Definition: TSystem.h:143
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
void SetRefreshFlag(Bool_t flag)
Definition: TBrowser.h:101
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
char * Form(const char *fmt,...)
FileStat_t fFileStat
Definition: TRemoteObject.h:45
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
ClassImp(TRemoteObject)
Bool_t fIsFolder
Definition: TRemoteObject.h:46
virtual ~TRemoteObject()
Delete remote object.
long Long_t
Definition: RtypesCore.h:50
virtual Bool_t IsDirectory(const char *dir=0) const
Check if object is a directory.
Definition: TSystemFile.cxx:51
tuple file
Definition: fildir.py:20
void dir(char *path=0)
Definition: rootalias.C:30
unsigned long ULong_t
Definition: RtypesCore.h:51
TString fKeyClassName
Definition: TRemoteObject.h:50
Long64_t fRemoteAddress
Definition: TRemoteObject.h:47
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
TString fClassName
Definition: TRemoteObject.h:48
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:31
virtual void Add(TObject *obj)
Definition: TList.h:81
Long_t fIno
Definition: TSystem.h:137
TList * Browse()
Browse OS system directories.
Long_t fDev
Definition: TSystem.h:136
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TRemoteObject()
Create a remote object.