Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TRemoteObject.h"
29#include "TSystemDirectory.h"
30#include "TApplication.h"
31#include "TROOT.h"
32#include "TBuffer.h"
33#include "TBrowser.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 Long64_t raddr = (Long64_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(TString::Format("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
93 if (obj) {
94 if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
95 gROOT->ProcessLine(TString::Format("((%s *)0x%zx)->SetDirectory(0);", obj->ClassName(), (size_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(TString::Format("((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(TString::Format("((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 const char *name = GetTitle();
143 TRemoteObject *sdir;
144
145 if (GetName()[0] == '.' && GetName()[1] == '.')
147
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 TString sdirpath;
160 if (!strcmp(fname.Data(), "."))
161 sdirpath = name;
162 else if (!strcmp(fname.Data(), ".."))
163 sdirpath = gSystem->GetDirName(name);
164 else {
165 sdirpath = name;
166 if (!sdirpath.EndsWith("/"))
167 sdirpath += "/";
168 sdirpath += fname.Data();
169 }
170 sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
171 objects->Add(sdir);
172 }
173 }
174 // then files...
175 TIter nextf(files);
176 while ((file=(TSystemFile*)nextf())) {
177 fname = file->GetName();
178 if (!file->IsDirectory()) {
179 sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
180 objects->Add(sdir);
181 }
182 }
183 delete files;
184 }
185 return objects;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Get remote file status.
190
192{
193 buf->fDev = fFileStat.fDev;
194 buf->fIno = fFileStat.fIno;
195 buf->fMode = fFileStat.fMode;
196 buf->fUid = fFileStat.fUid;
197 buf->fGid = fFileStat.fGid;
198 buf->fSize = fFileStat.fSize;
199 buf->fMtime = fFileStat.fMtime;
201 return kTRUE;
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Remote object streamer.
206
208{
209 if (b.IsReading()) {
210 b >> fFileStat.fDev;
211 b >> fFileStat.fIno;
212 b >> fFileStat.fMode;
213 b >> fFileStat.fUid;
214 b >> fFileStat.fGid;
215 b >> fFileStat.fSize;
216 b >> fFileStat.fMtime;
218 b >> fIsFolder;
219 b >> fRemoteAddress;
220 b >> fClassName;
221 b >> fKeyObjectName;
222 b >> fKeyClassName;
223 }
224 else {
225 b << fFileStat.fDev;
226 b << fFileStat.fIno;
227 b << fFileStat.fMode;
228 b << fFileStat.fUid;
229 b << fFileStat.fGid;
230 b << fFileStat.fSize;
231 b << fFileStat.fMtime;
233 b << fIsFolder;
234 b << fRemoteAddress;
235 b << fClassName;
236 b << fKeyObjectName;
237 b << fKeyClassName;
238 }
240}
#define b(i)
Definition RSha256.hxx:100
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TApplication * gApplication
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
@ kNoHidden
Definition TBrowser.h:55
Buffer base class used for serializing objects.
Definition TBuffer.h:43
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4456
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Definition TList.cxx:935
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition TObject.cxx:198
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual TClass * IsA() const
Definition TObject.h:245
The TRemoteObject class provides protocol for browsing ROOT objects from a remote ROOT session.
TString fClassName
virtual ~TRemoteObject()
Delete remote object.
TList * Browse()
Browse OS system directories.
TString fKeyObjectName
Bool_t GetFileStat(FileStat_t *sbuf)
Get remote file status.
TRemoteObject()
Create a remote object.
TString fKeyClassName
Long64_t fRemoteAddress
void Streamer(TBuffer &) override
Remote object streamer.
FileStat_t fFileStat
Basic string class.
Definition TString.h:139
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
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 Bool_t IsDirectory(const char *dir=nullptr) const
Check if object is a directory.
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:1398
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:934
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:871
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1032
Int_t fMode
Definition TSystem.h:125
Long64_t fSize
Definition TSystem.h:128
Long_t fDev
Definition TSystem.h:123
Int_t fGid
Definition TSystem.h:127
Long_t fMtime
Definition TSystem.h:129
Long_t fIno
Definition TSystem.h:124
Bool_t fIsLink
Definition TSystem.h:130
Int_t fUid
Definition TSystem.h:126