rpc_method.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. namespace internal {
  25. /// Descriptor of an RPC method
  26. class RpcMethod {
  27. public:
  28. enum RpcType {
  29. NORMAL_RPC = 0,
  30. CLIENT_STREAMING, // request streaming
  31. SERVER_STREAMING, // response streaming
  32. BIDI_STREAMING
  33. };
  34. RpcMethod(const char* name, RpcType type)
  35. : name_(name),
  36. suffix_for_stats_(nullptr),
  37. method_type_(type),
  38. channel_tag_(nullptr) {}
  39. RpcMethod(const char* name, const char* suffix_for_stats, RpcType type)
  40. : name_(name),
  41. suffix_for_stats_(suffix_for_stats),
  42. method_type_(type),
  43. channel_tag_(nullptr) {}
  44. RpcMethod(const char* name, RpcType type,
  45. const std::shared_ptr<ChannelInterface>& channel)
  46. : name_(name),
  47. suffix_for_stats_(nullptr),
  48. method_type_(type),
  49. channel_tag_(channel->RegisterMethod(name)) {}
  50. RpcMethod(const char* name, const char* suffix_for_stats, RpcType type,
  51. const std::shared_ptr<ChannelInterface>& channel)
  52. : name_(name),
  53. suffix_for_stats_(suffix_for_stats),
  54. method_type_(type),
  55. channel_tag_(channel->RegisterMethod(name)) {}
  56. const char* name() const { return name_; }
  57. const char* suffix_for_stats() const { return suffix_for_stats_; }
  58. RpcType method_type() const { return method_type_; }
  59. void SetMethodType(RpcType type) { method_type_ = type; }
  60. void* channel_tag() const { return channel_tag_; }
  61. private:
  62. const char* const name_;
  63. const char* const suffix_for_stats_;
  64. RpcType method_type_;
  65. void* const channel_tag_;
  66. };
  67. } // namespace internal
  68. } // namespace grpc
  69. #endif // GRPCPP_IMPL_CODEGEN_RPC_METHOD_H