GRPC C++  1.23.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 ::grpc_impl::ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
32 typedef ::grpc_impl::ServerAsyncResponseWriter<ByteBuffer>
34 typedef ::grpc_impl::ServerAsyncReader<ByteBuffer, ByteBuffer>
36 typedef ::grpc_impl::ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter;
37 
39  public:
40  const grpc::string& method() const { return method_; }
41  const grpc::string& host() const { return host_; }
42 
43  private:
44  friend class grpc_impl::Server;
45  friend class ServerInterface;
46 
47  void Clear() {
48  method_.clear();
49  host_.clear();
50  ServerContext::Clear();
51  }
52 
53  grpc::string method_;
54  grpc::string host_;
55 };
56 
57 // A generic service at the server side accepts all RPC methods and hosts. It is
58 // typically used in proxies. The generic service can be registered to a server
59 // which also has other services.
60 // Sample usage:
61 // ServerBuilder builder;
62 // auto cq = builder.AddCompletionQueue();
63 // AsyncGenericService generic_service;
64 // builder.RegisterAsyncGenericService(&generic_service);
65 // auto server = builder.BuildAndStart();
66 //
67 // // request a new call
68 // GenericServerContext context;
69 // GenericServerAsyncReaderWriter stream;
70 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
71 //
72 // When tag is retrieved from cq->Next(), context.method() can be used to look
73 // at the method and the RPC can be handled accordingly.
74 class AsyncGenericService final {
75  public:
76  AsyncGenericService() : server_(nullptr) {}
77 
78  void RequestCall(GenericServerContext* ctx,
79  GenericServerAsyncReaderWriter* reader_writer,
80  ::grpc_impl::CompletionQueue* call_cq,
81  ::grpc_impl::ServerCompletionQueue* notification_cq,
82  void* tag);
83 
84  private:
85  friend class grpc_impl::Server;
86  grpc_impl::Server* server_;
87 };
88 
89 namespace experimental {
90 
98  ByteBuffer> {
99  public:
103  virtual void OnStarted(GenericServerContext* context) {}
104 
105  private:
106  void OnStarted(::grpc_impl::ServerContext* ctx) final {
107  OnStarted(static_cast<GenericServerContext*>(ctx));
108  }
109 };
110 
111 } // namespace experimental
112 
113 namespace internal {
116  public:
117  void OnDone() override { delete this; }
118  void OnStarted(GenericServerContext*) override {
119  this->Finish(Status(StatusCode::UNIMPLEMENTED, ""));
120  }
121 };
122 } // namespace internal
123 
124 namespace experimental {
125 
130  public:
133 
139  }
140 
141  private:
143 
145  Handler() {
146  return new ::grpc_impl::internal::CallbackBidiHandler<ByteBuffer,
147  ByteBuffer>(
148  [this] { return CreateReactor(); });
149  }
150 
151  grpc_impl::Server* server_{nullptr};
152 };
153 } // namespace experimental
154 } // namespace grpc
155 
156 #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
AsyncGenericService()
Definition: async_generic_service.h:76
::grpc_impl::ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:35
const grpc::string & host() const
Definition: async_generic_service.h:41
std::string string
Definition: config.h:35
Represents a gRPC server.
Definition: server_impl.h:64
::grpc_impl::ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:33
::grpc_impl::Server Server
Definition: server.h:26
virtual void OnStarted(GenericServerContext *context)
Similar to ServerBidiReactor::OnStarted except for argument type.
Definition: async_generic_service.h:103
Definition: async_generic_service.h:114
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:74
A ServerContext allows the person implementing a service handler to:
Definition: server_context_impl.h:118
::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:96
::grpc_impl::ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:36
::grpc_impl::ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:31
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
virtual ServerGenericBidiReactor * CreateReactor()
The "method handler" for the generic API.
Definition: async_generic_service.h:137
Definition: server_interface.h:57
Definition: async_generic_service.h:38
CallbackGenericService()
Definition: async_generic_service.h:131
Definition: server_callback_impl.h:46
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:129
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: async_stream_impl.h:1012
virtual ~CallbackGenericService()
Definition: async_generic_service.h:132
const grpc::string & method() const
Definition: async_generic_service.h:40
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:101
void OnDone() override
Definition: async_generic_service.h:117
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:118
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue_impl.h:390
A sequence of bytes.
Definition: byte_buffer.h:72
ServerBidiReactor is the interface for a bidirectional streaming RPC.
Definition: server_callback_impl.h:107