VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
bag_reader_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 bag_reader_plugin_interface.h
26 * @brief Plugin interface for custom bag reader URL/type transformation and message processing.
27 *
28 * @details
29 * @c BagReaderPluginInterface is loaded dynamically via the @c Plugin system and bound to a
30 * @c BagReader instance with @c BagReader::bind_plugin_interface(). It allows a plugin to:
31 *
32 * 1. **Remap URLs and serialisation types** -- @c convert_url_meta() is called for every URL
33 * found in the bag, enabling renaming or type overriding before playback begins.
34 * 2. **Intercept messages** -- @c push() receives every replayed message, allowing the plugin
35 * to transform, filter, or republish them before forwarding via @c output_callback_.
36 *
37 * @par Example plugin implementation
38 * @code
39 * class MyPlugin : public vlink::BagReaderPluginInterface {
40 * public:
41 * VersionInfo get_version_info() const override { return {"MyPlugin", "1.0.0", ...}; }
42 *
43 * bool convert_url_meta(std::string& url, std::string& ser_type, vlink::SchemaType& schema_type) override {
44 * // Optionally remap url / ser_type / schema_type here
45 * return true;
46 * }
47 *
48 * void push(int64_t ts, const std::string& url,
49 * vlink::ActionType action, const vlink::Bytes& data) override {
50 * if (output_callback_) output_callback_(ts, url, action, data);
51 * }
52 * };
53 * VLINK_PLUGIN_DECLARE(MyPlugin)
54 * @endcode
55 */
56
57#pragma once
58
59#include <cstdint>
60#include <functional>
61#include <string>
62#include <utility>
63
64#include "../base/plugin.h"
65#include "../impl/types.h"
66
67namespace vlink {
68
69/**
70 * @class BagReaderPluginInterface
71 * @brief Abstract plugin interface for custom bag reading, URL conversion, and message relay.
72 *
73 * @details
74 * Loaded as a dynamic plugin via @c Plugin::load<BagReaderPluginInterface>().
75 * Bind to a reader with @c BagReader::bind_plugin_interface().
76 */
79
80 protected:
82
83 virtual ~BagReaderPluginInterface() = default;
84
85 public:
86 /**
87 * @struct VersionInfo
88 * @brief Plugin version and build metadata returned by @c get_version_info().
89 */
90 struct VersionInfo final {
91 std::string name; ///< Plugin display name.
92 std::string version; ///< Semantic version string.
93 std::string timestamp; ///< Build timestamp.
94 std::string tag; ///< Source control tag.
95 std::string commit_id; ///< Source control commit hash.
96 };
97
98 /**
99 * @brief Callback type used to forward processed messages to the @c BagReader output.
100 *
101 * @details
102 * Stored in @c output_callback_. Call this inside @c push() to forward a message.
103 */
105 std::function<void(int64_t timestamp, const std::string& url, ActionType action_type, const Bytes& data)>;
106
107 /**
108 * @brief Returns version and build metadata for this plugin.
109 *
110 * @return @c VersionInfo struct with name, version, timestamp, tag, and commit ID.
111 */
112 [[nodiscard]] virtual VersionInfo get_version_info() const = 0;
113
114 /**
115 * @brief Registers the output callback used to forward messages after processing.
116 *
117 * @details
118 * Called by @c BagReader::bind_plugin_interface() to inject its output pipeline.
119 * The plugin must call @p output_callback_ from @c push() to deliver messages.
120 *
121 * @param output_callback Callback to store in @c output_callback_.
122 */
123 void register_output_callback(OutputCallback&& output_callback);
124
125 /**
126 * @brief Called for each URL in the bag to allow remapping of address, serialisation type, and schema family.
127 *
128 * @details
129 * Implementations may modify @p url, @p ser_type, and/or @p schema_type in-place.
130 * Return @c true to accept the URL; return @c false to exclude it from playback.
131 *
132 * @param url URL string from the bag index (may be modified).
133 * @param ser_type Serialisation type string (may be modified).
134 * @param schema_type Coarse schema family (may be modified).
135 * @return @c true to include this URL in playback; @c false to exclude it.
136 */
137 virtual bool convert_url_meta(std::string& url, std::string& ser_type, SchemaType& schema_type) = 0;
138
139 /**
140 * @brief Called for each replayed message, allowing interception and transformation.
141 *
142 * @details
143 * Implementations should process the message and call @c output_callback_ to forward it.
144 * Dropping or delaying messages is permitted.
145 *
146 * @param timestamp Message timestamp in microseconds.
147 * @param url Topic URL string.
148 * @param action_type Action type.
149 * @param data Serialized payload bytes.
150 */
151 virtual void push(int64_t timestamp, const std::string& url, ActionType action_type, const Bytes& data) = 0;
152
153 protected:
155
156 private:
158};
159
160////////////////////////////////////////////////////////////////
161/// Details
162////////////////////////////////////////////////////////////////
163
165 output_callback_ = std::move(output_callback);
166}
167
168} // namespace vlink
#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
Core type definitions shared across all VLink node implementations.