GRPC C++  1.3.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, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
35 #define GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
36 
37 #include <list>
38 #include <vector>
39 
40 #include <grpc++/support/config.h>
41 #include <grpc/compression.h>
42 #include <grpc/grpc.h>
43 
44 namespace grpc {
45 namespace testing {
46 class ChannelArgumentsTest;
47 } // namespace testing
48 
49 class ResourceQuota;
50 
55  public:
58 
59  ChannelArguments(const ChannelArguments& other);
61  Swap(other);
62  return *this;
63  }
64 
65  void Swap(ChannelArguments& other);
66 
72  void SetChannelArgs(grpc_channel_args* channel_args) const;
73 
74  // gRPC specific channel argument setters
77  void SetSslTargetNameOverride(const grpc::string& name);
78  // TODO(yangg) add flow control options
81 
84 
86  void SetUserAgentPrefix(const grpc::string& user_agent_prefix);
87 
89  void SetResourceQuota(const ResourceQuota& resource_quota);
90 
92  void SetMaxReceiveMessageSize(int size);
93  void SetMaxSendMessageSize(int size);
94 
98  void SetLoadBalancingPolicyName(const grpc::string& lb_policy_name);
99 
102  void SetServiceConfigJSON(const grpc::string& service_config_json);
103 
104  // Generic channel argument setters. Only for advanced use cases.
106  void SetInt(const grpc::string& key, int value);
107 
108  // Generic channel argument setter. Only for advanced use cases.
110  void SetPointer(const grpc::string& key, void* value);
111 
112  void SetPointerWithVtable(const grpc::string& key, void* value,
113  const grpc_arg_pointer_vtable* vtable);
114 
116  void SetString(const grpc::string& key, const grpc::string& value);
117 
121  grpc_channel_args out;
122  out.num_args = args_.size();
123  out.args = args_.empty() ? NULL : const_cast<grpc_arg*>(&args_[0]);
124  return out;
125  }
126 
127  private:
130 
132  struct PointerVtableMembers {
133  static void* Copy(void* in) { return in; }
134  static void Destroy(grpc_exec_ctx* exec_ctx, void* in) {}
135  static int Compare(void* a, void* b) {
136  if (a < b) return -1;
137  if (a > b) return 1;
138  return 0;
139  }
140  };
141 
142  // Returns empty string when it is not set.
143  grpc::string GetSslTargetNameOverride() const;
144 
145  std::vector<grpc_arg> args_;
146  std::list<grpc::string> strings_;
147 };
148 
149 } // namespace grpc
150 
151 #endif // GRPCXX_SUPPORT_CHANNEL_ARGUMENTS_H
void SetMaxReceiveMessageSize(int size)
Sets the max receive and send message sizes.
friend class testing::ChannelArgumentsTest
Definition: channel_arguments.h:129
std::string string
Definition: config.h:50
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:142
Definition: grpc_types.h:100
grpc_arg * args
Definition: grpc_types.h:144
Options for channel creation.
Definition: channel_arguments.h:54
struct grpc_socket_mutator grpc_socket_mutator
The Socket Mutator interface allows changes on socket options.
Definition: grpc_types.h:88
ResourceQuota represents a bound on memory usage by the gRPC library.
Definition: resource_quota.h:48
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:120
void SetMaxSendMessageSize(int size)
friend class SecureChannelCredentials
Definition: channel_arguments.h:128
A single argument...
Definition: grpc_types.h:118
void Swap(ChannelArguments &other)
void SetResourceQuota(const ResourceQuota &resource_quota)
The given buffer pool will 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
Definition: compression_types.h:72
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:39
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:143
void SetInt(const grpc::string &key, int value)
Set an integer argument value under key.
ChannelArguments & operator=(ChannelArguments other)
Definition: channel_arguments.h:60
void SetUserAgentPrefix(const grpc::string &user_agent_prefix)
The given string will be sent at the front of the user agent string.
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.