106 TTHREAD_TLS(
bool) readingDirs (
false);
115 const char *ctor,
const char *origin)
129 TString aclicMode, arguments, io;
141 fCtor = fCtor.Strip(TString::kLeading,
':');
186 std::string norm_name;
188 free(demangled_name);
206 using exit_scope = std::shared_ptr<void*>;
207 exit_scope guard(
nullptr,
208 [
this,&setCanCall](
void *) { this->
fCanCall = setCanCall; } );
213 Error(
"SetupCallEnv",
"class %s not found in plugin %s",
fClass.Data(),
231 Error(
"SetupCallEnv",
"global function %s not found", method.
Data());
233 Error(
"SetupCallEnv",
"method %s not found in class %s", method.
Data(),
239 Error(
"SetupCallEnv",
"method %s is not public", method.
Data());
303 if (
fCtor.IsNull()) {
304 Error(
"ExecPlugin",
"no ctor specified for this handler %s",
fClass.Data());
324 if (nargs < fMethod->GetNargs() -
fMethod->GetNargsOpt() ||
326 Error(
"ExecPlugin",
"nargs (%d) not consistent with expected number of arguments ([%d-%d])",
341 const char *exist =
"";
347 if (strchr(opt,
'a')) {
353 if (path)
Printf(
" [Lib: %s]", path);
394 while ((er = (
TEnvRec*) next())) {
396 if ((s = strstr(er->
GetName(),
"Plugin."))) {
400 const char *val = env->
GetValue(s, (
const char*)
nullptr);
406 TString regexp = strtok(!cnt ?
v :
nullptr,
"; ");
407 if (regexp.
IsNull())
break;
408 TString clss = strtok(
nullptr,
"; ");
410 TString plugin = strtok(
nullptr,
"; ");
411 if (plugin.
IsNull())
break;
412 TString ctor = strtok(
nullptr,
";\"");
414 ctor = strtok(
nullptr,
";\"");
415 AddHandler(s, regexp, clss, plugin, ctor,
"TEnv");
429 void *dirp =
gSystem->OpenDirectory(path);
432 Info(
"LoadHandlerMacros",
"%s", path);
436 while ((
f1 =
gSystem->GetDirEntry(dirp))) {
438 if (
f[0] ==
'P' &&
f.EndsWith(
".C")) {
439 const char *p =
gSystem->PrependPathName(path,
f);
450 Info(
"LoadHandlerMacros",
" plugin macro: %s", s->
String().
Data());
453 Error(
"LoadHandlerMacros",
"pluging macro %s returned %ld",
511 TString plugindirs =
gEnv->GetValue(
"Root.PluginPath", (
char*)
nullptr);
512 if (plugindirs.
Length() == 0) {
513 plugindirs =
"plugins";
526 for (
Int_t j = 0; j < i; j++) {
535 const char *p =
gSystem->PrependPathName(
d, sbase);
538 void *dirp =
gSystem->OpenDirectory(
d);
541 Info(
"LoadHandlersFromPluginDirs",
"%s",
d.Data());
543 while ((
f1 =
gSystem->GetDirEntry(dirp))) {
546 const char *p1 =
gSystem->PrependPathName(
d, temp);
564 const char *className,
const char *pluginName,
565 const char *ctor,
const char *origin)
574 pluginName, ctor, origin);
588 if (
h->fBase == base) {
589 if (!regexp ||
h->fRegexp == regexp) {
610 if (
h->CanHandle(base, uri)) {
612 Info(
"FindHandler",
"found plugin for %s",
h->GetClass());
619 Info(
"FindHandler",
"did not find plugin for class %s and uri %s", base, uri);
621 Info(
"FindHandler",
"did not find plugin for class %s", base);
635 Int_t cnt = 0, cntmiss = 0;
637 Printf(
"=====================================================================");
638 Printf(
"Base Regexp Class Plugin");
639 Printf(
"=====================================================================");
644 if (
h->CheckPlugin() == -1)
647 Printf(
"=====================================================================");
648 Printf(
"%d plugin handlers registered", cnt);
649 Printf(
"[*] %d %s not available", cntmiss, cntmiss==1 ?
"plugin" :
"plugins");
650 Printf(
"=====================================================================\n");
670 Error(
"WritePluginMacros",
"cannot write in directory %s",
d.Data());
680 if (plugin && strcmp(plugin,
h->fBase) && strcmp(plugin,
h->fClass)) {
684 if (base !=
h->fBase) {
693 if (
gSystem->MakeDirectory(sdd) < 0) {
694 Error(
"WritePluginMacros",
"cannot create directory %s", sdd.
Data());
699 fn.
Form(
"P%03d_%s.C", idx,
h->fClass.Data());
700 const char *fd =
gSystem->PrependPathName(sdd, fn);
701 FILE *
f = fopen(fd,
"w");
703 fprintf(
f,
"void P%03d_%s()\n{\n", idx,
h->fClass.Data());
704 fprintf(
f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
705 h->fBase.Data(),
h->fRegexp.Data(),
h->fClass.Data());
706 fprintf(
f,
" \"%s\", \"%s\");\n",
h->fPlugin.Data(),
h->fCtor.Data());
716 fprintf(
f,
" gPluginMgr->AddHandler(\"%s\", \"%s\", \"%s\",\n",
744 if (!envFile || !envFile[0])
747 fd = fopen(envFile,
"w+");
750 Error(
"WritePluginRecords",
"error opening file %s", envFile);
760 if (plugin && strcmp(plugin,
h->fBase) && strcmp(plugin,
h->fClass)) {
764 if (base !=
h->fBase) {
773 fprintf(fd,
"Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(),
h->fRegexp.Data(),
774 h->fClass.Data(),
h->fPlugin.Data(),
h->fCtor.Data());
776 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(),
h->fRegexp.Data(),
777 h->fClass.Data(),
h->fPlugin.Data(),
h->fCtor.Data());
787 fprintf(fd,
"+Plugin.%s: %s %s %s \"%s\"\n", base2.
Data(), h2->
fRegexp.
Data(),
796 if (envFile && envFile[0])
int Int_t
Signed integer 4 bytes (int).
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
bool Bool_t
Boolean (0=false, 1=true) (bool).
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
const char Option_t
Option string (const char).
externTVirtualMutex * gInterpreterMutex
static bool & TPH__IsReadingDirs()
externTPluginManager * gPluginMgr
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
char * StrDup(const char *str)
Duplicate the string str.
#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 override
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
THashTable implements a hash table to store TObject's.
Each ROOT method (see TMethod) has a linked list of its arguments.
std::string GetTypeNormalizedName() const
Get the normalized name of the return type.
Method or function calling interface.
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
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.
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 or global function
AtomicInt_t fCanCall
!if 1 fCallEnv is ok, -1 fCallEnv is not ok, 0 fCallEnv not setup yet.
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.
void SetupCallEnv()
Setup ctor or static method call environment.
void LoadPluginImpl()
Load the plugin library for this handler.
TMethodCall * fCallEnv
!ctor method call environment
std::vector< std::string > fArgTupleTypeInfo
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.
TPluginManager(const TPluginManager &)=delete
void LoadHandlersFromEnv(TEnv *env)
Load plugin handlers specified in config file, like:
Bool_t fReadingDirs
! true if we are running LoadHandlersFromPluginDirs
THashTable * fBasesLoaded
! table of base classes already checked or loaded
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.
Regular expression class.
A sorted doubly linked list.
void Add(TObject *obj) override
Add object in sorted list.
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
const char * Data() const
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
externTVirtualRWMutex * 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.