GRPC C++  1.66.0
async_generic_service.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2018 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_GENERIC_ASYNC_GENERIC_SERVICE_H
20 #define GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H
21 
26 
27 struct grpc_server;
28 
29 namespace grpc {
30 
31 typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
36 
37 class GenericServerContext final : public ServerContext {
38  public:
39  const std::string& method() const { return method_; }
40  const std::string& host() const { return host_; }
41 
42  private:
43  friend class ServerInterface;
44 
45  std::string method_;
46  std::string host_;
47 };
48 
49 // A generic service at the server side accepts all RPC methods and hosts. It is
50 // typically used in proxies. The generic service can be registered to a server
51 // which also has other services.
52 // Sample usage:
53 // ServerBuilder builder;
54 // auto cq = builder.AddCompletionQueue();
55 // AsyncGenericService generic_service;
56 // builder.RegisterAsyncGenericService(&generic_service);
57 // auto server = builder.BuildAndStart();
58 //
59 // // request a new call
60 // GenericServerContext context;
61 // GenericServerAsyncReaderWriter stream;
62 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
63 //
64 // When tag is retrieved from cq->Next(), context.method() can be used to look
65 // at the method and the RPC can be handled accordingly.
66 class AsyncGenericService final {
67  public:
68  AsyncGenericService() : server_(nullptr) {}
69 
71  GenericServerAsyncReaderWriter* reader_writer,
72  grpc::CompletionQueue* call_cq,
73  grpc::ServerCompletionQueue* notification_cq, void* tag);
74 
75  private:
76  friend class grpc::Server;
77  grpc::Server* server_;
78 };
79 
80 } // namespace grpc
81 
82 #endif // GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H
grpc::ServerContext
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:578
grpc::Server
Represents a gRPC server.
Definition: server.h:57
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::ServerAsyncWriter
Async server-side API for doing server streaming RPCs, where the outgoing message stream from the ser...
Definition: server_context.h:58
grpc::GenericServerAsyncReader
ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:34
grpc::GenericServerAsyncResponseWriter
ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:33
grpc::AsyncGenericService::AsyncGenericService
AsyncGenericService()
Definition: async_generic_service.h:68
callback_generic_service.h
grpc_server
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:64
grpc::AsyncGenericService
Definition: async_generic_service.h:66
grpc::GenericServerContext
Definition: async_generic_service.h:37
grpc::ServerAsyncResponseWriter
Async server-side API for handling unary calls, where the single response message sent to the client ...
Definition: server_context.h:60
byte_buffer.h
grpc::ServerCompletionQueue
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:427
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:105
grpc::GenericServerAsyncReaderWriter
ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:32
grpc::GenericServerContext::host
const std::string & host() const
Definition: async_generic_service.h:40
grpc::ServerAsyncReader
Async server-side API for doing client-streaming RPCs, where the incoming message stream from the cli...
Definition: server_context.h:56
grpc::ServerAsyncReaderWriter
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: server_context.h:62
grpc::ServerInterface
Definition: server_interface.h:61
grpc::GenericServerAsyncWriter
ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:35
async_stream.h
grpc::GenericServerContext::method
const std::string & method() const
Definition: async_generic_service.h:39
grpc::AsyncGenericService::RequestCall
void RequestCall(GenericServerContext *ctx, GenericServerAsyncReaderWriter *reader_writer, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
port_platform.h