|
VLink
2.0.0
A high-performance communication middleware
|
Concrete MCAP-format BagWriter implementation with optional Zstd compression.
更多...
#include <vcap_writer.h>
Public 成员函数 | |
| VCAPWriter (const std::string &path, const Config &config={}) | |
| Opens or creates an MCAP file for recording. 更多... | |
| ~VCAPWriter () override | |
| Finalises the MCAP footer and flushes outstanding writes. 更多... | |
| void | register_split_callback (SplitCallback &&callback, bool before) override |
| Registers a callback invoked at each file-split boundary. 更多... | |
| void | register_schema_callback (SchemaCallback &&callback) override |
Registers a resolver that maps a serialisation-type string to SchemaData. 更多... | |
| bool | push_schema (const SchemaData &schema_data, bool immediate=false) override |
Embeds schema_data in the MCAP file for offline introspection. 更多... | |
| bool | is_dumping () const override |
| Returns the current value of the internal dumping flag. 更多... | |
| bool | is_split_mode () const override |
| Reports whether split-file recording is active. 更多... | |
| int | get_split_index () const override |
| Returns the index of the split part currently being written. 更多... | |
Public 成员函数 继承自 vlink::BagWriter | |
| BagWriter (const std::string &path, const Config &config={}) | |
| Constructs the base writer and opens the output file. 更多... | |
| virtual | ~BagWriter () |
| Halts the loop, flushes pending writes and closes the file. 更多... | |
| virtual void | bind_plugin_interface (const std::shared_ptr< BagPluginInterface > &plugin_interface) |
| Attaches a custom frame-forwarding plugin to this writer. 更多... | |
| virtual void | clear_plugin_interface () |
| Detaches the currently bound plugin, if any. 更多... | |
| int64_t | push (const Frame &frame, bool immediate=false) |
| Records a single frame to the bag. 更多... | |
| BagWriter & | operator<< (const Frame &frame) |
Streaming shorthand for push(frame). 更多... | |
| BagWriter & | operator<< (const SchemaData &schema_data) |
Streaming shorthand for push_schema(schema_data). 更多... | |
| bool | fail () const noexcept |
Returns whether a previous operator<< observed a write failure. 更多... | |
| operator bool () const noexcept | |
| Reports whether the streaming write state is still good (no latched failure). 更多... | |
| void | clear () noexcept |
Clears a latched fail() state so streaming writes can resume being observed. 更多... | |
| virtual void | set_url_loss (const std::string &url, double loss) |
Records the expected loss ratio for url as bag metadata. 更多... | |
Public 成员函数 继承自 vlink::MessageLoop | |
| MessageLoop () | |
Constructs a loop with the default kNormalType queue. 更多... | |
| MessageLoop (Type type) | |
| Constructs a loop with the given queue type. 更多... | |
| virtual | ~MessageLoop () |
| Destructor; requests quit and joins the dispatcher thread if needed. 更多... | |
| void | set_name (const std::string &name) |
| Sets a human-readable name visible to profiling tools. 更多... | |
| const std::string & | get_name () const |
Returns the loop name set via set_name. 更多... | |
| Type | get_type () const |
| Returns the queue type this loop was constructed with. 更多... | |
| Strategy | get_strategy () const |
| Returns the active back-pressure strategy. 更多... | |
| void | set_strategy (Strategy strategy) |
| Replaces the back-pressure strategy. 更多... | |
| void | register_begin_handler (Callback &&callback) |
| Registers a callback fired once at loop thread startup. 更多... | |
| void | register_end_handler (Callback &&callback) |
| Registers a callback fired once when the loop thread exits. 更多... | |
| void | register_idle_handler (Callback &&callback) |
| Registers a callback fired every time the queue becomes empty. 更多... | |
| bool | run () |
Runs the loop on the calling thread until quit is requested. 更多... | |
| bool | async_run () |
| Starts the loop on a new background thread. 更多... | |
| bool | spin () |
Alias of run blocking the calling thread. 更多... | |
| bool | spin_once (bool block=true) |
| Processes one batch of pending tasks and timers on the calling thread. 更多... | |
| bool | quit (bool force=false) |
| Requests the loop to exit. 更多... | |
| bool | wait_for_quit (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has fully exited. 更多... | |
| bool | post_task (Callback &&callback) |
| Posts a task for execution on the loop thread. 更多... | |
| TaskHandle | post_task_handle (Callback &&callback, const PostTaskOptions &options={}) |
Tracked variant of post_task returning a TaskHandle. 更多... | |
| bool | post_task_with_priority (Callback &&callback, uint16_t priority) |
Posts a task with an explicit priority on a kPriorityType loop. 更多... | |
| TaskHandle | post_task_with_priority_handle (Callback &&callback, uint16_t priority, const PostTaskOptions &options={}) |
Tracked variant of post_task_with_priority returning a TaskHandle. 更多... | |
| template<typename CallbackT , typename = std::enable_if_t<!std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::Status | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a void-returning callable and returns a chainable Schedule::Status. 更多... | |
| template<typename CallbackT , typename = std::enable_if_t<std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::RetStatus | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a bool-returning callable and returns a chainable Schedule::RetStatus. 更多... | |
| bool | wakeup () |
| Wakes the loop thread if it is suspended in its idle wait. 更多... | |
| void | reset_lockfree_capacity () |
| Recreates the lock-free queue, clearing all queued tasks and counters. 更多... | |
| bool | is_running () const |
| Reports whether the loop is currently running. 更多... | |
| bool | is_ready_to_quit () const |
Reports whether quit has been requested and the loop is winding down. 更多... | |
| bool | is_busy () const |
| Reports whether the loop is currently executing a task. 更多... | |
| size_t | get_task_count () const |
| Returns the current pending task count. 更多... | |
| virtual bool | wait_for_idle (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has drained its queue and is not executing a task. 更多... | |
| virtual size_t | get_max_timer_count () const |
| Returns the maximum number of timers that can be attached. 更多... | |
| virtual uint32_t | get_max_elapsed_time () const |
| Returns the maximum allowed task execution time in milliseconds. 更多... | |
| virtual bool | is_in_same_thread () const |
| Reports whether the calling thread is owned by this loop. 更多... | |
| std::shared_ptr< AliveState > | get_alive_state () const |
| Returns the shared lifetime flag used by cross-thread bridges. 更多... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task (FunctionT &&function, ArgsT &&... args) |
Dispatches a callable to the loop thread and returns a std::future for the result. 更多... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task_with_priority (FunctionT &&function, uint16_t priority, ArgsT &&... args) |
Priority variant of invoke_task; requires a kPriorityType loop. 更多... | |
Protected 成员函数 | |
| int64_t | record (const Frame &frame, bool immediate) override |
| int64_t | get_record_timestamp () const override |
| size_t | get_max_task_count () const override |
| Returns the maximum queue depth. 更多... | |
| void | on_begin () override |
| Hook invoked once on the loop thread before the first task runs. 更多... | |
| void | on_end () override |
| Hook invoked once on the loop thread after the last task runs. 更多... | |
Protected 成员函数 继承自 vlink::BagWriter | |
| std::string | convert_recorded_url (const std::string &url) const |
| std::vector< std::string > | recorded_urls_for_origin (const std::string &url) const |
| std::string | recover_recorded_url (const std::string &url) const |
| void | get_url_meta (const std::string &url, const std::string &ser, int &url_index, int &ser_index) const |
| void | get_url_meta (int url_index, int ser_index, std::string &url, std::string &ser) const |
| std::mutex & | sample_mutex () |
| std::unordered_map< std::string, double > & | url_loss_map_ref () |
| std::unordered_map< std::string, double > & | total_url_loss_map_ref () |
| void | flush_plugin () |
| void | detach_plugin () |
Protected 成员函数 继承自 vlink::MessageLoop | |
| virtual void | on_idle () |
| Hook invoked on the loop thread each time the queue becomes empty. 更多... | |
| virtual void | on_task_changed (Callback &&callback, uint32_t start_time) |
| Dispatches a ready task on the loop thread. 更多... | |
| virtual void | on_task_timeout (Callback &&callback, uint32_t elapsed_time) |
Hook invoked when a task exceeds get_max_elapsed_time(). 更多... | |
额外继承的成员函数 | |
Public 类型 继承自 vlink::BagWriter | |
| enum | CompressType : uint8_t { kCompressNone = 0 , kCompressAuto = 1 , kCompressZstd = 2 , kCompressLz4 = 3 , kCompressLzav = 4 } |
| Compression codec selector understood by the writer backends. 更多... | |
| using | SplitCallback = MoveFunction< void(int split_index, const std::string &split_filename)> |
| Notification fired when the writer rotates to a new split file. 更多... | |
| using | SchemaCallback = MoveFunction< SchemaData(const std::string &ser_type, SchemaType schema_type)> |
| Schema resolver used by the writer when a previously unseen URL is recorded. 更多... | |
| using | SystemClock = std::chrono::time_point< std::chrono::system_clock, std::chrono::milliseconds > |
| System clock alias used when formatting timestamps into split file names. 更多... | |
Public 类型 继承自 vlink::MessageLoop | |
| enum | Type : uint8_t { kNormalType = 0 , kLockfreeType = 1 , kPriorityType = 2 } |
| Internal queue implementation type. 更多... | |
| enum | Strategy : uint8_t { kOptimizationStrategy = 0 , kPopStrategy = 1 , kBlockStrategy = 2 } |
| Back-pressure strategy applied when the bounded queue is at capacity. 更多... | |
| enum | Priority : uint16_t { kNoPriority = 0 , kLowestPriority = 1 , kTimerPriority = 50 , kNormalPriority = 100 , kHighestPriority = std::numeric_limits<uint16_t>::max() } |
Built-in priority levels for kPriorityType loops; higher values dispatch first. 更多... | |
| using | Callback = MoveFunction< void()> |
| Callback type for tasks and event handlers. 更多... | |
静态 Public 成员函数 继承自 vlink::BagWriter | |
| static std::shared_ptr< BagWriter > | create (const std::string &path, const Config &config={}) |
Builds the concrete writer matching the extension of path. 更多... | |
| static std::shared_ptr< BagWriter > | filter_get (const std::string &path) |
Returns the cached writer for path, lazily creating and starting one. 更多... | |
| static BagWriter * | global_get () |
Returns the singleton writer driven by the VLINK_BAG_PATH environment variable. 更多... | |
静态 Protected 成员函数 继承自 vlink::BagWriter | |
| static const std::string & | get_default_tag_name () |
| static const std::string & | get_default_app_name () |
| static SchemaPluginInterface * | get_schema_interface () |
| static int32_t | get_default_timezone_diff () |
| static std::string_view | convert_action (ActionType type) |
| static std::string | get_format_date (SystemClock *current=nullptr, bool file_format=false) |
Concrete MCAP-format BagWriter implementation with optional Zstd compression.
Prefer BagWriter::create() for format-agnostic instantiation; instantiate this class directly when an MCAP-specific feature is required.
|
explicit |
Opens or creates an MCAP file for recording.
| path | Filesystem path of the .vcap or .vcapx target. |
| config | Recording configuration (split policy, compression, etc.). |
|
override |
Finalises the MCAP footer and flushes outstanding writes.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
实现了 vlink::BagWriter.
|
overridevirtual |
Returns the index of the split part currently being written.
实现了 vlink::BagWriter.
|
overridevirtual |
Returns the current value of the internal dumping flag.
true while messages are actively being persisted. 实现了 vlink::BagWriter.
|
overridevirtual |
Reports whether split-file recording is active.
true when emitting a .vcapx manifest with multiple parts. 实现了 vlink::BagWriter.
|
overrideprotectedvirtual |
Hook invoked once on the loop thread before the first task runs.
Subclasses override to perform per-thread initialisation.
重载 vlink::MessageLoop .
|
overrideprotectedvirtual |
Hook invoked once on the loop thread after the last task runs.
Subclasses override to perform per-thread cleanup.
重载 vlink::MessageLoop .
|
overridevirtual |
Embeds schema_data in the MCAP file for offline introspection.
| schema_data | Schema descriptor to embed. |
| immediate | true merges synchronously; false enqueues the write. |
false only when an immediate merge failed. 实现了 vlink::BagWriter.
|
overrideprotectedvirtual |
实现了 vlink::BagWriter.
|
overridevirtual |
Registers a resolver that maps a serialisation-type string to SchemaData.
| callback | Function consulted before writing a channel record. |
实现了 vlink::BagWriter.
|
overridevirtual |
Registers a callback invoked at each file-split boundary.
| callback | Receives (split_index, filename) before or after the split. |
| before | true fires before the new file is opened; false fires after. |
实现了 vlink::BagWriter.