Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPluginManager.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Fons Rademakers 26/1/2002
3
4/*************************************************************************
5 * Copyright (C) 1995-2002, 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 TPluginManager
13\ingroup Base
14
15This class implements a plugin library manager.
16
17It keeps track of a list of plugin handlers. A plugin handler knows which plugin
18library to load to get a specific class that is used to extend the
19functionality of a specific base class and how to create an object
20of this class. For example, to extend the base class TFile to be
21able to read SQLite files one needs to load the plugin library
22libRSQLite.so which defines the TRSQLiteServer class. This loading
23should be triggered when a given URI contains a regular expression
24defined by the handler.
25
26Plugin handlers can be defined via macros in a list of plugin
27directories. With $ROOTSYS/etc/plugins the default top plugin
28directory specified in $ROOTSYS/etc/system.rootrc. Additional
29directories can be specified by adding them to the end of the list.
30Macros for identical plugin handlers in later directories will
31override previous ones (the inverse of normal search path behavior).
32The macros must have names like `<BaseClass>/PX0_<PluginClass>.C`,
33e.g. TSQLServer/P20_TMySQLServer.C, to allow easy sorting and grouping.
34If the BaseClass is in a namespace the directory must have the name
35NameSpace@@BaseClass as `:` is a reserved pathname character on some
36operating systems. Macros not beginning with 'P' and ending with ".C"
37are ignored. These macros typically look like:
38~~~ {.cpp}
39 void P10_TDCacheFile()
40 {
41 gPluginMgr->AddHandler("TFile", "^dcache", "TDCacheFile",
42 "DCache", "TDCacheFile(const char*,Option_t*)");
43 }
44~~~
45Plugin handlers can also be defined via resources in the .rootrc
46file. Although now deprecated this method still works for backward
47compatibility, e.g.:
48~~~ {.cpp}
49 Plugin.TSQLServer: ^mysql: TMySQLServer MySQL "<constructor>"
50 Plugin.TVirtualFitter: * TFitter Minuit "TFitter(Int_t)"
51~~~
52Add a `+` in front of Plugin.TSQLServer to extend a previously
53existing definition of TSQLServer, useful when there is more than
54one plugin that can extend the same base class. The "<constructor>"
55should be the constructor or a static method that generates an
56instance of the specified class. Global methods should start with
57"::" in their name, like "::CreateFitter()".
58Instead of being a shared library a plugin can also be a CINT
59script, so instead of libDialog.so one can have Dialog.C.
60The * is a placeholder in case there is no need for a URI to
61differentiate between different plugins for the same base class.
62For the default plugins see $ROOTSYS/etc/system.rootrc.
63
64Plugin handlers can also be registered at run time, e.g.:
65~~~ {.cpp}
66 gPluginMgr->AddHandler("TSQLServer", "^sqlite:",
67 "TSQLiteServer", "RSQLite",
68 "TSQLiteServer(const char*,const char*,const char*)");
69~~~
70A list of currently defined handlers can be printed using:
71~~~ {.cpp}
72 gPluginMgr->Print(); // use option="a" to see ctors
73~~~
74The use of the plugin library manager removes all textual references
75to hard-coded class and library names and the resulting dependencies
76in the base classes. The plugin manager is used to extend a.o.
77TFile, TSQLServer, TGrid, etc. functionality.
78*/
79
80#include "TPluginManager.h"
81#include "TEnv.h"
82#include "TRegexp.h"
83#include "TROOT.h"
84#include "TSortedList.h"
85#include "THashList.h"
86#include "THashTable.h"
87#include "TClass.h"
88#include "TClassEdit.h"
89#include "TInterpreter.h"
90#include "TMethod.h"
91#include "TMethodArg.h"
92#include "TDataType.h"
93#include "TMethodCall.h"
94#include "TVirtualMutex.h"
95#include "TSystem.h"
96#include "TObjString.h"
97#include "TObjArray.h"
98#include "ThreadLocalStorage.h"
99
100#include <memory>
101#include <sstream>
102
103TPluginManager *gPluginMgr; // main plugin manager created in TROOT
104
105static bool &TPH__IsReadingDirs() {
106 TTHREAD_TLS(bool) readingDirs (false);
107 return readingDirs;
108}
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Create a plugin handler. Called by TPluginManager.
113
114TPluginHandler::TPluginHandler(const char *base, const char *regexp, const char *className, const char *pluginName,
115 const char *ctor, const char *origin)
116 : fBase(base),
117 fRegexp(regexp),
118 fClass(className),
119 fPlugin(pluginName),
120 fCtor(ctor),
121 fOrigin(origin),
122 fCallEnv(nullptr),
123 fMethod(nullptr),
124 fCanCall(0),
125 fIsMacro(kFALSE),
126 fIsGlobal(kFALSE),
127 fLoadStatus(-1)
128{
129 TString aclicMode, arguments, io;
132 if (fname.EndsWith(".C") || fname.EndsWith(".cxx") || fname.EndsWith(".cpp") ||
133 fname.EndsWith(".cc"))
135
136 if (validMacro && gROOT->LoadMacro(fPlugin, nullptr, kTRUE) == 0)
137 fIsMacro = kTRUE;
138
139 if (fCtor.BeginsWith("::")) {
142 }
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// Cleanup plugin handler object.
147
152
153////////////////////////////////////////////////////////////////////////////////
154/// Check if regular expression appears in the URI, if so return kTRUE.
155/// If URI = 0 always return kTRUE.
156
157Bool_t TPluginHandler::CanHandle(const char *base, const char *uri)
158{
159 if (fBase != base)
160 return kFALSE;
161
162 if (!uri || fRegexp == "*")
163 return kTRUE;
164
166 if (!fRegexp.MaybeRegexp())
167 wildcard = kTRUE;
168
170 TString ruri = uri;
171
172 if (ruri.Index(re) != kNPOS)
173 return kTRUE;
174 return kFALSE;
175}
176
177////////////////////////////////////////////////////////////////////////////////
178/// Return true if the name of the iarg-th argument's type match `type_name`
179Bool_t TPluginHandler::CheckNameMatch(int iarg, const std::type_info& ti)
180{
181 int err = 0;
183 if (err) {
184 return false;
185 }
186 std::string norm_name;
189 const TMethodArg *arg = static_cast<const TMethodArg *>(fMethod->GetListOfMethodArgs()->At(iarg));
190 return norm_name == arg->GetTypeNormalizedName();
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Setup ctor or static method call environment.
195
197{
198 int setCanCall = -1;
199
200 // Use a exit_scope guard, to insure that fCanCall is set (to the value of
201 // result) as the last action of this function before returning.
202
203 // When the standard supports it, we should use std::exit_code
204 // See N4189 for example.
205 // auto guard = make_exit_scope( [...]() { ... } );
206 using exit_scope = std::shared_ptr<void*>;
207 exit_scope guard(nullptr,
208 [this,&setCanCall](void *) { this->fCanCall = setCanCall; } );
209
210 // check if class exists
212 if (!cl && !fIsGlobal) {
213 Error("SetupCallEnv", "class %s not found in plugin %s", fClass.Data(),
214 fPlugin.Data());
215 return;
216 }
217
218 // split method and prototype strings
219 TString method = fCtor(0, fCtor.Index("("));
220 TString proto = fCtor(fCtor.Index("(")+1, fCtor.Index(")")-fCtor.Index("(")-1);
221
222 if (fIsGlobal) {
223 cl = nullptr;
224 fMethod = gROOT->GetGlobalFunctionWithPrototype(method, proto, kFALSE);
225 } else {
226 fMethod = cl->GetMethodWithPrototype(method, proto);
227 }
228
229 if (!fMethod) {
230 if (fIsGlobal)
231 Error("SetupCallEnv", "global function %s not found", method.Data());
232 else
233 Error("SetupCallEnv", "method %s not found in class %s", method.Data(),
234 fClass.Data());
235 return;
236 }
237
238 if (!fIsGlobal && !(fMethod->Property() & kIsPublic)) {
239 Error("SetupCallEnv", "method %s is not public", method.Data());
240 return;
241 }
242
243 fCallEnv = new TMethodCall;
245
246 // cache argument types for fast comparison
247 fArgTupleTypeInfo.clear();
249
250 setCanCall = 1;
251
252 return;
253}
254
255
256////////////////////////////////////////////////////////////////////////////////
257/// Check if the plugin library for this handler exits. Returns 0
258/// when it exists and -1 in case the plugin does not exist.
259
261{
262 if (fIsMacro) {
263 if (TClass::GetClass(fClass)) return 0;
264 return gROOT->LoadMacro(fPlugin, nullptr, kTRUE);
265 } else
266 return gROOT->LoadClass(fClass, fPlugin, kTRUE);
267}
268
269////////////////////////////////////////////////////////////////////////////////
270/// Load the plugin library for this handler. Sets status to 0 on successful loading
271/// and -1 in case the library does not exist or in case of error.
273{
274 if (fIsMacro) {
276 fLoadStatus = 0;
277 else
278 fLoadStatus = gROOT->LoadMacro(fPlugin);
279 } else {
280 // first call also loads dependent libraries declared via the rootmap file
281 if (TClass::LoadClass(fClass, /* silent = */ kFALSE))
282 fLoadStatus = 0;
283 else
284 fLoadStatus = gROOT->LoadClass(fClass, fPlugin);
285 }
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Load the plugin library for this handler. Returns 0 on successful loading
290/// and -1 in case the library does not exist or in case of error.
292{
293 // call once and cache the result to reduce lock contention
294 std::call_once(fLoadStatusFlag, &TPluginHandler::LoadPluginImpl, this);
295 return fLoadStatus;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Check that we can properly run ExecPlugin.
300
302{
303 if (fCtor.IsNull()) {
304 Error("ExecPlugin", "no ctor specified for this handler %s", fClass.Data());
305 return kFALSE;
306 }
307
308 if (fCanCall == 0) {
309 // Not initialized yet.
310 // SetupCallEnv is likely to require/take the interpreter lock.
311 // Grab it now to avoid dead-lock. In particular TPluginHandler::ExecPluginImpl
312 // takes the gInterpreterMutex and *then* call (indirectly) code that
313 // take the lock in fHandlers.
315
316 // Now check if another thread did not already do the work.
317 if (fCanCall == 0)
318 SetupCallEnv();
319 }
320
321 if (fCanCall == -1)
322 return kFALSE;
323
324 if (nargs < fMethod->GetNargs() - fMethod->GetNargsOpt() ||
325 nargs > fMethod->GetNargs()) {
326 Error("ExecPlugin", "nargs (%d) not consistent with expected number of arguments ([%d-%d])",
328 fMethod->GetNargs());
329 return kFALSE;
330 }
331
332 return kTRUE;
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Print info about the plugin handler. If option is "a" print
337/// also the ctor's that will be used.
338
340{
341 const char *exist = "";
342 if (CheckPlugin() == -1)
343 exist = " [*]";
344
345 Printf("%-20s %-13s %-18s %s%s", fBase.Data(), fRegexp.Data(),
347 if (strchr(opt, 'a')) {
348 if (!exist[0]) {
349 TString lib = fPlugin;
350 if (!lib.BeginsWith("lib"))
351 lib = "lib" + lib;
352 char *path = gSystem->DynamicPathName(lib, kTRUE);
353 if (path) Printf(" [Lib: %s]", path);
354 delete [] path;
355 }
356 Printf(" [Ctor: %s]", fCtor.Data());
357 Printf(" [origin: %s]", fOrigin.Data());
358 }
359}
360
361
362
363////////////////////////////////////////////////////////////////////////////////
364/// Constructor
365TPluginManager::TPluginManager() : fHandlers(new TList()), fBasesLoaded(nullptr), fReadingDirs(kFALSE)
366{
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Clean up the plugin manager.
373
375{
376 delete fHandlers;
377 delete fBasesLoaded;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Load plugin handlers specified in config file, like:
382/// ~~~ {.cpp}
383/// Plugin.TSQLServer: ^mysql: TMySQLServer MySQL "TMySQLServer(...)"
384/// ~~~
385/// Add a `+` before `Plugin.` to allow for the extension of an already defined resource (see TEnv).
386
388{
389 if (!env) return;
390
391 TIter next(env->GetTable());
392 TEnvRec *er;
393
394 while ((er = (TEnvRec*) next())) {
395 const char *s;
396 if ((s = strstr(er->GetName(), "Plugin."))) {
397 // use s, i.e. skip possible OS and application prefix to Plugin.
398 // so that GetValue() takes properly care of returning the value
399 // for the specified OS and/or application
400 const char *val = env->GetValue(s, (const char*)nullptr);
401 if (val) {
402 Int_t cnt = 0;
403 char *v = StrDup(val);
404 s += 7;
405 while (1) {
406 TString regexp = strtok(!cnt ? v : nullptr, "; "); // this method does not need to be reentrant
407 if (regexp.IsNull()) break;
408 TString clss = strtok(nullptr, "; ");
409 if (clss.IsNull()) break;
410 TString plugin = strtok(nullptr, "; ");
411 if (plugin.IsNull()) break;
412 TString ctor = strtok(nullptr, ";\"");
413 if (!ctor.Contains("("))
414 ctor = strtok(nullptr, ";\"");
415 AddHandler(s, regexp, clss, plugin, ctor, "TEnv");
416 cnt++;
417 }
418 delete [] v;
419 }
420 }
421 }
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// Load all plugin macros from the specified path/base directory.
426
428{
429 void *dirp = gSystem->OpenDirectory(path);
430 if (dirp) {
431 if (gDebug > 0)
432 Info("LoadHandlerMacros", "%s", path);
434 macros.SetOwner();
435 const char *f1;
436 while ((f1 = gSystem->GetDirEntry(dirp))) {
437 TString f = f1;
438 if (f[0] == 'P' && f.EndsWith(".C")) {
439 const char *p = gSystem->ConcatFileName(path, f);
441 macros.Add(new TObjString(p));
442 }
443 delete [] p;
444 }
445 }
446 // load macros in alphabetical order
447 TIter next(&macros);
448 TObjString *s;
449 while ((s = (TObjString*)next())) {
450 if (gDebug > 1)
451 Info("LoadHandlerMacros", " plugin macro: %s", s->String().Data());
452 Longptr_t res;
453 if ((res = gROOT->Macro(s->String(), nullptr, kFALSE)) < 0) {
454 Error("LoadHandlerMacros", "pluging macro %s returned %ld",
455 s->String().Data(), res);
456 }
457 }
458 }
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// Load plugin handlers specified via macros in a list of plugin
464/// directories. The `$ROOTSYS/etc/plugins` is the default top plugin directory
465/// specified in `$ROOTSYS/etc/system.rootrc`. The macros must have names
466/// like `<BaseClass>/PX0_<PluginClass>.C`, e.g. //`TSQLServer/P20_TMySQLServer.C`,
467/// to allow easy sorting and grouping. If the BaseClass is in a namespace
468/// the directory must have the name NameSpace@@BaseClass as : is a reserved
469/// pathname character on some operating systems. Macros not beginning with
470/// 'P' and ending with ".C" are ignored. If base is specified only plugin
471/// macros for that base class are loaded. The macros typically
472/// should look like:
473/// ~~~ {.cpp}
474/// void P10_TDCacheFile()
475/// {
476/// gPluginMgr->AddHandler("TFile", "^dcache", "TDCacheFile",
477/// "DCache", "TDCacheFile(const char*,Option_t*,const char*,Int_t)");
478/// }
479/// ~~~
480/// In general these macros should not cause side effects, by changing global
481/// ROOT state via, e.g. gSystem calls, etc. However, in specific cases
482/// this might be useful, e.g. adding a library search path, adding a specific
483/// dependency, check on some OS or ROOT capability or downloading
484/// of the plugin.
485
487{
488 TString sbase = base;
489 if (sbase.Length())
490 sbase.ReplaceAll("::", "@@");
491
493
495 return;
496
498
499 // While waiting for the lock, another thread may
500 // have process the requested plugin.
502 return;
503
504 if (!fBasesLoaded) {
505 fBasesLoaded = new THashTable();
507 }
509
511
512 TString plugindirs = gEnv->GetValue("Root.PluginPath", (char*)nullptr);
513 if (plugindirs.Length() == 0) {
514 plugindirs = "plugins";
516 }
517#ifdef WIN32
518 TObjArray *dirs = plugindirs.Tokenize(";");
519#else
520 TObjArray *dirs = plugindirs.Tokenize(":");
521#endif
522 TString d;
523 for (Int_t i = 0; i < dirs->GetEntriesFast(); i++) {
524 d = ((TObjString*)dirs->At(i))->GetString();
525 // check if directory already scanned
526 Int_t skip = 0;
527 for (Int_t j = 0; j < i; j++) {
528 TString pd = ((TObjString*)dirs->At(j))->GetString();
529 if (pd == d) {
530 skip++;
531 break;
532 }
533 }
534 if (!skip) {
535 if (sbase != "") {
536 const char *p = gSystem->ConcatFileName(d, sbase);
538 delete [] p;
539 } else {
540 void *dirp = gSystem->OpenDirectory(d);
541 if (dirp) {
542 if (gDebug > 0)
543 Info("LoadHandlersFromPluginDirs", "%s", d.Data());
544 const char *f1;
545 while ((f1 = gSystem->GetDirEntry(dirp))) {
546 TString f = f1;
547 const char *p = gSystem->ConcatFileName(d, f);
550 delete [] p;
551 }
552 }
554 }
555 }
556 }
558 delete dirs;
559}
560
561////////////////////////////////////////////////////////////////////////////////
562/// Add plugin handler to the list of handlers. If there is already a
563/// handler defined for the same base and regexp it will be replaced.
564
565void TPluginManager::AddHandler(const char *base, const char *regexp,
566 const char *className, const char *pluginName,
567 const char *ctor, const char *origin)
568{
569 // make sure there is no previous handler for the same case
570 RemoveHandler(base, regexp);
571
572 if (TPH__IsReadingDirs())
573 origin = gInterpreter->GetCurrentMacroName();
574
575 TPluginHandler *h = new TPluginHandler(base, regexp, className,
577 fHandlers->Add(h);
578}
579
580////////////////////////////////////////////////////////////////////////////////
581/// Remove handler for the specified base class and the specified
582/// regexp. If regexp=0 remove all handlers for the specified base.
583
584void TPluginManager::RemoveHandler(const char *base, const char *regexp)
585{
586 TIter next(fHandlers);
588
589 while ((h = (TPluginHandler*) next())) {
590 if (h->fBase == base) {
591 if (!regexp || h->fRegexp == regexp) {
593 delete h;
594 }
595 }
596 }
597}
598
599////////////////////////////////////////////////////////////////////////////////
600/// Returns the handler if there exists a handler for the specified URI.
601/// The uri can be 0 in which case the first matching plugin handler
602/// will be returned. Returns 0 in case handler is not found.
603
604TPluginHandler *TPluginManager::FindHandler(const char *base, const char *uri)
605{
607
608 TIter next(fHandlers);
610
611 while ((h = (TPluginHandler*) next())) {
612 if (h->CanHandle(base, uri)) {
613 if (gDebug > 0)
614 Info("FindHandler", "found plugin for %s", h->GetClass());
615 return h;
616 }
617 }
618
619 if (gDebug > 2) {
620 if (uri)
621 Info("FindHandler", "did not find plugin for class %s and uri %s", base, uri);
622 else
623 Info("FindHandler", "did not find plugin for class %s", base);
624 }
625
626 return nullptr;
627}
628
629////////////////////////////////////////////////////////////////////////////////
630/// Print list of registered plugin handlers. If option is "a" print
631/// also the ctor's that will be used.
632
634{
635 TIter next(fHandlers);
637 Int_t cnt = 0, cntmiss = 0;
638
639 Printf("=====================================================================");
640 Printf("Base Regexp Class Plugin");
641 Printf("=====================================================================");
642
643 while ((h = (TPluginHandler*) next())) {
644 cnt++;
645 h->Print(opt);
646 if (h->CheckPlugin() == -1)
647 cntmiss++;
648 }
649 Printf("=====================================================================");
650 Printf("%d plugin handlers registered", cnt);
651 Printf("[*] %d %s not available", cntmiss, cntmiss==1 ? "plugin" : "plugins");
652 Printf("=====================================================================\n");
653}
654
655////////////////////////////////////////////////////////////////////////////////
656/// Write in the specified directory the plugin macros. If plugin is specified
657/// and if it is a base class all macros for that base will be written. If it
658/// is a plugin class name, only that one macro will be written. If plugin
659/// is 0 all macros are written. Returns -1 if dir does not exist, 0 otherwise.
660
661Int_t TPluginManager::WritePluginMacros(const char *dir, const char *plugin) const
662{
663 const_cast<TPluginManager*>(this)->LoadHandlersFromPluginDirs();
664
665 TString d;
666 if (!dir || !dir[0])
667 d = ".";
668 else
669 d = dir;
670
672 Error("WritePluginMacros", "cannot write in directory %s", d.Data());
673 return -1;
674 }
675
676 TString base;
677 Int_t idx = 0;
678
680 while (lnk) {
681 TPluginHandler *h = (TPluginHandler *) lnk->GetObject();
682 if (plugin && strcmp(plugin, h->fBase) && strcmp(plugin, h->fClass)) {
683 lnk = lnk->Next();
684 continue;
685 }
686 if (base != h->fBase) {
687 idx = 10;
688 base = h->fBase;
689 } else
690 idx += 10;
691 const char *dd = gSystem->ConcatFileName(d, h->fBase);
692 TString sdd = dd;
693 sdd.ReplaceAll("::", "@@");
694 delete [] dd;
696 if (gSystem->MakeDirectory(sdd) < 0) {
697 Error("WritePluginMacros", "cannot create directory %s", sdd.Data());
698 return -1;
699 }
700 }
701 TString fn;
702 fn.Form("P%03d_%s.C", idx, h->fClass.Data());
703 const char *fd = gSystem->ConcatFileName(sdd, fn);
704 FILE *f = fopen(fd, "w");
705 if (f) {
706 fprintf(f, "void P%03d_%s()\n{\n", idx, h->fClass.Data());
707 fprintf(f, " gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
708 h->fBase.Data(), h->fRegexp.Data(), h->fClass.Data());
709 fprintf(f, " \"%s\", \"%s\");\n", h->fPlugin.Data(), h->fCtor.Data());
710
711 // check for different regexps cases for the same base + class and
712 // put them all in the same macro
713 TObjLink *lnk2 = lnk->Next();
714 while (lnk2) {
715 TPluginHandler *h2 = (TPluginHandler *) lnk2->GetObject();
716 if (h->fBase != h2->fBase || h->fClass != h2->fClass)
717 break;
718
719 fprintf(f, " gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
720 h2->fBase.Data(), h2->fRegexp.Data(), h2->fClass.Data());
721 fprintf(f, " \"%s\", \"%s\");\n", h2->fPlugin.Data(), h2->fCtor.Data());
722
723 lnk = lnk2;
724 lnk2 = lnk2->Next();
725 }
726 fprintf(f, "}\n");
727 fclose(f);
728 }
729 delete [] fd;
730 lnk = lnk->Next();
731 }
732 return 0;
733}
734
735////////////////////////////////////////////////////////////////////////////////
736/// Write in the specified environment config file the plugin records. If
737/// plugin is specified and if it is a base class all records for that
738/// base will be written. If it is a plugin class name, only that one
739/// record will be written. If plugin is 0 all macros are written.
740/// If envFile is 0 or "" the records are written to stdout.
741/// Returns -1 if envFile cannot be created or opened, 0 otherwise.
742
744{
745 const_cast<TPluginManager*>(this)->LoadHandlersFromPluginDirs();
746
747 FILE *fd;
748 if (!envFile || !envFile[0])
749 fd = stdout;
750 else
751 fd = fopen(envFile, "w+");
752
753 if (!fd) {
754 Error("WritePluginRecords", "error opening file %s", envFile);
755 return -1;
756 }
757
758 TString base, base2;
759 Int_t idx = 0;
760
762 while (lnk) {
763 TPluginHandler *h = (TPluginHandler *) lnk->GetObject();
764 if (plugin && strcmp(plugin, h->fBase) && strcmp(plugin, h->fClass)) {
765 lnk = lnk->Next();
766 continue;
767 }
768 if (base != h->fBase) {
769 idx = 1;
770 base = h->fBase;
771 base2 = base;
772 base2.ReplaceAll("::", "@@");
773 } else
774 idx += 1;
775
776 if (idx == 1)
777 fprintf(fd, "Plugin.%s: %s %s %s \"%s\"\n", base2.Data(), h->fRegexp.Data(),
778 h->fClass.Data(), h->fPlugin.Data(), h->fCtor.Data());
779 else
780 fprintf(fd, "+Plugin.%s: %s %s %s \"%s\"\n", base2.Data(), h->fRegexp.Data(),
781 h->fClass.Data(), h->fPlugin.Data(), h->fCtor.Data());
782
783 // check for different regexps cases for the same base + class and
784 // put them all in the same macro
785 TObjLink *lnk2 = lnk->Next();
786 while (lnk2) {
787 TPluginHandler *h2 = (TPluginHandler *) lnk2->GetObject();
788 if (h->fBase != h2->fBase || h->fClass != h2->fClass)
789 break;
790
791 fprintf(fd, "+Plugin.%s: %s %s %s \"%s\"\n", base2.Data(), h2->fRegexp.Data(),
792 h2->fClass.Data(), h2->fPlugin.Data(), h2->fCtor.Data());
793
794 lnk = lnk2;
795 lnk2 = lnk2->Next();
796 }
797 lnk = lnk->Next();
798 }
799
800 if (envFile && envFile[0])
801 fclose(fd);
802
803 return 0;
804}
Cppyy::TCppType_t fClass
#define d(i)
Definition RSha256.hxx:102
#define f(i)
Definition RSha256.hxx:104
#define h(i)
Definition RSha256.hxx:106
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kIsPublic
Definition TDictionary.h:75
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
winID h TVirtualViewer3D TVirtualGLPainter p
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
static bool & TPH__IsReadingDirs()
TPluginManager * gPluginMgr
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
#define gROOT
Definition TROOT.h:411
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
char * StrDup(const char *str)
Duplicate the string str.
Definition TString.cxx:2563
@ kReadPermission
Definition TSystem.h:55
@ kWritePermission
Definition TSystem.h:54
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define R__LOCKGUARD(mutex)
#define R__WRITE_LOCKGUARD(mutex)
#define R__READ_LOCKGUARD(mutex)
const char * proto
Definition civetweb.c:18822
#define free
Definition civetweb.c:1578
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
Definition TClass.cxx:5788
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2973
virtual bool UseRWLock(Bool_t enable=true)
Set this collection to use a RW lock upon access, making it thread safe.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Definition TEnv.h:86
The TEnv class reads config files, by default named .rootrc.
Definition TEnv.h:124
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:490
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Int_t GetNargs() const
Number of function arguments.
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
THashTable implements a hash table to store TObject's.
Definition THashTable.h:35
void Add(TObject *obj) override
Add object to the hash table.
TObject * FindObject(const char *name) const override
Find object using its name.
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:819
virtual TObjLink * FirstLink() const
Definition TList.h:102
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:354
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
std::string GetTypeNormalizedName() const
Get the normalized name of the return type.
Method or function calling interface.
Definition TMethodCall.h:37
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
An array of TObjects.
Definition TObjArray.h:31
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
bool CheckNameMatch(int iarg, const std::type_info &ti)
Return true if the name of the iarg-th argument's type match type_name
Int_t CheckPlugin() const
Check if the plugin library for this handler exits.
TFunction * fMethod
ctor method call environment
AtomicInt_t fCanCall
void Print(Option_t *opt="") const override
Print info about the plugin handler.
Bool_t CanHandle(const char *base, const char *uri)
Check if regular expression appears in the URI, if so return kTRUE.
~TPluginHandler()
Cleanup plugin handler object.
Bool_t CheckForExecPlugin(Int_t nargs)
Check that we can properly run ExecPlugin.
Bool_t fIsMacro
if 1 fCallEnv is ok, -1 fCallEnv is not ok, 0 fCallEnv not setup yet.
void SetupCallEnv()
Setup ctor or static method call environment.
void LoadPluginImpl()
Load the plugin library for this handler.
TMethodCall * fCallEnv
std::vector< std::string > fArgTupleTypeInfo
ctor method or global function
Int_t LoadPlugin()
Load the plugin library for this handler.
std::once_flag fLoadStatusFlag
This class implements a plugin library manager.
Int_t WritePluginMacros(const char *dir, const char *plugin=nullptr) const
Write in the specified directory the plugin macros.
void AddHandler(const char *base, const char *regexp, const char *className, const char *pluginName, const char *ctor=nullptr, const char *origin=nullptr)
Add plugin handler to the list of handlers.
void Print(Option_t *opt="") const override
Print list of registered plugin handlers.
~TPluginManager()
Clean up the plugin manager.
void RemoveHandler(const char *base, const char *regexp=nullptr)
Remove handler for the specified base class and the specified regexp.
void LoadHandlersFromEnv(TEnv *env)
Load plugin handlers specified in config file, like:
THashTable * fBasesLoaded
void LoadHandlerMacros(const char *path)
Load all plugin macros from the specified path/base directory.
Int_t WritePluginRecords(const char *envFile, const char *plugin=nullptr) const
Write in the specified environment config file the plugin records.
TPluginHandler * FindHandler(const char *base, const char *uri=nullptr)
Returns the handler if there exists a handler for the specified URI.
TPluginManager()
Constructor.
void LoadHandlersFromPluginDirs(const char *base=nullptr)
Load plugin handlers specified via macros in a list of plugin directories.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Definition TROOT.cxx:3107
Regular expression class.
Definition TRegexp.h:31
A sorted doubly linked list.
Definition TSortedList.h:28
Basic string class.
Definition TString.h:138
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1170
const char * Data() const
Definition TString.h:384
Bool_t MaybeRegexp() const
Returns true if string contains one of the regexp characters "^$.[]*+?".
Definition TString.cxx:959
@ kLeading
Definition TString.h:284
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:631
Bool_t IsNull() const
Definition TString.h:422
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:659
virtual void FreeDirectory(void *dirp)
Free a directory.
Definition TSystem.cxx:855
virtual void * OpenDirectory(const char *name)
Open a directory.
Definition TSystem.cxx:846
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
Definition TSystem.cxx:4282
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1082
virtual int MakeDirectory(const char *name)
Make a directory.
Definition TSystem.cxx:836
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition TSystem.cxx:1092
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1307
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
Definition TSystem.cxx:863
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Definition TSystem.cxx:2031
TF1 * f1
Definition legend1.C:11
R__EXTERN TVirtualRWMutex * gCoreMutex
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.