File indexing completed on 2025-01-18 10:12:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TRootSniffer
0013 #define ROOT_TRootSniffer
0014
0015 #include "TNamed.h"
0016 #include "TList.h"
0017 #include <memory>
0018 #include <string>
0019
0020 class TFolder;
0021 class TKey;
0022 class TBufferFile;
0023 class TDataMember;
0024 class THttpCallArg;
0025 class TRootSnifferStore;
0026 class TRootSniffer;
0027
0028 class TRootSnifferScanRec {
0029
0030 friend class TRootSniffer;
0031
0032 protected:
0033
0034 enum {
0035 kScan = 0x0001,
0036 kExpand = 0x0002,
0037 kSearch = 0x0004,
0038 kCheckChilds = 0x0008,
0039 kOnlyFields = 0x0010,
0040 kActions = 0x001F
0041 };
0042
0043 TRootSnifferScanRec *fParent{nullptr};
0044 UInt_t fMask{0};
0045 const char *fSearchPath{nullptr};
0046 Int_t fLevel{0};
0047 TString fItemName;
0048 TList fItemsNames;
0049 Int_t fRestriction{0};
0050
0051 TRootSnifferStore *fStore{nullptr};
0052 Bool_t fHasMore{kFALSE};
0053 Bool_t fNodeStarted{kFALSE};
0054 Int_t fNumFields{0};
0055 Int_t fNumChilds{0};
0056
0057 public:
0058 TRootSnifferScanRec();
0059 virtual ~TRootSnifferScanRec();
0060
0061 void CloseNode();
0062
0063
0064 Bool_t CanSetFields() const { return (fMask & kScan) && (fStore != nullptr); }
0065
0066
0067 Bool_t ScanOnlyFields() const { return (fMask & kOnlyFields) && (fMask & kScan); }
0068
0069
0070 void CreateNode(const char *_node_name);
0071
0072 void BeforeNextChild();
0073
0074
0075 void SetField(const char *name, const char *value, Bool_t with_quotes = kTRUE);
0076
0077
0078 void SetRootClass(TClass *cl);
0079
0080
0081 Bool_t CanExpandItem();
0082
0083
0084 Bool_t IsReadyForResult() const;
0085
0086
0087 Bool_t SetResult(void *obj, TClass *cl, TDataMember *member = nullptr);
0088
0089
0090 Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member = nullptr);
0091
0092
0093 Int_t Depth() const;
0094
0095
0096 Bool_t Done() const;
0097
0098
0099 void MakeItemName(const char *objname, TString &itemname);
0100
0101
0102 void BuildFullName(TString &buf, TRootSnifferScanRec *prnt = nullptr);
0103
0104
0105 Bool_t IsReadOnly(Bool_t dflt = kTRUE);
0106
0107 Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name = nullptr,
0108 TRootSniffer *sniffer = nullptr);
0109
0110 ClassDef(TRootSnifferScanRec, 0)
0111 };
0112
0113
0114
0115 class TRootSniffer : public TNamed {
0116 enum {
0117 kItemField = BIT(21)
0118 };
0119
0120 protected:
0121 TString fObjectsPath;
0122 Bool_t fReadOnly{kTRUE};
0123 Bool_t fScanGlobalDir{kTRUE};
0124 std::unique_ptr<TFolder> fTopFolder;
0125 THttpCallArg *fCurrentArg{nullptr};
0126 Int_t fCurrentRestrict{0};
0127 TString fCurrentAllowedMethods;
0128 TList fRestrictions;
0129 TString fAutoLoad;
0130
0131 void ScanObjectMembers(TRootSnifferScanRec &rec, TClass *cl, char *ptr);
0132
0133 virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj);
0134
0135 virtual void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class);
0136
0137 virtual void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj);
0138
0139 virtual Bool_t CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res);
0140
0141 void
0142 ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername = nullptr, TCollection *keys_lst = nullptr);
0143
0144 virtual void ScanRoot(TRootSnifferScanRec &rec);
0145
0146 TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes = kTRUE);
0147
0148 TObject *GetItem(const char *fullname, TFolder *&parent, Bool_t force = kFALSE, Bool_t within_objects = kTRUE);
0149
0150 TFolder *GetSubFolder(const char *foldername, Bool_t force = kFALSE);
0151
0152 const char *GetItemField(TFolder *parent, TObject *item, const char *name);
0153
0154 Bool_t IsItemField(TObject *obj) const;
0155
0156 Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get = nullptr);
0157
0158 Int_t WithCurrentUserName(const char *option);
0159
0160 virtual Bool_t CanDrawClass(TClass *) { return kFALSE; }
0161
0162 virtual Bool_t HasStreamerInfo() const { return kFALSE; }
0163
0164 virtual Bool_t ProduceJson(const std::string &path, const std::string &options, std::string &res);
0165
0166 virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res);
0167
0168 virtual Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res);
0169
0170 virtual Bool_t ProduceRootFile(const std::string &path, const std::string &options, std::string &res);
0171
0172 virtual Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res);
0173
0174 virtual Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res);
0175
0176 virtual Bool_t ExecuteCmd(const std::string &path, const std::string &options, std::string &res);
0177
0178 virtual Bool_t
0179 ProduceItem(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
0180
0181 virtual Bool_t
0182 ProduceMulti(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
0183
0184 public:
0185 TRootSniffer(const char *name = "sniff", const char *objpath = "Objects");
0186 virtual ~TRootSniffer();
0187
0188
0189
0190 void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; }
0191
0192
0193 Bool_t IsReadOnly() const { return fReadOnly; }
0194
0195 void Restrict(const char *path, const char *options);
0196
0197 Bool_t HasRestriction(const char *item_name);
0198
0199 Int_t CheckRestriction(const char *item_name);
0200
0201 void CreateOwnTopFolder();
0202
0203 TFolder *GetTopFolder(Bool_t force = kFALSE);
0204
0205
0206 void SetScanGlobalDir(Bool_t on = kTRUE) { fScanGlobalDir = on; }
0207
0208 void SetAutoLoad(const char *scripts = "");
0209
0210 const char *GetAutoLoad() const;
0211
0212
0213 Bool_t IsScanGlobalDir() const { return fScanGlobalDir; }
0214
0215 Bool_t RegisterObject(const char *subfolder, TObject *obj);
0216
0217 Bool_t UnregisterObject(TObject *obj);
0218
0219 Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon);
0220
0221 Bool_t CreateItem(const char *fullname, const char *title);
0222
0223 Bool_t SetItemField(const char *fullname, const char *name, const char *value);
0224
0225 const char *GetItemField(const char *fullname, const char *name);
0226
0227 THttpCallArg *SetCurrentCallArg(THttpCallArg *arg);
0228
0229
0230 void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields = kFALSE);
0231
0232 TObject *FindTObjectInHierarchy(const char *path);
0233
0234 virtual void *
0235 FindInHierarchy(const char *path, TClass **cl = nullptr, TDataMember **member = nullptr, Int_t *chld = nullptr);
0236
0237 Bool_t CanDrawItem(const char *path);
0238
0239 Bool_t CanExploreItem(const char *path);
0240
0241 virtual Bool_t IsStreamerInfoItem(const char *) { return kFALSE; }
0242
0243 virtual ULong_t GetStreamerInfoHash() { return 0; }
0244
0245 virtual ULong_t GetItemHash(const char *itemname);
0246
0247 Bool_t Produce(const std::string &path, const std::string &file, const std::string &options, std::string &res);
0248
0249 ClassDefOverride(TRootSniffer, 0)
0250 };
0251
0252 #endif