• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CLIENT_CHANNEL_DIRECT_CHANNEL_H
16 #define GRPC_SRC_CORE_CLIENT_CHANNEL_DIRECT_CHANNEL_H
17 
18 #include <memory>
19 
20 #include "src/core/lib/surface/channel.h"
21 #include "src/core/lib/transport/transport.h"
22 
23 namespace grpc_core {
24 
25 class DirectChannel final : public Channel {
26  public:
27   class TransportCallDestination final : public CallDestination {
28    public:
TransportCallDestination(OrphanablePtr<ClientTransport> transport)29     explicit TransportCallDestination(OrphanablePtr<ClientTransport> transport)
30         : transport_(std::move(transport)) {}
31 
transport()32     ClientTransport* transport() { return transport_.get(); }
33 
HandleCall(CallHandler handler)34     void HandleCall(CallHandler handler) override {
35       transport_->StartCall(std::move(handler));
36     }
37 
Orphaned()38     void Orphaned() override { transport_.reset(); }
39 
40    private:
41     OrphanablePtr<ClientTransport> transport_;
42   };
43 
44   static absl::StatusOr<RefCountedPtr<DirectChannel>> Create(
45       std::string target, const ChannelArgs& args);
46 
DirectChannel(std::string target,const ChannelArgs & args,std::shared_ptr<grpc_event_engine::experimental::EventEngine> event_engine,RefCountedPtr<TransportCallDestination> transport_call_destination,RefCountedPtr<UnstartedCallDestination> interception_chain)47   DirectChannel(
48       std::string target, const ChannelArgs& args,
49       std::shared_ptr<grpc_event_engine::experimental::EventEngine>
50           event_engine,
51       RefCountedPtr<TransportCallDestination> transport_call_destination,
52       RefCountedPtr<UnstartedCallDestination> interception_chain)
53       : Channel(std::move(target), args),
54         transport_call_destination_(std::move(transport_call_destination)),
55         interception_chain_(std::move(interception_chain)),
56         event_engine_(std::move(event_engine)) {}
57 
58   void Orphaned() override;
59   void StartCall(UnstartedCallHandler unstarted_handler) override;
IsLame()60   bool IsLame() const override { return false; }
61   grpc_call* CreateCall(grpc_call* parent_call, uint32_t propagation_mask,
62                         grpc_completion_queue* cq,
63                         grpc_pollset_set* pollset_set_alternative, Slice path,
64                         absl::optional<Slice> authority, Timestamp deadline,
65                         bool registered_method) override;
event_engine()66   grpc_event_engine::experimental::EventEngine* event_engine() const override {
67     return event_engine_.get();
68   }
SupportsConnectivityWatcher()69   bool SupportsConnectivityWatcher() const override { return false; }
CheckConnectivityState(bool)70   grpc_connectivity_state CheckConnectivityState(bool) override {
71     Crash("CheckConnectivityState not supported");
72   }
WatchConnectivityState(grpc_connectivity_state,Timestamp,grpc_completion_queue *,void *)73   void WatchConnectivityState(grpc_connectivity_state, Timestamp,
74                               grpc_completion_queue*, void*) override {
75     Crash("WatchConnectivityState not supported");
76   }
AddConnectivityWatcher(grpc_connectivity_state,OrphanablePtr<AsyncConnectivityStateWatcherInterface>)77   void AddConnectivityWatcher(
78       grpc_connectivity_state,
79       OrphanablePtr<AsyncConnectivityStateWatcherInterface>) override {
80     Crash("AddConnectivityWatcher not supported");
81   }
RemoveConnectivityWatcher(AsyncConnectivityStateWatcherInterface *)82   void RemoveConnectivityWatcher(
83       AsyncConnectivityStateWatcherInterface*) override {
84     Crash("RemoveConnectivityWatcher not supported");
85   }
86   void GetInfo(const grpc_channel_info* channel_info) override;
ResetConnectionBackoff()87   void ResetConnectionBackoff() override {}
Ping(grpc_completion_queue *,void *)88   void Ping(grpc_completion_queue*, void*) override {
89     Crash("Ping not supported");
90   }
91 
92  private:
93   RefCountedPtr<TransportCallDestination> transport_call_destination_;
94   RefCountedPtr<UnstartedCallDestination> interception_chain_;
95   const std::shared_ptr<grpc_event_engine::experimental::EventEngine>
96       event_engine_;
97 };
98 
99 }  // namespace grpc_core
100 
101 #endif  // GRPC_SRC_CORE_CLIENT_CHANNEL_DIRECT_CHANNEL_H
102