Skip to content

Commit 69eea20

Browse files
committed
pr comments, actually use new logic when creating robotclient
1 parent 4183152 commit 69eea20

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

src/viam/sdk/robot/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ std::shared_ptr<RobotClient> RobotClient::with_channel(std::shared_ptr<ViamChann
256256
std::shared_ptr<RobotClient> RobotClient::at_address(const std::string& address,
257257
const Options& options) {
258258
const char* uri = address.c_str();
259-
auto channel = ViamChannel::dial(uri, options.dial_options());
259+
auto channel = ViamChannel::dial_initial(uri, options.dial_options());
260260
std::shared_ptr<RobotClient> robot = RobotClient::with_channel(channel, options);
261261
robot->should_close_channel_ = true;
262262

src/viam/sdk/rpc/dial.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,35 @@ ViamChannel::ViamChannel(std::shared_ptr<grpc::Channel> channel, const char* pat
5252

5353
DialOptions::DialOptions() = default;
5454

55-
void DialOptions::set_credentials(boost::optional<Credentials> creds) {
55+
DialOptions& DialOptions::set_credentials(boost::optional<Credentials> creds) {
5656
credentials_ = std::move(creds);
57+
58+
return *this;
5759
}
5860

59-
void DialOptions::set_entity(boost::optional<std::string> entity) {
61+
DialOptions& DialOptions::set_entity(boost::optional<std::string> entity) {
6062
auth_entity_ = std::move(entity);
63+
64+
return *this;
6165
}
6266

63-
void DialOptions::set_initial_connection_attempts(int attempts) {
67+
DialOptions& DialOptions::set_initial_connection_attempts(int attempts) {
6468
initial_connection_attempts_ = attempts;
69+
70+
return *this;
6571
}
6672

67-
void DialOptions::set_timeout(std::chrono::duration<float> timeout) {
68-
timeout_ = std::move(timeout);
73+
DialOptions& DialOptions::set_timeout(std::chrono::duration<float> timeout) {
74+
timeout_ = timeout;
75+
76+
return *this;
6977
}
7078

71-
void DialOptions::set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout) {
72-
initial_connection_attempt_timeout_ = std::move(timeout);
79+
DialOptions& DialOptions::set_initial_connection_attempt_timeout(
80+
std::chrono::duration<float> timeout) {
81+
initial_connection_attempt_timeout_ = timeout;
82+
83+
return *this;
7384
}
7485

7586
const boost::optional<std::string>& DialOptions::entity() const {
@@ -88,25 +99,22 @@ const std::chrono::duration<float>& DialOptions::timeout() const {
8899
return timeout_;
89100
}
90101

91-
const std::chrono::duration<float>& DialOptions::initial_connection_attempt_timeout() const {
102+
std::chrono::duration<float> DialOptions::initial_connection_attempt_timeout() const {
92103
return initial_connection_attempt_timeout_;
93104
}
94105

95-
void DialOptions::set_allow_insecure_downgrade(bool allow) {
106+
DialOptions& DialOptions::set_allow_insecure_downgrade(bool allow) {
96107
allow_insecure_downgrade_ = allow;
108+
109+
return *this;
97110
}
98111

99112
bool DialOptions::allows_insecure_downgrade() const {
100113
return allow_insecure_downgrade_;
101114
}
102115

103-
std::shared_ptr<ViamChannel> ViamChannel::dial(const char* uri,
104-
const boost::optional<DialOptions>& options,
105-
bool initial_attempt) {
106-
if (!initial_attempt) {
107-
return dial(std::move(uri), options);
108-
}
109-
116+
std::shared_ptr<ViamChannel> ViamChannel::dial_initial(
117+
const char* uri, const boost::optional<DialOptions>& options) {
110118
DialOptions opts = options.get_value_or(DialOptions());
111119
auto timeout = opts.timeout();
112120
auto attempts_remaining = opts.initial_connection_attempts();
@@ -120,7 +128,7 @@ std::shared_ptr<ViamChannel> ViamChannel::dial(const char* uri,
120128
auto connection = dial(uri, opts);
121129
opts.set_timeout(timeout);
122130
return connection;
123-
} catch (...) {
131+
} catch (const std::exception&) {
124132
attempts_remaining -= 1;
125133
}
126134
}

src/viam/sdk/rpc/dial.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class ViamChannel {
2020
static std::shared_ptr<ViamChannel> dial(const char* uri,
2121
const boost::optional<DialOptions>& options);
2222

23-
// allows for specifying that this dial is an initial connection attempt, indicating that
24-
// initial connection options should be used.
25-
static std::shared_ptr<ViamChannel> dial(const char* uri,
26-
const boost::optional<DialOptions>& options,
27-
bool initial_attempt);
23+
// Specifies that this dial is an initial connection attempt and that initial connection options
24+
// should be used.
25+
static std::shared_ptr<ViamChannel> dial_initial(const char* uri,
26+
const boost::optional<DialOptions>& options);
2827

2928
const std::shared_ptr<GrpcChannel>& channel() const;
3029

@@ -57,14 +56,14 @@ class DialOptions {
5756
bool allows_insecure_downgrade() const;
5857
const std::chrono::duration<float>& timeout() const;
5958
int initial_connection_attempts() const;
60-
const std::chrono::duration<float>& initial_connection_attempt_timeout() const;
61-
62-
void set_entity(boost::optional<std::string> entity);
63-
void set_credentials(boost::optional<Credentials> creds);
64-
void set_allow_insecure_downgrade(bool allow);
65-
void set_timeout(std::chrono::duration<float> timeout);
66-
void set_initial_connection_attempts(int attempts);
67-
void set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout);
59+
std::chrono::duration<float> initial_connection_attempt_timeout() const;
60+
61+
DialOptions& set_entity(boost::optional<std::string> entity);
62+
DialOptions& set_credentials(boost::optional<Credentials> creds);
63+
DialOptions& set_allow_insecure_downgrade(bool allow);
64+
DialOptions& set_timeout(std::chrono::duration<float> timeout);
65+
DialOptions& set_initial_connection_attempts(int attempts);
66+
DialOptions& set_initial_connection_attempt_timeout(std::chrono::duration<float> timeout);
6867

6968
private:
7069
// TODO (RSDK-917): We currently don't provide a flag for disabling webRTC, instead relying on a

0 commit comments

Comments
 (0)