Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:35

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 
0006 #ifndef JANA2_JPLUGINLOADER_H
0007 #define JANA2_JPLUGINLOADER_H
0008 
0009 #include <JANA/Services/JParameterManager.h>
0010 #include <JANA/JService.h>
0011 
0012 #include <string>
0013 #include <vector>
0014 #include <list>
0015 #include <queue>
0016 
0017 
0018 class JComponentManager;
0019 class JApplication;
0020 
0021 class JPlugin {
0022     friend class JPluginLoader;
0023     JApplication* m_app;
0024     JLogger m_logger;
0025     std::string m_name;
0026     std::string m_path;
0027     void* m_handle;
0028 public:
0029     JPlugin(std::string name, std::string path) : m_name(name), m_path(path) {};
0030     ~JPlugin();
0031     std::string GetName() { return m_name; }
0032     std::string GetPath() { return m_path; }
0033 };
0034 
0035 class JPluginLoader : public JService {
0036 
0037 public:
0038 
0039     JPluginLoader() {
0040         SetPrefix("jana");
0041     }
0042     ~JPluginLoader() override = default;
0043     void Init() override;
0044 
0045     void add_plugin(std::string plugin_name);
0046     void add_plugin_path(std::string path);
0047     void attach_plugins(JComponentManager* jcm);
0048     void attach_plugin(std::string name, std::string path);
0049     void resolve_plugin_paths();
0050 
0051     bool is_valid_plugin_name(const std::string& plugin_name) const;
0052     bool is_valid_path(const std::string& path) const;
0053     std::string find_first_valid_path(const std::string& name, std::ostringstream& debug_log) const;
0054     std::string make_path_from_name(const std::string& name, const std::string& path_prefix) const;
0055 
0056 private:
0057     Service<JParameterManager> m_params {this};
0058 
0059     std::queue<std::string> m_all_plugins_requested;
0060     std::vector<std::string> m_plugins_from_parameter;
0061     std::vector<std::string> m_plugins_to_exclude;
0062     std::vector<std::string> m_plugin_paths;
0063     std::string m_plugin_paths_str;
0064 
0065     // We wish to preserve each plugin's insertion order
0066     // This way, plugins are unloaded in the reverse order they were added
0067     std::list<std::unique_ptr<JPlugin>> m_plugins; 
0068     std::map<std::string, JPlugin*> m_plugin_index;
0069 
0070     bool m_verbose = false;
0071 };
0072 
0073 
0074 #endif //JANA2_JPLUGINLOADER_H