• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2016 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_LAME_CLIENT_H
20 #define GRPC_SRC_CORE_LIB_SURFACE_LAME_CLIENT_H
21 
22 #include <grpc/grpc.h>
23 #include <grpc/support/port_platform.h>
24 
25 #include <memory>
26 
27 #include "absl/base/thread_annotations.h"
28 #include "absl/status/status.h"
29 #include "absl/status/statusor.h"
30 #include "src/core/lib/channel/channel_args.h"
31 #include "src/core/lib/channel/channel_fwd.h"
32 #include "src/core/lib/channel/promise_based_filter.h"
33 #include "src/core/lib/iomgr/error.h"
34 #include "src/core/lib/promise/arena_promise.h"
35 #include "src/core/lib/transport/connectivity_state.h"
36 #include "src/core/lib/transport/transport.h"
37 #include "src/core/util/sync.h"
38 
39 #define GRPC_ARG_LAME_FILTER_ERROR "grpc.lame_filter_error"
40 
41 namespace grpc_core {
42 
43 // This filter becomes the entire channel stack for a channel that fails to be
44 // created. Every call returns failure.
45 class LameClientFilter : public ChannelFilter {
46  public:
47   static const grpc_channel_filter kFilter;
48 
TypeName()49   static absl::string_view TypeName() { return "lame-client"; }
50 
51   explicit LameClientFilter(absl::Status error);
52 
53   static absl::StatusOr<std::unique_ptr<LameClientFilter>> Create(
54       const ChannelArgs& args, ChannelFilter::Args filter_args);
55   ArenaPromise<ServerMetadataHandle> MakeCallPromise(
56       CallArgs call_args, NextPromiseFactory next_promise_factory) override;
57   bool StartTransportOp(grpc_transport_op*) override;
58   bool GetChannelInfo(const grpc_channel_info*) override;
59 
60  private:
61   absl::Status error_;
62   Mutex mu_;
63   ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(mu_);
64 };
65 
66 extern const grpc_arg_pointer_vtable kLameFilterErrorArgVtable;
67 
68 grpc_arg MakeLameClientErrorArg(grpc_error_handle* error);
69 
70 }  // namespace grpc_core
71 
72 #endif  // GRPC_SRC_CORE_LIB_SURFACE_LAME_CLIENT_H
73