Viam C++ SDK current
Loading...
Searching...
No Matches
dial.hpp
1#pragma once
2
3#include <chrono>
4#include <memory>
5#include <string>
6
7#include <boost/optional.hpp>
8
9#include <viam/sdk/common/grpc_fwd.hpp>
10
11namespace viam {
12namespace sdk {
13
15 public:
16 Credentials(std::string type, std::string payload);
17 const std::string& type() const;
18 const std::string& payload() const;
19
20 private:
21 std::string type_;
22 std::string payload_;
23};
24
26 ViamChannel(std::shared_ptr<GrpcChannel> channel, char* path, void* runtime);
27
28 public:
29 class Options {
30 public:
31 Options();
32
33 const boost::optional<Credentials>& credentials() const;
34 const boost::optional<std::string>& entity() const;
35 bool allows_insecure_downgrade() const;
36 bool webrtc_disabled() const;
37 const std::chrono::duration<float>& timeout() const;
38 int initial_connection_attempts() const;
39 std::chrono::duration<float> initial_connection_attempt_timeout() const;
40
42 Options& set_entity(boost::optional<std::string> entity);
43
45 Options& set_credentials(boost::optional<Credentials> creds);
46
50
55 Options& set_webrtc_disabled(bool disable_webrtc);
56
59 Options& set_timeout(std::chrono::duration<float> timeout);
60
64
67 Options& set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout);
68
69 private:
70 boost::optional<std::string> auth_entity_;
71
72 boost::optional<Credentials> credentials_;
73
74 bool allow_insecure_downgrade_ = false;
75
76 bool disable_webrtc_ = false;
77
78 std::chrono::duration<float> timeout_{20};
79
80 int initial_connection_attempts_ = 3;
81
82 std::chrono::duration<float> initial_connection_attempt_timeout_{20};
83 };
84
85 explicit ViamChannel(std::shared_ptr<GrpcChannel> channel);
86
87 ViamChannel(ViamChannel&&) noexcept;
88
89 ViamChannel& operator=(ViamChannel&&) noexcept;
90
91 ~ViamChannel();
92
99 static ViamChannel dial(const char* uri, const boost::optional<Options>& options);
100
109 static ViamChannel dial_initial(const char* uri, const boost::optional<Options>& options);
110
111 const std::shared_ptr<GrpcChannel>& channel() const;
112
118 const boost::optional<std::string>& auth_token() const;
119
121 const char* get_channel_addr() const;
122
126 void close();
127
128 private:
129 struct impl;
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, boost::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 boost::optional<ViamChannel::Options>&
173 dial_options() const;
174
175 const boost::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 boost::optional<ViamChannel::Options> channel_options_;
185};
186
187} // namespace sdk
188} // namespace viam
Definition dial.hpp:14
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:29
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_entity(boost::optional< std::string > entity)
Set the URL to authenticate against.
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_credentials(boost::optional< Credentials > creds)
Set Credentials for connecting to the robot.
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....
Definition dial.hpp:25
const boost::optional< std::string > & auth_token() const
Returns the bearer token for connecting to the robot if one is needed; else returns null.
static ViamChannel dial(const char *uri, const boost::optional< Options > &options)
Connects to a robot at the given URI address, using the provided dial options (or default options is ...
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_initial(const char *uri, const boost::optional< Options > &options)
Dials to a robot at the given URI address, using the provided dial options (or default options is non...