diff options
author | Martin Braun <martin.braun@ettus.com> | 2019-07-23 10:12:41 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:32 -0800 |
commit | 053306f2934e6ac61f03783c36eeff6b2c5ffe0f (patch) | |
tree | 27c26a43477f9207972f9768d4a1de1dd7125653 /host | |
parent | 2a66eb62d89c5d18c176878ce036f0109706a9e2 (diff) | |
download | uhd-053306f2934e6ac61f03783c36eeff6b2c5ffe0f.tar.gz uhd-053306f2934e6ac61f03783c36eeff6b2c5ffe0f.tar.bz2 uhd-053306f2934e6ac61f03783c36eeff6b2c5ffe0f.zip |
rfnoc: actions: Add dictionary to all actions
This can be used to set arbitrary key/value pairs on the action object.
Easier to use than serialization, but doesn't require custom types,
either.
Diffstat (limited to 'host')
-rw-r--r-- | host/include/uhd/rfnoc/actions.hpp | 9 | ||||
-rw-r--r-- | host/lib/rfnoc/actions.cpp | 13 | ||||
-rw-r--r-- | host/tests/actions_test.cpp | 6 |
3 files changed, 22 insertions, 6 deletions
diff --git a/host/include/uhd/rfnoc/actions.hpp b/host/include/uhd/rfnoc/actions.hpp index bc681360b..b713bbed3 100644 --- a/host/include/uhd/rfnoc/actions.hpp +++ b/host/include/uhd/rfnoc/actions.hpp @@ -8,6 +8,7 @@ #define INCLUDED_LIBUHD_RFNOC_ACTIONS_HPP #include <uhd/config.hpp> +#include <uhd/types/device_addr.hpp> #include <uhd/types/metadata.hpp> #include <uhd/types/stream_cmd.hpp> #include <memory> @@ -36,12 +37,16 @@ public: //! An arbitrary payload. It is up to consumers and producers to // (de-)serialize it. std::vector<uint8_t> payload; + //! A dictionary of key-value pairs. May be used as desired. + uhd::device_addr_t args; //! Factory function - static sptr make(const std::string& key=""); + static sptr make(const std::string& key = "", + const uhd::device_addr_t& args = uhd::device_addr_t("")); protected: - action_info(const std::string& key); + action_info( + const std::string& key, const uhd::device_addr_t& args = uhd::device_addr_t("")); }; struct UHD_API stream_cmd_action_info : public action_info diff --git a/host/lib/rfnoc/actions.cpp b/host/lib/rfnoc/actions.cpp index c441c52b3..d4ed4559f 100644 --- a/host/lib/rfnoc/actions.cpp +++ b/host/lib/rfnoc/actions.cpp @@ -15,20 +15,25 @@ namespace { std::atomic<size_t> action_counter{0}; } -action_info::action_info(const std::string& key_) : id(action_counter++), key(key_) +action_info::action_info(const std::string& key, const uhd::device_addr_t& args) + : id(action_counter++), key(key), args(args) { // nop } //! Factory function -action_info::sptr action_info::make(const std::string& key) +action_info::sptr action_info::make( + const std::string& key, const uhd::device_addr_t& args) { + struct action_info_make_shared : public action_info + { + }; if (key == ACTION_KEY_STREAM_CMD) { return stream_cmd_action_info::make( uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); } - //return std::make_shared<action_info>(key); - return sptr(new action_info(key)); + // return std::make_shared<action_info_make_shared>(key, args); + return sptr(new action_info(key, args)); } /*** Stream Command Action Info **********************************************/ diff --git a/host/tests/actions_test.cpp b/host/tests/actions_test.cpp index 9218ad231..2f9d9a702 100644 --- a/host/tests/actions_test.cpp +++ b/host/tests/actions_test.cpp @@ -42,6 +42,12 @@ BOOST_AUTO_TEST_CASE(test_actions_single_node) node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd); mock_radio.update_fwd_policy(node_t::forwarding_policy_t::ONE_TO_ALL_OUT); node_accessor.send_action(&mock_radio, {res_source_info::INPUT_EDGE, 0}, other_cmd); + + stream_cmd = + stream_cmd_action_info::make(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); + stream_cmd->stream_cmd.num_samps = 37; + node_accessor.send_action(&mock_radio, {res_source_info::USER, 0}, stream_cmd); + BOOST_CHECK_EQUAL(mock_radio.last_num_samps, 37); } BOOST_AUTO_TEST_CASE(test_actions_simple_graph) |