GRPC C++  1.22.0
async_generic_service.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
20 #define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
21 
25 
26 struct grpc_server;
27 
28 namespace grpc {
29 
30 typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
35 
36 class GenericServerContext final : public ServerContext {
37  public:
38  const grpc::string& method() const { return method_; }
39  const grpc::string& host() const { return host_; }
40 
41  private:
42  friend class grpc_impl::Server;
43  friend class ServerInterface;
44 
45  void Clear() {
46  method_.clear();
47  host_.clear();
48  ServerContext::Clear();
49  }
50 
51  grpc::string method_;
52  grpc::string host_;
53 };
54 
55 // A generic service at the server side accepts all RPC methods and hosts. It is
56 // typically used in proxies. The generic service can be registered to a server
57 // which also has other services.
58 // Sample usage:
59 // ServerBuilder builder;
60 // auto cq = builder.AddCompletionQueue();
61 // AsyncGenericService generic_service;
62 // builder.RegisterAsyncGenericService(&generic_service);
63 // auto server = builder.BuildAndStart();
64 //
65 // // request a new call
66 // GenericServerContext context;
67 // GenericServerAsyncReaderWriter stream;
68 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
69 //
70 // When tag is retrieved from cq->Next(), context.method() can be used to look
71 // at the method and the RPC can be handled accordingly.
72 class AsyncGenericService final {
73  public:
74  AsyncGenericService() : server_(nullptr) {}
75 
76  void RequestCall(GenericServerContext* ctx,
77  GenericServerAsyncReaderWriter* reader_writer,
78  CompletionQueue* call_cq,
79  ServerCompletionQueue* notification_cq, void* tag);
80 
81  private:
82  friend class grpc_impl::Server;
83  grpc_impl::Server* server_;
84 };
85 
86 namespace experimental {
87 
94  : public ServerBidiReactor<ByteBuffer, ByteBuffer> {
95  public:
99  virtual void OnStarted(GenericServerContext* context) {}
100 
101  private:
102  void OnStarted(ServerContext* ctx) final {
103  OnStarted(static_cast<GenericServerContext*>(ctx));
104  }
105 };
106 
107 } // namespace experimental
108 
109 namespace internal {
112  public:
113  void OnDone() override { delete this; }
114  void OnStarted(GenericServerContext*) override {
115  this->Finish(Status(StatusCode::UNIMPLEMENTED, ""));
116  }
117 };
118 } // namespace internal
119 
120 namespace experimental {
121 
126  public:
129 
135  }
136 
137  private:
139 
142  [this] { return CreateReactor(); });
143  }
144 
145  grpc_impl::Server* server_{nullptr};
146 };
147 } // namespace experimental
148 } // namespace grpc
149 
150 #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
AsyncGenericService()
Definition: async_generic_service.h:74
const grpc::string & host() const
Definition: async_generic_service.h:39
std::string string
Definition: config.h:35
Definition: server_callback.h:47
ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:33
Represents a gRPC server.
Definition: server_impl.h:63
::grpc_impl::Server Server
Definition: server.h:26
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: async_stream.h:1009
virtual void OnStarted(GenericServerContext *context)
Similar to ServerBidiReactor::OnStarted except for argument type.
Definition: async_generic_service.h:99
Definition: async_generic_service.h:110
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:65
Definition: async_generic_service.h:72
A ServerContext allows the person implementing a service handler to:
Definition: server_context_impl.h:114
::google::protobuf::util::Status Status
Definition: config_protobuf.h:96
ServerGenericBidiReactor is the reactor class for bidi streaming RPCs invoked on a CallbackGenericSer...
Definition: async_generic_service.h:93
Async server-side API for doing server streaming RPCs, where the outgoing message stream from the ser...
Definition: async_stream.h:844
ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:34
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
ServerBidiReactor is the interface for a bidirectional streaming RPC.
Definition: server_callback.h:108
ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:31
virtual ServerGenericBidiReactor * CreateReactor()
The "method handler" for the generic API.
Definition: async_generic_service.h:133
Definition: server_interface.h:58
Definition: async_generic_service.h:36
CallbackGenericService()
Definition: async_generic_service.h:127
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:125
virtual ~CallbackGenericService()
Definition: async_generic_service.h:128
const grpc::string & method() const
Definition: async_generic_service.h:38
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:102
Async server-side API for handling unary calls, where the single response message sent to the client ...
Definition: async_unary_call.h:199
void OnDone() override
Definition: async_generic_service.h:113
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
void OnStarted(GenericServerContext *) override
Similar to ServerBidiReactor::OnStarted except for argument type.
Definition: async_generic_service.h:114
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue_impl.h:391
Async server-side API for doing client-streaming RPCs, where the incoming message stream from the cli...
Definition: async_stream.h:697
ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:32