GRPC C++  1.32.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 std::string& method() const { return method_; }
44  const std::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  std::string method_;
57  std::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::CompletionQueue* call_cq,
84  ::grpc::ServerCompletionQueue* notification_cq, void* tag);
85 
86  private:
87  friend class grpc_impl::Server;
88  grpc_impl::Server* server_;
89 };
90 
91 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
92 namespace experimental {
93 #endif
94 
100 
103  public:
104  const std::string& method() const { return method_; }
105  const std::string& host() const { return host_; }
106 
107  private:
109  friend class ::grpc::ServerInterface;
110 
111  void Clear() {
112  method_.clear();
113  host_.clear();
114  ::grpc_impl::CallbackServerContext::Clear();
115  }
116 
117  std::string method_;
118  std::string host_;
119 };
120 
125  public:
128 
133  GenericCallbackServerContext* /*ctx*/) {
134  class Reactor : public ServerGenericBidiReactor {
135  public:
136  Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); }
137  void OnDone() override { delete this; }
138  };
139  return new Reactor;
140  }
141 
142  private:
144 
146  Handler() {
147  return new ::grpc_impl::internal::CallbackBidiHandler<ByteBuffer,
148  ByteBuffer>(
150  return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
151  });
152  }
153 
154  grpc_impl::Server* server_{nullptr};
155 };
156 
157 #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL
158 } // namespace experimental
159 #endif
160 } // namespace grpc
161 
162 #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
grpc::experimental::CallbackGenericService::CallbackGenericService
CallbackGenericService()
Definition: async_generic_service.h:126
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:99
grpc
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
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:560
grpc::AsyncGenericService::RequestCall
void RequestCall(GenericServerContext *ctx, GenericServerAsyncReaderWriter *reader_writer, ::grpc::CompletionQueue *call_cq, ::grpc::ServerCompletionQueue *notification_cq, void *tag)
grpc::AsyncGenericService::AsyncGenericService
AsyncGenericService()
Definition: async_generic_service.h:79
grpc::Server
::grpc_impl::Server Server
Definition: server.h:26
byte_buffer.h
grpc_impl::Server
Represents a gRPC server.
Definition: server_impl.h:63
grpc::experimental::CallbackGenericService::~CallbackGenericService
virtual ~CallbackGenericService()
Definition: async_generic_service.h:127
grpc_impl::ServerContext
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context_impl.h:520
grpc::experimental::GenericCallbackServerContext
Definition: async_generic_service.h:101
grpc::GenericServerAsyncResponseWriter
::grpc_impl::ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:36
grpc_impl::internal::CallbackBidiHandler
Definition: server_callback_handlers.h:661
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::experimental::GenericCallbackServerContext::host
const std::string & host() const
Definition: async_generic_service.h:105
grpc::experimental::GenericCallbackServerContext::method
const std::string & method() const
Definition: async_generic_service.h:104
grpc::experimental::CallbackGenericService
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:124
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:132
grpc::GenericServerAsyncReaderWriter
::grpc_impl::ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:34
grpc::UNIMPLEMENTED
@ 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
port_platform.h
grpc::ServerCompletionQueue
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:421
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:1009
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:99
grpc::GenericServerContext::host
const std::string & host() const
Definition: async_generic_service.h:44
grpc::ServerInterface
Definition: server_interface.h:65
grpc::GenericServerContext::method
const std::string & method() const
Definition: async_generic_service.h:43