File tree Expand file tree Collapse file tree 11 files changed +145
-2
lines changed Expand file tree Collapse file tree 11 files changed +145
-2
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,7 @@ pub enum CErrorCode {
161
161
_CategoryRecordingStream = 0x0000_00100 ,
162
162
RecordingStreamCreationFailure ,
163
163
RecordingStreamSaveFailure ,
164
+ RecordingStreamStdoutFailure ,
164
165
// TODO(cmc): Really this should be its own category…
165
166
RecordingStreamSpawnFailure ,
166
167
@@ -468,6 +469,24 @@ pub extern "C" fn rr_recording_stream_save(
468
469
}
469
470
}
470
471
472
+ #[ allow( clippy:: result_large_err) ]
473
+ fn rr_recording_stream_stdout_impl ( stream : CRecordingStream ) -> Result < ( ) , CError > {
474
+ recording_stream ( stream) ?. stdout ( ) . map_err ( |err| {
475
+ CError :: new (
476
+ CErrorCode :: RecordingStreamStdoutFailure ,
477
+ & format ! ( "Failed to forward recording stream to stdout: {err}" ) ,
478
+ )
479
+ } )
480
+ }
481
+
482
+ #[ allow( unsafe_code) ]
483
+ #[ no_mangle]
484
+ pub extern "C" fn rr_recording_stream_stdout ( id : CRecordingStream , error : * mut CError ) {
485
+ if let Err ( err) = rr_recording_stream_stdout_impl ( id) {
486
+ err. write_error ( error) ;
487
+ }
488
+ }
489
+
471
490
#[ allow( clippy:: result_large_err) ]
472
491
fn rr_recording_stream_set_time_sequence_impl (
473
492
stream : CRecordingStream ,
Original file line number Diff line number Diff line change @@ -198,6 +198,7 @@ enum {
198
198
_RR_ERROR_CODE_CATEGORY_RECORDING_STREAM = 0x000000100 ,
199
199
RR_ERROR_CODE_RECORDING_STREAM_CREATION_FAILURE ,
200
200
RR_ERROR_CODE_RECORDING_STREAM_SAVE_FAILURE ,
201
+ RR_ERROR_CODE_RECORDING_STREAM_STDOUT_FAILURE ,
201
202
RR_ERROR_CODE_RECORDING_STREAM_SPAWN_FAILURE ,
202
203
203
204
// Arrow data processing errors.
@@ -333,6 +334,16 @@ extern void rr_recording_stream_spawn(
333
334
/// This function returns immediately.
334
335
extern void rr_recording_stream_save (rr_recording_stream stream , rr_string path , rr_error * error );
335
336
337
+ /// Stream all log-data to stdout.
338
+ ///
339
+ /// Pipe the result into the Rerun Viewer to visualize it.
340
+ ///
341
+ /// If there isn't any listener at the other end of the pipe, the `RecordingStream` will
342
+ /// default back to `buffered` mode, in order not to break the user's terminal.
343
+ ///
344
+ /// This function returns immediately.
345
+ extern void rr_recording_stream_stdout (rr_recording_stream stream , rr_error * error );
346
+
336
347
/// Initiates a flush the batching pipeline and waits for it to propagate.
337
348
///
338
349
/// See `rr_recording_stream` docs for ordering semantics and multithreading guarantees.
Original file line number Diff line number Diff line change @@ -80,6 +80,12 @@ Use [`RecordingStream::save`](https://docs.rs/rerun/latest/rerun/struct.Recordin
80
80
81
81
Streams all logging data to standard output, which can then be loaded by the Rerun Viewer by streaming it from standard input.
82
82
83
+ #### C++
84
+
85
+ Use [ ` RecordingStream::stdout ` ] ( https://ref.rerun.io/docs/cpp/stable/classrerun_1_1RecordingStream.html#SOMEHASH?speculative-link ) .
86
+
87
+ Check out our [ dedicated example] ( https://github.com/rerun-io/rerun/tree/latest/examples/cpp/stdio/main.cpp?speculative-link ) .
88
+
83
89
#### Python
84
90
85
91
Use [ ` rr.stdout ` ] ( https://ref.rerun.io/docs/python/stable/common/initialization_functions/#rerun.stdout?speculative-link ) .
Original file line number Diff line number Diff line change 1
1
add_subdirectory (clock )
2
2
add_subdirectory (custom_collection_adapter )
3
3
add_subdirectory (dna )
4
- add_subdirectory (shared_recording )
5
4
add_subdirectory (minimal )
5
+ add_subdirectory (shared_recording )
6
6
add_subdirectory (spawn_viewer )
7
+ add_subdirectory (stdio )
7
8
8
9
add_custom_target (examples )
9
10
10
11
add_dependencies (examples example_clock )
11
12
add_dependencies (examples example_custom_collection_adapter )
12
13
add_dependencies (examples example_dna )
13
- add_dependencies (examples example_shared_recording )
14
14
add_dependencies (examples example_minimal )
15
+ add_dependencies (examples example_shared_recording )
15
16
add_dependencies (examples example_spawn_viewer )
17
+ add_dependencies (examples example_stdio )
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.16...3.27 )
2
+
3
+ # If you use the example outside of the Rerun SDK you need to specify
4
+ # where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable.
5
+ # This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake.
6
+ if (DEFINED RERUN_REPOSITORY )
7
+ add_executable (example_stdio main.cpp )
8
+ rerun_strict_warning_settings (example_stdio )
9
+ else ()
10
+ project (example_stdio LANGUAGES CXX )
11
+
12
+ add_executable (example_stdio main.cpp )
13
+
14
+ # Set the path to the rerun_c build.
15
+ 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." )
16
+ option (RERUN_FIND_PACKAGE "Whether to use find_package to find a preinstalled rerun package (instead of using FetchContent)." OFF )
17
+
18
+ if (RERUN_FIND_PACKAGE )
19
+ find_package (rerun_sdk REQUIRED )
20
+ else ()
21
+ # Download the rerun_sdk
22
+ include (FetchContent )
23
+ FetchContent_Declare (rerun_sdk URL ${RERUN_CPP_URL} )
24
+ FetchContent_MakeAvailable (rerun_sdk )
25
+ endif ()
26
+
27
+ # Rerun requires at least C++17, but it should be compatible with newer versions.
28
+ set_property (TARGET example_stdio PROPERTY CXX_STANDARD 17 )
29
+ endif ()
30
+
31
+ # Link against rerun_sdk.
32
+ target_link_libraries (example_stdio PRIVATE rerun_sdk )
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Standard Input/Output example
3
+ python : https://github.com/rerun-io/rerun/tree/latest/examples/python/stdio/main.py?speculative-link
4
+ rust : https://github.com/rerun-io/rerun/tree/latest/examples/rust/stdio/src/main.rs?speculative-link
5
+ cpp : https://github.com/rerun-io/rerun/tree/latest/examples/cpp/stdio/main.cpp?speculative-link
6
+ thumbnail : https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/480w.png
7
+ ---
8
+
9
+ <picture >
10
+ <img src =" https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/full.png " alt =" " >
11
+ <source media =" (max-width: 480px) " srcset =" https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/480w.png " >
12
+ <source media =" (max-width: 768px) " srcset =" https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/768w.png " >
13
+ <source media =" (max-width: 1024px) " srcset =" https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/1024w.png " >
14
+ <source media =" (max-width: 1200px) " srcset =" https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/1200w.png " >
15
+ </picture >
16
+
17
+ Demonstrates how to log data to standard output with the Rerun SDK, and then visualize it from standard input with the Rerun Viewer.
18
+
19
+ To build it from a checkout of the repository (requires a Rust toolchain):
20
+ ``` bash
21
+ cmake .
22
+ cmake --build . --target example_stdio
23
+ echo ' hello from stdin!' | ./examples/cpp/stdio/example_stdio | rerun -
24
+ ```
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < string>
3
+
4
+ #include < rerun.hpp>
5
+
6
+ int main () {
7
+ const auto rec = rerun::RecordingStream (" rerun_example_stdio" );
8
+ rec.to_stdout ().exit_on_failure ();
9
+
10
+ std::string input;
11
+ std::string line;
12
+ while (std::getline (std::cin, line)) {
13
+ input += line + ' \n ' ;
14
+ }
15
+
16
+ rec.log (" stdin" , rerun::TextDocument (input));
17
+ }
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ namespace rerun {
45
45
_CategoryRecordingStream = 0x0000'0100 ,
46
46
RecordingStreamCreationFailure,
47
47
RecordingStreamSaveFailure,
48
+ RecordingStreamStdoutFailure,
48
49
RecordingStreamSpawnFailure,
49
50
50
51
// Arrow data processing errors.
Original file line number Diff line number Diff line change @@ -128,6 +128,12 @@ namespace rerun {
128
128
return status;
129
129
}
130
130
131
+ Error RecordingStream::to_stdout () const {
132
+ rr_error status = {};
133
+ rr_recording_stream_stdout (_id, &status);
134
+ return status;
135
+ }
136
+
131
137
void RecordingStream::flush_blocking () const {
132
138
rr_recording_stream_flush_blocking (_id);
133
139
}
You can’t perform that action at this time.
0 commit comments