mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Reworking plugin interface to not rely on macros.
The Plugin.cc file is now just a standard class, with the interface changed a bit to make it more easy to write. However, there're still some conventions that one must follow to make everything work (like using the right namespace structure). This commit also includes the option to compile built-in plugins dynamically instead of statically by adding SET(BRO_PLUGIN_BUILD_DYNAMIC TRUE) to their CMake config. This hasn't been tested much yet, and I'm still undecided if it's somethign we would want to do by default--but we could now if wanted. :) Also some minor other cleanup of plugin APIs and built infrastructure. All tested on MacOS only currently.
This commit is contained in:
parent
9227a57935
commit
ea01a1be30
21 changed files with 273 additions and 333 deletions
|
@ -20,12 +20,14 @@ namespace plugin {
|
|||
#define PLUGIN_HOOK_VOID(hook, method_call) \
|
||||
if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call;
|
||||
|
||||
|
||||
/**
|
||||
* A singleton object managing all plugins.
|
||||
*/
|
||||
class Manager
|
||||
{
|
||||
public:
|
||||
typedef void (*bif_init_func)(Plugin *);
|
||||
typedef std::list<Plugin*> plugin_list;
|
||||
typedef Plugin::component_list component_list;
|
||||
|
||||
|
@ -218,7 +220,12 @@ public:
|
|||
* ownership, yet assumes the pointer will stay valid at least until
|
||||
* the Manager is destroyed.
|
||||
*/
|
||||
static bool RegisterPlugin(Plugin* plugin);
|
||||
static void RegisterPlugin(Plugin* plugin);
|
||||
|
||||
/**
|
||||
* Internal method that registers a bif file's init function for a plugin.
|
||||
*/
|
||||
static void RegisterBifFile(const char* plugin, bif_init_func c);
|
||||
|
||||
private:
|
||||
bool ActivateDynamicPluginInternal(const std::string& name);
|
||||
|
@ -251,6 +258,14 @@ private:
|
|||
// This is a static method so that plugins can register themselves
|
||||
// even before the manager exists.
|
||||
static plugin_list* PluginsInternal();
|
||||
|
||||
typedef std::list<bif_init_func> bif_init_func_list;
|
||||
typedef std::map<std::string, bif_init_func_list*> bif_init_func_map;
|
||||
|
||||
// Returns a modifiable map of all bif files. This is a static method
|
||||
// so that plugins can register their bifs even before the manager
|
||||
// exists.
|
||||
static bif_init_func_map* BifFilesInternal();
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
@ -274,6 +289,17 @@ std::list<T *> Manager::Components() const
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal class used by bifcl-generated code to register its init functions at runtime.
|
||||
*/
|
||||
class __RegisterBif {
|
||||
public:
|
||||
__RegisterBif(const char* plugin, Manager::bif_init_func init)
|
||||
{
|
||||
Manager::RegisterBifFile(plugin, init);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue