diff options
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/auth_context.h | 7 | ||||
-rw-r--r-- | include/grpc++/auth_property_iterator.h | 77 | ||||
-rw-r--r-- | include/grpc++/completion_queue.h | 3 | ||||
-rw-r--r-- | include/grpc++/fixed_size_thread_pool.h | 67 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 7 | ||||
-rw-r--r-- | include/grpc++/thread_pool_interface.h | 4 |
6 files changed, 160 insertions, 5 deletions
diff --git a/include/grpc++/auth_context.h b/include/grpc++/auth_context.h index 158f8e3f07..c42105b927 100644 --- a/include/grpc++/auth_context.h +++ b/include/grpc++/auth_context.h @@ -36,14 +36,13 @@ #include <vector> +#include <grpc++/auth_property_iterator.h> #include <grpc++/config.h> namespace grpc { class AuthContext { public: - typedef std::pair<grpc::string, grpc::string> Property; - virtual ~AuthContext() {} // A peer identity, in general is one or more properties (in which case they @@ -54,6 +53,10 @@ class AuthContext { // Returns all the property values with the given name. virtual std::vector<grpc::string> FindPropertyValues( const grpc::string& name) const = 0; + + // Iteration over all the properties. + virtual AuthPropertyIterator begin() const = 0; + virtual AuthPropertyIterator end() const = 0; }; } // namespace grpc diff --git a/include/grpc++/auth_property_iterator.h b/include/grpc++/auth_property_iterator.h new file mode 100644 index 0000000000..c7870c46be --- /dev/null +++ b/include/grpc++/auth_property_iterator.h @@ -0,0 +1,77 @@ +/* + * + * Copyright 2015, 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_AUTH_PROPERTY_ITERATOR_H +#define GRPCXX_AUTH_PROPERTY_ITERATOR_H + +#include <iterator> +#include <vector> + +#include <grpc++/config.h> + +struct grpc_auth_context; +struct grpc_auth_property; +struct grpc_auth_property_iterator; + +namespace grpc { +class SecureAuthContext; + +typedef std::pair<grpc::string, grpc::string> AuthProperty; + +class AuthPropertyIterator + : public std::iterator<std::input_iterator_tag, const AuthProperty> { + public: + ~AuthPropertyIterator(); + AuthPropertyIterator& operator++(); + AuthPropertyIterator operator++(int); + bool operator==(const AuthPropertyIterator& rhs) const; + bool operator!=(const AuthPropertyIterator& rhs) const; + const AuthProperty operator*(); + + protected: + AuthPropertyIterator(); + AuthPropertyIterator(const grpc_auth_property* property, + const grpc_auth_property_iterator* iter); + private: + friend class SecureAuthContext; + const grpc_auth_property* property_; + // The following items form a grpc_auth_property_iterator. + const grpc_auth_context* ctx_; + size_t index_; + const char* name_; +}; + +} // namespace grpc + + #endif // GRPCXX_AUTH_PROPERTY_ITERATOR_H + diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index f32cbff06c..0523ab6a0e 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -105,7 +105,8 @@ class CompletionQueue : public GrpcLibrary { // Returns false if the queue is ready for destruction, true if event bool Next(void** tag, bool* ok) { - return (AsyncNextInternal(tag, ok, gpr_inf_future) != SHUTDOWN); + return (AsyncNextInternal(tag, ok, gpr_inf_future(GPR_CLOCK_REALTIME)) != + SHUTDOWN); } // Shutdown has to be called, and the CompletionQueue can only be diff --git a/include/grpc++/fixed_size_thread_pool.h b/include/grpc++/fixed_size_thread_pool.h new file mode 100644 index 0000000000..307e166142 --- /dev/null +++ b/include/grpc++/fixed_size_thread_pool.h @@ -0,0 +1,67 @@ +/* + * + * Copyright 2015, 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_FIXED_SIZE_THREAD_POOL_H +#define GRPCXX_FIXED_SIZE_THREAD_POOL_H + +#include <grpc++/config.h> + +#include <grpc++/impl/sync.h> +#include <grpc++/impl/thd.h> +#include <grpc++/thread_pool_interface.h> + +#include <queue> +#include <vector> + +namespace grpc { + +class FixedSizeThreadPool GRPC_FINAL : public ThreadPoolInterface { + public: + explicit FixedSizeThreadPool(int num_threads); + ~FixedSizeThreadPool(); + + void Add(const std::function<void()>& callback) GRPC_OVERRIDE; + + private: + grpc::mutex mu_; + grpc::condition_variable cv_; + bool shutdown_; + std::queue<std::function<void()>> callbacks_; + std::vector<grpc::thread*> threads_; + + void ThreadFunc(); +}; + +} // namespace grpc + +#endif // GRPCXX_FIXED_SIZE_THREAD_POOL_H diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 2123d03291..6f094eda3d 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -76,6 +76,10 @@ class CallOpBuffer; class CompletionQueue; class Server; +namespace testing { +class InteropContextInspector; +} // namespace testing + // Interface of server side rpc context. class ServerContext { public: @@ -93,7 +97,7 @@ class ServerContext { void AddInitialMetadata(const grpc::string& key, const grpc::string& value); void AddTrailingMetadata(const grpc::string& key, const grpc::string& value); - bool IsCancelled(); + bool IsCancelled() const; const std::multimap<grpc::string, grpc::string>& client_metadata() { return client_metadata_; @@ -102,6 +106,7 @@ class ServerContext { std::shared_ptr<const AuthContext> auth_context() const; private: + friend class ::grpc::testing::InteropContextInspector; friend class ::grpc::Server; template <class W, class R> friend class ::grpc::ServerAsyncReader; diff --git a/include/grpc++/thread_pool_interface.h b/include/grpc++/thread_pool_interface.h index ead307f6a2..d080b31dcc 100644 --- a/include/grpc++/thread_pool_interface.h +++ b/include/grpc++/thread_pool_interface.h @@ -44,9 +44,11 @@ class ThreadPoolInterface { virtual ~ThreadPoolInterface() {} // Schedule the given callback for execution. - virtual void ScheduleCallback(const std::function<void()>& callback) = 0; + virtual void Add(const std::function<void()>& callback) = 0; }; +ThreadPoolInterface* CreateDefaultThreadPool(); + } // namespace grpc #endif // GRPCXX_THREAD_POOL_INTERFACE_H |