VLink  2.0.0
A high-performance communication middleware
vlink::BagReader Class Referenceabstract

Format-agnostic VLink bag player driven by an internal MessageLoop. More...

#include <bag_reader.h>

Inheritance diagram for vlink::BagReader:
Collaboration diagram for vlink::BagReader:

Classes

struct  Config
 Playback parameters consumed by play(). More...
 
struct  Info
 Aggregated metadata extracted from the bag header, summary and URL index. More...
 

Public Types

enum  Status : uint8_t { kStopped = 0 , kPaused = 1 , kPlaying = 2 }
 Coarse playback state observable through get_status(). More...
 
using OutputCallback = FrameCallback
 Callback signature receiving one replayed Frame. More...
 
using StatusCallback = MoveFunction< void(Status status)>
 Callback fired on every transition of Status. More...
 
using ReadyCallback = MoveFunction< void()>
 Callback fired once after the bag has been opened and indexed. More...
 
using FinishCallback = MoveFunction< void(bool is_interrupted)>
 Callback fired when the current play session ends. More...
 
 Internal queue implementation type. More...
 Back-pressure strategy applied when the bounded queue is at capacity. More...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. More...

Public Member Functions

 BagReader (const std::string &path, bool read_only=true, bool try_to_fix=false)
 Constructs the base reader and stores construction-time options. More...
 
virtual ~BagReader ()
 Stops the loop, closes the file and releases backend resources. More...
 
virtual void bind_plugin_interface (const std::shared_ptr< BagPluginInterface > &plugin_interface)
 Attaches a custom URL/type/message rewrite plugin to this reader. More...
 
virtual void clear_plugin_interface ()
 Detaches the currently bound plugin, if any. More...
 
virtual void register_status_callback (StatusCallback &&status_callback)
 Installs a state-change observer. More...
 
virtual void register_ready_callback (ReadyCallback &&ready_callback)
 Installs the "open complete" observer. More...
 
virtual void register_finish_callback (FinishCallback &&finish_callback)
 Installs the "play session ended" observer. More...
 
virtual void register_output_callback (OutputCallback &&output_callback)
 Installs the per-frame data sink. More...
 
bool open_cursor (const Config &config)
 Opens (or rewinds) a synchronous sequential read cursor over the bag. More...
 
bool open_cursor ()
 Opens (or rewinds) a full, unfiltered sequential read cursor over the bag. More...
 
bool read_next (Frame &out)
 Reads the next frame in recorded order into out. More...
 
BagReaderoperator>> (Frame &out)
 Stream-style alias for read_next(), enabling while (reader >> frame). More...
 
bool eof () const noexcept
 Returns whether the cursor has reached the end of the bag. More...
 
bool fail () const noexcept
 Returns whether the last cursor operation failed (open or backend read error). More...
 
 operator bool () const noexcept
 Reports whether the cursor is still in a readable state (not at end, not failed). More...
 
virtual void play (const Config &config)=0
 Starts (or restarts) a play session with the supplied configuration. More...
 
virtual void stop ()=0
 Aborts the active session and rewinds to the start of the bag. More...
 
virtual void pause ()=0
 Suspends frame dispatch while preserving the current position. More...
 
virtual void resume ()=0
 Resumes dispatch from the paused position. More...
 
virtual void pause_to_next ()=0
 Emits exactly one frame from the paused position, then pauses again. More...
 
virtual void jump (int64_t begin_time, double rate, int times, bool force_to_play=false)=0
 Seeks playback to begin_time and applies updated rate and loop settings. More...
 
virtual std::future< bool > check ()=0
 Runs an asynchronous integrity verification pass. More...
 
virtual std::future< bool > reindex ()=0
 Rebuilds backend index tables in the background where supported. More...
 
virtual std::future< bool > fix (bool rebuild=false)=0
 Attempts to recover a corrupted bag in the background where supported. More...
 
virtual void tag (const std::string &tag_name)=0
 Overwrites the human-readable tag stored in the bag header. More...
 
virtual int64_t get_timestamp () const =0
 Returns the timestamp targeted by the playback cursor. More...
 
virtual int64_t get_real_timestamp () const =0
 Returns the timestamp of the most recently emitted frame. More...
 
