You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

grpc_library.h 2.2 kB

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