VLink  2.0.0
A high-performance communication middleware
runnable_plugin_interface.h File Reference

Plugin contract for self-driving plugins that own a private MessageLoop thread. More...

Include dependency graph for runnable_plugin_interface.h:

Go to the source code of this file.

Classes

class  vlink::RunablePluginInterface
 Abstract plugin base that already owns a MessageLoop event thread. More...
 

Namespaces

 

Detailed Description

Plugin contract for self-driving plugins that own a private MessageLoop thread.

RunablePluginInterface (the spelling is intentional and preserved for backwards compatibility) blends MessageLoop with the VLink Plugin framework so a dynamic plugin can carry its own event loop and dispatch timers, subscribers and other asynchronous primitives without depending on the host's loop.

Plugin contract:

Hook When the host calls it Mandatory action
constructor At Plugin::load time Cheap construction; no thread-local work yet
async_run() After load, on the host's thread Inherited from MessageLoop; starts the loop
on_init() Right after async_run() succeeds Set up subscribers, timers and other live resources
on_deinit() Just before unload Tear down everything created in on_init()
destructor When the Plugin handle is released Final cleanup; loop has already been stopped

Plugin lifecycle:

*   Plugin::load(...)
*        |
*        v
*   constructor  -->  async_run()  -->  on_init()
*                                          |
*                                          v
*                                     plugin work (loop running)
*                                          |
*                                          v
*                                       on_deinit()
*                                          |
*                                          v
*                                      stop loop / unload
* 
Example
// Inside the plugin shared library:
class MyPlugin : public vlink::RunablePluginInterface {
public:
void on_init() override { ... } // create subscribers / timers
void on_deinit() override { ... } // release everything created above
};
VLINK_PLUGIN_DECLARE(MyPlugin, 1, 0)
// Inside the host process:
vlink::Plugin plugin;
auto instance = plugin.load<vlink::RunablePluginInterface>("my_plugin.so", 1, 0);
instance->async_run();
instance->on_init();
// ... let it run ...
instance->on_deinit();
#define VLINK_PLUGIN_DECLARE(ImplementType, VersionMajor, VersionMinor)
Emits the extern "C" construction and destruction entry points exported by a plugin module.
Definition: plugin.h:387