Skip to content
Snippets Groups Projects
Commit 14a65f97 authored by Craig Tiller's avatar Craig Tiller
Browse files

Further progress

parent 5ef5db1d
No related branches found
No related tags found
No related merge requests found
......@@ -203,7 +203,7 @@ class RpcService {
public:
// Takes ownership.
void AddMethod(RpcServiceMethod* method) {
methods_.push_back(std::unique_ptr<RpcServiceMethod>(method));
methods_.emplace_back(method);
}
RpcServiceMethod* GetMethod(int i) { return methods_[i].get(); }
......
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __GRPCPP_IMPL_SERVICE_TYPE_H__
#define __GRPCPP_IMPL_SERVICE_TYPE_H__
namespace grpc {
class RpcService;
class SynchronousService {
public:
virtual ~SynchronousService() {}
virtual RpcService *service() = 0;
};
class AsynchronousService {
public:
virtual ~AsynchronousService() {}
};
} // namespace grpc
#endif // __GRPCPP_IMPL_SERVICE_TYPE_H__
\ No newline at end of file
......@@ -41,9 +41,11 @@
namespace grpc {
class AsynchronousService;
class RpcService;
class Server;
class ServerCredentials;
class SynchronousService;
class ThreadPoolInterface;
class ServerBuilder {
......@@ -53,7 +55,9 @@ class ServerBuilder {
// Register a service. This call does not take ownership of the service.
// The service must exist for the lifetime of the Server instance returned by
// BuildAndStart().
void RegisterService(RpcService* service);
void RegisterService(SynchronousService* service);
void ReigsterAsyncService(AsynchronousService *service);
// Add a listening port. Can be called multiple times.
void AddPort(const grpc::string& addr);
......@@ -71,6 +75,7 @@ class ServerBuilder {
private:
std::vector<RpcService*> services_;
std::vector<AsynchronousService*> async_services_;
std::vector<grpc::string> ports_;
std::shared_ptr<ServerCredentials> creds_;
ThreadPoolInterface* thread_pool_;
......
......@@ -108,8 +108,9 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor *file) {
std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
std::string temp =
"#include \"grpc++/impl/internal_stub.h\"\n"
"#include \"grpc++/status.h\"\n"
"#include <grpc++/impl/internal_stub.h>\n"
"#include <grpc++/impl/service_type.h>\n"
"#include <grpc++/status.h>\n"
"\n"
"namespace grpc {\n"
"class ChannelInterface;\n"
......@@ -147,6 +148,7 @@ std::string GetSourceIncludes() {
return "#include <grpc++/channel_interface.h>\n"
"#include <grpc++/impl/rpc_method.h>\n"
"#include <grpc++/impl/rpc_service_method.h>\n"
"#include <grpc++/impl/service_type.h>\n"
"#include <grpc++/stream.h>\n";
}
......@@ -165,8 +167,8 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
printer->Print(*vars,
"void $Method$(::grpc::ClientContext* context, "
"const $Request$& request, $Response$* response, "
"Status *status, "
"CompletionQueue *cq, void *tag);\n");
"::grpc::Status *status, "
"::grpc::CompletionQueue *cq, void *tag);\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
"::grpc::ClientWriter< $Request$>* $Method$("
......@@ -174,8 +176,8 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
printer->Print(*vars,
"::grpc::ClientWriter< $Request$>* $Method$("
"::grpc::ClientContext* context, $Response$* response, "
"Status *status, "
"CompletionQueue *cq, void *tag);\n");
"::grpc::Status *status, "
"::grpc::CompletionQueue *cq, void *tag);\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
......@@ -184,7 +186,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
printer->Print(*vars,
"::grpc::ClientReader< $Response$>* $Method$("
"::grpc::ClientContext* context, const $Request$* request, "
"CompletionQueue *cq, void *tag);\n");
"::grpc::CompletionQueue *cq, void *tag);\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"::grpc::ClientReaderWriter< $Request$, $Response$>* "
......@@ -192,7 +194,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
printer->Print(*vars,
"::grpc::ClientReaderWriter< $Request$, $Response$>* "
"$Method$(::grpc::ClientContext* context, "
"CompletionQueue *cq, void *tag);\n");
"::grpc::CompletionQueue *cq, void *tag);\n");
}
}
......@@ -297,7 +299,7 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
// Server side - Synchronous
printer->Print(
"class Service {\n"
"class Service : public ::grpc::SynchronousService {\n"
" public:\n");
printer->Indent();
printer->Print("Service() : service_(nullptr) {}\n");
......@@ -314,7 +316,7 @@ void PrintHeaderService(google::protobuf::io::Printer *printer,
// Server side - Asynchronous
printer->Print(
"class AsyncService final {\n"
"class AsyncService final : public ::grpc::AsynchronousService {\n"
" public:\n");
printer->Indent();
printer->Print("AsyncService() : service_(nullptr) {}\n");
......
......@@ -34,14 +34,19 @@
#include <grpc++/server_builder.h>
#include <grpc/support/log.h>
#include <grpc++/impl/service_type.h>
#include <grpc++/server.h>
namespace grpc {
ServerBuilder::ServerBuilder() : thread_pool_(nullptr) {}
void ServerBuilder::RegisterService(RpcService *service) {
services_.push_back(service);
void ServerBuilder::RegisterService(SynchronousService *service) {
services_.push_back(service->service());
}
void ServerBuilder::RegisterAsyncService(AsynchronousService *service) {
async_services_.push_back(service);
}
void ServerBuilder::AddPort(const grpc::string &addr) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment