VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
conf_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 conf_plugin_interface.h
26 * @brief Plugin ABI for dynamically loaded transport @c Conf factories.
27 *
28 * @details
29 * @c ConfPluginInterface is the abstract C++ interface that every externally loaded
30 * VLink transport plugin must implement. Plugins are shared libraries discovered at
31 * runtime via the @c VLINK_URL_PLUGINS environment variable (or the
32 * @c Url::init_plugins() call).
33 *
34 * @par Plugin Discovery and Loading
35 * When a @c Url is constructed and the built-in transport table does not recognise the
36 * transport field in the URL, @c Url::load_for_plugin() iterates over all loaded plugins and calls
37 * @c get_transport_type() on each to find a matching transport. If found,
38 * @c create() is called to obtain a fresh @c Conf instance for that transport.
39 *
40 * @par Implementing a Plugin
41 * @code
42 * // In your plugin shared library:
43 * struct MyTransportPlugin final : public vlink::ConfPluginInterface {
44 * vlink::TransportType get_transport_type() const override {
45 * return vlink::TransportType::kMyCustomTransport;
46 * }
47 * std::unique_ptr<vlink::Conf> create() const override {
48 * return std::make_unique<MyTransportConf>();
49 * }
50 * };
51 * VLINK_PLUGIN_EXPORT(MyTransportPlugin)
52 * @endcode
53 *
54 * @note The @c VLINK_PLUGIN_EXPORT macro (from @c base/plugin.h) injects the
55 * symbol needed for the plugin loader to locate and instantiate this type.
56 *
57 * @note Implementations must be stateless; @c create() may be called multiple times
58 * to produce independent @c Conf objects for different @c Url instances.
59 */
60
61#pragma once
62
63#include <memory>
64
65#include "../base/plugin.h"
66#include "./conf.h"
67
68namespace vlink {
69
70/**
71 * @struct ConfPluginInterface
72 * @brief Pure-virtual plugin interface for external transport @c Conf factories.
73 *
74 * @details
75 * Each VLink transport plugin exports exactly one concrete subclass of this
76 * interface. The VLink runtime loads the plugin shared library, locates the
77 * registered instance via @c VLINK_PLUGIN_REGISTER, and queries it for the
78 * supported transport backend and new @c Conf objects.
79 */
82
83 protected:
85
86 virtual ~ConfPluginInterface() = default;
87
88 public:
89 /**
90 * @brief Returns the transport backend handled by this plugin.
91 *
92 * @details
93 * Called by @c Url::load_for_plugin() to determine whether this plugin supports
94 * the transport of the URL being constructed.
95 *
96 * @return The @c TransportType enumeration value identifying the transport backend.
97 */
98 [[nodiscard]] virtual TransportType get_transport_type() const = 0;
99
100 /**
101 * @brief Creates and returns a new transport @c Conf instance.
102 *
103 * @details
104 * Called once per @c Url construction that matches this plugin's transport. The
105 * returned object must be fully initialised and ready for @c parse() calls.
106 * Ownership is transferred to the caller via @c unique_ptr.
107 *
108 * @return A heap-allocated @c Conf subclass specific to this transport.
109 */
110 [[nodiscard]] virtual std::unique_ptr<Conf> create() const = 0;
111
112 private:
114};
115
116} // namespace vlink
Abstract transport configuration base class and associated helper macros.
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
定义 macros.h:184
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