GRPC C++  0.13.1-pre1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
completion_queue.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015-2016, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
36 #ifndef GRPCXX_IMPL_CODEGEN_COMPLETION_QUEUE_H
37 #define GRPCXX_IMPL_CODEGEN_COMPLETION_QUEUE_H
38 
42 
43 struct grpc_completion_queue;
44 
45 namespace grpc {
46 
47 template <class R>
48 class ClientReader;
49 template <class W>
50 class ClientWriter;
51 template <class W, class R>
52 class ClientReaderWriter;
53 template <class R>
55 template <class W>
57 template <class W, class R>
59 template <class ServiceType, class RequestType, class ResponseType>
61 template <class ServiceType, class RequestType, class ResponseType>
63 template <class ServiceType, class RequestType, class ResponseType>
65 template <class ServiceType, class RequestType, class ResponseType>
68 
69 class Channel;
70 class ChannelInterface;
71 class ClientContext;
72 class CompletionQueueTag;
73 class CompletionQueue;
74 class RpcMethod;
75 class Server;
76 class ServerBuilder;
77 class ServerContext;
78 
81 class CompletionQueue : private GrpcLibrary {
82  public:
86 
90  explicit CompletionQueue(grpc_completion_queue* take);
91 
94 
96  enum NextStatus {
99  TIMEOUT
101  };
102 
113  template <typename T>
114  NextStatus AsyncNext(void** tag, bool* ok, const T& deadline) {
115  TimePoint<T> deadline_tp(deadline);
116  return AsyncNextInternal(tag, ok, deadline_tp.raw_time());
117  }
118 
126  bool Next(void** tag, bool* ok) {
127  return (AsyncNextInternal(tag, ok, gpr_inf_future(GPR_CLOCK_REALTIME)) !=
128  SHUTDOWN);
129  }
130 
138  void Shutdown();
139 
145  grpc_completion_queue* cq() { return cq_; }
146 
147  private:
148  // Friend synchronous wrappers so that they can access Pluck(), which is
149  // a semi-private API geared towards the synchronous implementation.
150  template <class R>
151  friend class ::grpc::ClientReader;
152  template <class W>
153  friend class ::grpc::ClientWriter;
154  template <class W, class R>
155  friend class ::grpc::ClientReaderWriter;
156  template <class R>
157  friend class ::grpc::ServerReader;
158  template <class W>
159  friend class ::grpc::ServerWriter;
160  template <class W, class R>
161  friend class ::grpc::ServerReaderWriter;
162  template <class ServiceType, class RequestType, class ResponseType>
163  friend class RpcMethodHandler;
164  template <class ServiceType, class RequestType, class ResponseType>
166  template <class ServiceType, class RequestType, class ResponseType>
168  template <class ServiceType, class RequestType, class ResponseType>
169  friend class BidiStreamingHandler;
170  friend class UnknownMethodHandler;
171  friend class ::grpc::Server;
172  friend class ::grpc::ServerContext;
173  template <class InputMessage, class OutputMessage>
174  friend Status BlockingUnaryCall(ChannelInterface* channel,
175  const RpcMethod& method,
176  ClientContext* context,
177  const InputMessage& request,
178  OutputMessage* result);
179 
180  NextStatus AsyncNextInternal(void** tag, bool* ok, gpr_timespec deadline);
181 
184  bool Pluck(CompletionQueueTag* tag);
185 
187  void TryPluck(CompletionQueueTag* tag);
188 
189  grpc_completion_queue* cq_; // owned
190 };
191 
195  private:
196  friend class ServerBuilder;
198 };
199 
200 } // namespace grpc
201 
202 #endif // GRPCXX_IMPL_CODEGEN_COMPLETION_QUEUE_H
An interface allowing implementors to process and filter event tags.
Definition: completion_queue_tag.h:40
friend Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, const InputMessage &request, OutputMessage *result)
Definition: client_unary_call.h:51
Got a new event; tag will be filled in with its associated value; ok indicating its success...
Definition: completion_queue.h:98
The completion queue has been shutdown.
Definition: completion_queue.h:97
gpr_timespec raw_time()
Definition: time.h:57
Definition: time.h:54
grpc_completion_queue * cq()
Returns a raw pointer to the underlying grpc_completion_queue instance.
Definition: completion_queue.h:145
Definition: client_context.h:152
Definition: completion_queue.h:54
bool Next(void **tag, bool *ok)
Read from the queue, blocking until an event is available or the queue is shutting down...
Definition: completion_queue.h:126
Definition: method_handler_impl.h:181
Definition: grpc_library.h:49
NextStatus AsyncNext(void **tag, bool *ok, const T &deadline)
Read from the queue, blocking up to deadline (or the queue's shutdown).
Definition: completion_queue.h:114
~CompletionQueue()
Destructor. Destroys the owned wrapped completion queue / instance.
Models a gRPC server.
Definition: server.h:65
Definition: completion_queue.h:60
void Shutdown()
Request the shutdown of the queue.
Codegen interface for grpc::Channel.
Definition: channel_interface.h:64
NextStatus
Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT.
Definition: completion_queue.h:96
CompletionQueue()
Default constructor.
Definition: server_context.h:90
Definition: completion_queue.h:56
A thin wrapper around grpc_completion_queue (see / src/core/surface/completion_queue.h).
Definition: completion_queue.h:81
Definition: completion_queue.h:62
Definition: rpc_method.h:43
Server-side interface for bi-directional streaming.
Definition: completion_queue.h:58
Definition: completion_queue.h:64
Did it work? If it didn't, why?
Definition: status.h:45
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:194
Definition: completion_queue.h:66
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:55
deadline was reached.
Definition: completion_queue.h:100
Channels represent a connection to an endpoint. Created by CreateChannel.
Definition: channel.h:49