• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 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_GRPC_LIBRARY_H
20 #define GRPCPP_IMPL_GRPC_LIBRARY_H
21 
22 #include <iostream>
23 
24 #include <grpc/grpc.h>
25 #include <grpcpp/impl/codegen/config.h>
26 #include <grpcpp/impl/codegen/core_codegen.h>
27 #include <grpcpp/impl/codegen/grpc_library.h>
28 
29 namespace grpc {
30 
31 namespace internal {
32 class GrpcLibrary final : public GrpcLibraryInterface {
33  public:
init()34   void init() override { grpc_init(); }
shutdown()35   void shutdown() override { grpc_shutdown(); }
36 };
37 
38 static GrpcLibrary g_gli;
39 static CoreCodegen g_core_codegen;
40 
41 /// Instantiating this class ensures the proper initialization of gRPC.
42 class GrpcLibraryInitializer final {
43  public:
GrpcLibraryInitializer()44   GrpcLibraryInitializer() {
45     if (grpc::g_glip == nullptr) {
46       grpc::g_glip = &g_gli;
47     }
48     if (grpc::g_core_codegen_interface == nullptr) {
49       grpc::g_core_codegen_interface = &g_core_codegen;
50     }
51   }
52 
53   /// A no-op method to force the linker to reference this class, which will
54   /// take care of initializing and shutting down the gRPC runtime.
summon()55   int summon() { return 0; }
56 };
57 
58 }  // namespace internal
59 }  // namespace grpc
60 
61 #endif  // GRPCPP_IMPL_GRPC_LIBRARY_H
62