-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK
DataLoader
s 3: barebones C and C++ support (#5330)
Exposes raw `DataLoader`s to the C++ SDK through 2 new methods: `RecordingStream::log_file_from_path` & `RecordingStream::log_file_from_contents`. Everything streams asynchronously, as expected. There's no way to configure the behavior of the `DataLoader` at all, yet. That comes next. :warning: I'm carrying bytes around in a `string_view` (see `rr_bytes`) and related, and the internet has been unhelpful to tell e whether I should or shouldn't. ```cpp rec.log_file_from_path(filepath); ``` ![image](https://github.com/rerun-io/rerun/assets/2910679/1933f08b-1b2b-483b-9576-ce2e0421cb62) --- Part of series of PR to expose configurable `DataLoader`s to our SDKs: - #5327 - #5328 - #5330 - #5337 - #5351 - #5355 --------- Co-authored-by: Andreas Reich <andreas@rerun.io>
- Loading branch information
Showing
12 changed files
with
410 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.16...3.27) | ||
|
||
# If you use the example outside of the Rerun SDK you need to specify | ||
# where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable. | ||
# This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake. | ||
if(DEFINED RERUN_REPOSITORY) | ||
add_executable(example_log_file main.cpp) | ||
rerun_strict_warning_settings(example_log_file) | ||
else() | ||
project(example_log_file LANGUAGES CXX) | ||
|
||
add_executable(example_log_file main.cpp) | ||
|
||
# Set the path to the rerun_c build. | ||
set(RERUN_CPP_URL "https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip" CACHE STRING "URL to the rerun_cpp zip.") | ||
option(RERUN_FIND_PACKAGE "Whether to use find_package to find a preinstalled rerun package (instead of using FetchContent)." OFF) | ||
|
||
if(RERUN_FIND_PACKAGE) | ||
find_package(rerun_sdk REQUIRED) | ||
else() | ||
# Download the rerun_sdk | ||
include(FetchContent) | ||
FetchContent_Declare(rerun_sdk URL ${RERUN_CPP_URL}) | ||
FetchContent_MakeAvailable(rerun_sdk) | ||
endif() | ||
|
||
# Rerun requires at least C++17, but it should be compatible with newer versions. | ||
set_property(TARGET example_log_file PROPERTY CXX_STANDARD 17) | ||
endif() | ||
|
||
# Link against rerun_sdk. | ||
target_link_libraries(example_log_file PRIVATE rerun_sdk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!--[metadata] | ||
title = "Log file example" | ||
--> | ||
|
||
Demonstrates how to log any file from the SDK using the [`DataLoader`](https://www.rerun.io/docs/howto/open-any-file) machinery. | ||
|
||
To build it from a checkout of the repository (requires a Rust toolchain): | ||
```bash | ||
cmake . | ||
cmake --build . --target example_log_file | ||
./examples/cpp/log_file/example_log_file examples/assets/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include <rerun.hpp> | ||
#include <rerun/third_party/cxxopts.hpp> | ||
|
||
int main(int argc, char** argv) { | ||
// Create a new `RecordingStream` which sends data over TCP to the viewer process. | ||
const auto rec = rerun::RecordingStream("rerun_example_log_file"); | ||
|
||
cxxopts::Options options( | ||
"rerun_example_log_file", | ||
"Demonstrates how to log any file from the SDK using the `DataLoader` machinery." | ||
); | ||
|
||
// clang-format off | ||
options.add_options() | ||
("h,help", "Print usage") | ||
// Rerun | ||
("spawn", "Start a new Rerun Viewer process and feed it data in real-time") | ||
("connect", "Connects and sends the logged data to a remote Rerun viewer") | ||
("save", "Log data to an rrd file", cxxopts::value<std::string>()) | ||
("stdout", "Log data to standard output, to be piped into a Rerun Viewer") | ||
// Example | ||
("from-contents", "Log the contents of the file directly (files only -- not supported by external loaders)", cxxopts::value<bool>()->default_value("false")) | ||
("filepaths", "The filepaths to be loaded and logged", cxxopts::value<std::vector<std::string>>()) | ||
; | ||
// clang-format on | ||
|
||
options.parse_positional({"filepaths"}); | ||
|
||
auto args = options.parse(argc, argv); | ||
|
||
if (args.count("help")) { | ||
std::cout << options.help() << std::endl; | ||
exit(0); | ||
} | ||
|
||
// TODO(#4602): need common rerun args helper library | ||
if (args["spawn"].as<bool>()) { | ||
rec.spawn().exit_on_failure(); | ||
} else if (args["connect"].as<bool>()) { | ||
rec.connect().exit_on_failure(); | ||
} else if (args["stdout"].as<bool>()) { | ||
rec.to_stdout().exit_on_failure(); | ||
} else if (args.count("save")) { | ||
rec.save(args["save"].as<std::string>()).exit_on_failure(); | ||
} else { | ||
rec.spawn().exit_on_failure(); | ||
} | ||
|
||
const auto from_contents = args["from-contents"].as<bool>(); | ||
if (args.count("filepaths")) { | ||
const auto filepaths = args["filepaths"].as<std::vector<std::string>>(); | ||
for (const auto& filepath : filepaths) { | ||
if (!from_contents) { | ||
// Either log the file using its path… | ||
rec.log_file_from_path(filepath); | ||
} else { | ||
// …or using its contents if you already have them loaded for some reason. | ||
if (std::filesystem::is_regular_file(filepath)) { | ||
std::ifstream file(filepath); | ||
std::stringstream contents; | ||
contents << file.rdbuf(); | ||
|
||
const auto data = contents.str(); | ||
rec.log_file_from_contents( | ||
filepath, | ||
reinterpret_cast<const std::byte*>(data.c_str()), | ||
data.size() | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.