|
|
|
@ -51,18 +51,26 @@ extern GrpcLibraryInterface* g_glip; |
|
|
|
|
/// Classes that require gRPC to be initialized should inherit from this class.
|
|
|
|
|
class GrpcLibraryCodegen { |
|
|
|
|
public: |
|
|
|
|
GrpcLibraryCodegen() { |
|
|
|
|
GPR_CODEGEN_ASSERT(g_glip && |
|
|
|
|
"gRPC library not initialized. See " |
|
|
|
|
"grpc::internal::GrpcLibraryInitializer."); |
|
|
|
|
g_glip->init(); |
|
|
|
|
GrpcLibraryCodegen(bool call_grpc_init = true) : grpc_init_called(false) { |
|
|
|
|
if (call_grpc_init) { |
|
|
|
|
GPR_CODEGEN_ASSERT(g_glip && |
|
|
|
|
"gRPC library not initialized. See " |
|
|
|
|
"grpc::internal::GrpcLibraryInitializer."); |
|
|
|
|
g_glip->init(); |
|
|
|
|
grpc_init_called = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
virtual ~GrpcLibraryCodegen() { |
|
|
|
|
GPR_CODEGEN_ASSERT(g_glip && |
|
|
|
|
"gRPC library not initialized. See " |
|
|
|
|
"grpc::internal::GrpcLibraryInitializer."); |
|
|
|
|
g_glip->shutdown(); |
|
|
|
|
if (grpc_init_called) { |
|
|
|
|
GPR_CODEGEN_ASSERT(g_glip && |
|
|
|
|
"gRPC library not initialized. See " |
|
|
|
|
"grpc::internal::GrpcLibraryInitializer."); |
|
|
|
|
g_glip->shutdown(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
bool grpc_init_called; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
} // namespace grpc
|
|
|
|
|