| Line | % of fetches | Source |
|---|---|---|
| 1 | // Copyright (c) 2007-2016 Hartmut Kaiser | |
| 2 | // | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 5 | ||
| 6 | /// \file component_action.hpp | |
| 7 | ||
| 8 | #if !defined(HPX_RUNTIME_ACTIONS_COMPONENT_ACTION_MAR_26_2008_1054AM) | |
| 9 | #define HPX_RUNTIME_ACTIONS_COMPONENT_ACTION_MAR_26_2008_1054AM | |
| 10 | ||
| 11 | #include <hpx/config.hpp> | |
| 12 | #include <hpx/runtime/actions/basic_action.hpp> | |
| 13 | #include <hpx/runtime/actions/continuation.hpp> | |
| 14 | #include <hpx/runtime/components/console_error_sink.hpp> | |
| 15 | #include <hpx/runtime/naming/address.hpp> | |
| 16 | #include <hpx/util/detail/count_num_args.hpp> | |
| 17 | #include <hpx/util/detail/pp_strip_parens.hpp> | |
| 18 | #include <hpx/util/unused.hpp> | |
| 19 | ||
| 20 | #include <boost/preprocessor/cat.hpp> | |
| 21 | ||
| 22 | #include <cstdlib> | |
| 23 | #include <sstream> | |
| 24 | #include <stdexcept> | |
| 25 | #include <string> | |
| 26 | #include <utility> | |
| 27 | ||
| 28 | #include <hpx/config/warnings_prefix.hpp> | |
| 29 | ||
| 30 | /////////////////////////////////////////////////////////////////////////////// | |
| 31 | namespace hpx { namespace actions | |
| 32 | { | |
| 33 | /// \cond NOINTERNAL | |
| 34 | ||
| 35 | /////////////////////////////////////////////////////////////////////////// | |
| 36 | // Specialized generic non-const component action types allowing to hold | |
| 37 | // a different number of arguments | |
| 38 | /////////////////////////////////////////////////////////////////////////// | |
| 39 | template < | |
| 40 | typename Component, typename R, typename ...Ps, | |
| 41 | typename TF, TF F, typename Derived> | |
| 42 | class basic_action_impl< | |
| 43 | R (Component::*)(Ps...), TF, F, Derived> | |
| 44 | : public basic_action<Component, R(Ps...), Derived> | |
| 45 | { | |
| 46 | public: | |
| 47 | static std::string get_action_name(naming::address::address_type lva) | |
| 48 | { | |
| 49 | std::stringstream name; | |
| 50 | name << "component action(" | |
| 51 | << detail::get_action_name<Derived>() | |
| 52 | << ") lva(" | |
| 53 | << reinterpret_cast<void const*>(get_lva<Component>::call(lva)) | |
| 54 | << ")"; | |
| 55 | return name.str(); | |
| 56 | } | |
| 57 | ||
| 58 | template <typename ...Ts> | |
| 59 | static R invoke(naming::address::address_type lva, Ts&&... vs) | |
| 60 | { | |
| 61 | basic_action<Component, R(Ps...), Derived>:: | |
| 62 | increment_invocation_count(); | |
| 63 | return (get_lva<Component>::call(lva)->*F) | |
| 64 | (std::forward<Ts>(vs)...); | |
| 65 | } | |
| 66 | }; | |
| 67 | ||
| 68 | /////////////////////////////////////////////////////////////////////////// | |
| 69 | // Specialized generic const component action types allowing to hold a | |
| 70 | // different number of arguments | |
| 71 | /////////////////////////////////////////////////////////////////////////// | |
| 72 | template < | |
| 73 | typename Component, typename R, typename ...Ps, | |
| 74 | typename TF, TF F, typename Derived> | |
| 75 | class basic_action_impl< | |
| 76 | R (Component::*)(Ps...) const, TF, F, Derived> | |
| 77 | : public basic_action<Component const, R(Ps...), Derived> | |
| 78 | { | |
| 79 | public: | |
| 80 | static std::string get_action_name(naming::address::address_type lva) | |
| 81 | { | |
| 82 | std::stringstream name; | |
| 83 | name << "component action(" | |
| 84 | << detail::get_action_name<Derived>() | |
| 85 | << ") lva(" | |
| 86 | << reinterpret_cast<void const*>(get_lva<Component>::call(lva)) | |
| 87 | << ")"; | |
| 88 | return name.str(); | |
| 89 | } | |
| 90 | ||
| 91 | template <typename ...Ts> | |
| 92 | static R invoke(naming::address::address_type lva, Ts&&... vs) | |
| 93 | { | |
| 94 | basic_action<Component const, R(Ps...), Derived>:: | |
| 95 | increment_invocation_count(); | |
| 96 | return (get_lva<Component const>::call(lva)->*F) | |
| 97 | (std::forward<Ts>(vs)...); | |
| 98 | } | |
| 99 | }; | |
| 100 | ||
| 101 | /// \endcond | |
| 102 | }} | |
| 103 | ||
| 104 | /// \def HPX_DEFINE_COMPONENT_ACTION(component, func, action_type) | |
| 105 | /// | |
| 106 | /// \brief Registers a member function of a component as an action type | |
| 107 | /// with HPX | |
| 108 | /// | |
| 109 | /// The macro \a HPX_DEFINE_COMPONENT_ACTION can be used to register a | |
| 110 | /// member function of a component as an action type named \a action_type. | |
| 111 | /// | |
| 112 | /// The parameter \a component is the type of the component exposing the | |
| 113 | /// member function \a func which should be associated with the newly defined | |
| 114 | /// action type. The parameter \p action_type is the name of the action type to | |
| 115 | /// register with HPX. | |
| 116 | /// | |
| 117 | /// \par Example: | |
| 118 | /// | |
| 119 | /// \code | |
| 120 | /// namespace app | |
| 121 | /// { | |
| 122 | /// // Define a simple component exposing one action 'print_greeting' | |
| 123 | /// class HPX_COMPONENT_EXPORT server | |
| 124 | /// : public hpx::components::simple_component_base<server> | |
| 125 | /// { | |
| 126 | /// void print_greeting() const | |
| 127 | /// { | |
| 128 | /// hpx::cout << "Hey, how are you?\n" << hpx::flush; | |
| 129 | /// } | |
| 130 | /// | |
| 131 | /// // Component actions need to be declared, this also defines the | |
| 132 | /// // type 'print_greeting_action' representing the action. | |
| 133 | /// HPX_DEFINE_COMPONENT_ACTION(server, print_greeting, | |
| 134 | /// print_greeting_action); | |
| 135 | /// }; | |
| 136 | /// } | |
| 137 | /// \endcode | |
| 138 | /// | |
| 139 | /// The first argument must provide the type name of the component the | |
| 140 | /// action is defined for. | |
| 141 | /// | |
| 142 | /// The second argument must provide the member function name the action | |
| 143 | /// should wrap. | |
| 144 | /// | |
| 145 | /// \note The macro \a HPX_DEFINE_COMPONENT_ACTION can be used with 2 or | |
| 146 | /// 3 arguments. The third argument is optional. | |
| 147 | /// | |
| 148 | /// The default value for the third argument (the typename of the defined | |
| 149 | /// action) is derived from the name of the function (as passed as the second | |
| 150 | /// argument) by appending '_action'. The third argument can be omitted only | |
| 151 | /// if the first argument with an appended suffix '_action' resolves to a valid, | |
| 152 | /// unqualified C++ type name. | |
| 153 | /// | |
| 154 | #define HPX_DEFINE_COMPONENT_ACTION(...) \ | |
| 155 | HPX_DEFINE_COMPONENT_ACTION_(__VA_ARGS__) \ | |
| 156 | /**/ | |
| 157 | ||
| 158 | /// \cond NOINTERNAL | |
| 159 | #define HPX_DEFINE_COMPONENT_ACTION_(...) \ | |
| 160 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 161 | HPX_DEFINE_COMPONENT_ACTION_, HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 162 | )(__VA_ARGS__)) \ | |
| 163 | /**/ | |
| 164 | ||
| 165 | #define HPX_DEFINE_COMPONENT_ACTION_3(component, func, name) \ | |
| 166 | struct name : hpx::actions::make_action< \ | |
| 167 | decltype(&component::func), &component::func, name>::type {} \ | |
| 168 | /**/ | |
| 169 | #define HPX_DEFINE_COMPONENT_ACTION_2(component, func) \ | |
| 170 | HPX_DEFINE_COMPONENT_ACTION_3(component, func, \ | |
| 171 | BOOST_PP_CAT(func, _action)) \ | |
| 172 | /**/ | |
| 173 | /// \endcond | |
| 174 | ||
| 175 | /// \cond NOINTERNAL | |
| 176 | #define HPX_DEFINE_COMPONENT_DIRECT_ACTION(...) \ | |
| 177 | HPX_DEFINE_COMPONENT_DIRECT_ACTION_(__VA_ARGS__) \ | |
| 178 | /**/ | |
| 179 | ||
| 180 | #define HPX_DEFINE_COMPONENT_DIRECT_ACTION_(...) \ | |
| 181 | HPX_UTIL_EXPAND_(BOOST_PP_CAT( \ | |
| 182 | HPX_DEFINE_COMPONENT_DIRECT_ACTION_, \ | |
| 183 | HPX_UTIL_PP_NARG(__VA_ARGS__) \ | |
| 184 | )(__VA_ARGS__)) \ | |
| 185 | /**/ | |
| 186 | ||
| 187 | #define HPX_DEFINE_COMPONENT_DIRECT_ACTION_3(component, func, name) \ | |
| 188 | struct name : hpx::actions::make_direct_action< \ | |
| 189 | decltype(&component::func), &component::func, name>::type {} \ | |
| 190 | /**/ | |
| 191 | ||
| 192 | #define HPX_DEFINE_COMPONENT_DIRECT_ACTION_2(component, func) \ | |
| 193 | HPX_DEFINE_COMPONENT_DIRECT_ACTION_3(component, func, \ | |
| 194 | BOOST_PP_CAT(func, _action)) \ | |
| 195 | /**/ | |
| 196 | /// \endcond | |
| 197 | ||
| 198 | #include <hpx/config/warnings_suffix.hpp> | |
| 199 | ||
| 200 | #endif | |
| 201 |
Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.