aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/actions.cpp
blob: 4de05b304a2c47269f1975280238b4a144a94105 (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
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#include <uhd/rfnoc/actions.hpp>
#include <uhd/rfnoc/defaults.hpp>
#include <atomic>

using namespace uhd::rfnoc;

namespace {
    // A static counter, which we use to uniquely label actions
    std::atomic<size_t> action_counter{0};
}

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, 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_make_shared>(key, args);
    return sptr(new action_info(key, args));
}

/*** Stream Command Action Info **********************************************/
stream_cmd_action_info::stream_cmd_action_info(
    const uhd::stream_cmd_t::stream_mode_t stream_mode)
    : action_info(ACTION_KEY_STREAM_CMD), stream_cmd(stream_mode)
{
    // nop
}

stream_cmd_action_info::sptr stream_cmd_action_info::make(
    const uhd::stream_cmd_t::stream_mode_t stream_mode)
{
    return sptr(new stream_cmd_action_info(stream_mode));
}

/*** RX Metadata Action Info *************************************************/
rx_event_action_info::rx_event_action_info() : action_info(ACTION_KEY_RX_EVENT)
{
    // nop
}

rx_event_action_info::sptr rx_event_action_info::make()
{
    struct rx_event_action_info_make_shared : public rx_event_action_info
    {
    };
    return std::make_shared<rx_event_action_info_make_shared>();
}

/*** TX Metadata Action Info *************************************************/
tx_event_action_info::tx_event_action_info(
    uhd::async_metadata_t::event_code_t event_code_)
    : action_info(ACTION_KEY_TX_EVENT), event_code(event_code_)
{
}

tx_event_action_info::sptr tx_event_action_info::make(
    uhd::async_metadata_t::event_code_t event_code)
{
    struct tx_event_action_info_make_shared : public tx_event_action_info
    {
        tx_event_action_info_make_shared(uhd::async_metadata_t::event_code_t event_code)
            : tx_event_action_info(event_code)
        {
        }
    };
    return std::make_shared<tx_event_action_info_make_shared>(event_code);
}