Rerun C++ SDK
Loading...
Searching...
No Matches
log_sink.hpp
1#pragma once
2
3#include <cstdint>
4#include <string_view>
5#include <utility>
6#include <vector>
7
8struct rr_log_sink;
9
10namespace rerun {
11 /// What happens when a client connects to a gRPC server.
12 enum class PlaybackBehavior {
13 /// Start by playing back all old data, then send data that arrived during playback.
15
16 /// Prioritize newly arriving messages, then replay history from newest to oldest.
18 };
19
20 struct LogSink;
21
22 /// Log sink which streams messages to an existing Rerun gRPC server.
23 ///
24 /// This is a gRPC client: it connects to a server but does not host one.
25 /// Use `GrpcServerSink` to host a server that SDKs and Viewers can connect to.
26 ///
27 /// The behavior of this sink is the same as the one set by `RecordingStream::connect_grpc`.
28 struct GrpcSink {
29 /// A Rerun gRPC URL.
30 ///
31 /// The scheme must be one of `rerun://`, `rerun+http://`, or `rerun+https://`,
32 /// and the pathname must be `/proxy`.
33 ///
34 /// The default is `rerun+http://127.0.0.1:9876/proxy`.
35 std::string_view url = "rerun+http://127.0.0.1:9876/proxy";
36
37 inline operator LogSink() const;
38 };
39
40 /// Log sink which hosts a Rerun gRPC server.
41 ///
42 /// This is a gRPC server: SDKs and Viewers connect to it.
43 /// Use `GrpcSink` to connect as a client to an existing server.
44 ///
45 /// `RecordingStream::set_sinks` copies this configuration into a native sink.
46 /// Destroying this descriptor has no effect on the server.
47 /// Replacing the sinks or destroying the recording shuts the server down.
49 std::string_view bind_ip = "0.0.0.0";
50 uint16_t port = 9876;
51 std::string_view server_memory_limit = "1GiB";
53 std::vector<std::string_view> cors_allow_origins;
54
55 GrpcServerSink() = default;
56
58 std::string_view bind_ip_, uint16_t port_ = 9876,
59 std::string_view server_memory_limit_ = "1GiB",
61 std::vector<std::string_view> cors_allow_origins_ = {}
62 )
63 : bind_ip(bind_ip_),
64 port(port_),
65 server_memory_limit(server_memory_limit_),
66 playback_behavior(playback_behavior_),
67 cors_allow_origins(std::move(cors_allow_origins_)) {}
68
69 inline operator LogSink() const;
70 };
71
72 /// Log sink which writes messages to a file.
73 struct FileSink {
74 /// Path to the output file.
75 std::string_view path;
76
77 inline operator LogSink() const;
78 };
79
80 /// A sink for log messages.
81 ///
82 /// See specific log sink types for more information:
83 /// * `GrpcSink`
84 /// * `GrpcServerSink`
85 /// * `FileSink`
86 struct LogSink {
87 enum class Kind {
88 Grpc = 0,
89 File = 1,
90 GrpcServer = 2,
91 };
92
93 Kind kind;
94
95 union {
96 GrpcSink grpc;
97 FileSink file;
98
99 /// Borrowed only during `RecordingStream::set_sinks`.
100 ///
101 /// `GrpcServerSink` contains a non-trivial `std::vector`, so storing it directly in
102 /// this tagged union would require custom construction and destruction.
103 /// The C bridge copies every field and does not retain this pointer.
105 };
106 };
107
108 inline GrpcSink::operator LogSink() const {
109 LogSink sink{};
110 sink.kind = LogSink::Kind::Grpc;
111 sink.grpc = *this;
112 return sink;
113 }
114
115 inline FileSink::operator LogSink() const {
116 LogSink sink{};
117 sink.kind = LogSink::Kind::File;
118 sink.file = *this;
119 return sink;
120 }
121
122 inline GrpcServerSink::operator LogSink() const {
123 LogSink sink{};
124 sink.kind = LogSink::Kind::GrpcServer;
125 sink.grpc_server = this;
126 return sink;
127 }
128
129 namespace detail {
130 rr_log_sink to_rr_log_sink(LogSink sink);
131 }
132} // namespace rerun
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
PlaybackBehavior
What happens when a client connects to a gRPC server.
Definition log_sink.hpp:12
@ OldestFirst
Start by playing back all old data, then send data that arrived during playback.
@ NewestFirst
Prioritize newly arriving messages, then replay history from newest to oldest.
Log sink which writes messages to a file.
Definition log_sink.hpp:73
std::string_view path
Path to the output file.
Definition log_sink.hpp:75
Log sink which hosts a Rerun gRPC server.
Definition log_sink.hpp:48
Log sink which streams messages to an existing Rerun gRPC server.
Definition log_sink.hpp:28
std::string_view url
A Rerun gRPC URL.
Definition log_sink.hpp:35
A sink for log messages.
Definition log_sink.hpp:86
const GrpcServerSink * grpc_server
Borrowed only during RecordingStream::set_sinks.
Definition log_sink.hpp:104