Skip to content

Commit

Permalink
expose settings to cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Mar 4, 2024
1 parent 4e0673d commit 9d1ad73
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 12 deletions.
29 changes: 27 additions & 2 deletions crates/rerun_c/src/rerun.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,30 @@ typedef struct rr_spawn_options {
rr_string executable_path;
} rr_spawn_options;

/// Recommended settings for the [`DataLoader`].
///
/// The loader is free to ignore some or all of these.
///
/// Refer to the field-level documentation for more information about each individual options.
//
// TODO(#3841): expose timepoint settings once we implement stateless APIs
typedef struct rr_data_loader_settings {
/// The recommended `RecordingId` to log the data to.
///
/// Unspecified by default.
rr_string recording_id;

/// What should the logged entity paths be prefixed with?
///
/// Unspecified by default.
rr_string entity_path_prefix;

/// Should the logged data be timeless?
///
/// Defaults to `false` if not set.
bool timeless;
} rr_data_loader_settings;

typedef struct rr_store_info {
/// The user-chosen name of the application doing the logging.
rr_string application_id;
Expand Down Expand Up @@ -432,7 +456,7 @@ extern void rr_recording_stream_log(
///
/// See <https://www.rerun.io/docs/howto/open-any-file> for more information.
extern void rr_recording_stream_log_file_from_path(
rr_recording_stream stream, rr_string path, rr_error* error
rr_recording_stream stream, rr_data_loader_settings settings, rr_string path, rr_error* error
);

/// Logs the given `contents` using all `DataLoader`s available.
Expand All @@ -444,7 +468,8 @@ extern void rr_recording_stream_log_file_from_path(
///
/// See <https://www.rerun.io/docs/howto/open-any-file> for more information.
extern void rr_recording_stream_log_file_from_contents(
rr_recording_stream stream, rr_string path, rr_bytes contents, rr_error* error
rr_recording_stream stream, rr_data_loader_settings settings, rr_string path, rr_bytes contents,
rr_error* error
);

// ----------------------------------------------------------------------------
Expand Down
29 changes: 27 additions & 2 deletions rerun_cpp/src/rerun/c/rerun.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions rerun_cpp/src/rerun/recording_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,23 @@ namespace rerun {
return status;
}

Error RecordingStream::try_log_file_from_path(const std::filesystem::path& filepath) const {
Error RecordingStream::try_log_file_from_path(
const std::filesystem::path& filepath, std::optional<std::string_view> recording_id,
std::optional<std::string_view> entity_path_prefix, bool timeless
) const {
if (!is_enabled()) {
return Error::ok();
}

rr_data_loader_settings settings = {};
settings.recording_id = detail::to_rr_string(recording_id);
settings.entity_path_prefix = detail::to_rr_string(entity_path_prefix);
settings.timeless = timeless;

rr_error status = {};
rr_recording_stream_log_file_from_path(
_id,
settings,
detail::to_rr_string(filepath.string()),
&status
);
Expand All @@ -273,7 +282,9 @@ namespace rerun {
}

Error RecordingStream::try_log_file_from_contents(
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size,
std::optional<std::string_view> recording_id,
std::optional<std::string_view> entity_path_prefix, bool timeless
) const {
if (!is_enabled()) {
return Error::ok();
Expand All @@ -283,9 +294,15 @@ namespace rerun {
data.bytes = reinterpret_cast<const uint8_t*>(contents);
data.length = static_cast<uint32_t>(contents_size);

rr_data_loader_settings settings = {};
settings.recording_id = detail::to_rr_string(recording_id);
settings.entity_path_prefix = detail::to_rr_string(entity_path_prefix);
settings.timeless = timeless;

rr_error status = {};
rr_recording_stream_log_file_from_contents(
_id,
settings,
detail::to_rr_string(filepath.string()),
data,
&status
Expand Down
45 changes: 39 additions & 6 deletions rerun_cpp/src/rerun/recording_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <chrono>
#include <cstdint> // uint32_t etc.
#include <filesystem>
#include <optional>
#include <string_view>
#include <vector>

Expand Down Expand Up @@ -505,10 +506,17 @@ namespace rerun {
/// See <https://www.rerun.io/docs/howto/open-any-file> for more information.
///
/// \param filepath Path to the file to be logged.
/// \param recording_id The recommended `RecordingId` to log the data to.
/// \param entity_path_prefix What should the logged entity paths be prefixed with?
/// \param timeless Should the logged data be timeless?
///
/// \see `try_log_file_from_path`
void log_file_from_path(const std::filesystem::path& filepath) const {
try_log_file_from_path(filepath).handle();
void log_file_from_path(
const std::filesystem::path& filepath,
std::optional<std::string_view> recording_id = std::nullopt,
std::optional<std::string_view> entity_path_prefix = std::nullopt, bool timeless = false
) const {
try_log_file_from_path(filepath, recording_id, entity_path_prefix, timeless).handle();
}

/// Logs the file at the given `path` using all `DataLoader`s available.
Expand All @@ -521,9 +529,16 @@ namespace rerun {
/// See <https://www.rerun.io/docs/howto/open-any-file> for more information.
///
/// \param filepath Path to the file to be logged.
/// \param recording_id The recommended `RecordingId` to log the data to.
/// \param entity_path_prefix What should the logged entity paths be prefixed with?
/// \param timeless Should the logged data be timeless?
///
/// \see `log_file_from_path`
Error try_log_file_from_path(const std::filesystem::path& filepath) const;
Error try_log_file_from_path(
const std::filesystem::path& filepath,
std::optional<std::string_view> recording_id = std::nullopt,
std::optional<std::string_view> entity_path_prefix = std::nullopt, bool timeless = false
) const;

/// Logs the given `contents` using all `DataLoader`s available.
///
Expand All @@ -537,12 +552,25 @@ namespace rerun {
/// \param filepath Path to the file that the `contents` belong to.
/// \param contents Contents to be logged.
/// \param contents_size Size in bytes of the `contents`.
/// \param recording_id The recommended `RecordingId` to log the data to.
/// \param entity_path_prefix What should the logged entity paths be prefixed with?
/// \param timeless Should the logged data be timeless?
///
/// \see `try_log_file_from_contents`
void log_file_from_contents(
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size,
std::optional<std::string_view> recording_id = std::nullopt,
std::optional<std::string_view> entity_path_prefix = std::nullopt, bool timeless = false
) const {
try_log_file_from_contents(filepath, contents, contents_size).handle();
try_log_file_from_contents(
filepath,
contents,
contents_size,
recording_id,
entity_path_prefix,
timeless
)
.handle();
}

/// Logs the given `contents` using all `DataLoader`s available.
Expand All @@ -557,10 +585,15 @@ namespace rerun {
/// \param filepath Path to the file that the `contents` belong to.
/// \param contents Contents to be logged.
/// \param contents_size Size in bytes of the `contents`.
/// \param recording_id The recommended `RecordingId` to log the data to.
/// \param entity_path_prefix What should the logged entity paths be prefixed with?
/// \param timeless Should the logged data be timeless?
///
/// \see `log_file_from_contents`
Error try_log_file_from_contents(
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size
const std::filesystem::path& filepath, const std::byte* contents, size_t contents_size,
std::optional<std::string_view> recording_id = std::nullopt,
std::optional<std::string_view> entity_path_prefix = std::nullopt, bool timeless = false
) const;

/// @}
Expand Down

0 comments on commit 9d1ad73

Please sign in to comment.