Skip to content

Commit 160ce48

Browse files
committed
impl(v3): add generator support for connection cq access
1 parent f944a14 commit 160ce48

7 files changed

Lines changed: 76 additions & 1 deletion

generator/generator_config.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ message ServiceConfiguration {
167167
// RPCs. If set to false (the default), a no-op resumption function will be
168168
// generated.
169169
bool omit_streaming_updater = 29;
170+
171+
// In rare cases, specifically bigtable::WaitForConsistency, the
172+
// CompletionQueue from the BackgroundThreads owned by the Connection is
173+
// needed elsewhere. This emits a protected accessor and friend function for
174+
// that purpose.
175+
bool emit_completion_queue_accessor = 30;
170176
}
171177

172178
message DiscoveryDocumentDefinedProduct {

generator/generator_config.textproto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ service {
588588
{rpc_name: "BigtableTableAdmin.CheckConsistency", idempotency: IDEMPOTENT}
589589
]
590590
omit_repo_metadata: true
591+
emit_completion_queue_accessor: true
591592
}
592593
593594
# Billing

generator/internal/connection_generator.cc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Status ConnectionGenerator::GenerateHeader() {
5757
{vars("idempotency_policy_header_path"), vars("retry_traits_header_path"),
5858
HasLongrunningMethod() ? "google/cloud/no_await_tag.h" : "",
5959
IsExperimental() ? "google/cloud/experimental_tag.h" : "",
60+
HasEmitCompletionQueueAccessor() ? "google/cloud/completion_queue.h"
61+
: "",
6062
"google/cloud/backoff_policy.h",
6163
HasLongrunningMethod() || HasAsyncMethod() ? "google/cloud/future.h"
6264
: "",
@@ -91,7 +93,21 @@ Status ConnectionGenerator::GenerateHeader() {
9193
}
9294
}
9395

94-
auto result = HeaderOpenNamespaces();
96+
Status result;
97+
if (HasEmitCompletionQueueAccessor()) {
98+
result = HeaderOpenNamespaces();
99+
if (!result.ok()) return result;
100+
HeaderPrint(R"""(class $connection_class_name$;)""");
101+
HeaderCloseNamespaces();
102+
103+
result = HeaderOpenNamespaces(NamespaceType::kInternal);
104+
if (!result.ok()) return result;
105+
HeaderPrint(
106+
R"""(StatusOr<CompletionQueue> completion_queue($product_namespace$::$connection_class_name$ const& conn);)""");
107+
HeaderCloseNamespaces();
108+
}
109+
110+
result = HeaderOpenNamespaces();
95111
if (!result.ok()) return result;
96112

97113
HeaderPrint(R"""(
@@ -315,6 +331,13 @@ class $connection_class_name$ {
315331
__FILE__, __LINE__);
316332
}
317333

334+
if (HasEmitCompletionQueueAccessor()) {
335+
HeaderPrint(R"""( protected:
336+
friend StatusOr<CompletionQueue> $product_internal_namespace$::completion_queue(
337+
$connection_class_name$ const& conn);
338+
virtual StatusOr<CompletionQueue> completion_queue() const;
339+
)""");
340+
}
318341
// close abstract interface Connection base class
319342
HeaderPrint("};\n");
320343

@@ -490,6 +513,15 @@ future<StatusOr<$response_type$>>
490513
__FILE__, __LINE__);
491514
}
492515

516+
if (HasEmitCompletionQueueAccessor()) {
517+
CcPrint(
518+
R"""(
519+
StatusOr<CompletionQueue> $connection_class_name$::completion_queue() const {
520+
return Status(StatusCode::kUnimplemented, "not implemented");
521+
}
522+
)""");
523+
}
524+
493525
if (HasGenerateGrpcTransport()) {
494526
EmitFactoryFunctionDefinition(EndpointLocationStyle());
495527
}

generator/internal/connection_impl_generator.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class $connection_class_name$Impl
133133
std::make_shared<google::cloud::internal::InvocationIdGenerator>();)""");
134134
}
135135

136+
if (HasEmitCompletionQueueAccessor()) {
137+
HeaderPrint(
138+
R"""(
139+
StatusOr<CompletionQueue> completion_queue() const override;
140+
)""");
141+
}
142+
136143
// This closes the *ConnectionImpl class definition.
137144
HeaderPrint("\n};\n");
138145

@@ -208,6 +215,15 @@ std::unique_ptr<PollingPolicy> polling_policy(Options const& options) {
208215
} // namespace
209216
)""");
210217

218+
if (HasEmitCompletionQueueAccessor()) {
219+
CcPrint(R"""(
220+
StatusOr<CompletionQueue> completion_queue(
221+
$product_namespace$::$connection_class_name$ const& conn) {
222+
return conn.completion_queue();
223+
}
224+
)""");
225+
}
226+
211227
// streaming updater functions
212228
if (!OmitStreamingUpdater(vars())) {
213229
for (auto const& method : methods()) {
@@ -242,6 +258,14 @@ void $service_name$$method_name$StreamingUpdater(
242258
CcPrintMethod(method, __FILE__, __LINE__, AsyncMethodDefinition(method));
243259
}
244260

261+
if (HasEmitCompletionQueueAccessor()) {
262+
CcPrint(R"""(
263+
StatusOr<CompletionQueue> $connection_class_name$Impl::completion_queue() const {
264+
return background_->cq();
265+
}
266+
)""");
267+
}
268+
245269
CcCloseNamespaces();
246270
return {};
247271
}

generator/internal/service_code_generator.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ bool ServiceCodeGenerator::IsDeprecated() const {
511511
return service_descriptor_->options().deprecated();
512512
}
513513

514+
bool ServiceCodeGenerator::HasEmitCompletionQueueAccessor() const {
515+
return vars().find("emit_completion_queue_accessor") != vars().end() &&
516+
vars().at("emit_completion_queue_accessor") == "true";
517+
}
518+
514519
} // namespace generator_internal
515520
} // namespace cloud
516521
} // namespace google

generator/internal/service_code_generator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class ServiceCodeGenerator : public GeneratorInterface {
246246
*/
247247
bool IsDeprecated() const;
248248

249+
bool HasEmitCompletionQueueAccessor() const;
250+
249251
private:
250252
void SetMethods();
251253

generator/standalone_main.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ std::vector<std::future<google::cloud::Status>> GenerateCodeFromProtos(
296296
if (service.omit_streaming_updater()) {
297297
args.emplace_back("--cpp_codegen_opt=omit_streaming_updater=true");
298298
}
299+
if (service.emit_completion_queue_accessor()) {
300+
args.emplace_back(
301+
"--cpp_codegen_opt=emit_completion_queue_accessor=true");
302+
}
303+
299304
if (service.generate_round_robin_decorator()) {
300305
args.emplace_back(
301306
"--cpp_codegen_opt=generate_round_robin_decorator=true");

0 commit comments

Comments
 (0)