| #pragma once | |
| #include <memory> | |
| #include <string> | |
| #include <thread> // NOLINT(build/c++11) | |
| #include "baremetal_callback.h" | |
| #include "biossettings_callback.h" | |
| #include "boottime_callback.h" | |
| #include "smbios_callback.h" | |
| #include "grpcpp/server_builder.h" | |
| namespace blobs { | |
| class GrpcInstance { | |
| public: | |
| explicit GrpcInstance(int instanceNumber, const std::string& basePath = "") | |
| : instance(instanceNumber), | |
| basePath_(basePath), | |
| smbiosServiceCallback( | |
| std::make_unique<SmbiosTransferServiceImpl>(instance, basePath)), | |
| biosSettingGrpcService( | |
| std::make_unique<BiosSettingsServiceImpl>(instance, basePath)), | |
| bmServiceCallback( | |
| std::make_unique<BaremetalTransferServiceImpl>(instance, basePath)), | |
| bootTimeServiceCallback( | |
| std::make_unique<BootTimeServiceImpl>(instance, basePath)) {} | |
| void start(); | |
| void stop(); | |
| protected: | |
| [[nodiscard]] std::string threadId(const std::thread& thread) const; | |
| [[nodiscard]] bool validatePreviousFile() const; | |
| void restoreLink(); | |
| void threadRun(); | |
| private: | |
| int instance; | |
| std::string basePath_; | |
| // Incoming gRPC requests arrive here | |
| // This is a pointer because gRPC RegisterService() requires it | |
| std::unique_ptr<SmbiosTransferServiceImpl> smbiosServiceCallback; | |
| std::unique_ptr<BiosSettingsServiceImpl> biosSettingGrpcService; | |
| std::unique_ptr<BaremetalTransferServiceImpl> bmServiceCallback; | |
| std::unique_ptr<BootTimeServiceImpl> bootTimeServiceCallback; | |
| // Here, and below, do not need parameters in constructor | |
| // This is a pointer because gRPC BuildAndStart() requires it | |
| std::unique_ptr<grpc::Server> grpcServer; | |
| // Not pointer, this has no prerequisites and can directly construct | |
| grpc::ServerBuilder grpcBuilder; | |
| // Should be unique, but gRPC API requires it to be shared | |
| std::shared_ptr<grpc::ServerCredentials> grpcCredentials; | |
| // gRPC runs its own event loop and does not use ASIO | |
| // This is a pointer because we need to construct it later | |
| std::unique_ptr<std::thread> grpcThread; | |
| }; | |
| } // namespace blobs |