virtual Status get_status () const =0
 Returns the current playback state. More...
 
virtual const Infoget_info () const =0
 Returns the cached header/summary metadata. More...
 
virtual std::vector< SchemaDatadetect_schema ()=0
 Scans the bag and collects every embedded schema descriptor. More...
 
virtual std::string get_ser_type (const std::string &url) const
 Resolves the serialisation type associated with url. More...
 
virtual SchemaType get_schema_type (const std::string &url) const
 Resolves the schema family associated with url. More...
 
virtual bool is_split_mode () const =0
 Returns whether the opened bag spans multiple split files. More...
 
virtual int get_split_index () const =0
 Returns the zero-based index of the split file currently being consumed. More...
 
virtual bool is_jumping () const =0
 Returns whether a jump() seek is still in progress. More...
 

Static Public Member Functions

static std::shared_ptr< BagReadercreate (const std::string &path, bool read_only=true, bool try_to_fix=false)
 Builds the concrete reader matching the extension of path. More...
 

Static Public Attributes

static constexpr int kInfinite {-1}
 Sentinel for Config::times that requests endless loop playback. More...
 

Protected Member Functions

virtual bool do_open_cursor (const Config &config)
 
virtual bool do_read_next (Frame &out, bool &is_error)
 
void process_output (Frame &frame)
 
void fill_frame_meta (Frame &frame) const
 
void flush_plugin ()
 
void process_url_metas (std::vector< Info::UrlMeta > &url_metas)
 
void rebuild_url_meta_lookup (const std::vector< Info::UrlMeta > &url_metas)
 
std::unordered_map< std::string, std::string > & url_ser_map ()
 
std::unordered_map< std::string, SchemaType > & url_schema_type_map ()
 
bool convert_playback_url (const std::string &input_url, std::string &output_url) const
 
bool match_playback_url_filter (std::string_view input_url, const std::unordered_set< std::string > &filter_urls) const
 
void detach_plugin ()
 

Static Protected Member Functions

static void rebuild_url_meta_maps (const std::vector< Info::UrlMeta > &url_metas, std::unordered_map< std::string, std::string > &ser_map, std::unordered_map< std::string, SchemaType > &schema_type_map)
 
static ActionType convert_action (std::string_view str)
 

Detailed Description

Format-agnostic VLink bag player driven by an internal MessageLoop.

Inherits MessageLoop so playback runs on a dedicated worker thread. Construction opens the target file and parses its index, but no frames are emitted until async_run() starts the loop and play() supplies a Config. All virtual operations are implemented by VDBReader and VCAPReader; the base class only carries shared plumbing (callback storage, plugin binding, URL filtering helpers).

Member Typedef Documentation

◆ FinishCallback

using vlink::BagReader::FinishCallback = MoveFunction<void(bool is_interrupted)>

Callback fired when the current play session ends.

Parameters
is_interruptedTrue if termination was caused by stop(); false on natural end.

◆ OutputCallback

Callback signature receiving one replayed Frame.

Invoked on the reader's MessageLoop thread. Frame::timestamp is relative to the recording start (microseconds), url is the playback URL, and data is a shallow view valid only for the duration of the call – copy it if it must outlive the callback. Frame::ser_type / schema_type are filled by the reader from the bag's URL metadata, so the frame is fully populated (no separate get_ser_type() / get_schema_type() lookup is required).

Note
Multiply Config::begin_time and Config::end_time by 1000 before comparing them against Frame::timestamp.

◆ ReadyCallback

Callback fired once after the bag has been opened and indexed.

◆ StatusCallback

Callback fired on every transition of Status.

Parameters
statusThe new playback state.

Member Enumeration Documentation

◆ Status

enum vlink::BagReader::Status : uint8_t

Coarse playback state observable through get_status().

Value Meaning
kStopped No active session; position is reset to the start of the bag
kPaused A play session is open but the dispatcher is suspended
kPlaying The dispatcher is actively delivering frames
Enumerator
kStopped 

Idle; no playback in progress.

kPaused 

Playback temporarily suspended; position retained.

kPlaying 

Actively forwarding frames to the output callback.

Constructor & Destructor Documentation

