Skip to content

Commit 29e6c7e

Browse files
authored
Merge branch 'main' into conan-windows
2 parents f7200a0 + 74575e2 commit 29e6c7e

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

src/viam/sdk/log/logging.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ void LogManager::set_global_log_level(log_level lvl) {
105105
}
106106

107107
void LogManager::set_global_log_level(int argc, char** argv) {
108-
if (argc >= 3 && strcmp(argv[2], "--log-level=debug") == 0) {
109-
set_global_log_level(log_level::debug);
108+
for (int i = 0; i < argc; ++i) {
109+
if (strcmp(argv[i], "--log-level=debug") == 0) {
110+
set_global_log_level(log_level::debug);
111+
return;
112+
}
110113
}
111114
}
112115

@@ -147,8 +150,8 @@ void LogManager::enable_console_logging() {
147150
void LogManager::disable_console_logging() {
148151
VIAM_SDK_LOG(debug) << "Disabling console logging";
149152

150-
// Set a filter which ignores all console logs unless they contain a console force flag which is
151-
// set to true.
153+
// Set a filter which ignores all console logs unless they contain a console force flag
154+
// which is set to true.
152155
console_sink_->set_filter(
153156
[filter = Filter{this}](const boost::log::attribute_value_set& attrs) {
154157
auto force = attrs[impl::attr_console_force_type{}];

src/viam/sdk/module/service.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
namespace viam {
4949
namespace sdk {
5050

51+
namespace {
52+
std::string get_protocol(int argc, char** argv) {
53+
for (int i = 0; i < argc; ++i) {
54+
if (strcmp(argv[i], "--tcp-mode") == 0) {
55+
return "dns:";
56+
}
57+
}
58+
return "unix:";
59+
}
60+
} // namespace
61+
5162
struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
5263
ServiceImpl(ModuleService& p) : parent(p) {}
5364

@@ -191,7 +202,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
191202
const std::lock_guard<std::mutex> lock(parent.lock_);
192203
const viam::module::v1::HandlerMap hm = to_proto(parent.module_->handles());
193204
*response->mutable_handlermap() = hm;
194-
auto new_parent_addr = request->parent_address();
205+
auto new_parent_addr = parent.grpc_conn_protocol_ + request->parent_address();
195206
if (parent.parent_addr_ != new_parent_addr) {
196207
parent.parent_addr_ = std::move(new_parent_addr);
197208
Options opts{0, boost::none};
@@ -233,21 +244,27 @@ std::shared_ptr<Resource> ModuleService::get_parent_resource_(const Name& name)
233244
return parent_->resource_by_name(name);
234245
}
235246

236-
ModuleService::ModuleService(std::string addr)
237-
: module_(std::make_unique<Module>(std::move(addr))), server_(std::make_unique<Server>()) {
247+
ModuleService::ModuleService(std::string addr) : ModuleService(std::move(addr), "unix:") {}
248+
249+
ModuleService::ModuleService(std::string addr, std::string grpc_conn_protocol)
250+
: module_(std::make_unique<Module>(std::move(addr))),
251+
grpc_conn_protocol_(std::move(grpc_conn_protocol)),
252+
server_(std::make_unique<Server>()) {
238253
impl_ = std::make_unique<ServiceImpl>(*this);
239254
}
240255

241256
ModuleService::ModuleService(int argc,
242257
char** argv,
243258
const std::vector<std::shared_ptr<ModelRegistration>>& registrations)
244-
: ModuleService([argc, argv] {
245-
if (argc < 2) {
246-
throw Exception(ErrorCondition::k_connection,
247-
"Need socket path as command line argument");
248-
}
249-
return argv[1];
250-
}()) {
259+
: ModuleService(
260+
[argc, argv] {
261+
if (argc < 2) {
262+
throw Exception(ErrorCondition::k_connection,
263+
"Need socket path as command line argument");
264+
}
265+
return (argv[1]);
266+
}(),
267+
get_protocol(argc, argv)) {
251268
LogManager::get().set_global_log_level(argc, argv);
252269

253270
for (auto&& mr : registrations) {
@@ -272,8 +289,7 @@ ModuleService::~ModuleService() {
272289

273290
void ModuleService::serve() {
274291
server_->register_service(impl_.get());
275-
const std::string address = "unix:" + module_->addr();
276-
server_->add_listening_port(address);
292+
server_->add_listening_port(grpc_conn_protocol_ + module_->addr());
277293

278294
module_->set_ready();
279295
server_->start();

src/viam/sdk/module/service.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class ModuleService {
3333
/// @param addr Address of socket to serve on.
3434
explicit ModuleService(std::string addr);
3535

36+
/// @brief Creates a new ModuleService that can serve on the provided socket.
37+
/// @param addr Address of socket to serve on.
38+
/// @param grpc_conn_protocol The protocol to connect with (UDS or TCP)
39+
explicit ModuleService(std::string addr, std::string grpc_conn_protocol);
40+
3641
/// @brief Creates a new ModuleService. Socket path and log level will be
3742
/// inferred from passed in command line arguments, and passed in model
3843
/// registrations will be registered and added to module.
@@ -70,6 +75,7 @@ class ModuleService {
7075

7176
std::shared_ptr<RobotClient> parent_;
7277
std::string parent_addr_;
78+
std::string grpc_conn_protocol_;
7379

7480
std::unique_ptr<Server> server_;
7581

src/viam/sdk/robot/client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ std::shared_ptr<RobotClient> RobotClient::at_address(const std::string& address,
363363

364364
std::shared_ptr<RobotClient> RobotClient::at_local_socket(const std::string& address,
365365
const Options& options) {
366-
const std::string addr = "unix:" + address;
366+
// TODO (RSDK-10720) - refactor/replace `at_local_socket`
367367
auto robot = RobotClient::with_channel(
368-
ViamChannel(sdk::impl::create_viam_channel(addr, grpc::InsecureChannelCredentials())),
368+
ViamChannel(sdk::impl::create_viam_channel(address, grpc::InsecureChannelCredentials())),
369369
options);
370370

371371
return robot;

src/viam/sdk/rpc/dial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ ViamChannel ViamChannel::dial(const char* uri, const boost::optional<DialOptions
183183
std::string address;
184184
if (std::string(proxy_path).find(localhost_prefix) == std::string::npos) {
185185
// proxy path is not a localhost address and is therefore a unix domain socket (UDS)
186+
// TODO (RSDK-10747) - update rust-utils to include this information directly, so that
187+
// the SDKs don't have to.
186188
address += "unix:";
187189
}
188190
address += proxy_path;

0 commit comments

Comments
 (0)