GRPC C++  1.36.1
channel_arguments.h
Go to the documentation of this file.
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 GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
20 #define GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
21 
22 #include <list>
23 #include <vector>
24 
25 #include <grpc/compression.h>
26 #include <grpc/grpc.h>
27 #include <grpcpp/resource_quota.h>
28 #include <grpcpp/support/config.h>
29 
30 namespace grpc {
31 class SecureChannelCredentials;
32 namespace testing {
33 class ChannelArgumentsTest;
34 } // namespace testing
35 
40  public:
43 
44  ChannelArguments(const ChannelArguments& other);
46  Swap(other);
47  return *this;
48  }
49 
50  void Swap(ChannelArguments& other);
51 
57  void SetChannelArgs(grpc_channel_args* channel_args) const;
58 
59  // gRPC specific channel argument setters
62  void SetSslTargetNameOverride(const std::string& name);
63  // TODO(yangg) add flow control options
66 
71  void SetGrpclbFallbackTimeout(int fallback_timeout);
72 
81 
83  void SetUserAgentPrefix(const std::string& user_agent_prefix);
84 
86  void SetResourceQuota(const grpc::ResourceQuota& resource_quota);
87 
89  void SetMaxReceiveMessageSize(int size);
90  void SetMaxSendMessageSize(int size);
91 
95  void SetLoadBalancingPolicyName(const std::string& lb_policy_name);
96 
99  void SetServiceConfigJSON(const std::string& service_config_json);
100 
101  // Generic channel argument setters. Only for advanced use cases.
103  void SetInt(const std::string& key, int value);
104 
105  // Generic channel argument setter. Only for advanced use cases.
107  void SetPointer(const std::string& key, void* value);
108 
109  void SetPointerWithVtable(const std::string& key, void* value,
110  const grpc_arg_pointer_vtable* vtable);
111 
113  void SetString(const std::string& key, const std::string& value);
114 
118  grpc_channel_args out;
119  out.num_args = args_.size();
120  out.args = args_.empty() ? nullptr : const_cast<grpc_arg*>(&args_[0]);
121  return out;
122  }
123 
124  private:
127 
129  struct PointerVtableMembers {
130  static void* Copy(void* in) { return in; }
131  static void Destroy(void* /*in*/) {}
132  static int Compare(void* a, void* b) {
133  if (a < b) return -1;
134  if (a > b) return 1;
135  return 0;
136  }
137  };
138 
139  // Returns empty string when it is not set.
140  std::string GetSslTargetNameOverride() const;
141 
142  std::vector<grpc_arg> args_;
143  std::list<std::string> strings_;
144 };
145 
146 } // namespace grpc
147 
148 #endif // GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
grpc_arg
A single argument...
Definition: grpc_types.h:103
compression.h
grpc_socket_mutator
struct grpc_socket_mutator grpc_socket_mutator
The Socket Mutator interface allows changes on socket options.
Definition: grpc_types.h:73
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::ChannelArguments::ChannelArgumentsTest
friend class grpc::testing::ChannelArgumentsTest
Definition: channel_arguments.h:126
grpc_compression_algorithm
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:57
grpc::ChannelArguments::SetLoadBalancingPolicyName
void SetLoadBalancingPolicyName(const std::string &lb_policy_name)
Set LB policy name.
grpc::ChannelArguments::SecureChannelCredentials
friend class grpc::SecureChannelCredentials
Definition: channel_arguments.h:125
grpc::ChannelArguments::SetInt
void SetInt(const std::string &key, int value)
Set an integer argument value under key.
grpc_arg_pointer_vtable
Definition: grpc_types.h:85
grpc_channel_args
An array of arguments that can be passed around.
Definition: grpc_types.h:132
grpc::ChannelArguments
Options for channel creation.
Definition: channel_arguments.h:39
grpc::ChannelArguments::Swap
void Swap(ChannelArguments &other)
grpc::ChannelArguments::SetUserAgentPrefix
void SetUserAgentPrefix(const std::string &user_agent_prefix)
Set the string to prepend to the user agent.
grpc::ChannelArguments::SetString
void SetString(const std::string &key, const std::string &value)
Set a textual argument value under key.
grpc.h
grpc::ChannelArguments::SetMaxSendMessageSize
void SetMaxSendMessageSize(int size)
grpc::ChannelArguments::SetMaxReceiveMessageSize
void SetMaxReceiveMessageSize(int size)
Set the max receive and send message sizes.
grpc_channel_args::num_args
size_t num_args
Definition: grpc_types.h:133
grpc::ResourceQuota
ResourceQuota represents a bound on memory and thread usage by the gRPC library.
Definition: resource_quota.h:34
grpc::ChannelArguments::SetGrpclbFallbackTimeout
void SetGrpclbFallbackTimeout(int fallback_timeout)
Set the grpclb fallback timeout (in ms) for the channel.
grpc::ChannelArguments::c_channel_args
grpc_channel_args c_channel_args() const
Return (by value) a C grpc_channel_args structure which points to arguments owned by this ChannelArgu...
Definition: channel_arguments.h:117
grpc::ChannelArguments::SetChannelArgs
void SetChannelArgs(grpc_channel_args *channel_args) const
Dump arguments in this instance to channel_args.
grpc::ChannelArguments::SetServiceConfigJSON
void SetServiceConfigJSON(const std::string &service_config_json)
Set service config in JSON form.
grpc::ChannelArguments::SetSocketMutator
void SetSocketMutator(grpc_socket_mutator *mutator)
For client channel's, the socket mutator operates on "channel" sockets.
resource_quota.h
config.h
grpc::ChannelArguments::SetPointerWithVtable
void SetPointerWithVtable(const std::string &key, void *value, const grpc_arg_pointer_vtable *vtable)
grpc::ChannelArguments::SetResourceQuota
void SetResourceQuota(const grpc::ResourceQuota &resource_quota)
Set the buffer pool to be attached to the constructed channel.
grpc::ChannelArguments::operator=
ChannelArguments & operator=(ChannelArguments other)
Definition: channel_arguments.h:45
grpc::ChannelArguments::~ChannelArguments
~ChannelArguments()
grpc::ChannelArguments::ChannelArguments
ChannelArguments()
grpc::ChannelArguments::SetCompressionAlgorithm
void SetCompressionAlgorithm(grpc_compression_algorithm algorithm)
Set the compression algorithm for the channel.
grpc::ChannelArguments::SetPointer
void SetPointer(const std::string &key, void *value)
Set a pointer argument value under key. Owership is not transferred.
grpc_channel_args::args
grpc_arg * args
Definition: grpc_types.h:134
grpc::ChannelArguments::SetSslTargetNameOverride
void SetSslTargetNameOverride(const std::string &name)
Set target name override for SSL host name checking.