Viam C++ SDK current
Loading...
Searching...
No Matches
dial.hpp
1#pragma once
2
3#include <chrono>
4#include <memory>
5#include <optional>
6#include <string>
7
8#include <viam/sdk/common/grpc_fwd.hpp>
9
10namespace viam {
11namespace sdk {
12
14 public:
15 Credentials(std::string type, std::string payload);
16 const std::string& type() const;
17 const std::string& payload() const;
18
19 private:
20 std::string type_;
21 std::string payload_;
22};
23
25 ViamChannel(std::shared_ptr<GrpcChannel> channel, char* path, void* runtime);
26
27 public:
28 class Options {
29 public:
30 Options();
31
32 const std::optional<Credentials>& credentials() const;
33 const std::optional<std::string>& entity() const;
34 bool allows_insecure_downgrade() const;
35 bool webrtc_disabled() const;
36 const std::chrono::duration<float>& timeout() const;
37 int initial_connection_attempts() const;
38 std::chrono::duration<float> initial_connection_attempt_timeout() const;
39
41 Options& set_entity(std::optional<std::string> entity);
42
44 Options& set_credentials(std::optional<Credentials> creds);
45
49
54 Options& set_webrtc_disabled(bool disable_webrtc);
55
58 Options& set_timeout(std::chrono::duration<float> timeout);
59
63
66 Options& set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout);
67
68 private:
69 std::optional<std::string> auth_entity_;
70
71 std::optional<Credentials> credentials_;
72
73 bool allow_insecure_downgrade_ = false;
74
75 bool disable_webrtc_ = false;
76
77 std::chrono::duration<float> timeout_{20};
78
79 int initial_connection_attempts_ = 3;
80
81 std::chrono::duration<float> initial_connection_attempt_timeout_{20};
82 };
83
84 explicit ViamChannel(std::shared_ptr<GrpcChannel> channel);
85
86 ViamChannel(ViamChannel&&) noexcept;
87
88 ViamChannel& operator=(ViamChannel&&) noexcept;
89
90 ~ViamChannel();
91
98 static ViamChannel dial(const char* uri, const std::optional<Options>& options);
99
108 static ViamChannel dial_initial(const char* uri, const std::optional<Options>& options);
109
110 const std::shared_ptr<GrpcChannel>& channel() const;
111
117 const std::optional<std::string>& auth_token() const;
118
120 const char* get_channel_addr() const;
121
125 void close();
126
127 private:
128 struct impl;
129 friend class ViamClient;
130
131 static ViamChannel dial_direct(const char* uri, const Options& opts);
132
133 const char* uri_;
134
135 std::unique_ptr<impl> pimpl_;
136};
137
138using DialOptions
139 [[deprecated("This class is now a member class of ViamChannel::Options. The alias DialOptions "
140 "may be removed in a future version")]] = ViamChannel::Options;
141
144
145class Options {
146 public:
147 Options(unsigned int refresh_interval, std::optional<ViamChannel::Options> channel_options)
148 : refresh_interval_(std::move(refresh_interval)),
149 channel_options_(std::move(channel_options)) {}
150
153 std::chrono::seconds refresh_interval() const;
154
155 std::chrono::seconds check_every_interval() const;
156
157 std::chrono::seconds reconnect_every_interval() const;
158
163 Options& set_check_every_interval(std::chrono::seconds interval);
164
169 Options& set_reconnect_every_interval(std::chrono::seconds interval);
170
171 [[deprecated("Please update your function calls to channel_options")]] //
172 const std::optional<ViamChannel::Options>&
173 dial_options() const;
174
175 const std::optional<ViamChannel::Options>& channel_options() const;
176
177 private:
178 std::chrono::seconds refresh_interval_{0};
179
180 std::chrono::seconds check_every_interval_{0};
181
182 std::chrono::seconds reconnect_every_interval_{0};
183
184 std::optional<ViamChannel::Options> channel_options_;
185};
186
187} // namespace sdk
188} // namespace viam
Definition dial.hpp:13
Options & set_reconnect_every_interval(std::chrono::seconds interval)
Sets how often to attempt to reconnect to the robot when disconnected. If set to 0,...
std::chrono::seconds refresh_interval() const
How often to refresh the status/parts of the robot, in seconds. If set to 0, the robot will not autom...
Options & set_check_every_interval(std::chrono::seconds interval)
Sets how often to verify connectivity to the robot, in seconds. If set to 0, will not check,...
Definition dial.hpp:28
Options & set_initial_connection_attempts(int attempts)
Set the number of attempts to make when initially connecting to a robot If set to 0 or a negative int...
Options & set_initial_connection_attempt_timeout(std::chrono::duration< float > timeout)
Set the timeout of connection attempts when initially dialing a robot Defaults to 20sec to match the ...
Options & set_timeout(std::chrono::duration< float > timeout)
Set the duration before the dial connection times out Set to 20sec to match _defaultOfferDeadline in ...
Options & set_webrtc_disabled(bool disable_webrtc)
Set whether to bypass WebRTC and connect directly to the robot. This dials directly through grpc bypa...
Options & set_allow_insecure_downgrade(bool allow)
Set whether to allow the RPC connection to be downgraded to an insecure connection if detected....
Options & set_credentials(std::optional< Credentials > creds)
Set Credentials for connecting to the robot.
Options & set_entity(std::optional< std::string > entity)
Set the URL to authenticate against.
Definition dial.hpp:24
const std::optional< std::string > & auth_token() const
Returns the bearer token for connecting to the robot if one is needed; else returns null.
void close()
Closes the connection of this channel to its associated robot. This method is called by the destructo...
const char * get_channel_addr() const
Returns the address of the robot to which this channel is connected.
static ViamChannel dial(const char *uri, const std::optional< Options > &options)
Connects to a robot at the given URI address, using the provided dial options (or default options is ...
static ViamChannel dial_initial(const char *uri, const std::optional< Options > &options)
Dials to a robot at the given URI address, using the provided dial options (or default options is non...
Definition viam_client.hpp:6