third_party.grpc/include/grpc++/generic/async_generic_service.h

79 lines
2.3 KiB
C
Raw Normal View History

/*
*
2017-06-07 20:57:36 +00:00
* Copyright 2015 gRPC authors.
*
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
*
2017-06-07 20:57:36 +00:00
* http://www.apache.org/licenses/LICENSE-2.0
*
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-08-21 22:35:03 +00:00
#ifndef GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H
#define GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H
#include <grpc++/support/async_stream.h>
2016-03-25 20:38:14 +00:00
#include <grpc++/support/byte_buffer.h>
2015-03-06 00:39:25 +00:00
struct grpc_server;
namespace grpc {
2015-03-17 17:49:39 +00:00
typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer>
GenericServerAsyncReaderWriter;
2016-11-01 23:31:56 +00:00
class GenericServerContext final : public ServerContext {
public:
const grpc::string& method() const { return method_; }
const grpc::string& host() const { return host_; }
private:
friend class Server;
2016-01-15 02:00:04 +00:00
friend class ServerInterface;
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 {
public:
AsyncGenericService() : server_(nullptr) {}
2015-03-12 05:17:13 +00:00
void RequestCall(GenericServerContext* ctx,
2015-03-12 23:40:19 +00:00
GenericServerAsyncReaderWriter* reader_writer,
CompletionQueue* call_cq,
ServerCompletionQueue* notification_cq, void* tag);
private:
2015-03-06 00:39:25 +00:00
friend class Server;
Server* server_;
};
2015-03-17 17:49:39 +00:00
} // namespace grpc
2016-01-14 23:27:08 +00:00
#endif // GRPCXX_GENERIC_ASYNC_GENERIC_SERVICE_H