HAL
plugin_manager.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
33 
34 #include <functional>
35 #include <map>
36 #include <memory>
37 #include <string>
38 #include <tuple>
39 
40 namespace hal
41 {
47  namespace plugin_manager
48  {
56  void add_existing_options_description(const ProgramOptions& existing_options);
57 
63  std::set<std::string> get_plugin_names();
64 
70  std::filesystem::path get_plugin_path(std::string plugin_name);
71 
79  std::unordered_map<std::string, std::string> get_cli_plugin_flags();
80 
88  std::unordered_map<std::string, std::string> get_ui_plugin_flags();
89 
97  ProgramOptions get_cli_plugin_options();
98 
106  bool load_all_plugins(const std::vector<std::filesystem::path>& directory_names = {});
107 
115  bool load(const std::string& plugin_name, const std::filesystem::path& file_path = std::filesystem::path());
116 
122  bool unload_all_plugins();
123 
130  bool unload(const std::string& plugin_name);
131 
141  BasePluginInterface* get_plugin_instance(const std::string& plugin_name, bool initialize = true, bool silent = false);
142 
153  template<typename T>
154  T* get_plugin_instance(const std::string& plugin_name, bool initialize = true)
155  {
156  return dynamic_cast<T*>(get_plugin_instance(plugin_name, initialize));
157  }
158 
166  template<typename T>
167  T* get_first_extension(const std::string& plugin_name, bool initialize = true)
168  {
169  BasePluginInterface* bpif = get_plugin_instance(plugin_name, initialize);
170  if (!bpif)
171  return nullptr;
172  return bpif->get_first_extension<T>();
173  }
174 
186  u64 add_model_changed_callback(std::function<void(bool, std::string const&, std::string const&)> callback);
187 
196 
201  {
203  std::vector<std::string> args;
204  std::string description;
205  };
206 
212  bool has_valid_file_extension(std::filesystem::path file_name);
213 
219  std::vector<PluginFeature> get_plugin_features(std::string name);
220 
221  } // namespace plugin_manager
222 } // namespace hal
uint64_t u64
Definition: defines.h:42
void add_existing_options_description(const ProgramOptions &existing_options)
u64 add_model_changed_callback(std::function< void(bool, std::string const &, std::string const &)> callback)
bool has_valid_file_extension(std::filesystem::path file_name)
T * get_first_extension(const std::string &plugin_name, bool initialize=true)
bool unload(const std::string &plugin_name)
std::set< std::string > get_plugin_names()
BasePluginInterface * get_plugin_instance(const std::string &plugin_name, bool initialize, bool silent)
std::unordered_map< std::string, std::string > get_cli_plugin_flags()
std::unordered_map< std::string, std::string > get_ui_plugin_flags()
std::filesystem::path get_plugin_path(std::string plugin_name)
ProgramOptions get_cli_plugin_options()
void remove_model_changed_callback(u64 id)
bool load_all_plugins(const std::vector< std::filesystem::path > &directory_names)
std::vector< PluginFeature > get_plugin_features(std::string name)
bool load(const std::string &plugin_name, const std::filesystem::path &file_path_or_empty)
void initialize()
Definition: event_log.cpp:302
std::string name
std::vector< std::string > args
FacExtensionInterface::Feature feature