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