GRPC C++  1.30.0
grpc_library.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
20 #define GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
21 
23 
24 namespace grpc {
25 
27  public:
28  virtual ~GrpcLibraryInterface() = default;
29  virtual void init() = 0;
30  virtual void shutdown() = 0;
31 };
32 
36 
39  public:
40  GrpcLibraryCodegen(bool call_grpc_init = true) : grpc_init_called_(false) {
41  if (call_grpc_init) {
43  "gRPC library not initialized. See "
44  "grpc::internal::GrpcLibraryInitializer.");
45  g_glip->init();
46  grpc_init_called_ = true;
47  }
48  }
49  virtual ~GrpcLibraryCodegen() {
50  if (grpc_init_called_) {
52  "gRPC library not initialized. See "
53  "grpc::internal::GrpcLibraryInitializer.");
54  g_glip->shutdown();
55  }
56  }
57 
58  private:
59  bool grpc_init_called_;
60 };
61 
62 } // namespace grpc
63 
64 #endif // GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
grpc::GrpcLibraryCodegen
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:38
grpc
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
grpc::GrpcLibraryCodegen::~GrpcLibraryCodegen
virtual ~GrpcLibraryCodegen()
Definition: grpc_library.h:49
grpc::GrpcLibraryCodegen::GrpcLibraryCodegen
GrpcLibraryCodegen(bool call_grpc_init=true)
Definition: grpc_library.h:40
core_codegen_interface.h
grpc::GrpcLibraryInterface
Definition: grpc_library.h:26
grpc::GrpcLibraryInterface::~GrpcLibraryInterface
virtual ~GrpcLibraryInterface()=default
grpc::GrpcLibraryInterface::shutdown
virtual void shutdown()=0
grpc::g_glip
GrpcLibraryInterface * g_glip
Initialized by grpc::GrpcLibraryInitializer from <grpcpp/impl/grpc_library.h>
GPR_CODEGEN_ASSERT
#define GPR_CODEGEN_ASSERT(x)
Codegen specific version of GPR_ASSERT.
Definition: core_codegen_interface.h:146
grpc::GrpcLibraryInterface::init
virtual void init()=0