1 // Copyright 2024 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H 16 #define GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H 17 18 #include <grpc/support/port_platform.h> 19 20 #include "src/core/lib/transport/call_spine.h" 21 #include "src/core/util/orphanable.h" 22 23 namespace grpc_core { 24 25 // UnstartedCallDestination is responsible for starting an UnstartedCallHandler 26 // and then processing operations on the resulting CallHandler. 27 // 28 // Examples of UnstartedCallDestinations include: 29 // - a load-balanced call in the client channel 30 // - a hijacking filter (see Interceptor) 31 class UnstartedCallDestination 32 : public DualRefCounted<UnstartedCallDestination> { 33 public: 34 using DualRefCounted::DualRefCounted; 35 36 ~UnstartedCallDestination() override = default; 37 // Start a call. The UnstartedCallHandler will be consumed by the Destination 38 // and started. 39 // Must be called from the party owned by the call, eg the following must 40 // hold: 41 // CHECK(GetContext<Activity>() == unstarted_call_handler.party()); 42 virtual void StartCall(UnstartedCallHandler unstarted_call_handler) = 0; 43 }; 44 45 // CallDestination is responsible for handling processing of an already started 46 // call. 47 // 48 // Examples of CallDestinations include: 49 // - a client transport 50 // - the server API 51 class CallDestination : public DualRefCounted<CallDestination> { 52 public: 53 virtual void HandleCall(CallHandler unstarted_call_handler) = 0; 54 }; 55 56 template <typename HC> MakeCallDestinationFromHandlerFunction(HC handle_call)57auto MakeCallDestinationFromHandlerFunction(HC handle_call) { 58 class Impl : public CallDestination { 59 public: 60 explicit Impl(HC handle_call) : handle_call_(std::move(handle_call)) {} 61 62 void Orphaned() override {} 63 64 void HandleCall(CallHandler call_handler) override { 65 handle_call_(std::move(call_handler)); 66 } 67 68 private: 69 HC handle_call_; 70 }; 71 return MakeRefCounted<Impl>(std::move(handle_call)); 72 } 73 74 } // namespace grpc_core 75 76 #endif // GRPC_SRC_CORE_LIB_TRANSPORT_CALL_DESTINATION_H 77