GRPC C++  1.13.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_GENERIC_ASYNC_GENERIC_SERVICE_H
20 #define GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H
21 
24 
25 struct grpc_server;
26 
27 namespace grpc {
28 
29 typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
31 
32 class GenericServerContext final : public ServerContext {
33  public:
34  const grpc::string& method() const { return method_; }
35  const grpc::string& host() const { return host_; }
36 
37  private:
38  friend class Server;
39  friend class ServerInterface;
40 
41  grpc::string method_;
42  grpc::string host_;
43 };
44 
45 // A generic service at the server side accepts all RPC methods and hosts. It is
46 // typically used in proxies. The generic service can be registered to a server
47 // which also has other services.
48 // Sample usage:
49 // ServerBuilder builder;
50 // auto cq = builder.AddCompletionQueue();
51 // AsyncGenericService generic_service;
52 // builder.RegisterAsyncGeneicService(&generic_service);
53 // auto server = builder.BuildAndStart();
54 //
55 // // request a new call
56 // GenericServerContext context;
57 // GenericAsyncReaderWriter stream;
58 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
59 //
60 // When tag is retrieved from cq->Next(), context.method() can be used to look
61 // at the method and the RPC can be handled accordingly.
62 class AsyncGenericService final {
63  public:
64  AsyncGenericService() : server_(nullptr) {}
65 
66  void RequestCall(GenericServerContext* ctx,
67  GenericServerAsyncReaderWriter* reader_writer,
68  CompletionQueue* call_cq,
69  ServerCompletionQueue* notification_cq, void* tag);
70 
71  private:
72  friend class Server;
73  Server* server_;
74 };
75 
76 } // namespace grpc
77 
78 #endif // GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H
AsyncGenericService()
Definition: async_generic_service.h:64
const grpc::string & host() const
Definition: async_generic_service.h:35
std::string string
Definition: config.h:35
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: async_stream.h:951
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:62
Represents a gRPC server.
Definition: server.h:52
An Alarm posts the user provided tag to its associated completion queue upon expiry or cancellation...
Definition: alarm.h:31
ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:30
A ServerContext allows the person implementing a service handler to:
Definition: server_context.h:96
Definition: server_interface.h:48
Definition: async_generic_service.h:32
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue.h).
Definition: completion_queue.h:94
const grpc::string & method() const
Definition: async_generic_service.h:34
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:364