forked from halfgaar/FlashMQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginloader.h
55 lines (43 loc) · 1.51 KB
/
pluginloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
This file is part of FlashMQ (https://www.flashmq.org)
Copyright (C) 2021-2023 Wiebe Cazemier
FlashMQ is free software: you can redistribute it and/or modify
it under the terms of The Open Software License 3.0 (OSL-3.0).
See LICENSE for license details.
*/
#ifndef PLUGINLOADER_H
#define PLUGINLOADER_H
#include <dlfcn.h>
#include <string>
#include <unistd.h>
#include <unordered_map>
enum class PluginFamily
{
None,
Determining,
FlashMQ,
MosquittoV2,
};
typedef int (*F_plugin_version)(void);
typedef void(*F_flashmq_plugin_main_init_v1)(std::unordered_map<std::string, std::string> &auth_opts);
typedef void(*F_flashmq_plugin_main_deinit_v1)(std::unordered_map<std::string, std::string> &auth_opts);
class PluginLoader
{
PluginFamily pluginFamily = PluginFamily::None;
int flashmqPluginVersionNumber = 0;
void* handle = nullptr;
F_plugin_version version = nullptr;
F_flashmq_plugin_main_init_v1 main_init_v1 = nullptr;
F_flashmq_plugin_main_deinit_v1 main_deinit_v1 = nullptr;
public:
PluginLoader();
PluginLoader(const PluginLoader &other) = delete;
bool loaded() const;
void loadPlugin(const std::string &pathToSoFile);
void *loadSymbol(const char *symbol, bool exceptionOnError = true) const;
PluginFamily getPluginFamily() const;
int getFlashMQPluginVersion() const;
void mainInit(std::unordered_map<std::string, std::string> &plugin_opts);
void mainDeinit(std::unordered_map<std::string, std::string> &plugin_opts);
};
#endif // PLUGINLOADER_H