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
22// IWYU pragma: private, include <grpcpp/impl/grpc_library.h>
23
24#include <grpcpp/impl/codegen/core_codegen_interface.h>
25
26namespace grpc {
27
28class GrpcLibraryInterface {
29 public:
30 virtual ~GrpcLibraryInterface() = default;
31 virtual void init() = 0;
32 virtual void shutdown() = 0;
33};
34
35/// Initialized by \a grpc::GrpcLibraryInitializer from
36/// <grpcpp/impl/grpc_library.h>
37extern GrpcLibraryInterface* g_glip;
38
39/// Classes that require gRPC to be initialized should inherit from this class.
40class GrpcLibraryCodegen {
41 public:
42 explicit GrpcLibraryCodegen(bool call_grpc_init = true)
43 : grpc_init_called_(false) {
44 if (call_grpc_init) {
45 GPR_CODEGEN_ASSERT(g_glip &&
46 "gRPC library not initialized. See "
47 "grpc::internal::GrpcLibraryInitializer.");
48 g_glip->init();
49 grpc_init_called_ = true;
50 }
51 }
52 virtual ~GrpcLibraryCodegen() {
53 if (grpc_init_called_) {
54 GPR_CODEGEN_ASSERT(g_glip &&
55 "gRPC library not initialized. See "
56 "grpc::internal::GrpcLibraryInitializer.");
57 g_glip->shutdown();
58 }
59 }
60
61 private:
62 bool grpc_init_called_;
63};
64
65} // namespace grpc
66
67#endif // GRPCPP_IMPL_CODEGEN_GRPC_LIBRARY_H
68

source code of include/grpcpp/impl/codegen/grpc_library.h