VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
runnable_plugin_interface.h
浏览该文件的文档.
1/*
2 * Copyright (C) 2026 by Thun Lu. All rights reserved.
3 * Author: Thun Lu <thun.lu@zohomail.cn>
4 * Repo: https://github.com/thun-res/vlink
5 * _ __ __ _ __
6 * | | / / / / (_) ____ / /__
7 * | | / / / / / / / __ \ / //_/
8 * | |/ / / /___ / / / / / / / ,<
9 * |___/ /_____/ /_/ /_/ /_/ /_/|_|
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 */
23
24/**
25 * @file runnable_plugin_interface.h
26 * @brief Plugin interface for self-contained, event-loop-driven plugin components.
27 *
28 * @details
29 * @c RunablePluginInterface (note: intentional spelling) combines a @c MessageLoop
30 * with the @c Plugin system to allow dynamic plugins to carry their own event loop.
31 *
32 * A plugin that inherits this interface runs in its own @c MessageLoop thread, started by
33 * @c async_run() after loading. The host calls @c on_init() to initialise the plugin and
34 * @c on_deinit() to clean up before unloading.
35 *
36 * @par Plugin implementation example
37 * @code
38 * class MyPlugin : public vlink::RunablePluginInterface {
39 * public:
40 * void on_init() override {
41 * // set up subscriptions, timers, etc.
42 * }
43 * void on_deinit() override {
44 * // stop timers, unsubscribe
45 * }
46 * };
47 * VLINK_PLUGIN_DECLARE(MyPlugin)
48 * @endcode
49 *
50 * @par Host usage
51 * @code
52 * vlink::Plugin plugin;
53 * auto instance = plugin.load<vlink::RunablePluginInterface>("my_plugin.so");
54 * instance->async_run();
55 * instance->on_init();
56 * // ... run ...
57 * instance->on_deinit();
58 * @endcode
59 */
60
61#pragma once
62
64#include "../base/plugin.h"
65
66namespace vlink {
67
68/**
69 * @class RunablePluginInterface
70 * @brief Abstract plugin interface that provides its own @c MessageLoop event thread.
71 *
72 * @details
73 * The plugin owns a @c MessageLoop and implements @c on_init() / @c on_deinit() for
74 * lifecycle management. The host is responsible for calling @c async_run() after loading.
75 */
78
79 protected:
81
82 ~RunablePluginInterface() override = default;
83
84 public:
85 /**
86 * @brief Called by the host after the plugin's event loop has started.
87 *
88 * @details
89 * Implement this method to create subscribers, timers, and other resources that
90 * require the loop to be running. This method is called on the caller's thread.
91 */
92 virtual void on_init() = 0;
93
94 /**
95 * @brief Called by the host before the plugin is unloaded.
96 *
97 * @details
98 * Implement this method to release all resources, cancel timers, and unsubscribe.
99 * After this call, the host will stop the event loop and unload the plugin.
100 */
101 virtual void on_deinit() = 0;
102
103 private:
105};
106
107} // namespace vlink
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
定义 macros.h:184
Single-threaded event loop with three queue types, timer management and task scheduling.
Type-safe dynamic plugin loader with version checking and lifecycle management.
#define VLINK_PLUGIN_REGISTER(InterfaceType)
Macro to register a plugin, automatically deriving its ID from the interface type name.
定义 plugin.h:343