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

Standard input/output support 4: C++ SDK stdout impl/examples/docs #4514

Merged
merged 8 commits into from
Dec 14, 2023
Merged
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
Next Next commit
add C support for RecordingStream::stdout
teh-cmc committed Dec 14, 2023
commit 06df4087752e3319c16ac4821f97e449b562dd29
19 changes: 19 additions & 0 deletions crates/rerun_c/src/lib.rs
Original file line number Diff line number Diff line change
@@ -161,6 +161,7 @@ pub enum CErrorCode {
_CategoryRecordingStream = 0x0000_00100,
RecordingStreamCreationFailure,
RecordingStreamSaveFailure,
RecordingStreamStdoutFailure,
// TODO(cmc): Really this should be its own category…
RecordingStreamSpawnFailure,

@@ -468,6 +469,24 @@ pub extern "C" fn rr_recording_stream_save(
}
}

#[allow(clippy::result_large_err)]
fn rr_recording_stream_stdout_impl(stream: CRecordingStream) -> Result<(), CError> {
recording_stream(stream)?.stdout().map_err(|err| {
CError::new(
CErrorCode::RecordingStreamStdoutFailure,
&format!("Failed to forward recording stream to stdout: {err}"),
)
})
}

#[allow(unsafe_code)]
#[no_mangle]
pub extern "C" fn rr_recording_stream_stdout(id: CRecordingStream, error: *mut CError) {
if let Err(err) = rr_recording_stream_stdout_impl(id) {
err.write_error(error);
}
}

#[allow(clippy::result_large_err)]
fn rr_recording_stream_set_time_sequence_impl(
stream: CRecordingStream,
11 changes: 11 additions & 0 deletions crates/rerun_c/src/rerun.h
Original file line number Diff line number Diff line change
@@ -198,6 +198,7 @@ enum {
_RR_ERROR_CODE_CATEGORY_RECORDING_STREAM = 0x000000100,
RR_ERROR_CODE_RECORDING_STREAM_CREATION_FAILURE,
RR_ERROR_CODE_RECORDING_STREAM_SAVE_FAILURE,
RR_ERROR_CODE_RECORDING_STREAM_STDOUT_FAILURE,
RR_ERROR_CODE_RECORDING_STREAM_SPAWN_FAILURE,

// Arrow data processing errors.
@@ -333,6 +334,16 @@ extern void rr_recording_stream_spawn(
/// This function returns immediately.
extern void rr_recording_stream_save(rr_recording_stream stream, rr_string path, rr_error* error);

/// Stream all log-data to stdout.
///
/// Pipe the result into the Rerun Viewer to visualize it.
///
/// If there isn't any listener at the other end of the pipe, the `RecordingStream` will
/// default back to `buffered` mode, in order not to break the user's terminal.
///
/// This function returns immediately.
extern void rr_recording_stream_stdout(rr_recording_stream stream, rr_error* error);

/// Initiates a flush the batching pipeline and waits for it to propagate.
///
/// See `rr_recording_stream` docs for ordering semantics and multithreading guarantees.