Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the many parameters of rerun::spawn / rerun::RecordingStream::spawn with a struct #4149

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions rerun_cpp/src/rerun/recording_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,11 @@ namespace rerun {
return status;
}

Error RecordingStream::spawn(
uint16_t port, std::string_view memory_limit, std::string_view executable_name,
std::optional<std::string_view> executable_path, float flush_timeout_sec
) const {
rr_spawn_options spawn_opts;
spawn_opts.port = port;
spawn_opts.memory_limit = detail::to_rr_string(memory_limit);
spawn_opts.executable_name = detail::to_rr_string(executable_name);
spawn_opts.executable_path = detail::to_rr_string(executable_path);

Error RecordingStream::spawn(const SpawnOptions& options, float flush_timeout_sec) const {
rr_spawn_options rerun_c_options = {};
options.fill_rerun_c_struct(rerun_c_options);
rr_error status = {};
rr_recording_stream_spawn(_id, &spawn_opts, flush_timeout_sec, &status);

rr_recording_stream_spawn(_id, &rerun_c_options, flush_timeout_sec, &status);
return status;
}

Expand Down
25 changes: 2 additions & 23 deletions rerun_cpp/src/rerun/recording_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "as_components.hpp"
#include "component_batch.hpp"
#include "error.hpp"
#include "spawn_options.hpp"

namespace rerun {
struct DataCell;
Expand Down Expand Up @@ -129,33 +130,11 @@ namespace rerun {
///
/// ## Parameters
///
/// port:
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
/// The port to listen on.
///
/// memory_limit:
/// An upper limit on how much memory the Rerun Viewer should use.
/// When this limit is reached, Rerun will drop the oldest data.
/// Example: `16GB` or `50%` (of system total).
///
/// executable_name:
/// Specifies the name of the Rerun executable.
/// You can omit the `.exe` suffix on Windows.
///
/// executable_path:
/// Enforce a specific executable to use instead of searching though PATH
/// for [`Self::executable_name`].
///
/// flush_timeout_sec:
/// The minimum time the SDK will wait during a flush before potentially
/// dropping data if progress is not being made. Passing a negative value indicates no
/// timeout, and can cause a call to `flush` to block indefinitely.
Error spawn(
uint16_t port = 9876, //
std::string_view memory_limit = "75%", //
std::string_view executable_name = "rerun", //
std::optional<std::string_view> executable_path = std::nullopt, //
float flush_timeout_sec = 2.0
) const;
Error spawn(const SpawnOptions& options = {}, float flush_timeout_sec = 2.0) const;

/// Stream all log-data to a given file.
///
Expand Down
17 changes: 4 additions & 13 deletions rerun_cpp/src/rerun/spawn.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#include "spawn.hpp"
#include "c/rerun.h"
#include "string_utils.hpp"

namespace rerun {
Error spawn(
uint16_t port, std::string_view memory_limit, std::string_view executable_name,
std::optional<std::string_view> executable_path
) {
rr_spawn_options spawn_opts;
spawn_opts.port = port;
spawn_opts.memory_limit = detail::to_rr_string(memory_limit);
spawn_opts.executable_name = detail::to_rr_string(executable_name);
spawn_opts.executable_path = detail::to_rr_string(executable_path);
Error spawn(const SpawnOptions& options) {
rr_spawn_options rerun_c_options = {};
options.fill_rerun_c_struct(rerun_c_options);
rr_error error = {};

rr_spawn(&spawn_opts, &error);

rr_spawn(&rerun_c_options, &error);
return Error(error);
}
} // namespace rerun
26 changes: 2 additions & 24 deletions rerun_cpp/src/rerun/spawn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,13 @@
#include <string_view>

#include "error.hpp"
#include "spawn_options.hpp"

namespace rerun {
/// Spawns a new Rerun Viewer process from an executable available in PATH, ready to
/// listen for incoming TCP connections.
///
/// If a Rerun Viewer is already listening on this TCP port, the stream will be redirected to
/// that viewer instead of starting a new one.
///
/// ## Parameters
///
/// port:
/// The port to listen on.
///
/// memory_limit:
/// An upper limit on how much memory the Rerun Viewer should use.
/// When this limit is reached, Rerun will drop the oldest data.
/// Example: `16GB` or `50%` (of system total).
///
/// executable_name:
/// Specifies the name of the Rerun executable.
/// You can omit the `.exe` suffix on Windows.
///
/// executable_path:
/// Enforce a specific executable to use instead of searching though PATH
/// for [`Self::executable_name`].
Error spawn(
uint16_t port = 9876, //
const std::string_view memory_limit = "75%", //
const std::string_view executable_name = "rerun", //
const std::optional<std::string_view> executable_path = std::nullopt //
);
Error spawn(const SpawnOptions& options = {});
} // namespace rerun
12 changes: 12 additions & 0 deletions rerun_cpp/src/rerun/spawn_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "spawn_options.hpp"
#include "c/rerun.h"
#include "string_utils.hpp"

namespace rerun {
void SpawnOptions::fill_rerun_c_struct(rr_spawn_options& spawn_opts) const {
spawn_opts.port = port;
spawn_opts.memory_limit = detail::to_rr_string(memory_limit);
spawn_opts.executable_name = detail::to_rr_string(executable_name);
spawn_opts.executable_path = detail::to_rr_string(executable_path);
}
} // namespace rerun
43 changes: 43 additions & 0 deletions rerun_cpp/src/rerun/spawn_options.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <cstdint>
#include <string_view>

extern "C" struct rr_spawn_options;

namespace rerun {

/// Options to control the behavior of `spawn`.
///
/// Refer to the field-level documentation for more information about each individual options.
///
/// The defaults are ok for most use cases.
///
/// Keep this in sync with rerun.h's `rr_spawn_options`.
struct SpawnOptions {
/// The port to listen on.
uint16_t port = 9876;

/// An upper limit on how much memory the Rerun Viewer should use.
/// When this limit is reached, Rerun will drop the oldest data.
/// Example: `16GB` or `50%` (of system total).
///
/// Defaults to `75%` if null.
std::string_view memory_limit = "75%";

/// Specifies the name of the Rerun executable.
///
/// You can omit the `.exe` suffix on Windows.
std::string_view executable_name = "rerun";

/// Enforce a specific executable to use instead of searching though PATH
/// for [`Self::executable_name`].
std::string_view executable_path = "";

/// Convert to the corresponding rerun_c struct.
///
/// Implementation note:
/// By not returning it we avoid including the C header in this header.
void fill_rerun_c_struct(rr_spawn_options& spawn_opts) const;
};
} // namespace rerun
Loading