diff options
author | yang-g <yangg@google.com> | 2016-05-12 14:01:13 -0700 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-05-12 14:01:13 -0700 |
commit | 73621357abc767b7dd4ea2d034942efb1a4353a1 (patch) | |
tree | 6073d9baa0c19fea52a0c329627412d980deb5ba /include/grpc++ | |
parent | af9b99b9848ed6c3837b9b3caf2b81227170f10f (diff) | |
parent | 26dd2b8d6b298b7225f317b66a05646aaefb6a48 (diff) |
Merge remote-tracking branch 'upstream/master' into unique_ptr_reset
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/impl/codegen/method_handler_impl.h | 14 | ||||
-rw-r--r-- | include/grpc++/impl/server_builder_option.h | 8 | ||||
-rw-r--r-- | include/grpc++/impl/server_builder_plugin.h | 67 | ||||
-rw-r--r-- | include/grpc++/impl/server_initializer.h | 70 | ||||
-rw-r--r-- | include/grpc++/server.h | 8 | ||||
-rw-r--r-- | include/grpc++/server_builder.h | 13 |
6 files changed, 174 insertions, 6 deletions
diff --git a/include/grpc++/impl/codegen/method_handler_impl.h b/include/grpc++/impl/codegen/method_handler_impl.h index ad74efabc4..21ac6c4fb5 100644 --- a/include/grpc++/impl/codegen/method_handler_impl.h +++ b/include/grpc++/impl/codegen/method_handler_impl.h @@ -44,10 +44,10 @@ namespace grpc { template <class ServiceType, class RequestType, class ResponseType> class RpcMethodHandler : public MethodHandler { public: - RpcMethodHandler( - std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ResponseType*)> func, - ServiceType* service) + RpcMethodHandler(std::function<Status(ServiceType*, ServerContext*, + const RequestType*, ResponseType*)> + func, + ServiceType* service) : func_(func), service_(service) {} void RunHandler(const HandlerParameter& param) GRPC_FINAL { @@ -88,7 +88,8 @@ class ClientStreamingHandler : public MethodHandler { public: ClientStreamingHandler( std::function<Status(ServiceType*, ServerContext*, - ServerReader<RequestType>*, ResponseType*)> func, + ServerReader<RequestType>*, ResponseType*)> + func, ServiceType* service) : func_(func), service_(service) {} @@ -124,7 +125,8 @@ class ServerStreamingHandler : public MethodHandler { public: ServerStreamingHandler( std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ServerWriter<ResponseType>*)> func, + ServerWriter<ResponseType>*)> + func, ServiceType* service) : func_(func), service_(service) {} diff --git a/include/grpc++/impl/server_builder_option.h b/include/grpc++/impl/server_builder_option.h index bcb19824fd..2b7e89f5e5 100644 --- a/include/grpc++/impl/server_builder_option.h +++ b/include/grpc++/impl/server_builder_option.h @@ -34,6 +34,10 @@ #ifndef GRPCXX_IMPL_SERVER_BUILDER_OPTION_H #define GRPCXX_IMPL_SERVER_BUILDER_OPTION_H +#include <map> +#include <memory> + +#include <grpc++/impl/server_builder_plugin.h> #include <grpc++/support/channel_arguments.h> namespace grpc { @@ -44,6 +48,10 @@ class ServerBuilderOption { virtual ~ServerBuilderOption() {} /// Alter the \a ChannelArguments used to create the gRPC server. virtual void UpdateArguments(ChannelArguments* args) = 0; + /// Alter the ServerBuilderPlugin map that will be added into ServerBuilder. + virtual void UpdatePlugins( + std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin> >* + plugins) = 0; }; } // namespace grpc diff --git a/include/grpc++/impl/server_builder_plugin.h b/include/grpc++/impl/server_builder_plugin.h new file mode 100644 index 0000000000..1e157efa11 --- /dev/null +++ b/include/grpc++/impl/server_builder_plugin.h @@ -0,0 +1,67 @@ +/* + * + * Copyright 2016, 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 GRPCXX_IMPL_SERVER_BUILDER_PLUGIN_H +#define GRPCXX_IMPL_SERVER_BUILDER_PLUGIN_H + +#include <memory> + +#include <grpc++/support/config.h> + +namespace grpc { + +class ServerInitializer; + +class ServerBuilderPlugin { + public: + virtual ~ServerBuilderPlugin() {} + virtual grpc::string name() = 0; + + // InitServer will be called in ServerBuilder::BuildAndStart(), after the + // Server instance is created. + virtual void InitServer(ServerInitializer* si) = 0; + + // Finish will be called at the end of ServerBuilder::BuildAndStart(). + virtual void Finish(ServerInitializer* si) = 0; + + // ChangeArguments is an interface that can be used in + // ServerBuilderOption::UpdatePlugins + virtual void ChangeArguments(const grpc::string& name, void* value) = 0; + + virtual bool has_sync_methods() const { return false; } + virtual bool has_async_methods() const { return false; } +}; + +} // namespace grpc + +#endif // GRPCXX_IMPL_SERVER_BUILDER_PLUGIN_H diff --git a/include/grpc++/impl/server_initializer.h b/include/grpc++/impl/server_initializer.h new file mode 100644 index 0000000000..dbcecc7026 --- /dev/null +++ b/include/grpc++/impl/server_initializer.h @@ -0,0 +1,70 @@ +/* + * + * Copyright 2016, 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 GRPCXX_IMPL_SERVER_INITIALIZER_H +#define GRPCXX_IMPL_SERVER_INITIALIZER_H + +#include <memory> +#include <vector> + +#include <grpc++/server.h> + +namespace grpc { + +class Server; +class Service; + +class ServerInitializer { + public: + ServerInitializer(Server* server) : server_(server) {} + + bool RegisterService(std::shared_ptr<Service> service) { + if (!server_->RegisterService(nullptr, service.get())) { + return false; + } + default_services_.push_back(service); + return true; + } + + const std::vector<grpc::string>* GetServiceList() { + return &server_->services_; + } + + private: + Server* server_; + std::vector<std::shared_ptr<Service> > default_services_; +}; + +} // namespace grpc + +#endif // GRPCXX_IMPL_SERVER_INITIALIZER_H diff --git a/include/grpc++/server.h b/include/grpc++/server.h index 729a5143bf..a0ee0e98e4 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -36,6 +36,7 @@ #include <list> #include <memory> +#include <vector> #include <grpc++/completion_queue.h> #include <grpc++/impl/call.h> @@ -57,6 +58,7 @@ class GenericServerContext; class AsyncGenericService; class ServerAsyncStreamingInterface; class ServerContext; +class ServerInitializer; class ThreadPoolInterface; /// Models a gRPC server. @@ -94,6 +96,7 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibraryCodegen { private: friend class AsyncGenericService; friend class ServerBuilder; + friend class ServerInitializer; class SyncRequest; class AsyncRequest; @@ -159,6 +162,8 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibraryCodegen { grpc_server* server() GRPC_OVERRIDE { return server_; }; + ServerInitializer* initializer(); + const int max_message_size_; // Completion queue. @@ -175,6 +180,7 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibraryCodegen { std::shared_ptr<GlobalCallbacks> global_callbacks_; std::list<SyncRequest>* sync_methods_; + std::vector<grpc::string> services_; std::unique_ptr<RpcServiceMethod> unknown_method_; bool has_generic_service_; @@ -184,6 +190,8 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibraryCodegen { ThreadPoolInterface* thread_pool_; // Whether the thread pool is created and owned by the server. bool thread_pool_owned_; + + std::unique_ptr<ServerInitializer> server_initializer_; }; } // namespace grpc diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index 86c7fecef5..ad629521cb 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -34,10 +34,12 @@ #ifndef GRPCXX_SERVER_BUILDER_H #define GRPCXX_SERVER_BUILDER_H +#include <map> #include <memory> #include <vector> #include <grpc++/impl/server_builder_option.h> +#include <grpc++/impl/server_builder_plugin.h> #include <grpc++/support/config.h> #include <grpc/compression.h> @@ -51,6 +53,10 @@ class ServerCompletionQueue; class ServerCredentials; class Service; +namespace testing { +class ServerBuilderPluginTest; +} // namespace testing + /// A builder class for the creation and startup of \a grpc::Server instances. class ServerBuilder { public: @@ -107,7 +113,13 @@ class ServerBuilder { /// Return a running server which is ready for processing calls. std::unique_ptr<Server> BuildAndStart(); + /// For internal use only: Register a ServerBuilderPlugin factory function. + static void InternalAddPluginFactory( + std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()); + private: + friend class ::grpc::testing::ServerBuilderPluginTest; + struct Port { grpc::string addr; std::shared_ptr<ServerCredentials> creds; @@ -130,6 +142,7 @@ class ServerBuilder { std::vector<Port> ports_; std::vector<ServerCompletionQueue*> cqs_; std::shared_ptr<ServerCredentials> creds_; + std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>> plugins_; AsyncGenericService* generic_service_; }; |