GRPC C++  1.46.2
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 
22 // IWYU pragma: private, include <grpcpp/generic/async_generic_service.h>
23 
25 
30 
31 struct grpc_server;
32 
33 namespace grpc {
34 
35 typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
40 
41 class GenericServerContext final : public ServerContext {
42  public:
43  const std::string& method() const { return method_; }
44  const std::string& host() const { return host_; }
45 
46  private:
47  friend class ServerInterface;
48 
49  std::string method_;
50  std::string host_;
51 };
52 
53 // A generic service at the server side accepts all RPC methods and hosts. It is
54 // typically used in proxies. The generic service can be registered to a server
55 // which also has other services.
56 // Sample usage:
57 // ServerBuilder builder;
58 // auto cq = builder.AddCompletionQueue();
59 // AsyncGenericService generic_service;
60 // builder.RegisterAsyncGenericService(&generic_service);
61 // auto server = builder.BuildAndStart();
62 //
63 // // request a new call
64 // GenericServerContext context;
65 // GenericServerAsyncReaderWriter stream;
66 // generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
67 //
68 // When tag is retrieved from cq->Next(), context.method() can be used to look
69 // at the method and the RPC can be handled accordingly.
70 class AsyncGenericService final {
71  public:
72  AsyncGenericService() : server_(nullptr) {}
73 
75  GenericServerAsyncReaderWriter* reader_writer,
76  grpc::CompletionQueue* call_cq,
77  grpc::ServerCompletionQueue* notification_cq, void* tag);
78 
79  private:
80  friend class grpc::Server;
81  grpc::Server* server_;
82 };
83 
88 
90  public:
91  const std::string& method() const { return method_; }
92  const std::string& host() const { return host_; }
93 
94  private:
95  friend class grpc::Server;
96 
97  std::string method_;
98  std::string host_;
99 };
100 
105  public:
108 
113  GenericCallbackServerContext* /*ctx*/) {
114  class Reactor : public ServerGenericBidiReactor {
115  public:
116  Reactor() { this->Finish(Status(StatusCode::UNIMPLEMENTED, "")); }
117  void OnDone() override { delete this; }
118  };
119  return new Reactor;
120  }
121 
122  private:
123  friend class grpc::Server;
124 
127  [this](grpc::CallbackServerContext* ctx) {
128  return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
129  });
130  }
131 
132  grpc::Server* server_{nullptr};
133 };
134 
135 } // namespace grpc
136 
137 #endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H
grpc::ServerContext
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:544
grpc::Server
Represents a gRPC server.
Definition: server.h:59
grpc
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
grpc::CallbackServerContext
Definition: server_context.h:584
grpc::ServerAsyncWriter
Async server-side API for doing server streaming RPCs, where the outgoing message stream from the ser...
Definition: async_stream.h:845
grpc::GenericServerAsyncReader
ServerAsyncReader< ByteBuffer, ByteBuffer > GenericServerAsyncReader
Definition: async_generic_service.h:38
grpc::GenericServerAsyncResponseWriter
ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:37
server_callback.h
grpc::AsyncGenericService::AsyncGenericService
AsyncGenericService()
Definition: async_generic_service.h:72
grpc::GenericCallbackServerContext::host
const std::string & host() const
Definition: async_generic_service.h:92
byte_buffer.h
grpc::ServerBidiReactor
ServerBidiReactor is the interface for a bidirectional streaming RPC.
Definition: server_callback.h:188
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:70
grpc::CallbackGenericService::CallbackGenericService
CallbackGenericService()
Definition: async_generic_service.h:106
grpc::GenericServerContext
Definition: async_generic_service.h:41
grpc::protobuf::util::Status
::google::protobuf::util::Status Status
Definition: config_protobuf.h:93
grpc::ServerAsyncResponseWriter
Async server-side API for handling unary calls, where the single response message sent to the client ...
Definition: async_unary_call.h:295
grpc::internal::CallbackBidiHandler
Definition: server_callback.h:49
grpc::UNIMPLEMENTED
@ UNIMPLEMENTED
Operation is not implemented or not supported/enabled in this service.
Definition: status_code_enum.h:117
async_stream.h
port_platform.h
grpc::ServerCompletionQueue
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:436
grpc::GenericCallbackServerContext
Definition: async_generic_service.h:89
server_callback_handlers.h
grpc::GenericCallbackServerContext::method
const std::string & method() const
Definition: async_generic_service.h:91
grpc::CompletionQueue
A thin wrapper around grpc_completion_queue (see src/core/lib/surface/completion_queue....
Definition: completion_queue.h:104
grpc::GenericServerAsyncReaderWriter
ServerAsyncReaderWriter< ByteBuffer, ByteBuffer > GenericServerAsyncReaderWriter
Definition: async_generic_service.h:36
grpc::GenericServerContext::host
const std::string & host() const
Definition: async_generic_service.h:44
grpc::ServerAsyncReader
Async server-side API for doing client-streaming RPCs, where the incoming message stream from the cli...
Definition: async_stream.h:698
grpc::ServerAsyncReaderWriter
Async server-side API for doing bidirectional streaming RPCs, where the incoming message stream comin...
Definition: async_stream.h:1010
grpc::ServerInterface
Definition: server_interface.h:61
grpc::GenericServerAsyncWriter
ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:39
grpc::CallbackGenericService::CreateReactor
virtual ServerGenericBidiReactor * CreateReactor(GenericCallbackServerContext *)
The "method handler" for the generic API.
Definition: async_generic_service.h:112
grpc::CallbackGenericService::~CallbackGenericService
virtual ~CallbackGenericService()
Definition: async_generic_service.h:107
grpc::GenericServerContext::method
const std::string & method() const
Definition: async_generic_service.h:43
grpc::AsyncGenericService::RequestCall
void RequestCall(GenericServerContext *ctx, GenericServerAsyncReaderWriter *reader_writer, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
grpc::CallbackGenericService
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: async_generic_service.h:104