call.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_CALL_H
  19. #define GRPCPP_IMPL_CALL_H
  20. #include <grpc/impl/grpc_types.h>
  21. #include <grpcpp/impl/call_hook.h>
  22. namespace grpc {
  23. class CompletionQueue;
  24. namespace experimental {
  25. class ClientRpcInfo;
  26. class ServerRpcInfo;
  27. } // namespace experimental
  28. namespace internal {
  29. class CallHook;
  30. class CallOpSetInterface;
  31. /// Straightforward wrapping of the C call object
  32. class Call final {
  33. public:
  34. Call()
  35. : call_hook_(nullptr),
  36. cq_(nullptr),
  37. call_(nullptr),
  38. max_receive_message_size_(-1) {}
  39. /// call is owned by the caller
  40. Call(grpc_call* call, CallHook* call_hook, grpc::CompletionQueue* cq)
  41. : call_hook_(call_hook),
  42. cq_(cq),
  43. call_(call),
  44. max_receive_message_size_(-1) {}
  45. Call(grpc_call* call, CallHook* call_hook, grpc::CompletionQueue* cq,
  46. experimental::ClientRpcInfo* rpc_info)
  47. : call_hook_(call_hook),
  48. cq_(cq),
  49. call_(call),
  50. max_receive_message_size_(-1),
  51. client_rpc_info_(rpc_info) {}
  52. Call(grpc_call* call, CallHook* call_hook, grpc::CompletionQueue* cq,
  53. int max_receive_message_size, experimental::ServerRpcInfo* rpc_info)
  54. : call_hook_(call_hook),
  55. cq_(cq),
  56. call_(call),
  57. max_receive_message_size_(max_receive_message_size),
  58. server_rpc_info_(rpc_info) {}
  59. void PerformOps(CallOpSetInterface* ops) {
  60. call_hook_->PerformOpsOnCall(ops, this);
  61. }
  62. grpc_call* call() const { return call_; }
  63. grpc::CompletionQueue* cq() const { return cq_; }
  64. int max_receive_message_size() const { return max_receive_message_size_; }
  65. experimental::ClientRpcInfo* client_rpc_info() const {
  66. return client_rpc_info_;
  67. }
  68. experimental::ServerRpcInfo* server_rpc_info() const {
  69. return server_rpc_info_;
  70. }
  71. private:
  72. CallHook* call_hook_;
  73. grpc::CompletionQueue* cq_;
  74. grpc_call* call_;
  75. int max_receive_message_size_;
  76. experimental::ClientRpcInfo* client_rpc_info_ = nullptr;
  77. experimental::ServerRpcInfo* server_rpc_info_ = nullptr;
  78. };
  79. } // namespace internal
  80. } // namespace grpc
  81. #endif // GRPCPP_IMPL_CALL_H