GRPC C++  1.6.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
20 #define GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
21 
22 #include <list>
23 #include <vector>
24 
25 #include <grpc++/support/config.h>
26 #include <grpc/compression.h>
27 #include <grpc/grpc.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
66 
69 
71  void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
72 
74  void SetResourceQuota(const ResourceQuota& resource_quota);
75 
77  void SetMaxReceiveMessageSize(int size);
78  void SetMaxSendMessageSize(int size);
79 
83  void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name);
84 
87  void SetServiceConfigJSON(const grpc::string& service_config_json);
88 
89  // Generic channel argument setters. Only for advanced use cases.
91  void SetInt(const grpc::string& key, int value);
92 
93  // Generic channel argument setter. Only for advanced use cases.
95  void SetPointer(const grpc::string& key, void* value);
96 
97  void SetPointerWithVtable(const grpc::string& key, void* value,
98  const grpc_arg_pointer_vtable* vtable);
99 
101  void SetString(const grpc::string& key, const grpc::string& value);
102 
106  grpc_channel_args out;
107  out.num_args = args_.size();
108  out.args = args_.empty() ? NULL : const_cast<grpc_arg*>(&args_[0]);
109  return out;
110  }
111 
112  private:
115 
117  struct PointerVtableMembers {
118  static void* Copy(void* in) { return in; }
119  static void Destroy(grpc_exec_ctx* exec_ctx, void* in) {}
120  static int Compare(void* a, void* b) {
121  if (a < b) return -1;
122  if (a > b) return 1;
123  return 0;
124  }
125  };
126 
127  // Returns empty string when it is not set.
128  grpc::string GetSslTargetNameOverride() const;
129 
130  std::vector<grpc_arg> args_;
131  std::list<grpc::string> strings_;
132 };
133 
134 } // namespace grpc
135 
136 #endif // GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
void SetMaxReceiveMessageSize(int size)
Set the max receive and send message sizes.
friend class testing::ChannelArgumentsTest
Definition: channel_arguments.h:114
std::string string
Definition: config.h:35
void SetString(const grpc::string &key, const grpc::string &value)
Set a textual argument value under key.
An array of arguments that can be passed around.
Definition: grpc_types.h:128
Definition: grpc_types.h:86
grpc_arg * args
Definition: grpc_types.h:130
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:74
ResourceQuota represents a bound on memory usage by the gRPC library.
Definition: resource_quota.h:34
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:105
void SetMaxSendMessageSize(int size)
friend class SecureChannelCredentials
Definition: channel_arguments.h:113
A single argument...
Definition: grpc_types.h:104
void Swap(ChannelArguments &other)
void SetResourceQuota(const ResourceQuota &resource_quota)
Set the buffer pool to be attached to the constructed channel.
void SetCompressionAlgorithm(grpc_compression_algorithm algorithm)
Set the compression algorithm for the channel.
void SetServiceConfigJSON(const grpc::string &service_config_json)
Set service config in JSON form.
void SetPointerWithVtable(const grpc::string &key, void *value, const grpc_arg_pointer_vtable *vtable)
grpc_compression_algorithm
The various compression algorithms supported by gRPC.
Definition: compression_types.h:56
void SetSslTargetNameOverride(const grpc::string &name)
Set target name override for SSL host name checking.
struct grpc_exec_ctx grpc_exec_ctx
Definition: exec_ctx_fwd.h:24
void SetLoadBalancingPolicyName(const grpc::string &lb_policy_name)
Set LB policy name.
void SetPointer(const grpc::string &key, void *value)
Set a pointer argument value under key. Owership is not transferred.
size_t num_args
Definition: grpc_types.h:129
void SetInt(const grpc::string &key, int value)
Set an integer argument value under key.
ChannelArguments & operator=(ChannelArguments other)
Definition: channel_arguments.h:45
void SetUserAgentPrefix(const grpc::string &user_agent_prefix)
Set the string to prepend to the user agent.
void SetChannelArgs(grpc_channel_args *channel_args) const
Dump arguments in this instance to channel_args.
void SetSocketMutator(grpc_socket_mutator *mutator)
Set the socket mutator for the channel.