GRPC C++  1.11.0
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/support/config.h>
28 
29 namespace grpc {
30 namespace testing {
31 class ChannelArgumentsTest;
32 } // namespace testing
33 
34 class ResourceQuota;
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 grpc::string& name);
63  // TODO(yangg) add flow control options
65  void SetCompressionAlgorithm(grpc_compression_algorithm algorithm);
66 
71  void SetGrpclbFallbackTimeout(int fallback_timeout);
72 
74  void SetSocketMutator(grpc_socket_mutator* mutator);
75 
77  void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
78 
80  void SetResourceQuota(const ResourceQuota& resource_quota);
81 
83  void SetMaxReceiveMessageSize(int size);
84  void SetMaxSendMessageSize(int size);
85 
89  void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name);
90 
93  void SetServiceConfigJSON(const grpc::string& service_config_json);
94 
95  // Generic channel argument setters. Only for advanced use cases.
97  void SetInt(const grpc::string& key, int value);
98 
99  // Generic channel argument setter. Only for advanced use cases.
101  void SetPointer(const grpc::string& key, void* value);
102 
103  void SetPointerWithVtable(const grpc::string& key, void* value,
104  const grpc_arg_pointer_vtable* vtable);
105 
107  void SetString(const grpc::string& key, const grpc::string& value);
108 
112  grpc_channel_args out;
113  out.num_args = args_.size();
114  out.args = args_.empty() ? NULL : const_cast<grpc_arg*>(&args_[0]);
115  return out;
116  }
117 
118  private:
119  friend class SecureChannelCredentials;
120  friend class testing::ChannelArgumentsTest;
121 
123  struct PointerVtableMembers {
124  static void* Copy(void* in) { return in; }
125  static void Destroy(void* in) {}
126  static int Compare(void* a, void* b) {
127  if (a < b) return -1;
128  if (a > b) return 1;
129  return 0;
130  }
131  };
132 
133  // Returns empty string when it is not set.
134  grpc::string GetSslTargetNameOverride() const;
135 
136  std::vector<grpc_arg> args_;
137  std::list<grpc::string> strings_;
138 };
139 
140 } // namespace grpc
141 
142 #endif // GRPCPP_SUPPORT_CHANNEL_ARGUMENTS_H
std::string string
Definition: config.h:35
An array of arguments that can be passed around.
Definition: grpc_types.h:132
Definition: grpc_types.h:85
grpc_arg * args
Definition: grpc_types.h:134
Options for channel creation.
Definition: channel_arguments.h:39
struct grpc_socket_mutator grpc_socket_mutator
The Socket Mutator interface allows changes on socket options.
Definition: grpc_types.h:73
ResourceQuota represents a bound on memory usage by the gRPC library.
Definition: resource_quota.h:34
A single argument...
Definition: grpc_types.h:103
grpc_compression_algorithm
The various compression algorithms supported by gRPC.
Definition: compression_types.h:56
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
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:111
size_t num_args
Definition: grpc_types.h:133
ChannelArguments & operator=(ChannelArguments other)
Definition: channel_arguments.h:45