From 3462f8e539f37ae2e6bd23802283ea02074318a2 Mon Sep 17 00:00:00 2001 From: sztomi Date: Sat, 28 Oct 2017 23:42:42 +0200 Subject: [PATCH 01/17] =?UTF-8?q?Reformat!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 63 +++- include/rpc/client.h | 231 +++++++------- include/rpc/client.inl | 77 ++--- include/rpc/compatibility.h | 6 +- include/rpc/config.h | 9 +- include/rpc/detail/all.h | 16 +- include/rpc/detail/any.h | 11 +- include/rpc/detail/async_writer.h | 133 ++++---- include/rpc/detail/bool.h | 6 +- include/rpc/detail/call.h | 72 ++--- include/rpc/detail/client_error.h | 40 +-- include/rpc/detail/constant.h | 6 +- include/rpc/detail/dev_utils.h | 8 +- include/rpc/detail/func_tools.h | 8 +- include/rpc/detail/func_traits.h | 45 ++- include/rpc/detail/if.h | 2 +- include/rpc/detail/invoke.h | 7 +- include/rpc/detail/is_specialization_of.h | 4 +- include/rpc/detail/log.h | 196 ++++++------ include/rpc/detail/make_unique.h | 10 +- include/rpc/detail/not.h | 5 +- include/rpc/detail/pimpl.h | 5 +- include/rpc/detail/response.h | 172 +++++------ include/rpc/detail/server_session.h | 38 +-- include/rpc/detail/thread_group.h | 32 +- include/rpc/detail/util.h | 15 +- include/rpc/dispatcher.h | 174 ++++++----- include/rpc/dispatcher.inl | 91 +++--- include/rpc/rpc_error.h | 36 +-- include/rpc/server.h | 175 +++++------ include/rpc/this_handler.h | 79 ++--- include/rpc/this_handler.inl | 16 +- include/rpc/this_server.h | 14 +- include/rpc/this_session.h | 34 +-- include/rpc/version.h | 2 +- lib/rpc/client.cc | 351 +++++++++++----------- lib/rpc/detail/client_error.cc | 10 +- lib/rpc/detail/response.cc | 72 +++-- lib/rpc/detail/server_session.cc | 218 +++++++------- lib/rpc/dispatcher.cc | 220 +++++++------- lib/rpc/rpc_error.cc | 18 +- lib/rpc/server.cc | 161 +++++----- lib/rpc/this_handler.cc | 20 +- lib/rpc/this_server.cc | 13 +- lib/rpc/this_session.cc | 18 +- 45 files changed, 1519 insertions(+), 1420 deletions(-) diff --git a/.clang-format b/.clang-format index 4e1f056f..f8743e16 100644 --- a/.clang-format +++ b/.clang-format @@ -1,7 +1,60 @@ -BasedOnStyle: LLVM -IndentWidth: 4 -Standard: Cpp11 -UseTab: Never +BasedOnStyle: Chromium +AccessModifierOffset: -2 +AlignAfterOpenBracket: true +AlignEscapedNewlinesLeft: true +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: false +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false ColumnLimit: 80 -AccessModifierOffset: -4 +CommentPragmas: '^ IWYU pragma:' ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +IndentCaseLabels: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +Language: Cpp +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 2 +UseTab: Never diff --git a/include/rpc/client.h b/include/rpc/client.h index 837e85c9..3e02fda1 100644 --- a/include/rpc/client.h +++ b/include/rpc/client.h @@ -22,126 +22,129 @@ namespace rpc { //! to the given server asynchronically and disconnects when it is destroyed. class client { public: - //! \brief Constructs a client. - //! - //! When a client is constructed, it initiates a connection - //! asynchronically. This means that it will not block while the connection - //! is established. However, when the first call is performed, it *might* - //! block if the connection was not already established. - //! - //! \param addr The address of the server to connect to. This might be an - //! IP address or a host name, too. - //! \param port The port on the server to connect to. - client(std::string const &addr, uint16_t port); - - //! \cond DOXYGEN_SKIP - client(client const &) = delete; - //! \endcond - - //! \brief Destructor. - //! - //! During destruction, the connection to the server is gracefully closed. - //! This means that any outstanding reads and writes are completed first. - ~client(); - - //! \brief Calls a function with the given name and arguments (if any). - //! - //! \param func_name The name of the function to call on the server. - //! \param args A variable number of arguments to pass to the called - //! function. - //! - //! \tparam Args The types of the arguments. Each type in this parameter - //! pack have to be serializable by msgpack. - //! - //! \returns A RPCLIB_MSGPACK::object containing the result of the function (if - //! any). To obtain a typed value, use the msgpack API. - //! - //! \throws rpc::rpc_error if the server responds with an error. - template - RPCLIB_MSGPACK::object_handle call(std::string const &func_name, Args... args); - - //! \brief Calls a function asynchronously with the given name and - //! arguments. - //! - //! A call is performed asynchronously in the context of the client, i.e. - //! this is not to be confused with parallel execution on the server. - //! This function differs from `call` in that it does not wait for the - //! result of the function. Instead, it returns a std::future that - //! can be used to retrieve the result later. - //! - //! \param func_name The name of the function to call. - //! \param args The arguments to pass to the function. - //! - //! \tparam Args The types of the arguments. - //! - //! \returns A std::future, possibly holding a future result - //! (which is a RPCLIB_MSGPACK::object). - template - std::future async_call(std::string const &func_name, - Args... args); - - //! \brief Sends a notification with the given name and arguments (if any). - //! - //! Notifications are a special kind of calls. They can be used to notify - //! the server, while not expecting a response. In `rpclib` terminology, - //! a notification is like an `async_call` without a return value. - //! - //! \param func_name The name of the notification to call. - //! \param args The arguments to pass to the function. - //! \tparam Args THe types of the arguments. - //! - //! \note This function returns immediately (possibly before the - //! notification is written to the socket). - template - void send(std::string const &func_name, Args... args); - - //! \brief Returns the timeout setting of this client in milliseconds. - //! - //! The timeout is applied to synchronous calls. If the timeout expires - //! without receiving a response from the server, rpc::timeout exception - //! will be thrown. - //! - //! \note The timeout has no effect on async calls. For those, - //! the preferred timeout mechanism remains using std::future. - //! - //! The default value for timeout is 5000ms (5 seconds). - nonstd::optional get_timeout() const; - - //! \brief Sets the timeout for synchronous calls. For more information, - //! see get_timeout(). - void set_timeout(int64_t value); - - //! \brief Clears the timeout for synchronous calls. For more information, - //! see get_timeout(). - void clear_timeout(); - - //! \brief Enum representing the connection states of the client. - enum class connection_state { initial, connected, disconnected, reset }; - - //! \brief Returns the current connection state. - connection_state get_connection_state() const; - - //! \brief Waits for the completion of all ongoing calls. - void wait_all_responses(); + //! \brief Constructs a client. + //! + //! When a client is constructed, it initiates a connection + //! asynchronically. This means that it will not block while the connection + //! is established. However, when the first call is performed, it *might* + //! block if the connection was not already established. + //! + //! \param addr The address of the server to connect to. This might be an + //! IP address or a host name, too. + //! \param port The port on the server to connect to. + client(std::string const &addr, uint16_t port); + + //! \cond DOXYGEN_SKIP + client(client const &) = delete; + //! \endcond + + //! \brief Destructor. + //! + //! During destruction, the connection to the server is gracefully closed. + //! This means that any outstanding reads and writes are completed first. + ~client(); + + //! \brief Calls a function with the given name and arguments (if any). + //! + //! \param func_name The name of the function to call on the server. + //! \param args A variable number of arguments to pass to the called + //! function. + //! + //! \tparam Args The types of the arguments. Each type in this parameter + //! pack have to be serializable by msgpack. + //! + //! \returns A RPCLIB_MSGPACK::object containing the result of the function + //! (if any). To obtain a typed value, use the msgpack API. + //! + //! \throws rpc::rpc_error if the server responds with an error. + template + RPCLIB_MSGPACK::object_handle call(std::string const &func_name, + Args... args); + + //! \brief Calls a function asynchronously with the given name and + //! arguments. + //! + //! A call is performed asynchronously in the context of the client, i.e. + //! this is not to be confused with parallel execution on the server. + //! This function differs from `call` in that it does not wait for the + //! result of the function. Instead, it returns a std::future that + //! can be used to retrieve the result later. + //! + //! \param func_name The name of the function to call. + //! \param args The arguments to pass to the function. + //! + //! \tparam Args The types of the arguments. + //! + //! \returns A std::future, possibly holding a future result + //! (which is a RPCLIB_MSGPACK::object). + template + std::future async_call( + std::string const &func_name, + Args... args); + + //! \brief Sends a notification with the given name and arguments (if any). + //! + //! Notifications are a special kind of calls. They can be used to notify + //! the server, while not expecting a response. In `rpclib` terminology, + //! a notification is like an `async_call` without a return value. + //! + //! \param func_name The name of the notification to call. + //! \param args The arguments to pass to the function. + //! \tparam Args THe types of the arguments. + //! + //! \note This function returns immediately (possibly before the + //! notification is written to the socket). + template + void send(std::string const &func_name, Args... args); + + //! \brief Returns the timeout setting of this client in milliseconds. + //! + //! The timeout is applied to synchronous calls. If the timeout expires + //! without receiving a response from the server, rpc::timeout exception + //! will be thrown. + //! + //! \note The timeout has no effect on async calls. For those, + //! the preferred timeout mechanism remains using std::future. + //! + //! The default value for timeout is 5000ms (5 seconds). + nonstd::optional get_timeout() const; + + //! \brief Sets the timeout for synchronous calls. For more information, + //! see get_timeout(). + void set_timeout(int64_t value); + + //! \brief Clears the timeout for synchronous calls. For more information, + //! see get_timeout(). + void clear_timeout(); + + //! \brief Enum representing the connection states of the client. + enum class connection_state { initial, connected, disconnected, reset }; + + //! \brief Returns the current connection state. + connection_state get_connection_state() const; + + //! \brief Waits for the completion of all ongoing calls. + void wait_all_responses(); private: - //! \brief Type of a promise holding a future response. - using rsp_promise = std::promise; + //! \brief Type of a promise holding a future response. + using rsp_promise = std::promise; - enum class request_type { call = 0, notification = 2 }; + enum class request_type { call = 0, notification = 2 }; - void wait_conn(); - void post(std::shared_ptr buffer, int idx, - std::string const& func_name, - std::shared_ptr p); - void post(RPCLIB_MSGPACK::sbuffer *buffer); - int get_next_call_idx(); - RPCLIB_NORETURN void throw_timeout(std::string const& func_name); + void wait_conn(); + void post(std::shared_ptr buffer, + int idx, + std::string const &func_name, + std::shared_ptr p); + void post(RPCLIB_MSGPACK::sbuffer *buffer); + int get_next_call_idx(); + RPCLIB_NORETURN void throw_timeout(std::string const &func_name); private: - static constexpr double buffer_grow_factor = 1.8; - RPCLIB_DECLARE_PIMPL() + static constexpr double buffer_grow_factor = 1.8; + RPCLIB_DECLARE_PIMPL() }; -} +} // namespace rpc #include "rpc/client.inl" diff --git a/include/rpc/client.inl b/include/rpc/client.inl index 04dc825b..856e7ee0 100644 --- a/include/rpc/client.inl +++ b/include/rpc/client.inl @@ -2,44 +2,45 @@ namespace rpc { template RPCLIB_MSGPACK::object_handle client::call(std::string const &func_name, - Args... args) { - RPCLIB_CREATE_LOG_CHANNEL(client) - auto future = async_call(func_name, std::forward(args)...); - if (auto timeout = get_timeout()) { - auto wait_result = future.wait_for(std::chrono::milliseconds(*timeout)); - if (wait_result == std::future_status::timeout) { - throw_timeout(func_name); - } + Args... args) { + RPCLIB_CREATE_LOG_CHANNEL(client) + auto future = async_call(func_name, std::forward(args)...); + if (auto timeout = get_timeout()) { + auto wait_result = future.wait_for(std::chrono::milliseconds(*timeout)); + if (wait_result == std::future_status::timeout) { + throw_timeout(func_name); } + } - return future.get(); + return future.get(); } template -std::future -client::async_call(std::string const &func_name, Args... args) { - RPCLIB_CREATE_LOG_CHANNEL(client) - wait_conn(); - using RPCLIB_MSGPACK::object; - LOG_DEBUG("Calling {}", func_name); +std::future client::async_call( + std::string const &func_name, + Args... args) { + RPCLIB_CREATE_LOG_CHANNEL(client) + wait_conn(); + using RPCLIB_MSGPACK::object; + LOG_DEBUG("Calling {}", func_name); - auto args_obj = std::make_tuple(args...); - const int idx = get_next_call_idx(); - auto call_obj = - std::make_tuple(static_cast(client::request_type::call), idx, - func_name, args_obj); + auto args_obj = std::make_tuple(args...); + const int idx = get_next_call_idx(); + auto call_obj = + std::make_tuple(static_cast(client::request_type::call), idx, + func_name, args_obj); - auto buffer = std::make_shared(); - RPCLIB_MSGPACK::pack(*buffer, call_obj); + auto buffer = std::make_shared(); + RPCLIB_MSGPACK::pack(*buffer, call_obj); - // TODO: Change to move semantics when asio starts supporting move-only - // handlers in post(). [sztomi, 2016-02-14] - auto p = std::make_shared>(); - auto ft = p->get_future(); + // TODO: Change to move semantics when asio starts supporting move-only + // handlers in post(). [sztomi, 2016-02-14] + auto p = std::make_shared>(); + auto ft = p->get_future(); - post(buffer, idx, func_name, p); + post(buffer, idx, func_name, p); - return ft; + return ft; } //! \brief Sends a notification with the given name and arguments (if any). @@ -50,17 +51,17 @@ client::async_call(std::string const &func_name, Args... args) { //! \tparam Args THe types of the arguments. template void client::send(std::string const &func_name, Args... args) { - RPCLIB_CREATE_LOG_CHANNEL(client) - LOG_DEBUG("Sending notification {}", func_name); + RPCLIB_CREATE_LOG_CHANNEL(client) + LOG_DEBUG("Sending notification {}", func_name); - auto args_obj = std::make_tuple(args...); - auto call_obj = std::make_tuple( - static_cast(client::request_type::notification), func_name, - args_obj); + auto args_obj = std::make_tuple(args...); + auto call_obj = + std::make_tuple(static_cast(client::request_type::notification), + func_name, args_obj); - auto buffer = new RPCLIB_MSGPACK::sbuffer; - RPCLIB_MSGPACK::pack(*buffer, call_obj); + auto buffer = new RPCLIB_MSGPACK::sbuffer; + RPCLIB_MSGPACK::pack(*buffer, call_obj); - post(buffer); -} + post(buffer); } +} // namespace rpc diff --git a/include/rpc/compatibility.h b/include/rpc/compatibility.h index 19baa201..ac10501d 100644 --- a/include/rpc/compatibility.h +++ b/include/rpc/compatibility.h @@ -12,9 +12,9 @@ #else #define RPCLIB_NORETURN __declspec(noreturn) -#define RPCLIB_CONSTEXPR const // bad replacement, but gets the job done +#define RPCLIB_CONSTEXPR const // bad replacement, but gets the job done #define RPCLIB_FINAL -#endif // !_MSC_VER +#endif // !_MSC_VER -#endif // COMPATIBILITY_H_PODKJ3 +#endif // COMPATIBILITY_H_PODKJ3 diff --git a/include/rpc/config.h b/include/rpc/config.h index f0611e34..fa14f007 100644 --- a/include/rpc/config.h +++ b/include/rpc/config.h @@ -8,18 +8,17 @@ #include "rpc/compatibility.h" -namespace rpc -{ +namespace rpc { using session_id_t = std::intptr_t; //! \brief Constants used in the library struct constants RPCLIB_FINAL { - static RPCLIB_CONSTEXPR std::size_t DEFAULT_BUFFER_SIZE = 1024 << 10; - static RPCLIB_CONSTEXPR std::uint16_t DEFAULT_PORT = 8080; + static RPCLIB_CONSTEXPR std::size_t DEFAULT_BUFFER_SIZE = 1024 << 10; + static RPCLIB_CONSTEXPR std::uint16_t DEFAULT_PORT = 8080; }; -} /* rpc */ +} // namespace rpc // This define allows the end user to replace the msgpack dependency. // To do so, one has to delete the msgpack headers that are diff --git a/include/rpc/detail/all.h b/include/rpc/detail/all.h index 5a060bfb..f95088de 100644 --- a/include/rpc/detail/all.h +++ b/include/rpc/detail/all.h @@ -3,24 +3,22 @@ #ifndef ALL_H_H8MAAYCG #define ALL_H_H8MAAYCG -#include "rpc/detail/invoke.h" -#include "rpc/detail/if.h" #include "rpc/detail/bool.h" +#include "rpc/detail/if.h" +#include "rpc/detail/invoke.h" namespace rpc { namespace detail { //! \brief This type can be used to check multiple conditions. //! It will be true_type if all its arguments are true. -template struct all : true_ {}; +template +struct all : true_ {}; template -struct all - : if_, false_> {}; - -} -} - +struct all : if_, false_> {}; +} // namespace detail +} // namespace rpc #endif /* end of include guard: ALL_H_H8MAAYCG */ diff --git a/include/rpc/detail/any.h b/include/rpc/detail/any.h index 09ffb81c..2a2c5d72 100644 --- a/include/rpc/detail/any.h +++ b/include/rpc/detail/any.h @@ -3,19 +3,20 @@ #ifndef ANY_H_4G3QUOAN #define ANY_H_4G3QUOAN -#include "rpc/detail/invoke.h" -#include "rpc/detail/if.h" #include "rpc/detail/bool.h" +#include "rpc/detail/if.h" +#include "rpc/detail/invoke.h" namespace rpc { namespace detail { //! \brief Evaluates to true_type if any of its arguments is true_type. -template struct any : false_ {}; +template +struct any : false_ {}; template struct any : if_> {}; -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: ANY_H_4G3QUOAN */ diff --git a/include/rpc/detail/async_writer.h b/include/rpc/detail/async_writer.h index 66488ff6..b94243b0 100644 --- a/include/rpc/detail/async_writer.h +++ b/include/rpc/detail/async_writer.h @@ -3,12 +3,12 @@ #ifndef ASYNC_WRITER_H_HQIRH28I #define ASYNC_WRITER_H_HQIRH28I -#include "asio.hpp" -#include "rpc/msgpack.hpp" #include #include #include #include +#include "asio.hpp" +#include "rpc/msgpack.hpp" namespace rpc { @@ -19,81 +19,80 @@ namespace detail { //! \brief Common logic for classes that have a write queue with async writing. class async_writer : public std::enable_shared_from_this { public: - async_writer(RPCLIB_ASIO::io_service *io, - RPCLIB_ASIO::ip::tcp::socket socket) - : socket_(std::move(socket)), write_strand_(*io), exit_(false) {} - - void do_write() { - if (exit_) { - return; - } - auto self(shared_from_this()); - auto &item = write_queue_.front(); - // the data in item remains valid until the handler is called - // since it will still be in the queue physically until then. - RPCLIB_ASIO::async_write( - socket_, RPCLIB_ASIO::buffer(item.data(), item.size()), - write_strand_.wrap( - [this, self](std::error_code ec, std::size_t transferred) { - (void)transferred; - if (!ec) { - write_queue_.pop_front(); - if (write_queue_.size() > 0) { - if (!exit_) { - do_write(); - } - } - } else { - LOG_ERROR("Error while writing to socket: {}", ec); - } - - if (exit_) { - LOG_INFO("Closing socket"); - try { - socket_.shutdown( - RPCLIB_ASIO::ip::tcp::socket::shutdown_both); - } - catch (std::system_error &e) { - (void)e; - LOG_WARN("std::system_error during socket shutdown. " - "Code: {}. Message: {}", e.code(), e.what()); - } - socket_.close(); - } - })); - } + async_writer(RPCLIB_ASIO::io_service *io, RPCLIB_ASIO::ip::tcp::socket socket) + : socket_(std::move(socket)), write_strand_(*io), exit_(false) {} - void write(RPCLIB_MSGPACK::sbuffer &&data) { - write_queue_.push_back(std::move(data)); - if (write_queue_.size() > 1) { - return; // there is an ongoing write chain so don't start another - } - - do_write(); + void do_write() { + if (exit_) { + return; + } + auto self(shared_from_this()); + auto &item = write_queue_.front(); + // the data in item remains valid until the handler is called + // since it will still be in the queue physically until then. + RPCLIB_ASIO::async_write( + socket_, RPCLIB_ASIO::buffer(item.data(), item.size()), + write_strand_.wrap( + [this, self](std::error_code ec, std::size_t transferred) { + (void)transferred; + if (!ec) { + write_queue_.pop_front(); + if (write_queue_.size() > 0) { + if (!exit_) { + do_write(); + } + } + } else { + LOG_ERROR("Error while writing to socket: {}", ec); + } + + if (exit_) { + LOG_INFO("Closing socket"); + try { + socket_.shutdown(RPCLIB_ASIO::ip::tcp::socket::shutdown_both); + } catch (std::system_error &e) { + (void)e; + LOG_WARN( + "std::system_error during socket shutdown. " + "Code: {}. Message: {}", + e.code(), e.what()); + } + socket_.close(); + } + })); + } + + void write(RPCLIB_MSGPACK::sbuffer &&data) { + write_queue_.push_back(std::move(data)); + if (write_queue_.size() > 1) { + return; // there is an ongoing write chain so don't start another } - friend class rpc::client; + do_write(); + } + + friend class rpc::client; protected: - template - std::shared_ptr shared_from_base() { - return std::static_pointer_cast(shared_from_this()); - } + template + std::shared_ptr shared_from_base() { + return std::static_pointer_cast(shared_from_this()); + } protected: - RPCLIB_ASIO::ip::tcp::socket socket_; - RPCLIB_ASIO::strand write_strand_; - std::atomic_bool exit_{false}; - bool exited_ = false; - std::mutex m_exit_; - std::condition_variable cv_exit_; + RPCLIB_ASIO::ip::tcp::socket socket_; + RPCLIB_ASIO::strand write_strand_; + std::atomic_bool exit_{false}; + bool exited_ = false; + std::mutex m_exit_; + std::condition_variable cv_exit_; private: - std::deque write_queue_; - RPCLIB_CREATE_LOG_CHANNEL(async_writer) + std::deque write_queue_; + RPCLIB_CREATE_LOG_CHANNEL(async_writer) }; -} /* detail */ -} /* rpc */ +} // namespace detail +} // namespace rpc #endif /* end of include guard: ASYNC_WRITER_H_HQIRH28I */ diff --git a/include/rpc/detail/bool.h b/include/rpc/detail/bool.h index 65f37d37..3111ba15 100644 --- a/include/rpc/detail/bool.h +++ b/include/rpc/detail/bool.h @@ -8,14 +8,14 @@ namespace rpc { namespace detail { -template +template using bool_ = constant; using true_ = bool_; using false_ = bool_; -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: BOOL_H_QLG6S5XZ */ diff --git a/include/rpc/detail/call.h b/include/rpc/detail/call.h index b5c9bdce..f5e531b3 100644 --- a/include/rpc/detail/call.h +++ b/include/rpc/detail/call.h @@ -13,28 +13,26 @@ namespace detail { //! \brief Calls a functor with argument provided directly template -auto call(Functor f, Arg &&arg) - -> decltype(f(std::forward(arg))) -{ - return f(std::forward(arg)); +auto call(Functor f, Arg &&arg) -> decltype(f(std::forward(arg))) { + return f(std::forward(arg)); } - // Default behaviour is to assume C++11, overriding RPCLIB_CXX_STANDARD can use // newer standards: #if RPCLIB_CXX_STANDARD >= 14 template -decltype(auto) call_helper(Functor func, std::tuple &¶ms, +decltype(auto) call_helper(Functor func, + std::tuple &¶ms, std::index_sequence) { - return func(std::get(params)...); + return func(std::get(params)...); } //! \brief Calls a functor with arguments provided as a tuple template decltype(auto) call(Functor f, std::tuple &args) { - return call_helper(f, std::forward>(args), - std::index_sequence_for{}); + return call_helper(f, std::forward>(args), + std::index_sequence_for{}); } #else @@ -42,51 +40,37 @@ decltype(auto) call(Functor f, std::tuple &args) { // N is number of arguments left in tuple to unpack template -struct call_helper -{ - template - static auto call( - Functor f, - std::tuple& args_t, - ArgsF&&... args_f) - -> decltype(call_helper::call( - f, args_t, std::get(args_t), - std::forward(args_f)...)) - { - return call_helper::call( - f, - args_t, - std::get(args_t), - std::forward(args_f)... - ); - } +struct call_helper { + template + static auto call(Functor f, std::tuple &args_t, ArgsF &&... args_f) + -> decltype(call_helper::call(f, + args_t, + std::get(args_t), + std::forward(args_f)...)) { + return call_helper::call(f, args_t, std::get(args_t), + std::forward(args_f)...); + } }; template <> -struct call_helper<0> -{ - template - static auto call( - Functor f, - std::tuple&, - ArgsF&&... args_f) - -> decltype(f(std::forward(args_f)...)) - { - return f(std::forward(args_f)...); - } +struct call_helper<0> { + template + static auto call(Functor f, std::tuple &, ArgsF &&... args_f) + -> decltype(f(std::forward(args_f)...)) { + return f(std::forward(args_f)...); + } }; //! \brief Calls a functor with arguments provided as a tuple template -auto call(Functor f, std::tuple& args_t) - -> decltype(call_helper::call(f, args_t)) -{ - return call_helper::call(f, args_t); +auto call(Functor f, std::tuple &args_t) + -> decltype(call_helper::call(f, args_t)) { + return call_helper::call(f, args_t); } #endif -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: CALL_H_ZXFACADH */ diff --git a/include/rpc/detail/client_error.h b/include/rpc/detail/client_error.h index 73edd2eb..99c441dd 100644 --- a/include/rpc/detail/client_error.h +++ b/include/rpc/detail/client_error.h @@ -3,8 +3,8 @@ #ifndef RPC_CLIENT_ERROR_H #define RPC_CLIENT_ERROR_H -#include #include +#include namespace rpc { namespace detail { @@ -14,26 +14,26 @@ namespace detail { //! wrong number of arguments, etc.) class client_error : public std::exception { public: - //! \brief Error codes used for signaling back to clients. These are used - //! to produce google-able error messages (since the msgpack-rpc protocol - //! does not define error handling in any more detail than sending an - //! object). - //! \note Care must be taken to keep these codes stable even between major - //! versions. - enum class code : uint16_t { - no_such_function = 1, - wrong_arity = 2, - protocol_error = 4 - }; - - client_error(code c, const std::string &msg); - - const char *what() const noexcept; + //! \brief Error codes used for signaling back to clients. These are used + //! to produce google-able error messages (since the msgpack-rpc protocol + //! does not define error handling in any more detail than sending an + //! object). + //! \note Care must be taken to keep these codes stable even between major + //! versions. + enum class code : uint16_t { + no_such_function = 1, + wrong_arity = 2, + protocol_error = 4 + }; + + client_error(code c, const std::string &msg); + + const char *what() const noexcept; private: - std::string what_; + std::string what_; }; -} -} +} // namespace detail +} // namespace rpc -#endif // RPC_CLIENT_ERROR_H +#endif // RPC_CLIENT_ERROR_H diff --git a/include/rpc/detail/constant.h b/include/rpc/detail/constant.h index 1c373b3a..4f4617d0 100644 --- a/include/rpc/detail/constant.h +++ b/include/rpc/detail/constant.h @@ -8,10 +8,10 @@ namespace rpc { namespace detail { -template +template struct constant : std::integral_constant {}; -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: CONSTANT_H_5CXUYJEW */ diff --git a/include/rpc/detail/dev_utils.h b/include/rpc/detail/dev_utils.h index 32532097..444d4439 100644 --- a/include/rpc/detail/dev_utils.h +++ b/include/rpc/detail/dev_utils.h @@ -10,12 +10,12 @@ namespace rpc { namespace detail { inline void name_thread(std::string const &name) { - (void)name; + (void)name; #ifdef RPCLIB_LINUX - pthread_setname_np(pthread_self(), name.c_str()); + pthread_setname_np(pthread_self(), name.c_str()); #endif } -} /* detail */ -} /* rpc */ +} // namespace detail +} // namespace rpc #endif /* end of include guard: DEV_UTILS_H_JQSWE2OS */ diff --git a/include/rpc/detail/func_tools.h b/include/rpc/detail/func_tools.h index 4f18e482..60ae788a 100644 --- a/include/rpc/detail/func_tools.h +++ b/include/rpc/detail/func_tools.h @@ -3,14 +3,13 @@ #ifndef FUNC_TOOLS_H_9FNRD4G2 #define FUNC_TOOLS_H_9FNRD4G2 -#include "rpc/detail/invoke.h" #include "rpc/detail/all.h" #include "rpc/detail/any.h" +#include "rpc/detail/invoke.h" namespace rpc { namespace detail { - enum class enabled {}; template @@ -19,8 +18,7 @@ using enable_if = invoke::value, enabled>>; template using disable_if = invoke::value, enabled>>; - -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: FUNC_TOOLS_H_9FNRD4G2 */ diff --git a/include/rpc/detail/func_traits.h b/include/rpc/detail/func_traits.h index 1847d99d..3650524c 100644 --- a/include/rpc/detail/func_traits.h +++ b/include/rpc/detail/func_traits.h @@ -22,14 +22,26 @@ struct nonzero_arg {}; struct void_result {}; struct nonvoid_result {}; -template struct arg_count_trait { typedef nonzero_arg type; }; +template +struct arg_count_trait { + typedef nonzero_arg type; +}; -template <> struct arg_count_trait<0> { typedef zero_arg type; }; +template <> +struct arg_count_trait<0> { + typedef zero_arg type; +}; -template struct result_trait { typedef nonvoid_result type; }; +template +struct result_trait { + typedef nonvoid_result type; +}; -template <> struct result_trait { typedef void_result type; }; -} +template <> +struct result_trait { + typedef void_result type; +}; +} // namespace tags //! \brief Provides a small function traits implementation that //! works with a reasonably large set of functors. @@ -42,10 +54,11 @@ struct func_traits : func_traits {}; template struct func_traits : func_traits {}; -template struct func_traits { - using result_type = R; - using arg_count = std::integral_constant; - using args_type = std::tuple::type...>; +template +struct func_traits { + using result_type = R; + using arg_count = std::integral_constant; + using args_type = std::tuple::type...>; }; template @@ -58,12 +71,14 @@ template struct func_kind_info : func_kind_info {}; -template struct func_kind_info { - typedef typename tags::arg_count_trait::type args_kind; - typedef typename tags::result_trait::type result_kind; +template +struct func_kind_info { + typedef typename tags::arg_count_trait::type args_kind; + typedef typename tags::result_trait::type result_kind; }; -template using is_zero_arg = is_zero::arg_count>; +template +using is_zero_arg = is_zero::arg_count>; template using is_single_arg = @@ -71,7 +86,7 @@ using is_single_arg = template using is_void_result = std::is_void::result_type>; -} -} +} // namespace detail +} // namespace rpc #endif /* end of include guard: FUNC_TRAITS_H_HWIWA6G0 */ diff --git a/include/rpc/detail/if.h b/include/rpc/detail/if.h index 7e4cab4f..83ea604e 100644 --- a/include/rpc/detail/if.h +++ b/include/rpc/detail/if.h @@ -11,6 +11,6 @@ namespace detail { template using if_ = invoke>; } -} +} // namespace rpc #endif /* end of include guard: IF_H_1OW9DR7G */ diff --git a/include/rpc/detail/invoke.h b/include/rpc/detail/invoke.h index 4a491582..534b6256 100644 --- a/include/rpc/detail/invoke.h +++ b/include/rpc/detail/invoke.h @@ -6,10 +6,9 @@ namespace rpc { namespace detail { -template +template using invoke = typename T::type; - -}} - +} +} // namespace rpc #endif /* end of include guard: INVOKE_H_0CWMPLUE */ diff --git a/include/rpc/detail/is_specialization_of.h b/include/rpc/detail/is_specialization_of.h index c4003cee..1a10988f 100644 --- a/include/rpc/detail/is_specialization_of.h +++ b/include/rpc/detail/is_specialization_of.h @@ -14,7 +14,7 @@ struct is_specialization_of : false_ {}; template