Skip to content

Commit

Permalink
Merge pull request grpc#1066 from yang-g/clangformat
Browse files Browse the repository at this point in the history
clang-format c++ code
  • Loading branch information
vjpai committed Mar 19, 2015
2 parents 99f1c1e + 050e37a commit f0b6e26
Show file tree
Hide file tree
Showing 40 changed files with 240 additions and 250 deletions.
5 changes: 3 additions & 2 deletions include/grpc++/async_generic_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ struct grpc_server;

namespace grpc {

typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> GenericServerAsyncReaderWriter;
typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
GenericServerAsyncReaderWriter;

class GenericServerContext GRPC_FINAL : public ServerContext {
public:
Expand Down Expand Up @@ -74,6 +75,6 @@ class AsyncGenericService GRPC_FINAL {
Server* server_;
};

} // namespace grpc
} // namespace grpc

#endif // GRPCXX_ASYNC_GENERIC_SERVICE_H
7 changes: 3 additions & 4 deletions include/grpc++/async_unary_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ template <class R>
class ClientAsyncResponseReader GRPC_FINAL {
public:
ClientAsyncResponseReader(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod& method, ClientContext* context,
const grpc::protobuf::Message& request, void* tag)
: context_(context),
call_(channel->CreateCall(method, context, cq)) {
const RpcMethod& method, ClientContext* context,
const grpc::protobuf::Message& request, void* tag)
: context_(context), call_(channel->CreateCall(method, context, cq)) {
init_buf_.Reset(tag);
init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_);
init_buf_.AddSendMessage(request);
Expand Down
4 changes: 1 addition & 3 deletions include/grpc++/byte_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class ByteBuffer GRPC_FINAL {
buffer_ = buf;
}

grpc_byte_buffer* buffer() const {
return buffer_;
}
grpc_byte_buffer* buffer() const { return buffer_; }

grpc_byte_buffer* buffer_;
};
Expand Down
4 changes: 2 additions & 2 deletions include/grpc++/channel_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ChannelInterface : public CallHook {
public:
virtual ~ChannelInterface() {}

virtual Call CreateCall(const RpcMethod &method, ClientContext *context,
CompletionQueue *cq) = 0;
virtual Call CreateCall(const RpcMethod& method, ClientContext* context,
CompletionQueue* cq) = 0;
};

} // namespace grpc
Expand Down
30 changes: 13 additions & 17 deletions include/grpc++/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class ClientContext {
ClientContext();
~ClientContext();

void AddMetadata(const grpc::string &meta_key,
const grpc::string &meta_value);
void AddMetadata(const grpc::string& meta_key,
const grpc::string& meta_value);

const std::multimap<grpc::string, grpc::string>& GetServerInitialMetadata() {
GPR_ASSERT(initial_metadata_received_);
Expand All @@ -87,19 +87,17 @@ class ClientContext {
return trailing_metadata_;
}

void set_absolute_deadline(const system_clock::time_point &deadline);
void set_absolute_deadline(const system_clock::time_point& deadline);
system_clock::time_point absolute_deadline();

void set_authority(const grpc::string& authority) {
authority_ = authority;
}
void set_authority(const grpc::string& authority) { authority_ = authority; }

void TryCancel();

private:
// Disallow copy and assign.
ClientContext(const ClientContext &);
ClientContext &operator=(const ClientContext &);
ClientContext(const ClientContext&);
ClientContext& operator=(const ClientContext&);

friend class CallOpBuffer;
friend class Channel;
Expand All @@ -118,24 +116,22 @@ class ClientContext {
template <class R>
friend class ::grpc::ClientAsyncResponseReader;

grpc_call *call() { return call_; }
void set_call(grpc_call *call) {
grpc_call* call() { return call_; }
void set_call(grpc_call* call) {
GPR_ASSERT(call_ == nullptr);
call_ = call;
}

grpc_completion_queue *cq() { return cq_; }
void set_cq(grpc_completion_queue *cq) { cq_ = cq; }
grpc_completion_queue* cq() { return cq_; }
void set_cq(grpc_completion_queue* cq) { cq_ = cq; }

gpr_timespec RawDeadline() { return absolute_deadline_; }

grpc::string authority() {
return authority_;
}
grpc::string authority() { return authority_; }

bool initial_metadata_received_;
grpc_call *call_;
grpc_completion_queue *cq_;
grpc_call* call_;
grpc_completion_queue* cq_;
gpr_timespec absolute_deadline_;
grpc::string authority_;
std::multimap<grpc::string, grpc::string> send_initial_metadata_;
Expand Down
37 changes: 19 additions & 18 deletions include/grpc++/completion_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,37 +66,38 @@ class CompletionQueueTag {
// to do)
// If this function returns false, the tag is dropped and not returned
// from the completion queue
virtual bool FinalizeResult(void **tag, bool *status) = 0;
virtual bool FinalizeResult(void** tag, bool* status) = 0;
};

// grpc_completion_queue wrapper class
class CompletionQueue {
public:
CompletionQueue();
explicit CompletionQueue(grpc_completion_queue *take);
explicit CompletionQueue(grpc_completion_queue* take);
~CompletionQueue();

// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT
enum NextStatus {SHUTDOWN, GOT_EVENT, TIMEOUT};
enum NextStatus { SHUTDOWN, GOT_EVENT, TIMEOUT };

// Nonblocking (until deadline) read from queue.
// Cannot rely on result of tag or ok if return is TIMEOUT
NextStatus AsyncNext(void **tag, bool *ok,
std::chrono::system_clock::time_point deadline);
NextStatus AsyncNext(void** tag, bool* ok,
std::chrono::system_clock::time_point deadline);

// Blocking (until deadline) read from queue.
// Returns false if the queue is ready for destruction, true if event
bool Next(void **tag, bool *ok) {
return (AsyncNext(tag,ok,
(std::chrono::system_clock::time_point::max)()) !=
SHUTDOWN);

bool Next(void** tag, bool* ok) {
return (
AsyncNext(tag, ok, (std::chrono::system_clock::time_point::max)()) !=
SHUTDOWN);
}

// Shutdown has to be called, and the CompletionQueue can only be
// destructed when false is returned from Next().
void Shutdown();

grpc_completion_queue *cq() { return cq_; }
grpc_completion_queue* cq() { return cq_; }

private:
// Friend synchronous wrappers so that they can access Pluck(), which is
Expand All @@ -115,20 +116,20 @@ class CompletionQueue {
friend class ::grpc::ServerReaderWriter;
friend class ::grpc::Server;
friend class ::grpc::ServerContext;
friend Status BlockingUnaryCall(ChannelInterface *channel,
const RpcMethod &method,
ClientContext *context,
const grpc::protobuf::Message &request,
grpc::protobuf::Message *result);
friend Status BlockingUnaryCall(ChannelInterface* channel,
const RpcMethod& method,
ClientContext* context,
const grpc::protobuf::Message& request,
grpc::protobuf::Message* result);

// Wraps grpc_completion_queue_pluck.
// Cannot be mixed with calls to Next().
bool Pluck(CompletionQueueTag *tag);
bool Pluck(CompletionQueueTag* tag);

// Does a single polling pluck on tag
void TryPluck(CompletionQueueTag *tag);
void TryPluck(CompletionQueueTag* tag);

grpc_completion_queue *cq_; // owned
grpc_completion_queue* cq_; // owned
};

} // namespace grpc
Expand Down
7 changes: 4 additions & 3 deletions include/grpc++/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@

#ifndef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM
#include <google/protobuf/io/zero_copy_stream.h>
#define GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ::google::protobuf::io::ZeroCopyOutputStream
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ::google::protobuf::io::ZeroCopyInputStream
#define GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM \
::google::protobuf::io::ZeroCopyOutputStream
#define GRPC_CUSTOM_ZEROCOPYINPUTSTREAM \
::google::protobuf::io::ZeroCopyInputStream
#endif


namespace grpc {

typedef GRPC_CUSTOM_STRING string;
Expand Down
2 changes: 1 addition & 1 deletion include/grpc++/generic_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class GenericStub GRPC_FINAL {
std::shared_ptr<ChannelInterface> channel_;
};

} // namespace grpc
} // namespace grpc

#endif // GRPCXX_GENERIC_STUB_H
72 changes: 36 additions & 36 deletions include/grpc++/impl/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,89 +55,89 @@ class CallOpBuffer : public CompletionQueueTag {
CallOpBuffer();
~CallOpBuffer();

void Reset(void *next_return_tag);
void Reset(void* next_return_tag);

// Does not take ownership.
void AddSendInitialMetadata(
std::multimap<grpc::string, grpc::string> *metadata);
void AddSendInitialMetadata(ClientContext *ctx);
void AddRecvInitialMetadata(ClientContext *ctx);
void AddSendMessage(const grpc::protobuf::Message &message);
std::multimap<grpc::string, grpc::string>* metadata);
void AddSendInitialMetadata(ClientContext* ctx);
void AddRecvInitialMetadata(ClientContext* ctx);
void AddSendMessage(const grpc::protobuf::Message& message);
void AddSendMessage(const ByteBuffer& message);
void AddRecvMessage(grpc::protobuf::Message *message);
void AddRecvMessage(ByteBuffer *message);
void AddRecvMessage(grpc::protobuf::Message* message);
void AddRecvMessage(ByteBuffer* message);
void AddClientSendClose();
void AddClientRecvStatus(ClientContext *ctx, Status *status);
void AddServerSendStatus(std::multimap<grpc::string, grpc::string> *metadata,
const Status &status);
void AddServerRecvClose(bool *cancelled);
void AddClientRecvStatus(ClientContext* ctx, Status* status);
void AddServerSendStatus(std::multimap<grpc::string, grpc::string>* metadata,
const Status& status);
void AddServerRecvClose(bool* cancelled);

// INTERNAL API:

// Convert to an array of grpc_op elements
void FillOps(grpc_op *ops, size_t *nops);
void FillOps(grpc_op* ops, size_t* nops);

// Called by completion queue just prior to returning from Next() or Pluck()
bool FinalizeResult(void **tag, bool *status) GRPC_OVERRIDE;
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;

bool got_message;

private:
void *return_tag_;
void* return_tag_;
// Send initial metadata
bool send_initial_metadata_;
size_t initial_metadata_count_;
grpc_metadata *initial_metadata_;
grpc_metadata* initial_metadata_;
// Recv initial metadta
std::multimap<grpc::string, grpc::string> *recv_initial_metadata_;
std::multimap<grpc::string, grpc::string>* recv_initial_metadata_;
grpc_metadata_array recv_initial_metadata_arr_;
// Send message
const grpc::protobuf::Message *send_message_;
const ByteBuffer *send_message_buffer_;
grpc_byte_buffer *send_buf_;
const grpc::protobuf::Message* send_message_;
const ByteBuffer* send_message_buffer_;
grpc_byte_buffer* send_buf_;
// Recv message
grpc::protobuf::Message *recv_message_;
ByteBuffer *recv_message_buffer_;
grpc_byte_buffer *recv_buf_;
grpc::protobuf::Message* recv_message_;
ByteBuffer* recv_message_buffer_;
grpc_byte_buffer* recv_buf_;
// Client send close
bool client_send_close_;
// Client recv status
std::multimap<grpc::string, grpc::string> *recv_trailing_metadata_;
Status *recv_status_;
std::multimap<grpc::string, grpc::string>* recv_trailing_metadata_;
Status* recv_status_;
grpc_metadata_array recv_trailing_metadata_arr_;
grpc_status_code status_code_;
char *status_details_;
char* status_details_;
size_t status_details_capacity_;
// Server send status
const Status *send_status_;
const Status* send_status_;
size_t trailing_metadata_count_;
grpc_metadata *trailing_metadata_;
grpc_metadata* trailing_metadata_;
int cancelled_buf_;
bool *recv_closed_;
bool* recv_closed_;
};

// Channel and Server implement this to allow them to hook performing ops
class CallHook {
public:
virtual ~CallHook() {}
virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) = 0;
virtual void PerformOpsOnCall(CallOpBuffer* ops, Call* call) = 0;
};

// Straightforward wrapping of the C call object
class Call GRPC_FINAL {
public:
/* call is owned by the caller */
Call(grpc_call *call, CallHook *call_hook_, CompletionQueue *cq);
Call(grpc_call* call, CallHook* call_hook_, CompletionQueue* cq);

void PerformOps(CallOpBuffer *buffer);
void PerformOps(CallOpBuffer* buffer);

grpc_call *call() { return call_; }
CompletionQueue *cq() { return cq_; }
grpc_call* call() { return call_; }
CompletionQueue* cq() { return cq_; }

private:
CallHook *call_hook_;
CompletionQueue *cq_;
grpc_call *call_;
CallHook* call_hook_;
CompletionQueue* cq_;
grpc_call* call_;
};

} // namespace grpc
Expand Down
8 changes: 4 additions & 4 deletions include/grpc++/impl/client_unary_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class RpcMethod;
class Status;

// Wrapper that performs a blocking unary call
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
ClientContext *context,
const grpc::protobuf::Message &request,
grpc::protobuf::Message *result);
Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method,
ClientContext* context,
const grpc::protobuf::Message& request,
grpc::protobuf::Message* result);

} // namespace grpc

Expand Down
10 changes: 5 additions & 5 deletions src/cpp/client/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ class StreamContextInterface;

class Channel GRPC_FINAL : public ChannelInterface {
public:
Channel(const grpc::string &target, grpc_channel *c_channel);
Channel(const grpc::string& target, grpc_channel* c_channel);
~Channel() GRPC_OVERRIDE;

virtual Call CreateCall(const RpcMethod &method, ClientContext *context,
CompletionQueue *cq) GRPC_OVERRIDE;
virtual void PerformOpsOnCall(CallOpBuffer *ops, Call *call) GRPC_OVERRIDE;
virtual Call CreateCall(const RpcMethod& method, ClientContext* context,
CompletionQueue* cq) GRPC_OVERRIDE;
virtual void PerformOpsOnCall(CallOpBuffer* ops, Call* call) GRPC_OVERRIDE;

private:
const grpc::string target_;
grpc_channel *const c_channel_; // owned
grpc_channel* const c_channel_; // owned
};

} // namespace grpc
Expand Down
Loading

0 comments on commit f0b6e26

Please sign in to comment.