3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_IMPL_H
20 #define GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_IMPL_H
25 #include <grpc/compression.h>
26 #include <grpc/grpc.h>
27 #include <grpcpp/resource_quota.h>
28 #include <grpcpp/support/config.h>
32 class ChannelArgumentsTest;
33 } // namespace testing
38 class SecureChannelCredentials;
40 /// Options for channel creation. The user can use generic setters to pass
41 /// key value pairs down to C channel creation code. For gRPC related options,
42 /// concrete setters are provided.
43 class ChannelArguments {
48 ChannelArguments(const ChannelArguments& other);
49 ChannelArguments& operator=(ChannelArguments other) {
54 void Swap(ChannelArguments& other);
56 /// Dump arguments in this instance to \a channel_args. Does not take
57 /// ownership of \a channel_args.
59 /// Note that the underlying arguments are shared. Changes made to either \a
60 /// channel_args or this instance would be reflected on both.
61 void SetChannelArgs(grpc_channel_args* channel_args) const;
63 // gRPC specific channel argument setters
64 /// Set target name override for SSL host name checking. This option is for
65 /// testing only and should never be used in production.
66 void SetSslTargetNameOverride(const grpc::string& name);
67 // TODO(yangg) add flow control options
68 /// Set the compression algorithm for the channel.
69 void SetCompressionAlgorithm(grpc_compression_algorithm algorithm);
71 /// Set the grpclb fallback timeout (in ms) for the channel. If this amount
72 /// of time has passed but we have not gotten any non-empty \a serverlist from
73 /// the balancer, we will fall back to use the backend address(es) returned by
75 void SetGrpclbFallbackTimeout(int fallback_timeout);
77 /// For client channel's, the socket mutator operates on
78 /// "channel" sockets. For server's, the socket mutator operates
79 /// only on "listen" sockets.
80 /// TODO(apolcyn): allow socket mutators to also operate
81 /// on server "channel" sockets, and adjust the socket mutator
82 /// object to be more speficic about which type of socket
83 /// it should operate on.
84 void SetSocketMutator(grpc_socket_mutator* mutator);
86 /// Set the string to prepend to the user agent.
87 void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
89 /// Set the buffer pool to be attached to the constructed channel.
90 void SetResourceQuota(const grpc::ResourceQuota& resource_quota);
92 /// Set the max receive and send message sizes.
93 void SetMaxReceiveMessageSize(int size);
94 void SetMaxSendMessageSize(int size);
96 /// Set LB policy name.
97 /// Note that if the name resolver returns only balancer addresses, the
98 /// grpclb LB policy will be used, regardless of what is specified here.
99 void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name);
101 /// Set service config in JSON form.
102 /// Primarily meant for use in unit tests.
103 void SetServiceConfigJSON(const grpc::string& service_config_json);
105 // Generic channel argument setters. Only for advanced use cases.
106 /// Set an integer argument \a value under \a key.
107 void SetInt(const grpc::string& key, int value);
109 // Generic channel argument setter. Only for advanced use cases.
110 /// Set a pointer argument \a value under \a key. Owership is not transferred.
111 void SetPointer(const grpc::string& key, void* value);
113 void SetPointerWithVtable(const grpc::string& key, void* value,
114 const grpc_arg_pointer_vtable* vtable);
116 /// Set a textual argument \a value under \a key.
117 void SetString(const grpc::string& key, const grpc::string& value);
119 /// Return (by value) a C \a grpc_channel_args structure which points to
120 /// arguments owned by this \a ChannelArguments instance
121 grpc_channel_args c_channel_args() const {
122 grpc_channel_args out;
123 out.num_args = args_.size();
124 out.args = args_.empty() ? NULL : const_cast<grpc_arg*>(&args_[0]);
129 friend class grpc_impl::SecureChannelCredentials;
130 friend class grpc::testing::ChannelArgumentsTest;
132 /// Default pointer argument operations.
133 struct PointerVtableMembers {
134 static void* Copy(void* in) { return in; }
135 static void Destroy(void* in) {}
136 static int Compare(void* a, void* b) {
137 if (a < b) return -1;
143 // Returns empty string when it is not set.
144 grpc::string GetSslTargetNameOverride() const;
146 std::vector<grpc_arg> args_;
147 std::list<grpc::string> strings_;
150 } // namespace grpc_impl
152 #endif // GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_IMPL_H