◆ BagReader()

vlink::BagReader::BagReader ( const std::string &  path,
bool  read_only = true,
bool  try_to_fix = false 
)
explicit

Constructs the base reader and stores construction-time options.

Parameters
pathBag file path passed to the concrete subclass.
read_onlyWhen true, prevents the backend from acquiring write access.
try_to_fixWhen true, allows the subclass to run recovery while opening.

◆ ~BagReader()

virtual vlink::BagReader::~BagReader ( )
virtual

Stops the loop, closes the file and releases backend resources.

Member Function Documentation

◆ bind_plugin_interface()

virtual void vlink::BagReader::bind_plugin_interface ( const std::shared_ptr< BagPluginInterface > &  plugin_interface)
virtual

Attaches a custom URL/type/message rewrite plugin to this reader.

The plugin's convert_url_meta() runs once per URL discovered in the bag and may rename topics, override serialisation types or filter URLs out. Its on_read() hook sees every replayed frame before it reaches the user OutputCallback.

Parameters
plugin_interfacePlugin instance, or nullptr to detach the current binding.
See also
clear_plugin_interface() for the named equivalent of passing nullptr.

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ check()

virtual std::future<bool> vlink::BagReader::check ( )
pure virtual

Runs an asynchronous integrity verification pass.

Returns
Future resolving to true when the bag is structurally intact.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ clear_plugin_interface()

virtual void vlink::BagReader::clear_plugin_interface ( )
virtual

Detaches the currently bound plugin, if any.

Convenience wrapper equivalent to bind_plugin_interface(nullptr): flushes the bound plugin, clears its callback together with the plugin-derived URL remap / exclusion state, and drops the binding. Safe to call when no plugin is bound (in which case it is a no-op).

◆ convert_action()

static ActionType vlink::BagReader::convert_action ( std::string_view  str)
staticprotected

◆ convert_playback_url()

bool vlink::BagReader::convert_playback_url ( const std::string &  input_url,
std::string &  output_url 
) const
protected

◆ create()

static std::shared_ptr<BagReader> vlink::BagReader::create ( const std::string &  path,
bool  read_only = true,
bool  try_to_fix = false 
)
static

Builds the concrete reader matching the extension of path.

Suffix dispatch: .vdb / .vdbx select VDBReader, .vcap / .vcapx select VCAPReader; any other suffix returns nullptr.

Parameters
pathBag file path on disk.
read_onlyWhen true, opens the backend read-only and rejects mutating calls.
try_to_fixWhen true, allows backends to attempt a recovery pass while opening.
Returns
Shared pointer to the freshly built reader, or nullptr for an unknown suffix.

◆ detach_plugin()

void vlink::BagReader::detach_plugin ( )
protected

◆ detect_schema()

virtual std::vector<SchemaData> vlink::BagReader::detect_schema ( )
pure virtual

Scans the bag and collects every embedded schema descriptor.

Returns
Vector of SchemaData entries.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ do_open_cursor()

virtual bool vlink::BagReader::do_open_cursor ( const Config config)
protectedvirtual

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ do_read_next()

virtual bool vlink::BagReader::do_read_next ( Frame out,
bool &  is_error 
)
protectedvirtual

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ eof()

bool vlink::BagReader::eof ( ) const
noexcept

Returns whether the cursor has reached the end of the bag.

◆ fail()

bool vlink::BagReader::fail ( ) const
noexcept

Returns whether the last cursor operation failed (open or backend read error).

◆ fill_frame_meta()

void vlink::BagReader::fill_frame_meta ( Frame frame) const
protected

◆ fix()

virtual std::future<bool> vlink::BagReader::fix ( bool  rebuild = false)
pure virtual

Attempts to recover a corrupted bag in the background where supported.

Parameters
rebuildWhen true, also forces a full index rebuild.
Returns
Future resolving to true when recovery succeeded.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ flush_plugin()

void vlink::BagReader::flush_plugin ( )
protected

◆ get_info()

virtual const Info& vlink::BagReader::get_info ( ) const
pure virtual

Returns the cached header/summary metadata.

Returns
Constant reference to the Info populated at open time.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ get_real_timestamp()

