@@ -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-
272257ModuleService::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
304291void 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 ();
0 commit comments