MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / startServer

Method startServer

app/src/API/GRPC/GRPCServer.cpp:453–479  ·  view source on GitHub ↗

* @brief Starts the gRPC server on a background thread. */

Source from the content-addressed store, hash-verified

451 * @brief Starts the gRPC server on a background thread.
452 */
453void 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.

Callers

nothing calls this directly

Calls 3

externalConnectionsMethod · 0.80
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected