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 19 #ifndef GRPC_SRC_CORE_LIB_SURFACE_LEGACY_CHANNEL_H 20 #define GRPC_SRC_CORE_LIB_SURFACE_LEGACY_CHANNEL_H 21 22 #include <grpc/event_engine/event_engine.h> 23 #include <grpc/grpc.h> 24 #include <grpc/support/port_platform.h> 25 26 #include <string> 27 28 #include "absl/status/statusor.h" 29 #include "absl/types/optional.h" 30 #include "src/core/client_channel/client_channel_filter.h" 31 #include "src/core/lib/channel/channel_args.h" 32 #include "src/core/lib/channel/channel_fwd.h" 33 #include "src/core/lib/channel/channel_stack.h" // IWYU pragma: keep 34 #include "src/core/lib/iomgr/iomgr_fwd.h" 35 #include "src/core/lib/slice/slice.h" 36 #include "src/core/lib/surface/channel.h" 37 #include "src/core/lib/surface/channel_stack_type.h" 38 #include "src/core/lib/transport/call_arena_allocator.h" 39 #include "src/core/lib/transport/transport.h" 40 #include "src/core/telemetry/stats.h" 41 #include "src/core/util/ref_counted_ptr.h" 42 #include "src/core/util/time.h" 43 44 namespace grpc_core { 45 46 class LegacyChannel final : public Channel { 47 public: 48 static absl::StatusOr<RefCountedPtr<Channel>> Create( 49 std::string target, ChannelArgs args, 50 grpc_channel_stack_type channel_stack_type); 51 52 // Do not instantiate directly -- use Create() instead. 53 LegacyChannel(bool is_client, std::string target, 54 const ChannelArgs& channel_args, 55 RefCountedPtr<grpc_channel_stack> channel_stack); 56 57 void Orphaned() override; 58 59 bool IsLame() const override; 60 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; 66 StartCall(UnstartedCallHandler)67 void StartCall(UnstartedCallHandler) override { 68 Crash("StartCall() not supported on LegacyChannel"); 69 } 70 event_engine()71 grpc_event_engine::experimental::EventEngine* event_engine() const override { 72 return channel_stack_->EventEngine(); 73 } 74 75 bool SupportsConnectivityWatcher() const override; 76 77 grpc_connectivity_state CheckConnectivityState(bool try_to_connect) override; 78 79 void WatchConnectivityState(grpc_connectivity_state last_observed_state, 80 Timestamp deadline, grpc_completion_queue* cq, 81 void* tag) override; 82 83 void AddConnectivityWatcher( 84 grpc_connectivity_state initial_state, 85 OrphanablePtr<AsyncConnectivityStateWatcherInterface> watcher) override; 86 void RemoveConnectivityWatcher( 87 AsyncConnectivityStateWatcherInterface* watcher) override; 88 89 void GetInfo(const grpc_channel_info* channel_info) override; 90 91 void ResetConnectionBackoff() override; 92 93 void Ping(grpc_completion_queue* cq, void* tag) override; 94 is_client()95 bool is_client() const override { return is_client_; } channel_stack()96 grpc_channel_stack* channel_stack() const override { 97 return channel_stack_.get(); 98 } 99 100 private: 101 class StateWatcher; 102 103 // Returns the client channel filter if this is a client channel, 104 // otherwise null. 105 ClientChannelFilter* GetClientChannelFilter() const; 106 107 const bool is_client_; 108 RefCountedPtr<grpc_channel_stack> channel_stack_; 109 }; 110 111 } // namespace grpc_core 112 113 #endif // GRPC_SRC_CORE_LIB_SURFACE_LEGACY_CHANNEL_H 114