HAL
plugin_interface_base.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"
29 #include "hal_core/utilities/log.h"
30 
31 #include <set>
32 #include <string>
33 #include <vector>
34 
35 namespace hal
36 {
37  class AbstractExtensionInterface;
38 
43 #ifdef COMPILER_CLANG
44 #pragma clang diagnostic push
45 #pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
46 #endif
47  class BasePluginInterface;
48  extern "C" PLUGIN_API std::unique_ptr<BasePluginInterface> create_plugin_instance();
49 #ifdef COMPILER_CLANG
50 #pragma clang diagnostic pop
51 #endif
52 
57  {
58  protected:
59  std::vector<AbstractExtensionInterface*> m_extensions;
60 
61  public:
62  BasePluginInterface() = default;
63  virtual ~BasePluginInterface();
64 
70  virtual void initialize();
71 
77  virtual std::string get_name() const = 0;
78 
84  virtual std::string get_version() const = 0;
85 
91  virtual std::string get_description() const;
92 
98  virtual std::set<std::string> get_dependencies() const;
99 
105  template<typename... Args>
106  inline void log(const Args&... args) const
107  {
108  log_info(get_name(), args...);
109  }
110 
114  virtual void on_load();
115 
119  virtual void on_unload();
120 
125  virtual void initialize_logging();
126 
131  virtual std::vector<AbstractExtensionInterface*> get_extensions() const;
132 
137  template<typename T>
139  {
140  for (AbstractExtensionInterface* aeif : get_extensions())
141  {
142  T* retval = dynamic_cast<T*>(aeif);
143  if (retval)
144  return retval;
145  }
146  return nullptr;
147  }
148 
153  void delete_extension(AbstractExtensionInterface* aeif);
154  };
155 
156  using instantiate_plugin_function = std::unique_ptr<BasePluginInterface> (*)();
157 } // namespace hal
#define PLUGIN_API
Definition: arch_linux.h:32
#define CORE_API
Definition: arch_linux.h:28
void log(const Args &... args) const
virtual std::string get_name() const =0
std::vector< AbstractExtensionInterface * > m_extensions
virtual std::string get_version() const =0
#define log_info(channel,...)
Definition: log.h:70
void initialize()
Definition: event_log.cpp:302
std::unique_ptr< BasePluginInterface > create_plugin_instance()
Definition: plugin_gui.cpp:71
std::unique_ptr< BasePluginInterface >(*)() instantiate_plugin_function