Skip to content

Commit 914e9e7

Browse files
committed
support for tcp-mode flag
1 parent 16819e0 commit 914e9e7

File tree

5 files changed

+31
-47
lines changed

5 files changed

+31
-47
lines changed

src/viam/examples/modules/simple/main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ int main(int argc, char** argv) try {
9595
&MySensor::validate);
9696

9797
std::vector<std::shared_ptr<ModelRegistration>> mrs = {mr};
98-
VIAM_SDK_LOG(info) << "making my_mod!";
9998
auto my_mod = std::make_shared<ModuleService>(argc, argv, mrs);
100-
VIAM_SDK_LOG(info) << "about to serve!";
10199
my_mod->serve();
102100

103101
return EXIT_SUCCESS;

src/viam/sdk/module/service.cpp

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ struct ModuleService::ServiceImpl : viam::module::v1::ModuleService::Service {
192192
const std::lock_guard<std::mutex> lock(parent.lock_);
193193
const viam::module::v1::HandlerMap hm = to_proto(parent.module_->handles());
194194
*response->mutable_handlermap() = hm;
195-
auto new_parent_addr = parent.parent_addr_protocol_ + request->parent_address();
195+
auto new_parent_addr = parent.grpc_conn_protocol_ + request->parent_address();
196196
if (parent.parent_addr_ != new_parent_addr) {
197197
parent.parent_addr_ = std::move(new_parent_addr);
198198
Options opts{0, boost::none};
@@ -234,51 +234,38 @@ std::shared_ptr<Resource> ModuleService::get_parent_resource_(const Name& name)
234234
return parent_->resource_by_name(name);
235235
}
236236

237-
namespace {
237+
ModuleService::ModuleService(std::string addr) : ModuleService(std::move(addr), "unix:") {}
238238

239-
bool tcp_set() {
240-
// NOLINTNEXTLINE
241-
const char* using_tcp = std::getenv("VIAM_TCP_SOCKETS");
242-
if (!using_tcp) {
243-
return false;
244-
}
245-
std::vector<std::string> true_values{"true", "yes", "1", "TRUE", "YES"};
246-
return std::any_of(true_values.begin(), true_values.end(), [&](const std::string& v) {
247-
return using_tcp == v;
248-
});
239+
ModuleService::ModuleService(std::string addr, std::string grpc_conn_protocol)
240+
: module_(std::make_unique<Module>(std::move(addr))),
241+
grpc_conn_protocol_(std::move(grpc_conn_protocol)),
242+
server_(std::make_unique<Server>()) {
243+
impl_ = std::make_unique<ServiceImpl>(*this);
249244
}
250245

251-
std::string get_parent_addr_protocol() {
252-
VIAM_SDK_LOG(info) << "getting protocol!!";
253-
// NOLINTNEXTLINE
254-
const char* protocol = std::getenv("VIAM_PARENT_ADDR_PROTOCOL");
255-
if (!protocol) {
256-
if (tcp_set()) {
246+
namespace {
247+
std::string get_protocol(int argc, char** argv) {
248+
for (int i = 0; i < argc; ++i) {
249+
if (strcmp(argv[i], "--tcp-mode") == 0) {
257250
return "dns:";
258251
}
259-
return "unix:";
260252
}
261-
return std::string(protocol);
253+
return "unix:";
262254
}
263255
} // namespace
264256

265-
ModuleService::ModuleService(std::string addr)
266-
: module_(std::make_unique<Module>(std::move(addr))),
267-
parent_addr_protocol_(get_parent_addr_protocol()),
268-
server_(std::make_unique<Server>()) {
269-
impl_ = std::make_unique<ServiceImpl>(*this);
270-
}
271-
272257
ModuleService::ModuleService(int argc,
273258
char** argv,
274259
const std::vector<std::shared_ptr<ModelRegistration>>& registrations)
275-
: ModuleService([argc, argv] {
276-
if (argc < 2) {
277-
throw Exception(ErrorCondition::k_connection,
278-
"Need socket path as command line argument");
279-
}
280-
return argv[1];
281-
}()) {
260+
: ModuleService(
261+
[argc, argv] {
262+
if (argc < 2) {
263+
throw Exception(ErrorCondition::k_connection,
264+
"Need socket path as command line argument");
265+
}
266+
return (argv[1]);
267+
}(),
268+
get_protocol(argc, argv)) {
282269
LogManager::get().set_global_log_level(argc, argv);
283270

284271
for (auto&& mr : registrations) {
@@ -302,10 +289,8 @@ ModuleService::~ModuleService() {
302289
}
303290

304291
void ModuleService::serve() {
305-
std::cout << "trying to start serving!!\n\n\n";
306-
std::cout << "we have " << parent_addr_protocol_ << " and " << module_->addr();
307292
server_->register_service(impl_.get());
308-
server_->add_listening_port(parent_addr_protocol_ + module_->addr());
293+
server_->add_listening_port(grpc_conn_protocol_ + module_->addr());
309294

310295
module_->set_ready();
311296
server_->start();

src/viam/sdk/module/service.hpp

Lines changed: 6 additions & 2 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,8 +75,7 @@ class ModuleService {
7075

7176
std::shared_ptr<RobotClient> parent_;
7277
std::string parent_addr_;
73-
// CR erodkin: rename to `grpc_conn_protocol`
74-
std::string parent_addr_protocol_;
78+
std::string grpc_conn_protocol_;
7579

7680
std::unique_ptr<Server> server_;
7781

src/viam/sdk/robot/client.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,7 @@ 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-
// CR erodkin: this function is now totally pointless, so let's get rid of it
367-
// otoh, it's public and someone _could_ be using it... maybe we leave it around just in case?
368-
std::cout << "\n\n\n\t\t address is " << address << "\n\n" << std::flush;
369-
// auto addr = "unix:" + address;
366+
// TODO (RSDK-10720) - refactor/replace `at_local_socket`
370367
auto robot = RobotClient::with_channel(
371368
ViamChannel(sdk::impl::create_viam_channel(address, grpc::InsecureChannelCredentials())),
372369
options);

src/viam/sdk/rpc/dial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ 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-
std::cout << "\n\n\n\t\t\tsomehow this is happening\n\n\n";
186+
// TODO (RSDK-10747) - update rust-utils to include this information directly, so that
187+
// the SDKs don't have to.
187188
address += "unix:";
188189
}
189190
address += proxy_path;
190-
std::cout << "address is " << address << "\n\n";
191191

192192
auto chan =
193193
ViamChannel(sdk::impl::create_viam_channel(address, grpc::InsecureChannelCredentials()),

0 commit comments

Comments
 (0)