Logo ROOT  
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
15The TRemoteObject class provides protocol for browsing ROOT objects
16from a remote ROOT session.
17
18It 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{
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Create a remote object.
50
51TRemoteObject::TRemoteObject(const char *name, const char *title,
52 const char *classname) : TNamed(name, title)
53{
55 fClassName = classname;
56 if ((fClassName == "TSystemDirectory") ||
57 (fClassName == "TFile"))
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())
90 b->SetRefreshFlag(kFALSE);
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);
97 b->SetRefreshFlag(kTRUE);
98 }
99 }
100 if (fClassName == "TSystemDirectory") {
101 if (b->GetRefreshFlag())
102 b->SetRefreshFlag(kFALSE);
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())
118 b->SetRefreshFlag(kFALSE);
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] == '.')
148
150 TList *files = dir.GetListOfFiles();
151 if (files) {
152 files->Sort();
153 TIter next(files);
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;
204 return kTRUE;
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Remote object streamer.
209
210void 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;
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;
236 b << fIsFolder;
237 b << fRemoteAddress;
238 b << fClassName;
239 b << fKeyObjectName;
240 b << fKeyClassName;
241 }
242 TNamed::Streamer(b);
243}
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
unsigned long ULong_t
Definition: RtypesCore.h:51
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
char name[80]
Definition: TGX11.cxx:109
#define gROOT
Definition: TROOT.h:415
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
@ kNoHidden
Definition: TBrowser.h:53
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
A doubly linked list.
Definition: TList.h:44
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition: TList.cxx:934
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session.
Definition: TRemoteObject.h:36
TString fClassName
Definition: TRemoteObject.h:42
virtual ~TRemoteObject()
Delete remote object.
TList * Browse()
Browse OS system directories.
TString fKeyObjectName
Definition: TRemoteObject.h:43
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
TRemoteObject()
Create a remote object.
Bool_t fIsFolder
Definition: TRemoteObject.h:40
TString fKeyClassName
Definition: TRemoteObject.h:44
Long64_t fRemoteAddress
Definition: TRemoteObject.h:41
FileStat_t fFileStat
Definition: TRemoteObject.h:39
Basic string class.
Definition: TString.h:131
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition: TString.cxx:2177
const char * Data() const
Definition: TString.h:364
Describes an Operating System directory for the browser.
virtual TList * GetListOfFiles() const
Returns a TList of TSystemFile objects representing the contents of the directory.
A TSystemFile describes an operating system file.
Definition: TSystemFile.h:29
virtual const char * DirName(const char *pathname)
Return the directory name in pathname.
Definition: TSystem.cxx:1014
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:1389
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:942
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:879
Definition: file.py:1
Int_t fMode
Definition: TSystem.h:128
Long64_t fSize
Definition: TSystem.h:131
Long_t fDev
Definition: TSystem.h:126
Int_t fGid
Definition: TSystem.h:130
Long_t fMtime
Definition: TSystem.h:132
Long_t fIno
Definition: TSystem.h:127
Bool_t fIsLink
Definition: TSystem.h:133
Int_t fUid
Definition: TSystem.h:129