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 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 discovered by
32  * the URL layer when @c Url::init_plugins() reads @c VLINK_URL_PLUGINS. Each
33  * plugin exports exactly one concrete subclass of @c ConfPluginInterface; the
34  * runtime asks it for its existing @c TransportType and uses @c create() to
35  * obtain a fresh @c Conf instance when a URL with that transport is constructed.
36  *
37  * @par Plugin contract
38  * | Member | Required | Description |
39  * | ------------------------------- | ----------------- | ------------------------------------------------- |
40  * | @c VLINK_PLUGIN_REGISTER(iface) | Yes | Tags the interface with a stable plugin id. |
41  * | @c VLINK_PLUGIN_DECLARE(...) | Yes (in @c .cc) | Exports the create / destroy plugin entry points. |
42  * | @c get_transport_type() const | Override | Reports the @c TransportType the plugin handles. |
43  * | @c create() const | Override | Allocates a new transport @c Conf instance. |
44  *
45  * @par Lifecycle
46  * @code
47  * +-----------+ +--------------+ +-----------------+
48  * | Url::ctor | -------> | init_plugins | -------> | dlopen library |
49  * +-----------+ +------+-------+ +--------+--------+
50  * | |
51  * | v
52  * | +-----------------------+
53  * | | Plugin::create_object |
54  * | +-----------+-----------+
55  * | |
56  * v v
57  * +----------------+ +------------------+
58  * | load_for_plugin| -------> | plugin->create() |
59  * +----------------+ +--------+---------+
60  * |
61  * v
62  * +-------------+
63  * | unique<Conf>|
64  * +-------------+
65  * @endcode
66  *
67  * @par Loading constraints
68  * @c VLINK_URL_PLUGINS accepts recognized transport module names, not arbitrary
69  * plugin names. For example, @c zenoh maps to the fixed library base name
70  * @c vlink-zenoh and to the existing @c TransportType::kZenoh. Unknown module
71  * names are rejected before @c Plugin::load() is called, linked transports take
72  * precedence over plugins, and @c TransportType::kUnknown is never dispatched to
73  * this interface. New URL schemes therefore require core enum, URL mapping,
74  * and backend creation support before this plugin interface can be used.
75  *
76  * @note Implementations must remain stateless because @c create() may be invoked
77  * repeatedly to serve several independent @c Url instances.
78  */
79 
80 #pragma once
81 
82 #include <memory>
83 
84 #include "../base/plugin.h"
85 #include "./conf.h"
86 
87 namespace vlink {
88 
89 /**
90  * @struct ConfPluginInterface
91  * @brief Stateless factory contract that external recognized-transport plugins must implement.
92  *
93  * @details
94  * Subclasses are loaded from shared libraries by the VLink runtime when a URL
95  * uses a recognized transport that is not built in. The interface cannot
96  * register a new @c TransportType or URL scheme; it only supplies @c Conf
97  * instances for existing transport identifiers. It intentionally exposes only
98  * the two queries needed by @c Url::load_for_plugin(); plugin-specific state
99  * lives inside the @c Conf instances returned by @c create().
100  */
103 
104  protected:
105  ConfPluginInterface() = default;
106 
107  virtual ~ConfPluginInterface() = default;
108 
109  public:
110  /**
111  * @brief Reports the transport identifier this plugin can produce confs for.
112  *
113  * @details
114  * Called by @c Url::load_for_plugin() to match URL transports to loaded
115  * plugins. The same identifier may be returned by at most one plugin.
116  *
117  * @return @c TransportType value covered by this plugin.
118  */
119  [[nodiscard]] virtual TransportType get_transport_type() const = 0;
120 
121  /**
122  * @brief Allocates a fresh transport @c Conf instance.
123  *
124  * @details
125  * Invoked once per @c Url constructor whose transport matches the plugin.
126  * The returned object must be ready to receive @c parse() calls immediately.
127  *
128  * @return Heap-allocated transport @c Conf owned by the caller.
129  */
130  [[nodiscard]] virtual std::unique_ptr<Conf> create() const = 0;
131 
132  private:
134 };
135 
136 } // 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:345