4848namespace viam {
4949namespace 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+
5162struct 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
241256ModuleService::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
273290void 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 ();
0 commit comments