MaCh3  2.8.0
Reference Guide
Classes | Namespaces | Macros | Typedefs | Variables
plugin.hpp File Reference

Plugin interface and registration macros for MaCh3. More...

#include <cstdint>
#include <memory>
#include <type_traits>
#include "CLI/API/m3argparse.hpp"
Include dependency graph for plugin.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  M3::IPlugin
 Interface for MaCh3 plugins and modules. More...
 
class  M3::PluginBase
 Base class for core modules in MaCh3. More...
 

Namespaces

 M3
 Main namespace for MaCh3 software.
 

Macros

#define MACH3_REGISTER_PLUGIN(PluginClass)
 Macro to register a plugin class with MaCh3. More...
 

Typedefs

typedef IPlugin M3::IModule
 Alias for IPlugin, used for core modules. More...
 
typedef PluginBase M3::IModuleBase
 Alias for IPluginBase, used for core modules. More...
 
typedef std::uint32_t(* plugin_api_version_t) ()
 Function pointer type for the plugin API-version query. More...
 
typedef M3::IPlugin *(* create_plugin_t) ()
 Function pointer type for the plugin factory. More...
 
typedef void(* destroy_plugin_t) (M3::IPlugin *)
 Function pointer type for plugin destructor function. More...
 

Variables

constexpr std::uint32_t M3::PLUGIN_API_VERSION = 1
 Fix API compatibility: increment when the plugin/parser contract changes incompatibly. More...
 

Detailed Description

Plugin interface and registration macros for MaCh3.

Definition in file plugin.hpp.

Macro Definition Documentation

◆ MACH3_REGISTER_PLUGIN

#define MACH3_REGISTER_PLUGIN (   PluginClass)
Value:
static_assert(std::is_base_of<M3::IPlugin, PluginClass>::value, "PluginClass must derive from M3::IPlugin"); \
extern "C" __attribute__((visibility("default"))) std::uint32_t plugin_api_version() { \
} \
extern "C" __attribute__((visibility("default"))) M3::IPlugin* create_plugin() { \
return new PluginClass(); \
} \
extern "C" __attribute__((visibility("default"))) void destroy_plugin(M3::IPlugin* p) { \
delete p; \
}
Main namespace for MaCh3 software.
constexpr std::uint32_t PLUGIN_API_VERSION
Fix API compatibility: increment when the plugin/parser contract changes incompatibly.
Definition: plugin.hpp:12

Macro to register a plugin class with MaCh3.

This macro generates the required API-version, factory and destructor functions for a plugin class. Use it in your plugin implementation file.

Fix API compatibility: export the version and factories even with hidden default visibility. functions generated by MACH3_REGISTER_PLUGIN are now visible to code outside the plugin’s shared library. thanks to attribute((visibility("default"))) that matters when a plugin is built with hidden visibility by default, for example with -fvisibility=hidden.

Parameters
PluginClassThe plugin class that implements M3::IPlugin

Example usage:

class MyPlugin : public M3::IPlugin {
// ... implementation
};
Interface for MaCh3 plugins and modules.
Definition: plugin.hpp:19
#define MACH3_REGISTER_PLUGIN(PluginClass)
Macro to register a plugin class with MaCh3.
Definition: plugin.hpp:87

Definition at line 87 of file plugin.hpp.

Typedef Documentation

◆ create_plugin_t

typedef M3::IPlugin*(* create_plugin_t) ()

Function pointer type for the plugin factory.

Definition at line 60 of file plugin.hpp.

◆ destroy_plugin_t

destroy_plugin_t

Function pointer type for plugin destructor function.

Definition at line 64 of file plugin.hpp.

◆ plugin_api_version_t

typedef std::uint32_t(* plugin_api_version_t) ()

Function pointer type for the plugin API-version query.

Definition at line 57 of file plugin.hpp.