107 TTHREAD_TLS(
bool) readingDirs (
false);
117 const char *className,
const char *pluginName,
118 const char *ctor,
const char *origin):
131 TString aclicMode, arguments, io;
192 using exit_scope = std::shared_ptr<void*>;
193 exit_scope guard(
nullptr,
194 [
this,&setCanCall](
void *) { this->
fCanCall = setCanCall; } );
199 Error(
"SetupCallEnv",
"class %s not found in plugin %s",
fClass.
Data(),
217 Error(
"SetupCallEnv",
"global function %s not found", method.
Data());
219 Error(
"SetupCallEnv",
"method %s not found in class %s", method.
Data(),
225 Error(
"SetupCallEnv",
"method %s is not public", method.
Data());
272 Error(
"ExecPlugin",
"no ctor specified for this handler %s",
fClass.
Data());
295 Error(
"ExecPlugin",
"nargs (%d) not consistent with expected number of arguments ([%d-%d])",
310 const char *exist =
"";
316 if (strchr(opt,
'a')) {
322 if (path)
Printf(
" [Lib: %s]", path);
357 while ((er = (
TEnvRec*) next())) {
359 if ((s = strstr(er->
GetName(),
"Plugin."))) {
363 const char *val = env->
GetValue(s, (
const char*)
nullptr);
369 TString regexp = strtok(!cnt ?
v :
nullptr,
"; ");
370 if (regexp.
IsNull())
break;
371 TString clss = strtok(
nullptr,
"; ");
373 TString plugin = strtok(
nullptr,
"; ");
374 if (plugin.
IsNull())
break;
375 TString ctor = strtok(
nullptr,
";\"");
377 ctor = strtok(
nullptr,
";\"");
378 AddHandler(s, regexp, clss, plugin, ctor,
"TEnv");
395 Info(
"LoadHandlerMacros",
"%s", path);
401 if (
f[0] ==
'P' &&
f.EndsWith(
".C")) {
414 Info(
"LoadHandlerMacros",
" plugin macro: %s", s->
String().
Data());
417 Error(
"LoadHandlerMacros",
"pluging macro %s returned %ld",
476 if (plugindirs.
Length() == 0) {
477 plugindirs =
"plugins";
490 for (
Int_t j = 0; j < i; j++) {
506 Info(
"LoadHandlersFromPluginDirs",
"%s",
d.Data());
529 const char *className,
const char *pluginName,
530 const char *ctor,
const char *origin)
546 pluginName, ctor, origin);
566 if (
h->fBase == base) {
567 if (!regexp ||
h->fRegexp == regexp) {
589 if (
h->CanHandle(base, uri)) {
591 Info(
"FindHandler",
"found plugin for %s",
h->GetClass());
598 Info(
"FindHandler",
"did not find plugin for class %s and uri %s", base, uri);
600 Info(
"FindHandler",
"did not find plugin for class %s", base);
616 Int_t cnt = 0, cntmiss = 0;
618 Printf(
"=====================================================================");
619 Printf(
"Base Regexp Class Plugin");
620 Printf(
"=====================================================================");
625 if (
h->CheckPlugin() == -1)
628 Printf(
"=====================================================================");
629 Printf(
"%d plugin handlers registered", cnt);
630 Printf(
"[*] %d %s not available", cntmiss, cntmiss==1 ?
"plugin" :
"plugins");
631 Printf(
"=====================================================================\n");
653 Error(
"WritePluginMacros",
"cannot write in directory %s",
d.Data());
663 if (plugin && strcmp(plugin,
h->fBase) && strcmp(plugin,
h->fClass)) {
667 if (base !=
h->fBase) {
678 Error(
"WritePluginMacros",
"cannot create directory %s", sdd.
Data());
683 fn.
Form(
"P%03d_%s.C", idx,
h->fClass.Data());
685 FILE *
f = fopen(fd,
"w");
687 fprintf(
f,
"void P%03d_%s()\n{\n", idx,
h->fClass.Data());
688 fprintf(
f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
689 h->fBase.Data(),
h->fRegexp.Data(),
h->fClass.Data());
690 fprintf(
f,
" \"%s\", \"%s\");\n",
h->fPlugin.Data(),
h->fCtor.Data());
700 fprintf(
f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
731 if (!envFile || !envFile[0])
734 fd = fopen(envFile,
"w+");
737 Error(
"WritePluginRecords",
"error opening file %s", envFile);
747 if (plugin && strcmp(plugin,
h->fBase) && strcmp(plugin,
h->fClass)) {
751 if (base !=
h->fBase) {
760 fprintf(fd,
"Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(),
h->fRegexp.Data(),
761 h->fClass.Data(),
h->fPlugin.Data(),
h->fCtor.Data());
763 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(),
h->fRegexp.Data(),
764 h->fClass.Data(),
h->fPlugin.Data(),
h->fCtor.Data());
774 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(), h2->
fRegexp.
Data(),
783 if (envFile && envFile[0])
R__EXTERN TVirtualMutex * gInterpreterMutex
static bool & TPH__IsReadingDirs()
TPluginManager * gPluginMgr
static TVirtualMutex * gPluginManagerMutex
void Printf(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
R__EXTERN TSystem * gSystem
#define R__LOCKGUARD2(mutex)
#define R__LOCKGUARD(mutex)
#define R__WRITE_LOCKGUARD(mutex)
#define R__READ_LOCKGUARD(mutex)
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
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.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetName() const
Returns name of object.
The TEnv class reads config files, by default named .rootrc.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
THashList * GetTable() const
Long_t Property() const
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.
THashTable implements a hash table to store TObject's.
void Add(TObject *obj)
Add object to the hash table.
TObject * FindObject(const char *name) const
Find object using its name.
virtual void Add(TObject *obj)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual TObjLink * FirstLink() const
Method or function calling interface.
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const
Wrapper around a TObject so it can be stored in a TList.
TObject * GetObject() const
Collectable string class.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Int_t CheckPlugin() const
Check if the plugin library for this handler exits.
void Print(Option_t *opt="") const
Print info about the plugin handler.
TFunction * fMethod
ctor method call environment
AtomicInt_t fCanCall
ctor method or global function
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.
Int_t LoadPlugin()
Load the plugin library for this handler.
This class implements a plugin library manager.
void LoadHandlersFromPluginDirs(const char *base=0)
Load plugin handlers specified via macros in a list of plugin directories.
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.
~TPluginManager()
Clean up the plugin manager.
TPluginHandler * FindHandler(const char *base, const char *uri=0)
Returns the handler if there exists a handler for the specified URI.
void Print(Option_t *opt="") const
Print list of registered plugin handlers.
void LoadHandlersFromEnv(TEnv *env)
Load plugin handlers specified in config file, like:
void RemoveHandler(const char *base, const char *regexp=0)
Remove handler for the specified base class and the specified regexp.
THashTable * fBasesLoaded
void LoadHandlerMacros(const char *path)
Load all plugin macros from the specified path/base directory.
Int_t WritePluginMacros(const char *dir, const char *plugin=0) const
Write in the specified directory the plugin macros.
Int_t WritePluginRecords(const char *envFile, const char *plugin=0) const
Write in the specified environment config file the plugin records.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
Regular expression class.
A sorted doubly linked list.
void Add(TObject *obj)
Add object in sorted list.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
const char * Data() const
Bool_t MaybeRegexp() const
Returns true if string contains one of the regexp characters "^$.[]*+?".
TString & ReplaceAll(const TString &s1, const TString &s2)
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual void FreeDirectory(void *dirp)
Free a directory.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
virtual TString SplitAclicMode(const char *filename, TString &mode, TString &args, TString &io) const
This method split a filename of the form:
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
virtual int MakeDirectory(const char *name)
Make a directory.
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
virtual const char * GetDirEntry(void *dirp)
Get a directory entry. Returns 0 if no more entries.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
This class implements a mutex interface.
R__EXTERN TVirtualRWMutex * gCoreMutex