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

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