GRPC C++  1.26.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 
26 
27 struct grpc_server;
28 
29 namespace grpc {
30 
31 typedef ::grpc_impl::ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
33 typedef ::grpc_impl::ServerAsyncResponseWriter<ByteBuffer>
35 typedef ::grpc_impl::ServerAsyncReader<ByteBuffer, ByteBuffer>
37 typedef ::grpc_impl::ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter;
38 
40  public:
41  const grpc::string& method() const { return method_; }
42  const grpc::string& host() const { return host_; }
43 
44  private:
45  friend class grpc_impl::Server;
46  friend class grpc::ServerInterface;
47 
48  void Clear() {
49  method_.clear();
50  host_.clear();
51  ::grpc_impl::ServerContext::Clear();
52  }
53 
54  grpc::string method_;
55  grpc::string host_;
56 };
57 
58 // A generic service at the server side accepts all RPC methods and hosts. It is
59 // typically used in proxies. The generic service can be registered to a server
60 // which also has other services.
61 // Sample usage:
62 // ServerBuilder builder;
63 // auto cq = builder.AddCompletionQueue();
64 // AsyncGenericService generic_service;
65 // builder.RegisterAsyncGenericService(&generic_service);
66 // auto server = builder.BuildAndStart();
67 //
68 // // request a new call
69 // GenericServerContext context;
70 // GenericServerAsyncReaderWriter stream;
71 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
72 //
73 // When tag is retrieved from cq->Next(), context.method() can be used to look
74 // at the method and the RPC can be handled accordingly.
75 class AsyncGenericService final {
76  public:
77  AsyncGenericService() : server_(nullptr) {}
78 
79  void RequestCall(GenericServerContext* ctx,
80  GenericServerAsyncReaderWriter* reader_writer,
81  ::grpc_impl::CompletionQueue* call_cq,
82  ::grpc_impl::ServerCompletionQueue* notification_cq,
83  void* tag);
84 
85  private:
86  friend class grpc_impl::Server;
87  grpc_impl::Server* server_;
88 };
89 
90 namespace experimental {
91 
97 
100  public:
101  const grpc::string& method() const { return method_; }
102  const grpc::string& host() const { return host_; }
103 
104  private:
106  friend class ::grpc::ServerInterface;
107 
108  void Clear() {
109  method_.clear();
110  host_.clear();
111  ::grpc_impl::CallbackServerContext::Clear();
112  }
113 
114  grpc::string method_;
115  grpc::string host_;
116 };
117 
122  public:
125 
130  GenericCallbackServerContext* /*ctx*/) {
131  class Reactor : public ServerGenericBidiReactor {
132  public:
133  Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); }
134  void OnDone() override { delete this; }
135  };
136  return new Reactor;
137  }
138 
139  private:
141 
143  Handler() {
144  return new ::grpc_impl::internal::CallbackBidiHandler<ByteBuffer,
145  ByteBuffer>(
147  return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
148  });
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
Definition: server_context_impl.h:528
AsyncGenericService()
Definition: async_generic_service.h:77
::grpc_impl::ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:36
const grpc::string & host() const
Definition: async_generic_service.h:42
std::string string
Definition: config.h:35
Represents a gRPC server.
Definition: server_impl.h:62
::grpc_impl::ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:34
::grpc_impl::Server Server
Definition: server.h:26
ServerBidiReactor is the interface for a bidirectional streaming RPC.
Definition: server_callback_impl.h:146
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:75
A ServerContext or CallbackServerContext allows the code implementing a service handler to: ...
Definition: server_context_impl.h:488
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
const grpc::string & host() const
Definition: async_generic_service.h:102
::grpc_impl::ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:37
::grpc_impl::ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:32
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
Definition: server_interface.h:59
virtual ServerGenericBidiReactor * CreateReactor(GenericCallbackServerContext *)
The "method handler" for the generic API.
Definition: async_generic_service.h:129
Definition: async_generic_service.h:39
CallbackGenericService()
Definition: async_generic_service.h:123
Definition: server_callback_handlers.h:607
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:121
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:124
const grpc::string & method() const
Definition: async_generic_service.h:41
const grpc::string & method() const
Definition: async_generic_service.h:101
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue_impl.h:100
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:115
::grpc_impl::ServerBidiReactor< ByteBuffer, ByteBuffer > ServerGenericBidiReactor
ServerGenericBidiReactor is the reactor class for bidi streaming RPCs invoked on a CallbackGenericSer...
Definition: async_generic_service.h:96
Definition: async_generic_service.h:98
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue_impl.h:389
A sequence of bytes.
Definition: byte_buffer.h:67