ImagingTools Core SDK
PluginInterface.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5#if defined _MSC_VER || defined __MINGW32__ || defined __MINGW64__
6 #define IMT_PLUGIN_FUNCTION_EXPORT __declspec(dllexport)
7#elif defined __GNUC__
8 #define IMT_PLUGIN_FUNCTION_EXPORT __attribute__ ((visibility("default")))
9#else
10 #define IMT_PLUGIN_FUNCTION_EXPORT
11#endif
12
13#define IMT_MAKE_STRING(value) #value
14
15#ifndef QT_NO_DEBUG
16 #define IMT_CREATE_PLUGIN_INSTANCE_FUNCTION(suffix) CreatePluginInstanceDebug##suffix
17 #define IMT_CREATE_PLUGIN_INSTANCE_FUNCTION_NAME(suffix) IMT_MAKE_STRING(CreatePluginInstanceDebug##suffix)
18#define IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION(suffix) DestroyPluginInstanceDebug##suffix
19 #define IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION_NAME(suffix) IMT_MAKE_STRING(DestroyPluginInstanceDebug##suffix)
20#else // !QT_NO_DEBUG
21 #define IMT_CREATE_PLUGIN_INSTANCE_FUNCTION(suffix) CreatePluginInstance##suffix
22 #define IMT_CREATE_PLUGIN_INSTANCE_FUNCTION_NAME(suffix) IMT_MAKE_STRING(CreatePluginInstance##suffix)
23 #define IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION(suffix) DestroyPluginInstance##suffix
24 #define IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION_NAME(suffix) IMT_MAKE_STRING(DestroyPluginInstance##suffix)
25#endif // !QT_NO_DEBUG
26
27
28#define IMT_CREATE_PLUGIN_FUNCTION(PluginType) CreatePluginInstanceFunction##PluginType
29#define IMT_DESTROY_PLUGIN_FUNCTION(PluginType) DestroyPluginInstanceFunction##PluginType
30
31#define IMT_CREATE_PLUGIN_FUNCTION_PTR(PluginType, PluginInterface)\
32PluginInterface* (*IMT_CREATE_PLUGIN_FUNCTION(PluginType))();
33
34#define IMT_DESTROY_PLUGIN_FUNCTION_PTR(PluginType, PluginInterface)\
35void (*IMT_DESTROY_PLUGIN_FUNCTION(PluginType))(PluginInterface*);\
36
37#define IMT_DECLARE_PLUGIN_INTERFACE(PluginType, PluginInterface)\
38typedef IMT_CREATE_PLUGIN_FUNCTION_PTR(PluginType, PluginInterface);\
39typedef IMT_DESTROY_PLUGIN_FUNCTION_PTR(PluginType, PluginInterface);\
40extern "C" IMT_PLUGIN_FUNCTION_EXPORT PluginInterface* IMT_CREATE_PLUGIN_INSTANCE_FUNCTION(PluginType)();\
41extern "C" IMT_PLUGIN_FUNCTION_EXPORT void IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION(PluginType)(PluginInterface* pluginInstancePtr);\
42
43
44#define IMT_REGISTER_PLUGIN(PluginInterface, PluginImplementation, PluginType, PluginName)\
45 IMT_DECLARE_PLUGIN_INTERFACE(PluginType, PluginInterface);\
46 PluginInterface* IMT_CREATE_PLUGIN_INSTANCE_FUNCTION(PluginType)()\
47 {\
48 return new PluginImplementation(#PluginName, #PluginType);\
49 }\
50 void IMT_DESTROY_PLUGIN_INSTANCE_FUNCTION(PluginType)(PluginInterface* pluginInstancePtr)\
51 {\
52 Q_ASSERT(pluginInstancePtr != nullptr);\
53 if (pluginInstancePtr != nullptr){\
54 delete pluginInstancePtr;\
55 };\
56 }\
57
58