15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_CONNECTION_OPTIONS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_CONNECTION_OPTIONS_H
18#include "google/cloud/common_options.h"
19#include "google/cloud/completion_queue.h"
20#include "google/cloud/grpc_options.h"
21#include "google/cloud/internal/algorithm.h"
22#include "google/cloud/internal/background_threads_impl.h"
23#include "google/cloud/internal/populate_common_options.h"
24#include "google/cloud/internal/populate_grpc_options.h"
25#include "google/cloud/options.h"
26#include "google/cloud/status_or.h"
27#include "google/cloud/tracing_options.h"
28#include "google/cloud/version.h"
29#include <grpcpp/grpcpp.h>
39template <
typename ConnectionTraits>
40class ConnectionOptions;
44template <
typename ConnectionTraits>
45Options MakeOptions(ConnectionOptions<ConnectionTraits>);
49
50
51
52
53template <
typename ConnectionTraits>
54class ConnectionOptions {
57
58
59
60
64
65
66
67
69 std::shared_ptr<grpc::ChannelCredentials> credentials)
73 internal::DefaultTracingComponents()
)
75 internal::DefaultTracingOptions()
)
77 ConnectionTraits::default_endpoint())
79 ConnectionTraits::default_num_channels())),
80 user_agent_prefix_(ConnectionTraits::user_agent_prefix()) {}
83
84
85
86
87 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `UnifiedCredentialsOption`")
89 std::shared_ptr<grpc::ChannelCredentials> v) {
95
96
97
98
99 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `UnifiedCredentialsOption`")
100 std::shared_ptr<grpc::ChannelCredentials>
credentials()
const {
105
106
107
108
109
110
111
112
113
114
115 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `EndpointOption`")
122
123
124
125
126 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `EndpointOption`")
130
131
132
133
134
135
136
137
138
139
140
141 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcNumChannelsOption`")
145
146
147
148
149 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcNumChannelsOption`")
156
157
158
159
160
161
162
163
164 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `TracingComponentsOption`")
170
171
172
173
174 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `TracingComponentsOption`")
181
182
183
184
185 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `TracingComponentsOption`")
192
193
194
195
196 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `TracingComponentsOption`")
197 std::set<std::string>
const&
components()
const {
202
203
204
205
206 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcTracingOption`")
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcChannelsArgumentOption`")
231 return channel_pool_domain_;
235
236
237
238
239 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcChannelsArgumentsOption`")
241 channel_pool_domain_ = std::move(v);
246
247
248
249
250
251
252
253
254 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `UserAgentProductsOption`")
257 prefix += user_agent_prefix_;
258 user_agent_prefix_ = std::move(prefix);
263
264
265
266
267 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `UserAgentProductsOption`")
271
272
273
274
275
276
277
278
279
280 GOOGLE_CLOUD_CPP_DEPRECATED(
281 "Not intended for use in application code. There is no alternative "
282 "implemented or planned.")
284 return internal::MakeChannelArguments(internal::MakeOptions(*
this));
288
289
290
291
292
293
294 GOOGLE_CLOUD_CPP_DEPRECATED(
295 "Use `Options` and `GrpcBackgroundThreadPoolSizeOption`")
297 background_thread_pool_size_ = s;
302 GOOGLE_CLOUD_CPP_DEPRECATED(
303 "Use `Options` and `GrpcBackgroundThreadPoolSizeOption`")
305 return background_thread_pool_size_;
309
310
311
312
313
314
315
316
317
318
319
320 GOOGLE_CLOUD_CPP_DEPRECATED(
"Use `Options` and `GrpcCompletionQueueOption`")
323 background_threads_factory_ = [cq] {
324 return std::make_unique<internal::CustomerSuppliedBackgroundThreads>(cq);
330 using BackgroundThreadsFactory = ::
google::
cloud::BackgroundThreadsFactory;
334 GOOGLE_CLOUD_CPP_DEPRECATED(
335 "Not intended for applications to use. There is no alternative "
336 "implemented or planned")
338 if (background_threads_factory_)
return background_threads_factory_;
339 auto const s = background_thread_pool_size_;
340 return [s] {
return internal::DefaultBackgroundThreads(s); };
344 template <
typename T>
345 friend Options internal::MakeOptions(ConnectionOptions<T>);
351 std::string user_agent_prefix_;
352 std::string channel_pool_domain_;
353 std::size_t background_thread_pool_size_ = 0;
354 BackgroundThreadsFactory background_threads_factory_;
361#include "google/cloud/internal/disable_deprecation_warnings.inc"
362template <
typename ConnectionTraits>
363Options MakeOptions(ConnectionOptions<ConnectionTraits> old) {
364 Options opts = std::move(old.opts_);
367 old.background_threads_factory());
368 if (!old.channel_pool_domain_.empty()) {
374 {{
"grpc.channel_pooling_domain", std::move(old.channel_pool_domain_)}});
378#include "google/cloud/internal/diagnostics_pop.inc"
A object representing the background threads available to a Client.
Definition: background_threads.h:27
Call the functor associated with asynchronous operations when they complete.
Definition: completion_queue.h:47
ConnectionOptions()
The default options, using grpc::GoogleDefaultCredentials().
Definition: connection_options.h:61
std::string const & channel_pool_domain() const
Define the gRPC channel domain for clients configured with this object.
Definition: connection_options.h:230
ConnectionOptions & set_channel_pool_domain(std::string v)
Set the value for channel_pool_domain().
Definition: connection_options.h:240
std::size_t background_thread_pool_size() const
Definition: connection_options.h:304
ConnectionOptions & set_background_thread_pool_size(std::size_t s)
Set the number of background threads.
Definition: connection_options.h:296
ConnectionOptions & disable_tracing(std::string const &component)
Disable tracing for component in clients configured with this object.
Definition: connection_options.h:186
BackgroundThreadsFactory background_threads_factory() const
Definition: connection_options.h:337
ConnectionOptions & enable_tracing(std::string const &component)
Enable tracing for component in clients configured with this object.
Definition: connection_options.h:175
int num_channels() const
The number of transport channels to create.
Definition: connection_options.h:142
std::shared_ptr< grpc::ChannelCredentials > credentials() const
The gRPC credentials used by clients configured with this object.
Definition: connection_options.h:100
std::string const & endpoint() const
The endpoint used by clients configured with this object.
Definition: connection_options.h:127
bool tracing_enabled(std::string const &component) const
Return whether tracing is enabled for the given component.
Definition: connection_options.h:165
std::set< std::string > const & components() const
Return the set of tracing components.
Definition: connection_options.h:197
grpc::ChannelArguments CreateChannelArguments() const
Create a new grpc::ChannelArguments configured with the options in this object.
Definition: connection_options.h:283
std::string const & user_agent_prefix() const
Return the current value for the user agent string.
Definition: connection_options.h:268
ConnectionOptions & add_user_agent_prefix(std::string prefix)
Prepend prefix to the user-agent string.
Definition: connection_options.h:255
ConnectionOptions & set_endpoint(std::string v)
Change the gRPC endpoint.
Definition: connection_options.h:116
ConnectionOptions & set_num_channels(int num_channels)
Set the value for num_channels().
Definition: connection_options.h:150
ConnectionOptions & set_credentials(std::shared_ptr< grpc::ChannelCredentials > v)
Change the gRPC credentials value.
Definition: connection_options.h:88
TracingOptions const & tracing_options() const
Return the options for use when tracing RPCs.
Definition: connection_options.h:207
ConnectionOptions(std::shared_ptr< grpc::ChannelCredentials > credentials)
The default options, using an explicit credentials object.
Definition: connection_options.h:68
ConnectionOptions & DisableBackgroundThreads(google::cloud::CompletionQueue const &cq)
Configure the connection to use cq for all background work.
Definition: connection_options.h:321
A class that holds option structs indexed by their type.
Definition: options.h:91
ValueTypeT< T > const & get() const
Returns a reference to the value for T, or a value-initialized default if T was not set.
Definition: options.h:174
ValueTypeT< T > & lookup(ValueTypeT< T > value={})
Returns a reference to the value for option T, setting the value to init_value if necessary.
Definition: options.h:202
Options & set(ValueTypeT< T > v)
Sets option T to the value v and returns a reference to *this.
Definition: options.h:125
Options()=default
Constructs an empty instance.
The configuration parameters for RPC/protobuf tracing.
Definition: tracing_options.h:33
Contains all the Google Cloud C++ Library APIs.
Definition: async_operation.h:23
Definition: async_operation.h:22
Change the endpoint.
Definition: common_options.h:39
Changes the BackgroundThreadsFactory.
Definition: grpc_options.h:169
A string-string map of arguments for grpc::ChannelArguments::SetString.
Definition: grpc_options.h:78
The gRPC credentials used by clients configured with this object.
Definition: grpc_options.h:36
The number of transport channels to create.
Definition: grpc_options.h:56
The TracingOptions to use when printing grpc protocol buffer messages.
Definition: grpc_options.h:110
Return whether tracing is enabled for the given component.
Definition: common_options.h:70
User-agent products to include with each request.
Definition: common_options.h:55
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Definition: version.h:45
#define GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
Definition: version.h:43