aboutsummaryrefslogtreecommitdiffstats
path: root/host/include/uhd/rfnoc/actions.hpp
blob: 7326cfd6dacdace3db68c6a0310095a8c971bc55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#ifndef INCLUDED_LIBUHD_RFNOC_ACTIONS_HPP
#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>
#include <string>
#include <vector>

namespace uhd { namespace rfnoc {

/*! Container for an action
 *
 * In the RFNoC context, an action is comparable to a command. Nodes in the
 * graph can send each other actions. action_info is the payload of such an
 * action message. Nodes pass shared pointers to action_info objects between
 * each other to avoid costly copies of large action_info objects.
 */
struct UHD_API action_info
{
public:
    virtual ~action_info() {}

    using sptr = std::shared_ptr<action_info>;
    //! A unique counter for this action
    const size_t id;
    //! A string identifier for this action
    std::string key;
    //! 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 = "",
        const uhd::device_addr_t& args      = uhd::device_addr_t(""));

protected:
    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
{
public:
    using sptr = std::shared_ptr<stream_cmd_action_info>;

    uhd::stream_cmd_t stream_cmd;

    //! Factory function
    static sptr make(const uhd::stream_cmd_t::stream_mode_t stream_mode);

private:
    stream_cmd_action_info(const uhd::stream_cmd_t::stream_mode_t stream_mode);
};

struct UHD_API rx_event_action_info : public action_info
{
public:
    using sptr = std::shared_ptr<rx_event_action_info>;

    //! The error code that describes the event
    uhd::rx_metadata_t::error_code_t error_code = uhd::rx_metadata_t::ERROR_CODE_NONE;

    //! Factory function
    static sptr make();

private:
    rx_event_action_info();
};

struct UHD_API tx_event_action_info : public action_info
{
public:
    using sptr = std::shared_ptr<tx_event_action_info>;

    //! The event code that describes the event
    uhd::async_metadata_t::event_code_t event_code;

    //! Has time specification?
    bool has_tsf;

    //! When the async event occurred
    uint64_t tsf;

    //! Factory function
    static sptr make(uhd::async_metadata_t::event_code_t event_code);

protected:
    tx_event_action_info(uhd::async_metadata_t::event_code_t event_code);
};

}} /* namespace uhd::rfnoc */

#endif /* INCLUDED_LIBUHD_RFNOC_ACTIONS_HPP */