virtual int64_t vlink::BagReader::get_real_timestamp ( ) const
pure virtual

Returns the timestamp of the most recently emitted frame.

Returns
Real delivered timestamp in milliseconds, or 0 when no frame is in flight.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ get_schema_type()

virtual SchemaType vlink::BagReader::get_schema_type ( const std::string &  url) const
virtual

Resolves the schema family associated with url.

Parameters
urlFully-qualified URL to look up.
Returns
Coarse SchemaType, or SchemaType::kUnknown when unavailable.

◆ get_ser_type()

virtual std::string vlink::BagReader::get_ser_type ( const std::string &  url) const
virtual

Resolves the serialisation type associated with url.

Parameters
urlFully-qualified URL to look up.
Returns
Stored serialisation type, or an empty string when url is unknown.

◆ get_split_index()

virtual int vlink::BagReader::get_split_index ( ) const
pure virtual

Returns the zero-based index of the split file currently being consumed.

Returns
Active split index, or 0 for a single-file bag.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ get_status()

virtual Status vlink::BagReader::get_status ( ) const
pure virtual

Returns the current playback state.

Returns
One of kStopped, kPaused or kPlaying.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ get_timestamp()

virtual int64_t vlink::BagReader::get_timestamp ( ) const
pure virtual

Returns the timestamp targeted by the playback cursor.

Returns
Current playback time in milliseconds, relative to the recording start.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ is_jumping()

virtual bool vlink::BagReader::is_jumping ( ) const
pure virtual

Returns whether a jump() seek is still in progress.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ is_split_mode()

virtual bool vlink::BagReader::is_split_mode ( ) const
pure virtual

Returns whether the opened bag spans multiple split files.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ jump()

virtual void vlink::BagReader::jump ( int64_t  begin_time,
double  rate,
int  times,
bool  force_to_play = false 
)
pure virtual

Seeks playback to begin_time and applies updated rate and loop settings.

Parameters
begin_timeTarget recording timestamp in milliseconds.
rateNew playback speed multiplier.
timesLoop count to apply after the seek.
force_to_playWhen true, transitions to kPlaying even if currently paused.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ match_playback_url_filter()

bool vlink::BagReader::match_playback_url_filter ( std::string_view  input_url,
const std::unordered_set< std::string > &  filter_urls 
) const
protected

◆ open_cursor() [1/2]

bool vlink::BagReader::open_cursor ( )

Opens (or rewinds) a full, unfiltered sequential read cursor over the bag.

Convenience overload equivalent to open_cursor() with a default Config: every stored frame is visited in recorded order.

Returns
true when the cursor is positioned and ready, false on open failure (sets fail()).

◆ open_cursor() [2/2]

bool vlink::BagReader::open_cursor ( const Config config)

Opens (or rewinds) a synchronous sequential read cursor over the bag.

The cursor is an alternative to the timed play() / register_output_callback() path: it walks every stored frame in recorded order and hands them back one at a time through read_next() / operator>>, with no inter-frame delay, no loop thread and independent of any async_run() / play() session (a dedicated backend statement / iterator is used). Only Config::filter_urls and the Config::begin_time / Config::end_time window are honoured; rate, times and the auto_* / skip_blank flags are ignored. Any bound BagPluginInterface URL remap and URL exclusions still apply, but the plugin's on_read() interception (which is playback-only) does not run.

Calling it again rewinds the cursor and re-applies config, clearing the eof() / fail() state. read_next() and operator>> open a default (full, unfiltered) cursor automatically on first use, so an explicit call is only needed to apply a filter or seek window.

Parameters
configCursor filter and time window (rate / loop / auto flags are ignored).
Returns
true when the cursor is positioned and ready, false on open failure (sets fail()).
Note
The cursor is single-threaded; do not drive it concurrently with an active play() session on the same reader.

◆ operator bool()

vlink::BagReader::operator bool ( ) const
explicitnoexcept

Reports whether the cursor is still in a readable state (not at end, not failed).

Returns true while a frame can still be read, so while (reader >> frame) stops at end of bag or on error.

◆ operator>>()

BagReader& vlink::BagReader::operator>> ( Frame out)

Stream-style alias for read_next(), enabling while (reader >> frame).

