• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_INTERNAL_H
18 #define GRPC_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_INTERNAL_H
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include <utility>
23 
24 #include "absl/functional/any_invocable.h"
25 #include "absl/log/check.h"
26 #include "src/core/lib/resource_quota/arena.h"
27 #include "src/core/lib/transport/call_destination.h"
28 #include "src/core/load_balancing/lb_policy.h"
29 #include "src/core/service_config/service_config_call_data.h"
30 #include "src/core/telemetry/call_tracer.h"
31 #include "src/core/util/down_cast.h"
32 #include "src/core/util/unique_type_name.h"
33 
34 //
35 // This file contains internal interfaces used to allow various plugins
36 // (filters, LB policies, etc) to access internal data provided by the
37 // ClientChannelFilter that is not normally accessible via external APIs.
38 //
39 
40 // Channel arg key for health check service name.
41 #define GRPC_ARG_HEALTH_CHECK_SERVICE_NAME \
42   "grpc.internal.health_check_service_name"
43 
44 namespace grpc_core {
45 
46 // Internal type for LB call state interface.  Provides an interface for
47 // LB policies to access internal call attributes.
48 class ClientChannelLbCallState : public LoadBalancingPolicy::CallState {
49  public:
50   template <typename A>
GetCallAttribute()51   A* GetCallAttribute() const {
52     return DownCast<A*>(GetCallAttribute(A::TypeName()));
53   }
54 
55   virtual ServiceConfigCallData::CallAttributeInterface* GetCallAttribute(
56       UniqueTypeName type) const = 0;
57   virtual ClientCallTracer::CallAttemptTracer* GetCallAttemptTracer() const = 0;
58 };
59 
60 // Internal type for ServiceConfigCallData.  Handles call commits.
61 class ClientChannelServiceConfigCallData final : public ServiceConfigCallData {
62  public:
ClientChannelServiceConfigCallData(Arena * arena)63   explicit ClientChannelServiceConfigCallData(Arena* arena)
64       : ServiceConfigCallData(arena) {}
65 
SetOnCommit(absl::AnyInvocable<void ()> on_commit)66   void SetOnCommit(absl::AnyInvocable<void()> on_commit) {
67     CHECK(on_commit_ == nullptr);
68     on_commit_ = std::move(on_commit);
69   }
70 
Commit()71   void Commit() {
72     auto on_commit = std::move(on_commit_);
73     if (on_commit != nullptr) on_commit();
74   }
75 
76  private:
77   absl::AnyInvocable<void()> on_commit_;
78 };
79 
80 template <>
81 struct ContextSubclass<ClientChannelServiceConfigCallData> {
82   using Base = ServiceConfigCallData;
83 };
84 
85 class SubchannelInterfaceWithCallDestination : public SubchannelInterface {
86  public:
87   using SubchannelInterface::SubchannelInterface;
88   // Obtain the call destination for this subchannel.
89   virtual RefCountedPtr<UnstartedCallDestination> call_destination() = 0;
90 };
91 
92 }  // namespace grpc_core
93 
94 #endif  // GRPC_SRC_CORE_CLIENT_CHANNEL_CLIENT_CHANNEL_INTERNAL_H
95