aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/async_generic_service.h80
-rw-r--r--include/grpc++/async_unary_call.h7
-rw-r--r--include/grpc++/byte_buffer.h82
-rw-r--r--include/grpc++/channel_interface.h4
-rw-r--r--include/grpc++/client_context.h30
-rw-r--r--include/grpc++/completion_queue.h43
-rw-r--r--include/grpc++/config.h7
-rw-r--r--include/grpc++/credentials.h18
-rw-r--r--include/grpc++/generic_stub.h62
-rw-r--r--include/grpc++/impl/call.h73
-rw-r--r--include/grpc++/impl/client_unary_call.h8
-rw-r--r--include/grpc++/server.h10
-rw-r--r--include/grpc++/server_builder.h11
-rw-r--r--include/grpc++/server_context.h2
-rw-r--r--include/grpc++/slice.h74
15 files changed, 425 insertions, 86 deletions
diff --git a/include/grpc++/async_generic_service.h b/include/grpc++/async_generic_service.h
new file mode 100644
index 0000000000..911d31cb1f
--- /dev/null
+++ b/include/grpc++/async_generic_service.h
@@ -0,0 +1,80 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_ASYNC_GENERIC_SERVICE_H
+#define GRPCXX_ASYNC_GENERIC_SERVICE_H
+
+#include <grpc++/byte_buffer.h>
+#include <grpc++/stream.h>
+
+struct grpc_server;
+
+namespace grpc {
+
+typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
+ GenericServerAsyncReaderWriter;
+
+class GenericServerContext GRPC_FINAL : public ServerContext {
+ public:
+ const grpc::string& method() const { return method_; }
+ const grpc::string& host() const { return host_; }
+
+ private:
+ friend class Server;
+
+ grpc::string method_;
+ grpc::string host_;
+};
+
+class AsyncGenericService GRPC_FINAL {
+ public:
+ // TODO(yangg) Once we can add multiple completion queues to the server
+ // in c core, add a CompletionQueue* argument to the ctor here.
+ // TODO(yangg) support methods list.
+ AsyncGenericService(const grpc::string& methods) : server_(nullptr) {}
+
+ void RequestCall(GenericServerContext* ctx,
+ GenericServerAsyncReaderWriter* reader_writer,
+ CompletionQueue* cq, void* tag);
+
+ // The new rpc event should be obtained from this completion queue.
+ CompletionQueue* completion_queue();
+
+ private:
+ friend class Server;
+ Server* server_;
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_ASYNC_GENERIC_SERVICE_H
diff --git a/include/grpc++/async_unary_call.h b/include/grpc++/async_unary_call.h
index 658941bb6d..d1d5be5b50 100644
--- a/include/grpc++/async_unary_call.h
+++ b/include/grpc++/async_unary_call.h
@@ -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);
diff --git a/include/grpc++/byte_buffer.h b/include/grpc++/byte_buffer.h
new file mode 100644
index 0000000000..ceb62622fd
--- /dev/null
+++ b/include/grpc++/byte_buffer.h
@@ -0,0 +1,82 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_BYTE_BUFFER_H
+#define GRPCXX_BYTE_BUFFER_H
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc++/config.h>
+#include <grpc++/slice.h>
+
+#include <vector>
+
+namespace grpc {
+
+class ByteBuffer GRPC_FINAL {
+ public:
+ ByteBuffer() : buffer_(nullptr) {}
+
+ ByteBuffer(Slice* slices, size_t nslices);
+
+ ~ByteBuffer() {
+ if (buffer_) {
+ grpc_byte_buffer_destroy(buffer_);
+ }
+ }
+
+ void Dump(std::vector<Slice>* slices);
+
+ void Clear();
+ size_t Length();
+
+ private:
+ friend class CallOpBuffer;
+
+ // takes ownership
+ void set_buffer(grpc_byte_buffer* buf) {
+ if (buffer_) {
+ gpr_log(GPR_ERROR, "Overriding existing buffer");
+ Clear();
+ }
+ buffer_ = buf;
+ }
+
+ grpc_byte_buffer* buffer() const { return buffer_; }
+
+ grpc_byte_buffer* buffer_;
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_BYTE_BUFFER_H
diff --git a/include/grpc++/channel_interface.h b/include/grpc++/channel_interface.h
index 51260aed3d..7d50b45280 100644
--- a/include/grpc++/channel_interface.h
+++ b/include/grpc++/channel_interface.h
@@ -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
diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h
index c55d7c2d58..4e7f5a7be0 100644
--- a/include/grpc++/client_context.h
+++ b/include/grpc++/client_context.h
@@ -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_);
@@ -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;
@@ -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_;
diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h
index f741e3c36b..f4619a1060 100644
--- a/include/grpc++/completion_queue.h
+++ b/include/grpc++/completion_queue.h
@@ -34,6 +34,7 @@
#ifndef GRPCXX_COMPLETION_QUEUE_H
#define GRPCXX_COMPLETION_QUEUE_H
+#include <chrono>
#include <grpc++/impl/client_unary_call.h>
struct grpc_completion_queue;
@@ -65,26 +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();
- // Blocking read from queue.
- // Returns true if an event was received, false if the queue is ready
- // for destruction.
- bool Next(void **tag, bool *ok);
+ // Tri-state return for AsyncNext: 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);
+
+ // 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);
+ }
// 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
@@ -103,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
diff --git a/include/grpc++/config.h b/include/grpc++/config.h
index 0267b85215..35bf507364 100644
--- a/include/grpc++/config.h
+++ b/include/grpc++/config.h
@@ -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;
diff --git a/include/grpc++/credentials.h b/include/grpc++/credentials.h
index c677cc3e0a..2ac3eec95c 100644
--- a/include/grpc++/credentials.h
+++ b/include/grpc++/credentials.h
@@ -50,8 +50,8 @@ class Credentials {
protected:
friend std::unique_ptr<Credentials> CompositeCredentials(
- const std::unique_ptr<Credentials>& creds1,
- const std::unique_ptr<Credentials>& creds2);
+ const std::unique_ptr<Credentials>& creds1,
+ const std::unique_ptr<Credentials>& creds2);
virtual SecureCredentials* AsSecureCredentials() = 0;
@@ -105,6 +105,20 @@ std::unique_ptr<Credentials> ServiceAccountCredentials(
const grpc::string& json_key, const grpc::string& scope,
std::chrono::seconds token_lifetime);
+// Builds JWT credentials.
+// json_key is the JSON key string containing the client's private key.
+// token_lifetime is the lifetime of each Json Web Token (JWT) created with
+// this credentials. It should not exceed grpc_max_auth_token_lifetime or
+// will be cropped to this value.
+std::unique_ptr<Credentials> JWTCredentials(
+ const grpc::string& json_key, std::chrono::seconds token_lifetime);
+
+// Builds refresh token credentials.
+// json_refresh_token is the JSON string containing the refresh token along
+// with a client_id and client_secret.
+std::unique_ptr<Credentials> RefreshTokenCredentials(
+ const grpc::string& json_refresh_token);
+
// Builds IAM credentials.
std::unique_ptr<Credentials> IAMCredentials(
const grpc::string& authorization_token,
diff --git a/include/grpc++/generic_stub.h b/include/grpc++/generic_stub.h
new file mode 100644
index 0000000000..d4c8380ad4
--- /dev/null
+++ b/include/grpc++/generic_stub.h
@@ -0,0 +1,62 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_GENERIC_STUB_H
+#define GRPCXX_GENERIC_STUB_H
+
+#include <grpc++/byte_buffer.h>
+#include <grpc++/stream.h>
+
+namespace grpc {
+
+typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer>
+ GenericClientAsyncReaderWriter;
+
+// Generic stubs provide a type-unsafe interface to call gRPC methods
+// by name.
+class GenericStub GRPC_FINAL {
+ public:
+ explicit GenericStub(std::shared_ptr<ChannelInterface> channel)
+ : channel_(channel) {}
+
+ // begin a call to a named method
+ std::unique_ptr<GenericClientAsyncReaderWriter> Call(
+ ClientContext* context, const grpc::string& method);
+
+ private:
+ std::shared_ptr<ChannelInterface> channel_;
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_GENERIC_STUB_H
diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h
index 5de5662973..e117ac6313 100644
--- a/include/grpc++/impl/call.h
+++ b/include/grpc++/impl/call.h
@@ -35,9 +35,9 @@
#define GRPCXX_IMPL_CALL_H
#include <grpc/grpc.h>
+#include <grpc++/completion_queue.h>
#include <grpc++/config.h>
#include <grpc++/status.h>
-#include <grpc++/completion_queue.h>
#include <memory>
#include <map>
@@ -47,6 +47,7 @@ struct grpc_op;
namespace grpc {
+class ByteBuffer;
class Call;
class CallOpBuffer : public CompletionQueueTag {
@@ -54,85 +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);
- void AddRecvMessage(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 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_;
- grpc_byte_buffer *send_message_buf_;
+ const grpc::protobuf::Message* send_message_;
+ const ByteBuffer* send_message_buffer_;
+ grpc_byte_buffer* send_buf_;
// Recv message
- grpc::protobuf::Message *recv_message_;
- grpc_byte_buffer *recv_message_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
diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h
index fd9715da50..0e8aeed781 100644
--- a/include/grpc++/impl/client_unary_call.h
+++ b/include/grpc++/impl/client_unary_call.h
@@ -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
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index 43c8432caf..bddb4f62aa 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -49,6 +49,8 @@ struct grpc_server;
namespace grpc {
class AsynchronousService;
+class GenericServerContext;
+class AsyncGenericService;
class RpcService;
class RpcServiceMethod;
class ServerCredentials;
@@ -69,6 +71,7 @@ class Server GRPC_FINAL : private CallHook,
void Wait();
private:
+ friend class AsyncGenericService;
friend class ServerBuilder;
class SyncRequest;
@@ -81,8 +84,9 @@ class Server GRPC_FINAL : private CallHook,
// The service must exist for the lifetime of the Server instance.
bool RegisterService(RpcService* service);
bool RegisterAsyncService(AsynchronousService* service);
+ void RegisterAsyncGenericService(AsyncGenericService* service);
// Add a listening port. Can be called multiple times.
- int AddPort(const grpc::string& addr, ServerCredentials* creds);
+ int AddListeningPort(const grpc::string& addr, ServerCredentials* creds);
// Start the server.
bool Start();
@@ -98,6 +102,10 @@ class Server GRPC_FINAL : private CallHook,
ServerAsyncStreamingInterface* stream,
CompletionQueue* cq, void* tag) GRPC_OVERRIDE;
+ void RequestAsyncGenericCall(GenericServerContext* context,
+ ServerAsyncStreamingInterface* stream,
+ CompletionQueue* cq, void* tag);
+
// Completion queue.
CompletionQueue cq_;
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index a327077563..9a9932ebe0 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -41,6 +41,7 @@
namespace grpc {
+class AsyncGenericService;
class AsynchronousService;
class CompletionQueue;
class RpcService;
@@ -64,10 +65,13 @@ class ServerBuilder {
// instance returned by BuildAndStart().
void RegisterAsyncService(AsynchronousService* service);
+ // Register a generic service.
+ void RegisterAsyncGenericService(AsyncGenericService* service);
+
// Add a listening port. Can be called multiple times.
- void AddPort(const grpc::string& addr,
- std::shared_ptr<ServerCredentials> creds,
- int* selected_port = nullptr);
+ void AddListeningPort(const grpc::string& addr,
+ std::shared_ptr<ServerCredentials> creds,
+ int* selected_port = nullptr);
// Set the thread pool used for running appliation rpc handlers.
// Does not take ownership.
@@ -87,6 +91,7 @@ class ServerBuilder {
std::vector<AsynchronousService*> async_services_;
std::vector<Port> ports_;
std::shared_ptr<ServerCredentials> creds_;
+ AsyncGenericService* generic_service_;
ThreadPoolInterface* thread_pool_;
};
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h
index a986fff46b..9e3b80c641 100644
--- a/include/grpc++/server_context.h
+++ b/include/grpc++/server_context.h
@@ -66,7 +66,7 @@ class CompletionQueue;
class Server;
// Interface of server side rpc context.
-class ServerContext GRPC_FINAL {
+class ServerContext {
public:
ServerContext(); // for async calls
~ServerContext();
diff --git a/include/grpc++/slice.h b/include/grpc++/slice.h
new file mode 100644
index 0000000000..3e01bcf0ad
--- /dev/null
+++ b/include/grpc++/slice.h
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_SLICE_H
+#define GRPCXX_SLICE_H
+
+#include <grpc/support/slice.h>
+#include <grpc++/config.h>
+
+namespace grpc {
+
+class Slice GRPC_FINAL {
+ public:
+ // construct empty slice
+ Slice();
+ // destructor - drops one ref
+ ~Slice();
+ // construct slice from grpc slice, adding a ref
+ enum AddRef { ADD_REF };
+ Slice(gpr_slice slice, AddRef);
+ // construct slice from grpc slice, stealing a ref
+ enum StealRef { STEAL_REF };
+ Slice(gpr_slice slice, StealRef);
+ // copy constructor - adds a ref
+ Slice(const Slice& other);
+ // assignment - ref count is unchanged
+ Slice& operator=(Slice other) {
+ std::swap(slice_, other.slice_);
+ return *this;
+ }
+
+ size_t size() const { return GPR_SLICE_LENGTH(slice_); }
+ const gpr_uint8* begin() const { return GPR_SLICE_START_PTR(slice_); }
+ const gpr_uint8* end() const { return GPR_SLICE_END_PTR(slice_); }
+
+ private:
+ friend class ByteBuffer;
+
+ gpr_slice slice_;
+};
+
+} // namespace grpc
+
+#endif // GRPCXX_SLICE_H