aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/include/uhdlib/rfnoc/block_container.hpp
blob: 3c75892a43c011dc0afe051fd42a354854cd30ae (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
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#ifndef INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP
#define INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP

#include <uhd/rfnoc/noc_block_base.hpp>
#include <uhd/rfnoc/block_id.hpp>
#include <boost/units/detail/utility.hpp>
#include <unordered_set>
#include <mutex>
#include <vector>

namespace uhd { namespace rfnoc { namespace detail {

/*! Storage container for RFNoC block controllers
 */
class block_container_t
{
public:
    block_container_t();

    void register_block(noc_block_base::sptr block);

    /*! Returns the block ids of all blocks that match the specified hint
     *
     * See uhd::rfnoc::rfnoc_graph::find_blocks() for details.
     */
    std::vector<block_id_t> find_blocks(const std::string& block_id_hint) const;

    /*! Checks if a specific NoC block exists on the device.
     *
     * See uhd::rfnoc::rfnoc_graph::has_block() for details.
     */
    bool has_block(const block_id_t& block_id) const;

    /*! \brief Returns a block controller class for an NoC block.
     *
     * See uhd::rfnoc::rfnoc_graph::get_block() for details.
     */
    noc_block_base::sptr get_block(const block_id_t& block_id) const;

    /*! Initialize properties on all registered blocks
     */
    void init_props();

    /*! Call shutdown() on all blocks
     *
     * After calling this, blocks won't be able to do anything anymore!
     */
    void shutdown();

private:
    //! Lock access to the storage
    mutable std::mutex _mutex;

    //! The actual block registry
    std::unordered_set<noc_block_base::sptr> _blocks;
};

}}} /* namespace uhd::rfnoc::detail */

#endif /* INCLUDED_LIBUHD_BLOCK_CONTAINER_HPP */