* @brief Starts the gRPC server on a background thread. */
| 451 | * @brief Starts the gRPC server on a background thread. |
| 452 | */ |
| 453 | void API::GRPC::GRPCServer::startServer() |
| 454 | { |
| 455 | const bool external = API::Server::instance().externalConnections(); |
| 456 | const auto address = external ? QStringLiteral("0.0.0.0:%1").arg(API_GRPC_PORT) |
| 457 | : QStringLiteral("127.0.0.1:%1").arg(API_GRPC_PORT); |
| 458 | |
| 459 | (void)API::CommandHandler::instance(); |
| 460 | |
| 461 | m_service = std::make_unique<SerialStudioServiceImpl>(this); |
| 462 | grpc::ServerBuilder builder; |
| 463 | builder.AddListeningPort(address.toStdString(), grpc::InsecureServerCredentials()); |
| 464 | builder.RegisterService(m_service.get()); |
| 465 | |
| 466 | m_grpcServer = builder.BuildAndStart(); |
| 467 | if (!m_grpcServer) { |
| 468 | m_service.reset(); |
| 469 | Misc::Utilities::showMessageBox(tr("Unable to start gRPC server"), |
| 470 | tr("Failed to bind to %1").arg(address), |
| 471 | QMessageBox::Warning); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | m_serverThread = std::thread([this]() { m_grpcServer->Wait(); }); |
| 476 | |
| 477 | m_writerRunning.store(true); |
| 478 | m_writerThread = std::thread([this]() { writerLoop(); }); |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * @brief Stops the gRPC server and cancels all active streams. |
nothing calls this directly
no test coverage detected