| #include "grpcblob_server.h" | |
| #include <array> | |
| #include <memory> | |
| #include "absl/log/log.h" | |
| #include "grpc_instance.h" | |
| #include "grpcblob_defs.h" | |
| #include "grpcpp/ext/proto_server_reflection_plugin.h" | |
| #include "grpcpp/health_check_service_interface.h" | |
| namespace blobs { | |
| class GrpcBlobDetails { | |
| public: | |
| explicit GrpcBlobDetails() { | |
| auto size = static_cast<int>(instances.size()); | |
| for (int i = 0; i < size; ++i) { | |
| instances[i] = std::make_unique<GrpcInstance>(i); | |
| } | |
| } | |
| void start() { | |
| auto size = static_cast<int>(instances.size()); | |
| for (int i = 0; i < size; ++i) { | |
| LOG(INFO) << "GrpcBlobDetails STARTING GrpcInstance " << i; | |
| instances[i]->start(); | |
| } | |
| } | |
| void stop() { | |
| auto size = static_cast<int>(instances.size()); | |
| for (int i = 0; i < size; ++i) { | |
| instances[i]->stop(); | |
| } | |
| } | |
| private: | |
| std::array<std::unique_ptr<GrpcInstance>, numInstances> instances; | |
| }; | |
| GrpcBlobServer::GrpcBlobServer() | |
| : details(std::make_shared<GrpcBlobDetails>()) {} | |
| void GrpcBlobServer::start() { | |
| LOG(INFO) << "SMBIOS gRPC server: Starting"; | |
| // Universal gRPC server boilerplate | |
| grpc::EnableDefaultHealthCheckService(true); | |
| grpc::reflection::InitProtoReflectionServerBuilderPlugin(); | |
| details->start(); | |
| } | |
| void GrpcBlobServer::stop() { | |
| LOG(INFO) << "SMBIOS gRPC server: Stopping"; | |
| details->stop(); | |
| } | |
| } // namespace blobs |