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.

rpc_method.h 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_CODEGEN_RPC_METHOD_H
  19. #define GRPCPP_IMPL_CODEGEN_RPC_METHOD_H
  20. // IWYU pragma: private, include <grpcpp/impl/rpc_method.h>
  21. #include <memory>
  22. #include <grpcpp/impl/codegen/channel_interface.h>
  23. namespace grpc
  24. {
  25. namespace internal
  26. {
  27. /// Descriptor of an RPC method
  28. class RpcMethod
  29. {
  30. public:
  31. enum RpcType
  32. {
  33. NORMAL_RPC = 0,
  34. CLIENT_STREAMING, // request streaming
  35. SERVER_STREAMING, // response streaming
  36. BIDI_STREAMING
  37. };
  38. RpcMethod(const char* name, RpcType type) :
  39. name_(name),
  40. suffix_for_stats_(nullptr),
  41. method_type_(type),
  42. channel_tag_(nullptr)
  43. {
  44. }
  45. RpcMethod(const char* name, const char* suffix_for_stats, RpcType type) :
  46. name_(name),
  47. suffix_for_stats_(suffix_for_stats),
  48. method_type_(type),
  49. channel_tag_(nullptr)
  50. {
  51. }
  52. RpcMethod(const char* name, RpcType type, const std::shared_ptr<ChannelInterface>& channel) :
  53. name_(name),
  54. suffix_for_stats_(nullptr),
  55. method_type_(type),
  56. channel_tag_(channel->RegisterMethod(name))
  57. {
  58. }
  59. RpcMethod(const char* name, const char* suffix_for_stats, RpcType type, const std::shared_ptr<ChannelInterface>& channel) :
  60. name_(name),
  61. suffix_for_stats_(suffix_for_stats),
  62. method_type_(type),
  63. channel_tag_(channel->RegisterMethod(name))
  64. {
  65. }
  66. const char* name() const
  67. {
  68. return name_;
  69. }
  70. const char* suffix_for_stats() const
  71. {
  72. return suffix_for_stats_;
  73. }
  74. RpcType method_type() const
  75. {
  76. return method_type_;
  77. }
  78. void SetMethodType(RpcType type)
  79. {
  80. method_type_ = type;
  81. }
  82. void* channel_tag() const
  83. {
  84. return channel_tag_;
  85. }
  86. private:
  87. const char* const name_;
  88. const char* const suffix_for_stats_;
  89. RpcType method_type_;
  90. void* const channel_tag_;
  91. };
  92. } // namespace internal
  93. } // namespace grpc
  94. #endif // GRPCPP_IMPL_CODEGEN_RPC_METHOD_H