Skip to content

Commit

Permalink
Merge pull request grpc#932 from yang-g/imacros
Browse files Browse the repository at this point in the history
Add a macro to control the string and protobuf::Message typedef.
  • Loading branch information
nicolasnoble committed Mar 3, 2015
2 parents d437948 + 5b61d51 commit 95fb8b1
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 93 deletions.
3 changes: 1 addition & 2 deletions include/grpc++/async_unary_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClientAsyncResponseReader GRPC_FINAL {
public:
ClientAsyncResponseReader(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod& method, ClientContext* context,
const google::protobuf::Message& request, void* tag)
const grpc::protobuf::Message& request, void* tag)
: context_(context),
call_(channel->CreateCall(method, context, cq)) {
init_buf_.Reset(tag);
Expand Down Expand Up @@ -77,7 +77,6 @@ class ClientAsyncResponseReader GRPC_FINAL {
call_.PerformOps(&finish_buf_);
}


private:
ClientContext* context_;
Call call_;
Expand Down
6 changes: 0 additions & 6 deletions include/grpc++/channel_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
#include <grpc++/status.h>
#include <grpc++/impl/call.h>

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google

struct grpc_call;

namespace grpc {
Expand Down
6 changes: 0 additions & 6 deletions include/grpc++/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ using std::chrono::system_clock;
struct grpc_call;
struct grpc_completion_queue;

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google

namespace grpc {

class CallOpBuffer;
Expand Down
4 changes: 2 additions & 2 deletions include/grpc++/completion_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class CompletionQueue {
friend Status BlockingUnaryCall(ChannelInterface *channel,
const RpcMethod &method,
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result);
const grpc::protobuf::Message &request,
grpc::protobuf::Message *result);

// Wraps grpc_completion_queue_pluck.
// Cannot be mixed with calls to Next().
Expand Down
18 changes: 15 additions & 3 deletions include/grpc++/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#ifndef GRPCXX_CONFIG_H
#define GRPCXX_CONFIG_H

#include <string>

#ifdef GRPC_OLD_CXX
#define GRPC_FINAL
#define GRPC_OVERRIDE
Expand All @@ -44,9 +42,23 @@
#define GRPC_OVERRIDE override
#endif

#ifndef GRPC_CUSTOM_STRING
#include <string>
#define GRPC_CUSTOM_STRING std::string
#endif

#ifndef GRPC_CUSTOM_MESSAGE
#include <google/protobuf/message.h>
#define GRPC_CUSTOM_MESSAGE ::google::protobuf::Message
#endif

namespace grpc {

typedef std::string string;
typedef GRPC_CUSTOM_STRING string;

namespace protobuf {
typedef GRPC_CUSTOM_MESSAGE Message;
} // namespace protobuf

} // namespace grpc

Expand Down
14 changes: 4 additions & 10 deletions include/grpc++/impl/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@
#include <memory>
#include <map>

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google

struct grpc_call;
struct grpc_op;

Expand All @@ -67,8 +61,8 @@ class CallOpBuffer : public CompletionQueueTag {
std::multimap<grpc::string, grpc::string> *metadata);
void AddSendInitialMetadata(ClientContext *ctx);
void AddRecvInitialMetadata(ClientContext *ctx);
void AddSendMessage(const google::protobuf::Message &message);
void AddRecvMessage(google::protobuf::Message *message);
void AddSendMessage(const grpc::protobuf::Message &message);
void AddRecvMessage(grpc::protobuf::Message *message);
void AddClientSendClose();
void AddClientRecvStatus(ClientContext *ctx, Status *status);
void AddServerSendStatus(std::multimap<grpc::string, grpc::string> *metadata,
Expand All @@ -95,10 +89,10 @@ class CallOpBuffer : public CompletionQueueTag {
std::multimap<grpc::string, grpc::string> *recv_initial_metadata_;
grpc_metadata_array recv_initial_metadata_arr_;
// Send message
const google::protobuf::Message *send_message_;
const grpc::protobuf::Message *send_message_;
grpc_byte_buffer *send_message_buf_;
// Recv message
google::protobuf::Message *recv_message_;
grpc::protobuf::Message *recv_message_;
grpc_byte_buffer *recv_message_buf_;
// Client send close
bool client_send_close_;
Expand Down
10 changes: 3 additions & 7 deletions include/grpc++/impl/client_unary_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
#ifndef GRPCXX_IMPL_CLIENT_UNARY_CALL_H
#define GRPCXX_IMPL_CLIENT_UNARY_CALL_H

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google
#include <grpc++/config.h>

namespace grpc {

Expand All @@ -51,8 +47,8 @@ class Status;
// Wrapper that performs a blocking unary call
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result);
const grpc::protobuf::Message &request,
grpc::protobuf::Message *result);

} // namespace grpc

Expand Down
6 changes: 0 additions & 6 deletions include/grpc++/impl/rpc_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@
#ifndef GRPCXX_IMPL_RPC_METHOD_H
#define GRPCXX_IMPL_RPC_METHOD_H

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google

namespace grpc {

class RpcMethod {
Expand Down
20 changes: 10 additions & 10 deletions include/grpc++/impl/rpc_service_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class MethodHandler {
virtual ~MethodHandler() {}
struct HandlerParameter {
HandlerParameter(Call* c, ServerContext* context,
const google::protobuf::Message* req,
google::protobuf::Message* resp)
const grpc::protobuf::Message* req,
grpc::protobuf::Message* resp)
: call(c), server_context(context), request(req), response(resp) {}
Call* call;
ServerContext* server_context;
const google::protobuf::Message* request;
google::protobuf::Message* response;
const grpc::protobuf::Message* request;
grpc::protobuf::Message* response;
};
virtual Status RunHandler(const HandlerParameter& param) = 0;
};
Expand Down Expand Up @@ -165,26 +165,26 @@ class RpcServiceMethod : public RpcMethod {
// Takes ownership of the handler and two prototype objects.
RpcServiceMethod(const char* name, RpcMethod::RpcType type,
MethodHandler* handler,
google::protobuf::Message* request_prototype,
google::protobuf::Message* response_prototype)
grpc::protobuf::Message* request_prototype,
grpc::protobuf::Message* response_prototype)
: RpcMethod(name, type),
handler_(handler),
request_prototype_(request_prototype),
response_prototype_(response_prototype) {}

MethodHandler* handler() { return handler_.get(); }

google::protobuf::Message* AllocateRequestProto() {
grpc::protobuf::Message* AllocateRequestProto() {
return request_prototype_->New();
}
google::protobuf::Message* AllocateResponseProto() {
grpc::protobuf::Message* AllocateResponseProto() {
return response_prototype_->New();
}

private:
std::unique_ptr<MethodHandler> handler_;
std::unique_ptr<google::protobuf::Message> request_prototype_;
std::unique_ptr<google::protobuf::Message> response_prototype_;
std::unique_ptr<grpc::protobuf::Message> request_prototype_;
std::unique_ptr<grpc::protobuf::Message> response_prototype_;
};

// This class contains all the method information for an rpc service. It is
Expand Down
12 changes: 4 additions & 8 deletions include/grpc++/impl/service_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
#ifndef GRPCXX_IMPL_SERVICE_TYPE_H
#define GRPCXX_IMPL_SERVICE_TYPE_H

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google
#include <grpc++/config.h>

namespace grpc {

Expand Down Expand Up @@ -72,7 +68,7 @@ class AsynchronousService {
public:
virtual void RequestAsyncCall(void* registered_method,
ServerContext* context,
::google::protobuf::Message* request,
::grpc::protobuf::Message* request,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) = 0;
};
Expand All @@ -91,7 +87,7 @@ class AsynchronousService {

protected:
void RequestAsyncUnary(int index, ServerContext* context,
::google::protobuf::Message* request,
grpc::protobuf::Message* request,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) {
dispatch_impl_->RequestAsyncCall(request_args_[index], context, request,
Expand All @@ -104,7 +100,7 @@ class AsynchronousService {
stream, cq, tag);
}
void RequestServerStreaming(int index, ServerContext* context,
::google::protobuf::Message* request,
grpc::protobuf::Message* request,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) {
dispatch_impl_->RequestAsyncCall(request_args_[index], context, request,
Expand Down
8 changes: 1 addition & 7 deletions include/grpc++/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@

struct grpc_server;

namespace google {
namespace protobuf {
class Message;
} // namespace protobuf
} // namespace google

namespace grpc {
class AsynchronousService;
class RpcService;
Expand Down Expand Up @@ -101,7 +95,7 @@ class Server GRPC_FINAL : private CallHook,

// DispatchImpl
void RequestAsyncCall(void* registered_method, ServerContext* context,
::google::protobuf::Message* request,
grpc::protobuf::Message* request,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag);

Expand Down
12 changes: 6 additions & 6 deletions include/grpc++/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ClientReader GRPC_FINAL : public ClientStreamingInterface,
public:
// Blocking create a stream and write the first request out.
ClientReader(ChannelInterface* channel, const RpcMethod& method,
ClientContext* context, const google::protobuf::Message& request)
ClientContext* context, const grpc::protobuf::Message& request)
: context_(context), call_(channel->CreateCall(method, context, &cq_)) {
CallOpBuffer buf;
buf.AddSendInitialMetadata(&context->send_initial_metadata_);
Expand Down Expand Up @@ -142,7 +142,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface,
public:
// Blocking create a stream.
ClientWriter(ChannelInterface* channel, const RpcMethod& method,
ClientContext* context, google::protobuf::Message* response)
ClientContext* context, grpc::protobuf::Message* response)
: context_(context),
response_(response),
call_(channel->CreateCall(method, context, &cq_)) {
Expand Down Expand Up @@ -179,7 +179,7 @@ class ClientWriter GRPC_FINAL : public ClientStreamingInterface,

private:
ClientContext* context_;
google::protobuf::Message* const response_;
grpc::protobuf::Message* const response_;
CompletionQueue cq_;
Call call_;
};
Expand Down Expand Up @@ -386,7 +386,7 @@ class ClientAsyncReader GRPC_FINAL : public ClientAsyncStreamingInterface,
// Create a stream and write the first request out.
ClientAsyncReader(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod& method, ClientContext* context,
const google::protobuf::Message& request, void* tag)
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_);
Expand Down Expand Up @@ -436,7 +436,7 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncStreamingInterface,
public:
ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq,
const RpcMethod& method, ClientContext* context,
google::protobuf::Message* response, void* tag)
grpc::protobuf::Message* response, void* tag)
: context_(context),
response_(response),
call_(channel->CreateCall(method, context, cq)) {
Expand Down Expand Up @@ -477,7 +477,7 @@ class ClientAsyncWriter GRPC_FINAL : public ClientAsyncStreamingInterface,

private:
ClientContext* context_;
google::protobuf::Message* const response_;
grpc::protobuf::Message* const response_;
Call call_;
CallOpBuffer init_buf_;
CallOpBuffer meta_buf_;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/client/client_unary_call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace grpc {
// Wrapper that performs a blocking unary call
Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method,
ClientContext *context,
const google::protobuf::Message &request,
google::protobuf::Message *result) {
const grpc::protobuf::Message &request,
grpc::protobuf::Message *result) {
CompletionQueue cq;
Call call(channel->CreateCall(method, context, &cq));
CallOpBuffer buf;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/common/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ void CallOpBuffer::AddSendInitialMetadata(ClientContext* ctx) {
AddSendInitialMetadata(&ctx->send_initial_metadata_);
}

void CallOpBuffer::AddSendMessage(const google::protobuf::Message& message) {
void CallOpBuffer::AddSendMessage(const grpc::protobuf::Message& message) {
send_message_ = &message;
}

void CallOpBuffer::AddRecvMessage(google::protobuf::Message* message) {
void CallOpBuffer::AddRecvMessage(grpc::protobuf::Message* message) {
recv_message_ = message;
recv_message_->Clear();
}
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/proto/proto_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

namespace grpc {

bool SerializeProto(const google::protobuf::Message &msg,
bool SerializeProto(const grpc::protobuf::Message &msg,
grpc_byte_buffer **bp) {
grpc::string msg_str;
bool success = msg.SerializeToString(&msg_str);
Expand All @@ -54,7 +54,7 @@ bool SerializeProto(const google::protobuf::Message &msg,
}

bool DeserializeProto(grpc_byte_buffer *buffer,
google::protobuf::Message *msg) {
grpc::protobuf::Message *msg) {
grpc::string msg_string;
grpc_byte_buffer_reader *reader = grpc_byte_buffer_reader_create(buffer);
gpr_slice slice;
Expand Down
11 changes: 4 additions & 7 deletions src/cpp/proto/proto_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,20 @@
#ifndef GRPC_INTERNAL_CPP_PROTO_PROTO_UTILS_H
#define GRPC_INTERNAL_CPP_PROTO_PROTO_UTILS_H

#include <grpc++/config.h>

struct grpc_byte_buffer;
namespace google {
namespace protobuf {
class Message;
}
}

namespace grpc {

// Serialize the msg into a buffer created inside the function. The caller
// should destroy the returned buffer when done with it. If serialization fails,
// false is returned and buffer is left unchanged.
bool SerializeProto(const google::protobuf::Message &msg,
bool SerializeProto(const grpc::protobuf::Message &msg,
grpc_byte_buffer **buffer);

// The caller keeps ownership of buffer and msg.
bool DeserializeProto(grpc_byte_buffer *buffer, google::protobuf::Message *msg);
bool DeserializeProto(grpc_byte_buffer *buffer, grpc::protobuf::Message *msg);

} // namespace grpc

Expand Down
Loading

0 comments on commit 95fb8b1

Please sign in to comment.