112 TTHREAD_TLS(
bool) readingDirs (
false);
122 const char *className,
const char *pluginName,
123 const char *ctor,
const char *origin):
136 TString aclicMode, arguments, io;
197 using exit_scope = std::shared_ptr<void*>;
198 exit_scope guard(
nullptr,
199 [
this,&setCanCall](
void *) { this->
fCanCall = setCanCall; } );
204 Error(
"SetupCallEnv",
"class %s not found in plugin %s",
fClass.
Data(),
217 fMethod = cl->GetMethodWithPrototype(method, proto);
222 Error(
"SetupCallEnv",
"global function %s not found", method.
Data());
224 Error(
"SetupCallEnv",
"method %s not found in class %s", method.
Data(),
230 Error(
"SetupCallEnv",
"method %s is not public", method.
Data());
277 Error(
"ExecPlugin",
"no ctor specified for this handler %s",
fClass.
Data());
300 Error(
"ExecPlugin",
"nargs (%d) not consistent with expected number of arguments ([%d-%d])",
315 const char *exist =
"";
321 if (strchr(opt,
'a')) {
327 if (path)
Printf(
" [Lib: %s]", path);
363 while ((er = (
TEnvRec*) next())) {
365 if ((s = strstr(er->GetName(),
"Plugin."))) {
369 const char *val = env->
GetValue(s, (
const char*)0);
375 TString regexp = strtok(!cnt ? v : 0,
"; ");
376 if (regexp.
IsNull())
break;
377 TString clss = strtok(0,
"; ");
379 TString plugin = strtok(0,
"; ");
380 if (plugin.
IsNull())
break;
381 TString ctor = strtok(0,
";\"");
383 ctor = strtok(0,
";\"");
384 AddHandler(s, regexp, clss, plugin, ctor,
"TEnv");
401 Info(
"LoadHandlerMacros",
"%s", path);
407 if (f[0] ==
'P' && f.
EndsWith(
".C")) {
420 Info(
"LoadHandlerMacros",
" plugin macro: %s", s->
String().
Data());
423 Error(
"LoadHandlerMacros",
"pluging macro %s returned %ld",
464 if (fBasesLoaded && fBasesLoaded->FindObject(sbase))
471 if (fBasesLoaded && fBasesLoaded->FindObject(sbase))
476 fBasesLoaded->SetOwner();
483 if (plugindirs.
Length() == 0) {
484 plugindirs =
"plugins";
497 for (
Int_t j = 0; j < i; j++) {
507 LoadHandlerMacros(p);
513 Info(
"LoadHandlersFromPluginDirs",
"%s", d.
Data());
518 LoadHandlerMacros(p);
536 const char *className,
const char *pluginName,
537 const char *ctor,
const char *origin)
542 fHandlers =
new TList;
547 RemoveHandler(base, regexp);
553 pluginName, ctor, origin);
567 if (!fHandlers)
return;
569 TIter next(fHandlers);
573 if (h->
fBase == base) {
574 if (!regexp || h->
fRegexp == regexp) {
575 fHandlers->Remove(h);
589 LoadHandlersFromPluginDirs(base);
592 TIter next(fHandlers);
598 Info(
"FindHandler",
"found plugin for %s", h->
GetClass());
605 Info(
"FindHandler",
"did not find plugin for class %s and uri %s", base, uri);
607 Info(
"FindHandler",
"did not find plugin for class %s", base);
619 if (!fHandlers)
return;
621 TIter next(fHandlers);
625 Printf(
"=====================================================================");
626 Printf(
"Base Regexp Class Plugin");
627 Printf(
"=====================================================================");
635 Printf(
"=====================================================================");
636 Printf(
"%d plugin handlers registered", cnt);
637 Printf(
"[*] %d %s not available", cntmiss, cntmiss==1 ?
"plugin" :
"plugins");
638 Printf(
"=====================================================================\n");
651 if (!fHandlers)
return 0;
660 Error(
"WritePluginMacros",
"cannot write in directory %s", d.
Data());
667 TObjLink *lnk = fHandlers->FirstLink();
670 if (plugin && strcmp(plugin, h->
fBase) && strcmp(plugin, h->
fClass)) {
674 if (base != h->
fBase) {
685 Error(
"WritePluginMacros",
"cannot create directory %s", sdd.
Data());
692 FILE *f = fopen(fd,
"w");
694 fprintf(f,
"void P%03d_%s()\n{\n", idx, h->
fClass.
Data());
695 fprintf(f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
707 fprintf(f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
735 if (!fHandlers)
return 0;
738 if (!envFile || !envFile[0])
741 fd = fopen(envFile,
"w+");
744 Error(
"WritePluginRecords",
"error opening file %s", envFile);
751 TObjLink *lnk = fHandlers->FirstLink();
754 if (plugin && strcmp(plugin, h->
fBase) && strcmp(plugin, h->
fClass)) {
758 if (base != h->
fBase) {
767 fprintf(fd,
"Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(), h->
fRegexp.
Data(),
770 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(), h->
fRegexp.
Data(),
781 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(), h2->
fRegexp.
Data(),
790 if (envFile && envFile[0])
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Int_t CheckPlugin() const
Check if the plugin library for this handler exits.
void LoadHandlerMacros(const char *path)
Load all plugin macros from the specified path/base directory.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Collectable string class.
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form: ~~~ {.cpp} [path/]macro.C[+|++[k|f|g|O|c|s|d|v|-]][(args)]...
R__EXTERN TVirtualMutex * gInterpreterMutex
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
void RemoveHandler(const char *base, const char *regexp=0)
Remove handler for the specified base class and the specified regexp.
virtual int MakeDirectory(const char *name)
Make a directory.
Regular expression class.
This class implements a mutex interface.
TPluginHandler * FindHandler(const char *base, const char *uri=0)
Returns the handler if there exists a handler for the specified URI.
void LoadHandlersFromEnv(TEnv *env)
Load plugin handlers specified in config file, like: Plugin.TFile: ^rfio: TRFIOFile RFI...
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Int_t LoadPlugin()
Load the plugin library for this handler.
The TEnv class reads config files, by default named .rootrc.
~TPluginManager()
Clean up the plugin manager.
TObject * At(Int_t idx) const
Int_t WritePluginRecords(const char *envFile, const char *plugin=0) const
Write in the specified environment config file the plugin records.
static bool & TPH__IsReadingDirs()
void SetupCallEnv()
Setup ctor or static method call environment.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
THashTable implements a hash table to store TObject's.
void LoadHandlersFromPluginDirs(const char *base=0)
Load plugin handlers specified via macros in a list of plugin directories.
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
#define R__WRITE_LOCKGUARD(mutex)
A sorted doubly linked list.
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
R__EXTERN TVirtualRWMutex * gCoreMutex
Bool_t CheckForExecPlugin(Int_t nargs)
Check that we can properly run ExecPlugin.
Method or function calling interface.
void Print(Option_t *opt="") const
Print list of registered plugin handlers.
#define R__READ_LOCKGUARD(mutex)
Int_t GetNargs() const
Number of function arguments.
void AddHandler(const char *base, const char *regexp, const char *className, const char *pluginName, const char *ctor=0, const char *origin=0)
Add plugin handler to the list of handlers.
R__EXTERN TSystem * gSystem
THashList * GetTable() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Int_t GetEntriesFast() const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
This class implements a plugin library manager.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
The ROOT global object gROOT contains a list of all defined classes.
virtual void FreeDirectory(void *dirp)
Free a directory.
char * StrDup(const char *str)
Duplicate the string str.
#define R__LOCKGUARD2(mutex)
AtomicInt_t fCanCall
ctor method or global function
void Print(Option_t *opt="") const
Print info about the plugin handler.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Wrapper around a TObject so it can be stored in a TList.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Bool_t fIsMacro
if 1 fCallEnv is ok, -1 fCallEnv is not ok, 0 fCallEnv not setup yet.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static constexpr double s
#define R__LOCKGUARD(mutex)
static TVirtualMutex * gPluginManagerMutex
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.
Int_t WritePluginMacros(const char *dir, const char *plugin=0) const
Write in the specified directory the plugin macros.
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
Bool_t CanHandle(const char *base, const char *uri)
Check if regular expression appears in the URI, if so return kTRUE.
TObject * GetObject() const
TPluginManager * gPluginMgr
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
void Add(TObject *obj)
Add object in sorted list.
~TPluginHandler()
Cleanup plugin handler object.
TFunction * fMethod
ctor method call environment
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
static char * skip(char **buf, const char *delimiters)
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Bool_t MaybeRegexp() const
Returns true if string contains one of the regexp characters "^$.[]*+?".
const char * Data() const
const char * GetClass() const