2015-02-24 18:34:47 +00:00
|
|
|
/*
|
|
|
|
*
|
2017-06-07 20:57:36 +00:00
|
|
|
* Copyright 2015 gRPC authors.
|
2015-02-24 18:34:47 +00:00
|
|
|
*
|
2017-06-07 20:57:36 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-02-24 18:34:47 +00:00
|
|
|
*
|
2017-06-07 20:57:36 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-02-24 18:34:47 +00:00
|
|
|
*
|
2017-06-07 20:57:36 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-02-24 18:34:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-08-21 22:35:03 +00:00
|
|
|
#ifndef GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H
|
|
|
|
#define GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H
|
2015-02-24 18:34:47 +00:00
|
|
|
|
2015-08-21 22:49:35 +00:00
|
|
|
#include <grpc++/support/async_stream.h>
|
2016-03-25 20:38:14 +00:00
|
|
|
#include <grpc++/support/byte_buffer.h>
|
2015-02-24 18:34:47 +00:00
|
|
|
|
2015-03-06 00:39:25 +00:00
|
|
|
struct grpc_server;
|
|
|
|
|
2015-02-24 18:34:47 +00:00
|
|
|
namespace grpc {
|
|
|
|
|
2015-03-17 17:49:39 +00:00
|
|
|
typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
|
|
|
|
GenericServerAsyncReaderWriter;
|
2015-02-24 18:34:47 +00:00
|
|
|
|
2016-11-01 23:31:56 +00:00
|
|
|
class GenericServerContext final : public ServerContext {
|
2015-02-24 18:34:47 +00:00
|
|
|
public:
|
|
|
|
const grpc::string& method() const { return method_; }
|
|
|
|
const grpc::string& host() const { return host_; }
|
|
|
|
|
|
|
|
private:
|
2015-03-07 00:11:16 +00:00
|
|
|
friend class Server;
|
2016-01-15 02:00:04 +00:00
|
|
|
friend class ServerInterface;
|
2015-03-07 00:11:16 +00:00
|
|
|
|
2015-02-24 18:34:47 +00:00
|
|
|
grpc::string method_;
|
|
|
|
grpc::string host_;
|
|
|
|
};
|
|
|
|
|
2017-12-12 19:45:32 +00:00
|
|
|
// A generic service at the server side accepts all RPC methods and hosts. It is
|
|
|
|
// typically used in proxies. The generic service can be registered to a server
|
|
|
|
// which also has other services.
|
|
|
|
// Sample usage:
|
|
|
|
// ServerBuilder builder;
|
|
|
|
// auto cq = builder.AddCompletionQueue();
|
|
|
|
// AsyncGenericService generic_service;
|
|
|
|
// builder.RegisterAsyncGeneicService(&generic_service);
|
|
|
|
// auto server = builder.BuildAndStart();
|
|
|
|
//
|
|
|
|
// // request a new call
|
|
|
|
// GenericServerContext context;
|
|
|
|
// GenericAsyncReaderWriter stream;
|
|
|
|
// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag);
|
|
|
|
//
|
|
|
|
// When tag is retrieved from cq->Next(), context.method() can be used to look
|
|
|
|
// at the method and the RPC can be handled accordingly.
|
2016-11-01 23:31:56 +00:00
|
|
|
class AsyncGenericService final {
|
2015-02-24 18:34:47 +00:00
|
|
|
public:
|
2016-01-07 18:20:46 +00:00
|
|
|
AsyncGenericService() : server_(nullptr) {}
|
2015-02-24 18:34:47 +00:00
|
|
|
|
2015-03-12 05:17:13 +00:00
|
|
|
void RequestCall(GenericServerContext* ctx,
|
2015-03-12 23:40:19 +00:00
|
|
|
GenericServerAsyncReaderWriter* reader_writer,
|
2015-05-06 18:45:59 +00:00
|
|
|
CompletionQueue* call_cq,
|
|
|
|
ServerCompletionQueue* notification_cq, void* tag);
|
2015-03-16 20:11:29 +00:00
|
|
|
|
2015-02-24 18:34:47 +00:00
|
|
|
private:
|
2015-03-06 00:39:25 +00:00
|
|
|
friend class Server;
|
|
|
|
Server* server_;
|
2015-02-24 18:34:47 +00:00
|
|
|
};
|
|
|
|
|
2015-03-17 17:49:39 +00:00
|
|
|
} // namespace grpc
|
2015-02-24 18:34:47 +00:00
|
|
|
|
2016-01-14 23:27:08 +00:00
|
|
|
#endif // GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H
|