Class BulkDataStore
Defined in File bulk_data_store.hpp
Nested Relationships
Nested Types
Class Documentation
-
class BulkDataStore
Filesystem-based storage for uploaded bulk data files.
Stores files in a directory structure: {storage_dir}/{entity_id}/{category}/{item_id}/ descriptor.json — metadata sidecar {original_filename} — payload
Thread-safe: uses mutex for rename + descriptor write operations. Large payload writes happen outside the lock.
Categories are configured at construction time. The “rosbags” category is NOT managed here — it is handled by FaultManager.
- Todo:
#215 Per-category config (BulkDataCategoryConfig): access mode (read-only/write-only/read-write), per-category max_file_size, source_path/upload_path templates, human-readable name. Currently categories are plain string IDs with a single global upload limit. See https://github.com/selfpatch/ros2_medkit/issues/215
Public Functions
-
BulkDataStore(const std::string &storage_dir, size_t max_upload_bytes, std::vector<std::string> categories = {})
Construct a BulkDataStore.
- Parameters:
storage_dir – Base directory for uploaded files
max_upload_bytes – Global max upload size in bytes (0 = unlimited)
categories – List of allowed category names (besides “rosbags”)
-
tl::expected<ItemDescriptor, std::string> store(const std::string &entity_id, const std::string &category, const std::string &filename, const std::string &content_type, const std::string &data, const std::string &description = "", const nlohmann::json &metadata = {})
Upload a file.
Uses atomic write: payload → tmp file → rename + write descriptor.json.
- Parameters:
entity_id – Entity this file belongs to
category – Bulk data category (must be in configured list)
filename – Original filename
content_type – MIME type
data – File contents
description – Optional text description
metadata – Optional JSON metadata
- Returns:
ItemDescriptor on success, error message on failure
-
tl::expected<void, std::string> remove(const std::string &entity_id, const std::string &category, const std::string &item_id)
Delete an uploaded item.
- Parameters:
entity_id – Entity ID
category – Category name
item_id – Item ID to delete
- Returns:
void on success, error message if not found
-
std::vector<std::string> list_categories() const
List configured categories (does NOT include “rosbags”)
-
std::vector<ItemDescriptor> list_items(const std::string &entity_id, const std::string &category) const
List items in a category for an entity (scans filesystem)
-
std::optional<ItemDescriptor> get_item(const std::string &entity_id, const std::string &category, const std::string &item_id) const
Get single item descriptor.
-
std::optional<std::string> get_file_path(const std::string &entity_id, const std::string &category, const std::string &item_id) const
Get filesystem path to uploaded file (for streaming download)
-
bool is_known_category(const std::string &category) const
Check if category is in configured list.
-
inline size_t max_upload_bytes() const
Get max upload size in bytes.
-
struct ItemDescriptor
Metadata descriptor for an uploaded bulk data item.