GRPC C++  1.19.0-dev
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 
24 
25 struct grpc_server;
26 
27 namespace grpc {
28 
29 typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
34 
35 class GenericServerContext final : public ServerContext {
36  public:
37  const grpc::string& method() const { return method_; }
38  const grpc::string& host() const { return host_; }
39 
40  private:
41  friend class Server;
42  friend class ServerInterface;
43 
44  grpc::string method_;
45  grpc::string host_;
46 };
47 
48 // A generic service at the server side accepts all RPC methods and hosts. It is
49 // typically used in proxies. The generic service can be registered to a server
50 // which also has other services.
51 // Sample usage:
52 // ServerBuilder builder;
53 // auto cq = builder.AddCompletionQueue();
54 // AsyncGenericService generic_service;
55 // builder.RegisterAsyncGenericService(&generic_service);
56 // auto server = builder.BuildAndStart();
57 //
58 // // request a new call
59 // GenericServerContext context;
60 // GenericServerAsyncReaderWriter stream;
61 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
62 //
63 // When tag is retrieved from cq->Next(), context.method() can be used to look
64 // at the method and the RPC can be handled accordingly.
65 class AsyncGenericService final {
66  public:
67  AsyncGenericService() : server_(nullptr) {}
68 
69  void RequestCall(GenericServerContext* ctx,
70  GenericServerAsyncReaderWriter* reader_writer,
71  CompletionQueue* call_cq,
72  ServerCompletionQueue* notification_cq, void* tag);
73 
74  private:
75  friend class Server;
76  Server* server_;
77 };
78 
79 } // namespace grpc
80 
81 #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
AsyncGenericService()
Definition: async_generic_service.h:67
const grpc::string & host() const
Definition: async_generic_service.h:38
std::string string
Definition: config.h:35
ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:32
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: async_stream.h:1011
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:65
Async server-side API for doing server streaming RPCs, where the outgoing message stream from the ser...
Definition: async_stream.h:846
ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:33
Represents a gRPC server.
Definition: server.h:53
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:30
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:109
Definition: server_interface.h:50
Definition: async_generic_service.h:35
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:95
const grpc::string & method() const
Definition: async_generic_service.h:37
Async server-side API for handling unary calls, where the single response message sent to the client ...
Definition: async_unary_call.h:200
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:373
Async server-side API for doing client-streaming RPCs, where the incoming message stream from the cli...
Definition: async_stream.h:699
ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:31