forked from CESNET/ipfixprobe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pluginmgr.hpp
79 lines (69 loc) · 1.96 KB
/
pluginmgr.hpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* \file pluginmgr.hpp
* \brief Plugin manager factory
* \author Jiri Havranek <[email protected]>
* \date 2021
*/
/*
* Copyright (C) 2021 CESNET
*
* LICENSE TERMS
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Company nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
*
*
*/
#ifndef IPXP_PLUGIN_MANAGER_HPP
#define IPXP_PLUGIN_MANAGER_HPP
#include <exception>
#include <functional>
#include <map>
#include <string>
#include <vector>
#include <ipfixprobe/plugin.hpp>
namespace ipxp {
class PluginManagerError : public std::runtime_error {
public:
explicit PluginManagerError(const std::string& msg)
: std::runtime_error(msg)
{
}
explicit PluginManagerError(const char* msg)
: std::runtime_error(msg)
{
}
};
// TODO: should be singleton
class PluginManager {
public:
PluginManager();
~PluginManager();
void register_plugin(const std::string& name, PluginGetter g);
Plugin* get(const std::string& name);
std::vector<Plugin*> get() const;
Plugin* load(const std::string& name);
private:
struct LoadedPlugin {
void* m_handle;
std::string m_file;
};
std::map<std::string, PluginGetter> m_getters;
std::vector<LoadedPlugin> m_loaded_so;
PluginRecord* m_last_rec;
void unload();
void register_loaded_plugins();
};
} // namespace ipxp
#endif /* IPXP_PLUGIN_MANAGER_HPP */