• 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 /// Instantiating this class ensures the proper initialization of gRPC.
39 class GrpcLibraryInitializer final {
40  public:
GrpcLibraryInitializer()41   GrpcLibraryInitializer() {
42     if (grpc::g_glip == nullptr) {
43       static auto* const g_gli = new GrpcLibrary();
44       grpc::g_glip = g_gli;
45     }
46     if (grpc::g_core_codegen_interface == nullptr) {
47       static auto* const g_core_codegen = new CoreCodegen();
48       grpc::g_core_codegen_interface = g_core_codegen;
49     }
50   }
51 
52   /// A no-op method to force the linker to reference this class, which will
53   /// take care of initializing and shutting down the gRPC runtime.
summon()54   int summon() { return 0; }
55 };
56 
57 }  // namespace internal
58 }  // namespace grpc
59 
60 #endif  // GRPCPP_IMPL_GRPC_LIBRARY_H
61