Skip to content

Commit 565cf4c

Browse files
authored
RSDK-10579: Robot client update (#425)
1 parent c949ca0 commit 565cf4c

File tree

7 files changed

+174
-177
lines changed

7 files changed

+174
-177
lines changed

src/viam/sdk/common/client_helper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ bool isStatusCancelled(int status) noexcept {
2323
return status == ::grpc::StatusCode::CANCELLED;
2424
}
2525

26+
void set_name(...) {} // NOLINT(cert-dcl50-cpp)
27+
2628
} // namespace client_helper_details
2729

2830
ClientContext::ClientContext() : wrapped_context_(std::make_unique<GrpcClientContext>()) {

src/viam/sdk/common/client_helper.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ namespace client_helper_details {
1515
// Helper function to test equality of status with grpc::StatusCode::CANCELLED.
1616
bool isStatusCancelled(int status) noexcept;
1717

18+
// Set the mutable name of a request to the client name.
19+
// This function only participates in overload resolution if the request has a mutable_name method.
20+
template <typename RequestType,
21+
typename ClientType,
22+
typename = decltype(&RequestType::mutable_name)>
23+
void set_name(RequestType* req, const ClientType* client) {
24+
*req->mutable_name() = client->name();
25+
}
26+
27+
// No-op version of set_name above. This overload is only selected if the request type does not have
28+
// a mutable_name field.
29+
void set_name(...);
30+
1831
} // namespace client_helper_details
1932

2033
// the authority on a grpc::ClientContext is sometimes set to an invalid uri on mac, causing
@@ -96,7 +109,7 @@ class ClientHelper {
96109

97110
template <typename ResponseHandlerCallable, typename ErrorHandlerCallable>
98111
auto invoke(ResponseHandlerCallable&& rhc, ErrorHandlerCallable&& ehc) {
99-
*request_.mutable_name() = client_->name();
112+
client_helper_details::set_name(&request_, client_);
100113
ClientContext ctx;
101114

102115
if (debug_key_ != "") {

src/viam/sdk/log/logging.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ void LogManager::init_logging() {
133133
console_sink_ = boost::make_shared<
134134
boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend>>(backend);
135135

136-
console_sink_->set_filter(Filter{this});
136+
boost::log::core::get()->add_sink(console_sink_);
137+
137138
console_sink_->set_formatter(fmt);
139+
enable_console_logging();
140+
}
138141

139-
boost::log::core::get()->add_sink(console_sink_);
140-
VIAM_SDK_LOG(debug) << "Initialized console logging";
142+
void LogManager::enable_console_logging() {
143+
console_sink_->set_filter(Filter{this});
144+
VIAM_SDK_LOG(debug) << "Console logging enabled";
141145
}
142146

143147
void LogManager::disable_console_logging() {

src/viam/sdk/log/logging.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class LogManager {
113113
LogManager& operator=(LogManager&&) = delete;
114114

115115
void init_logging();
116+
void enable_console_logging();
116117
void disable_console_logging();
117118

118119
LogSource sdk_logger_;

0 commit comments

Comments
 (0)