Parameters
outReceives the next frame.
Returns
Reference to *this, whose bool conversion reflects the post-read stream state.

◆ pause()

virtual void vlink::BagReader::pause ( )
pure virtual

Suspends frame dispatch while preserving the current position.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ pause_to_next()

virtual void vlink::BagReader::pause_to_next ( )
pure virtual

Emits exactly one frame from the paused position, then pauses again.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ play()

virtual void vlink::BagReader::play ( const Config config)
pure virtual

Starts (or restarts) a play session with the supplied configuration.

Transitions the reader into kPlaying. Requires that async_run() has already been called so that the loop thread can dispatch frames.

Parameters
configPlayback window, rate, loop count and URL filter.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ process_output()

void vlink::BagReader::process_output ( Frame frame)
protected

◆ process_url_metas()

void vlink::BagReader::process_url_metas ( std::vector< Info::UrlMeta > &  url_metas)
protected

◆ read_next()

bool vlink::BagReader::read_next ( Frame out)

Reads the next frame in recorded order into out.

Lazily calls open_cursor() with a default Config on first use. On success out is fully populated (the same URL remap and ser_type / schema_type fill applied to playback frames); out.data is a shallow view that stays valid only until the next read_next() / operator>> call – copy it if it must outlive that.

Parameters
outReceives the next frame.
Returns
true when a frame was read; false at end of bag (sets eof()) or on error (sets fail()).

◆ rebuild_url_meta_lookup()

void vlink::BagReader::rebuild_url_meta_lookup ( const std::vector< Info::UrlMeta > &  url_metas)
protected

◆ rebuild_url_meta_maps()

static void vlink::BagReader::rebuild_url_meta_maps ( const std::vector< Info::UrlMeta > &  url_metas,
std::unordered_map< std::string, std::string > &  ser_map,
std::unordered_map< std::string, SchemaType > &  schema_type_map 
)
staticprotected

◆ register_finish_callback()

virtual void vlink::BagReader::register_finish_callback ( FinishCallback &&  finish_callback)
virtual

Installs the "play session ended" observer.

Parameters
finish_callbackFunction invoked at the end of a play session.

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ register_output_callback()

virtual void vlink::BagReader::register_output_callback ( OutputCallback &&  output_callback)
virtual

Installs the per-frame data sink.

Parameters
output_callbackFunction called for every replayed message.

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ register_ready_callback()

virtual void vlink::BagReader::register_ready_callback ( ReadyCallback &&  ready_callback)
virtual

Installs the "open complete" observer.

Parameters
ready_callbackFunction invoked once the bag is open and the index is parsed.

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ register_status_callback()

virtual void vlink::BagReader::register_status_callback ( StatusCallback &&  status_callback)
virtual

Installs a state-change observer.

Parameters
status_callbackFunction invoked with the new Status on every transition.

Reimplemented in vlink::VDBReader, and vlink::VCAPReader.

◆ reindex()

virtual std::future<bool> vlink::BagReader::reindex ( )
pure virtual

Rebuilds backend index tables in the background where supported.

Returns
Future resolving to true on success.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ resume()

virtual void vlink::BagReader::resume ( )
pure virtual

Resumes dispatch from the paused position.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ stop()

virtual void vlink::BagReader::stop ( )
pure virtual

Aborts the active session and rewinds to the start of the bag.

Drives the reader into kStopped and invokes the FinishCallback with is_interrupted set to true.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ tag()

virtual void vlink::BagReader::tag ( const std::string &  tag_name)
pure virtual

Overwrites the human-readable tag stored in the bag header.

Parameters
tag_nameNew tag value.

Implemented in vlink::VDBReader, and vlink::VCAPReader.

◆ url_schema_type_map()

std::unordered_map<std::string, SchemaType>& vlink::BagReader::url_schema_type_map ( )
protected

◆ url_ser_map()

std::unordered_map<std::string, std::string>& vlink::BagReader::url_ser_map ( )
protected

Member Data Documentation

◆ kInfinite

constexpr int vlink::BagReader::kInfinite {-1}
staticconstexpr

Sentinel for Config::times that requests endless loop playback.


The documentation for this class was generated from the following file: