Skip to content
Snippets Groups Projects
Commit 573523f1 authored by Craig Tiller's avatar Craig Tiller
Browse files

clang-format

parent 73b7018e
No related branches found
No related tags found
No related merge requests found
...@@ -60,12 +60,18 @@ class ChannelInterface; ...@@ -60,12 +60,18 @@ class ChannelInterface;
class CompletionQueue; class CompletionQueue;
class RpcMethod; class RpcMethod;
class Status; class Status;
template <class R> class ClientReader; template <class R>
template <class W> class ClientWriter; class ClientReader;
template <class R, class W> class ClientReaderWriter; template <class W>
template <class R> class ClientAsyncReader; class ClientWriter;
template <class W> class ClientAsyncWriter; template <class R, class W>
template <class R, class W> class ClientAsyncReaderWriter; class ClientReaderWriter;
template <class R>
class ClientAsyncReader;
template <class W>
class ClientAsyncWriter;
template <class R, class W>
class ClientAsyncReaderWriter;
class ClientContext { class ClientContext {
public: public:
...@@ -97,13 +103,20 @@ class ClientContext { ...@@ -97,13 +103,20 @@ class ClientContext {
friend class CallOpBuffer; friend class CallOpBuffer;
friend class Channel; friend class Channel;
template <class R> friend class ::grpc::ClientReader; template <class R>
template <class W> friend class ::grpc::ClientWriter; friend class ::grpc::ClientReader;
template <class R, class W> friend class ::grpc::ClientReaderWriter; template <class W>
template <class R> friend class ::grpc::ClientAsyncReader; friend class ::grpc::ClientWriter;
template <class W> friend class ::grpc::ClientAsyncWriter; template <class R, class W>
template <class R, class W> friend class ::grpc::ClientAsyncReaderWriter; friend class ::grpc::ClientReaderWriter;
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, template <class R>
friend class ::grpc::ClientAsyncReader;
template <class W>
friend class ::grpc::ClientAsyncWriter;
template <class R, class W>
friend class ::grpc::ClientAsyncReaderWriter;
friend Status BlockingUnaryCall(ChannelInterface *channel,
const RpcMethod &method,
ClientContext *context, ClientContext *context,
const google::protobuf::Message &request, const google::protobuf::Message &request,
google::protobuf::Message *result); google::protobuf::Message *result);
......
...@@ -84,14 +84,21 @@ class CompletionQueue { ...@@ -84,14 +84,21 @@ class CompletionQueue {
grpc_completion_queue *cq() { return cq_; } grpc_completion_queue *cq() { return cq_; }
private: private:
template <class R> friend class ::grpc::ClientReader; template <class R>
template <class W> friend class ::grpc::ClientWriter; friend class ::grpc::ClientReader;
template <class R, class W> friend class ::grpc::ClientReaderWriter; template <class W>
template <class R> friend class ::grpc::ServerReader; friend class ::grpc::ClientWriter;
template <class W> friend class ::grpc::ServerWriter; template <class R, class W>
template <class R, class W> friend class ::grpc::ServerReaderWriter; friend class ::grpc::ClientReaderWriter;
template <class R>
friend class ::grpc::ServerReader;
template <class W>
friend class ::grpc::ServerWriter;
template <class R, class W>
friend class ::grpc::ServerReaderWriter;
friend class ::grpc::Server; friend class ::grpc::Server;
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, friend Status BlockingUnaryCall(ChannelInterface *channel,
const RpcMethod &method,
ClientContext *context, ClientContext *context,
const google::protobuf::Message &request, const google::protobuf::Message &request,
google::protobuf::Message *result); google::protobuf::Message *result);
......
...@@ -85,6 +85,7 @@ class CallOpBuffer : public CompletionQueueTag { ...@@ -85,6 +85,7 @@ class CallOpBuffer : public CompletionQueueTag {
void FinalizeResult(void **tag, bool *status) override; void FinalizeResult(void **tag, bool *status) override;
bool got_message = false; bool got_message = false;
private: private:
void *return_tag_ = nullptr; void *return_tag_ = nullptr;
// Send initial metadata // Send initial metadata
......
...@@ -64,4 +64,3 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ...@@ -64,4 +64,3 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
} // namespace grpc } // namespace grpc
#endif #endif
...@@ -55,14 +55,10 @@ class MethodHandler { ...@@ -55,14 +55,10 @@ class MethodHandler {
public: public:
virtual ~MethodHandler() {} virtual ~MethodHandler() {}
struct HandlerParameter { struct HandlerParameter {
HandlerParameter(Call *c, HandlerParameter(Call* c, ServerContext* context,
ServerContext* context,
const google::protobuf::Message* req, const google::protobuf::Message* req,
google::protobuf::Message* resp) google::protobuf::Message* resp)
: call(c), : call(c), server_context(context), request(req), response(resp) {}
server_context(context),
request(req),
response(resp) {}
Call* call; Call* call;
ServerContext* server_context; ServerContext* server_context;
const google::protobuf::Message* request; const google::protobuf::Message* request;
...@@ -152,7 +148,8 @@ class BidiStreamingHandler : public MethodHandler { ...@@ -152,7 +148,8 @@ class BidiStreamingHandler : public MethodHandler {
: func_(func), service_(service) {} : func_(func), service_(service) {}
Status RunHandler(const HandlerParameter& param) final { Status RunHandler(const HandlerParameter& param) final {
ServerReaderWriter<ResponseType, RequestType> stream(param.call, param.server_context); ServerReaderWriter<ResponseType, RequestType> stream(param.call,
param.server_context);
return func_(service_, param.server_context, &stream); return func_(service_, param.server_context, &stream);
} }
...@@ -195,9 +192,7 @@ class RpcServiceMethod : public RpcMethod { ...@@ -195,9 +192,7 @@ class RpcServiceMethod : public RpcMethod {
class RpcService { class RpcService {
public: public:
// Takes ownership. // Takes ownership.
void AddMethod(RpcServiceMethod* method) { void AddMethod(RpcServiceMethod* method) { methods_.emplace_back(method); }
methods_.emplace_back(method);
}
RpcServiceMethod* GetMethod(int i) { return methods_[i].get(); } RpcServiceMethod* GetMethod(int i) { return methods_[i].get(); }
int GetMethodCount() const { return methods_.size(); } int GetMethodCount() const { return methods_.size(); }
......
...@@ -88,8 +88,7 @@ class ClientReader final : public ClientStreamingInterface, ...@@ -88,8 +88,7 @@ class ClientReader final : public ClientStreamingInterface,
public: public:
// Blocking create a stream and write the first request out. // Blocking create a stream and write the first request out.
ClientReader(ChannelInterface* channel, const RpcMethod& method, ClientReader(ChannelInterface* channel, const RpcMethod& method,
ClientContext *context, ClientContext* context, const google::protobuf::Message& request)
const google::protobuf::Message &request)
: context_(context), call_(channel->CreateCall(method, context, &cq_)) { : context_(context), call_(channel->CreateCall(method, context, &cq_)) {
CallOpBuffer buf; CallOpBuffer buf;
buf.AddSendInitialMetadata(&context->send_initial_metadata_); buf.AddSendInitialMetadata(&context->send_initial_metadata_);
...@@ -145,9 +144,9 @@ class ClientWriter final : public ClientStreamingInterface, ...@@ -145,9 +144,9 @@ class ClientWriter final : public ClientStreamingInterface,
public: public:
// Blocking create a stream. // Blocking create a stream.
ClientWriter(ChannelInterface* channel, const RpcMethod& method, ClientWriter(ChannelInterface* channel, const RpcMethod& method,
ClientContext *context, ClientContext* context, google::protobuf::Message* response)
google::protobuf::Message *response) : context_(context),
: context_(context), response_(response), response_(response),
call_(channel->CreateCall(method, context, &cq_)) { call_(channel->CreateCall(method, context, &cq_)) {
CallOpBuffer buf; CallOpBuffer buf;
buf.AddSendInitialMetadata(&context->send_initial_metadata_); buf.AddSendInitialMetadata(&context->send_initial_metadata_);
...@@ -194,8 +193,8 @@ class ClientReaderWriter final : public ClientStreamingInterface, ...@@ -194,8 +193,8 @@ class ClientReaderWriter final : public ClientStreamingInterface,
public ReaderInterface<R> { public ReaderInterface<R> {
public: public:
// Blocking create a stream. // Blocking create a stream.
ClientReaderWriter(ChannelInterface *channel, ClientReaderWriter(ChannelInterface* channel, const RpcMethod& method,
const RpcMethod &method, ClientContext *context) ClientContext* context)
: context_(context), call_(channel->CreateCall(method, context, &cq_)) { : context_(context), call_(channel->CreateCall(method, context, &cq_)) {
CallOpBuffer buf; CallOpBuffer buf;
buf.AddSendInitialMetadata(&context->send_initial_metadata_); buf.AddSendInitialMetadata(&context->send_initial_metadata_);
...@@ -445,7 +444,8 @@ class ClientAsyncWriter final : public ClientAsyncStreamingInterface, ...@@ -445,7 +444,8 @@ class ClientAsyncWriter final : public ClientAsyncStreamingInterface,
ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq, ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod& method, ClientContext* context, const RpcMethod& method, ClientContext* context,
google::protobuf::Message* response, void* tag) google::protobuf::Message* response, void* tag)
: context_(context), response_(response), : context_(context),
response_(response),
call_(channel->CreateCall(method, context, cq)) { call_(channel->CreateCall(method, context, cq)) {
init_buf_.Reset(tag); init_buf_.Reset(tag);
init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_); init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_);
...@@ -502,7 +502,8 @@ class ClientAsyncReaderWriter final : public ClientAsyncStreamingInterface, ...@@ -502,7 +502,8 @@ class ClientAsyncReaderWriter final : public ClientAsyncStreamingInterface,
public AsyncReaderInterface<R> { public AsyncReaderInterface<R> {
public: public:
ClientAsyncReaderWriter(ChannelInterface* channel, CompletionQueue* cq, ClientAsyncReaderWriter(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod &method, ClientContext *context, void* tag) const RpcMethod& method, ClientContext* context,
void* tag)
: context_(context), call_(channel->CreateCall(method, context, cq)) { : context_(context), call_(channel->CreateCall(method, context, cq)) {
init_buf_.Reset(tag); init_buf_.Reset(tag);
init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_); init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_);
......
...@@ -93,8 +93,7 @@ void Channel::PerformOpsOnCall(CallOpBuffer *buf, Call *call) { ...@@ -93,8 +93,7 @@ void Channel::PerformOpsOnCall(CallOpBuffer *buf, Call *call) {
grpc_op ops[MAX_OPS]; grpc_op ops[MAX_OPS];
buf->FillOps(ops, &nops); buf->FillOps(ops, &nops);
GPR_ASSERT(GRPC_CALL_OK == GPR_ASSERT(GRPC_CALL_OK ==
grpc_call_start_batch(call->call(), ops, nops, grpc_call_start_batch(call->call(), ops, nops, buf));
buf));
} }
} // namespace grpc } // namespace grpc
...@@ -59,8 +59,7 @@ class Channel final : public ChannelInterface { ...@@ -59,8 +59,7 @@ class Channel final : public ChannelInterface {
virtual Call CreateCall(const RpcMethod &method, ClientContext *context, virtual Call CreateCall(const RpcMethod &method, ClientContext *context,
CompletionQueue *cq) override; CompletionQueue *cq) override;
virtual void PerformOpsOnCall(CallOpBuffer *ops, virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) override;
Call *call) override;
private: private:
const grpc::string target_; const grpc::string target_;
......
...@@ -95,13 +95,13 @@ namespace { ...@@ -95,13 +95,13 @@ namespace {
// mess. Make sure it does not happen. // mess. Make sure it does not happen.
grpc_metadata* FillMetadataArray( grpc_metadata* FillMetadataArray(
std::multimap<grpc::string, grpc::string>* metadata) { std::multimap<grpc::string, grpc::string>* metadata) {
if (metadata->empty()) { return nullptr; } if (metadata->empty()) {
grpc_metadata* metadata_array = (grpc_metadata*)gpr_malloc( return nullptr;
metadata->size()* sizeof(grpc_metadata)); }
grpc_metadata* metadata_array =
(grpc_metadata*)gpr_malloc(metadata->size() * sizeof(grpc_metadata));
size_t i = 0; size_t i = 0;
for (auto iter = metadata->cbegin(); for (auto iter = metadata->cbegin(); iter != metadata->cend(); ++iter, ++i) {
iter != metadata->cend();
++iter, ++i) {
metadata_array[i].key = iter->first.c_str(); metadata_array[i].key = iter->first.c_str();
metadata_array[i].value = iter->second.c_str(); metadata_array[i].value = iter->second.c_str();
metadata_array[i].value_length = iter->second.size(); metadata_array[i].value_length = iter->second.size();
...@@ -114,7 +114,8 @@ void FillMetadataMap(grpc_metadata_array* arr, ...@@ -114,7 +114,8 @@ void FillMetadataMap(grpc_metadata_array* arr,
for (size_t i = 0; i < arr->count; i++) { for (size_t i = 0; i < arr->count; i++) {
// TODO(yangg) handle duplicates? // TODO(yangg) handle duplicates?
metadata->insert(std::pair<grpc::string, grpc::string>( metadata->insert(std::pair<grpc::string, grpc::string>(
arr->metadata[i].key, {arr->metadata[i].value, arr->metadata[i].value_length})); arr->metadata[i].key,
{arr->metadata[i].value, arr->metadata[i].value_length}));
} }
grpc_metadata_array_destroy(arr); grpc_metadata_array_destroy(arr);
grpc_metadata_array_init(arr); grpc_metadata_array_init(arr);
...@@ -133,7 +134,6 @@ void CallOpBuffer::AddRecvInitialMetadata( ...@@ -133,7 +134,6 @@ void CallOpBuffer::AddRecvInitialMetadata(
recv_initial_metadata_ = metadata; recv_initial_metadata_ = metadata;
} }
void CallOpBuffer::AddSendInitialMetadata(ClientContext* ctx) { void CallOpBuffer::AddSendInitialMetadata(ClientContext* ctx) {
AddSendInitialMetadata(&ctx->send_initial_metadata_); AddSendInitialMetadata(&ctx->send_initial_metadata_);
} }
...@@ -146,9 +146,7 @@ void CallOpBuffer::AddRecvMessage(google::protobuf::Message *message) { ...@@ -146,9 +146,7 @@ void CallOpBuffer::AddRecvMessage(google::protobuf::Message *message) {
recv_message_ = message; recv_message_ = message;
} }
void CallOpBuffer::AddClientSendClose() { void CallOpBuffer::AddClientSendClose() { client_send_close_ = true; }
client_send_close_ = true;
}
void CallOpBuffer::AddServerRecvClose(bool* cancelled) { void CallOpBuffer::AddServerRecvClose(bool* cancelled) {
recv_closed_ = cancelled; recv_closed_ = cancelled;
...@@ -270,8 +268,7 @@ void CallOpBuffer::FinalizeResult(void **tag, bool *status) { ...@@ -270,8 +268,7 @@ void CallOpBuffer::FinalizeResult(void **tag, bool *status) {
FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_); FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_);
*recv_status_ = Status( *recv_status_ = Status(
static_cast<StatusCode>(status_code_), static_cast<StatusCode>(status_code_),
status_details_ ? grpc::string(status_details_) status_details_ ? grpc::string(status_details_) : grpc::string());
: grpc::string());
} }
if (recv_closed_) { if (recv_closed_) {
*recv_closed_ = cancelled_buf_ != 0; *recv_closed_ = cancelled_buf_ != 0;
......
...@@ -52,7 +52,9 @@ void CompletionQueue::Shutdown() { grpc_completion_queue_shutdown(cq_); } ...@@ -52,7 +52,9 @@ void CompletionQueue::Shutdown() { grpc_completion_queue_shutdown(cq_); }
// Helper class so we can declare a unique_ptr with grpc_event // Helper class so we can declare a unique_ptr with grpc_event
class EventDeleter { class EventDeleter {
public: public:
void operator()(grpc_event *ev) { if (ev) grpc_event_finish(ev); } void operator()(grpc_event *ev) {
if (ev) grpc_event_finish(ev);
}
}; };
bool CompletionQueue::Next(void **tag, bool *ok) { bool CompletionQueue::Next(void **tag, bool *ok) {
......
...@@ -54,8 +54,8 @@ AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); } ...@@ -54,8 +54,8 @@ AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); }
void AsyncServerContext::Accept(grpc_completion_queue *cq) { void AsyncServerContext::Accept(grpc_completion_queue *cq) {
GPR_ASSERT(grpc_call_server_accept_old(call_, cq, this) == GRPC_CALL_OK); GPR_ASSERT(grpc_call_server_accept_old(call_, cq, this) == GRPC_CALL_OK);
GPR_ASSERT(grpc_call_server_end_initial_metadata_old(call_, GRPC_WRITE_BUFFER_HINT) == GPR_ASSERT(grpc_call_server_end_initial_metadata_old(
GRPC_CALL_OK); call_, GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
} }
bool AsyncServerContext::StartRead(google::protobuf::Message *request) { bool AsyncServerContext::StartRead(google::protobuf::Message *request) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment