VLink  2.1.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 Stable ABI implemented by transport plugins that ship a @c Conf factory.
27  *
28  * @details
29  * This is an internal implementation header used by the URL routing layer and by
30  * out-of-tree plugins for recognized transport backends; it is not part of the
31  * public application API. External plugins are shared libraries made available
32  * according to the process-wide @c VLINK_URL_PLUGINS value: an explicit module
33  * list is preloaded, while a complete value of @c auto (case-insensitive) enables
34  * first-use loading of the fixed library for a recognized transport. An empty
35  * value or the case-insensitive value @c none disables plugin loading. Each
36  * plugin exports exactly one concrete subclass of @c ConfPluginInterface; the
37  * runtime asks it for its existing @c TransportType and uses @c create() to
38  * obtain a fresh @c Conf instance when a URL with that transport is constructed.
39  * The complete setting is sampled once when the process-wide plugin manager is
40  * initialized.
41  *
42  * @par Plugin contract
43  * | Member | Required | Description |
44  * | ------------------------------- | ----------------- | ------------------------------------------------- |
45  * | @c VLINK_PLUGIN_REGISTER(iface) | Yes | Tags the interface with a stable plugin id. |
46  * | @c VLINK_PLUGIN_DECLARE(...) | Yes (in @c .cc) | Exports the create / destroy plugin entry points. |
47  * | @c get_transport_type() const | Override | Reports the @c TransportType the plugin handles. |
48  * | @c create() const | Override | Allocates a new transport @c Conf instance. |
49  *
50  * @par Lifecycle
51  * @code
52  * first Url/plugin use -> sample VLINK_URL_PLUGINS
53  * | | |
54  * | list | auto | empty / none
55  * v v v
56  * explicit first-use load disabled
57  * preload vlink-<module>
58  * | |
59  * +-----> validate type -> registry -> plugin->create()
60  * |
61  * v
62  * unique_ptr<Conf>
63  * @endcode
64  *
65  * @par Loading constraints
66  * In list mode, @c VLINK_URL_PLUGINS accepts recognized transport module names,
67  * not arbitrary plugin names. For example, @c zenoh maps to the fixed library
68  * base name @c vlink-zenoh and to the existing @c TransportType::kZenoh. The
69  * on-demand path derives the same fixed name and is enabled only when the entire
70  * sampled value equals @c auto, ignoring case. Mode values cannot be combined
71  * with an explicit list. Unknown module names are rejected before
72  * @c Plugin::load() is called, linked transports take precedence over plugins,
73  * and @c TransportType::kUnknown is never dispatched to this interface. New URL
74  * schemes therefore require core enum, URL mapping, and backend creation support
75  * before this interface can be used.
76  *
77  * @note Implementations must remain stateless because @c create() may be invoked
78  * repeatedly to serve several independent @c Url instances.
79  */
80 
81 #pragma once
82 
83 #include <memory>
84 
85 #include "../base/plugin.h"
86 #include "./conf.h"
87 
88 namespace vlink {
89 
90 /**
91  * @struct ConfPluginInterface
92  * @brief Stateless factory contract that external recognized-transport plugins must implement.
93  *
94  * @details
95  * Subclasses may be explicitly preloaded from a module list in
96  * @c VLINK_URL_PLUGINS or loaded on first use of a recognized, unlinked transport
97  * when its complete value is @c auto (case-insensitive). The interface cannot
98  * register a new @c TransportType or URL scheme; it only supplies @c Conf
99  * instances for existing transport identifiers. It intentionally exposes only
100  * the two queries needed by @c Url::load_for_plugin(); plugin-specific state
101  * lives inside the @c Conf instances returned by @c create().
102  */
105 
106  protected:
107  ConfPluginInterface() = default;
108 
109  virtual ~ConfPluginInterface() = default;
110 
111  public:
112  /**
113  * @brief Reports the transport identifier this plugin can produce confs for.
114  *
115  * @details
116  * Called by @c Url::load_for_plugin() to match URL transports to loaded
117  * plugins. The same identifier may be returned by at most one plugin.
118  *
119  * @return @c TransportType value covered by this plugin.
120  */
121  [[nodiscard]] virtual TransportType get_transport_type() const = 0;
122 
123  /**
124  * @brief Allocates a fresh transport @c Conf instance.
125  *
126  * @details
127  * Invoked once per @c Url constructor whose transport matches the plugin.
128  * The returned object must be ready to receive @c parse() calls immediately.
129  *
130  * @return Heap-allocated transport @c Conf owned by the caller.
131  */
132  [[nodiscard]] virtual std::unique_ptr<Conf> create() const = 0;
133 
134  private:
136 };
137 
138 } // namespace vlink
Transport-configuration base contract and the supporting boilerplate macros.
#define VLINK_DISALLOW_COPY_AND_ASSIGN(classname)
Deletes the copy constructor and copy-assignment operator of classname.
Definition: macros.h:174
#define VLINK_PLUGIN_REGISTER(InterfaceType)
Declares a plugin's identity from the demangled name of its abstract interface.
Definition: plugin.h:347