aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpcpp
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-06-19 08:11:13 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-06-20 07:59:05 -0700
commitd170b83e0d29b93d3de7c508281cfeae38ae141e (patch)
treebd3980c00ed96fb0ca7b1f41538d20d32aea3778 /include/grpcpp
parenta6194db176cbcf958e77e0bc012981181f05663c (diff)
Allow AsyncServer with one generic to compile
Diffstat (limited to 'include/grpcpp')
-rw-r--r--include/grpcpp/impl/codegen/rpc_service_method.h45
-rw-r--r--include/grpcpp/impl/codegen/service_type.h30
2 files changed, 63 insertions, 12 deletions
diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h
index 1b4e57d80c..c38ea2b062 100644
--- a/include/grpcpp/impl/codegen/rpc_service_method.h
+++ b/include/grpcpp/impl/codegen/rpc_service_method.h
@@ -31,6 +31,8 @@
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/status.h>
+#include <grpc/support/log.h>
+
namespace grpc {
class ServerContext;
@@ -59,18 +61,57 @@ class RpcServiceMethod : public RpcMethod {
/// Takes ownership of the handler
RpcServiceMethod(const char* name, RpcMethod::RpcType type,
MethodHandler* handler)
- : RpcMethod(name, type), server_tag_(nullptr), handler_(handler) {}
+ : RpcMethod(name, type),
+ server_tag_(nullptr),
+ async_type_(AsyncType::UNSET),
+ handler_(handler) {}
+
+ enum class AsyncType {
+ UNSET,
+ ASYNC,
+ CODEGEN_GENERIC,
+ };
void set_server_tag(void* tag) { server_tag_ = tag; }
void* server_tag() const { return server_tag_; }
/// if MethodHandler is nullptr, then this is an async method
MethodHandler* handler() const { return handler_.get(); }
- void ResetHandler() { handler_.reset(); }
void SetHandler(MethodHandler* handler) { handler_.reset(handler); }
+ void SetServerAsyncType(RpcServiceMethod::AsyncType type) {
+ if (async_type_ == AsyncType::UNSET) {
+ // this marks this method as async
+ handler_.reset();
+ } else {
+ // this is not an error condition, as it allows users to declare a server
+ // like WithCodegenGenericMethod_foo<AsyncService>. However since it
+ // overwrites behavior, it should be logged.
+ gpr_log(
+ GPR_INFO,
+ "You are marking method %s as '%s', even though it was "
+ "previously marked '%s'. This behavior will overwrite the original "
+ "behavior. If you expected this then ignore this message.",
+ name(), TypeToString(async_type_), TypeToString(type));
+ }
+ async_type_ = type;
+ }
private:
void* server_tag_;
+ RpcServiceMethod::AsyncType async_type_;
std::unique_ptr<MethodHandler> handler_;
+
+ const char* TypeToString(RpcServiceMethod::AsyncType type) {
+ switch (type) {
+ case AsyncType::UNSET:
+ return "unset";
+ case AsyncType::ASYNC:
+ return "async";
+ case AsyncType::CODEGEN_GENERIC:
+ return "codegen generic";
+ default:
+ GPR_UNREACHABLE_CODE(return "unknown");
+ }
+ }
};
} // namespace internal
diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h
index af94d653f0..dc63b9dc21 100644
--- a/include/grpcpp/impl/codegen/service_type.h
+++ b/include/grpcpp/impl/codegen/service_type.h
@@ -124,30 +124,40 @@ class Service {
}
void MarkMethodAsync(int index) {
+ // This does not have to be a hard error, however no one has approached us
+ // with a use case yet. Please file an issue if you believe you have one.
GPR_CODEGEN_ASSERT(
methods_[index].get() != nullptr &&
"Cannot mark the method as 'async' because it has already been "
"marked as 'generic'.");
- methods_[index]->ResetHandler();
+ methods_[index]->SetServerAsyncType(
+ internal::RpcServiceMethod::AsyncType::ASYNC);
+ }
+
+ void MarkMethodCodegenGeneric(int index) {
+ // This does not have to be a hard error, however no one has approached us
+ // with a use case yet. Please file an issue if you believe you have one.
+ GPR_CODEGEN_ASSERT(
+ methods_[index].get() != nullptr &&
+ "Cannot mark the method as 'codegen generic' because it has already "
+ "been marked as 'generic'.");
+ methods_[index]->SetServerAsyncType(
+ internal::RpcServiceMethod::AsyncType::CODEGEN_GENERIC);
}
void MarkMethodGeneric(int index) {
+ // This does not have to be a hard error, however no one has approached us
+ // with a use case yet. Please file an issue if you believe you have one.
GPR_CODEGEN_ASSERT(
methods_[index]->handler() != nullptr &&
"Cannot mark the method as 'generic' because it has already been "
- "marked as 'async'.");
+ "marked as 'async' or 'codegen generic'.");
methods_[index].reset();
}
- void MarkMethodCodegenGeneric(int index) {
- GPR_CODEGEN_ASSERT(methods_[index]->handler() != nullptr &&
- "Cannot mark the method as 'codegen generic' because it "
- "has already been "
- "marked as 'async' or 'generic'.");
- methods_[index]->ResetHandler();
- }
-
void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) {
+ // This does not have to be a hard error, however no one has approached us
+ // with a use case yet. Please file an issue if you believe you have one.
GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() &&
"Cannot mark an async or generic method Streamed");
methods_[index]->SetHandler(streamed_method);