call.h 2.7 KB

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