From 50a7a68ca2a5ade22a97502389ec1e0d4dcb0a10 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 4 Jun 2015 12:53:40 -0700 Subject: Progress commit on fixing up C++ --- src/compiler/cpp_generator.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/compiler/cpp_generator.cc') diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index b0d2b5d229..d03eaddf40 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -113,6 +113,7 @@ grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file, grpc::string temp = "#include \n" "#include \n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -1045,8 +1046,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, " new ::grpc::RpcMethodHandler< $ns$$Service$::Service, " "$Request$, " "$Response$>(\n" - " std::mem_fn(&$ns$$Service$::Service::$Method$), this),\n" - " new $Request$, new $Response$));\n"); + " std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( *vars, @@ -1055,8 +1055,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, " ::grpc::RpcMethod::CLIENT_STREAMING,\n" " new ::grpc::ClientStreamingHandler< " "$ns$$Service$::Service, $Request$, $Response$>(\n" - " std::mem_fn(&$ns$$Service$::Service::$Method$), this),\n" - " new $Request$, new $Response$));\n"); + " std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, @@ -1065,8 +1064,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, " ::grpc::RpcMethod::SERVER_STREAMING,\n" " new ::grpc::ServerStreamingHandler< " "$ns$$Service$::Service, $Request$, $Response$>(\n" - " std::mem_fn(&$ns$$Service$::Service::$Method$), this),\n" - " new $Request$, new $Response$));\n"); + " std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); } else if (BidiStreaming(method)) { printer->Print( *vars, @@ -1075,8 +1073,7 @@ void PrintSourceService(grpc::protobuf::io::Printer *printer, " ::grpc::RpcMethod::BIDI_STREAMING,\n" " new ::grpc::BidiStreamingHandler< " "$ns$$Service$::Service, $Request$, $Response$>(\n" - " std::mem_fn(&$ns$$Service$::Service::$Method$), this),\n" - " new $Request$, new $Response$));\n"); + " std::mem_fn(&$ns$$Service$::Service::$Method$), this)));\n"); } } printer->Print("return service_;\n"); -- cgit v1.2.3 From ce40de58da69dc5fb1569d4dca934ef7eea4d3b1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 5 Jun 2015 07:14:58 -0700 Subject: clang-format --- include/grpc++/async_unary_call.h | 13 ++- include/grpc++/byte_buffer.h | 3 +- include/grpc++/completion_queue.h | 2 +- include/grpc++/config.h | 20 ++-- include/grpc++/config_protobuf.h | 3 +- include/grpc++/impl/call.h | 68 ++++++----- include/grpc++/impl/client_unary_call.h | 13 +-- include/grpc++/impl/proto_utils.h | 18 +-- include/grpc++/impl/rpc_service_method.h | 24 ++-- include/grpc++/impl/serialization_traits.h | 5 +- include/grpc++/impl/service_type.h | 19 ++- include/grpc++/server.h | 67 ++++++----- include/grpc++/stream.h | 25 ++-- include/grpc/support/port_platform.h | 20 +++- src/compiler/config.h | 6 +- src/compiler/cpp_generator.cc | 181 ++++++++++++++--------------- src/cpp/client/channel.h | 8 +- src/cpp/proto/proto_utils.cc | 8 +- src/cpp/server/server.cc | 58 ++++----- 19 files changed, 303 insertions(+), 258 deletions(-) (limited to 'src/compiler/cpp_generator.cc') diff --git a/include/grpc++/async_unary_call.h b/include/grpc++/async_unary_call.h index 3d475d0668..a3c9e20213 100644 --- a/include/grpc++/async_unary_call.h +++ b/include/grpc++/async_unary_call.h @@ -90,9 +90,11 @@ class ClientAsyncResponseReader GRPC_FINAL private: ClientContext* context_; Call call_; - SneakyCallOpSet init_buf_; + SneakyCallOpSet init_buf_; CallOpSet meta_buf_; - CallOpSet, CallOpClientRecvStatus> finish_buf_; + CallOpSet, + CallOpClientRecvStatus> finish_buf_; }; template @@ -119,7 +121,9 @@ class ServerAsyncResponseWriter GRPC_FINAL } // The response is dropped if the status is not OK. if (status.IsOk() && !finish_buf_.SendMessage(msg)) { - finish_buf_.ServerSendStatus(ctx_->trailing_metadata_, Status(INVALID_ARGUMENT, "Failed to serialize message")); + finish_buf_.ServerSendStatus( + ctx_->trailing_metadata_, + Status(INVALID_ARGUMENT, "Failed to serialize message")); } else { finish_buf_.ServerSendStatus(ctx_->trailing_metadata_, status); } @@ -143,7 +147,8 @@ class ServerAsyncResponseWriter GRPC_FINAL Call call_; ServerContext* ctx_; CallOpSet meta_buf_; - CallOpSet finish_buf_; + CallOpSet finish_buf_; }; } // namespace grpc diff --git a/include/grpc++/byte_buffer.h b/include/grpc++/byte_buffer.h index 618ec764df..80b3397a2d 100644 --- a/include/grpc++/byte_buffer.h +++ b/include/grpc++/byte_buffer.h @@ -85,7 +85,8 @@ class ByteBuffer GRPC_FINAL { template <> class SerializationTraits { public: - static Status Deserialize(grpc_byte_buffer* byte_buffer, ByteBuffer* dest, int max_message_size) { + static Status Deserialize(grpc_byte_buffer* byte_buffer, ByteBuffer* dest, + int max_message_size) { dest->set_buffer(byte_buffer); return Status::OK; } diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index 0490073937..a3e7a9c9f4 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -95,7 +95,7 @@ class CompletionQueue : public GrpcLibrary { // Nonblocking (until deadline) read from queue. // Cannot rely on result of tag or ok if return is TIMEOUT - template + template NextStatus AsyncNext(void** tag, bool* ok, const T& deadline) { TimePoint deadline_tp(deadline); return AsyncNextInternal(tag, ok, deadline_tp.raw_time()); diff --git a/include/grpc++/config.h b/include/grpc++/config.h index af248b66e3..1362c0a1fa 100644 --- a/include/grpc++/config.h +++ b/include/grpc++/config.h @@ -46,7 +46,7 @@ #define GRPC_CXX0X_NO_OVERRIDE 1 #define GRPC_CXX0X_NO_CHRONO 1 #define GRPC_CXX0X_NO_THREAD 1 -#endif +#endif #endif // Visual Studio #ifndef __clang__ @@ -80,16 +80,22 @@ #ifdef GRPC_CXX0X_NO_NULLPTR #include const class { -public: - template operator T*() const {return static_cast(0);} - template operator std::unique_ptr() const { + public: + template + operator T *() const { + return static_cast(0); + } + template + operator std::unique_ptr() const { return std::unique_ptr(static_cast(0)); } - template operator std::shared_ptr() const { + template + operator std::shared_ptr() const { return std::shared_ptr(static_cast(0)); } - operator bool() const {return false;} -private: + operator bool() const { return false; } + + private: void operator&() const = delete; } nullptr = {}; #endif diff --git a/include/grpc++/config_protobuf.h b/include/grpc++/config_protobuf.h index f6938b02ce..3afc7a58e2 100644 --- a/include/grpc++/config_protobuf.h +++ b/include/grpc++/config_protobuf.h @@ -51,8 +51,7 @@ ::google::protobuf::io::ZeroCopyOutputStream #define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \ ::google::protobuf::io::ZeroCopyInputStream -#define GRPC_CUSTOM_CODEDINPUTSTREAM \ - ::google::protobuf::io::CodedInputStream +#define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream #endif namespace grpc { diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h index 40dbf9e641..88056470e3 100644 --- a/include/grpc++/impl/call.h +++ b/include/grpc++/impl/call.h @@ -54,7 +54,8 @@ class Call; void FillMetadataMap(grpc_metadata_array* arr, std::multimap* metadata); -grpc_metadata* FillMetadataArray(const std::multimap& metadata); +grpc_metadata* FillMetadataArray( + const std::multimap& metadata); class CallNoOp { protected: @@ -66,7 +67,8 @@ class CallOpSendInitialMetadata { public: CallOpSendInitialMetadata() : send_(false) {} - void SendInitialMetadata(const std::multimap& metadata) { + void SendInitialMetadata( + const std::multimap& metadata) { send_ = true; initial_metadata_count_ = metadata.size(); initial_metadata_ = FillMetadataArray(metadata); @@ -118,16 +120,14 @@ class CallOpRecvMessage { public: CallOpRecvMessage() : got_message(false), message_(nullptr) {} - void RecvMessage(R* message) { - message_ = message; - } + void RecvMessage(R* message) { message_ = message; } bool got_message; protected: void AddOp(grpc_op* ops, size_t* nops) { if (message_ == nullptr) return; - grpc_op *op = &ops[(*nops)++]; + grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &recv_buf_; } @@ -137,7 +137,9 @@ class CallOpRecvMessage { if (recv_buf_) { if (*status) { got_message = true; - *status = SerializationTraits::Deserialize(recv_buf_, message_, max_message_size).IsOk(); + *status = SerializationTraits::Deserialize(recv_buf_, message_, + max_message_size) + .IsOk(); } else { got_message = false; grpc_byte_buffer_destroy(recv_buf_); @@ -159,8 +161,10 @@ class CallOpGenericRecvMessage { template void RecvMessage(R* message) { - deserialize_ = [message](grpc_byte_buffer* buf, int max_message_size) -> Status { - return SerializationTraits::Deserialize(buf, message, max_message_size); + deserialize_ = [message](grpc_byte_buffer* buf, + int max_message_size) -> Status { + return SerializationTraits::Deserialize(buf, message, + max_message_size); }; } @@ -169,7 +173,7 @@ class CallOpGenericRecvMessage { protected: void AddOp(grpc_op* ops, size_t* nops) { if (!deserialize_) return; - grpc_op *op = &ops[(*nops)++]; + grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_MESSAGE; op->data.recv_message = &recv_buf_; } @@ -218,7 +222,9 @@ class CallOpServerSendStatus { public: CallOpServerSendStatus() : send_status_available_(false) {} - void ServerSendStatus(const std::multimap& trailing_metadata, const Status& status){ + void ServerSendStatus( + const std::multimap& trailing_metadata, + const Status& status) { trailing_metadata_count_ = trailing_metadata.size(); trailing_metadata_ = FillMetadataArray(trailing_metadata); send_status_available_ = true; @@ -232,8 +238,7 @@ class CallOpServerSendStatus { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = trailing_metadata_count_; - op->data.send_status_from_server.trailing_metadata = - trailing_metadata_; + op->data.send_status_from_server.trailing_metadata = trailing_metadata_; op->data.send_status_from_server.status = send_status_code_; op->data.send_status_from_server.status_details = send_status_details_.empty() ? nullptr : send_status_details_.c_str(); @@ -280,9 +285,7 @@ class CallOpRecvInitialMetadata { class CallOpClientRecvStatus { public: - CallOpClientRecvStatus() { - memset(this, 0, sizeof(*this)); - } + CallOpClientRecvStatus() { memset(this, 0, sizeof(*this)); } void ClientRecvStatus(ClientContext* context, Status* status) { recv_trailing_metadata_ = &context->trailing_metadata_; @@ -323,7 +326,9 @@ class CallOpSetInterface : public CompletionQueueTag { CallOpSetInterface() : max_message_size_(0) {} virtual void FillOps(grpc_op* ops, size_t* nops) = 0; - void set_max_message_size(int max_message_size) { max_message_size_ = max_message_size; } + void set_max_message_size(int max_message_size) { + max_message_size_ = max_message_size; + } protected: int max_message_size_; @@ -332,14 +337,15 @@ class CallOpSetInterface : public CompletionQueueTag { template class WrapAndDerive : public T {}; -template -class CallOpSet : public CallOpSetInterface, -public WrapAndDerive, -public WrapAndDerive, -public WrapAndDerive, -public WrapAndDerive, -public WrapAndDerive, -public WrapAndDerive { +template +class CallOpSet : public CallOpSetInterface, + public WrapAndDerive, + public WrapAndDerive, + public WrapAndDerive, + public WrapAndDerive, + public WrapAndDerive, + public WrapAndDerive { public: CallOpSet() : return_tag_(this) {} void FillOps(grpc_op* ops, size_t* nops) GRPC_OVERRIDE { @@ -365,7 +371,7 @@ public WrapAndDerive { void set_output_tag(void* return_tag) { return_tag_ = return_tag; } private: - void *return_tag_; + void* return_tag_; }; #if 0 @@ -444,11 +450,15 @@ class CallOpBuffer : public CompletionQueueTag { #endif // SneakyCallOpBuffer does not post completions to the completion queue -template -class SneakyCallOpSet GRPC_FINAL : public CallOpSet { +template +class SneakyCallOpSet GRPC_FINAL + : public CallOpSet { public: bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE { - return CallOpSet::FinalizeResult(tag, status) && false; + return CallOpSet::FinalizeResult(tag, + status) && + false; } }; diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h index 5e37e63c6d..c1832f9eb8 100644 --- a/include/grpc++/impl/client_unary_call.h +++ b/include/grpc++/impl/client_unary_call.h @@ -49,18 +49,13 @@ class Status; // Wrapper that performs a blocking unary call template Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, - ClientContext* context, - const InputMessage& request, + ClientContext* context, const InputMessage& request, OutputMessage* result) { CompletionQueue cq; Call call(channel->CreateCall(method, context, &cq)); - CallOpSet< - CallOpSendInitialMetadata, - CallOpSendMessage, - CallOpRecvInitialMetadata, - CallOpRecvMessage, - CallOpClientSendClose, - CallOpClientRecvStatus> ops; + CallOpSet, + CallOpClientSendClose, CallOpClientRecvStatus> ops; Status status; ops.SendInitialMetadata(context->send_initial_metadata_); if (!ops.SendMessage(request)) { diff --git a/include/grpc++/impl/proto_utils.h b/include/grpc++/impl/proto_utils.h index 1a0cc31a8a..ee19859198 100644 --- a/include/grpc++/impl/proto_utils.h +++ b/include/grpc++/impl/proto_utils.h @@ -55,14 +55,18 @@ Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, int max_message_size); template -class SerializationTraits::value>::type> { +class SerializationTraits::value>::type> { public: - static bool Serialize(const grpc::protobuf::Message& msg, grpc_byte_buffer** buffer) { - return SerializeProto(msg, buffer); - } - static Status Deserialize(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, int max_message_size) { - return DeserializeProto(buffer, msg, max_message_size); - } + static bool Serialize(const grpc::protobuf::Message& msg, + grpc_byte_buffer** buffer) { + return SerializeProto(msg, buffer); + } + static Status Deserialize(grpc_byte_buffer* buffer, + grpc::protobuf::Message* msg, + int max_message_size) { + return DeserializeProto(buffer, msg, max_message_size); + } }; } // namespace grpc diff --git a/include/grpc++/impl/rpc_service_method.h b/include/grpc++/impl/rpc_service_method.h index cd31b22323..1bf39fca3b 100644 --- a/include/grpc++/impl/rpc_service_method.h +++ b/include/grpc++/impl/rpc_service_method.h @@ -55,9 +55,12 @@ class MethodHandler { public: virtual ~MethodHandler() {} struct HandlerParameter { - HandlerParameter(Call* c, ServerContext* context, - grpc_byte_buffer* req, int max_size) - : call(c), server_context(context), request(req), max_message_size(max_size) {} + HandlerParameter(Call* c, ServerContext* context, grpc_byte_buffer* req, + int max_size) + : call(c), + server_context(context), + request(req), + max_message_size(max_size) {} Call* call; ServerContext* server_context; // Handler required to grpc_byte_buffer_destroy this @@ -79,14 +82,16 @@ class RpcMethodHandler : public MethodHandler { void RunHandler(const HandlerParameter& param) GRPC_FINAL { RequestType req; - Status status = SerializationTraits::Deserialize(param.request, &req, param.max_message_size); + Status status = SerializationTraits::Deserialize( + param.request, &req, param.max_message_size); ResponseType rsp; if (status.IsOk()) { status = func_(service_, param.server_context, &req, &rsp); } GPR_ASSERT(!param.server_context->sent_initial_metadata_); - CallOpSet ops; + CallOpSet ops; ops.SendInitialMetadata(param.server_context->initial_metadata_); if (status.IsOk()) { if (!ops.SendMessage(rsp)) { @@ -122,7 +127,8 @@ class ClientStreamingHandler : public MethodHandler { Status status = func_(service_, param.server_context, &reader, &rsp); GPR_ASSERT(!param.server_context->sent_initial_metadata_); - CallOpSet ops; + CallOpSet ops; ops.SendInitialMetadata(param.server_context->initial_metadata_); if (status.IsOk()) { if (!ops.SendMessage(rsp)) { @@ -152,7 +158,8 @@ class ServerStreamingHandler : public MethodHandler { void RunHandler(const HandlerParameter& param) GRPC_FINAL { RequestType req; - Status status = SerializationTraits::Deserialize(param.request, &req, param.max_message_size); + Status status = SerializationTraits::Deserialize( + param.request, &req, param.max_message_size); if (status.IsOk()) { ServerWriter writer(param.call, param.server_context); @@ -211,8 +218,7 @@ class RpcServiceMethod : public RpcMethod { // Takes ownership of the handler RpcServiceMethod(const char* name, RpcMethod::RpcType type, MethodHandler* handler) - : RpcMethod(name, type, nullptr), - handler_(handler) {} + : RpcMethod(name, type, nullptr), handler_(handler) {} MethodHandler* handler() { return handler_.get(); } diff --git a/include/grpc++/impl/serialization_traits.h b/include/grpc++/impl/serialization_traits.h index 4648bbfc33..e4f086e08d 100644 --- a/include/grpc++/impl/serialization_traits.h +++ b/include/grpc++/impl/serialization_traits.h @@ -38,9 +38,10 @@ struct grpc_byte_buffer; namespace grpc { -template +template class SerializationTraits; } // namespace grpc -#endif // GRPCXX_IMPL_SERIALIZATION_TRAITS_H +#endif // GRPCXX_IMPL_SERIALIZATION_TRAITS_H diff --git a/include/grpc++/impl/service_type.h b/include/grpc++/impl/service_type.h index af21d9b8cf..8f9f38f193 100644 --- a/include/grpc++/impl/service_type.h +++ b/include/grpc++/impl/service_type.h @@ -77,21 +77,20 @@ class AsynchronousService { protected: template - void RequestAsyncUnary(int index, ServerContext* context, - Message* request, + void RequestAsyncUnary(int index, ServerContext* context, Message* request, ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, ServerCompletionQueue* notification_cq, void* tag) { - server_->RequestAsyncCall(request_args_[index], context, - stream, call_cq, notification_cq, tag, request); + server_->RequestAsyncCall(request_args_[index], context, stream, call_cq, + notification_cq, tag, request); } void RequestClientStreaming(int index, ServerContext* context, ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, ServerCompletionQueue* notification_cq, void* tag) { - server_->RequestAsyncCall(request_args_[index], context, - stream, call_cq, notification_cq, tag); + server_->RequestAsyncCall(request_args_[index], context, stream, call_cq, + notification_cq, tag); } template void RequestServerStreaming(int index, ServerContext* context, @@ -100,15 +99,15 @@ class AsynchronousService { CompletionQueue* call_cq, ServerCompletionQueue* notification_cq, void* tag) { - server_->RequestAsyncCall(request_args_[index], context, - stream, call_cq, notification_cq, tag, request); + server_->RequestAsyncCall(request_args_[index], context, stream, call_cq, + notification_cq, tag, request); } void RequestBidiStreaming(int index, ServerContext* context, ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, ServerCompletionQueue* notification_cq, void* tag) { - server_->RequestAsyncCall(request_args_[index], context, - stream, call_cq, notification_cq, tag); + server_->RequestAsyncCall(request_args_[index], context, stream, call_cq, + notification_cq, tag); } private: diff --git a/include/grpc++/server.h b/include/grpc++/server.h index a6883e24e6..8c7551ccf1 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -58,8 +58,7 @@ class ServerCredentials; class ThreadPoolInterface; // Currently it only supports handling rpcs in a single thread. -class Server GRPC_FINAL : public GrpcLibrary, - private CallHook { +class Server GRPC_FINAL : public GrpcLibrary, private CallHook { public: ~Server(); @@ -97,14 +96,13 @@ class Server GRPC_FINAL : public GrpcLibrary, void RunRpc(); void ScheduleCallback(); - void PerformOpsOnCall(CallOpSetInterface *ops, Call* call) GRPC_OVERRIDE; + void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) GRPC_OVERRIDE; class BaseAsyncRequest : public CompletionQueueTag { public: BaseAsyncRequest(Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, - CompletionQueue* call_cq, - void* tag); + ServerAsyncStreamingInterface* stream, + CompletionQueue* call_cq, void* tag); virtual ~BaseAsyncRequest(); bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE; @@ -123,20 +121,24 @@ class Server GRPC_FINAL : public GrpcLibrary, class RegisteredAsyncRequest : public BaseAsyncRequest { public: RegisteredAsyncRequest(Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag); + ServerAsyncStreamingInterface* stream, + CompletionQueue* call_cq, void* tag); // uses BaseAsyncRequest::FinalizeResult protected: - void IssueRequest(void* registered_method, grpc_byte_buffer** payload, ServerCompletionQueue *notification_cq); + void IssueRequest(void* registered_method, grpc_byte_buffer** payload, + ServerCompletionQueue* notification_cq); }; class NoPayloadAsyncRequest GRPC_FINAL : public RegisteredAsyncRequest { public: - NoPayloadAsyncRequest(void* registered_method, Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, void* tag) - : RegisteredAsyncRequest(server, context, stream, call_cq, tag) { + NoPayloadAsyncRequest(void* registered_method, Server* server, + ServerContext* context, + ServerAsyncStreamingInterface* stream, + CompletionQueue* call_cq, + ServerCompletionQueue* notification_cq, void* tag) + : RegisteredAsyncRequest(server, context, stream, call_cq, tag) { IssueRequest(registered_method, nullptr, notification_cq); } @@ -146,15 +148,23 @@ class Server GRPC_FINAL : public GrpcLibrary, template class PayloadAsyncRequest GRPC_FINAL : public RegisteredAsyncRequest { public: - PayloadAsyncRequest(void* registered_method, Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, void* tag, Message* request) - : RegisteredAsyncRequest(server, context, stream, call_cq, tag), request_(request) { + PayloadAsyncRequest(void* registered_method, Server* server, + ServerContext* context, + ServerAsyncStreamingInterface* stream, + CompletionQueue* call_cq, + ServerCompletionQueue* notification_cq, void* tag, + Message* request) + : RegisteredAsyncRequest(server, context, stream, call_cq, tag), + request_(request) { IssueRequest(registered_method, &payload_, notification_cq); } bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE { - bool serialization_status = *status && payload_ && SerializationTraits::Deserialize(payload_, request_, server_->max_message_size_).IsOk(); + bool serialization_status = + *status && payload_ && + SerializationTraits::Deserialize(payload_, request_, + server_->max_message_size_) + .IsOk(); bool ret = RegisteredAsyncRequest::FinalizeResult(tag, status); *status = serialization_status && *status; return ret; @@ -168,10 +178,9 @@ class Server GRPC_FINAL : public GrpcLibrary, class GenericAsyncRequest GRPC_FINAL : public BaseAsyncRequest { public: GenericAsyncRequest(Server* server, GenericServerContext* context, - ServerAsyncStreamingInterface* stream, - CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, - void* tag); + ServerAsyncStreamingInterface* stream, + CompletionQueue* call_cq, + ServerCompletionQueue* notification_cq, void* tag); bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE; @@ -183,17 +192,18 @@ class Server GRPC_FINAL : public GrpcLibrary, void RequestAsyncCall(void* registered_method, ServerContext* context, ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, - void* tag, Message *message) { - new PayloadAsyncRequest(registered_method, this, context, stream, call_cq, notification_cq, tag, message); + ServerCompletionQueue* notification_cq, void* tag, + Message* message) { + new PayloadAsyncRequest(registered_method, this, context, stream, + call_cq, notification_cq, tag, message); } void RequestAsyncCall(void* registered_method, ServerContext* context, ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, - void* tag) { - new NoPayloadAsyncRequest(registered_method, this, context, stream, call_cq, notification_cq, tag); + ServerCompletionQueue* notification_cq, void* tag) { + new NoPayloadAsyncRequest(registered_method, this, context, stream, call_cq, + notification_cq, tag); } void RequestAsyncGenericCall(GenericServerContext* context, @@ -201,7 +211,8 @@ class Server GRPC_FINAL : public GrpcLibrary, CompletionQueue* call_cq, ServerCompletionQueue* notification_cq, void* tag) { - new GenericAsyncRequest(this, context, stream, call_cq, notification_cq, tag); + new GenericAsyncRequest(this, context, stream, call_cq, notification_cq, + tag); } const int max_message_size_; diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index eb2bce678f..2495f96abf 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -97,7 +97,8 @@ class ClientReader GRPC_FINAL : public ClientReaderInterface { ClientReader(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, const W& request) : context_(context), call_(channel->CreateCall(method, context, &cq_)) { - CallOpSet ops; + CallOpSet ops; ops.SendInitialMetadata(context->send_initial_metadata_); // TODO(ctiller): don't assert GPR_ASSERT(ops.SendMessage(request)); @@ -158,8 +159,7 @@ class ClientWriter : public ClientWriterInterface { template ClientWriter(ChannelInterface* channel, const RpcMethod& method, ClientContext* context, R* response) - : context_(context), - call_(channel->CreateCall(method, context, &cq_)) { + : context_(context), call_(channel->CreateCall(method, context, &cq_)) { finish_ops_.RecvMessage(response); CallOpSet ops; @@ -408,8 +408,7 @@ class AsyncWriterInterface { template class ClientAsyncReaderInterface : public ClientAsyncStreamingInterface, - public AsyncReaderInterface { -}; + public AsyncReaderInterface {}; template class ClientAsyncReader GRPC_FINAL : public ClientAsyncReaderInterface { @@ -457,7 +456,8 @@ class ClientAsyncReader GRPC_FINAL : public ClientAsyncReaderInterface { private: ClientContext* context_; Call call_; - CallOpSet init_ops_; + CallOpSet + init_ops_; CallOpSet meta_ops_; CallOpSet> read_ops_; CallOpSet finish_ops_; @@ -477,8 +477,7 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncWriterInterface { ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq, const RpcMethod& method, ClientContext* context, R* response, void* tag) - : context_(context), - call_(channel->CreateCall(method, context, cq)) { + : context_(context), call_(channel->CreateCall(method, context, cq)) { finish_ops_.RecvMessage(response); init_ops_.set_output_tag(tag); @@ -523,7 +522,8 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncWriterInterface { CallOpSet meta_ops_; CallOpSet write_ops_; CallOpSet writes_done_ops_; - CallOpSet finish_ops_; + CallOpSet finish_ops_; }; // Client-side interface for bi-directional streaming. @@ -628,7 +628,9 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface, } // The response is dropped if the status is not OK. if (status.IsOk() && !finish_ops_.SendMessage(msg)) { - finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, Status(INTERNAL, "Failed to serialize response")); + finish_ops_.ServerSendStatus( + ctx_->trailing_metadata_, + Status(INTERNAL, "Failed to serialize response")); } else { finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); } @@ -653,7 +655,8 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface, ServerContext* ctx_; CallOpSet meta_ops_; CallOpSet> read_ops_; - CallOpSet finish_ops_; + CallOpSet finish_ops_; }; template diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index 077eeb1c07..4fbce9c8d9 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -223,7 +223,9 @@ #endif /* Validate platform combinations */ -#if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + defined(GPR_WIN32_ATOMIC) != 1 +#if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \ + defined(GPR_WIN32_ATOMIC) != \ + 1 #error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC #endif @@ -231,7 +233,9 @@ #error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64 #endif -#if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != 1 +#if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + \ + defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \ + 1 #error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WIN32, GPR_CPU_IPHONE, GPR_CPU_CUSTOM #endif @@ -239,11 +243,15 @@ #error Must define GPR_POSIX_SOCKET to use GPR_POSIX_MULTIPOLL_WITH_POLL #endif -#if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + defined(GPR_CUSTOM_SOCKET) != 1 +#if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + \ + defined(GPR_CUSTOM_SOCKET) != \ + 1 #error Must define exactly one of GPR_POSIX_SOCKET, GPR_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET #endif -#if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + defined(GPR_CUSTOM_TLS) != 1 +#if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \ + defined(GPR_CUSTOM_TLS) != \ + 1 #error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS #endif @@ -268,10 +276,10 @@ typedef uintptr_t gpr_uintptr; #ifndef GRPC_MUST_USE_RESULT #ifdef __GNUC__ -#define GRPC_MUST_USE_RESULT __attribute__ ((warn_unused_result)) +#define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) #else #define GRPC_MUST_USE_RESULT #endif #endif -#endif /* GRPC_SUPPORT_PORT_PLATFORM_H */ +#endif /* GRPC_SUPPORT_PORT_PLATFORM_H */ diff --git a/src/compiler/config.h b/src/compiler/config.h index 06ccd8530c..cd52aca57d 100644 --- a/src/compiler/config.h +++ b/src/compiler/config.h @@ -49,7 +49,8 @@ #ifndef GRPC_CUSTOM_CODEGENERATOR #include #define GRPC_CUSTOM_CODEGENERATOR ::google::protobuf::compiler::CodeGenerator -#define GRPC_CUSTOM_GENERATORCONTEXT ::google::protobuf::compiler::GeneratorContext +#define GRPC_CUSTOM_GENERATORCONTEXT \ + ::google::protobuf::compiler::GeneratorContext #endif #ifndef GRPC_CUSTOM_PRINTER @@ -58,7 +59,8 @@ #include #define GRPC_CUSTOM_PRINTER ::google::protobuf::io::Printer #define GRPC_CUSTOM_CODEDOUTPUTSTREAM ::google::protobuf::io::CodedOutputStream -#define GRPC_CUSTOM_STRINGOUTPUTSTREAM ::google::protobuf::io::StringOutputStream +#define GRPC_CUSTOM_STRINGOUTPUTSTREAM \ + ::google::protobuf::io::StringOutputStream #endif #ifndef GRPC_CUSTOM_PLUGINMAIN diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index d03eaddf40..0b69848f7d 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -97,7 +97,8 @@ grpc::string GetHeaderPrologue(const grpc::protobuf::FileDescriptor *file, vars["filename_base"] = grpc_generator::StripProto(file->name()); printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); - printer.Print(vars, "// If you make any local change, they will be lost.\n"); + printer.Print(vars, + "// If you make any local change, they will be lost.\n"); printer.Print(vars, "// source: $filename$\n"); printer.Print(vars, "#ifndef GRPC_$filename_identifier$__INCLUDED\n"); printer.Print(vars, "#define GRPC_$filename_identifier$__INCLUDED\n"); @@ -142,10 +143,10 @@ grpc::string GetHeaderIncludes(const grpc::protobuf::FileDescriptor *file, return temp; } -void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, - const grpc::protobuf::MethodDescriptor *method, - std::map *vars, - bool is_public) { +void PrintHeaderClientMethodInterfaces( + grpc::protobuf::io::Printer *printer, + const grpc::protobuf::MethodDescriptor *method, + std::map *vars, bool is_public) { (*vars)["Method"] = method->name(); (*vars)["Request"] = grpc_cpp_generator::ClassName(method->input_type(), true); @@ -158,19 +159,17 @@ void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, *vars, "virtual ::grpc::Status $Method$(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response) = 0;\n"); - printer->Print( - *vars, - "std::unique_ptr< " - "::grpc::ClientAsyncResponseReaderInterface< $Response$>> " - "Async$Method$(::grpc::ClientContext* context, " - "const $Request$& request, " - "::grpc::CompletionQueue* cq) {\n"); + printer->Print(*vars, + "std::unique_ptr< " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>> " + "Async$Method$(::grpc::ClientContext* context, " + "const $Request$& request, " + "::grpc::CompletionQueue* cq) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientAsyncResponseReaderInterface< $Response$>>(" - "Async$Method$Raw(context, request, cq));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientAsyncResponseReaderInterface< $Response$>>(" + "Async$Method$Raw(context, request, cq));\n"); printer->Outdent(); printer->Print("}\n"); } else if (ClientOnlyStreaming(method)) { @@ -189,14 +188,14 @@ void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, printer->Print( *vars, "std::unique_ptr< ::grpc::ClientAsyncWriterInterface< $Request$>>" - " Async$Method$(::grpc::ClientContext* context, $Response$* response, " + " Async$Method$(::grpc::ClientContext* context, $Response$* " + "response, " "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientAsyncWriterInterface< $Request$>>(" - "Async$Method$Raw(context, response, cq, tag));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientAsyncWriterInterface< $Request$>>(" + "Async$Method$Raw(context, response, cq, tag));\n"); printer->Outdent(); printer->Print("}\n"); } else if (ServerOnlyStreaming(method)) { @@ -219,18 +218,17 @@ void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, "::grpc::ClientContext* context, const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientAsyncReaderInterface< $Response$>>(" - "Async$Method$Raw(context, request, cq, tag));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientAsyncReaderInterface< $Response$>>(" + "Async$Method$Raw(context, request, cq, tag));\n"); printer->Outdent(); printer->Print("}\n"); } else if (BidiStreaming(method)) { - printer->Print( - *vars, - "std::unique_ptr< ::grpc::ClientReaderWriterInterface< $Request$, $Response$>> " - "$Method$(::grpc::ClientContext* context) {\n"); + printer->Print(*vars, + "std::unique_ptr< ::grpc::ClientReaderWriterInterface< " + "$Request$, $Response$>> " + "$Method$(::grpc::ClientContext* context) {\n"); printer->Indent(); printer->Print( *vars, @@ -268,12 +266,11 @@ void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, "virtual ::grpc::ClientWriterInterface< $Request$>*" " $Method$Raw(" "::grpc::ClientContext* context, $Response$* response) = 0;\n"); - printer->Print( - *vars, - "virtual ::grpc::ClientAsyncWriterInterface< $Request$>*" - " Async$Method$Raw(::grpc::ClientContext* context, " - "$Response$* response, " - "::grpc::CompletionQueue* cq, void* tag) = 0;\n"); + printer->Print(*vars, + "virtual ::grpc::ClientAsyncWriterInterface< $Request$>*" + " Async$Method$Raw(::grpc::ClientContext* context, " + "$Response$* response, " + "::grpc::CompletionQueue* cq, void* tag) = 0;\n"); } else if (ServerOnlyStreaming(method)) { printer->Print( *vars, @@ -286,16 +283,15 @@ void PrintHeaderClientMethodInterfaces(grpc::protobuf::io::Printer *printer, "::grpc::ClientContext* context, const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag) = 0;\n"); } else if (BidiStreaming(method)) { - printer->Print( - *vars, - "virtual ::grpc::ClientReaderWriterInterface< $Request$, $Response$>* " - "$Method$Raw(::grpc::ClientContext* context) = 0;\n"); - printer->Print( - *vars, - "virtual ::grpc::ClientAsyncReaderWriterInterface< " - "$Request$, $Response$>* " - "Async$Method$Raw(::grpc::ClientContext* context, " - "::grpc::CompletionQueue* cq, void* tag) = 0;\n"); + printer->Print(*vars, + "virtual ::grpc::ClientReaderWriterInterface< $Request$, " + "$Response$>* " + "$Method$Raw(::grpc::ClientContext* context) = 0;\n"); + printer->Print(*vars, + "virtual ::grpc::ClientAsyncReaderWriterInterface< " + "$Request$, $Response$>* " + "Async$Method$Raw(::grpc::ClientContext* context, " + "::grpc::CompletionQueue* cq, void* tag) = 0;\n"); } } } @@ -322,11 +318,10 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, "const $Request$& request, " "::grpc::CompletionQueue* cq) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientAsyncResponseReader< $Response$>>(" - "Async$Method$Raw(context, request, cq));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientAsyncResponseReader< $Response$>>(" + "Async$Method$Raw(context, request, cq));\n"); printer->Outdent(); printer->Print("}\n"); } else if (ClientOnlyStreaming(method)) { @@ -336,17 +331,16 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, " $Method$(" "::grpc::ClientContext* context, $Response$* response) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< ::grpc::ClientWriter< $Request$>>" - "($Method$Raw(context, response));\n"); + printer->Print(*vars, + "return std::unique_ptr< ::grpc::ClientWriter< $Request$>>" + "($Method$Raw(context, response));\n"); printer->Outdent(); printer->Print("}\n"); - printer->Print( - *vars, - "std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>>" - " Async$Method$(::grpc::ClientContext* context, $Response$* response, " - "::grpc::CompletionQueue* cq, void* tag) {\n"); + printer->Print(*vars, + "std::unique_ptr< ::grpc::ClientAsyncWriter< $Request$>>" + " Async$Method$(::grpc::ClientContext* context, " + "$Response$* response, " + "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Indent(); printer->Print( *vars, @@ -386,53 +380,47 @@ void PrintHeaderClientMethod(grpc::protobuf::io::Printer *printer, "std::unique_ptr< ::grpc::ClientReaderWriter< $Request$, $Response$>>" " $Method$(::grpc::ClientContext* context) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientReaderWriter< $Request$, $Response$>>(" - "$Method$Raw(context));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientReaderWriter< $Request$, $Response$>>(" + "$Method$Raw(context));\n"); printer->Outdent(); printer->Print("}\n"); - printer->Print( - *vars, - "std::unique_ptr< ::grpc::ClientAsyncReaderWriter< " - "$Request$, $Response$>> " - "Async$Method$(::grpc::ClientContext* context, " - "::grpc::CompletionQueue* cq, void* tag) {\n"); + printer->Print(*vars, + "std::unique_ptr< ::grpc::ClientAsyncReaderWriter< " + "$Request$, $Response$>> " + "Async$Method$(::grpc::ClientContext* context, " + "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Indent(); - printer->Print( - *vars, - "return std::unique_ptr< " - "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>>(" - "Async$Method$Raw(context, cq, tag));\n"); + printer->Print(*vars, + "return std::unique_ptr< " + "::grpc::ClientAsyncReaderWriter< $Request$, $Response$>>(" + "Async$Method$Raw(context, cq, tag));\n"); printer->Outdent(); printer->Print("}\n"); } } else { if (NoStreaming(method)) { - printer->Print( - *vars, - "::grpc::ClientAsyncResponseReader< $Response$>* " - "Async$Method$Raw(::grpc::ClientContext* context, " - "const $Request$& request, " - "::grpc::CompletionQueue* cq) GRPC_OVERRIDE;\n"); + printer->Print(*vars, + "::grpc::ClientAsyncResponseReader< $Response$>* " + "Async$Method$Raw(::grpc::ClientContext* context, " + "const $Request$& request, " + "::grpc::CompletionQueue* cq) GRPC_OVERRIDE;\n"); } else if (ClientOnlyStreaming(method)) { - printer->Print( - *vars, - "::grpc::ClientWriter< $Request$>* $Method$Raw(" - "::grpc::ClientContext* context, $Response$* response) " - "GRPC_OVERRIDE;\n"); + printer->Print(*vars, + "::grpc::ClientWriter< $Request$>* $Method$Raw(" + "::grpc::ClientContext* context, $Response$* response) " + "GRPC_OVERRIDE;\n"); printer->Print( *vars, "::grpc::ClientAsyncWriter< $Request$>* Async$Method$Raw(" "::grpc::ClientContext* context, $Response$* response, " "::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE;\n"); } else if (ServerOnlyStreaming(method)) { - printer->Print( - *vars, - "::grpc::ClientReader< $Response$>* $Method$Raw(" - "::grpc::ClientContext* context, const $Request$& request)" - " GRPC_OVERRIDE;\n"); + printer->Print(*vars, + "::grpc::ClientReader< $Response$>* $Method$Raw(" + "::grpc::ClientContext* context, const $Request$& request)" + " GRPC_OVERRIDE;\n"); printer->Print( *vars, "::grpc::ClientAsyncReader< $Response$>* Async$Method$Raw(" @@ -630,7 +618,7 @@ grpc::string GetHeaderServices(const grpc::protobuf::FileDescriptor *file, const Parameters ¶ms) { grpc::string output; { - // Scope the output stream so it closes and finalizes output to the string. + // Scope the output stream so it closes and finalizes output to the string. grpc::protobuf::io::StringOutputStream output_stream(&output); grpc::protobuf::io::Printer printer(&output_stream, '$'); std::map vars; @@ -694,7 +682,8 @@ grpc::string GetSourcePrologue(const grpc::protobuf::FileDescriptor *file, vars["filename_base"] = grpc_generator::StripProto(file->name()); printer.Print(vars, "// Generated by the gRPC protobuf plugin.\n"); - printer.Print(vars, "// If you make any local change, they will be lost.\n"); + printer.Print(vars, + "// If you make any local change, they will be lost.\n"); printer.Print(vars, "// source: $filename$\n\n"); printer.Print(vars, "#include \"$filename_base$.pb.h\"\n"); printer.Print(vars, "#include \"$filename_base$.grpc.pb.h\"\n"); diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index 69baa419a6..9108713c58 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -50,16 +50,16 @@ class CompletionQueue; class Credentials; class StreamContextInterface; -class Channel GRPC_FINAL : public GrpcLibrary, - public ChannelInterface { +class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface { public: Channel(const grpc::string& target, grpc_channel* c_channel); ~Channel() GRPC_OVERRIDE; - virtual void *RegisterMethod(const char *method) GRPC_OVERRIDE; + virtual void* RegisterMethod(const char* method) GRPC_OVERRIDE; virtual Call CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) GRPC_OVERRIDE; - virtual void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) GRPC_OVERRIDE; + virtual void PerformOpsOnCall(CallOpSetInterface* ops, + Call* call) GRPC_OVERRIDE; private: const grpc::string target_; diff --git a/src/cpp/proto/proto_utils.cc b/src/cpp/proto/proto_utils.cc index a4a37c7000..9e8bf1a631 100644 --- a/src/cpp/proto/proto_utils.cc +++ b/src/cpp/proto/proto_utils.cc @@ -67,7 +67,7 @@ class GrpcBufferWriter GRPC_FINAL slice_ = gpr_slice_malloc(block_size_); } *data = GPR_SLICE_START_PTR(slice_); - byte_count_ += *size = GPR_SLICE_LENGTH(slice_); + byte_count_ += * size = GPR_SLICE_LENGTH(slice_); gpr_slice_buffer_add(slice_buffer_, slice_); return true; } @@ -118,7 +118,7 @@ class GrpcBufferReader GRPC_FINAL } gpr_slice_unref(slice_); *data = GPR_SLICE_START_PTR(slice_); - byte_count_ += *size = GPR_SLICE_LENGTH(slice_); + byte_count_ += * size = GPR_SLICE_LENGTH(slice_); return true; } @@ -158,7 +158,7 @@ bool SerializeProto(const grpc::protobuf::Message& msg, grpc_byte_buffer** bp) { } Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, - int max_message_size) { + int max_message_size) { if (!buffer) { return Status(INVALID_ARGUMENT, "No payload"); } @@ -169,7 +169,7 @@ Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, } if (!msg->ParseFromCodedStream(&decoder)) { return Status(INVALID_ARGUMENT, msg->InitializationErrorString()); - } + } if (!decoder.ConsumedEntireMessage()) { return Status(INVALID_ARGUMENT, "Did not read entire message"); } diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index bd97d707a7..b750868607 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -71,9 +71,7 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { grpc_metadata_array_init(&request_metadata_); } - ~SyncRequest() { - grpc_metadata_array_destroy(&request_metadata_); - } + ~SyncRequest() { grpc_metadata_array_destroy(&request_metadata_); } static SyncRequest* Wait(CompletionQueue* cq, bool* ok) { void* tag = nullptr; @@ -129,8 +127,8 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag { void Run() { ctx_.BeginCompletionOp(&call_); - method_->handler()->RunHandler( - MethodHandler::HandlerParameter(&call_, &ctx_, request_payload_, call_.max_message_size())); + method_->handler()->RunHandler(MethodHandler::HandlerParameter( + &call_, &ctx_, request_payload_, call_.max_message_size())); void* ignored_tag; bool ignored_ok; cq_.Shutdown(); @@ -422,23 +420,27 @@ void Server::RequestAsyncGenericCall(GenericServerContext* context, } #endif -Server::BaseAsyncRequest::BaseAsyncRequest(Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag) -: server_(server), context_(context), stream_(stream), call_cq_(call_cq), call_(nullptr) { +Server::BaseAsyncRequest::BaseAsyncRequest( + Server* server, ServerContext* context, + ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag) + : server_(server), + context_(context), + stream_(stream), + call_cq_(call_cq), + call_(nullptr) { memset(&initial_metadata_array_, 0, sizeof(initial_metadata_array_)); } -Server::BaseAsyncRequest::~BaseAsyncRequest() { -} +Server::BaseAsyncRequest::~BaseAsyncRequest() {} bool Server::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) { if (*status) { for (size_t i = 0; i < initial_metadata_array_.count; i++) { context_->client_metadata_.insert(std::make_pair( grpc::string(initial_metadata_array_.metadata[i].key), - grpc::string( - initial_metadata_array_.metadata[i].value, - initial_metadata_array_.metadata[i].value + initial_metadata_array_.metadata[i].value_length))); + grpc::string(initial_metadata_array_.metadata[i].value, + initial_metadata_array_.metadata[i].value + + initial_metadata_array_.metadata[i].value_length))); } } context_->call_ = call_; @@ -453,27 +455,31 @@ bool Server::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) { return true; } -Server::RegisteredAsyncRequest::RegisteredAsyncRequest(Server* server, ServerContext* context, - ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag) +Server::RegisteredAsyncRequest::RegisteredAsyncRequest( + Server* server, ServerContext* context, + ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, void* tag) : BaseAsyncRequest(server, context, stream, call_cq, tag) {} - -void Server::RegisteredAsyncRequest::IssueRequest(void* registered_method, grpc_byte_buffer** payload, ServerCompletionQueue *notification_cq) { +void Server::RegisteredAsyncRequest::IssueRequest( + void* registered_method, grpc_byte_buffer** payload, + ServerCompletionQueue* notification_cq) { grpc_server_request_registered_call( - server_->server_, registered_method, &call_, &context_->deadline_, &initial_metadata_array_, payload, call_cq_->cq(), notification_cq->cq(), this); + server_->server_, registered_method, &call_, &context_->deadline_, + &initial_metadata_array_, payload, call_cq_->cq(), notification_cq->cq(), + this); } -Server::GenericAsyncRequest::GenericAsyncRequest(Server* server, GenericServerContext* context, - ServerAsyncStreamingInterface* stream, - CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, - void* tag) -: BaseAsyncRequest(server, context, stream, call_cq, tag) { +Server::GenericAsyncRequest::GenericAsyncRequest( + Server* server, GenericServerContext* context, + ServerAsyncStreamingInterface* stream, CompletionQueue* call_cq, + ServerCompletionQueue* notification_cq, void* tag) + : BaseAsyncRequest(server, context, stream, call_cq, tag) { grpc_call_details_init(&call_details_); GPR_ASSERT(notification_cq); GPR_ASSERT(call_cq); - grpc_server_request_call(server->server_, &call_, &call_details_, &initial_metadata_array_, - call_cq->cq(), notification_cq->cq(), this); + grpc_server_request_call(server->server_, &call_, &call_details_, + &initial_metadata_array_, call_cq->cq(), + notification_cq->cq(), this); } bool Server::GenericAsyncRequest::FinalizeResult(void** tag, bool* status) { -- cgit v1.2.3 From b14fbf7804a32f2e22c41e1ff85998ecdf9ccd1e Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 10 Jun 2015 23:49:23 +0200 Subject: Flagging unused parameters as unused. --- src/compiler/cpp_generator.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/compiler/cpp_generator.cc') diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index b0d2b5d229..c00c85bb90 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -849,6 +849,9 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, "::grpc::Status $ns$$Service$::Service::$Method$(" "::grpc::ServerContext* context, " "const $Request$* request, $Response$* response) {\n"); + printer->Print(" (void) context;\n"); + printer->Print(" (void) request;\n"); + printer->Print(" (void) response;\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED);\n"); @@ -859,6 +862,9 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, "::grpc::ServerContext* context, " "::grpc::ServerReader< $Request$>* reader, " "$Response$* response) {\n"); + printer->Print(" (void) context;\n"); + printer->Print(" (void) reader;\n"); + printer->Print(" (void) response;\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED);\n"); @@ -869,6 +875,9 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, "::grpc::ServerContext* context, " "const $Request$* request, " "::grpc::ServerWriter< $Response$>* writer) {\n"); + printer->Print(" (void) context;\n"); + printer->Print(" (void) request;\n"); + printer->Print(" (void) writer;\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED);\n"); @@ -879,6 +888,8 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, "::grpc::ServerContext* context, " "::grpc::ServerReaderWriter< $Response$, $Request$>* " "stream) {\n"); + printer->Print(" (void) context;\n"); + printer->Print(" (void) stream;\n"); printer->Print( " return ::grpc::Status(" "::grpc::StatusCode::UNIMPLEMENTED);\n"); -- cgit v1.2.3 From c1a2c314fb45dafe73b01db23944503cf8961330 Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Tue, 16 Jun 2015 10:59:46 -0700 Subject: Update the Status API --- include/grpc++/async_unary_call.h | 4 +- include/grpc++/client_context.h | 2 +- include/grpc++/impl/client_unary_call.h | 2 +- include/grpc++/impl/service_type.h | 2 +- include/grpc++/status.h | 9 ++--- include/grpc++/stream.h | 4 +- src/compiler/cpp_generator.cc | 8 ++-- src/cpp/client/client_unary_call.cc | 2 +- src/cpp/common/call.cc | 4 +- src/cpp/util/status.cc | 2 +- test/cpp/end2end/async_end2end_test.cc | 18 ++++----- test/cpp/end2end/client_crash_test.cc | 4 +- test/cpp/end2end/end2end_test.cc | 68 ++++++++++++++++---------------- test/cpp/end2end/generic_end2end_test.cc | 4 +- test/cpp/end2end/mock_test.cc | 4 +- test/cpp/end2end/thread_stress_test.cc | 6 +-- test/cpp/interop/interop_client.cc | 8 ++-- test/cpp/qps/client_sync.cc | 4 +- test/cpp/qps/driver.cc | 4 +- test/cpp/qps/qps_worker.cc | 24 +++++------ test/cpp/util/cli_call.cc | 6 +-- test/cpp/util/cli_call_test.cc | 2 +- 22 files changed, 95 insertions(+), 96 deletions(-) (limited to 'src/compiler/cpp_generator.cc') diff --git a/include/grpc++/async_unary_call.h b/include/grpc++/async_unary_call.h index 786f8c7184..abb6308782 100644 --- a/include/grpc++/async_unary_call.h +++ b/include/grpc++/async_unary_call.h @@ -117,7 +117,7 @@ class ServerAsyncResponseWriter GRPC_FINAL ctx_->sent_initial_metadata_ = true; } // The response is dropped if the status is not OK. - if (status.IsOk()) { + if (status.ok()) { finish_buf_.AddSendMessage(msg); } finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); @@ -125,7 +125,7 @@ class ServerAsyncResponseWriter GRPC_FINAL } void FinishWithError(const Status& status, void* tag) { - GPR_ASSERT(!status.IsOk()); + GPR_ASSERT(!status.ok()); finish_buf_.Reset(tag); if (!ctx_->sent_initial_metadata_) { finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 6d9015f278..ecf4cc7f7b 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -41,6 +41,7 @@ #include #include #include +#include #include struct grpc_call; @@ -53,7 +54,6 @@ class ChannelInterface; class CompletionQueue; class Credentials; class RpcMethod; -class Status; template class ClientReader; template diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h index 0e8aeed781..2f234fd3ac 100644 --- a/include/grpc++/impl/client_unary_call.h +++ b/include/grpc++/impl/client_unary_call.h @@ -35,6 +35,7 @@ #define GRPCXX_IMPL_CLIENT_UNARY_CALL_H #include +#include namespace grpc { @@ -42,7 +43,6 @@ class ChannelInterface; class ClientContext; class CompletionQueue; class RpcMethod; -class Status; // Wrapper that performs a blocking unary call Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, diff --git a/include/grpc++/impl/service_type.h b/include/grpc++/impl/service_type.h index bc39bb82ac..25e437edad 100644 --- a/include/grpc++/impl/service_type.h +++ b/include/grpc++/impl/service_type.h @@ -35,6 +35,7 @@ #define GRPCXX_IMPL_SERVICE_TYPE_H #include +#include namespace grpc { @@ -44,7 +45,6 @@ class RpcService; class Server; class ServerCompletionQueue; class ServerContext; -class Status; class SynchronousService { public: diff --git a/include/grpc++/status.h b/include/grpc++/status.h index 8073319eab..fb8526ddce 100644 --- a/include/grpc++/status.h +++ b/include/grpc++/status.h @@ -42,18 +42,17 @@ namespace grpc { class Status { public: Status() : code_(StatusCode::OK) {} - explicit Status(StatusCode code) : code_(code) {} Status(StatusCode code, const grpc::string& details) : code_(code), details_(details) {} // Pre-defined special status objects. static const Status& OK; - static const Status& Cancelled; + static const Status& CANCELLED; - StatusCode code() const { return code_; } - grpc::string details() const { return details_; } + StatusCode error_code() const { return code_; } + grpc::string error_message() const { return details_; } - bool IsOk() const { return code_ == StatusCode::OK; } + bool ok() const { return code_ == StatusCode::OK; } private: StatusCode code_; diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index c836f98c2a..472911e62b 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -615,7 +615,7 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface, ctx_->sent_initial_metadata_ = true; } // The response is dropped if the status is not OK. - if (status.IsOk()) { + if (status.ok()) { finish_buf_.AddSendMessage(msg); } finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); @@ -623,7 +623,7 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface, } void FinishWithError(const Status& status, void* tag) { - GPR_ASSERT(!status.IsOk()); + GPR_ASSERT(!status.ok()); finish_buf_.Reset(tag); if (!ctx_->sent_initial_metadata_) { finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index c00c85bb90..6cd615019b 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -854,7 +854,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, printer->Print(" (void) response;\n"); printer->Print( " return ::grpc::Status(" - "::grpc::StatusCode::UNIMPLEMENTED);\n"); + "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); printer->Print("}\n\n"); } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, @@ -867,7 +867,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, printer->Print(" (void) response;\n"); printer->Print( " return ::grpc::Status(" - "::grpc::StatusCode::UNIMPLEMENTED);\n"); + "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); printer->Print("}\n\n"); } else if (ServerOnlyStreaming(method)) { printer->Print(*vars, @@ -880,7 +880,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, printer->Print(" (void) writer;\n"); printer->Print( " return ::grpc::Status(" - "::grpc::StatusCode::UNIMPLEMENTED);\n"); + "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); printer->Print("}\n\n"); } else if (BidiStreaming(method)) { printer->Print(*vars, @@ -892,7 +892,7 @@ void PrintSourceServerMethod(grpc::protobuf::io::Printer *printer, printer->Print(" (void) stream;\n"); printer->Print( " return ::grpc::Status(" - "::grpc::StatusCode::UNIMPLEMENTED);\n"); + "::grpc::StatusCode::UNIMPLEMENTED, \"\");\n"); printer->Print("}\n\n"); } } diff --git a/src/cpp/client/client_unary_call.cc b/src/cpp/client/client_unary_call.cc index 7e7ea78bcd..55e589306f 100644 --- a/src/cpp/client/client_unary_call.cc +++ b/src/cpp/client/client_unary_call.cc @@ -57,7 +57,7 @@ Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, buf.AddClientSendClose(); buf.AddClientRecvStatus(context, &status); call.PerformOps(&buf); - GPR_ASSERT((cq.Pluck(&buf) && buf.got_message) || !status.IsOk()); + GPR_ASSERT((cq.Pluck(&buf) && buf.got_message) || !status.ok()); return status; } diff --git a/src/cpp/common/call.cc b/src/cpp/common/call.cc index 1068111e3f..bbe4bf6d8b 100644 --- a/src/cpp/common/call.cc +++ b/src/cpp/common/call.cc @@ -214,8 +214,8 @@ void CallOpBuffer::AddServerSendStatus( trailing_metadata_count_ = 0; } send_status_available_ = true; - send_status_code_ = static_cast(status.code()); - send_status_details_ = status.details(); + send_status_code_ = static_cast(status.error_code()); + send_status_details_ = status.error_message(); } void CallOpBuffer::FillOps(grpc_op* ops, size_t* nops) { diff --git a/src/cpp/util/status.cc b/src/cpp/util/status.cc index b694a513e7..5bb9eda3d9 100644 --- a/src/cpp/util/status.cc +++ b/src/cpp/util/status.cc @@ -36,6 +36,6 @@ namespace grpc { const Status& Status::OK = Status(); -const Status& Status::Cancelled = Status(StatusCode::CANCELLED); +const Status& Status::CANCELLED = Status(StatusCode::CANCELLED, ""); } // namespace grpc diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 24595a820f..871f956491 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -157,7 +157,7 @@ class AsyncEnd2endTest : public ::testing::Test { client_ok(4); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } } @@ -218,7 +218,7 @@ TEST_F(AsyncEnd2endTest, AsyncNextRpc) { verify_timed_ok(&cli_cq_, 4, true); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } // Two pings and a final pong. @@ -272,7 +272,7 @@ TEST_F(AsyncEnd2endTest, SimpleClientStreaming) { client_ok(10); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } // One ping, two pongs. @@ -323,7 +323,7 @@ TEST_F(AsyncEnd2endTest, SimpleServerStreaming) { cli_stream->Finish(&recv_status, tag(9)); client_ok(9); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } // One ping, one pong. @@ -376,7 +376,7 @@ TEST_F(AsyncEnd2endTest, SimpleBidiStreaming) { cli_stream->Finish(&recv_status, tag(10)); client_ok(10); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } // Metadata tests @@ -420,7 +420,7 @@ TEST_F(AsyncEnd2endTest, ClientInitialMetadataRpc) { client_ok(4); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) { @@ -467,7 +467,7 @@ TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) { client_ok(6); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { @@ -507,7 +507,7 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { response_reader->Finish(&recv_response, &recv_status, tag(5)); client_ok(5); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); EXPECT_EQ(meta1.second, server_trailing_metadata.find(meta1.first)->second); EXPECT_EQ(meta2.second, server_trailing_metadata.find(meta2.first)->second); @@ -580,7 +580,7 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) { response_reader->Finish(&recv_response, &recv_status, tag(6)); client_ok(6); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); EXPECT_EQ(meta5.second, server_trailing_metadata.find(meta5.first)->second); EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second); diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc index e86681f75a..aeba295947 100644 --- a/test/cpp/end2end/client_crash_test.cc +++ b/test/cpp/end2end/client_crash_test.cc @@ -119,7 +119,7 @@ TEST_F(CrashTest, KillAfterWrite) { EXPECT_FALSE(stream->Read(&response)); - EXPECT_FALSE(stream->Finish().IsOk()); + EXPECT_FALSE(stream->Finish().ok()); } TEST_F(CrashTest, KillBeforeWrite) { @@ -142,7 +142,7 @@ TEST_F(CrashTest, KillBeforeWrite) { EXPECT_FALSE(stream->Write(request)); EXPECT_FALSE(stream->Read(&response)); - EXPECT_FALSE(stream->Finish().IsOk()); + EXPECT_FALSE(stream->Finish().ok()); } } // namespace diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index f48cf953a4..45ba8b0878 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -101,13 +101,13 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { gpr_now(), gpr_time_from_micros(request->param().client_cancel_after_us()))); } - return Status::Cancelled; + return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(), gpr_time_from_micros(request->param().server_cancel_after_us()))); - return Status::Cancelled; + return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); } @@ -232,7 +232,7 @@ static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, ClientContext context; Status s = stub->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } } @@ -265,7 +265,7 @@ TEST_F(End2endTest, RpcDeadlineExpires) { std::chrono::system_clock::now() + std::chrono::microseconds(10); context.set_deadline(deadline); Status s = stub_->Echo(&context, request, &response); - EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.code()); + EXPECT_EQ(StatusCode::DEADLINE_EXCEEDED, s.error_code()); } // Set a long but finite deadline. @@ -281,7 +281,7 @@ TEST_F(End2endTest, RpcLongDeadline) { context.set_deadline(deadline); Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } // Ask server to echo back the deadline it sees. @@ -298,7 +298,7 @@ TEST_F(End2endTest, EchoDeadline) { context.set_deadline(deadline); Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); gpr_timespec sent_deadline; Timepoint2Timespec(deadline, &sent_deadline); // Allow 1 second error. @@ -317,7 +317,7 @@ TEST_F(End2endTest, EchoDeadlineForNoDeadlineRpc) { ClientContext context; Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); EXPECT_EQ(response.param().request_deadline(), gpr_inf_future.tv_sec); } @@ -329,9 +329,9 @@ TEST_F(End2endTest, UnimplementedRpc) { ClientContext context; Status s = stub_->Unimplemented(&context, request, &response); - EXPECT_FALSE(s.IsOk()); - EXPECT_EQ(s.code(), grpc::StatusCode::UNIMPLEMENTED); - EXPECT_EQ(s.details(), ""); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(s.error_code(), grpc::StatusCode::UNIMPLEMENTED); + EXPECT_EQ(s.error_message(), ""); EXPECT_EQ(response.message(), ""); } @@ -347,7 +347,7 @@ TEST_F(End2endTest, RequestStreamOneRequest) { stream->WritesDone(); Status s = stream->Finish(); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } TEST_F(End2endTest, RequestStreamTwoRequests) { @@ -363,7 +363,7 @@ TEST_F(End2endTest, RequestStreamTwoRequests) { stream->WritesDone(); Status s = stream->Finish(); EXPECT_EQ(response.message(), "hellohello"); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } TEST_F(End2endTest, ResponseStream) { @@ -383,7 +383,7 @@ TEST_F(End2endTest, ResponseStream) { EXPECT_FALSE(stream->Read(&response)); Status s = stream->Finish(); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } TEST_F(End2endTest, BidiStream) { @@ -414,7 +414,7 @@ TEST_F(End2endTest, BidiStream) { EXPECT_FALSE(stream->Read(&response)); Status s = stream->Finish(); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } // Talk to the two services with the same name but different package names. @@ -433,7 +433,7 @@ TEST_F(End2endTest, DiffPackageServices) { ClientContext context; Status s = stub->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); std::unique_ptr dup_pkg_stub( @@ -441,7 +441,7 @@ TEST_F(End2endTest, DiffPackageServices) { ClientContext context2; s = dup_pkg_stub->Echo(&context2, request, &response); EXPECT_EQ("no package", response.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } // rpc and stream should fail on bad credentials. @@ -459,16 +459,16 @@ TEST_F(End2endTest, BadCredentials) { Status s = stub->Echo(&context, request, &response); EXPECT_EQ("", response.message()); - EXPECT_FALSE(s.IsOk()); - EXPECT_EQ(StatusCode::UNKNOWN, s.code()); - EXPECT_EQ("Rpc sent on a lame channel.", s.details()); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(StatusCode::UNKNOWN, s.error_code()); + EXPECT_EQ("Rpc sent on a lame channel.", s.error_message()); ClientContext context2; auto stream = stub->BidiStream(&context2); s = stream->Finish(); - EXPECT_FALSE(s.IsOk()); - EXPECT_EQ(StatusCode::UNKNOWN, s.code()); - EXPECT_EQ("Rpc sent on a lame channel.", s.details()); + EXPECT_FALSE(s.ok()); + EXPECT_EQ(StatusCode::UNKNOWN, s.error_code()); + EXPECT_EQ("Rpc sent on a lame channel.", s.error_message()); } void CancelRpc(ClientContext* context, int delay_us, TestServiceImpl* service) { @@ -491,8 +491,8 @@ TEST_F(End2endTest, ClientCancelsRpc) { std::thread cancel_thread(CancelRpc, &context, kCancelDelayUs, &service_); Status s = stub_->Echo(&context, request, &response); cancel_thread.join(); - EXPECT_EQ(StatusCode::CANCELLED, s.code()); - EXPECT_EQ(s.details(), "Cancelled"); + EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); + EXPECT_EQ(s.error_message(), "Cancelled"); } // Server cancels rpc after 1ms @@ -505,8 +505,8 @@ TEST_F(End2endTest, ServerCancelsRpc) { ClientContext context; Status s = stub_->Echo(&context, request, &response); - EXPECT_EQ(StatusCode::CANCELLED, s.code()); - EXPECT_TRUE(s.details().empty()); + EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); + EXPECT_TRUE(s.error_message().empty()); } // Client cancels request stream after sending two messages @@ -524,7 +524,7 @@ TEST_F(End2endTest, ClientCancelsRequestStream) { context.TryCancel(); Status s = stream->Finish(); - EXPECT_EQ(grpc::StatusCode::CANCELLED, s.code()); + EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); EXPECT_EQ(response.message(), ""); } @@ -558,7 +558,7 @@ TEST_F(End2endTest, ClientCancelsResponseStream) { Status s = stream->Finish(); // The final status could be either of CANCELLED or OK depending on // who won the race. - EXPECT_GE(grpc::StatusCode::CANCELLED, s.code()); + EXPECT_GE(grpc::StatusCode::CANCELLED, s.error_code()); } // Client cancels bidi stream after sending some messages @@ -591,7 +591,7 @@ TEST_F(End2endTest, ClientCancelsBidi) { } Status s = stream->Finish(); - EXPECT_EQ(grpc::StatusCode::CANCELLED, s.code()); + EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code()); } TEST_F(End2endTest, RpcMaxMessageSize) { @@ -602,7 +602,7 @@ TEST_F(End2endTest, RpcMaxMessageSize) { ClientContext context; Status s = stub_->Echo(&context, request, &response); - EXPECT_FALSE(s.IsOk()); + EXPECT_FALSE(s.ok()); } bool MetadataContains(const std::multimap& metadata, @@ -632,7 +632,7 @@ TEST_F(End2endTest, SetPerCallCredentials) { Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(request.message(), response.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); EXPECT_TRUE(MetadataContains(context.GetServerTrailingMetadata(), GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, "fake_token")); @@ -652,8 +652,8 @@ TEST_F(End2endTest, InsecurePerCallCredentials) { request.mutable_param()->set_echo_metadata(true); Status s = stub_->Echo(&context, request, &response); - EXPECT_EQ(StatusCode::CANCELLED, s.code()); - EXPECT_EQ("Failed to set credentials to rpc.", s.details()); + EXPECT_EQ(StatusCode::CANCELLED, s.error_code()); + EXPECT_EQ("Failed to set credentials to rpc.", s.error_message()); } TEST_F(End2endTest, OverridePerCallCredentials) { @@ -684,7 +684,7 @@ TEST_F(End2endTest, OverridePerCallCredentials) { GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, "fake_selector1")); EXPECT_EQ(request.message(), response.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } } // namespace testing diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 80e43fd854..7132b6b1f1 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -190,7 +190,7 @@ class GenericEnd2endTest : public ::testing::Test { client_ok(9); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } } @@ -273,7 +273,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { client_ok(10); EXPECT_EQ(send_response.message(), recv_response.message()); - EXPECT_TRUE(recv_status.IsOk()); + EXPECT_TRUE(recv_status.ok()); } } // namespace diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc index 0226da672c..2809ab8d3c 100644 --- a/test/cpp/end2end/mock_test.cc +++ b/test/cpp/end2end/mock_test.cc @@ -168,7 +168,7 @@ class FakeClient { request.set_message("hello world"); Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(request.message(), response.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } void DoBidiStream() { @@ -199,7 +199,7 @@ class FakeClient { EXPECT_FALSE(stream->Read(&response)); Status s = stream->Finish(); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } void ResetStub(TestService::StubInterface* stub) { stub_ = stub; } diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc index 5ee29e40f4..0b43dfd106 100644 --- a/test/cpp/end2end/thread_stress_test.cc +++ b/test/cpp/end2end/thread_stress_test.cc @@ -99,13 +99,13 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service { gpr_now(), gpr_time_from_micros(request->param().client_cancel_after_us()))); } - return Status::Cancelled; + return Status::CANCELLED; } else if (request->has_param() && request->param().server_cancel_after_us()) { gpr_sleep_until(gpr_time_add( gpr_now(), gpr_time_from_micros(request->param().server_cancel_after_us()))); - return Status::Cancelled; + return Status::CANCELLED; } else { EXPECT_FALSE(context->IsCancelled()); } @@ -219,7 +219,7 @@ static void SendRpc(grpc::cpp::test::util::TestService::Stub* stub, ClientContext context; Status s = stub->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); } } diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index e351059246..f08f90b139 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -65,11 +65,11 @@ InteropClient::InteropClient(std::shared_ptr channel) : channel_(channel) {} void InteropClient::AssertOkOrPrintErrorStatus(const Status& s) { - if (s.IsOk()) { + if (s.ok()) { return; } - gpr_log(GPR_INFO, "Error status code: %d, message: %s", s.code(), - s.details().c_str()); + gpr_log(GPR_INFO, "Error status code: %d, message: %s", s.error_code(), + s.error_message().c_str()); GPR_ASSERT(0); } @@ -321,7 +321,7 @@ void InteropClient::DoCancelAfterBegin() { gpr_log(GPR_INFO, "Trying to cancel..."); context.TryCancel(); Status s = stream->Finish(); - GPR_ASSERT(s.code() == StatusCode::CANCELLED); + GPR_ASSERT(s.error_code() == StatusCode::CANCELLED); gpr_log(GPR_INFO, "Canceling streaming done."); } diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index d1682caf06..718698bfe1 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -103,7 +103,7 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient { grpc::Status s = stub->UnaryCall(&context, request_, &responses_[thread_idx]); histogram->Add((Timer::Now() - start) * 1e9); - return s.IsOk(); + return s.ok(); } }; @@ -124,7 +124,7 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient { for (auto stream = stream_.begin(); stream != stream_.end(); stream++) { if (*stream) { (*stream)->WritesDone(); - EXPECT_TRUE((*stream)->Finish().IsOk()); + EXPECT_TRUE((*stream)->Finish().ok()); } } } diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index bf12730f97..c8cc11e6ab 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -241,11 +241,11 @@ std::unique_ptr RunScenario( for (auto client = clients.begin(); client != clients.end(); client++) { GPR_ASSERT(client->stream->WritesDone()); - GPR_ASSERT(client->stream->Finish().IsOk()); + GPR_ASSERT(client->stream->Finish().ok()); } for (auto server = servers.begin(); server != servers.end(); server++) { GPR_ASSERT(server->stream->WritesDone()); - GPR_ASSERT(server->stream->Finish().IsOk()); + GPR_ASSERT(server->stream->Finish().ok()); } return result; } diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index 40cc4cb89b..423275ee85 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -100,7 +100,7 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { GRPC_OVERRIDE { InstanceGuard g(this); if (!g.Acquired()) { - return Status(RESOURCE_EXHAUSTED); + return Status(StatusCode::RESOURCE_EXHAUSTED, ""); } grpc_profiler_start("qps_client.prof"); @@ -114,7 +114,7 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { GRPC_OVERRIDE { InstanceGuard g(this); if (!g.Acquired()) { - return Status(RESOURCE_EXHAUSTED); + return Status(StatusCode::RESOURCE_EXHAUSTED, ""); } grpc_profiler_start("qps_server.prof"); @@ -159,22 +159,22 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { ServerReaderWriter* stream) { ClientArgs args; if (!stream->Read(&args)) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } if (!args.has_setup()) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } auto client = CreateClient(args.setup()); if (!client) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } ClientStatus status; if (!stream->Write(status)) { - return Status(UNKNOWN); + return Status(StatusCode::UNKNOWN, ""); } while (stream->Read(&args)) { if (!args.has_mark()) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } *status.mutable_stats() = client->Mark(); stream->Write(status); @@ -187,23 +187,23 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { ServerReaderWriter* stream) { ServerArgs args; if (!stream->Read(&args)) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } if (!args.has_setup()) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } auto server = CreateServer(args.setup(), server_port_); if (!server) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } ServerStatus status; status.set_port(server_port_); if (!stream->Write(status)) { - return Status(UNKNOWN); + return Status(StatusCode::UNKNOWN, ""); } while (stream->Read(&args)) { if (!args.has_mark()) { - return Status(INVALID_ARGUMENT); + return Status(StatusCode::INVALID_ARGUMENT, ""); } *status.mutable_stats() = server->Mark(); stream->Write(status); diff --git a/test/cpp/util/cli_call.cc b/test/cpp/util/cli_call.cc index eb67b8d314..fa952e8349 100644 --- a/test/cpp/util/cli_call.cc +++ b/test/cpp/util/cli_call.cc @@ -86,7 +86,7 @@ void CliCall::Call(std::shared_ptr channel, cq.Next(&got_tag, &ok); GPR_ASSERT(ok); - if (status.IsOk()) { + if (status.ok()) { std::cout << "RPC finished with OK status." << std::endl; std::vector slices; recv_buffer.Dump(&slices); @@ -97,8 +97,8 @@ void CliCall::Call(std::shared_ptr channel, slices[i].size()); } } else { - std::cout << "RPC finished with status code " << status.code() - << " details: " << status.details() << std::endl; + std::cout << "RPC finished with status code " << status.error_code() + << " details: " << status.error_message() << std::endl; } } diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc index 457a5e77de..12539c7479 100644 --- a/test/cpp/util/cli_call_test.cc +++ b/test/cpp/util/cli_call_test.cc @@ -108,7 +108,7 @@ TEST_F(CliCallTest, SimpleRpc) { ClientContext context; Status s = stub_->Echo(&context, request, &response); EXPECT_EQ(response.message(), request.message()); - EXPECT_TRUE(s.IsOk()); + EXPECT_TRUE(s.ok()); const grpc::string kMethod("/grpc.cpp.test.util.TestService/Echo"); grpc::string request_bin, response_bin, expected_response_bin; -- cgit v1.2.3