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
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a remote object.
40
46
47////////////////////////////////////////////////////////////////////////////////
48/// Create a remote object.
49
50TRemoteObject::TRemoteObject(const char *name, const char *title,
51 const char *classname) : TNamed(name, title)
52{
54 fClassName = classname;
55 if ((fClassName == "TSystemDirectory") ||
56 (fClassName == "TFile"))
58 if (!strcmp(classname, "TSystemDirectory") ||
59 !strcmp(classname, "TSystemFile")) {
61 }
62 Long64_t raddr = (Long64_t) this;
64}
65
66////////////////////////////////////////////////////////////////////////////////
67/// Delete remote object.
68
72
73////////////////////////////////////////////////////////////////////////////////
74/// Browse remote object.
75
77{
78 TList *ret;
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())
89 b->SetRefreshFlag(kFALSE);
91 TObject *obj = (TObject *)gROOT->ProcessLine(TString::Format("((TApplicationServer *)gApplication)->BrowseKey(\"%s\");", GetName()));
92 if (obj) {
93 if (obj->IsA()->GetMethodWithPrototype("SetDirectory", "TDirectory*"))
94 gROOT->ProcessLine(TString::Format("((%s *)0x%zx)->SetDirectory(0);", obj->ClassName(), (size_t)obj));
95 obj->Browse(b);
96 b->SetRefreshFlag(kTRUE);
97 }
98 }
99 if (fClassName == "TSystemDirectory") {
100 if (b->GetRefreshFlag())
101 b->SetRefreshFlag(kFALSE);
103 ret = (TList *)gROOT->ProcessLine(TString::Format("((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())
117 b->SetRefreshFlag(kFALSE);
119 ret = (TList *)gROOT->ProcessLine(TString::Format("((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 const char *name = GetTitle();
143
144 if (GetName()[0] == '.' && GetName()[1] == '.')
146
148 TList *files = dir.GetListOfFiles();
149 if (files) {
150 files->Sort();
151 TIter next(files);
152 TSystemFile *file;
154 // directories first
155 while ((file=(TSystemFile*)next())) {
156 fname = file->GetName();
157 if (file->IsDirectory()) {
159 if (!strcmp(fname.Data(), "."))
160 sdirpath = name;
161 else if (!strcmp(fname.Data(), ".."))
163 else {
164 sdirpath = name;
165 if (!sdirpath.EndsWith("/"))
166 sdirpath += "/";
167 sdirpath += fname.Data();
168 }
169 sdir = new TRemoteObject(fname.Data(), sdirpath.Data(), "TSystemDirectory");
170 objects->Add(sdir);
171 }
172 }
173 // then files...
175 while ((file=(TSystemFile*)nextf())) {
176 fname = file->GetName();
177 if (!file->IsDirectory()) {
178 sdir = new TRemoteObject(fname.Data(), gSystem->WorkingDirectory(), "TSystemFile");
179 objects->Add(sdir);
180 }
181 }
182 delete files;
183 }
184 return objects;
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// Get remote file status.
189
191{
192 buf->fDev = fFileStat.fDev;
193 buf->fIno = fFileStat.fIno;
194 buf->fMode = fFileStat.fMode;
195 buf->fUid = fFileStat.fUid;
196 buf->fGid = fFileStat.fGid;
197 buf->fSize = fFileStat.fSize;
198 buf->fMtime = fFileStat.fMtime;
200 return kTRUE;
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Remote object streamer.
205
207{
208 if (b.IsReading()) {
209 b >> fFileStat.fDev;
210 b >> fFileStat.fIno;
211 b >> fFileStat.fMode;
212 b >> fFileStat.fUid;
213 b >> fFileStat.fGid;
214 b >> fFileStat.fSize;
215 b >> fFileStat.fMtime;
217 b >> fIsFolder;
218 b >> fRemoteAddress;
219 b >> fClassName;
220 b >> fKeyObjectName;
221 b >> fKeyClassName;
222 }
223 else {
224 b << fFileStat.fDev;
225 b << fFileStat.fIno;
226 b << fFileStat.fMode;
227 b << fFileStat.fUid;
228 b << fFileStat.fGid;
229 b << fFileStat.fSize;
230 b << fFileStat.fMtime;
232 b << fIsFolder;
233 b << fRemoteAddress;
234 b << fClassName;
235 b << fKeyObjectName;
236 b << fKeyClassName;
237 }
239}
#define b(i)
Definition RSha256.hxx:100
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
#define gROOT
Definition TROOT.h:411
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
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
A doubly linked list.
Definition TList.h:38
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:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:50
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:226
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual TClass * IsA() const
Definition TObject.h:246
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:138
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:2384
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:1409
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:944
virtual const char * WorkingDirectory()
Return working directory.
Definition TSystem.cxx:881
virtual TString GetDirName(const char *pathname)
Return the directory name in pathname.
Definition TSystem.cxx:1042
Int_t fMode
Definition TSystem.h:135
Long64_t fSize
Definition TSystem.h:138
Long_t fDev
Definition TSystem.h:133
Int_t fGid
Definition TSystem.h:137
Long_t fMtime
Definition TSystem.h:139
Long_t fIno
Definition TSystem.h:134
Bool_t fIsLink
Definition TSystem.h:140
Int_t fUid
Definition TSystem.h:136